Repository navigation
Give every box-owned class its own internal namespace - #270
Conversation
There was a problem hiding this comment.
Reviewed exact head 29ebd8e99446e07b70331436839e79d0049dba62 against fetched main a63e47c366505074dab80db9285b8a7b3b6d051b, including full changed files, constant resolution, class creation/reopening and lexical-scope registration. No existing reviews/threads or tracked AGENTS.md/CLAUDE.md were found. No actionable finding established. Giving the first box-owned class an independent identity closes the shared-display-name shortcut; the regression exercises aliases, reopening and nested mixins as well as simple reads.
Independent Darwin arm64 checks: corpus 1112 (14 output lines) and existing 647, 853 and 961 match stdout, stderr and exit status from clean Ruby 4.0.10 in evaluator and VM. Duplicate/dead-definition and diff whitespace gates pass. Reused an existing successful ordinary O2 build only after all 2,430 tracked regular files matched exact head byte for byte. Build log uses compiler checkout 9dec2ff6; copied binary SHA-256 c9f3cf6f0e8b3b3af6031cec2f0036070dac0d93fbfe03bd25dd302625dcfa3a.
No fresh main integration build, full corpus, upstream whole-file or affected-platform/resource acceptance was run here. The author's selected upstream results remain selected results. No merge: draft state, recorded global holds and incomplete hosted coverage prevent it. Queued jobs are not passes. COMMENT because the authenticated account owns the PR.
284km
left a comment
There was a problem hiding this comment.
Reviewed cd8e47f. The change reads right; one thing blocks the merge.
- In a box, every new class or module now gets its own internal identity (
AnonClass_/AnonModule_, shown by its name), not only when another box already has the name, so same-named classes in separate boxes are independent.named_class_of_alfollows the constant binding for a qualified name inside a box, so aliases, reopening and the VM's include path reach the box-owned class. Outside boxes, only a removed constant starts a fresh identity, as on main.register_class_lexreplaces the hand-saved lexical scope, which fixesTimeout::State::GET_TIMEwhen a box requires Timeout. - Ran on the author's build at this head (clean tree): corpus 1112 and the expanded 1057 are identical to ruby 4.0.10 on the evaluator and
MERE_RUBY_VM=1, both without and withRUBY_BOX=1. The only difference is the program name in the experimental warning,ruby:vsmere-ruby:, which is expected.
Minor (stale base): please merge current main and re-run. The branch is based on fd5f54b. Since then, #262, #285 and #288 have changed the same class-definition path. #288 in particular changed classes defined inside a singleton class: corpus 1061 and 1062, is_sng_cls, and the GC owner of nested (sng:...) keys. git merge-tree is clean, but this PR's "every box-owned class is anonymous internally" and #288's nested-singleton naming have not been run together. Please merge main, rebuild, and post corpus --both and MERE_RUBY_VM=1 --both (including 1057, 1061, 1062 and 1112, with and without RUBY_BOX=1 for 1112), the gates, and the test_box selections on the merged tree.
No mere-pr-review-watch inline comments.
284km
left a comment
There was a problem hiding this comment.
Follow-up review of exact head cd8e47f8a8518f4ebaca1328b7f5057c50025af4, compared with fetched current main f4303e1497a9b532d3681c5e827662bff17bc06a. Read the implementation, related constant/class registration and VM lookup paths, regression programs, validation record, existing reviews and discussions. Neither fetched main nor head contains tracked AGENTS.md/CLAUDE.md instructions. A separate temporary clone was used.
Two new Major / P2 findings are attached: absolute scoped constant reads lose their root anchor, and VM scoped mixin lookup loses a user-defined const_missing hook when Box mode gives the first namespace an internal identity. Both work on freshly built current main and fail on freshly built head, with hash indexing on/off. These are actual runtime regressions, independent of sandbox restrictions. The existing review's request for current-main integration validation remains outstanding; it is not duplicated as a new finding.
The independent identities and nesting registration do fix the covered isolation/Timeout behavior. Independent Darwin arm64 validation:
- Corpus 1112, 1057, 647, 853, 961, 962, 736, 738, 760, 455 and 579 under their normal invocation environment: 44/44 exact stdout/stderr/status matches against clean Ruby 4.0.10, across evaluator/VM and hash indexing on/off. Additional Box nesting/inheritance/alias/reopening/exception-restoration/Timeout probes match stdout and status; the experimental-warning text differs. The new findings require additional Box-mode/shadowing/hook coverage.
- Unchanged upstream ruby/test_box.rb selections add_constants_in_box, eval_with_constants, eval_with_classes and very_basic_method_calls_and_constants: 4 tests / 53 assertions, zero failures/errors/skips, exit 0 on reference and both head engines, seed 1 and tight GC. These are selected tests, not whole-file acceptance.
- Eight source gates pass (gc_roots, dup_defs, dead_defs, meth_writes, name_len, ns_names, rx_caps, name_spec), diff whitespace passes, generated-C bracket depth 155/1024 passes.
The initial corpus/upstream checks reused ordinary O2 binary e97a2cc29797e4c19c2e0b022896cc621146cdfbb392bc760506d7881c8c739f after all 2,594 tracked regular files matched head byte-for-byte and all three imported mgz modules matched pin 661a01d8. Then head and current main were independently rebuilt with ordinary O2, clean pinned compiler 9dec2ff687a08433247dbdb7729bc19c8522e538 and that mgz pin. Fresh head SHA-256: 1632df56593ddbecd553471f4e32de29356600d7877642b7c4e08eeaddf7c4a8; fresh main: 668c585a3a38eef3ebcf833249d2dfa06d7266faf317981130be4e4ad0f162b6. All reported finding comparisons use these fresh builds. Corpus 1112 and 1057 were also repeated on fresh head: 8/8 exact stdout/stderr/status matches across both engines and hash-index settings. The first /usr/bin/time -l attempt was restricted by sandbox sysctl access; the automatically approved rerun completed normally. No sandbox error is counted as a program failure.
No full corpus sweep, complete original upstream-file inventory, Rails suite, Linux execution, tested current-main integration or platform/resource merge acceptance is claimed here. Hosted checks at posting: running — Additional upstream gem tests / macos-26, build-linux; queued — Delegation and URI tests / macos-26, Upstream gem tests / macos-26, Upstream Rake tests / macos-26, build-macos, unittest-reference; failed — none currently exposed. Downstream acceptance remains incomplete; queued jobs are not passes. Latest main CI run 45733853136 remains pending with zero exposed jobs and clears no historical failure. Recorded hold_all_merges / new_failure_review_required conditions remain active. Already-reviewed ready PRs were reconsidered: #254 and #272 retain actual failed checks; #313 has running build coverage; #290 still has incomplete hosted coverage. merelang/mere has no open PRs. No merge.
COMMENT because the authenticated account owns this PR; the two P2 regressions require correction before merging.
| // Every new box-owned class has its own internal namespace, including | ||
| // the first class with a display name. A removed constant also starts | ||
| // a fresh identity outside boxes, preserving references to the old class. | ||
| if (if already then false else true) && (removed9 || vec_get box_st 0 == 1) then |
There was a problem hiding this comment.
[Major / P2] Preserve the absolute root when the first Box namespace becomes internal
With RUBY_BOX=1, this new unconditional internal identity removes the direct display-name key that absolute scoped reads currently rely on. For example, run this in the main box or inside Ruby::Box.new.eval:
module R; X = :top; end
module S
module R; X = :inner; end
p [R::X, ::R::X]
endClean Ruby 4.0.10 and fresh current main print [:inner, :top]; this head prints [:inner, :inner] on both engines, with hash indexing on/off. eval_e's absolute EConst fallback strips :: and retries through lexical lookup when R::X is no longer a direct key. Thus an explicit root reference silently reads the wrong namespace. Resolve absolute paths through the root's actual internal bindings while retaining the root anchor, and add this shadowing case to the Box regression.
There was a problem hiding this comment.
Fixed in 084596d. Absolute paths now resolve the actual root receiver and follow that namespace instead of falling back through lexical lookup. Relative reads first walk the actual lexical identities, including autoloads. Corpus 1112 runs the shadowing repro in the main box and two independent boxes. The additional frame-label Minor is fixed too: class/module body labels use the stored constant-assigned name without invoking an overridden Module#name; name, inspect and missing-constant messages are covered. All 44 rows match Ruby 4.0.10 on both engines, including parent RUBY_BOX=1 and hash indexing ON/OFF. Both final full sweeps pass 965/965; gates, record hygiene and the original Box selection pass. Actual fixed-seed tight-GC RSS is in the updated description and committed record.
| // the first class with a display name. A removed constant also starts | ||
| // a fresh identity outside boxes, preserving references to the old class. | ||
| if (if already then false else true) && (removed9 || vec_get box_st 0 == 1) then | ||
| (let internal = fresh_anon (if is_module then "AnonModule_" else "AnonClass_") in |
There was a problem hiding this comment.
[Major / P2] Retain const_missing dispatch in VM scoped mixin lookup
Giving the first namespace an internal identity also regresses the compiled scoped-constant path. Run this as a script with RUBY_BOX=1 MERE_RUBY_VM=1:
module HookedPath
Real = Module.new { def value = :ok }
Namespace = Module.new
Namespace.const_set(:Feature, Real)
def self.const_missing(name)
($calls ||= []) << name
name == :Alias ? Namespace : super
end
end
class Receiver
include HookedPath::Alias::Feature
end
p [Receiver.new.value, $calls]Ruby 4.0.10 and freshly built current main print [:ok, [:Alias]]. Fresh head's evaluator also succeeds, but its VM raises NameError: uninitialized constant HookedPath::Alias and exits 1, with hash indexing on/off. The existing corpus 736 also reproduces this when the parent process enables Box mode. Resolve missing scope segments against the actual namespace receiver and invoke its const_missing once, as the evaluator mixin path does; add a compiled Box-mode control alongside the direct-binding include coverage.
There was a problem hiding this comment.
Fixed in 084596d. The VM mixin resolver now follows the actual namespace values and invokes const_missing for missing segments, retaining the returned receiver and calling the hook once. The expanded Box regression covers the reported include, hooks returning nil, inheritance and anonymous runtime superclasses. Existing corpus 736 also matches Ruby with parent RUBY_BOX=1 on both engines and hash index ON/OFF. Both fresh final full sweeps pass 965/965, all source gates and record hygiene pass, and the unchanged original test_box.rb selections pass 4 tests / 53 assertions on both candidate engines (matching main: 4 / 8, one error). The implementation and completed record were pushed together.
284km
left a comment
There was a problem hiding this comment.
Re-checked 513a0a6 (main merged in). The merge with current main addresses my stale-base request, but neither of the bot's two Major/P2 findings (02:20, main.mere 67016/67017) is fixed. Both still reproduce on the author's build at this head (clean tree, binary newer than every .mere file), with RUBY_BOX=1:
- Absolute root:
module R; X = :top; end; module S; module R; X = :inner; end; p [R::X, ::R::X]; endprints[:inner, :inner]on the evaluator and the VM (ruby 4.0.10:[:inner, :top]). - VM scoped mixin lookup: the
HookedPath::Alias::Featureinclude (const_missing returning a namespace) raisesNameError: uninitialized constant HookedPath::Aliason the VM (ruby and this head's evaluator:[:ok, [:Alias]]).
New, from the same run (Minor): that NameError's backtrace shows the internal identity, in '<class:AnonClass_4>', where ruby shows <class:Receiver>. Making every box-owned class internally anonymous leaks the internal name into backtrace labels. Please check the class-body label (and Module#name / inspect / error messages) for box-owned classes, and add one to corpus 1112.
Please fix all three, add the two bot repros and the label to corpus 1112, and re-post corpus --both / MERE_RUBY_VM=1 --both (with and without RUBY_BOX=1 for 1112), the gates and the test_box selections.
284km
left a comment
There was a problem hiding this comment.
Follow-up review of exact head 084596da9a846915cefe508f94fb3daeb307d9e4 against fetched current main 121c3d4f3848ada5be8ee8e0f676ca9f4951f7aa. Read the changes, related class/constant/frame code, expanded regression and validation record, existing reviews and replies. Neither fetched tree contains tracked AGENTS.md/CLAUDE.md instructions. Work used a separate temporary clone.
The previous absolute-root and VM scoped-mixin repros now pass, and the reported class/module frame labels use public names, including when Module#name is overridden. The expanded regression usefully covers the actual namespace receivers. Two new findings are attached: Major / P2 — a class created by a method's string eval loses the enclosing lexical constant; Minor / P3 — bare missing-constant diagnostics expose internal identities. Both are independently reproduced on fresh O2 head and work correctly on fresh current main, evaluator/VM and hash indexing on/off. Existing string module_eval/class_eval deficiencies are excluded from the new finding.
Independent Darwin arm64 validation:
- 52/52 focused corpus stdout/stderr/status comparisons against clean Ruby 4.0.10: 1112, 1057, 1061, 1062, 647, 853, 961, 962, 736, 738 and 760, both engines and hash-index settings; 1112/736 also with parent RUBY_BOX=1. Only the exact interpreter prefix of the Box experimental warning is canonicalized.
- Unchanged original ruby/test_box.rb selections add_constants_in_box, eval_with_constants, eval_with_classes and very_basic_method_calls_and_constants: reference and both head engines pass 4 tests / 53 assertions, zero failures/errors/skips, tight GC and seed 1. Selected tests only.
- Eight source gates, diff whitespace, generated-C depth 155/1024, and hygiene for the changed loop record pass.
Those initial checks reused the recorded final O2 binary b82c81d6f3153dc78edc2ab1c2be6b11ec3f990b2a143bf31a2047066ecb1bdf after all 2,640 tracked regular files and all three imported mgz modules matched the pinned sources byte-for-byte. Then head and current main were freshly built with clean pinned compiler 9dec2ff687a08433247dbdb7729bc19c8522e538, mgz 661a01d8bb68f5acd68e3192bd47f081d179c436. Fresh head SHA-256: 677947f989dcc14e32dbf4b011a3db9a20a9e6e1827f395a720bab317aa39f5d; main: 7482c1ec2c3d432702dfe74fb566d718da1f366641381f6fce79d323bead8468. Finding comparisons use these fresh builds. Fresh head also repeats all eight Box-mode 1112/736 controls successfully. No full corpus sweep, complete upstream-file acceptance, Linux/resource comparison or tested prospective main integration is claimed.
Hosted checks at final inspection: running — Small upstream gem tests / macos-26, build-linux; queued — runtime-load-path (macos-15), Additional upstream gem tests / macos-26, Delegation and URI tests / macos-26, Upstream gem tests / macos-26, build-macos, unittest-reference; failed — none exposed. Downstream acceptance remains incomplete; queues are not passes. Latest main CI run 45801978207 exposes zero jobs and does not clear historical failures. Recorded hold_all_merges/new_failure_review_required remain active. Already-reviewed open PRs were reconsidered: #254, #317 and #326 have failed checks; #242 has running coverage; #268 has no exposed checks. merelang/mere has no open PRs. No merge.
COMMENT because the authenticated account owns the PR. The new P2 needs correction before merging.
| let _ = set_lex internal in | ||
| let r = try_or (fn (u: unit) -> (let _ = cls_home_note env in register_class world internal body)) (FRaise VNil) in | ||
| let _ = set_lex saved_lex in | ||
| let r = try_or (fn (u: unit) -> (let _ = cls_home_note env in register_class_lex world internal body)) (FRaise VNil) in |
There was a problem hiding this comment.
[Major / P2] Preserve the caller's lexical nesting for classes created by eval
With RUBY_BOX=1, a fresh class created by a method's string eval now takes this internal-identity path, but register_class_lex only pushes onto cur_nest(); it does not restore the caller env's __nest as the ordinary class-registration path does. For example:
module LexOuter
X = :outer
def self.make
eval('class Inner; p X; end')
end
end
LexOuter.makeClean Ruby 4.0.10 and current main print :outer. This head raises NameError: uninitialized constant AnonClass_2::X on both engines with hash indexing on/off. Preserve the actual enclosing lexical identities when entering the new class body, including eval's saved nesting, and cover these paths in the Box regression.
There was a problem hiding this comment.
Fixed in 66182b2. The new internal-identity registration path now uses the existing with_env_nest helper to restore the caller environment's actual lexical nesting before register_class_lex pushes the new class/module, and restores the enclosing nesting when a body raises. This matches the ordinary registration path without reconstructing namespace prefixes.
Corpus 1112 now has 68 rows, including method string eval, explicit binding, qualified class opening, Module.nesting and exception restoration in the main box and two child boxes. It matches Ruby 4.0.10 on both engines, including parent RUBY_BOX=1 and hash index ON/OFF. The earlier stored-name frame-label fix is retained. Unchanged original Box selections pass 4/53 and Eval selections 4/145 on both candidate engines; matching main outcomes and fixed-seed tight-GC RSS are in the description and committed record.
Both final full sweeps pass 965/965, evaluator and MERE_RUBY_VM=1, hash ON/OFF. All eight source gates, bracket depth, full/explicit record_hygiene and whitespace checks pass. The fix, expanded fixture and completed record were pushed together.
| // Every new box-owned class has its own internal namespace, including | ||
| // the first class with a display name. A removed constant also starts | ||
| // a fresh identity outside boxes, preserving references to the old class. | ||
| if (if already then false else true) && (removed9 || vec_get box_st 0 == 1) then |
There was a problem hiding this comment.
[Minor / P3] Display the public namespace in bare-constant NameErrors
Giving the first enclosing namespace an internal identity exposes that identity in the bare-constant error path. With RUBY_BOX=1:
begin
module PublicOuter
class PublicInner
Absent
end
end
rescue NameError => error
p error.message.lines.first.chomp
endRuby 4.0.10 and current main report uninitialized constant PublicOuter::PublicInner::Absent; this head reports uninitialized constant AnonModule_1::PublicInner::Absent on the evaluator and uninitialized constant AnonClass_2::Absent on the VM, with hash indexing on/off. error.receiver.name already gives the correct public name. Normalize the owner through its stored/display name when constructing the bare EConst NameError, and add an unqualified missing-constant case inside a nested Box class to the regression.
There was a problem hiding this comment.
Fixed in 66182b2. Bare EConst NameError construction now renders the actual owner's stored/display name through cls_display, including the BasicObject lookup branch; the exception receiver remains the actual owner identity. The earlier class/module frame-label correction is retained and still avoids dispatching an overridden Module#name.
Corpus 1112 adds nested PublicOuter/PublicInner bare missing constants and a qualified BasicObject subclass case, checking the first message line, receiver.name and the actual class-body frame label in the main box and two independent boxes. All 68 rows match Ruby 4.0.10 on both engines, including parent RUBY_BOX=1 and hash indexing ON/OFF.
Fresh evaluator and VM full corpus sweeps both pass 965/965. Source gates, bracket depth, full/explicit record hygiene and original Box/Eval selections pass. Fixed-seed tight-GC max RSS and all final results are posted in the description and committed loop note.
284km
left a comment
There was a problem hiding this comment.
Re-review at 66182b26. Both bot findings are fixed. On a build of this head, with and without RUBY_BOX=1, these all match clean Ruby 4.0.10 on both engines: the method string-eval class (:outer), the bare missing constant (uninitialized constant PublicOuter::PublicInner::Absent), a class-body singleton method's caller_locations label (Labeled.where), Module.nesting in a nested class, and a missing constant inside an anonymous class. The only difference is the program name in the Box experimental warning. The earlier AnonClass label point is covered by the stored-name frame label. The test merge with current main is clean. With corpus 965/965 on both engines and the 68 rows of corpus 1112 posted, this is ready.
Classes with the same displayed name in separate Ruby boxes now have independent internal identities. Qualified reads, reopening, aliases and mixins follow each box's actual constant binding; ordinary class reopening outside boxes retains its identity. Common lexical-scope registration also fixes
Timeout::State::GET_TIMEwhen a box loads Timeout.The review findings are corrected together:
const_missingonce, including hooks returning nil.Module#name.Corpus 1112 now has 68 rows covering the two reported repros, class/module frame labels,
name,inspect, missing-constant messages, aliases, inheritance and box isolation. It matches clean Ruby 4.0.10 (tools/ref_ruby.sh) in stdout, stderr and status on both engines. Requested 1057 (72 rows), 1061 (44), and 1062 (22) match too. Both 1112 and lexical-autoload corpus 736 additionally match with parentRUBY_BOX=1, evaluator/VM and hash index ON/OFF; only the exact interpreter prefix of the experimental warning is canonicalized.Completed local acceptance on main integration
f4303e14plus all review corrections:sh run_corpus.sh --both: 965/965, hash index ON/OFF, exit 0.MERE_RUBY_VM=1 sh run_corpus.sh --both: 965/965, ON/OFF, exit 0.record_hygiene, and whitespace checks: PASS.ruby/test_box.rbselectionsadd_constants_in_box,eval_with_constants,eval_with_classes,very_basic_method_calls_and_constants: reference and both candidate engines 4 tests / 53 assertions, PASS, withRUBY_BOX=1. Matching main stops atTimeout::State::GET_TIME: 4 / 8, one error.Maximum RSS bytes, ordinary O2,
MERE_RUBY_GC_TIGHT=1, fixed--seed=1:The candidate completes 45 additional Box assertions and more library loading, so these are process maxima, not a matched-workload heap-growth comparison. The separate A1 Box prelude/loaded-features cause is recorded separately; no loaded feature is fabricated here.
The unchanged original
ruby/test_eval.rbselectionseval_basic,eval_binding_basic,module_eval_string_basicandinstance_eval_string_basicwere additionally compared with matching main:reference, main and candidate pass 4 tests / 145 assertions on both engines, with RUBY_BOX=1 and fixed --seed=1.
Eval-selection tight-GC maximum RSS bytes: reference 26017792; main evaluator/VM 172769280/174637056; candidate evaluator/VM 167084032/168984576.
Compiler
9dec2ff6, mgz661a01d8; validated O2 binary SHA-256eb761784e8fd2defec956d3d9bb1499c97ec91a7b38d8c018688a46badefb79b. The full sweeps above use this final eval-nesting and name-corrected binary. Code, expanded regression and completed record are in one push. No full unit/Rails suite, reference gem installation or workflow change. Runtime acceptance of newer main revisions is not claimed.