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 @@ -26,7 +26,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export/README

## Required

- [A tuple's parts read after their variables change](/quest/m2/ts-swap-parts.md) - `(a, b) = (b, a)` swaps instead of copying one into both
- [Byte-slice locals that crash the translator](/quest/m2/ts-scalar-ice.md) - `take_apart` never reaches the arm `find_scalars` promised it wouldn't
- [Fixture cases by name](/quest/m2/ts-harness-names.md) - adding a harness case never renumbers another
- [Byte slices without objects](/quest/m2/ts-byte-views/README.md) - reading through a translated cursor allocates no object per read
Expand Down
24 changes: 0 additions & 24 deletions quest/m2/ts-swap-parts.md

This file was deleted.

4 changes: 3 additions & 1 deletion ts/fixtures/codec/expected/coding/decode.DecodeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export function fmt$Display(self: DecodeError, __formatter: rt.Formatter): rt.Re
return rt.fmtWriteStr(__formatter, "expected end");
}
if (self.tag === "MessageTooLarge") {
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.usizeDisplay(self.size, f), (f: rt.Formatter) => rt.usizeDisplay(self.max, f)];
const _26: rt.usize = self.size;
const _28: rt.usize = self.max;
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.usizeDisplay(_26, f), (f: rt.Formatter) => rt.usizeDisplay(_28, f)];
return rt.fmtWriteFmt(__formatter, ["message too large: ", args4[0], " bytes exceeds ", args4[1], " byte limit"]);
}
if (self.tag === "ExpectedData") {
Expand Down
12 changes: 6 additions & 6 deletions ts/fixtures/lang/expected/fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ export function panics(kind: rt.u8, rest: rt.ByteSlice, out: rt.ByteVec): void {
const _129: rt.u8 = rt.optionExpect(missing, rt.fmtFormat(["missing ", args10[0]]));
put(out, rt.fmtToString((f: rt.Formatter) => rt.u8Display(_129, f)));
} else if (_7 === 11) {
const part7 = { _0: n };
const args12: rt.Fmt[] = [(f: rt.Formatter) => Fails.fmt$Display(part7, f)];
const part5 = { _0: n };
const args12: rt.Fmt[] = [(f: rt.Formatter) => Fails.fmt$Display(part5, f)];
put(out, rt.fmtFormat([args12[0]]));
} else if (_7 === 12) {
const _157: Fails.Fails = { _0: n };
Expand All @@ -555,8 +555,8 @@ export function panics(kind: rt.u8, rest: rt.ByteSlice, out: rt.ByteVec): void {
} else if (_7 === 15) {
const buf: Uint8Array = rt.bytes(3);
rt.byteSliceCopyFromSlice(rt.byteSliceFrom(buf), rt.byteSliceRange(rest, 0, rt.min(rest.length, 4)));
const part6 = rt.byteSliceFrom(buf);
const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(part6), f, rt.u8Debug)];
const arg3 = rt.byteSliceFrom(buf);
const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(arg3), f, rt.u8Debug)];
put(out, rt.fmtFormat([args18[0]]));
} else if (_7 === 16) {
const _221: rt.Result<string, rt.FromUtf8Error> = rt.stringFromUtf8(rt.byteSliceToByteVec(rest));
Expand All @@ -573,8 +573,8 @@ export function panics(kind: rt.u8, rest: rt.ByteSlice, out: rt.ByteVec): void {
const part3 = rt.u8Rem(rt.u8Div(n, 6), 6) as rt.usize;
const dest: rt.usize = rt.usizeRem(unwrapOr$Option_u8(rt.byteSliceGet(rest, 1), 0) as rt.usize, 4);
rt.byteSliceCopyWithin(rt.byteSliceFrom(buf2), part2, part3, dest);
const part4 = rt.byteSliceFrom(buf2);
const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(part4), f, rt.u8Debug)];
const arg2 = rt.byteSliceFrom(buf2);
const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(arg2), f, rt.u8Debug)];
put(out, rt.fmtFormat([args20[0]]));
} else if (_7 === 18) {
const _271: rt.usize = rt.u8Rem(n, 8) as rt.usize;
Expand Down
66 changes: 47 additions & 19 deletions ts/fixtures/lang/expected/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export function shape(data: rt.ByteSlice): Shape.Shape {

/** `Copy` aggregates: a copy changes apart from its original. */
export function copies(data: rt.ByteSlice, out: rt.ByteVec): void {
let _211!: Uint8Array;
let _265!: Uint8Array;
let poll!: rt.Poll<Uint8Array>;
let _246!: rt.u8;
let _300!: rt.u8;
const p: Point.Point = Point.new(unwrapOr$Option_u8(rt.byteSliceFirst(data), 0) as rt.i32, 7);
const q: Point.Point = copy$Point(p);
q.x = rt.i32Add(q.x, 100);
Expand Down Expand Up @@ -143,6 +143,34 @@ export function copies(data: rt.ByteSlice, out: rt.ByteVec): void {
const both: [rt.u32, rt.u32] = [n, n];
n = 9;
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32Add(rt.u32Add(both[0], both[1]), n))));
let s: string = "ab";
let t: string = "cde";
let x: Point.Point = p;
let y: Point.Point = q;
const _120: [rt.u8, rt.u8] = [data.length & 0xff, 1];
let i: rt.u8 = _120[0];
let j: rt.u8 = 1;
const _125: rt.usize = rt.usizeRem(data.length, 3);
let iterStart: rt.usize = 0;
const iterEnd: rt.usize = _125;
while (iterStart++ < iterEnd) {
const _135: string = t;
const _136: string = s;
s = _135;
t = _136;
const _140: Point.Point = y;
const _141: Point.Point = x;
x = _140;
y = _141;
const _144: [rt.u8, rt.u8] = [j, i];
const _142: rt.u8 = _144[0];
const _143: rt.u8 = _144[1];
i = _142;
j = _143;
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s));
rt.byteVecPush(out, (x.x & 0xff) ^ i);
}
rt.byteVecPush(out, (rt.stringLen(t) & 0xff) ^ (y.y & 0xff) ^ j);
const word: Uint8Array = Uint8Array.of(0, 0, 0, data.length & 0xff);
const converted: rt.u32 = rt.u32FromBeBytes(word);
word[0] = 9;
Expand Down Expand Up @@ -182,24 +210,24 @@ export function copies(data: rt.ByteSlice, out: rt.ByteVec): void {
shape_.width = 6;
}
}
const _202: Shape.Shape = copy$Shape(shape_);
const iter2: rt.Iter<Shape.Shape> = rt.iterSlice([copy$Shape(before), _202]);
const _256: Shape.Shape = copy$Shape(shape_);
const iter3: rt.Iter<Shape.Shape> = rt.iterSlice([copy$Shape(before), _256]);
while (true) {
const _204: Shape.Shape | rt.Done = iter2.next();
if (_204 === rt.DONE) {
const _258: Shape.Shape | rt.Done = iter3.next();
if (_258 === rt.DONE) {
break;
}
const shape2: Shape.Shape = _204;
const shape2: Shape.Shape = _258;
if (shape2.tag === "Dot") {
_211 = rt.bytes(3);
_265 = rt.bytes(3);
} else if (shape2.tag === "Line") {
const from: Point.Point = shape2._0;
_211 = Uint8Array.of(1, from.x & 0xff, from.y & 0xff);
_265 = Uint8Array.of(1, from.x & 0xff, from.y & 0xff);
} else {
const corner: Point.Point = shape2.corner;
_211 = Uint8Array.of(corner.x & 0xff, corner.y & 0xff, shape2.width & 0xff);
_265 = Uint8Array.of(corner.x & 0xff, corner.y & 0xff, shape2.width & 0xff);
}
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(_211));
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(_265));
}
if (rt.usizeRem(data.length, 2) === 0) {
poll = rt.Pending as rt.Poll<Uint8Array>;
Expand All @@ -211,20 +239,20 @@ export function copies(data: rt.ByteSlice, out: rt.ByteVec): void {
const bytes: rt.ByteSlice = rt.byteSliceFrom(poll);
bytes.data[bytes.start] = 9;
}
const _239: rt.Poll<Uint8Array> = copy$Poll_u8s(poll);
const iter3: rt.Iter<rt.Poll<Uint8Array>> = rt.iterSlice([copy$Poll_u8s(polled_), _239]);
const _293: rt.Poll<Uint8Array> = copy$Poll_u8s(poll);
const iter4: rt.Iter<rt.Poll<Uint8Array>> = rt.iterSlice([copy$Poll_u8s(polled_), _293]);
while (true) {
const _241: rt.Poll<Uint8Array> | rt.Done = iter3.next();
if (_241 === rt.DONE) {
const _295: rt.Poll<Uint8Array> | rt.Done = iter4.next();
if (_295 === rt.DONE) {
break;
}
const poll2: rt.Poll<Uint8Array> = _241;
const poll2: rt.Poll<Uint8Array> = _295;
if (poll2 !== rt.Pending) {
_246 = poll2[0];
_300 = poll2[0];
} else {
_246 = 255;
_300 = 255;
}
rt.byteVecPush(out, _246);
rt.byteVecPush(out, _300);
}
shares(data, out);
unwritten(data, out);
Expand Down
86 changes: 52 additions & 34 deletions ts/fixtures/lang/expected/splits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function code(out: rt.ByteVec, n: rt.u8): rt.u8 {

export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
let _58!: rt.u8;
let _139!: rt.u8;
let _169!: rt.u8;
let err!: Short.Short;
const _4: rt.u8 = rt.u8Rem(kind, 8);
if (_4 === 0) {
Expand Down Expand Up @@ -86,12 +86,12 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
rt.byteVecPush(out, sum);
rt.byteVecExtendFromSlice(out, new rt.ByteSlice(restData, restStart, restLen));
} else if (_4 === 1) {
const mid3: number = rt.u8Rem(unwrapOr$Option_u8(rt.byteSliceFirst(data), 0), 8) as rt.usize;
if (mid3 > data.length) {
const mid4: number = rt.u8Rem(unwrapOr$Option_u8(rt.byteSliceFirst(data), 0), 8) as rt.usize;
if (mid4 > data.length) {
rt.panic("mid > len");
}
rt.byteVecPush(out, mid3 & 0xff);
rt.byteVecExtendFromSlice(out, new rt.ByteSlice(data.data, data.start + mid3, data.length - mid3));
rt.byteVecPush(out, mid4 & 0xff);
rt.byteVecExtendFromSlice(out, new rt.ByteSlice(data.data, data.start + mid4, data.length - mid4));
} else if (_4 === 2) {
const _33: rt.Result<[rt.u8, rt.u16, rt.ByteSlice], Short.Short> = header(data);
if (_33.ok) {
Expand All @@ -106,17 +106,17 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
rt.byteVecPush(out, 241 ^ (_33.error._0 & 0xff));
}
} else if (_4 === 3) {
const mid2: number = rt.usizeDiv(data.length, 2);
if (mid2 > data.length) {
const mid3: number = rt.usizeDiv(data.length, 2);
if (mid3 > data.length) {
rt.panic("mid > len");
}
const head: rt.ByteSlice = new rt.ByteSlice(data.data, data.start, mid2);
const head: rt.ByteSlice = new rt.ByteSlice(data.data, data.start, mid3);
let iterStart: rt.u8 = 0;
const iterEnd: rt.u8 = 3;
while ((_58 = iterStart++) < iterEnd) {
rt.byteVecPush(out, opaque(head) ^ _58);
}
rt.byteVecPush(out, opaque(new rt.ByteSlice(data.data, data.start + mid2, data.length - mid2)));
rt.byteVecPush(out, opaque(new rt.ByteSlice(data.data, data.start + mid3, data.length - mid3)));
} else if (_4 === 4) {
const mid: number = rt.usizeDiv(data.length, 3);
if (mid > data.length) {
Expand Down Expand Up @@ -147,20 +147,38 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
}
rt.byteVecPush(out, pair_0Len & 0xff);
if (!((pair_1Len === 0))) {
const _194Len: number = pair_1Len;
if (0 >= _194Len) {
rt.panic("index out of bounds: the len is " + _194Len + " but the index is " + 0);
const _224Len: number = pair_1Len;
if (0 >= _224Len) {
rt.panic("index out of bounds: the len is " + _224Len + " but the index is " + 0);
}
rt.byteVecPush(out, pair_1Data[pair_1Start]);
}
rt.byteVecExtendFromSlice(out, new rt.ByteSlice(pair_0Data, pair_0Start, pair_0Len));
const mid2: number = rt.usizeDiv(data.length, 2);
if (mid2 > data.length) {
rt.panic("mid > len");
}
let a3: rt.ByteSlice = new rt.ByteSlice(data.data, data.start, mid2);
let b4: rt.ByteSlice = new rt.ByteSlice(data.data, data.start + mid2, data.length - mid2);
const _101: rt.usize = rt.usizeRem(data.length, 3);
let iterStart3: rt.usize = 0;
const iterEnd3: rt.usize = _101;
while (iterStart3++ < iterEnd3) {
const _111: rt.ByteSlice = b4;
const _112: rt.ByteSlice = a3;
a3 = _111;
b4 = _112;
rt.byteVecPush(out, opaque(a3));
}
rt.byteVecPush(out, a3.length & 0xff);
rt.byteVecPush(out, opaque(b4));
} else if (_4 === 5) {
let rest2: rt.ByteSlice = data;
while (true) {
const _94: [rt.u8, rt.u8, rt.ByteSlice] | undefined = two(rest2);
if (_94 !== undefined) {
rt.byteVecPush(out, _94[0] ^ _94[1]);
rest2 = _94[2];
const _124: [rt.u8, rt.u8, rt.ByteSlice] | undefined = two(rest2);
if (_124 !== undefined) {
rt.byteVecPush(out, _124[0] ^ _124[1]);
rest2 = _124[2];
} else {
break;
}
Expand All @@ -170,8 +188,8 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const split: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitFirstChunk(data, 4);
b5: {
if (split !== undefined) {
const _197: rt.ByteSlice = split[0];
if ((_197.data[_197.start] & 1) === 0) {
const _227: rt.ByteSlice = split[0];
if ((_227.data[_227.start] & 1) === 0) {
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32WrappingAdd(((split[0].data[split[0].start] << 24) | (split[0].data[split[0].start + 1] << 16) | (split[0].data[split[0].start + 2] << 8) | split[0].data[split[0].start + 3]) >>> 0, 3))));
rt.byteVecPush(out, split[1].length & 0xff);
break b5;
Expand All @@ -181,18 +199,18 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
return _2[0].data[_2[0].start + 3] ^ (_2[1].length & 0xff);
}));
}
const _129: rt.Result<[rt.ByteSlice, rt.ByteSlice], Short.Short> = take(data, 3);
if (_129.ok) {
rt.byteVecPush(out, opaque(_129.value[0]));
rt.byteVecPush(out, _129.value[1].length & 0xff);
const _159: rt.Result<[rt.ByteSlice, rt.ByteSlice], Short.Short> = take(data, 3);
if (_159.ok) {
rt.byteVecPush(out, opaque(_159.value[0]));
rt.byteVecPush(out, _159.value[1].length & 0xff);
} else {
const e: Short.Short = _129.error;
const e: Short.Short = _159.error;
if (e.tag === "Empty") {
_139 = 0;
_169 = 0;
} else {
_139 = e._0 & 0xff;
_169 = e._0 & 0xff;
}
rt.byteVecPush(out, _139);
rt.byteVecPush(out, _169);
}
} else {
const first2: rt.u8 = code(out, 7);
Expand All @@ -207,21 +225,21 @@ export function splits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
} else {
err = { tag: "Need", _0: data.length } as Short.Short;
}
const _1602: Short.Short = err;
const _1902: Short.Short = err;
if (data.length !== 0) {
rt.byteVecPush(out, data.data[data.start]);
} else if (_1602.tag === "Empty") {
} else if (_1902.tag === "Empty") {
rt.byteVecPush(out, 224);
} else {
rt.byteVecPush(out, 225 ^ (_1602._0 & 0xff));
rt.byteVecPush(out, 225 ^ (_1902._0 & 0xff));
}
const _170: rt.Result<rt.u8, rt.u8 | undefined> = second(data, rt.byteSliceFirst(data));
if (_170.ok) {
rt.byteVecPush(out, _170.value);
} else if (_170.error === undefined) {
const _200: rt.Result<rt.u8, rt.u8 | undefined> = second(data, rt.byteSliceFirst(data));
if (_200.ok) {
rt.byteVecPush(out, _200.value);
} else if (_200.error === undefined) {
rt.byteVecPush(out, 170);
} else {
rt.byteVecPush(out, _170.error ^ 85);
rt.byteVecPush(out, _200.error ^ 85);
}
if (2 <= data.length) {
rt.byteVecPush(out, data.data[data.start + 1] ^ ((data.length - 2) & 0xff));
Expand Down
14 changes: 14 additions & 0 deletions ts/fixtures/lang/src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ pub fn copies(data: &[u8], out: &mut Vec<u8>) {
n = 9;
out.extend_from_slice(&(both.0 + both.1 + n).to_be_bytes());

// So does a tuple of references, though the variables they came from are assigned
// others: a swap in a loop.
let (mut s, mut t) = ("ab", "cde");
let (mut x, mut y) = (&p, &q);
let (mut i, mut j) = (data.len() as u8, 1u8);
for _ in 0..data.len() % 3 {
(s, t) = (t, s);
(x, y) = (y, x);
(i, j) = (j, i);
out.extend_from_slice(s.as_bytes());
out.push(x.x as u8 ^ i);
}
out.push(t.len() as u8 ^ y.y as u8 ^ j);

// A value computed from a call keeps that call before a later one, though it is read
// after.
// A conversion reads its bytes before they change.
Expand Down
8 changes: 8 additions & 0 deletions ts/fixtures/lang/src/splits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ pub fn splits(kind: u8, data: &[u8], out: &mut Vec<u8>) {
out.push(pair.1[0]);
}
out.extend_from_slice(pair.0);
// Two variables swapped through a tuple, which reads each before either changes.
let (mut a, mut b) = data.split_at(data.len() / 2);
for _ in 0..data.len() % 3 {
(a, b) = (b, a);
out.push(opaque(a));
}
out.push(a.len() as u8);
out.push(opaque(b));
}
5 => {
let mut rest = data;
Expand Down
4 changes: 3 additions & 1 deletion ts/fixtures/task/expected/drops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,9 @@ export function arcs(log: Log.Log, id: rt.u32, at: rt.u8): void {
unwind = 94;
_193 = true;
_194 = false;
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, max.value), (f: rt.Formatter) => rt.fmtPad(f, min.value)];
const _92: string = max.value;
const _96: string = min.value;
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _92), (f: rt.Formatter) => rt.fmtPad(f, _96)];
Log.note(log, rt.fmtFormat(["max ", args2[0], " min ", args2[1]]));
count("name", name);
count("other", other);
Expand Down
Loading