Repository navigation
vm.c: do not cache what const_missing gives for a lexical read - #7835
Conversation
OP_GETCONST cached the value of a const_missing hook as if it were the constant, so later reads at that place gave the same value without calling the hook, until the entry was dropped. CRuby calls the hook for each read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X4cowTc1oGMNQfUma7zNdD
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
OP_GETCONSTcaches the value a lexical constant read gives, and it cached the value of aconst_missinghook as if it were the constant. Later reads at the same place then got that value without calling the hook again:The value stays until the entry is dropped, by a collision or by setting any constant, and the hook is skipped for each read it serves. CRuby calls
const_missingfor each read.Fix
const_get()clears*cachepwhen it callsconst_missing, the way a deprecated constant already keeps itself out of the cache (3a118cb). A read the hook answers is then not cached. A read that finds the constant is cached as before.This also closes the other way a stale value could be cached: Ruby code run during the lookup setting the constant before
OP_GETCONSTstores what it found. Of the code a lookup can run, an autoload reads the constant again after loading, a deprecation warning is not cached, andconst_missingis now not cached either.Tests
test/t/module.rb: a lexical read callsconst_missingeach time, and reads the constant once it is set.🤖 Generated with Claude Code
Summary by CodeRabbit
const_missingare no longer cached, so each read callsconst_missingagain. Once the constant is defined, reads return its stored value.