summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorÉtienne Barrié <[email protected]>2024-10-14 11:28:59 +0200
committerJean Boussier <[email protected]>2024-10-21 12:33:02 +0200
commit257f78fb671151f1db06dcd8e35cf4cc736f735e (patch)
treecf67eb44cc8134d82eac7d688b23fe33a9ba7910 /compile.c
parent75ef89ca16d2c94e845b80e8b97bfc811370a890 (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
Notes: Merged: https://github.com/ruby/ruby/pull/11893
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/compile.c b/compile.c
index 5bf496ed59..b89d97bdf8 100644
--- a/compile.c
+++ b/compile.c
@@ -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);
+ VALUE lit = get_string_value(node);
+ return rb_str_with_debug_created_info(lit, rb_iseq_path(iseq), (int)nd_line(node));
}
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) {
+ const rb_compile_option_t *option = ISEQ_COMPILE_DATA(iseq)->option;
+ if ((option->debug_frozen_string_literal || RTEST(ruby_debug)) &&
+ option->frozen_string_literal != ISEQ_FROZEN_STRING_LITERAL_DISABLED) {
+ lit = rb_str_with_debug_created_info(lit, rb_iseq_path(iseq), line);
+ }
+ switch (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");
}
+ RB_OBJ_WRITTEN(iseq, Qundef, lit);
}
break;
}