docs(gc): add precise-tracing API redesign plan#55
docs(gc): add precise-tracing API redesign plan#55Flamki wants to merge 5 commits intoboa-dev:mainfrom
Conversation
|
I don't think we want a plan to "redesign an API", we want an API redesign proposal. That's much better than just proposing to do it "somehow", since that doesn't prove its feasibility. Having at least a proposed API would open discussion on how to improve it or change it to better fit Boa's needs. |
|
Thanks for the clarification — agreed. I updated this PR to be an API redesign proposal (not just a plan). The latest commit adds a concrete draft API surface and feasibility path:
If useful, I can split the proposed API into focused follow-up issues (by parity area) after this gets initial review direction. |
notes/precise_tracing_api_plan.md
Outdated
| pub struct Root<T: Trace + ?Sized> { | ||
| ptr: Gc<T>, | ||
| slot: RootSlotId, | ||
| } |
There was a problem hiding this comment.
If roots are not tied to the gc context by lifetime, couldn't you cause UB by holding onto a reference to the inner data of a root, then dropping the context and trying to access the hold reference?
There was a problem hiding this comment.
Great point, thanks — agreed this needed to be explicit.
I updated the proposal to brand roots with the GC context lifetime:
Root<'gc, T>now carries a context lifetime markerScope::rootnow returnsRoot<'gc, T>(tied to the same scope/context lifetime)- added a safety note clarifying that safe code cannot keep rooted references after the context/scope is dropped
So the intended model is that roots cannot outlive their owning GC context in safe code.
notes/precise_tracing_api_plan.md
Outdated
|
|
||
| impl<'gc> Scope<'gc> { | ||
| pub fn alloc<T: Trace + 'static>(&mut self, value: T) -> Gc<T>; | ||
| pub fn root<T: Trace + 'static>(&'gc mut self, value: &Gc<T>) -> Root<'gc, T>; |
There was a problem hiding this comment.
Wait, this is extremely limiting since it essentially means you cannot have more than one root at a time
There was a problem hiding this comment.
Thanks, that’s a fair concern.
I pushed an update that keeps the lifetime safety guarantee without serializing root creation:
- changed
Scope::rootfrom an exclusive-borrow shape to a shared-borrow shape - roots are now scope-branded (
Root<'scope, 'gc, T>) so they remain tied to the owning context lifetime - documented the expected implementation detail that root-slot registration uses internal mutability, which allows multiple roots to exist at once
So the model now aims for both:
- no “single-root-at-a-time” restriction, and
- no safe-code path for roots to outlive their owning GC context.
There was a problem hiding this comment.
That still doesn't allow multiple roots, because Scope mutably borrows from GcContext, so the underlying Root also mutably borrows from GcContext.
There was a problem hiding this comment.
Good catch. Fixed now:
Scopeuses shared&GcContext(not mutable borrow)rootstays lifetime-branded (Root<'scope, 'gc, T>)- model now allows multiple roots + keeps context-lifetime safety
This PR adds a focused planning note for the GC redesign direction after removing the
gc_allocatorexperiment path.What this adds
notes/precise_tracing_api_plan.mdWhy
Recent maintainer guidance points toward API-focused GC redesign and staged integration, while
#54removes theCollector: Allocatorexperiment. This note captures a practical plan that matches that direction and keeps scope clear.Scope
Validation
cargo fmt --all -- --checkcargo test --workspace