8000 ZJIT: SideExit on optional args by composerinteralia · Pull Request #13633 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Z 8000 JIT: SideExit on optional args #13633

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ZJIT: SideExit on optional args
We haven't implemented optional args yet, so `SideExit` for now.
Prior to this commit `def test(a=true) a` would compile to:

```
fn test:
bb0(v0:BasicObject, v1:BasicObject):
  v3:TrueClassExact = Const Value(true)
  Return v3
```

But that is only correct for the case where the caller does not pass in
the optional arg. We probably need a guard on the PC similar to what
YJIT has.
  • Loading branch information
composerinteralia committed Jun 17, 2025
commit 917c02246fbb5ccc182cdadfff5539687d88170c
19 changes: 19 additions & 0 deletions zjit/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,13 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
let exit_state = state.clone();
profiles.profile_stack(&exit_state);

// TODO: Remove this and implement optional arguments
if unsafe { get_iseq_flags_has_opt(iseq) } {
let exit_id = fun.push_insn(block, Insn::Snapshot { state: exit_state });
fun.push_insn(block, Insn::SideExit { state: exit_id });
break; // End the block
}

// try_into() call below is unfortunate. Maybe pick i32 instead of usize for opcodes.
let opcode: u32 = unsafe { rb_iseq_opcode_at_pc(iseq, pc) }
.try_into()
Expand Down Expand Up @@ -3476,6 +3483,18 @@ mod tests {
"#]]);
}

#[test]
fn test_cant_compile_optional_arg() {
eval("
def test(a=nil) = a
");
assert_method_hir("test", expect![[r#"
fn test:
bb0(v0:BasicObject, v1:BasicObject):
SideExit
"#]]);
}

#[test]
fn test_cant_compile_splat() {
eval("
Expand Down
Loading
0