Repository navigation
feat(ts): translate static atomics, and a RefCell thread-local's set and with_borrow_mut - #232
Conversation
Quest-Claim: c5cfab38ff419e2b
…nd with_borrow_mut Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tomics Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 4c4c8e4
No actionable findings. Reusing one module value per static preserves identity and atomic state; reading evaluated initialization avoids relying on another crate's initializer MIR. Unsupported static forms remain explicit refusals. The RefCell helpers retain the exclusive borrow through mutation/drop and use Place for values that require write-back, while Cell helpers keep their existing lowering.
The fixtures check initial values before reset, shared byte-table identity, integer extremes, mutation and observable drops. A useful nonblocking addition would exercise RefCell::set before the first get, with an initializer side effect, to directly check the lazy-install path.
Verification: static diff, surrounding lowering/runtime logic and generated fixtures, with an independent pass. No translator, TypeScript compilation, differential tests, mutation checks or census runs performed; author-reported results were not independently reproduced.
(Written by OpenAI)
Claims quest/m2/ts-shared.md.
Problem
A
staticatomic, as kio'swaiterand moq-net'slistingtake their ids from (static NEXT: AtomicU64), was refused as "a constant of type&Atomic". ARefCellthread-local'ssetandwith_borrow_mutwere refused, because std's bodies write the cell in place. And a reference to an immutable static's bytes (&TABLEforstatic TABLE: [u8; 4]) crashed the translator:expected memory, got Static.Approach
&STATICreaches the translator as a pointer constant into aGlobalAlloc::Static, and each static becomes one module value. A static atomic isexport const NEXT: rt.Atomic<rt.u64> = /* @__PURE__ */ new rt.Atomic(1), the sameItem::Valuea thread-local's key is. Its initial integer is read from the static's evaluated allocation, which works when the static is another crate's, as kio's is to moq-net. Thread-local keys and statics now share one map of module values.AtomicPtrstatics,static mut, and a borrow of part of a static are refused with a message naming them. An immutable[u8; N]static is its bytes,export const TABLE: rt.ByteSlice, one object every borrow returns, soptr::eqholds; it crashed before. Any other static is refused as a static of its type.LocalKey::<RefCell<T>>::setmaps tort.localKeyRefCellSet: on a lazy key's first use it installs the value without running the initializer, and otherwise it borrows exclusively, drops the old value, and writes.with_borrow_mutmaps tort.localKeyWithBorrowMut, or…Placewith anrt.Placeover the cell's value when JS copiesT. It is listed among the mappings that lend a place.Tests:
staticslang fixture covers every atomic kind at module level and in a function, with initial values at the types' extremes and the immutable byte table and its identity, all differential against native wasm32.localsadds aRefCell<u32>key (place path),with_borrow_mutthat drops what it held, andsetonRefCellkeys.localKeyRefCellSetnot dropping the old value (276), and the place's setter writing nothing (406).Census (refusals, main → this branch): kio 154 → 153, model 541 → 537, moq-net 1614 → 1607. The remaining static refusals are
AtomicPtrstatics in parking_lot and wasmtimer.No hot path changes (module values and a few runtime helpers), so no bench.
Impact
rt.localKeyRefCellSet,rt.localKeyWithBorrowMut, andrt.localKeyWithBorrowMutPlace. All additive, so noMIGRATE.mdentry.Alternatives
constis: another crate's static has no such MIR in metadata.with_borrow_mutandsetbodies lower: they write in place, which the crate's copy analysis of its own bodies can't see.Follow-ups
AtomicPtrstatics, other interior-mutable statics such asOnceLockandLazyLock, and aconstof an atomic (lock_api'sRawMutex::INIT) are still refused.Review
Local review: Codex (
quest review), gpt-6.1-sol, medium effort, on head4c4c8e4d062a06411b7f9c01794b44198245dd0e. Round 2: no findings. The head since,ee1afffb815c25824356442ac8a2574100670576, only adds a conflict-free merge of main (#236), with snapshots unchanged.Round 1 (head
4dad3461), one finding:&TABLE) built a freshUint8Arrayat each use, soptr::eq(table(), table())was false. Such a static is now one module value every use returns. Thestaticsfixture checksptr::eq, which reports 440 differences against the old per-use copy.🤖 Generated with Claude Code
(written by Claude Opus 5.5)