From: XrXr@users.noreply.github.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:104791] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements
Date: Thu, 05 Aug 2021 15:29:31 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-93126.20210805152930.16806@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17806.20210416032511.16806@ruby-lang.org
Issue #17806 has been updated by alanwu (Alan Wu).
Hi @mk, from the description you gave, it's possible that you are running into #17725.
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)
```
If that fixes the issue I would try to run the test unmodified with a build of the master branch.
If the issue still exists on the master branch, I would try creating a reduced reproducer by logging `::Integer.ancestors` before each | call and refinement creation, assuming it's an issue related to lookup caching.
----------------------------------------
Bug #17806: Bad interaction between method cache, prepend, and refinements
https://bugs.ruby-lang.org/issues/17806#change-93126
* 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/
next prev parent reply other threads:[~2021-08-05 15:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 3:25 [ruby-core:103469] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements XrXr
2021-05-29 5:57 ` [ruby-core:104096] " nagachika00
2021-08-05 11:49 ` [ruby-core:104788] " mkaeppler
2021-08-05 15:29 ` XrXr [this message]
2021-08-12 13:31 ` [ruby-core:104897] " mkaeppler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-93126.20210805152930.16806@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).