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 6726A1F5AE for ; Sat, 1 Aug 2020 14:54:51 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id AE4FF120BAD; Sat, 1 Aug 2020 23:54:17 +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 20FEB120A26 for ; Sat, 1 Aug 2020 23:54:14 +0900 (JST) Received: by filterdrecv-p3mdw1-7ff865655c-mjt6x with SMTP id filterdrecv-p3mdw1-7ff865655c-mjt6x-20-5F258232-30 2020-08-01 14:54:42.717317352 +0000 UTC m=+247105.746063928 Received: from herokuapp.com (unknown) by ismtpd0090p1iad2.sendgrid.net (SG) with ESMTP id Qmotg71AQxiBcbxicp0hcg for ; Sat, 01 Aug 2020 14:54:42.677 +0000 (UTC) Date: Sat, 01 Aug 2020 14:54:42 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75269 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr3GURd+cdmqDK+0rijwpL?= =?us-ascii?Q?V2LR0+BmNKeTL+yUSn3HOeuxzAEIRtx2YD77l6B?= =?us-ascii?Q?Tiwrb3N5tyZXBRd5Y8ASl9rLinTWhR5UAYiOFm1?= =?us-ascii?Q?vui0OQ=2FZziH2lOoAgQJVyzmkhnNjyHyXeZHhA4V?= =?us-ascii?Q?uVK5npWNika62gK3ESMLvONL4nrZnkZKAoeg4cE?= =?us-ascii?Q?wX=2FU5MbDu0SJVsPNo=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99440 Subject: [ruby-core:99440] [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). In other words, lazily initializing @ivars causes reads to need some branching because they need to handle both the initialized and uninitialized cases. So @ivars reads can no longer be straight-line code, which can impact performance as shown above. I think it's also often less readable. If variables are initialized in `initialize` it's clear which state is kept in that class. Also if the natural default is not `nil` but say `0` then `@foo = 0` in `initialize` is useful information (notably it gives the type), and it can be a simple `attr_reader :foo` to read it instead of the convoluted: ```ruby def foo @foo || 0 end ``` ---------------------------------------- Feature #17055: Allow suppressing uninitialized instance variable and method redefined verbose mode warnings https://bugs.ruby-lang.org/issues/17055#change-86895 * 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/