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 792F81F990 for ; Wed, 5 Aug 2020 20:58:51 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D4C85120B3E; Thu, 6 Aug 2020 05:58:18 +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 6F8A0120B3C for ; Thu, 6 Aug 2020 05:58:16 +0900 (JST) Received: by filterdrecv-p3iad2-d8cc6d457-s4grk with SMTP id filterdrecv-p3iad2-d8cc6d457-s4grk-18-5F2B1D84-2E 2020-08-05 20:58:44.297638377 +0000 UTC m=+615029.487897904 Received: from herokuapp.com (unknown) by geopod-ismtpd-1-2 (SG) with ESMTP id Y636neW2RomLR2omvovXzQ for ; Wed, 05 Aug 2020 20:58:44.208 +0000 (UTC) Date: Wed, 05 Aug 2020 20:58:44 +0000 (UTC) From: bughitgithub@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75314 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Misc X-Redmine-Issue-Id: 17104 X-Redmine-Issue-Author: bughit X-Redmine-Sender: bughit 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?Lz0+3qGVJFpKTmjP+6UJd2KKTsj+AtuP2yOGs8HtvQKCGdr4Do04vqOIQ6RFNN?= =?us-ascii?Q?S3dvk2L5Vst+xe1ak5U16TyiMvYL1EiwMTdegk2?= =?us-ascii?Q?Fms3YavBkygXm+71UZ6VldW079RN3sGTqyY6E0G?= =?us-ascii?Q?vXfUX+MirssqrjDMyUVIuQhf7G5kJEkNAgPy2qV?= =?us-ascii?Q?Xf2dRyaIRS3O5a6NV7NqZGrvqCZk2o9maMB83Zl?= =?us-ascii?Q?3Ir5dw36TUT8uKLRA=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99488 Subject: [ruby-core:99488] [Ruby master Misc#17104] Why are interpolated string literals frozen? 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 #17104 has been updated by bughit (bug hit). If you want to get a mutable string from an interpolated literal `+"_#{method1}_"`, 2 allocation will be done instead of 1, if it weren't pointlessly frozen. In this case a feature designed to reduce allocations is producing more allocations. Behavior that's counter-intuitive and illogical and acting counter to its intent, is not simple. This happens to be something that can be changed without breaking anything. Can it get a second look? ---------------------------------------- Misc #17104: Why are interpolated string literals frozen? https://bugs.ruby-lang.org/issues/17104#change-86944 * Author: bughit (bug hit) * Status: Closed * Priority: Normal ---------------------------------------- ```rb #frozen_string_literal: true def foo(str) "#{str}" end fr1 = 'a' fr2 = 'a' fr1_1 = foo(fr1) fr2_1 = foo(fr2) puts fr1.__id__, fr2.__id__, fr1_1.__id__, fr2_1.__id__ puts fr1_1 << 'b' ``` Isn't the point of frozen literals to avoid needless allocations? But interpolated strings are allocated each time, so freezing appears pointless. -- https://bugs.ruby-lang.org/