Repository navigation
vm: Object.constants stops reporting the qualified index keys (1620 -> 317) - #946
Merged
Merged
Conversation
…> 317) #817 is titled "Object.constants is empty (MRI: 120)". Measured 2026-11-15 through cmd/oracle against MRI 4.0.7, it is the opposite, and the surplus has a shape the title does not mention: MRI before after total 120 1620 317 containing "::" 0 1303 0 core missing none none none 1303 of the 1620 were QUALIFIED names -- AASM::Error, ActionCable::Channel::Base, Acme::Client::Error::BadNonce. MRI has none, because a nested constant belongs to its enclosing module. ## The tree was already right; Object carried flat aliases beside it AASM.constants.include?(:Error) true AASM.constants any name with "::" false AASM.const_get(:Error) "AASM::Error" So this was double registration, not a broken namespace. ⭐ And one of those aliases is a name this interpreter's own API refuses: Object.send(:remove_const, :"AASM::Error") => NameError: wrong constant name AASM::Error Object.constants reported a key remove_const will not accept. ## ⛔ The fix is ONE site, not the 52 the count suggests `git grep -c 'vm.consts[qualified]'` gives 52 files, 53 occurrences, so "change the idiom" is the obvious move. Two readings stopped it, in opposite directions: 1. json.go:58-61 says the flat key exists "so a re-raised library error's exceptionObject lookup finds the very same class". 2. ⛔ That comment is STALE. exceptionObject -> errorClass (vm.go:252-266) walks the tree for a qualified name and never reads the flat key; its own comment says the walk is strict, segment by segment. The flat registration predates that walk -- the lines above errorClass describe exactly the fix that introduced it -- and the justification outlived its reason. So the comment refuted the first hypothesis and the code refuted the comment. ⛔ But the keys ARE read, by the bindings rather than by exceptionObject: vm.kafkaClass("Kafka::Producer") and three siblings in kafka alone, plus actioncable_bind.go:204, io.go:2323 and embed.go:133. They have become an index from qualified name to class. Removing the writes would break those, which is why the enumeration is the right place: the table keeps the index, and `constants` stops reporting it as constants. One predicate in publicConstNames, which both Module#constants and the no-argument Module.constants funnel through. ## Proved by mutation Removing the predicate: 1303 against the expected 0, on BOTH paths (Object.constants and Module.constants), with every other assertion in the test unchanged -- so the test isolates the filter, and it confirms that Module.constants really is a second path into the same helper. The test also asserts what a filter could break and a "zero qualified names" check alone would not notice: 32 core constants still present, the tree still reachable through its parent, and the bindings' own qualified lookups (Kafka::Producer, JSON::ParserError, Acme::Client::Error::BadNonce) still resolving. ## ⚠ What this does NOT close 317 against MRI's 120. The remainder is bound gem top-levels -- AASM, Acme, ActionCable, AbstractController -- present before any `require`, where MRI autoloads. That is a separate decision with a separate cost, and #817 should stay open for it rather than be closed on the half that moved. Refs #817, #941 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vm: Object.constants stops reporting the qualified index keys (1620 -> 317)
#817 is titled "Object.constants is empty (MRI: 120)". Measured 2026-11-15
through cmd/oracle against MRI 4.0.7, it is the opposite, and the surplus has a
shape the title does not mention:
total 120 1620 317
containing "::" 0 1303 0
core missing none none none
1303 of the 1620 were QUALIFIED names -- AASM::Error,
ActionCable::Channel::Base, Acme::Client::Error::BadNonce. MRI has none, because
a nested constant belongs to its enclosing module.
The tree was already right; Object carried flat aliases beside it
AASM.constants.include?(:Error) true
AASM.constants any name with "::" false
AASM.const_get(:Error) "AASM::Error"
So this was double registration, not a broken namespace.
⭐ And one of those aliases is a name this interpreter's own API refuses:
Object.send(:remove_const, :"AASM::Error")
=> NameError: wrong constant name AASM::Error
Object.constants reported a key remove_const will not accept.
⛔ The fix is ONE site, not the 52 the count suggests
git grep -c 'vm.consts[qualified]'gives 52 files, 53 occurrences, so "changethe idiom" is the obvious move. Two readings stopped it, in opposite directions:
exceptionObject lookup finds the very same class".
the tree for a qualified name and never reads the flat key; its own comment
says the walk is strict, segment by segment. The flat registration predates
that walk -- the lines above errorClass describe exactly the fix that
introduced it -- and the justification outlived its reason.
So the comment refuted the first hypothesis and the code refuted the comment.
⛔ But the keys ARE read, by the bindings rather than by exceptionObject:
vm.kafkaClass("Kafka::Producer") and three siblings in kafka alone, plus
actioncable_bind.go:204, io.go:2323 and embed.go:133. They have become an index
from qualified name to class. Removing the writes would break those, which is
why the enumeration is the right place: the table keeps the index, and
constantsstops reporting it as constants.One predicate in publicConstNames, which both Module#constants and the
no-argument Module.constants funnel through.
Proved by mutation
Removing the predicate: 1303 against the expected 0, on BOTH paths
(Object.constants and Module.constants), with every other assertion in the test
unchanged -- so the test isolates the filter, and it confirms that
Module.constants really is a second path into the same helper.
The test also asserts what a filter could break and a "zero qualified names"
check alone would not notice: 32 core constants still present, the tree still
reachable through its parent, and the bindings' own qualified lookups
(Kafka::Producer, JSON::ParserError, Acme::Client::Error::BadNonce) still
resolving.
⚠ What this does NOT close
317 against MRI's 120. The remainder is bound gem top-levels -- AASM, Acme,
ActionCable, AbstractController -- present before any
require, where MRIautoloads. That is a separate decision with a separate cost, and #817 should
stay open for it rather than be closed on the half that moved.
Refs #817, #941
Co-Authored-By: Claude Opus 5 noreply@anthropic.com