From d154bc649da2784abf4f767520775aaebb1ea4fc Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:19:17 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m3/ts-array-as-slice.md Quest-Claim: fc56876c1aec3555 From 89873f368e1b22527e27b841642a6d28d3748510 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:28:13 -0700 Subject: [PATCH 2/5] feat(ts): translate an array as a slice `<[T; N]>::as_slice` and `as_mut_slice` are the reference they take: a reference to an array of bytes is an `rt.ByteSlice` already, and to one of other values its JS array, so writes through the slice land in the array. Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 1 - quest/m3/ts-array-as-slice.md | 14 ---- ts/fixtures/lang/expected/arrays.ts | 109 +++++++++++++++++++++++++++ ts/fixtures/lang/expected/harness.ts | 8 +- ts/fixtures/lang/src/arrays.rs | 71 ++++++++++++++++- ts/fixtures/lang/src/harness.rs | 1 + ts/fixtures/lang/src/lib.rs | 12 +-- ts/src/lower/library.rs | 3 + 8 files changed, 194 insertions(+), 25 deletions(-) delete mode 100644 quest/m3/ts-array-as-slice.md diff --git a/quest/m3/README.md b/quest/m3/README.md index 71c6aaa8c..015538735 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -31,7 +31,6 @@ generic std gap is planned here even when moq never calls it. - [A B-tree's drop order](/quest/m3/ts-btree-drop.md) - dropping a whole `BTreeMap` or `BTreeSet` drops its entries node by node, as std's does - [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do - [References to byte-array keys a collection yields](/quest/m3/ts-byte-key-refs.md) - `keys`, `iter`, `get_key_value`, and `HashSet::get` of a `[u8; N]` key translate -- [An array as a slice](/quest/m3/ts-array-as-slice.md) - `<[T; N]>::as_slice` and `as_mut_slice` translate - [Closures that return an Option whose None is rt.None](/quest/m3/ts-option-closures.md) - `find_map`, `filter_map`, and `map_while` to `Option>` keep `None` apart from `Some(None)` - [Peekable::next_if_eq against another type](/quest/m3/ts-next-if-eq-other.md) - `next_if_eq` with an expected value of another type than the item, such as a `&str` of `String` items, translates - [A slice's edits in place](/quest/m3/ts-slice-edits.md) - `fill`, `rotate_left`, and `copy_from_slice` of other values translate diff --git a/quest/m3/ts-array-as-slice.md b/quest/m3/ts-array-as-slice.md deleted file mode 100644 index 3c815701e..000000000 --- a/quest/m3/ts-array-as-slice.md +++ /dev/null @@ -1,14 +0,0 @@ -# [XS] An array as a slice - -## Goal - -rust2-ts translates `<[T; N]>::as_slice` and `as_mut_slice`, for bytes and other values. -Proven by differential tests against native Rust. - -## Plan - -`as_slice` refuses with a span today, as "unsupported call to `std::array::::as_slice`". -A `&[u8; N]` is already an `rt.ByteSlice` and a reference to another array its JS array, -so each is the reference it is given. - -Public API: the translator's output. diff --git a/ts/fixtures/lang/expected/arrays.ts b/ts/fixtures/lang/expected/arrays.ts index cfc2e7204..2c33f89e1 100644 --- a/ts/fixtures/lang/expected/arrays.ts +++ b/ts/fixtures/lang/expected/arrays.ts @@ -1,6 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; +import { copy$u32s, copy$u8s } from "./lib.ts"; /** Each byte an operation, its value the operand; each puts what it read. */ export function fromFns(data: rt.ByteSlice, out: rt.ByteVec): void { @@ -94,4 +95,112 @@ export function counted$5(op: rt.u8): rt.usize[] { }); } +/** + * Arrays as slices, of bytes and of other values, empty ones included; each byte an + * operation, its value the operand. Writes through `as_mut_slice` land in the array. + */ +export function asSlices(data: rt.ByteSlice, out: rt.ByteVec): void { + const bytes: Uint8Array = rt.bytes(4); + const wide: rt.u16[] = Array.from({ length: 3 }, (): rt.u16 => { + return 0; + }); + const words: string[] = ["", ""]; + const item = copy$u8s(rt.bytes(2)); + const grid: Uint8Array[] = Array.from({ length: 3 }, (): Uint8Array => { + return copy$u8s(item); + }); + const item2 = copy$u32s(Array.from({ length: 2 }, (): rt.u32 => { + return 0; + })); + const pairs: rt.u32[][] = Array.from({ length: 2 }, (): rt.u32[] => { + return copy$u32s(item2); + }); + for (const op of rt.byteSliceView(data)) { + const i: rt.usize = op as rt.usize; + const _22: rt.u8 = rt.u8Rem(op, 8); + if (_22 === 0) { + const s: rt.ByteSlice = rt.byteSliceFrom(bytes); + const _26: rt.usize = rt.usizeRem(i, 4); + rt.idx(s, _26); + s.data[s.start + _26] = op; + rt.byteSliceView(s).reverse(); + } else if (_22 === 1) { + const _32: rt.u16 = op as rt.u16; + const _35: rt.u16[] = wide; + const _37: rt.usize = rt.usizeRem(i, 3); + rt.idx(_35, _37); + _35[_37] = (_32 << 7) & 0xffff; + } else if (_22 === 2) { + const _43: string[] = words; + const _45: rt.usize = rt.usizeRem(i, 2); + rt.idx(_43, _45); + _43[_45] = _43[_45] + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(op, 26)) as rt.char); + } else if (_22 === 3) { + const _56: Uint8Array[] = grid; + const _58: rt.usize = rt.usizeRem(i, 3); + rt.idx(_56, _58); + const row: rt.ByteSlice = rt.byteSliceFrom(_56[_58]); + const _63: rt.ByteSlice = row; + const _64: rt.usize = rt.usizeRem(i, 2); + rt.idx(_63, _64); + _63.data[_63.start + _64] = op; + const _70: rt.ByteSlice = row; + const _72: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 2); + rt.idx(_70, _72); + const read: rt.u8 = _70.data[_70.start + _72]; + const _78: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 3); + if (!(_78 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _78); + } + grid[_78][0] = grid[_78][0] ^ read; + } else if (_22 === 4) { + const all: rt.u32[][] = pairs; + const _89: rt.usize = rt.usizeRem(i, 2); + rt.idx(all, _89); + const pair: rt.u32[] = all[_89]; + const _94: rt.u32 = op as rt.u32; + rt.idx(pair, 0); + pair[0] = _94; + const _99: rt.u32 = op as rt.u32; + rt.idx(pair, 1); + pair[1] = (_99 << 20) >>> 0; + rt.sliceSwap(all, 0, 1); + } else if (_22 === 5) { + (([] as rt.u16[])).reverse(); + rt.byteSliceCopyFromSlice(rt.byteSliceFrom(Uint8Array.of()), rt.byteSliceFrom(Uint8Array.of())); + rt.byteVecPush(out, rt.u8Add((([] as rt.u16[])).length & 0xff, rt.byteSliceFrom(Uint8Array.of()).length & 0xff)); + } else if (_22 === 6) { + written(rt.byteSliceFrom(bytes), wide, op); + } else { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.iterSum(rt.iterMap(rt.iterSlice(wide), (_2: rt.u16): rt.u32 => { + return _2 as rt.u32; + }), rt.u32Add, 0)).reverse())); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(bytes)); + } + } + const _145: rt.ByteSlice = rt.byteSliceFrom(bytes); + const _148: rt.u16[] = wide; + const _151: string[] = words; + const _154: Uint8Array[] = grid; + const _157: rt.u32[][] = pairs; + const _160: rt.u16[] = []; + const _163: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of()); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_145), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(_148, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(_151, f, rt.fmtStr), (f: rt.Formatter) => rt.fmtList(_154, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(_157, f, (value: rt.u32[], f: rt.Formatter) => rt.fmtList(value, f, rt.u32Debug)), (f: rt.Formatter) => rt.fmtList(_160, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_163), f, rt.u8Debug)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", args2[6]]))); +} + +/** Arrays lent by `&mut`, written through their slices. */ +export function written(bytes: rt.ByteSlice, wide: rt.u16[], op: rt.u8): void { + const s: rt.ByteSlice = bytes; + rt.idx(s, 0); + const _5: rt.u8 = rt.u8WrappingAdd(s.data[s.start], op); + rt.idx(s, 3); + s.data[s.start + 3] = _5; + const w: rt.u16[] = wide; + const _16: rt.u16 = op as rt.u16; + rt.idx(w, 0); + w[0] = _16; + rt.sliceSwap(w, 1, 2); +} + //# sourceMappingURL=arrays.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index ec5131533..69739d1f8 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -1,7 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { fromFns } from "./arrays.ts"; +import { fromFns, asSlices } from "./arrays.ts"; import { atomics } from "./atomics.ts"; import { borrows } from "./borrows.ts"; import { bounds } from "./bounds.ts"; @@ -90,7 +90,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) refs(data21, out21); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2121: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { counts(data22, out22); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _375: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _378: rt.ByteSlice, out23: rt.ByteVec): void => { rounding(out23); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2123: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); @@ -176,7 +176,9 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) reducers(data63, out64); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::writers", (_2164: rt.u8, data64: rt.ByteSlice, out65: rt.ByteVec): void => { writers(data64, out65); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["errors::eqs", eqs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]; + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["errors::eqs", eqs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::as_slices", (_2165: rt.u8, data65: rt.ByteSlice, out66: rt.ByteVec): void => { + asSlices(data65, out66); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]; } /** Run one case. */ diff --git a/ts/fixtures/lang/src/arrays.rs b/ts/fixtures/lang/src/arrays.rs index 0126762f6..8eb6e5b83 100644 --- a/ts/fixtures/lang/src/arrays.rs +++ b/ts/fixtures/lang/src/arrays.rs @@ -1,6 +1,6 @@ //! Arrays `array::from_fn` makes, calling its function on each index in order: of bytes, //! wide integers, atomics each its own, strings, nested arrays, none at all, and a length -//! a const parameter gives. +//! a const parameter gives; and arrays as slices, written through. use std::sync::atomic::{AtomicU64, Ordering}; @@ -55,3 +55,72 @@ fn doubled(i: usize) -> u16 { fn counted(op: u8) -> [usize; N] { std::array::from_fn(|i| i * N + usize::from(op)) } + +/// Arrays as slices, of bytes and of other values, empty ones included; each byte an +/// operation, its value the operand. Writes through `as_mut_slice` land in the array. +pub fn as_slices(data: &[u8], out: &mut Vec) { + let mut bytes = [0u8; 4]; + let mut wide = [0u16; 3]; + let mut words = [String::new(), String::new()]; + let mut grid = [[0u8; 2]; 3]; + let mut pairs = [[0u32; 2]; 2]; + let mut none: [u16; 0] = []; + let mut empty: [u8; 0] = []; + for &op in data { + let i = usize::from(op); + match op % 8 { + 0 => { + let s = bytes.as_mut_slice(); + s[i % 4] = op; + s.reverse(); + } + 1 => wide.as_mut_slice()[i % 3] = u16::from(op) << 7, + 2 => words.as_mut_slice()[i % 2].push(char::from(b'a' + op % 26)), + // An element of one array as a slice, as the slice of the outer array lends it. + 3 => { + let row = &mut grid.as_mut_slice()[i % 3]; + row.as_mut_slice()[i % 2] = op; + let read = row.as_slice()[(i + 1) % 2]; + grid[(i + 1) % 3][0] ^= read; + } + 4 => { + let all = pairs.as_mut_slice(); + let pair = all[i % 2].as_mut_slice(); + pair[0] = u32::from(op); + pair[1] = u32::from(op) << 20; + all.swap(0, 1); + } + 5 => { + none.as_mut_slice().reverse(); + empty.as_mut_slice().copy_from_slice(&[]); + out.push(none.as_slice().len() as u8 + empty.as_slice().len() as u8); + } + 6 => written(&mut bytes, &mut wide, op), + _ => { + let sum: u32 = wide.as_slice().iter().map(|&w| u32::from(w)).sum(); + out.extend_from_slice(&sum.to_le_bytes()); + out.extend_from_slice(bytes.as_slice()); + } + } + } + let s = format!( + "{:?} {:?} {:?} {:?} {:?} {:?} {:?}", + bytes.as_slice(), + wide.as_slice(), + words.as_slice(), + grid.as_slice(), + pairs.as_slice(), + none.as_slice(), + empty.as_slice() + ); + out.extend_from_slice(s.as_bytes()); +} + +/// Arrays lent by `&mut`, written through their slices. +fn written(bytes: &mut [u8; 4], wide: &mut [u16; 3], op: u8) { + let s = bytes.as_mut_slice(); + s[3] = s[0].wrapping_add(op); + let w = wide.as_mut_slice(); + w[0] = u16::from(op); + w.swap(1, 2); +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 3a0a53f8c..fa31ac77f 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -147,6 +147,7 @@ fn cases() -> Vec<(&'static str, Case)> { ("iters::reducers", |_, data, out| iters::reducers(data, out)), ("pointers::writers", |_, data, out| pointers::writers(data, out)), ("errors::eqs", errors::eqs), + ("arrays::as_slices", |_, data, out| arrays::as_slices(data, out)), ] } diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index 758ff3872..c1784c0b8 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -7,12 +7,12 @@ //! and `Result`'s combinators from core's MIR, `Option`s of values that can already be //! `undefined`, atomics, `static` ones included, trait objects, one-time cells, mutexes, //! `Cell`s, `UnsafeCell`s, `RefCell`s, read-write locks, and thread-locals, the defaults -//! of std types, the counts of shared pointers, arrays `array::from_fn` makes, maps of -//! `Option`s, values held back past a write of a variable they name, what `Hash` writes -//! into `DefaultHasher` and `RandomState`, slices' `windows` and chunks, mutable ones -//! written through, their parts by inclusive and checked ranges and by fixed size, -//! `Vec::drain`, the order, equality, and hashes of bytes, ranges of `Bound`s and of the -//! crate's own `RangeBounds`, and the equality of `Result`s and std's errors. +//! of std types, the counts of shared pointers, arrays `array::from_fn` makes, arrays as +//! slices, maps of `Option`s, values held back past a write of a variable they name, what +//! `Hash` writes into `DefaultHasher` and `RandomState`, slices' `windows` and chunks, +//! mutable ones written through, their parts by inclusive and checked ranges and by fixed +//! size, `Vec::drain`, the order, equality, and hashes of bytes, ranges of `Bound`s and of +//! the crate's own `RangeBounds`, and the equality of `Result`s and std's errors. //! //! `harness::run` is the entry point both sides of the differential test run, and //! `fmt::Fault` an error only `caller.ts` prints. diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 2ecd5a8cc..89a919d09 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -1823,6 +1823,9 @@ fn mapping<'tcx>( let layout = tcx.layout_of(env.as_query_input(targ(gargs, 0))).ok()?; Expr::lit(layout.size.bytes().to_string()) } + // A reference to an array of bytes is an `rt.ByteSlice` already, and to one of other + // values its JS array, so each is its own slice, and writes through it land in it. + ("array", "as_slice" | "as_mut_slice") => args.pop()?, ("array", "from_fn") => { let n = gargs.consts().next()?.try_to_target_usize(tcx)?; let f = match targ(gargs, 0).kind() { From 01c95019425164917b857519e45ac752a9aa4c08 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:53:15 -0700 Subject: [PATCH 3/5] test(ts): write through an array's slices with the slice edits main now translates Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/arrays.ts | 74 ++++++++++++++--------------- ts/fixtures/lang/src/arrays.rs | 14 +++--- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/ts/fixtures/lang/expected/arrays.ts b/ts/fixtures/lang/expected/arrays.ts index 2c33f89e1..948ba8f01 100644 --- a/ts/fixtures/lang/expected/arrays.ts +++ b/ts/fixtures/lang/expected/arrays.ts @@ -123,51 +123,46 @@ export function asSlices(data: rt.ByteSlice, out: rt.ByteVec): void { const _26: rt.usize = rt.usizeRem(i, 4); rt.idx(s, _26); s.data[s.start + _26] = op; - rt.byteSliceView(s).reverse(); + rt.byteSliceRotateLeft(s, 1); } else if (_22 === 1) { const _32: rt.u16 = op as rt.u16; const _35: rt.u16[] = wide; const _37: rt.usize = rt.usizeRem(i, 3); rt.idx(_35, _37); _35[_37] = (_32 << 7) & 0xffff; + rt.sliceRotateRight(wide, 1); } else if (_22 === 2) { - const _43: string[] = words; - const _45: rt.usize = rt.usizeRem(i, 2); - rt.idx(_43, _45); - _43[_45] = _43[_45] + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(op, 26)) as rt.char); + const _46: string[] = words; + const _48: rt.usize = rt.usizeRem(i, 2); + rt.idx(_46, _48); + _46[_48] = _46[_48] + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(op, 26)) as rt.char); } else if (_22 === 3) { - const _56: Uint8Array[] = grid; - const _58: rt.usize = rt.usizeRem(i, 3); - rt.idx(_56, _58); - const row: rt.ByteSlice = rt.byteSliceFrom(_56[_58]); - const _63: rt.ByteSlice = row; - const _64: rt.usize = rt.usizeRem(i, 2); - rt.idx(_63, _64); - _63.data[_63.start + _64] = op; - const _70: rt.ByteSlice = row; - const _72: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 2); - rt.idx(_70, _72); - const read: rt.u8 = _70.data[_70.start + _72]; - const _78: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 3); - if (!(_78 < 3)) { - rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _78); + const _59: Uint8Array[] = grid; + const _61: rt.usize = rt.usizeRem(i, 3); + rt.idx(_59, _61); + const row: rt.ByteSlice = rt.byteSliceFrom(_59[_61]); + const _66: rt.ByteSlice = row; + const _67: rt.usize = rt.usizeRem(i, 2); + rt.idx(_66, _67); + _66.data[_66.start + _67] = op; + const _73: rt.ByteSlice = row; + const _75: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 2); + rt.idx(_73, _75); + const read: rt.u8 = _73.data[_73.start + _75]; + const _81: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 3); + if (!(_81 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _81); } - grid[_78][0] = grid[_78][0] ^ read; + grid[_81][0] = grid[_81][0] ^ read; } else if (_22 === 4) { const all: rt.u32[][] = pairs; - const _89: rt.usize = rt.usizeRem(i, 2); - rt.idx(all, _89); - const pair: rt.u32[] = all[_89]; - const _94: rt.u32 = op as rt.u32; - rt.idx(pair, 0); - pair[0] = _94; - const _99: rt.u32 = op as rt.u32; - rt.idx(pair, 1); - pair[1] = (_99 << 20) >>> 0; + const _93: rt.usize = rt.usizeRem(i, 2); + rt.idx(all, _93); + rt.sliceCopyFromSlice(all[_93], [op as rt.u32, (((op as rt.u32)) << 20) >>> 0]); rt.sliceSwap(all, 0, 1); } else if (_22 === 5) { (([] as rt.u16[])).reverse(); - rt.byteSliceCopyFromSlice(rt.byteSliceFrom(Uint8Array.of()), rt.byteSliceFrom(Uint8Array.of())); + rt.byteSliceFill(rt.byteSliceFrom(Uint8Array.of()), op); rt.byteVecPush(out, rt.u8Add((([] as rt.u16[])).length & 0xff, rt.byteSliceFrom(Uint8Array.of()).length & 0xff)); } else if (_22 === 6) { written(rt.byteSliceFrom(bytes), wide, op); @@ -178,14 +173,14 @@ export function asSlices(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(bytes)); } } - const _145: rt.ByteSlice = rt.byteSliceFrom(bytes); - const _148: rt.u16[] = wide; - const _151: string[] = words; - const _154: Uint8Array[] = grid; - const _157: rt.u32[][] = pairs; - const _160: rt.u16[] = []; - const _163: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of()); - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_145), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(_148, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(_151, f, rt.fmtStr), (f: rt.Formatter) => rt.fmtList(_154, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(_157, f, (value: rt.u32[], f: rt.Formatter) => rt.fmtList(value, f, rt.u32Debug)), (f: rt.Formatter) => rt.fmtList(_160, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_163), f, rt.u8Debug)]; + const _143: rt.ByteSlice = rt.byteSliceFrom(bytes); + const _146: rt.u16[] = wide; + const _149: string[] = words; + const _152: Uint8Array[] = grid; + const _155: rt.u32[][] = pairs; + const _158: rt.u16[] = []; + const _161: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of()); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_143), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(_146, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(_149, f, rt.fmtStr), (f: rt.Formatter) => rt.fmtList(_152, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(_155, f, (value: rt.u32[], f: rt.Formatter) => rt.fmtList(value, f, rt.u32Debug)), (f: rt.Formatter) => rt.fmtList(_158, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_161), f, rt.u8Debug)]; rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", args2[6]]))); } @@ -201,6 +196,7 @@ export function written(bytes: rt.ByteSlice, wide: rt.u16[], op: rt.u8): void { rt.idx(w, 0); w[0] = _16; rt.sliceSwap(w, 1, 2); + rt.sliceRangeMut(w, 1).fill(rt.u16Add(op as rt.u16, 1)); } //# sourceMappingURL=arrays.ts.map diff --git a/ts/fixtures/lang/src/arrays.rs b/ts/fixtures/lang/src/arrays.rs index 8eb6e5b83..c55e4300d 100644 --- a/ts/fixtures/lang/src/arrays.rs +++ b/ts/fixtures/lang/src/arrays.rs @@ -72,9 +72,12 @@ pub fn as_slices(data: &[u8], out: &mut Vec) { 0 => { let s = bytes.as_mut_slice(); s[i % 4] = op; - s.reverse(); + s.rotate_left(1); + } + 1 => { + wide.as_mut_slice()[i % 3] = u16::from(op) << 7; + wide.as_mut_slice().rotate_right(1); } - 1 => wide.as_mut_slice()[i % 3] = u16::from(op) << 7, 2 => words.as_mut_slice()[i % 2].push(char::from(b'a' + op % 26)), // An element of one array as a slice, as the slice of the outer array lends it. 3 => { @@ -85,14 +88,12 @@ pub fn as_slices(data: &[u8], out: &mut Vec) { } 4 => { let all = pairs.as_mut_slice(); - let pair = all[i % 2].as_mut_slice(); - pair[0] = u32::from(op); - pair[1] = u32::from(op) << 20; + all[i % 2].as_mut_slice().copy_from_slice(&[u32::from(op), u32::from(op) << 20]); all.swap(0, 1); } 5 => { none.as_mut_slice().reverse(); - empty.as_mut_slice().copy_from_slice(&[]); + empty.as_mut_slice().fill(op); out.push(none.as_slice().len() as u8 + empty.as_slice().len() as u8); } 6 => written(&mut bytes, &mut wide, op), @@ -123,4 +124,5 @@ fn written(bytes: &mut [u8; 4], wide: &mut [u16; 3], op: u8) { let w = wide.as_mut_slice(); w[0] = u16::from(op); w.swap(1, 2); + w[1..].fill(u16::from(op) + 1); } From 1ca0993cd30aa5f7583c46b3edce373c109153c2 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:54:27 -0700 Subject: [PATCH 4/5] style(ts): format the array slices fixture Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/src/arrays.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ts/fixtures/lang/src/arrays.rs b/ts/fixtures/lang/src/arrays.rs index c55e4300d..6101e2077 100644 --- a/ts/fixtures/lang/src/arrays.rs +++ b/ts/fixtures/lang/src/arrays.rs @@ -88,7 +88,9 @@ pub fn as_slices(data: &[u8], out: &mut Vec) { } 4 => { let all = pairs.as_mut_slice(); - all[i % 2].as_mut_slice().copy_from_slice(&[u32::from(op), u32::from(op) << 20]); + all[i % 2] + .as_mut_slice() + .copy_from_slice(&[u32::from(op), u32::from(op) << 20]); all.swap(0, 1); } 5 => { From 53d1fcd9981ad1509d92882827ad86d0e7008821 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 09:51:21 -0700 Subject: [PATCH 5/5] test(ts): regenerate the lang harness after merging main Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/harness.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 0d4f4e551..95f4f47f4 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -1,7 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { fromFns } from "./arrays.ts"; +import { fromFns, asSlices } from "./arrays.ts"; import { atomics } from "./atomics.ts"; import { borrows } from "./borrows.ts"; import { bounds } from "./bounds.ts"; @@ -90,7 +90,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) refs(data21, out21); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2121: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { counts(data22, out22); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _390: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _393: rt.ByteSlice, out23: rt.ByteVec): void => { rounding(out23); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2123: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); @@ -178,6 +178,8 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) writers(data64, out65); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["errors::eqs", eqs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["slices::edits", slices_edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::iters", iters] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::drains", strs_drains] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::hinted", hinted] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::made", (_2165: rt.u8, data65: rt.ByteSlice, out66: rt.ByteVec): void => { made(data65, out66); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::as_slices", (_2166: rt.u8, data66: rt.ByteSlice, out67: rt.ByteVec): void => { + asSlices(data66, out67); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]; }