8000 Merge pull request #216 from jhawthorn/fix_overridden_eq · github/ruby@ae8add9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae8add9

Browse files
authored
Merge pull request #216 from jhawthorn/fix_overridden_eq
Fix opt_eq for overridden equality
2 parents 99e87e7 + d897223 commit ae8add9

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

bootstraptest/test_yjit.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,14 +1943,34 @@ def eq(a, b)
19431943
]
19441944
}
19451945

1946-
# Redefined eq
1946+
# Redefined String eq
19471947
assert_equal 'true', %q{
19481948
class String
19491949
def ==(other)
19501950
true
19511951
end
19521952
end
19531953
1954-
"foo" == "bar"
1955-
"foo" == "bar"
1954+
def eq(a, b)
1955+
a == b
1956+
end
1957+
1958+
eq("foo", "bar")
1959+
eq("foo", "bar")
1960+
}
1961+
1962+
# Redefined Integer eq
1963+
assert_equal 'true', %q{
1964+
class Integer
1965+
def ==(other)
1966+
true
1967+
end
1968+
end
1969+
1970+
def eq(a, b)
1971+
a == b
1972+
end
1973+
1974+
eq(1, 2)
1975+
eq(1, 2)
19561976
}

yjit_codegen.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,8 @@ gen_equality_specialized(jitstate_t* jit, ctx_t* ctx, uint8_t *side_exit)
20192019

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

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

20392040
return true;
20402041
} else if (CLASS_OF(comptime_a) == rb_cString &&
2041-
CLASS_OF(comptime_b) == rb_cString) {
2042+
CLASS_OF(comptime_b) == rb_cString) {
20422043
if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_EQ)) {
2043-
return YJIT_CANT_COMPILE;
2044+
// if overridden, emit the generic version
2045+
return false;
20442046
}
20452047

20462048
// Load a and b in preparation for call later

0 commit comments

Comments
 (0)
0