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=-4.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 9FF641F8C6 for ; Thu, 5 Aug 2021 11:49:42 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5AB7B120ABF; Thu, 5 Aug 2021 20:48:22 +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 AB73A120AC6 for ; Thu, 5 Aug 2021 20:48:20 +0900 (JST) Received: by filterdrecv-59cd58ccfb-cptwc with SMTP id filterdrecv-59cd58ccfb-cptwc-1-610BD04A-9 2021-08-05 11:49:30.196951448 +0000 UTC m=+73735.417947987 Received: from herokuapp.com (unknown) by ismtpd0190p1mdw1.sendgrid.net (SG) with ESMTP id ljb_XKicSwSGfic6Y4Swew for ; Thu, 05 Aug 2021 11:49:30.125 +0000 (UTC) Date: Thu, 05 Aug 2021 11:49:30 +0000 (UTC) From: mkaeppler@gitlab.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: mk 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: 80920 X-SG-EID: =?us-ascii?Q?2IjJ2mvoEzbWaTrhskTR5Z6Jr7Htund8XDSpIP9M8J=2FwUTDxvzh+RdiEaHGfqQ?= =?us-ascii?Q?6r2MuqJYJNG+FHEwFJ+iOw8SaVRW=2Fj+pEjY4cbJ?= =?us-ascii?Q?biFnDQVowumT+6uH7YZRrwQcrkEfPz0XAzbtd1v?= =?us-ascii?Q?HP350x8CufwKbiZaLMORtcQF+M5a+wHzCCfSBHP?= =?us-ascii?Q?fqOg23n9IpOrAd9Sch3XIwutzZ2D5a2iggQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 104788 Subject: [ruby-core:104788] [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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17806 has been updated by mk (Matthias K=E4ppler). Hi @alanwu, at GitLab we are currently working on making our application Ruby 3 ready. We are running into a strange issue in our test suite where refinements fai= ls to be applied when everything suggests they should be. During my research I stumbled on this issue here and I was wondering if you= could give me your thoughts on whether this could be a Ruby VM bug. I summarized in this issue what the problem is: https://gitlab.com/gitlab-o= rg/gitlab/-/issues/337614 To recap the high-level highlights and observations: - We use rspec-parameterized and its table-syntax extension (which override= s the pipe `|` operator using refinements) - Whenever we run a test that composes a test table using integer arguments= , Ruby will invoke the built-in bitwise-OR instead of the refinement, thus = breaking the test - When I add another refinement to Integer at the top of the test file, eve= n when not `using` it, the test will start to pass This leads me to believe it could be due to Ruby's method table being messe= d up somehow, since it is very suspicious that by refining a class with an = unused method, another refinement should suddenly start to apply. Since thi= s changeset here touches the caching behavior, I thought you might have an = idea whether it could be related. We also verified that this happens not just with 3.0.2, but also 3.0.1, but= works on 2.7, so it is likely not strictly related to this particular chan= ge. But since I have no evidence that it is in fact a Ruby bug, I was also = hesitant to open a new issue. I have so far not been able to produce a minimal executable test case eithe= r. Any hints and thoughts for how to debug this would be appreciated! ---------------------------------------- Bug #17806: Bad interaction between method cache, prepend, and refinements https://bugs.ruby-lang.org/issues/17806#change-93123 * 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 =3D Class.new { def foo; end } _refinement =3D 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: