From 40f090f4339820d19da8ecdf81a981489c22eb57 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 2 Jun 2023 14:25:19 -0400 Subject: Revert "Revert "Fix cvar caching when class is cloned"" This reverts commit 10621f7cb9a0c70e568f89cce47a02e878af6778. This was reverted because the gc integrity build started failing. We have figured out a fix so I'm reopening the PR. Original commit message: Fix cvar caching when class is cloned The class variable cache that was added in ruby#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 --- variable.c | 1 + 1 file changed, 1 insertion(+) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 64cb07407c..0491562d22 100644 --- a/variable.c +++ b/variable.c @@ -3693,6 +3693,7 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) ent = ALLOC(struct rb_cvar_class_tbl_entry); ent->class_value = target; ent->global_cvar_state = GET_GLOBAL_CVAR_STATE(); + ent->cref = 0; rb_id_table_insert(rb_cvc_tbl, id, (VALUE)ent); RB_DEBUG_COUNTER_INC(cvar_inline_miss); } -- cgit v1.2.3