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 (patch) | |
tree | cf67eb44cc8134d82eac7d688b23fe33a9ba7910 /prism_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
Notes:
Merged: https://github.com/ruby/ruby/pull/11893
Diffstat (limited to 'prism_compile.c')
-rw-r--r-- | prism_compile.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/prism_compile.c b/prism_compile.c index d5b764cd89..46ffccaaa1 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -319,10 +319,7 @@ parse_static_literal_string(rb_iseq_t *iseq, const pm_scope_node_t *scope_node, if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) { int line_number = pm_node_line_number(scope_node->parser, node); - VALUE debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX(line_number)); - value = rb_str_dup(value); - rb_ivar_set(value, id_debug_created_info, rb_ary_freeze(debug_info)); - rb_str_freeze(value); + value = rb_str_with_debug_created_info(value, rb_iseq_path(iseq), line_number); } return value; @@ -726,9 +723,7 @@ static VALUE pm_static_literal_string(rb_iseq_t *iseq, VALUE string, int line_number) { 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_number)); - rb_ivar_set(string, id_debug_created_info, rb_ary_freeze(debug_info)); - return rb_str_freeze(string); + return rb_str_with_debug_created_info(string, rb_iseq_path(iseq), line_number); } else { return rb_fstring(string); |