diff options
author | Étienne Barrié <[email protected]> | 2024-10-14 11:28:59 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-10-21 12:33:02 +0200 |
commit | 257f78fb671151f1db06dcd8e35cf4cc736f735e () | |
tree | cf67eb44cc8134d82eac7d688b23fe33a9ba7910 /compile.c | |
parent | 75ef89ca16d2c94e845b80e8b97bfc811370a890 (diff) |
Show where mutated chilled strings were allocated
[Feature #20205] The warning now suggests running with --debug-frozen-string-literal: ``` test.rb:3: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information) ``` When using --debug-frozen-string-literal, the location where the string was created is shown: ``` test.rb:3: warning: literal string will be frozen in the future test.rb:1: info: the string was created here ``` When resurrecting strings and debug mode is not enabled, the overhead is a simple FL_TEST_RAW. When mutating chilled strings and deprecation warnings are not enabled, the overhead is a simple warning category enabled check. Co-authored-by: Jean Boussier <[email protected]> Co-authored-by: Nobuyoshi Nakada <[email protected]> Co-authored-by: Jean Boussier <[email protected]>
Notes: Merged: https://.com/ruby/ruby/pull/11893
-rw-r--r-- | compile.c | 23 |
1 files changed, 9 insertions, 14 deletions
@@ -4873,10 +4873,8 @@ static_literal_value(const NODE *node, rb_iseq_t *iseq) case NODE_FILE: case NODE_STR: if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) { - VALUE debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX((int)nd_line(node))); - VALUE lit = rb_str_dup(get_string_value(node)); - rb_ivar_set(lit, id_debug_created_info, rb_ary_freeze(debug_info)); - return rb_str_freeze(lit); } else { return get_string_value(node); @@ -10927,28 +10925,25 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no debugp_param("nd_lit", get_string_value(node)); if (!popped) { VALUE lit = get_string_value(node); - switch (ISEQ_COMPILE_DATA(iseq)->option->frozen_string_literal) { case ISEQ_FROZEN_STRING_LITERAL_UNSET: ADD_INSN1(ret, node, putchilledstring, lit); - RB_OBJ_WRITTEN(iseq, Qundef, lit); break; case ISEQ_FROZEN_STRING_LITERAL_DISABLED: ADD_INSN1(ret, node, putstring, lit); - RB_OBJ_WRITTEN(iseq, Qundef, lit); break; case ISEQ_FROZEN_STRING_LITERAL_ENABLED: - if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) { - VALUE debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX(line)); - lit = rb_str_dup(lit); - rb_ivar_set(lit, id_debug_created_info, rb_ary_freeze(debug_info)); - lit = rb_str_freeze(lit); - } ADD_INSN1(ret, node, putobject, lit); - RB_OBJ_WRITTEN(iseq, Qundef, lit); break; default: rb_bug("invalid frozen_string_literal"); } } break; } |