Thanks to visit codestin.com
Credit goes to github.com

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

Merged
merged 2 commits into from
Jul 2, 2025
Merged

ZJIT: throw to HIR #13729

merged 2 commits into from
Jul 2, 2025

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

zjit/src/hir.rs Outdated
@@ -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)

Copy link
Member Author

Choose a reason for hiding this comment

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

We do need to have a FrameState to check interrupts. Return should technically do that as well, and it doesn't as of yet. Maybe there should be a dedicated CheckInterrupts, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a dedicated CheckInterrupts

zjit/src/hir.rs Outdated
@@ -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

@XrXr XrXr force-pushed the zjit-throw-hir branch from e04d1f0 to 424485d Compare July 2, 2025 14:48
@XrXr XrXr enabled auto-merge (rebase) July 2, 2025 14:48
@XrXr XrXr merged commit ddb8de1 into ruby:master Jul 2, 2025
84 checks passed
@XrXr XrXr deleted the zjit-throw-hir branch July 2, 2025 15:52
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