ruby/lib/ruby_vm/rjit
É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
..
.document RJIT: Clean up unnecessary documentation 2023-12-21 16:47:13 -08:00
assembler.rb RJIT: Convert opt_case_dispatch keys with #to_value 2023-12-21 17:47:36 -08:00
block.rb
branch_stub.rb
c_pointer.rb RJIT: Distinguish Pointer with Array 2023-12-22 11:24:04 -08:00
c_type.rb RJIT: Distinguish Pointer with Array 2023-12-22 11:24:04 -08:00
code_block.rb RJIT: Avoid retaining comments unless --rjit-dump-disasm 2023-12-19 00:05:19 -08:00
compiler.rb RJIT: Prefer STDERR over $stderr 2023-12-22 21:48:26 -08:00
context.rb RJIT: Fix a wrong comparison in set_local_type 2023-12-21 16:45:37 -08:00
entry_stub.rb RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
exit_compiler.rb RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
hooks.rb s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
insn_compiler.rb Implement chilled strings 2024-03-19 09:26:49 +01:00
invariants.rb YJIT: Compile exception handlers (#8171) 2023-08-08 16:06:22 -07:00
jit_state.rb RJIT: Add --rjit-verify-ctx option 2023-04-04 00:35:29 -07:00
stats.rb RJIT: Clean up unnecessary documentation 2023-12-21 16:47:13 -08:00
type.rb RJIT: Remove Type::CArray and limit use of Type::CString 2023-08-28 17:14:33 -04:00