Skip to content

Rust JSG: #[jsg_traced] for enums and &'static T - #8578

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-17-rjsg-traced-enum-ref
Nov 19, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-17-rjsg-traced-enum-ref

Conversation

@littledivy

Copy link
Copy Markdown
Member

#[jsg_traced] only took structs, and &str was the only reference type that 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. &'static T is now Traced and HoldsNoGcReferences for T: HoldsNoGcReferences + Sync. That covers &'static str and replaces the &str entry. Conversion, both DropCounters, Carried and NotReported move to #[jsg_traced]. A new compile test checks that an enum variant holding a jsg::Rc or a TracedGlobal fails to compile. jsg_traced_unchecked! is now only for types from outside JSG and for the generic <T> form.

#[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.
@littledivy
littledivy requested review from a team as code owners November 18, 2026 04:20

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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

@littledivy
littledivy merged commit daec905 into main Nov 19, 2026
23 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-17-rjsg-traced-enum-ref branch November 19, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants