Skip to content

Commit 240c9d6

Browse files
authored
ZJIT: Add new test and TODO
This was supposed to go in with ruby#16476 but I didn't realize I never pushed...
1 parent e832057 commit 240c9d6

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

zjit/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7905,6 +7905,8 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
79057905
let join_block = insn_idx_to_block.get(&insn_idx).copied().unwrap_or_else(|| fun.new_block(insn_idx));
79067906
let join_param = fun.push_insn(join_block, Insn::Param);
79077907
// Dedup by expected shape so objects with different classes but the same shape can share code
7908+
// TODO(max): De-duplicate further by checking ivar offsets to allow
7909+
// different shapes with the same ivar layout to share code
79087910
let mut seen_shapes = Vec::with_capacity(summary.buckets().len());
79097911
for &profiled_type in summary.buckets() {
79107912
// End of the buckets

zjit/src/hir/opt_tests.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7507,6 +7507,68 @@ mod hir_opt_tests {
75077507
");
75087508
}
75097509

7510+
#[test]
7511+
fn test_optimize_getivar_polymorphic_with_subclass() {
7512+
set_call_threshold(3);
7513+
eval(r#"
7514+
class C
7515+
def initialize
7516+
@foo = 3
7517+
end
7518+
7519+
def foo = @foo + 1
7520+
end
7521+
7522+
class D < C
7523+
def initialize
7524+
super
7525+
@bar = 4
7526+
end
7527+
end
7528+
7529+
O1 = C.new
7530+
O2 = D.new
7531+
O1.foo
7532+
O2.foo
7533+
"#);
7534+
assert_snapshot!(hir_string_proc("C.instance_method(:foo)"), @"
7535+
fn foo@<compiled>:7:
7536+
bb1():
7537+
EntryPoint interpreter
7538+
v1:BasicObject = LoadSelf
7539+
Jump bb3(v1)
7540+
bb2():
7541+
EntryPoint JIT(0)
7542+
v4:BasicObject = LoadArg :self@0
7543+
Jump bb3(v4)
7544+
bb3(v6:BasicObject):
7545+
PatchPoint SingleRactorMode
7546+
v11:HeapBasicObject = GuardType v6, HeapBasicObject
7547+
v12:CShape = LoadField v11, :_shape_id@0x1000
7548+
v14:CShape[0x1001] = Const CShape(0x1001)
7549+
v15:CBool = IsBitEqual v12, v14
7550+
IfTrue v15, bb5()
7551+
v19:CShape[0x1002] = Const CShape(0x1002)
7552+
v20:CBool = IsBitEqual v12, v19
7553+
IfTrue v20, bb6()
7554+
v24:BasicObject = GetIvar v11, :@foo
7555+
Jump bb4(v24)
7556+
bb5():
7557+
v17:BasicObject = LoadField v11, :@foo@0x1003
7558+
Jump bb4(v17)
7559+
bb6():
7560+
v22:BasicObject = LoadField v11, :@foo@0x1003
7561+
Jump bb4(v22)
7562+
bb4(v13:BasicObject):
7563+
v27:Fixnum[1] = Const Value(1)
7564+
PatchPoint MethodRedefined(Integer@0x1008, +@0x1010, cme:0x1018)
7565+
v38:Fixnum = GuardType v13, Fixnum
7566+
v39:Fixnum = FixnumAdd v38, v27
7567+
CheckInterrupts
7568+
Return v39
7569+
");
7570+
}
7571+
75107572
#[test]
75117573
fn test_dont_optimize_attr_accessor_polymorphic() {
75127574
set_call_threshold(3);

0 commit comments

Comments
 (0)