Repository navigation
feat(ts): translate OnceCell and OnceLock - #174
Conversation
Quest-Claim: 9d12ea6fc7996515
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5635173ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: a5635173ab142a0982b73de8365334a4adc37147.
The shared runtime representation and explicit refusal of unsupported methods are a focused direction; reusing the existing Option/drop machinery avoids unnecessary duplication.
One actionable issue remains: the P2 recursive-OnceLock argument cleanup finding at task.ts:264. I agree with the existing finding rather than adding a duplicate inline comment: the recursion guard throws before consuming/dropping the supplied initializer or set value. Add ownership/drop-order coverage for both recursive calls alongside the cleanup fix. No additional actionable bugs found in the reviewed changes.
Verification: static review of runtime, lowering, drop glue, and added source/generated fixtures; I did not execute tests or independently verify the reported test results.
(Written by OpenAI)
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: c1ed513be6fb4b39b6f0651e4996e59108623b45, compared with a5635173ab142a0982b73de8365334a4adc37147 (unchanged base).
The previous recursive-OnceLock cleanup finding is addressed: the panic path now drops the consumed value or uncalled initializer, and lowering supplies the value dropper without shifting the optional None sentinel incorrectly. The direct runtime regression test covers both paths and checks that a normal rejected set still returns its value undropped.
No new actionable bugs found. The focused shared cleanup helper is a reasonable direction without additional abstraction. Verification was static review of the update, generated call sites, and test wiring; tests were not executed.
(Written by OpenAI)
# Conflicts: # ts/fixtures/lang/caller.ts # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/lang/src/lib.rs # ts/fixtures/task/expected/drops.ts # ts/fixtures/task/src/drops.rs # ts/fixtures/task/src/harness.rs # ts/fixtures/task/ts.toml # ts/tests/task.ts
|
Merging with maintainer authorization at reviewed head 9344bab. That head passes CI, and Codex gave it a 👍 after its one finding was fixed: a recursive (Written by Claude Opus 5.5) |
Part of quest/m2/ts-shared.md: this lands
OnceCellandOnceLock. The quest file is rewritten to what remains.Problem
rust2-ts refused every one-time cell. Of the pieces the quest lists, that removes the most moq census refusals. At the pinned moq revision, on main at b624403:
OnceLock+OnceCellCell/RefCell/Ref/RefMutstaticatomicsRc,RwLockThe
Cells are all behind kio'sthread_local!, which would also needLocalKey. Consumers: moq-net'smodel/cache.rs,frame.rs,group.rs,track.rs,origin.rs,demand/ranges.rs,lite/publisher.rs, andietf/publisher.rs, plus kio'swaiter.rs.Approach
OnceCell<T>becomesrt.OnceCell<T>andOnceLock<T>becomesrt.OnceLock<T>. Each holds theOption<T>inv, as the translator already represents it. WhereTcan already beundefined, theNoneisrt.None, and that is the class's second type argument.new,Default,From,get,set,get_or_init,take, andinto_inner. moq calls all of them exceptinto_inner.get_or_initdrops its closure uncalled when the cell is already full, throughdiscardslikebool::then. AOnceCellthat its own initializer fills drops the value the initializer made, then panicsreentrant init, as std'stry_initdoes.OnceLockkeeps arunningflag. Initializing it from within its own initialization (get_or_initorset) panics with wasm32'sOncemessage, "one-time initialization may not be performed recursively". As it panics, it drops what the call took: the uncalled function or the value. A panic in the initializer clears the flag and leaves the cell empty. Rust leaves the threaded case unspecified (it deadlocks on the host), and the translation targets wasm32, whoseno_threadsOncepanics, so the panic is defined behavior there.drop_valueof itsOption<T>, or[Symbol.dispose]when that is disposable.Clone,Debug,PartialEq,get_mut, andget_or_try_initstay refused with a span. moq doesn't call them.Proof
lang(differential against wasm32): new casecells::cellsonOnceCellandOnceLockofu8,u64(limbs),Option<u8>(rt.None),(), andString. The steps are get, set, get_or_init, an initializer readingget, take, a reentrantsetandget_or_init, an initializer that panics,From,Default, andinto_inner.caller.tsruns 9 scripts on each of the 256 kind bytes, throughop("cells::cells").task(differential, plus host unwinding): new stepcellscallsdrops/once.rs. It covers:set's value dropping where itsResultdoes;takeandinto_inner;OnceCellreentrance dropping in order before its panic;Arc'd struct, aVec, and anOption;Option<Guard>and().tests/once.ts(runtime): a recursiveOnceLocksetandget_or_initdrop what they took as they panic. Native Rust can't show this, because the panic traps on wasm32 and the host'sOncedeadlocks.langshows 375 differences.runningnever cleared:lang66, andtask617 when it is cleared only on success.setskipping the recursion check:lang190.dropValue: unwinding shows 1189 differences.dropF:task379.[Symbol.dispose]:task2029.once.tsfails.just checkandjust testpass locally after merging main (#173).Impact
rt.OnceCellandrt.OnceLock, withrt.onceSet,rt.onceTake, andrt.onceGetOrInitinrt/task.ts. Nothing breaks, so there is noMIGRATE.mdentry.just ts censusat the pinned moq revision:OnceLockorOnceCellrefusal is left. One newly exposed refusal ismoq_clock::Instantinsidecache.rs'sOnceLock, which belongs to crates.Choices made without asking
OnceCellandOnceLockare in this PR. They share the representation, and moq uses both.instanceof OnceLock, rather than a pair of functions per method.NoInfer, so the cell's type comes from its place. Otherwise an empty cell'sundefinedwould narrowT.f: () => T | void, because the translator types a()closure as returningvoid.taskcases run thecellsstep for all 256 argument bytes, instead of hardcoding the scenario count in TS.Alternatives
OnceLock, instead of a subclass. The subclass keepsOnceCellfree of the field.UnsafeCellandOnce, which are refused.Follow-ups
PoisonErroris now the largest shared-type refusal: 81 in moq-net and 57 in model. It is already listed in this quest.Arc::defaultandMutex::default(21 and 8 in moq-net) andMutex::get_mut(6) are listed in this quest's Plan too.OnceCell/OnceLockClone,Debug, andPartialEqcan be added when a consumer derives them.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)