Repository navigation
Let Rust JSG code ask whether a TracedGlobal is empty - #8659
Conversation
There was a problem hiding this comment.
Superseded by the review of
ff14e2d8.
This review, of b560369c
✅ Approved — No correctness, security, performance or documentation problems were found in the new TracedGlobal emptiness API, its README rule or its tests.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
The README's Drop rule and its 'Tested by' paragraph match the new API and tests.
Reviewed commit: b560369c
A resource's `Drop` may keep a `TracedGlobal` it moves out of a field, but whether that handle still has a value depends on which GC collected the resource's wrapper. If the resource was the value's only holder, a scavenge leaves the handle live, while a full GC finds the value dead in the same pause and empties the handle, so `as_local` panics on it. Code keeping such a handle had no way to tell the two apart. In this patch `TracedGlobal` gains `is_empty(lock)` and `try_as_local(lock)`, which returns `None` for an empty handle. Both check the isolate and read the slot under the lock, as `as_local` does. The README's `Drop` rule says when the handle is empty and points to them. The drop_moved_traced_global tests now check that the handle is empty after the full GC path and live after the scavenge path.
b560369 to
ff14e2d
Compare
There was a problem hiding this comment.
✅ Approved — I found no correctness or documentation problems in the new TracedGlobal::is_empty and try_as_local methods, the README's Drop rule or the updated tests.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
No issues found.
is_emptychecks the isolate and reads the strong slot the same wayas_localdoes. Treatingptr == 0as empty matches the null value the file already uses for an emptied handle.try_as_localchecks for an empty handle before it builds aLocal, so it never reachesglobal_to_localwith a null handle.- The tests check both outcomes: the full-GC path leaves the handle empty and the scavenge path leaves it live.
📝 Documentation: ✅ LGTM
No issues found. The README's Drop rule and the doc comments match the new API and how it behaves.
Reviewed commit: ff14e2d8
|
Hmm I'm actually rethinking this direction a bit - is there any way we could rather just say that types that hold GC references must have no destructor? |
A resource that holds GC references can't implement Drop any more, so nothing moves a reference out of a dropping resource's fields. The machinery that made a dropping resource's references strong and parentless first, for its own Drop (#8403), a field type's Drop (#8466) and its TracedGlobals (#8600), has nothing left to do. In this patch VisitMode::DetachForDrop, GcVisitor::detach_for_drop, GarbageCollected::detach_before_drop, Traced::needs_drop_detach and its forwarding impls, and the macro's Drop probes go away. wrappable_invoke_drop drops the resource without visiting it first, and GC and detaching visits no longer check for a drop visit. TracedGlobal::let_go_of_traced stays, since GC and detaching visits use it. TracedGlobal::is_empty and try_as_local (#8659) go too: they were for a handle that a resource's Drop moved out, which can't happen any more.
A resource that holds GC references can't implement Drop any more, so nothing moves a reference out of a dropping resource's fields. The machinery that made a dropping resource's references strong and parentless first, for its own Drop (#8403), a field type's Drop (#8466) and its TracedGlobals (#8600), has nothing left to do. In this patch VisitMode::DetachForDrop, GcVisitor::detach_for_drop, GarbageCollected::detach_before_drop, Traced::needs_drop_detach and its forwarding impls, and the macro's Drop probes go away. wrappable_invoke_drop drops the resource without visiting it first, and GC and detaching visits no longer check for a drop visit. TracedGlobal::let_go_of_traced stays, since GC and detaching visits use it. TracedGlobal::is_empty and try_as_local (#8659) go too: they were for a handle that a resource's Drop moved out, which can't happen any more.
A resource's
Dropmay keep aTracedGlobalit moves out of a field (#8600), but whether that handle still has a value depends on which GC collected the resource's wrapper. If the resource was the value's only holder, a scavenge leaves the handle live, while a full GC finds the value dead in the same pause and empties the handle, soas_localpanics on it. Code keeping such a handle had no way to tell the two apart.In this patch
TracedGlobalgainsis_empty(lock)andtry_as_local(lock), which returnsNonefor an empty handle. Both check the isolate and read the slot under the lock, asas_localdoes. The README'sDroprule says when the handle is empty and points to them. The drop_moved_traced_global tests now check that the handle is empty after the full GC path and live after the scavenge path.