[API] Enhance Trace trait with trace_non_roots, run_finalizer and standard types - #96
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the GC Trace trait API (adding trace_non_roots and run_finalizer) and introduces optional Trace/Finalize implementations for additional standard-library and third-party types to broaden out-of-the-box GC compatibility.
Changes:
- Added
trace_non_rootsandrun_finalizertoTraceacross collectors (mark_sweep,mark_sweep_branded,null_collector_branded). - Added optional
Trace/Finalizeimpls (gated by features) for several external crates and additional std types. - Updated dependencies/features and lockfile to support the new optional integrations.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| oscars/src/collectors/null_collector_branded/trace.rs | Expands Trace API and adds many new Trace/Finalize impls (std + external crates) under feature gates. |
| oscars/src/collectors/mark_sweep/trace.rs | Extends Trace trait with trace_non_roots default method. |
| oscars/src/collectors/mark_sweep_branded/trace.rs | Extends Trace trait with trace_non_roots and a default run_finalizer. |
| oscars/Cargo.toml | Adds optional dependencies and feature flags for external type support. |
| Cargo.lock | Updates dependency resolution to include newly added optional crates and transitive updates. |
Suppressed comments (3)
oscars/src/collectors/null_collector_branded/trace.rs:351
Traceforhashbrown::HashSetis currently a no-op. Elements can containGcpointers and must be visited; add aT: Tracebound and trace each element.
unsafe impl<T, S> Trace for hashbrown::hash_set::HashSet<T, S> {
#[inline]
unsafe fn trace(&self, _tracer: &mut Tracer) {}
}
oscars/src/collectors/null_collector_branded/trace.rs:360
TraceforBinaryHeapis implemented as a no-op due to the lack ofiter_mut(), but tracing only requires&self. This should iterate the heap and trace each element so reachableGcpointers are not skipped.
unsafe impl<T: Trace> Trace for rust_alloc::collections::BinaryHeap<T> {
#[inline]
unsafe fn trace(&self, _tracer: &mut Tracer) {
// BinaryHeap has no iter_mut(); the null collector's trace is a no-op
// so no values need to be visited here.
}
}
oscars/src/collectors/null_collector_branded/trace.rs:409
Traceforstd::collections::HashSetis currently a no-op. Elements can containGcpointers and must be traced; add aT: Tracebound and trace each element.
unsafe impl<T, S> Trace for std::collections::HashSet<T, S> {
#[inline]
unsafe fn trace(&self, _tracer: &mut Tracer) {}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2d3c80b to
2a3b0bf
Compare
nekevss
left a comment
There was a problem hiding this comment.
Approving for now. I left one comment, and we will need to address it in the future. @shruti2522 could you file an issue to track it.
| rustc-hash = "2.1.1" | ||
| thin-vec = { version = "0.2", optional = true } | ||
| # Optional Trace/Finalize impls for external types. | ||
| boa_string = { git = "https://github.com/boa-dev/boa.git", branch = "main", optional = true } |
There was a problem hiding this comment.
Hmmmm, we will probably need to look into handling this differently in the future for a release ... I don't think this will resolve correctly for what we need.
But since this is still experimental we can leave it for now. But we will need to address it. It probably means that in the long run, oscars would need to be moved into boa OR the boa_string definitions will need to be added to boa_string
follow up to PR #95
trace_non_rootsandrun_finalizerto theTracetrait acrossmark_sweep_brandedandnull_collector_brandedTraceandFinalizefor standard library collections (HashMap,HashSet,BinaryHeap) and utility types (Instant,Path)TraceandFinalizefor boa specific types (boa_string::JsString,icu_locale_core,either::Either,arrayvec::ArrayVec)