From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_NXDOMAIN,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C6C4C1F8C6 for ; Thu, 5 Aug 2021 15:29:46 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9B92F1209E9; Fri, 6 Aug 2021 00:28:24 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id E2A2B1209B5 for ; Fri, 6 Aug 2021 00:28:22 +0900 (JST) Received: by filterdrecv-7c9f9f88f-226hk with SMTP id filterdrecv-7c9f9f88f-226hk-1-610C03DB-1 2021-08-05 15:29:31.04095028 +0000 UTC m=+853785.418420211 Received: from herokuapp.com (unknown) by ismtpd0147p1iad2.sendgrid.net (SG) with ESMTP id 23Z2JB22SNii-qwLpY1UMw for ; Thu, 05 Aug 2021 15:29:30.950 +0000 (UTC) Date: Thu, 05 Aug 2021 15:29:31 +0000 (UTC) From: XrXr@users.noreply.github.com Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17806 X-Redmine-Issue-Author: alanwu X-Redmine-Sender: alanwu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 80923 X-SG-EID: =?us-ascii?Q?PWg67P6owy8ojUUZg1G=2FQM4Z0jTQ2XLCqLM8Y2L8tUvRFuUPM6+aKANjRFY5CJ?= =?us-ascii?Q?rI7pY0xHcq1Zyiknnkl8XLwDBs=2FhPaWgWI9wL8X?= =?us-ascii?Q?Qn2WocibodqZiq8WlmMUGsQ+CnLranbkMretokG?= =?us-ascii?Q?CI+9lBXImV6jBKrux3jnZg5Ii0ygbF24ivW9ySN?= =?us-ascii?Q?IwMlYMit=2F41V69UzaSnbmdSRCuwUAVgJfIlr0NE?= =?us-ascii?Q?uQcnd2aJFmK5gkeyk=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 104791 Subject: [ruby-core:104791] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/