Repository navigation
Rust JSG: #[jsg_traced] for enums and &'static T - #8578
Conversation
#[jsg_traced] only took structs, and only &str of the reference types was Traced, so an enum of plain variants or a struct holding a &'static AtomicUsize still used jsg_traced_unchecked!, which checks nothing. In this patch #[jsg_traced] also takes an enum and bounds the fields of every variant by HoldsNoGcReferences, and &'static T is Traced and HoldsNoGcReferences for T: HoldsNoGcReferences + Sync, which covers &'static str and replaces the &str entry. Conversion, both DropCounters, Carried and NotReported move to #[jsg_traced], and a compile test checks that an enum variant holding a jsg::Rc or a TracedGlobal fails to compile. jsg_traced_unchecked! is left for types from outside JSG and the generic <T> form.
There was a problem hiding this comment.
✅ Approved — The enum and &'static T support is sound: field bounds cover every variant, and the reference impl only accepts GC-free Sync targets. No defects 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
The &'static T impls are bounded by HoldsNoGcReferences + Sync, so no GC reference can go untraced.
📖 AGENTS.md: ✅ LGTM
The src/rust/AGENTS.md edit is consistent with the change.
📋 Code Quality: ✅ LGTM
Field collection over struct and enum variants is correct, and unions produce a clear compile error.
⚡ Performance: ✅ LGTM
Compile-time-only change; the generated trace is a no-op.
📝 Documentation: ✅ LGTM
The updated doc comments and READMEs describe enum support and the &'static T bounds accurately.
Reviewed commit: 2940c754
#[jsg_traced]only took structs, and&strwas the only reference type that wasTraced. So an enum of plain variants, or a struct holding a&'static AtomicUsize, still usedjsg_traced_unchecked!, which checks nothing.In this patch
#[jsg_traced]also takes an enum and bounds the fields of every variant byHoldsNoGcReferences.&'static Tis nowTracedandHoldsNoGcReferencesforT: HoldsNoGcReferences + Sync. That covers&'static strand replaces the&strentry.Conversion, bothDropCounters,CarriedandNotReportedmove to#[jsg_traced]. A new compile test checks that an enum variant holding ajsg::Rcor aTracedGlobalfails to compile.jsg_traced_unchecked!is now only for types from outside JSG and for the generic<T>form.