Issue #17660 has been updated by Eregon (Benoit Daloze).


tenderlovemaking (Aaron Patterson) wrote in #note-6:
> this is CRuby specific and only for basic operations like `Integer#+` or `NilClass#nil?`, etc.

It is not CRuby-specific, in fact this new method does make sense on at least TruffleRuby too.
(https://github.com/oracle/truffleruby/blob/cbb97d56017a10497925e062c87b55bdea545b19/src/main/java/org/truffleruby/core/inlined/CoreMethodAssumptions.java#L63 for details)

`RubyVM.stat` is also not CRuby-specific, other Rubies might just have different keys.
`GC.stat` is similar, and is already implemented on JRuby & TruffleRuby, with slightly different keys.
In general, nothing is CRuby-specific, because gems will rely on it and then other Ruby implementations typically prefer to implement it than change all gems depending on it
(some gems use a feature check so it doesn't fail, but typically the extra insight from those methods is useful).

It seems good to mention in the docs that the set of redefined methods reported might change by version and Ruby implementation.

----------------------------------------
Feature #17660: Expose information about which basic methods have been redefined
https://bugs.ruby-lang.org/issues/17660#change-90645

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Priority: Normal
----------------------------------------
I would like to tell if code is redefining methods that can impact
MRI's optimizations.  This commit exposes which basic methods have been
redefined.  For example:

```ruby
class Integer
  def +(x); x ** self; end
end

p RubyVM.redefined_methods # => {Integer=>[:+]}
```

This will allow us to prevent basic method redefinitions from happening
by checking for them in CI environments.  For example:

```ruby
Minitest.after_run {
  fail "Basic methods have been redefine" if RubyVM.redefined_methods.any?
}
```

---Files--------------------------------
0001-Expose-information-about-which-basic-methods-have-be.patch (3.89 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>