[ruby-core:104897] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements
From:
mkaeppler@...
Date:
2021-08-12 13:31:36 UTC
List:
ruby-core #104897
Issue #17806 has been updated by mk (Matthias K舊pler).
Thanks @alanwu!
I forgot to watch this issue so I was never notified of your response. Sorry for the delay.
> I would try running these two lines before requiring the test file that contains the | call:
>
> ```
> iseq = RubyVM::InstructionSequence
> iseq.compile_option = iseq.compile_option.merge(specialized_instruction: false)
> ```
Thank you so much -- I was eventually able to verify that this is indeed the problem. Moving this in front of `application.rb` (this is a Rails app) fixes the test.
> If that fixes the issue I would try to run the test unmodified with a build of the master branch.
Yep, we have a system in place that applies custom patches to our CI and production Rubies, and I was able to verify that applying https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/fb4cf204a662a8cd9dafef6f31f2bd0db9129abe/diff and https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/fa0279d947c3962c3f8c32852278d3ebb964cb19/diff to `3.0.2` resolves the issue (the former turns the test green, the latter fixes a segfault I ran into after applying the former).
Again, I really appreciate your help -- this caused me quite the headache :-)
----------------------------------------
Bug #17806: Bad interaction between method cache, prepend, and refinements
https://bugs.ruby-lang.org/issues/17806#change-93257
* Author: alanwu (Alan Wu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: DONE
----------------------------------------
I'm running into a couple of issues with Ruby 3's new method cache and
refinements.
The first script raises `SystemStackError` unexpectedly:
```ruby
module R1
refine Hash do
def foo; :r1; end
end
end
class Hash
prepend(Module.new)
end
class Hash
def foo; end
end
{}.method(:foo) # put it on pCMC
module R2
refine Hash do
def foo; :r2; end
end
end
{}.foo # SystemStackError
```
The second script calls the wrong method:
```ruby
klass = Class.new { def foo; end }
_refinement = Module.new do
refine(klass) { def foo; :refined; end }
end
klass.prepend(Module.new)
klass.new.foo # cache foo
klass.define_method(:foo) { :second }
p klass.new.foo # prints nil. False caching.
```
I submitted a GitHub PR to fix the issue: https://github.com/ruby/ruby/pull/4386
--
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>