Skip to content

Commit 677c363

Browse files
committed
ZJIT: Fix insn arg index for defined, add tests
1 parent 657b2f0 commit 677c363

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ fn main() {
368368
.allowlist_function("rb_iseqw_to_iseq")
369369
.allowlist_function("rb_iseq_label")
370370
.allowlist_function("rb_iseq_line_no")
371+
.allowlist_function("rb_iseq_defined_string")
371372
.allowlist_type("defined_type")
372373

373374
// From builtin.h

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,22 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
606606
Ok(())
607607
},
608608
Insn::Snapshot { state } => write!(f, "Snapshot {}", state),
609+
Insn::Defined { op_type, v, .. } => {
610+
// op_type (enum defined_type) printing logic from iseq.c.
611+
// Not sure why rb_iseq_defined_string() isn't exhaustive.
612+
use std::borrow::Cow;
613+
let op_type = *op_type as u32;
614+
let op_type = if op_type == DEFINED_FUNC {
615+
Cow::Borrowed("func")
616+
} else if op_type == DEFINED_REF {
617+
Cow::Borrowed("ref")
618+
} else if op_type == DEFINED_CONST_FROM {
619+
Cow::Borrowed("constant-from")
620+
} else {
621+
String::from_utf8_lossy(unsafe { rb_iseq_defined_string(op_type).as_rstring_byte_slice().unwrap() })
622+
};
623+
write!(f, "Defined {op_type}, {v}")
624+
}
609625
Insn::DefinedIvar { self_val, id, .. } => write!(f, "DefinedIvar {self_val}, :{}", id.contents_lossy().into_owned()),
610626
Insn::GetIvar { self_val, id, .. } => write!(f, "GetIvar {self_val}, :{}", id.contents_lossy().into_owned()),
611627
Insn::SetIvar { self_val, id, val, .. } => write!(f, "SetIvar {self_val}, :{}, {val}", id.contents_lossy().into_owned()),
@@ -2165,9 +2181,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
21652181
state.stack_push(fun.push_insn(block, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(1)) }));
21662182
}
21672183
YARVINSN_defined => {
2184+
// (rb_num_t op_type, VALUE obj, VALUE pushval)
21682185
let op_type = get_arg(pc, 0).as_usize();
2169-
let obj = get_arg(pc, 0);
2170-
let pushval = get_arg(pc, 0);
2186+
let obj = get_arg(pc, 1);
2187+
let pushval = get_arg(pc, 2);
21712188
let v = state.stack_pop()?;
21722189
state.stack_push(fun.push_insn(block, Insn::Defined { op_type, obj, pushval, v }));
21732190
}

0 commit comments

Comments
 (0)