Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export/README
- [Byte slices without objects](/quest/m2/ts-byte-views/README.md) - reading through a translated cursor allocates no object per read
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures
- [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values
- [Held values that name a reassigned variable](/quest/m2/ts-aliases.md) - a held place or folded value reads what Rust read, in and across loop iterations
- [Translate moq-net's model to TypeScript](/quest/m2/ts-model/README.md) - the model translates with kio, moq-clock, and moq-pattern, for moq to compare against WASM
- [Translate against the prebuilt std](/quest/m2/ts-std-build.md) - measure whether `-Zbuild-std` is still needed now that panics abort, and drop it if not
- [Waiting: Swift 6.4 in nixpkgs-unstable](/quest/m2/uniffi-swift-arm.md) - the nightly UniFFI fixtures move back to arm
Expand Down
28 changes: 0 additions & 28 deletions quest/m2/ts-aliases.md

This file was deleted.

97 changes: 49 additions & 48 deletions ts/fixtures/lang/expected/harness.ts

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions ts/fixtures/lang/expected/holds.Row.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by rust2-ts. Do not edit.

export interface Row {
cells: Uint8Array;
}

//# sourceMappingURL=holds.Row.ts.map
325 changes: 325 additions & 0 deletions ts/fixtures/lang/expected/holds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$u8s } from "./lib.ts";
import { unwrapOr$Option_u8, mapOr$Option_usize_u8_consumers_closure8 } from "./core/option.ts";
import type * as Row from "./holds.Row.ts";

export function set(x: rt.Place<rt.u8>, v: rt.u8): void {
x.v = v;
}

export function whole(p: [string, Row.Row, rt.u8]): rt.u8 {
return (rt.stringLen(p[0]) & 0xff) ^ p[1].cells[1] ^ p[2];
}

export function holds(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const a: rt.u8 = unwrapOr$Option_u8(rt.byteSliceFirst(data), 0);
const b: rt.u8 = unwrapOr$Option_u8(rt.byteSliceGet(data, 1), 0);
const _10: rt.u8 = rt.u8Rem(kind, 7);
if (_10 === 0) {
places(a, b, data, out);
} else if (_10 === 1) {
indexed(data, out);
} else if (_10 === 2) {
reborrows(a, b, data, out);
} else if (_10 === 3) {
copies(a, data, out);
} else if (_10 === 4) {
closures(a, b, data, out);
} else if (_10 === 5) {
parts(a, b, data, out);
} else {
ranges(data, out);
}
}

/**
* A `&mut` through nested indexes lent as an `rt.Place`, each index assigned again while
* it lives, and one through a reference assigned another.
*/
export function places(a: rt.u8, b: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const item = copy$u8s(rt.bytes(4));
const grid: Uint8Array[] = Array.from({ length: 4 }, (): Uint8Array => {
return copy$u8s(item);
});
const rows: Row.Row[] = [{ cells: rt.bytes(4) }, { cells: rt.bytes(4) }, { cells: rt.bytes(4) }];
const _16: [rt.usize, rt.usize] = [rt.u8Rem(a, 4) as rt.usize, rt.u8Rem(b, 4) as rt.usize];
let i: rt.usize = _16[0];
let j: rt.usize = _16[1];
for (const k of rt.byteSliceView(data)) {
const _30: rt.usize = i;
if (!(_30 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _30);
}
const _32: rt.usize = j;
if (!(_32 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _32);
}
const _35: rt.usize = rt.usizeRem(i, 3);
if (!(_35 < 3)) {
rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _35);
}
const _39: rt.usize = j;
if (!(_39 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _39);
}
i = rt.usizeRem(rt.usizeAdd(i, k as rt.usize), 4);
j = rt.usizeRem(rt.usizeAdd(j, 1), 4);
set(rt.place(() => grid[_30][_32], (value) => grid[_30][_32] = value), k);
set(rt.place(() => rows[_35].cells[_39], (value2) => rows[_35].cells[_39] = value2), k ^ 1);
}
rt.iterExtendBytes(out, rt.iterFlatten(rt.iterMap(rt.iterSlice(grid), rt.byteSliceFrom), (value: rt.ByteSlice) => rt.iterSlice(rt.byteSliceView(value))));
for (const _61 of rows) {
rt.iterExtendBytes(out, rt.iterSlice(_61.cells));
}
const x: Uint8Array = rt.bytes(4).fill(a);
const y: Uint8Array = rt.bytes(4).fill(b);
let r: rt.ByteSlice = rt.byteSliceFrom(x);
const _72: rt.usize = rt.u8Rem(a, 4) as rt.usize;
const _76: rt.usize = r.length;
if (!(_72 < _76)) {
rt.panic("index out of bounds: the len is " + _76 + " but the index is " + _72);
}
const borrowed = r;
const borrowed2 = r.start + _72;
const s: rt.Place<rt.u8> = rt.place(() => borrowed.data[borrowed2], (value3) => borrowed.data[borrowed2] = value3);
r = rt.byteSliceFrom(y);
set(s, 9);
const _84: rt.usize = r.length;
if (!(0 < _84)) {
rt.panic("index out of bounds: the len is " + _84 + " but the index is " + 0);
}
const _80: rt.u8 = rt.u8WrappingAdd(r.data[r.start], 1);
const _88: rt.usize = r.length;
if (!(0 < _88)) {
rt.panic("index out of bounds: the len is " + _88 + " but the index is " + 0);
}
r.data[r.start] = _80;
rt.iterExtendBytes(out, rt.iterSlice(x));
rt.iterExtendBytes(out, rt.iterSlice(y));
}

