Repository navigation
feat(ts): translate std's Once over the runtime's OnceLock - #262
Conversation
Quest-Claim: f1bf91be7dd6a091
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/caller.ts # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 49828c55f9a88cbf74cf9d18c6042d30b4d5545f.
No actionable findings. The shared OnceLock state preserves recursive-initialization checks and publishes completion only after the callback returns. Already-completed calls drop the uncalled closure, and constant-memory lowering accepts only the incomplete state. The non-poisoned OnceState matches the documented single-threaded wasm32 abort model.
Direction: reusing OnceLock is simpler than maintaining a second state machine. Keeping the remaining UnsafeCell work explicit avoids claiming that the full crossbeam collector now translates. The differential fixtures cover local/static instances, completion observed during initialization, forced calls, owned captures and recursion. A useful small extension is an owned capture dropped by an already-completed ordinary call_once, beside the forced-call case.
Verification limits: static GitHub review with an independent runtime/drop pass. I did not execute the translator, differential tests, mutation tests, census or just ci; reported results are not independently verified.
(Written by OpenAI)
Problem
crossbeam-epoch keeps its collector in its own
OnceLock, a stdOncebeside anUnsafeCell<MaybeUninit<T>>. std'sOncehad no mapping, so the model's census refused it 8 times: the type, the static's memory,is_completed, andcall_once. Quest:quest/m2/ts-model/once.md.Approach
Oncereuses the runtime'sOnceLockrather than adding a cell:rt.Onceis anrt.OnceLock<true>.Once::new(), and aOnceread from a static's or const's memory in itsIncompletestate, arenew rt.OnceLock(undefined). Any other state is refused, as forOnceLock.call_onceandcall_once_forcearert.onceCall. It runsfthroughonceGetOrInit, or dropsfuncalled once theOncehas run (discards).no_threads' message,one-time initialization may not be performed recursively.is_completedisv === true.OnceStateis theOnceitself.is_poisonedisrt.onceIsPoisoned, which always returnsfalse: a panic aborts, so poisoning is never observable without unwinding.poisonispub(crate)in std, so no crate can poison one either.wait,wait_force, andDebugstay refused.Differential cases in
statics::onces, run against native wasm32:Slotin a static, read from memorystatic OnceOnces: run once,call_once_force's state, a function dropped uncalled (seen through anRccount)call_onceandcall_once_force, comparing the panic message with wasm32'sNamed scripts in
caller.tsmake sure these run. I checked that the test catches regressions: a mutated panic message failed 669 cases, and skipping the drop failed 23.Census, from
just ts censusat the pinned moq revision:Every
Oncerefusal is gone and no new refusal appears. crossbeam-epoch'sOnceLock<Collector>is now refused only at itsUnsafeCell: the field atsync/once_lock.rs:11, andgetat lines 64 and 77.Impact
std::sync::OnceandOnceStatenow translate.rt.Once,rt.OnceState,rt.onceCall,rt.onceIsPoisoned.MIGRATE.mdentry.Alternatives
rt.Onceclass with its own state. Dropped:OnceLockalready tracks incomplete, running, and complete, including the reentrancy panic.OnceasOnceLock<()>withrt.None. Clumsier output, and it needs a sentinelNoneat every call.is_poisonedto a barefalse. This leaves the closure'sstateparameter unread, whichtscrejects.Follow-ups
The quest's Goal also needs std's
UnsafeCell, which nothing translates yet (10 refusals in the model's census). This PR rewrites the quest to that remaining work asquest/m2/ts-model/unsafe-cell.md, at the same rank in the epic, rather than deleting it.Choices made without asking:
[M].Review
quest review, Codex gpt-6.1-sol, medium effort.harness.rs,caller.ts, and the regeneratedexpected/harness.ts.just cipassed on 49828c5.Merge of main at
23b09571c0aa65fe273f47bfc2d077073ee28bf9: the lang harness case list conflicted with #259's cases; resolved by keeping main's cases thenstatics::onces, and the regeneratedexpected/harness.tsonly adds that case and renumbers one placeholder.just cipassed on this exact tree. No translator or runtime code changed since49828c55, so this is a recorded skip, too trivial to review, on top of round 2's clean review.(written by Claude Opus 5.5)
🤖 Generated with Claude Code