ruby/vm_opts.h
É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

68 lines
1.7 KiB
C

#ifndef RUBY_VM_OPTS_H/*-*-c-*-*/
#define RUBY_VM_OPTS_H
/**********************************************************************
vm_opts.h - VM optimize option
$Author$
Copyright (C) 2004-2007 Koichi Sasada
**********************************************************************/
/* Compile options.
* You can change these options at runtime by VM::CompileOption.
* Following definitions are default values.
*/
#define OPT_TAILCALL_OPTIMIZATION 0
#define OPT_PEEPHOLE_OPTIMIZATION 1
#define OPT_SPECIALISED_INSTRUCTION 1
#define OPT_INLINE_CONST_CACHE 1
#define OPT_FROZEN_STRING_LITERAL -1
#define OPT_DEBUG_FROZEN_STRING_LITERAL 0
/* Build Options.
* You can't change these options at runtime.
*/
/* C compiler dependent */
/*
* 0: direct (using labeled goto using GCC special)
* 1: token (switch/case)
* 2: call (function call for each insn dispatch)
*/
#ifndef OPT_THREADED_CODE
#define OPT_THREADED_CODE 0
#endif
#define OPT_DIRECT_THREADED_CODE (OPT_THREADED_CODE == 0)
#define OPT_TOKEN_THREADED_CODE (OPT_THREADED_CODE == 1)
#define OPT_CALL_THREADED_CODE (OPT_THREADED_CODE == 2)
/* VM running option */
#define OPT_CHECKED_RUN 1
#define OPT_INLINE_METHOD_CACHE 1
#define OPT_GLOBAL_METHOD_CACHE 1
#ifndef OPT_IC_FOR_IVAR
#define OPT_IC_FOR_IVAR 1
#endif
/* architecture independent, affects generated code */
#define OPT_OPERANDS_UNIFICATION 1
#define OPT_INSTRUCTIONS_UNIFICATION 0
#define OPT_UNIFY_ALL_COMBINATION 0
/* misc */
#ifndef OPT_SUPPORT_JOKE
#define OPT_SUPPORT_JOKE 0
#endif
#ifndef VM_COLLECT_USAGE_DETAILS
#define VM_COLLECT_USAGE_DETAILS 0
#endif
#endif /* RUBY_VM_OPTS_H */