diff options
author | Kevin Newton <kddnewton@gmail.com> | 2022-03-31 11:04:25 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2022-04-01 14:48:22 -0400 |
commit | 6068da8937d7e4358943f95e7450dae7179a7763 (patch) | |
tree | 68ad7d95ec12f1dec4b1b745725c9579ab2f10ec /variable.c | |
parent | 20c190f95a28dd4e57cb96f939ff314dfb88b1f4 (diff) |
Finer-grained constant cache invalidation (take 2)
This commit reintroduces finer-grained constant cache invalidation.
After 8008fb7 got merged, it was causing issues on token-threaded
builds (such as on Windows).
The issue was that when you're iterating through instruction sequences
and using the translator functions to get back the instruction structs,
you're either using `rb_vm_insn_null_translator` or
`rb_vm_insn_addr2insn2` depending if it's a direct-threading build.
`rb_vm_insn_addr2insn2` does some normalization to always return to
you the non-trace version of whatever instruction you're looking at.
`rb_vm_insn_null_translator` does not do that normalization.
This means that when you're looping through the instructions if you're
trying to do an opcode comparison, it can change depending on the type
of threading that you're using. This can be very confusing. So, this
commit creates a new translator function
`rb_vm_insn_normalizing_translator` to always return the non-trace
version so that opcode comparisons don't have to worry about different
configurations.
[Feature #18589]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5716
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/variable.c b/variable.c index 1dd867cc0c..577c2b855f 100644 --- a/variable.c +++ b/variable.c @@ -2848,7 +2848,7 @@ rb_const_remove(VALUE mod, ID id) undefined_constant(mod, ID2SYM(id)); } - rb_clear_constant_cache(); + rb_clear_constant_cache_for_id(id); val = ce->value; if (val == Qundef) { @@ -3132,7 +3132,7 @@ rb_const_set(VALUE klass, ID id, VALUE val) struct rb_id_table *tbl = RCLASS_CONST_TBL(klass); if (!tbl) { RCLASS_CONST_TBL(klass) = tbl = rb_id_table_create(0); - rb_clear_constant_cache(); + rb_clear_constant_cache_for_id(id); ce = ZALLOC(rb_const_entry_t); rb_id_table_insert(tbl, id, (VALUE)ce); setup_const_entry(ce, klass, val, CONST_PUBLIC); @@ -3210,7 +3210,7 @@ const_tbl_update(struct autoload_const *ac) struct autoload_data_i *ele = current_autoload_data(klass, id, &ac); if (ele) { - rb_clear_constant_cache(); + rb_clear_constant_cache_for_id(id); ac->value = val; /* autoload_i is non-WB-protected */ ac->file = rb_source_location(&ac->line); @@ -3238,11 +3238,11 @@ const_tbl_update(struct autoload_const *ac) "previous definition of %"PRIsVALUE" was here", name); } } - rb_clear_constant_cache(); + rb_clear_constant_cache_for_id(id); setup_const_entry(ce, klass, val, visibility); } else { - rb_clear_constant_cache(); + rb_clear_constant_cache_for_id(id); ce = ZALLOC(rb_const_entry_t); rb_id_table_insert(tbl, id, (VALUE)ce); @@ -3297,10 +3297,6 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv, VALUE val = argv[i]; id = rb_check_id(&val); if (!id) { - if (i > 0) { - rb_clear_constant_cache(); - } - undefined_constant(mod, val); } if ((ce = rb_const_lookup(mod, id))) { @@ -3315,15 +3311,12 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv, ac->flag |= flag; } } + rb_clear_constant_cache_for_id(id); } else { - if (i > 0) { - rb_clear_constant_cache(); - } undefined_constant(mod, ID2SYM(id)); } } - rb_clear_constant_cache(); } void |