Skip to content

Commit

Permalink
Merge pull request #216 from jhawthorn/fix_overridden_eq
Browse files Browse the repository at this point in the history
Fix opt_eq for overridden equality
  • Loading branch information
maximecb committed Sep 13, 2021
2 parents 99e87e7 + d897223 commit ae8add9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
26 changes: 23 additions & 3 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1943,14 +1943,34 @@ def eq(a, b)
]
}

# Redefined eq
# Redefined String eq
assert_equal 'true', %q{
class String
def ==(other)
true
end
end
"foo" == "bar"
"foo" == "bar"
def eq(a, b)
a == b
end
eq("foo", "bar")
eq("foo", "bar")
}

# Redefined Integer eq
assert_equal 'true', %q{
class Integer
def ==(other)
true
end
end
def eq(a, b)
a == b
end
eq(1, 2)
eq(1, 2)
}
8 changes: 5 additions & 3 deletions yjit_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,8 @@ gen_equality_specialized(jitstate_t* jit, ctx_t* ctx, uint8_t *side_exit)

if (FIXNUM_P(comptime_a) && FIXNUM_P(comptime_b)) {
if (!assume_bop_not_redefined(jit->block, INTEGER_REDEFINED_OP_FLAG, BOP_EQ)) {
return YJIT_CANT_COMPILE;
// if overridden, emit the generic version
return false;
}

guard_two_fixnums(ctx, side_exit);
Expand All @@ -2038,9 +2039,10 @@ gen_equality_specialized(jitstate_t* jit, ctx_t* ctx, uint8_t *side_exit)

return true;
} else if (CLASS_OF(comptime_a) == rb_cString &&
CLASS_OF(comptime_b) == rb_cString) {
CLASS_OF(comptime_b) == rb_cString) {
if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_EQ)) {
return YJIT_CANT_COMPILE;
// if overridden, emit the generic version
return false;
}

// Load a and b in preparation for call later
Expand Down

0 comments on commit ae8add9

Please sign in to comment.