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 --- include/ruby/internal/abi.h | 2 +- include/ruby/internal/core/rarray.h | 4 ++-- include/ruby/internal/fl_type.h | 2 +- include/ruby/internal/intern/error.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include/ruby/internal') diff --git a/include/ruby/internal/abi.h b/include/ruby/internal/abi.h index e735a67564..e6d1fa7e8f 100644 --- a/include/ruby/internal/abi.h +++ b/include/ruby/internal/abi.h @@ -24,7 +24,7 @@ * In released versions of Ruby, this number is not defined since teeny * versions of Ruby should guarantee ABI compatibility. */ -#define RUBY_ABI_VERSION 0 +#define RUBY_ABI_VERSION 1 /* Windows does not support weak symbols so ruby_abi_version will not exist * in the shared library. */ diff --git a/include/ruby/internal/core/rarray.h b/include/ruby/internal/core/rarray.h index 90690fe794..73cc0f5dd9 100644 --- a/include/ruby/internal/core/rarray.h +++ b/include/ruby/internal/core/rarray.h @@ -80,6 +80,8 @@ * here is at least incomplete. */ enum ruby_rarray_flags { + /* RUBY_FL_USER0 is for ELTS_SHARED */ + /** * This flag has something to do with memory footprint. If the array is * "small" enough, ruby tries to be creative to abuse padding bits of @@ -99,8 +101,6 @@ enum ruby_rarray_flags { */ RARRAY_EMBED_FLAG = RUBY_FL_USER1, - /* RUBY_FL_USER2 is for ELTS_SHARED */ - /** * When an array employs embedded strategy (see ::RARRAY_EMBED_FLAG), these * bits are used to store the number of elements actually filled into diff --git a/include/ruby/internal/fl_type.h b/include/ruby/internal/fl_type.h index 2a8bdccd46..f80f65ef8f 100644 --- a/include/ruby/internal/fl_type.h +++ b/include/ruby/internal/fl_type.h @@ -370,7 +370,7 @@ ruby_fl_type { * 3rd parties. It must be an implementation detail that they should never * know. Might better be hidden. */ - RUBY_ELTS_SHARED = RUBY_FL_USER2, + RUBY_ELTS_SHARED = RUBY_FL_USER0, /** * This flag has something to do with an object's class. There are kind of diff --git a/include/ruby/internal/intern/error.h b/include/ruby/internal/intern/error.h index b1e2c130b9..1fd9ec2f51 100644 --- a/include/ruby/internal/intern/error.h +++ b/include/ruby/internal/intern/error.h @@ -258,7 +258,7 @@ rb_check_frozen_inline(VALUE obj) /* ref: internal CHILLED_STRING_P() This is an implementation detail subject to change. */ - if (RB_UNLIKELY(RB_TYPE_P(obj, T_STRING) && FL_TEST_RAW(obj, RUBY_FL_USER3))) { + if (RB_UNLIKELY(RB_TYPE_P(obj, T_STRING) && FL_TEST_RAW(obj, RUBY_FL_USER2 | RUBY_FL_USER3))) { // STR_CHILLED rb_str_modify(obj); } } -- cgit v1.2.3