diff options
author | eileencodes <eileencodes@gmail.com> | 2023-02-07 15:46:50 -0500 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2023-06-01 08:52:48 -0700 |
commit | 77d1b082470790c17c24a2f406b4fec5d522636b (patch) | |
tree | 828c633fb2a2566dd53628df4e9d63501257e4a5 /yjit/src/cruby_bindings.inc.rs | |
parent | b7ee51e81dd63990ec27daaa151864214cbf85d2 (diff) | |
download | ruby-77d1b082470790c17c24a2f406b4fec5d522636b.tar.gz |
Fix cvar caching when class is cloned
The class variable cache that was added in
https://github.com/ruby/ruby/pull/4544 changed the behavior of class
variables on cloned classes. As reported when a class is cloned AND a
class variable was set, and the class variable was read from the
original class, reading a class variable from the cloned class would
return the value from the original class.
This was happening because the IC (inline cache) is stored on the ISEQ
which is shared between the original and cloned class, therefore they
share the cache too.
To fix this we are now storing the `cref` in the cache so that we can
check if it's equal to the current `cref`. If it's different we don't
want to read from the cache. If it's the same we do. Cloned classes
don't share the same cref with their original class.
This will need to be backported to 3.1 in addition to 3.2 since the bug
exists in both versions.
We also added a marking function which was missing.
Fixes [Bug #19379]
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Diffstat (limited to 'yjit/src/cruby_bindings.inc.rs')
-rw-r--r-- | yjit/src/cruby_bindings.inc.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index 048da7b0ff..16bb6e1feb 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -806,6 +806,7 @@ pub type rb_shape_t = rb_shape; pub struct rb_cvar_class_tbl_entry { pub index: u32, pub global_cvar_state: rb_serial_t, + pub cref: *const rb_cref_t, pub class_value: VALUE, } pub const VM_CALL_ARGS_SPLAT_bit: vm_call_flag_bits = 0; |