Skip to content

ZJIT: throw to HIR #13729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

ZJIT: throw to HIR #13729

wants to merge 2 commits into from

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Jun 27, 2025

  • ZJIT: Use initialization shorthand
  • ZJIT: throw to HIR

No codegen for this for now since the calling convention is
somewhat in flux, and I'm not sure how best to do a unwind
with a value other than Qundef.

@matzbot matzbot requested a review from a team June 27, 2025 14:57
Copy link
Contributor

@tekknolagi tekknolagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@@ -488,6 +488,7 @@ pub enum Insn {

/// Control flow instructions
Return { val: InsnId },
Throw { state: u32, val: InsnId },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use state; we're probably going to need that for side exits and that's our conventional use case for the Snapshot InsnId. Maybe throw_state?

(Do we need to have a FrameState for throw? It feels like yes but I don't actually know how this works)

@@ -1013,6 +1031,7 @@ impl Function {
}
},
Return { val } => Return { val: find!(*val) },
&Throw { state, val } => Throw { state, val: find!(val) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: we can probably make a smarter macro find!(x) that expands to x: find!(x), etc

@@ -1117,7 +1136,7 @@ impl Function {
match &self.insns[insn.0] {
Insn::Param { .. } => unimplemented!("params should not be present in block.insns"),
Insn::SetGlobal { .. } | Insn::ArraySet { .. } | Insn::Snapshot { .. } | Insn::Jump(_)
| Insn::IfTrue { .. } | Insn::IfFalse { .. } | Insn::Return { .. }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: we should probably use has_output here

@@ -2696,6 +2716,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
fun.push_insn(block, Insn::Return { val: state.stack_pop()? });
break; // Don't enqueue the next block as a successor
}
YARVINSN_throw => {
fun.push_insn(block, Insn::Throw { state: get_arg(pc, 0).as_u32(), val: state.stack_pop()? });
break; // Don't enqueue the next block as a successor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: we can probably extract this into is_terminator below? maybe?

@tekknolagi
Copy link
Contributor

Since codegen for this (and others) is challenging, maybe we should be compiling hard-to-codegen instructions into explicit side-exits for now instead of aborting compilation. Though that does require that they have a FrameState

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants