Skip to content

feat(ts): translate array::from_fn and maps whose values can be undefined - #203

Merged
kixelated merged 7 commits into
mainfrom
quest/m2/ts-model/kio-std
Oct 29, 2026
Merged

kixelated merged 7 commits into
mainfrom
quest/m2/ts-model/kio-std

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Works on quest/m2/ts-model/kio-std.md. #201 added trailing_zeros to 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_fn had no mapping. kio calls it in Waiter::clone and task::Chunk::new; zlib-rs calls it in crc32_braid.
  • A HashMap or BTreeMap whose value can be undefined (an Option or ()) was refused outright. kio's Shared<T>::default makes moq-net's Shared<HashMap<RequestId, Option<Joined<_>>>>, and moq-net calls get, insert, and remove on it. rangemap's RangeInclusiveSet is a BTreeMap<_, ()>. The runtime returned undefined for a missing key, which is also how a stored None looks.

#193 already added Default of arrays, (), and tuples, so this PR drops that part.

Approach

  • array::from_fn::<T, N, F> maps to rt.arrayFromFn(N, f), or rt.bytesFromFn(N, f) for u8, which calls f on 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.
  • A map's value can now be undefined. get, get_mut (where it isn't a place), insert, and remove of HashMap and BTreeMap take the Option's rt.None last, as slice::get already does. The runtime returns it for a missing key. Maps whose values can't be undefined emit the same code as before. hashGet only does the extra has lookup when it gets a None and the stored value is undefined.
  • A key, or a set or deque item, that can be undefined is still refused with a span. The reject fixture now covers it with a HashSet<Option<u8>>.

Tests: lang gains differential cases against native wasm32:

  • arrays::from_fns: call order seen through a &mut capture; bytes, u64, separate atomics (kio's shape), a closure that owns a String, empty and nested arrays, a fn item, and a const-generic length.
  • collections::optionals: HashMap/BTreeMap of Option<u8>, (), and Option<String> through get, insert, remove, and get_mut. Also hashed tuple keys, the entry API, and moq-net's get().cloned().flatten().

Changing btreeGet to return undefined for a missing key makes lang report 173 differences.

Census (just ts census, moq pin as of #196, against origin/main at e964c24e)

Config Before After
kio.toml 214 212
model.toml 613 587
net.toml 1,684 1,636
  • Removed: kio's two array::from_fn refusals (waiter.rs:177, task.rs:65), zlib-rs's crc32/braid.rs:107, moq-net's HashMap of Option<Joined> (shared.rs:29, publisher.rs ×5, publisher/tracks.rs ×2), and rangemap's BTreeMap<_, ()> refusals.
  • Newly visible: rangemap's BTreeMap::range by RangeEndWrapper (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

  • Translator output: array::from_fn, and maps of Options or (), now translate.
  • Runtime: new rt.arrayFromFn and rt.bytesFromFn. hashGet, hashInsert, hashRemove, btreeGet, btreeInsert, and btreeRemove take an optional trailing none. Not breaking.

Alternatives

  • Keep refusing maps of 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 an Option of the value.
  • Lift the refusal for keys and set/deque items too. No consumer needs it yet, and first, pop_front, and the rest would each need rt.None. Left refused, fails loud.

Follow-ups

  • quest/m2/ts-model/kio-std.md, rewritten here to trailing_zeros of every integer width and NonZero, which kio's task.rs reaches.
  • rangemap's BTreeMap::range by 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

kixelated and others added 3 commits October 28, 2026 16:51
…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
@kixelated kixelated changed the title std gaps kio reaches feat(ts): translate array::from_fn and maps whose values can be undefined Oct 29, 2026
@kixelated
kixelated marked this pull request as ready for review October 29, 2026 02:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T14:54:22.624313Z 1c86c57 Manual request
🔒 Security Review ✅ Completed 2026-10-29T14:57:08.942958Z 1c86c57 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 1c86c57fa9

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1c86c57fa9

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@kixelated
kixelated merged commit 79e4398 into main Oct 29, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-model/kio-std branch October 29, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant