Repository navigation
feat(ts): translate array::from_fn and maps whose values can be undefined - #203
Conversation
Quest-Claim: e0bb8a6498a2f827
…ined array::from_fn calls its function on each index in order, into an array or, of bytes, a Uint8Array. A HashMap's or BTreeMap's value can now be an Option or (): get, get_mut, insert, and remove take the Option's rt.None last, so None stays apart from Some(None). Keys and set and deque items that can be undefined still fail with a span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-std # Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/reject/census.md
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: 4532271e22ba336eb57cf1bdf5da7e3d4ee766a3.
No actionable bugs found. Extending the existing rt.None convention is simpler than boxing every map value: missing keys stay distinct from stored undefined in both primitive-key and hashed-key paths, while mutable-place results retain their own missing-value representation. Keeping unsupported keys and set/deque items refused limits the change appropriately. The array::from_fn helpers preserve ascending call order, empty-array behavior, and independent element construction while reusing existing closure cleanup.
Verification: static inspection of lowering, sentinel/dropper argument placement, collection runtime paths, closure handling, and generated differential fixtures. I did not run builds, tests, census, or the reported mutation check; reported results were not independently reproduced.
(Written by OpenAI)
…-std # Conflicts: # ts/fixtures/lang/expected/harness.ts
…-std # Conflicts: # quest/m2/ts-model/README.md # quest/m2/ts-model/kio-std.md # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/expected/lib.ts # ts/fixtures/lang/src/harness.rs
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Works on quest/m2/ts-model/kio-std.md. #201 added
trailing_zerosto the quest after this PR opened. This PR leaves that out and rewrites the quest to it.Problem
kio reaches std that rust2-ts refused:
std::array::from_fnhad no mapping. kio calls it inWaiter::cloneandtask::Chunk::new; zlib-rs calls it incrc32_braid.HashMaporBTreeMapwhose value can beundefined(anOptionor()) was refused outright. kio'sShared<T>::defaultmakes moq-net'sShared<HashMap<RequestId, Option<Joined<_>>>>, and moq-net callsget,insert, andremoveon it. rangemap'sRangeInclusiveSetis aBTreeMap<_, ()>. The runtime returnedundefinedfor a missing key, which is also how a storedNonelooks.#193 already added
Defaultof arrays,(), and tuples, so this PR drops that part.Approach
array::from_fn::<T, N, F>maps tort.arrayFromFn(N, f), orrt.bytesFromFn(N, f)foru8, which callsfon each index in order. A closure that owns a value that drops is dropped after the call, through the existing closure handling. A length the instance can't evaluate is refused with a span.undefined.get,get_mut(where it isn't a place),insert, andremoveofHashMapandBTreeMaptake theOption'srt.Nonelast, asslice::getalready does. The runtime returns it for a missing key. Maps whose values can't beundefinedemit the same code as before.hashGetonly does the extrahaslookup when it gets aNoneand the stored value isundefined.undefinedis still refused with a span. The reject fixture now covers it with aHashSet<Option<u8>>.Tests:
langgains differential cases against native wasm32:arrays::from_fns: call order seen through a&mutcapture; bytes,u64, separate atomics (kio's shape), a closure that owns aString, empty and nested arrays, a fn item, and a const-generic length.collections::optionals:HashMap/BTreeMapofOption<u8>,(), andOption<String>throughget,insert,remove, andget_mut. Also hashed tuple keys, the entry API, and moq-net'sget().cloned().flatten().Changing
btreeGetto returnundefinedfor a missing key makeslangreport 173 differences.Census (
just ts census, moq pin as of #196, againstorigin/mainate964c24e)kio.tomlmodel.tomlnet.tomlarray::from_fnrefusals (waiter.rs:177,task.rs:65), zlib-rs'scrc32/braid.rs:107, moq-net'sHashMapofOption<Joined>(shared.rs:29,publisher.rs×5,publisher/tracks.rs×2), and rangemap'sBTreeMap<_, ()>refusals.BTreeMap::rangebyRangeEndWrapper(map.rs:210,inclusive_map.rs:578). These were hidden behind the map refusal and fall under the existing "looking up a key by another type" gap.Impact
array::from_fn, and maps ofOptions or(), now translate.rt.arrayFromFnandrt.bytesFromFn.hashGet,hashInsert,hashRemove,btreeGet,btreeInsert, andbtreeRemovetake an optional trailingnone. Not breaking.Alternatives
Options and wrap such values in a box. That changes the representation for every consumer, where a sentinel only touches the three methods that return anOptionof the value.first,pop_front, and the rest would each needrt.None. Left refused, fails loud.Follow-ups
trailing_zerosof every integer width andNonZero, which kio'stask.rsreaches.BTreeMap::rangeby a borrowed wrapper type, now the next refusal there (already covered by the README's "looking up a key by another type it borrows as").(Written by Claude Opus 5.5)
🤖 Generated with Claude Code