Actions
Misc #16961
closedIs overriding a method in a subclass considered as a breaking change or not?
Status:
Closed
Assignee:
-
Description
Background¶
- In [Bug #15589], I'm going to make
Integer#zero?
faster (comparable to== 0
) on JIT by making sure the method is inlinable by MJIT.- Currently
Integer#zero?
is not defined and it's implemented asNumeric#zero?
. - However,
Numeric#zero?
's method definition handles not onlyInteger
but alsoRational
andComplex
. Becauserb_equal
which callsrb_funcall
is used forRational
andComplex
, we can't predict what'd happen there and it preventsNumeric#zero?
from being inlined by MJIT. Moreover, reducing inlined code size is always good for JIT-ed code. So specializingNumeric#zero?
toInteger#zero?
will be beneficial for MJIT's inlining regardless ofrb_funcall
's presence. - So I'd like to define
Integer#zero?
for optimizing JIT-ed code ofzero?
call againstInteger
.
- Currently
Discussion¶
Theoretically, overriding a method in a subclass in Ruby core might change an existing application's behavior (If a user overwrote Numeric#zero?
and then Ruby core overwrote Integer#zero?
, the user's definition would get suddenly ignored for Integer).
How should we decide whether the change is acceptable or not? Some possible ideas:
- Search all gems using gem-codesearch and check if there's any code to be broken.
- In
Integer#zero?
's case I found this code but it's not gonna be broken by overridingInteger#zero?
. Otherzero?
method definitions seemed for other classes, but I can double check every occurrence if this will be the measure.
- In
- Discuss and make a decision on case-by-case basis.
- In
Integer#zero?
's case we'll discuss whether overridingInteger#zero?
is acceptable or not.
- In
Actions
Like0
Like0Like0Like0Like0Like0Like0