Skip to content

Commit cdb9c25

Browse files
authored
ZJIT: Guard receiver class for CCallVariadic (ruby#14630)
1 parent 1d00c11 commit cdb9c25

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

test/ruby/test_zjit.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ def entry = test(a: 1, b: 2)
470470
}
471471
end
472472

473+
def test_send_ccall_variadic_with_different_receiver_classes
474+
assert_compiles '[true, true]', %q{
475+
def test(obj) = obj.start_with?("a")
476+
[test("abc"), test(:abc)]
477+
}, call_threshold: 2
478+
end
479+
473480
def test_forwardable_iseq
474481
assert_compiles '1', %q{
475482
def test(...) = 1

zjit/src/hir.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,11 @@ impl Function {
21692169
state
21702170
});
21712171

2172+
if let Some(profiled_type) = profiled_type {
2173+
// Guard receiver class
2174+
recv = fun.push_insn(block, Insn::GuardType { val: recv, guard_type: Type::from_profiled_type(profiled_type), state });
2175+
}
2176+
21722177
let cfun = unsafe { get_mct_func(cfunc) }.cast();
21732178
let ccall = fun.push_insn(block, Insn::CCallVariadic {
21742179
cfun,
@@ -7131,9 +7136,10 @@ mod opt_tests {
71317136
v4:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
71327137
v6:StringExact = StringCopy v4
71337138
PatchPoint MethodRedefined(Object@0x1008, puts@0x1010, cme:0x1018)
7134-
v16:BasicObject = CCallVariadic puts@0x1040, v0, v6
7139+
v16:HeapObject[class_exact*:Object@VALUE(0x1008)] = GuardType v0, HeapObject[class_exact*:Object@VALUE(0x1008)]
7140+
v17:BasicObject = CCallVariadic puts@0x1040, v16, v6
71357141
CheckInterrupts
7136-
Return v16
7142+
Return v17
71377143
");
71387144
}
71397145

@@ -8515,7 +8521,8 @@ mod opt_tests {
85158521
PatchPoint MethodRedefined(Set@0x1008, new@0x1010, cme:0x1018)
85168522
v10:HeapObject = ObjectAlloc v34
85178523
PatchPoint MethodRedefined(Set@0x1008, initialize@0x1040, cme:0x1048)
8518-
v39:BasicObject = CCallVariadic initialize@0x1070, v10
8524+
v39:HeapObject[class_exact:Set] = GuardType v10, HeapObject[class_exact:Set]
8525+
v40:BasicObject = CCallVariadic initialize@0x1070, v39
85198526
CheckInterrupts
85208527
CheckInterrupts
85218528
Return v10

0 commit comments

Comments
 (0)