Issue #17660 has been updated by tenderlovemaking (Aaron Patterson).


Eregon (Benoit Daloze) wrote in #note-2:
> It sounds useful, +1 from me.
> I think we should clarify in the name that only redefined basic methods are reported, and not all redefined methods.
> How about `redefined_basic_methods`?

This sound good to me. I wasn't very happy with the name 

> Putting it under `RubyVM` increases the issue that `RubyVM` is becoming less and less CRuby-specific.
> But I'm pretty much convinced this will happen anyway since ruby-core doesn't seem to want to avoid that (https://bugs.ruby-lang.org/issues/15752#note-28).
> So I'm not against it, just making note of this aspect.

I don't really have an opinion where to put this new method, but it's *definitely* CRuby specific and I want to make sure that fact is reflected.  I kind of assumed the methods on `RubyVM` were specific to the VM being run, so some methods change or are optional depending on the runtime (similar to methods on `GC`).  One example is `RubyVM.stat`. The values returned on MRI don't make sense in JRuby, so I wouldn't expect it to be implemented.

> I think having this method under a "VM"-named module makes sense at least.
> We should consider this method like any other new method, i.e., `RubyVM` is de facto no longer experimental.
> 
> Another place where this method might make sense is as a instance method of `Class` (or `Module`).

As I said, I don't have any strong opinion about where to put this method as long as a) I can have the method, and b) it communicates to the user that this is CRuby specific and only for basic operations like `Integer#+` or `NilClass#nil?`, etc.

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

* 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>