Repository navigation
A class bound to a constant in its own body is not its own lexical parent - #421
Merged
Merged
Conversation
…rent
assignConstIn gives an unnamed class the qualified name of the constant
it is bound to, and the lexical parent of the scope it is bound in. In
class << o
CONST = self
end
the scope and the value are the same singleton class, and a singleton
class is unnamed — so it was recorded as its own lexical parent. Nothing
is nested in itself, and every later bare-constant read in that scope
then walked a ring:
class << o
x = CONST # 17 GB. ruby: instant
end
language/singleton_class_spec.rb allocated 71.7 GB, which is the largest
of the five reasons the rubyspec-ratchet lane kept dying, and the one
still killing it after the other four were fixed.
Two changes, because two things were wrong:
- assignConstIn does not record a lexical parent that would make the
class its own ancestor.
- nesting stops at a repeat. The lexical chain is shaped by the program
and cannot be assumed acyclic; ancestors has guarded itself this way
all along, and this is the same guard for the same reason. A ring
from any other route now costs a short walk rather than the machine.
before 71.7 GB
after 78 MB, and the spec reports pass=40 fail=9 error=4
Checked against ruby 3: the four shapes the spec reads the constant in,
the same shape one level in on a real class's singleton, a non-class
constant, a class bound outside its own body (which still takes its
lexical parent and qualified name), and a missing constant still raising.
This was referenced Aug 21, 2026
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.
assignConstIngives an unnamed class the qualified name of the constant it is bound to, and the lexical parent of the scope it is bound in. Inthe scope and the value are the same singleton class, and a singleton class is unnamed — so it was recorded as its own lexical parent. Nothing is nested in itself, and every later bare-constant read in that scope then walked a ring:
language/singleton_class_spec.rballocated 71.7 GB. It is the largest of the five reasonsrubyspec-ratchetkept dying, and the one still killing it after the other four were fixed (#415, #416, #417, #418; #412 is the watcher that found them).pass=40 fail=9 error=4Two changes, because two things were wrong
assignConstIndoes not record a lexical parent that would make the class its own ancestor.nestingstops at a repeat. The lexical chain is shaped by the program and cannot be assumed acyclic —ancestorshas guarded itself this way all along, and this is the same guard for the same reason. A ring arriving by any other route now costs a short walk rather than the machine.Fixing only the cause would have left the walk defenceless; fixing only the walk would have left the ring in the object graph.
Checked against ruby 3
The four shapes the spec reads the constant in; the same shape one level in, on a real class's singleton; a non-class constant; a class bound outside its own body, which still takes its lexical parent and qualified name (
M::Inner); and a missing constant still raisingNameError.Full
internal/vmsuite green.🤖 Generated with Claude Code