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-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 B48B21F5AE for ; Wed, 29 Jul 2020 20:48:22 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BBC1812099F; Thu, 30 Jul 2020 05:47:41 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1CFD0120988 for ; Thu, 30 Jul 2020 05:47:38 +0900 (JST) Received: by filterdrecv-p3iad2-d8cc6d457-bxf2m with SMTP id filterdrecv-p3iad2-d8cc6d457-bxf2m-18-5F21E086-44 2020-07-29 20:48:06.500998999 +0000 UTC m=+9588.254202653 Received: from herokuapp.com (unknown) by ismtpd0074p1mdw1.sendgrid.net (SG) with ESMTP id vcuUY-q7R-qN0JEh4qnnrg for ; Wed, 29 Jul 2020 20:48:06.390 +0000 (UTC) Date: Wed, 29 Jul 2020 20:48:06 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75221 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17055 X-Redmine-Issue-Author: jeremyevans0 X-Redmine-Sender: Eregon 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-SG-EID: =?us-ascii?Q?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr3XIq+Zdzy0u3AJkrwCWs?= =?us-ascii?Q?3P2SsQ9mh0FA2F54DJfP=2FX3d+0QGqNnyForyGKE?= =?us-ascii?Q?UkRYG5+Q8vGXG6qnJvrDCthZo0Vc+KUHiILeuQe?= =?us-ascii?Q?el7pbI+FXVVCVA5MX55qieCQuP0c=2FkRD5ttrhmo?= =?us-ascii?Q?yIRJLPf49JwyJK0EKcFcDMogNrXN3YMB7C+wBac?= =?us-ascii?Q?oLf6uEkHyQfWkw1aU=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99395 Subject: [ruby-core:99395] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings 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 #17055 has been updated by Eregon (Benoit Daloze). jeremyevans0 (Jeremy Evans) wrote: > Not initializing instance variables to nil can be much better for performance Why is that? Because just writing extra instance variables in `initialize` is much slower in MRI? It's already an allocation path so it's not that fast anyway (unless escape analyzed, and then writing instance variables should be pretty much free). It seems a very narrow use-case to me, and extremely MRI-specific. In fact I wouldn't be surprised if on other Ruby implementations initializing led to better performance (e.g., no need to grow the ivar storage dynamically later, or change the shape/hidden class). I would much prefer a Warning category for this. Or probably your `warning` gem could be used to suppress those conveniently? Calling more methods when doing warnings is adding more boilerplate, complexity and edge cases to these code paths. ---------------------------------------- Feature #17055: Allow suppressing uninitialized instance variable and method redefined verbose mode warnings https://bugs.ruby-lang.org/issues/17055#change-86836 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Priority: Normal ---------------------------------------- These two verbose mode warnings are both fairly common and have good reasons why you would not want to warn about them in specific cases. Not initializing instance variables to nil can be much better for performance, and redefining methods without removing the method first is the only safe approach in multi-threaded code. There are reasons that you may want to issue verbose warnings by default in these cases. For uninitialized instance variables, it helps catch typos. For method redefinition, it could alert you that a method already exists when you didn't expect it to, such as when a file is loaded multiple times when it should only be loaded once. I propose we keep the default behavior the same, but offer the ability to opt-out of these warnings by defining methods. For uninitialized instance variables in verbose mode, I propose we call `expected_uninitialized_instance_variable?(iv)` on the object. If this method doesn't exist or returns false/nil, we issue the warning. If the method exists and returns true, we suppress the warning. Similarly, for redefined methods, we call `expected_redefined_method?(method_name)` on the class or module. If the method doesn't exist or returns false/nil, we issue the warning. If the method exists and returns true, we suppress the warning. This approach allows high performance code (uninitialized instance variables) and safe code (redefining methods without removing) to work without verbose mode warnings. I have implemented this support in a pull request: https://github.com/ruby/ruby/pull/3371 -- https://bugs.ruby-lang.org/