Issue #16153 has been updated by duerst (Martin D=FCrst).


`freeze(eventual: false)` gives the impression that it will never be frozen=
, but the proposal is to have this mean that it is frozen immediately.

So it would be better to say `freeze(immediately: true)` for what happens n=
ow, and `frozen(immediately: false)` for the new behavior.

Please also note the use of the `ly` ending, which makes it more grammatica=
l English (but can be decided on independently).

----------------------------------------
Feature #16153: eventually_frozen flag to gradually phase-in frozen strings
https://bugs.ruby-lang.org/issues/16153#change-81606

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------
Freezing objects can give us a nice performance boost, but freezing previou=
sly non-frozen objects is a backward-incompatible change which is hard to h=
andle because the place where the object is mutated can be far from where i=
t was frozen, and tests might not cover the cases of frozen input vs non-fr=
ozen input.

I propose adding a flag which gives us a migration path for freezing object=
s. For purposes of discussion I will call this flag "eventually_frozen". It=
 would act as a pseudo-frozen flag where mutating the object would result i=
n a warning instead of an error. It would also change the return value of `=
Object#frozen?` so code like `obj =3D obj.dup if obj.frozen?` would work as=
 expected to remove the warning. Note that eventually_frozen strings cannot=
 be deduplicated, as they are in reality mutable.

This way it would be possible for Symbol#to_s (and many others) to return a=
n eventually_frozen string in 2.7 which gives apps and gems time to migrate=
, before finally becoming a frozen deduplicated string in 3.0. This might e=
ven open up a migration path for eventually using `frozen_string_literal:tr=
ue` as default. For example if it was possible to add `frozen_string_litera=
l:eventual` to all files in a project (or as a global switch), we could run=
 that in production to discover where to fix things, and then change it to =
`frozen_string_literal:true` for a bug-free performance boost.

Proposed changes:
* Object#freeze(eventual:false)
   * if `eventual` keyword is false, set frozen=3Dtrue and eventually_froze=
n=3Dfalse
   * if `eventual` keyword is true, set eventually_frozen=3Dtrue UNLESS fro=
zen flag is already true
* String#+@
   * if eventually_frozen is true, create a duplicate string with eventuall=
y_frozen=3Dfalse
* Object#frozen?(eventual:true)
   * return true if `eventual` keyword and eventually_frozen flag are both =
true
* rb_check_frozen
   * output warning if eventually_frozen flag is true




-- =

https://bugs.ruby-lang.org/

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