Repository navigation
Rust JSG: check the fields of a jsg_traced struct for GC references - #8465
Conversation
There was a problem hiding this comment.
Superseded by the review of
d773d46a.
This review, of ade244a3
✅ Approved — This compile-time-only change tightens GC-reference checking for traced structs; no issues found.
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 security concerns. The change strengthens a compile-time guarantee that a no-op trace can't hide a GC reference.
📖 AGENTS.md: ✅ LGTM
src/rust/AGENTS.md documents #[jsg_traced] and when to use the unchecked jsg::jsg_traced! instead.
📋 Code Quality: ✅ LGTM
The new #[jsg_traced] expansion is correct: it bounds every field type by jsg::HoldsNoGcReferences, keeps existing where-clause predicates, and handles unit, tuple and named-field structs. Every migrated type (Fill, SharedFill, NoData, Reaction, DropFlag) holds only fields that satisfy the marker, and jsg_macros is already a proc-macro dependency of every crate that now uses the attribute.
⚡ Performance: ✅ LGTM
Compile-time-only change; no runtime performance impact.
📝 Documentation: ✅ LGTM
The macro README and the jsg_traced! docs describe the new checked attribute and say the macro form is unchecked.
Reviewed commit: ade244a3
ade244a to
d773d46
Compare
There was a problem hiding this comment.
Superseded by the review of
20dad059.
This review, of d773d46a
✅ Approved — This change is compile-time only. It makes the #[jsg_traced] attribute check every field of a traced struct for GC references, and no issues were found.
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 security concerns. The change only adds compile-time checks, and they are stricter than before: a no-op trace can no longer hide a GC reference in a struct's fields.
📖 AGENTS.md: ✅ LGTM
src/rust/AGENTS.md documents #[jsg_traced] and when to use the unchecked jsg::jsg_traced! instead.
📋 Code Quality: ✅ LGTM
The #[jsg_traced] expansion requires every field type to implement jsg::HoldsNoGcReferences. It keeps the struct's existing where-clause predicates and works for unit, tuple and named-field structs. Every type moved onto the attribute holds only fields that implement the marker.
⚡ Performance: ✅ LGTM
Compile-time-only change with no runtime performance impact.
📝 Documentation: ✅ LGTM
The macro README and the jsg_traced! docs describe the new checked attribute, and they say the macro form does not check fields.
Reviewed commit: d773d46a
`jsg_traced!(Foo)` gives a concrete type a no-op `trace` and `HoldsNoGcReferences` without looking at its fields. If the memory cache's `Fill` gained a `TracedGlobal` field, `jsg_traced!(Fill, ...)` would still compile and claim no GC references. The handle would never be visited, and `IoContext::add_object` would accept it, which is the leak #8401 closed for the generic form. In this patch: - A new `#[jsg_traced]` attribute implements the same no-op `Traced` and `HoldsNoGcReferences` for a struct, but bounds each field's type by `HoldsNoGcReferences`. A `jsg::Rc` or `TracedGlobal` field fails to compile at the field. Unlike `#[jsg_struct]`, the bounds are not higher-ranked, since a trace that visits nothing must not quietly drop the marker instead. - `Fill`, `SharedFill`, `NoData`, io-context's `IoOwnedSpan` and two io-context test types move onto it. `jsg_traced!(Foo)` stays for types whose fields can't implement the marker because they come from outside JSG (`FallbackPermit`, `SpanBuilder`, `memory_cache::Binding`), and its docs now say the claim is unchecked. - A new compile test checks that a `TracedGlobal` or `jsg::Rc` field is rejected, and that nested plain data still compiles. Without the bounds it fails because the code compiles. The change is compile-time only.
d773d46 to
20dad05
Compare
There was a problem hiding this comment.
✅ Approved — This change only affects compile time and makes the checks stricter. No issues were found, and the doc and IoOwnedSpan follow-ups from the earlier discussion are done.
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
This only adds compile-time checks, and they are stricter than before: a struct whose trace visits nothing can no longer hide a GC reference in its fields.
📖 AGENTS.md: ✅ LGTM
src/rust/AGENTS.md documents the checked attribute and when to use the unchecked macro instead.
📋 Code Quality: ✅ LGTM
IoOwnedSpan on #[jsg_traced] meets the field bound: IoOwned<T> gets the marker for T: HoldsNoGcReferences + Send, and ThreadBoundSpan has both. The new proc_macro_deps entry lets the attribute resolve in the io-context crate.
⚡ Performance: ✅ LGTM
This change only affects compile time and adds no runtime cost.
📝 Documentation: ✅ LGTM
The review checklist and the JSG README now recommend #[jsg_traced] and describe jsg::jsg_traced! as the unchecked fallback.
Reviewed commit: 20dad059
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8465 +/- ##
==========================================
- Coverage 66.53% 66.42% -0.11%
==========================================
Files 783 794 +11
Lines 201160 202837 +1677
Branches 31480 31503 +23
==========================================
+ Hits 133841 134741 +900
- Misses 48875 49644 +769
- Partials 18444 18452 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jsg_traced!(Foo)gives a concrete type a no-optraceandHoldsNoGcReferenceswithout looking at its fields. If the memory cache'sFillgained aTracedGlobalfield,jsg_traced!(Fill, ...)would still compile and claim no GC references. The handle would never be visited, andIoContext::add_objectwould accept it, which is the leak #8401 closed for the generic form.In this patch:
#[jsg_traced]attribute implements the same no-opTracedandHoldsNoGcReferencesfor a struct, but bounds each field's type byHoldsNoGcReferences. Ajsg::RcorTracedGlobalfield fails to compile at the field. Unlike#[jsg_struct], the bounds are not higher-ranked, since a trace that visits nothing must not quietly drop the marker instead.Fill,SharedFill,NoDataand two io-context test types move onto it.jsg_traced!(Foo)stays for types whose fields can't implement the marker because they come from outside JSG (FallbackPermit,SpanBuilder,memory_cache::Binding), and its docs now say the claim is unchecked.TracedGlobalorjsg::Rcfield is rejected, and that nested plain data still compiles. Without the bounds it fails because the code compiles. The change is compile-time only.