/**
* Shared and mutable borrows of an element, the index assigned again before the read,
* and kept across iterations.
*/
export function indexed(data: rt.ByteSlice, out: rt.ByteVec): void {
let i: rt.usize = 0;
const kept: rt.u8[] = [];
while (i < data.length) {
const _9: rt.usize = i;
rt.idx(data, _9);
i = rt.usizeAdd(i, 1);
rt.byteVecPush(out, data.data[data.start + _9]);
kept.push(data.data[data.start + _9]);
}
rt.iterExtendBytes(out, rt.iterSlice(kept));
const v: rt.ByteVec = rt.byteSliceToByteVec(data);
let i2: rt.usize = 0;
while (i2 < v.length) {
const at = rt.idx(v, i2);
i2 = rt.usizeAdd(i2, 2);
const _31: rt.u8 = rt.u8WrappingAdd(v.data[at], i2 & 0xff);
v.data[at] = _31;
}
rt.iterExtendBytes(out, rt.iterSlice(rt.byteVecView(v)));
}

/**
* A reborrow through a reference that is then assigned another, shared and mutable, in a
* loop.
*/
export function reborrows(a: rt.u8, b: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
let x: rt.u8 = a;
let y: rt.u8 = b;
let r: rt.Place<rt.u8> = rt.place(() => x, (value) => x = value);
const s: rt.Place<rt.u8> = r;
r = rt.place(() => y, (value2) => y = value2);
s.v = rt.u8WrappingAdd(s.v, 1);
r.v = rt.u8WrappingAdd(r.v, 2);
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(x, y)));
let r2: rt.u8 = a;
const kept: rt.u8[] = [];
for (const _25 of rt.byteSliceView(data)) {
const s2: rt.u8 = r2;
r2 = _25;
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(s2, r2)));
kept.push(s2);
}
rt.iterExtendBytes(out, rt.iterSlice(kept));
}

/**
* A copy of a reference whose source is assigned another, and of an `Option` a range's
* `next` assigns again.
*/
export function copies(a: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
let r: rt.u8 = a;
const kept: rt.u8[] = [];
for (const _9 of rt.byteSliceView(data)) {
const s: rt.u8 = r;
r = _9;
kept.push(s);
}
rt.iterExtendBytes(out, rt.iterSlice(kept));
const range: rt.Range<rt.usize> = new rt.Range(0, data.length);
let cur: rt.usize | undefined = range.start < range.end ? range.start++ : undefined;
const some: boolean = cur !== undefined;
const copied: rt.usize | undefined = cur;
cur = range.start < range.end ? range.start++ : undefined;
rt.byteVecPush(out, some ? 1 : 0);
rt.byteVecPush(out, mapOr$Option_usize_u8_consumers_closure8(copied, 255, (c: rt.usize): rt.u8 => {
return c & 0xff;
}));
while (true) {
const was: rt.usize | undefined = cur;
cur = range.start < range.end ? range.start++ : undefined;
if (was !== undefined) {
rt.byteVecPush(out, was & 0xff);
rt.byteVecPush(out, mapOr$Option_usize_u8_consumers_closure8(cur, 255, (c2: rt.usize): rt.u8 => {
return c2 & 0xff;
}));
} else {
break;
}
}
}

