ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: duerst@it.aoyama.ac.jp
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99551] [Ruby master Feature#17104] Do not freeze interpolated strings when using frozen-string-literal
Date: Tue, 11 Aug 2020 06:22:28 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-87013.20200811062227.8741@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17104.20200805200602.8741@ruby-lang.org

Issue #17104 has been updated by duerst (Martin Dürst).


bughit (bug hit) wrote in #note-11:
> > However in my view what defines a literal, is the use of a specific syntax, so ""
> 
> There is only one reason for freezing literals, to be able to intern them and reduce allocation. In fact the feature is poorly named, after the consequence(freezing), not the cause (interning).

My understanding is that another reason is avoidance of alias effects. It's easy to write code that when cut down to the essential, does this:
```
a = b = "My string"
a.gsub!(/My/, 'Your')
```
and expects `b` to still be "My string". Freezing makes sure this throws an error.

(This is not an argument for or againts freezing interpolated strings.)


----------------------------------------
Feature #17104: Do not freeze interpolated strings when using frozen-string-literal
https://bugs.ruby-lang.org/issues/17104#change-87013

* Author: bughit (bug hit)
* Status: Open
* 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/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

  parent reply	other threads:[~2020-08-11  6:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-05 20:06 [ruby-core:99485] [Ruby master Misc#17104] Why are interpolated string literals frozen? bughitgithub
2020-08-05 20:25 ` [ruby-core:99487] " merch-redmine
2020-08-05 20:58 ` [ruby-core:99488] " bughitgithub
2020-08-05 21:05 ` [ruby-core:99489] " merch-redmine
2020-08-05 21:10 ` [ruby-core:99490] " eregontp
2020-08-05 21:18 ` [ruby-core:99491] " bughitgithub
2020-08-05 21:26 ` [ruby-core:99492] [Ruby master Feature#17104] Do not freeze interpolated strings when using frozen-string-literal merch-redmine
2020-08-06  1:37 ` [ruby-core:99493] " daniel
2020-08-06  9:23 ` [ruby-core:99496] " jean.boussier
2020-08-06 10:12 ` [ruby-core:99497] " eregontp
2020-08-06 11:10 ` [ruby-core:99501] " jean.boussier
2020-08-10 18:51 ` [ruby-core:99546] " bughitgithub
2020-08-11  6:22 ` duerst [this message]
2020-08-11 15:57 ` [ruby-core:99560] " bughitgithub
2020-08-26  7:43 ` [ruby-core:99699] " akr
2020-08-31  8:50 ` [ruby-core:99793] " matz
2020-08-31 19:28 ` [ruby-core:99802] " eregontp
2020-09-01 15:39 ` [ruby-core:99817] " mame
2020-09-01 18:18 ` [ruby-core:99822] " eregontp
2020-09-02 14:15 ` [ruby-core:99840] " nobu
2020-09-03  0:29 ` [ruby-core:99858] " ko1
2020-09-03 14:26 ` [ruby-core:99877] " eregontp
2020-09-15 19:35 ` [ruby-core:100015] " eregontp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-87013.20200811062227.8741@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).