Repository navigation
feat(ts): translate an array's map, each_ref, and each_mut - #310
Merged
Merged
Conversation
Quest-Claim: 09b3365f28c1927e
`<[T; N]>::map` calls its closure on each element in order, into an array or, of bytes, a Uint8Array. It moves each element into the closure and discards none, so elements that drop are allowed and a closure owning a value that drops drops after the last call. `each_ref` and `each_mut` lend each element as `first_mut` does: one JS copies as its place, an array of bytes as its view, and an object as itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
kixelated
marked this pull request as ready for review
October 30, 2026 22:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
<[T; N]>::mapwas refused at its span as an unsupported call, for every element type(quest/m3/ts-array-map.md, found by #302).
Its stable siblings
each_refandeach_mutwere refused the same way.Approach
mapbecomesrt.arrayMap, orrt.bytesMapfor a[u8; N]result, which is aUint8Arrayasarray::from_fn's is. Each calls the closure on each element in order.mapmoves each element into its closure, sodiscardslists it as discarding nothing.A mapping that discards nothing moves every by-value operand into its result or a
closure, so a closure that owns a value that drops can drop after the call
(
rt.dropAfter) even when the elements drop too. No existing&[]entry takes aclosure, so nothing else changes.
each_refandeach_mutlend each element asfirst_mutdoes: an element JS copiesas its
rt.Place(rt.arrayPlaces), an array of bytes as itsrt.ByteSlice, and anobject as itself (
rt.arrayFrom).arrays::maps:[u8; N]sources and results in both directions,N = 0,captures by reference (order seen) and by move,
Option<u8>andOption<Option<u8>>/Option<()>elements whoseNoneisrt.None, arrays ofarrays changed in the closure and in the result, and a const-generic length.
arrays::lent:each_mutof bytes,u16s, strings, byte arrays, and otherarrays, writes landing in the array;
each_refof each; empty arrays.drops::closures::iterated: an array of guards mapped by a closure that ownsa guard. Native and TS logs match: elements drop inside the calls, the closure after
the last, and what it kept when the result drops.
arrayMaporder, detachedeach_mutplaces) made the langdifferential report 360 differences.
Impact
<[T; N]>::map,each_ref, andeach_mutnow translate.rt.arrayMap,rt.bytesMap,rt.arrayFrom,rt.arrayPlaces.Alternatives
discardsnaming the closure)instead of relaxing
called_closuresfor mappings that discard nothing. Rejected:more runtime surface for the same order.
Not covered
differential harness can't observe it.
try_map,zip, and thesplit_array_*methods are unstable, so they stay refused attheir span.
Follow-ups
None.
Review
quest review, Codexgpt-6.1-sol, medium effort.ece4e3ad: no findings.2fddea5f50d44292b38f35f113f8ce0ba04354e7: no findings. That head mergesorigin/main(feat(ts): translate zero-sized values MIR never assigns #304) with a hand-resolved conflict in the lang harness's case list.just cipassed locally on2fddea5f.🤖 Generated with Claude Code
(written by Claude Opus 5.5)