docs(D-W6.2): closure-capture + hash-slot reproducers, identify real drift#605
Open
docs(D-W6.2): closure-capture + hash-slot reproducers, identify real drift#605
Conversation
…drift D-W6.2 investigation outcome: The simple closure-capture and hash-slot patterns all work correctly without the walker gate. Reproducers landing in src/test/resources/unit/refcount/drift/: - closure_capture.t (8 tests) — single, two-, three-, five-layer wrap, plus a 20-closure chain. - hash_slot.t (14 tests) — direct slot, package global, 50-entry registry, slot overwrite. - sub_install.t (12 tests, copied from earlier branch) — five sub-install patterns. All pass on master AND with the walker gate disabled. Therefore the simple shapes of these three code paths have correct cooperative refCount semantics; they are NOT the source of the drift. PJ_DESTROY_TRACE=1 instrumentation added to DestroyDispatch.callDestroy (zero-cost when off; prints Pkg::subname for RuntimeCode and the class name for blessed objects). The actual drift, surfaced by `PJ_DESTROY_TRACE=1 ./jperl -e 'use Class::MOP'` (gate disabled), is in the metaclass-instance lifecycle: the same Class::MOP::Class instance is destroyed TWICE (same identity hash) — once via MortalList.flush, once via MortalList.drainPendingSince in a cascading flush. Investigation notes in dev/modules/moose_support.md (Phase D-W6.2) describe three concrete next leads: 1. Audit MortalList.deferDecrementIfTracked for double-add. 2. Audit MortalList.drainPendingSince for entries that have already been zeroed. 3. Trace which scope-exit on Class/MOP/Class.pm:260 puts the metaclass on the deferred queue. D-W6.4 (a new sub-phase) is added to track this work; D-W6.1 and D-W6.2 are closed as "the simple patterns work, the actual drift is elsewhere". Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Apr 29, 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.
Summary
D-W6.2 investigation outcome. The simple closure-capture and
hash-slot patterns all work correctly without the walker gate —
they are not the drift source. The actual refCount drift is in the
metaclass-instance lifecycle during
Class::MOPload.What landed
src/test/resources/unit/refcount/drift/:sub_install.t(12 tests) — five sub-install shapes.closure_capture.t(8 tests) — single through five-layer wrap, plusa 20-closure chain.
hash_slot.t(14 tests) — direct slot, package global, 50-entryregistry, slot overwrite.
All pass on master AND with the walker gate disabled.
DestroyDispatch.callDestroygets aPJ_DESTROY_TRACE=1env-flagthat prints every destroy with
Pkg::subnameforRuntimeCodeandclass name for blessed objects. Zero cost when off.
What we actually found
PJ_DESTROY_TRACE=1 ./jperl -e 'use Class::MOP'(gate disabled)fails with
Can't call method "get_method" on an undefined valuein
Class::MOP::Attribute::_remove_accessor. The$classis undefbecause
$self->associated_class()(a weakened ref) reads asundef — the metaclass it pointed to was destroyed.
The trace shows the same
Class::MOP::Class@1424108509instancedestroyed twice (same identity hash):
So the actual drift is either the metaclass being added to the
MortalList.pendingqueue twice, or the same entry being processedonce via
flushand once via the cascadingdrainPendingSinceinside another destroy.
Next steps (D-W6.4 — a new sub-phase)
Three concrete leads, all documented in
dev/modules/moose_support.md:MortalList.deferDecrementIfTrackedfor double-add. Asingle
RuntimeBaseshould never appear twice inpending.MortalList.drainPendingSincefor entries already atrefCount=MIN_VALUE(already destroyed) — should skip them.Class/MOP/Class.pm:260puts themetaclass on the deferred queue. That line is likely the last
statement of
_construct_class_instance.D-W6.1 (sub-install) and D-W6.2 (closure-capture) are now closed:
the simple patterns demonstrably work; the destroys we observed in
use Class::MOPare symptoms of the metaclass-lifecycle bug, notdirect manifestations of those code paths.
Test plan
make(build + unit tests) green.PJ_DESTROY_TRACEis off bydefault; reproducers are new files).
Generated with Devin
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>