From 6deeec5d459ecff5ec4628523b14ac7379fd942e Mon Sep 17 00:00:00 2001 From: Jean byroot Boussier Date: Wed, 13 Nov 2024 15:20:00 +0100 Subject: Mark strings returned by Symbol#to_s as chilled (#12065) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use FL_USER0 for ELTS_SHARED This makes space in RString for two bits for chilled strings. * Mark strings returned by `Symbol#to_s` as chilled [Feature #20350] `STR_CHILLED` now spans on two user flags. If one bit is set it marks a chilled string literal, if it's the other it marks a `Symbol#to_s` chilled string. Since it's not possible, and doesn't make much sense to include debug info when `--debug-frozen-string-literal` is set, we can't include allocation source, but we can safely include the symbol name in the warning message, making it much easier to find the source of the issue. Co-Authored-By: Étienne Barrié --------- Co-authored-by: Étienne Barrié Co-authored-by: Jean Boussier --- error.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'error.c') diff --git a/error.c b/error.c index 3fc1d96d6c..384a56f5df 100644 --- a/error.c +++ b/error.c @@ -4016,7 +4016,7 @@ rb_error_frozen_object(VALUE frozen_obj) } void -rb_warn_unchilled(VALUE obj) +rb_warn_unchilled_literal(VALUE obj) { rb_warning_category_t category = RB_WARN_CATEGORY_DEPRECATED; if (!NIL_P(ruby_verbose) && rb_warning_category_enabled_p(category)) { @@ -4047,6 +4047,15 @@ rb_warn_unchilled(VALUE obj) } } +void +rb_warn_unchilled_symbol_to_s(VALUE obj) +{ + rb_category_warn( + RB_WARN_CATEGORY_DEPRECATED, + "warning: string returned by :%s.to_s will be frozen in the future", RSTRING_PTR(obj) + ); +} + #undef rb_check_frozen void rb_check_frozen(VALUE obj) -- cgit v1.2.3