ruby/ext/objspace
Étienne Barrié 12be40ae6b Implement chilled strings
[Feature #20205]

As a path toward enabling frozen string literals by default in the future,
this commit introduce "chilled strings". From a user perspective chilled
strings pretend to be frozen, but on the first attempt to mutate them,
they lose their frozen status and emit a warning rather than to raise a
`FrozenError`.

Implementation wise, `rb_compile_option_struct.frozen_string_literal` is
no longer a boolean but a tri-state of `enabled/disabled/unset`.

When code is compiled with frozen string literals neither explictly enabled
or disabled, string literals are compiled with a new `putchilledstring`
instruction. This instruction is identical to `putstring` except it marks
the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags.

Chilled strings have the `FL_FREEZE` flag as to minimize the need to check
for chilled strings across the codebase, and to improve compatibility with
C extensions.

Notes:
  - `String#freeze`: clears the chilled flag.
  - `String#-@`: acts as if the string was mutable.
  - `String#+@`: acts as if the string was mutable.
  - `String#clone`: copies the chilled flag.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-19 09:26:49 +01:00
..
lib [DOC] Improve ObjectSpace#dump_XXX method docs 2023-02-19 22:32:52 +02:00
depend Mark asan fake stacks during machine stack marking 2024-01-19 09:55:12 +11:00
extconf.rb
object_tracing.c Merge gc.h and internal/gc.h 2023-02-09 10:32:29 -05:00
objspace.c [DOC] Fix invalid documentation for reachable_objects_from (#10172) 2024-03-05 01:35:51 +09:00
objspace.h
objspace_dump.c Implement chilled strings 2024-03-19 09:26:49 +01:00