Repository navigation
Honor Ruby dispatch in deprecation proxies and Module hooks - #317
Conversation
284km
left a comment
There was a problem hiding this comment.
Reviewed exact head b018a5ab and its clean prospective integration with current main 751362a3 (integration tree bdc2f1a5431f911b8cd2c932ea46d237bcc6a94e). Read the surrounding Module-instance/backing-module, native-super, identity dispatch, hook and alias paths, plus the added records. No new actionable finding in this diff.
Preserving the original hook receiver and checking for the actual native ancestor before a super fallback are useful improvements. The regression corpus also covers callback installation during feature insertion, frozen overrides, and replaced/undefined native boundaries.
Independent validation:
- Fresh ordinary O2 builds of the exact head and prospective integration with clean pinned Mere
9dec2ff687a08433247dbdb7729bc19c8522e538and mgz661a01d8bb68f5acd68e3192bd47f081d179c436. The main control uses the fresh O2 build of unchanged751362a3made earlier in this review session. - Corpus 942–944 plus eight existing sender/super/Module-notification/reflection files: head 44/44 and integration 44/44 comparisons match clean Ruby 4.0.10 in stdout, stderr and exit status, across evaluator/VM and hash index ON/OFF with tight GC. Main passes the existing 32 comparisons and reproduces differences in all 12 new comparisons.
- All eight source gates and generated-C bracket depth 155/1024 pass on both head and integration; explicit hygiene for the new Markdown/JSON records and prospective-diff whitespace checks pass.
- Checked the attached Rails record's before/after file inventory and source hashes: unchanged three-file inputs, with the documented 93 matching after cases on each engine. These are author-provided measurements, not a Rails rerun by this review.
- Additional exploration retains existing Module-subclass-target hook-argument identity differences and a native-hook undef_method setup refusal, both reproducible on main; these are excluded from passing totals and new findings.
Prerequisite #292 is merged; its C API checks/runtime guard have no net delta in the prospective integration. No whole unit/Rails suite or resource/platform acceptance is claimed here. Hosted Linux build and macOS gem jobs are still running; macOS build/reference jobs remain queued, and downstream CI coverage is incomplete. The recorded all-merge hold and new-failure investigation requirement remain active, including for already-reviewed PRs; no merge or queue exception is taken. COMMENT because this is the authenticated user's own PR.
284km
left a comment
There was a problem hiding this comment.
Review of head b018a5ab (reference: Ruby 4.0.10 via tools/ref_ruby.sh).
Verdict
No Critical, Major or Minor finding. I found no regression. The suggestions below are gaps that already exist on main, next to the paths this PR touches. None of them blocks this PR.
What I checked, and how
Builds. "Candidate" is a clean build of this head (binary newer than every .mere file). "Main" is a clean build of d0843046, the base the PR compares with. I also used a clean build of fc646ea7 (main, newer) for the before/after probes. I ran binaries only. Each probe ran on the evaluator and on the VM (MERE_RUBY_VM=1).
Merge. git diff origin/main...pr reports two merge bases. The branch merges d0843046, plus fb86db60 and c15756b9 (#292/#302, already on main). git merge-tree --write-tree origin/main pr317 is clean. Against current main, the net change is main.mere, corpus 942–944, the loop note and the record. capi/check/api.rb and corpus 1025 have no net change, as the PR body says.
Running:
- Corpus 942, 943, 944: match Ruby on both engines. All three differ on main, so each one tests the change.
- Corpus 1025 (C API insertion skips Ruby hooks): matches on both engines.
- New probe: a
Modulesubclass whose six hooks are instance methods that raise.rb_include_module,rb_prepend_moduleandrb_extend_objectfrom a C extension still skip all six hooks, and the module lands in the ancestors. A Ruby-levelincludeof the same kind of module callsappend_features. This matches Ruby; main misses the Ruby-level call. deprecate_constantprobes: an override on the singleton of a frozen class, throughextend, inherited from a superclass singleton, an instance method of aModulesubclass,superinto native on a frozen class (FrozenError, right receiver) and on a non-constant name (NameError),send/public_send/method(...).call, and anObject/Kernelmethod of the same name (nativeModule#deprecate_constantstill wins). All match Ruby.const_missingon a module with a deprecated constant: matches.- Mixin hook probes: hooks that skip
super(nothing is inserted), hooks from a module included into theModulesubclass,superfromincluded(returns nil), a singletonincludedon aModulesubclass instance, ancestors identity, and ordinary modules with all six singleton hooks plussuper. All match. Main differs on most of them. - Identity operator probes on
ObjectandBasicObjectsubclasses:equal?undefined,==/!=undefined, through__send__,public_send,sendand the operator syntax. All match, except the cases under S1 and S2 below. - An
ActiveSupport::Deprecation::DeprecatedConstantProxyshape: aModulesubclass that undefines all public instance methods except__*andobject_id, definesappend_features/prepend_features/extend_objectthat forward to the target, and has privateconst_missingandmethod_missing.include/prepend/extend,==,!=,equal?,is_a?and forwarded calls all match Ruby, on both engines. Two constant paths differ (S3). - Neighbouring corpus 114, 151, 170, 681, 683, 705, 969 and 1102: match on both engines.
Cost (instructions retired, median of 3, alternating, main d0843046 vs candidate):
| Loop | Engine | main | candidate | change |
|---|---|---|---|---|
method calls with == and != (200k iterations) |
evaluator | 19.72 G | 19.70 G | −0.1% |
| same | VM | 20.95 G | 20.95 G | 0.0% |
| class bodies with include, prepend, extend and hooks (20k) | evaluator | 15.13 G | 15.27 G | +0.9% |
| same | VM | 15.56 G | 15.70 G | +0.9% |
The method-call path costs nothing. The mixin path costs about 750 more instructions for each plain include (about 4% of one include). That is small. See S6.
Not checked: the full corpus, the Rails files, the test_module/test_class/test_object selections, and RSS. I read the author's numbers for those and did not re-run them.
Suggestions (all present on main as well; not caused by this PR)
S1. a != b syntax, when only == is undefined. BasicObject#!= should call == through normal dispatch, so it reaches method_missing(:==). With this PR, x.__send__(:!=, 1) does that. The operator form x != 1 still returns true without calling method_missing. Without a method_missing, it returns true where Ruby raises NoMethodError for ==. So the two forms now disagree. The same gap shows in Array#include? (which calls ==) and in Integer#== / Integer#=== when they turn the comparison around (case proxy when 3). Corpus 944 undefines both operators, so it does not see this.
S2. ! undefined. !x and x.__send__(:!) return false. Ruby calls method_missing(:!), or raises NoMethodError if there is none. DeprecatedConstantProxy undefines ! (it does not match ^__|^object_id$). So !proxy gives the right value but skips the deprecation warning.
S3. Constants on a Module-subclass proxy. With Old = K.new (K < Module, private const_missing), Old::X raises TypeError: #<object> is not a class/module. Ruby calls const_missing. This happens without any undef. K.new::X written inline works. Also, with const_get undefined, proxy.const_get(:X) goes to the native const_missing and raises NameError, where Ruby calls method_missing(:const_get, :X). On the VM only, undef_method :const_get in a Module subclass body raises NameError; the evaluator accepts it. These are the DeprecatedConstantProxy constant paths.
S4. undef_method of a hook on a Module subclass. undef_method of any of included, extended, prepended, append_features, extend_object or prepend_features raises NameError. Ruby allows it. So the new undef_blocked branch in module_hook_has cannot be reached yet, and no corpus covers it.
S5. deprecate_constant on a Module-subclass instance. An override that calls super raises "super: no superclass method". The new super_missing arm only matches a VClass receiver. Also, the native Class.new(Module).new.deprecate_constant(:Q) returns the backing module, not the receiver.
S6. Mixin cost. About +750 instructions for each include (above). If it matters later, the new mod_inst_self lookup in pristine_include_defaults and module_hook_has is the likely place. No change requested.
Unrelated, also on main: a def self.const_get override is ignored by A.const_get(:X).
CI
At the time of this review: 4 runs succeeded (NKF Wasm engine, Linux build dependency controls, Rails measurement harness, Delegation and URI gem suites). CI, Gem suites, Additional gem suites, Small pure Ruby gem suites, Rake suite and Runtime load path controls were queued or in progress.
|
CI failure investigated: the corpus itself, VM corpus, vm_check, and snippet comparison all pass. The failing step is the subsequent whole-file ISeq comparison for main's Tracked with both CI job links, exact counts and completed local isolation in #323. Clean Ruby 4.0.10 reproduces the same metadata difference on main This is handed to the VM stream. I am not requesting a merge while the CI investigation/hold remains open. |
|
Updated head: Merged main Fresh local acceptance: corpus --both 1011/1011, VM 1011 / 0 fallback / 0 differences, source gates plus default/explicit hygiene pass. All 10 selected CRuby cases (62 assertions) pass on reference and both before/after engines. The three targeted ActiveSupport files improve 86 MATCH / 7 RED → 93 MATCH / 0 RED on evaluator and VM; all files COMPLETE, no bounds events. Three fixed-seed RSS pairs and their variation are in the description/record. Code and records were pushed together once. The PR remains Ready and mergeable. The inline-comment endpoint is currently empty; the earlier reviews cover the old head, so this update still needs the review bot on the exact new head before merge. |
284km
left a comment
There was a problem hiding this comment.
Re-reviewed updated head 095b6b1fd846446ec42ba525b0e33276de8ab0be against freshly fetched current main b9ca06d6700c44ded301131930a5dbd9107202be, including the existing reviews, response, backing creation/clone paths and every access to include_defaults_cache. No new actionable finding established.
The no-backing fast path addresses the earlier ordinary-module hook lookup cost in the implementation. Both backing creation and cloning set the permanent flag before hook selection; the extended corpus covers ordinary mixins before/after backing creation and GC. The author reports -0.10%/-0.33% instruction change for the cold workload and a retained +1.54%/+1.30% after backing creation. These are author measurements, not an independent performance rerun, and the warm cost remains disclosed.
Independent Darwin arm64 validation: 48 main/head executions over corpus 942–944, 969, 1102 and an additional ordinary-hook/backing-clone/GC probe, with tight GC, evaluator/strict VM and hash index ON/OFF against Ruby 4.0.10. All 24 final head comparisons match stdout, stderr and exit status; main matches the eight existing-regression comparisons and differs in the 16 changed-behavior comparisons. An initial extra probe incorrectly tried calling a Module-subclass instance method on an included class; that invalid assertion was removed before the final probe comparisons, with initial output retained. Nine source gates and generated-C bracket depth 155/1024 pass. The first GC-root check refused copied timestamps; a fresh copy of the provenance-verified identical generated C passes. No test failure was suppressed.
The existing O2 head binary 392ed2f3... was copied into an isolated snapshot after comparing all 2,769 tracked files byte-for-byte before and after copying, matching the committed binary and generated-C digests, and verifying pinned mgz 661a01d8 blobs. Runtime/build inputs are identical between recorded build d0336e5 and this documentation/record-only final commit; compiler is pinned Mere 9dec2ff6. Main reuses the O2 binary previously verified against all 397 tracked runtime/build source inputs. No fresh builds, cost/RSS rerun, complete Rails/unit suite or Linux acceptance claimed. The prospective merge with current main is source-clean; no integration binary was tested.
No merge: the recorded all-merge hold/new-failure investigation remains active, including for already-reviewed candidates. Main's executed Linux network contract failure is not unassigned-runner queueing; hosted PR coverage is incomplete and not counted as passing. COMMENT because the authenticated account owns this PR.
284km
left a comment
There was a problem hiding this comment.
Review of 095b6b1f. No Critical/Major/Minor findings. Re-review: the mixin-cost Minor is addressed. Ordinary modules without a Module-subclass backing now take the original hook lookup, guarded by a flag that is set only once a backing is installed (−0.10%% evaluator / −0.33%% VM). The +1.54%% / +1.30%% left after a backing exists is a rare path with the reason documented, and I accept it as a small exception. The review bot reviewed this head with no findings, and the test merge with current main is clean.
Respect Ruby overrides of Module#deprecate_constant, preserve the original Module-subclass mixin-hook receiver, and dispatch undefined ==/!= through method_missing. Corpus 942–944 covers these paths.
Merged main
29016cb8b45142e7e57af80fbb49ae03d4916fb3and addressed the no-hook performance Minor. Measured runtimed0336e573a7040a3768ab5816925b83c09a13fb9; ordinary O2, Mere 9dec2ff6 / mgz661a01d8. Reference:tools/ref_ruby.sh, clean Ruby 4.0.10, revision a704b7cd95a42cc0cf5f307137bf3aac0285b915, Prism 1.8.2, no extra gems.Ordinary modules retain the original hook lookup until a Module-subclass backing is created. The usual no-hook workload removes the reviewed increase. After a backing exists, the lookup still distinguishes the original Ruby receiver; its residual cost is shown separately, since skipping it would lose subclass hooks. Removing that lookup for every ordinary module after this point would require separate per-module bookkeeping or a different backing representation. This patch keeps the existing mapping and reports the remaining warm cost as a small exception.
Instructions retired, medians of three alternating before/after pairs against current main. The mixin cases each execute 20,000 class bodies containing include, prepend and extend. Exact workload text and hashes are recorded.
run_corpus.sh --both: 1011/1011, hash ON/OFF.All current selected CRuby cases pass on all five executions. No whole-file acceptance is claimed from these selections.
All three Rails files are COMPLETE on both sides in every run, with no wall or memory bounds events.
Max RSS, KiB, three alternating full-file evaluator pairs, fixed seed12345, 600s / 2GiB per family, jobs2, MT_CPU=0:
RSS varies between samples; no stable memory improvement is claimed. Native gems are explicitly reused from runtime63213030 / binary c7800ad2, with installation provenance retained separately from measured digests. These are targeted files, not a new full-component run.
Evidence:
railstest/framework/records/activesupport-deprecation-dispatch.jsonandloop/2026-11-27-codex-rails1-deprecation-no-hook.md. Historical acceptance remains pinned to its original record commit.