Downstream: zig-utils/zig-js#62 Related: #4
Problem
Visitor.isManaged must safely accept wild legacy/embedder pointers, so a miss in the exact ownership/index paths falls back to a full live-cell-list scan. Precise runtime edges often hold a valid typed allocation that may be GC-managed or arena/embedded. Treating those as wild pointers makes an embedded root Environment scan the entire heap during every young collection.
A post-optimization zig-js object_churn profile attributes about 22% of samples to headerForPayload, primarily Environment parent/root edges that miss the managed heap.
Design
- add a trusted typed Visitor predicate for valid typed allocation pointers;
- derive the exact allocation size from the pointee type;
- when the binding guarantees that managed cells of that size use owned storage, validate only the matching owned size class and header magic;
- return false directly for a valid arena/embedded allocation instead of falling back to the live-cell list;
- retain isManaged unchanged for arbitrary, stale, interior, and wild pointers;
- preserve generic fallback behavior for bindings without owned typed storage.
Acceptance criteria
- Typed managed cells validate and can be marked.
- Valid typed stack/arena/embedded objects reject without the live-list fallback.
- Broad isManaged retains safe wild/interior/stale rejection.
- Bindings without owned storage retain existing behavior.
- zig-gc tests pass.
- Downstream profile removes the repeated headerForPayload live-list cost with identical checksums.