Skip to content

Commit 630a6f8

Browse files
committed
.
1 parent 6552dad commit 630a6f8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

zjit/src/cruby_methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,9 @@ fn inline_basic_object_neq(fun: &mut hir::Function, block: hir::BlockId, recv: h
640640
let result = fun.push_insn(block, hir::Insn::Const { val: hir::Const::Value(Qfalse) });
641641
return Some(result);
642642
}
643-
if fun.is_a(other, types::StringExact) && fun.assume_expected_cfunc(block, recv_class, ID!(eq), rb_str_equal as _, state) {
643+
if fun.is_a(other, types::String) && fun.assume_expected_cfunc(block, recv_class, ID!(eq), rb_str_equal as _, state) {
644644
let recv = fun.coerce_to(block, recv, types::StringExact, state);
645-
let other = fun.coerce_to(block, other, types::StringExact, state);
645+
let other = fun.coerce_to(block, other, types::String, state);
646646
let return_type = types::BoolExact;
647647
let elidable = true;
648648
// TODO(max): Make StringEqual its own opcode so that we can later constant-fold StringEqual(a, a) => true

zjit/src/hir/opt_tests.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,41 @@ mod hir_opt_tests {
553553
");
554554
}
555555

556+
#[test]
557+
fn test_optimize_string_neq_string_subclass() {
558+
eval(r#"
559+
class C < String; end
560+
S = C.new("bar")
561+
def test(s) = s != S
562+
test "foo"
563+
"#);
564+
assert_snapshot!(hir_string("test"), @r"
565+
fn test@<compiled>:4:
566+
bb0():
567+
EntryPoint interpreter
568+
v1:BasicObject = LoadSelf
569+
v2:BasicObject = GetLocal l0, SP@4
570+
Jump bb2(v1, v2)
571+
bb1(v5:BasicObject, v6:BasicObject):
572+
EntryPoint JIT(0)
573+
Jump bb2(v5, v6)
574+
bb2(v8:BasicObject, v9:BasicObject):
575+
PatchPoint SingleRactorMode
576+
PatchPoint StableConstantNames(0x1000, S)
577+
v25:StringSubclass[VALUE(0x1008)] = Const Value(VALUE(0x1008))
578+
PatchPoint MethodRedefined(String@0x1010, !=@0x1018, cme:0x1020)
579+
PatchPoint NoSingletonClass(String@0x1010)
580+
v29:StringExact = GuardType v9, StringExact
581+
PatchPoint MethodRedefined(String@0x1010, ==@0x1048, cme:0x1050)
582+
PatchPoint NoSingletonClass(String@0x1010)
583+
v33:BoolExact = CCall v29, :String#==@0x1078, v25
584+
v34:BoolExact = BoolNot v33
585+
IncrCounter inline_cfunc_optimized_send_count
586+
CheckInterrupts
587+
Return v34
588+
");
589+
}
590+
556591
#[test]
557592
fn test_optimize_string_neq_nil() {
558593
eval(r#"

0 commit comments

Comments
 (0)