bun_ptr: RefPtr::new_cyclic; a BackRef<_, Root> can no longer be dangling
JA
2mo ago+115+115+012345678901234567890123456789-7-7-0123456789
What
Follow-up to #40192 (raised in review of #40203): BackRef::dangling() was generic over the provenance marker, so a BackRef<T, Root> — which can hand out a ThisPtr — could be created dangling and "patched later" (CronJob::self_ref did exactly that: Cell::new(BackRef::dangling()) then set(BackRef::from(job.this_ptr())) after RefPtr::new).
RefPtr::new_cyclic(|this: SelfRoot<T>| -> T)(à laArc::new_cyclic): allocates the slot, handsinitan opaqueSelfRoot<T>token to store, writes the value, adopts the ref.SelfRoothas no accessors of its own —this_ptr(&self, owner: &T)/backref(&self, owner: &T)need the constructed&T, so the pointer cannot be followed insideinit.BackRef::dangling()is now only available forShared/Mut(sealedDanglingOkbound), so aRootback-reference is always minted from a real root (From<ThisPtr>,from_root, ornew_cyclic).CronJob::self_refbecomes aSelfRoot<CronJob>field initialised throughnew_cyclic(self.self_ref.this_ptr(self)); noCell, no two-phase init.
Testing
test/js/bun/cron 162/162 on debug+ASAN; clippy clean on bun_ptr / bun_runtime / bun_bundler (the two bundler BackRef::dangling() placeholders are Shared and unchanged).