/**
* Closures made in a loop that capture a reference to what that iteration reads, called
* after it: an element, a payload, a field, and a value a loop breaks with.
*/
export function closures(a: rt.u8, b: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
let _31!: rt.usize;
let _47!: rt.usize;
const arr: Uint8Array = Uint8Array.of(a, b, 3, 4, 5, 6, 7, 8);
const rows: Row.Row[] = [{ cells: rt.bytes(4).fill(a) }, { cells: rt.bytes(4).fill(b) }, { cells: rt.bytes(4).fill(7) }];
const v: rt.ByteVec = rt.byteSliceToByteVec(data);
const fs: Array<() => rt.u8> = [];
for (const _17 of rt.byteSliceView(data)) {
fs.push((): rt.u8 => {
return _17;
});
}
const _28: rt.usize = v.length;
let iterStart: rt.usize = 0;
const iterEnd: rt.usize = _28;
while ((_31 = iterStart++) < iterEnd) {
const at = rt.idx(v, _31);
const _39: () => rt.u8 = (): rt.u8 => {
return rt.u8WrappingAdd(v.data[at], 1);
};
fs.push(_39);
}
const _43: rt.usize = rt.byteSliceFrom(arr).length;
let rangeStart: rt.usize = 0;
const rangeEnd: rt.usize = _43;
while ((_47 = rangeStart++) < rangeEnd) {
const i2: rt.usize = _47;
if (!(i2 < 8)) {
rt.panic("index out of bounds: the len is " + 8 + " but the index is " + i2);
}
fs.push((): rt.u8 => {
return arr[i2];
});
}
const iter3: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data)));
while (true) {
const _61: [rt.usize, rt.u8] | rt.Done = iter3.next();
if (_61 === rt.DONE) {
break;
}
const captured = _61[0];
const _68: () => rt.u8 = (): rt.u8 => {
return rt.u8WrappingAdd(_61[1], captured & 0xff);
};
fs.push(_68);
}
const itS: Row.Row[] = rows;
let itI: number = 0;
while (true) {
const _74: Row.Row | rt.Done = itI < itS.length ? itS[itI++] : rt.DONE;
if (_74 !== rt.DONE) {
const cells: rt.ByteSlice = rt.byteSliceFrom(_74.cells);
fs.push((): rt.u8 => {
return cells.data[cells.start + 1];
});
} else {
break;
}
}
for (const _86 of rt.byteSliceView(data)) {
let n: rt.u8 = _86;
while (!(rt.u8Rem(n, 3) === 0)) {
n = rt.u8WrappingAdd(n, 1);
}
const _96: rt.usize = rt.usizeRem(_86 as rt.usize, 3);
if (!(_96 < 3)) {
rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _96);
}
const captured2 = n;
fs.push((): rt.u8 => {
return rows[_96].cells[0] ^ captured2;
});
}
for (const _111 of fs) {
rt.byteVecPush(out, _111());
}
rt.dropAll(fs);
}

/**
* A tuple of references and a number, read by its fields and whole after the variables
* it was made of are assigned again, and one made in a loop from a variable it assigns.
*/
export function parts(a: rt.u8, b: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const rows: Row.Row[] = [{ cells: rt.bytes(4).fill(a) }, { cells: rt.bytes(4).fill(b) }];
let s: string = "ab";
let x: Row.Row = rows[0];
let n: rt.u8 = a;
const _17: string = s;
const _18: Row.Row = x;
const pair: [string, Row.Row, rt.u8] = [_17, _18, n];
s = "zzz";
x = rows[1];
n = rt.u8WrappingAdd(n, 1);
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(_17));
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(_18.cells[0], pair[2], whole(pair))));
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s));
rt.byteVecPush(out, x.cells[0] ^ n);
let total: rt.u8 = 0;
for (const _47 of rt.byteSliceView(data)) {
const p: [rt.u8, rt.u8] = [n, _47];
n = rt.u8WrappingMul(n, 3);
total = rt.u8WrappingAdd(rt.u8WrappingAdd(total, p[0]), _47);
}
rt.byteVecPush(out, total);
}

/** A range's start read, then the range stepped, once and in a loop. */
export function ranges(data: rt.ByteSlice, out: rt.ByteVec): void {
let _16!: rt.usize;
const range: rt.Range<rt.usize> = new rt.Range(0, data.length);
const before: rt.usize = range.start;
const first: rt.usize | undefined = range.start < range.end ? range.start++ : undefined;
rt.byteVecPush(out, before & 0xff);
rt.byteVecPush(out, mapOr$Option_usize_u8_consumers_closure8(first, 255, (f: rt.usize): rt.u8 => {
return f & 0xff;
}));
const range2: rt.Range<rt.usize> = new rt.Range(0, data.length);
while (true) {
const before2: rt.usize = range2.start;
const _16Some: boolean = range2.start < range2.end;
if (_16Some) {
_16 = range2.start++;
}
if (_16Some) {
rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(before2 & 0xff, _16 & 0xff)));
} else {
break;
}
}
}

//# sourceMappingURL=holds.ts.map
5 changes: 3 additions & 2 deletions ts/fixtures/lang/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::{
arrays, atomics, borrows, captures, cells, chars, chunks, collections, combinators, counts, cows, defaults,
durations, dyns, edits, floats, fmt, generics, ints, iters, keys, locals, locks, nested, objects, pointers, refs,
shapes, splits, statics, strs, utf8, wrappers,
durations, dyns, edits, floats, fmt, generics, holds, ints, iters, keys, locals, locks, nested, objects, pointers,
refs, shapes, splits, statics, strs, utf8, wrappers,
};

/// The native side's entry: [`run`], except that a case starting with 0xff prints a
Expand Down Expand Up @@ -113,6 +113,7 @@ fn cases() -> Vec<(&'static str, Case)> {
("arrays::from_fns", |_, data, out| arrays::from_fns(data, out)),
("collections::optionals", collections::optionals),
("objects::objects", |_, data, out| objects::objects(data, out)),
("holds::holds", holds::holds),
]
}

Expand Down
Loading