From: bughitgithub@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99560] [Ruby master Feature#17104] Do not freeze interpolated strings when using frozen-string-literal
Date: Tue, 11 Aug 2020 15:57:20 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-87020.20200811155720.8741@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17104.20200805200602.8741@ruby-lang.org
Issue #17104 has been updated by bughit (bug hit).
> another reason is avoidance of alias effects
What you've shown is not another reason for freezing.
`a = b = "My string"`
both a and b refer to the same string object regardless of interning/freezing
there's no expectation that mutating it via `a` will not affect `b`
the interning scenario is:
```rb
a = "My string"
b = "My string"
a.gsub!(/My/, 'Your')
```
here there's an appearance of 2 string objects but when they are interned, there's only one, so mutation can not be allowed. As I said, interning is the feature, and it requires freezing.
----------------------------------------
Feature #17104: Do not freeze interpolated strings when using frozen-string-literal
https://bugs.ruby-lang.org/issues/17104#change-87020
* 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/
next prev parent reply other threads:[~2020-08-11 15:57 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 ` [ruby-core:99551] " duerst
2020-08-11 15:57 ` bughitgithub [this message]
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-87020.20200811155720.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).