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 @@ -22,7 +22,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
## Required

- [Cheaper byte slices](/quest/m2/ts-byte-views.md) - splitting a `&[u8]` stops making a `Uint8Array` view per split
- [MIR's own census refusals](/quest/m2/ts-mir-census.md) - the census refuses no function THIR translated, and points type refusals at their locals
- [Smaller output from MIR](/quest/m2/ts-mir-size.md) - the bench's bundles shrink back to THIR's sizes, coroutine classes first
- [Wide-integer runtime off bigint](/quest/m2/ts-wide-bigint.md) - checked sums, 128-bit quotients, and comparisons with numbers stop going through `bigint`, kept only if measured faster
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it
Expand Down
30 changes: 0 additions & 30 deletions quest/m2/ts-mir-census.md

This file was deleted.

12 changes: 8 additions & 4 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ It runs `cargo check` on the package with itself as `RUSTC_WRAPPER`, for
`wasm32-unknown-unknown`. Every crate compiles as rustc would; the configured library is
also translated, after type and borrow checking, starting from its roots and following
what they reach. A construct outside the subset is a compile error with its span, and
then nothing is written.
then nothing is written. A type without a JS value is refused where a value of it is made
or received, such as a parameter, a field, or a call, rather than again at each variable
holding one; any variable or temporary that holds a type whose JS value is ambiguous, such
as `Option<()>`, is refused at its own span.

```toml
# ts.toml, beside the package's Cargo.toml unless --manifest-path says otherwise.
Expand Down Expand Up @@ -60,6 +63,7 @@ runtime: what std does that JS does not, with iterators in `rt/iter.ts`, collect
| `enum` | a union of objects tagged by variant |
| `Option<T>` | `T \| undefined`; refused if `T` can already be `undefined`, as `()` and `Option` can |
| `Result<T, E>` | `rt.Result<T, E>`: `{ ok: true, value }` or `{ ok: false, error }` |
| `ControlFlow<B, C>` | `rt.Result<C, B>`, `Ok` to continue; what `?` branches on is the value it was applied to |
| tuple, `[T; N]`, `&[T]`, `Vec<T>` | an array, `Uint8Array` for bytes, `rt.ByteVec` for `Vec<u8>` |
| `&T`, `&mut T`, `Box<T>` | the value: a `&mut` must point at an object JS can change in place |
| an iterator | `rt.Iter<Item>`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` |
Expand Down Expand Up @@ -283,9 +287,9 @@ own `impl Iterator` with `next_back`, `len`, or another provided method of its o
format specs (a precision, `+`, `{:b}`, `{:x?}`, and widths from arguments), writing to a
`String` with `write!`, a copy of a closure that changes what it captured, `mem::swap`,
`replace`, or `take` of a reference's whole pointee, assigning an `Arc`, a waker, a
`MutexGuard`, a pinned reference, or a future through a reference, a `ControlFlow` other
than the one `?` makes, a switch on or a field of another crate's type without a mapping,
and std functions without a mapping in `src/lower/library.rs`.
`MutexGuard`, a pinned reference, or a future through a reference, a switch on or a
field of another crate's type without a mapping, and std functions without a mapping in
`src/lower/library.rs`.

## Tests

Expand Down
8 changes: 6 additions & 2 deletions ts/fixtures/codec/expected/lite/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export function decodeSize(r: Decoder.Decoder, max: rt.usize): rt.Result<rt.usiz
*/
export function decodeWith$Group_decode_closure0(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result<Group.Group, DecodeError.DecodeError>): rt.Result<Group.Group, DecodeError.DecodeError> {
let _3!: rt.Result<rt.usize, DecodeError.DecodeError>;
let size!: rt.usize;
let body!: Decoder.Decoder;
let _9!: rt.Result<Decoder.Decoder, DecodeError.DecodeError>;
let result!: rt.Result<Group.Group, DecodeError.DecodeError>;
_3 = decodeSize(r, 65535);
if (_3.ok) {
_9 = Decoder.sub(r, _3.value);
size = _3.value;
_9 = Decoder.sub(r, size);
if (_9.ok) {
body = _9.value;
result = rt.resultAndThen(rt.resultMapErr(decode(body), DecodeError.complete), (msg: Group.Group): rt.Result<Group.Group, DecodeError.DecodeError> => {
Expand Down Expand Up @@ -66,12 +68,14 @@ export function decodeWith$Group_decode_closure0(r: Decoder.Decoder, decode: (a0
*/
export function decodeWith$Probe_decode_closure0(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result<Probe.Probe, DecodeError.DecodeError>): rt.Result<Probe.Probe, DecodeError.DecodeError> {
let _3!: rt.Result<rt.usize, DecodeError.DecodeError>;
let size!: rt.usize;
let body!: Decoder.Decoder;
let _9!: rt.Result<Decoder.Decoder, DecodeError.DecodeError>;
let result!: rt.Result<Probe.Probe, DecodeError.DecodeError>;
_3 = decodeSize(r, 65535);
if (_3.ok) {
_9 = Decoder.sub(r, _3.value);
size = _3.value;
_9 = Decoder.sub(r, size);
if (_9.ok) {
body = _9.value;
result = rt.resultAndThen(rt.resultMapErr(decode(body), DecodeError.complete), (msg: Probe.Probe): rt.Result<Probe.Probe, DecodeError.DecodeError> => {
Expand Down
2 changes: 2 additions & 0 deletions ts/fixtures/codec/src/lite/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub(super) fn decode_with<T: Message>(
) -> Result<T, DecodeError> {
let size = decode_size(r, T::MAX_SIZE)?;
let mut body = r.sub(size)?;
// Left out with its arguments, whose `Option<()>` has no JS value.
tracing::trace!(empty = (size == 0).then_some(()).is_some(), "body");

// The body is complete, so running short inside it is malformed, not a wait for more.
let result = decode(&mut body)
Expand Down
8 changes: 5 additions & 3 deletions ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ints, strings, derived, written, panics } from "./fmt.ts";
import { methods } from "./generics.ts";
import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts";
import { adaptors, consumers, ranges, options, own, values } from "./iters.ts";
import { copies, order, discriminants, loops, patterns, closures, library } from "./shapes.ts";
import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts";

/** Run one case. */
export function run(input: Uint8Array): rt.ByteVec {
Expand All @@ -24,7 +24,7 @@ export function run(input: Uint8Array): rt.ByteVec {
_10 = [input[0], input[1]] as [rt.u8, rt.u8];
op = _10[0];
kind = _10[1];
_14 = rt.u8Rem(op, 38);
_14 = rt.u8Rem(op, 39);
if (_14 === 0) {
u8Op(kind, input.subarray(2, input.length - 0), out);
} else if (_14 === 1) {
Expand Down Expand Up @@ -117,8 +117,10 @@ export function run(input: Uint8Array): rt.ByteVec {
sets(kind, input.subarray(2, input.length - 0), out);
} else if (_14 === 36) {
btreeMaps(kind, input.subarray(2, input.length - 0), out);
} else {
} else if (_14 === 37) {
deques(input.subarray(2, input.length - 0), out);
} else {
flows(input.subarray(2, input.length - 0), out);
}
return out;
}
Expand Down
182 changes: 178 additions & 4 deletions ts/fixtures/lang/expected/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,26 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void {
let _66!: Point.Point;
let _71!: rt.u8;
let _73!: rt.u8;
let boxed!: Moved.Moved;
let _81!: rt.u16;
let _83!: rt.u16;
let n!: rt.u32;
let both!: [rt.u32, rt.u32];
let word!: Uint8Array;
let converted!: rt.u32;
let cell!: Uint8Array;
let source!: Uint8Array;
let returned!: Uint8Array;
let _128!: rt.u8;
let _145!: rt.u8;
let marked!: boolean;
let opt!: Meters.Meters | undefined;
let taken!: Meters.Meters | undefined;
let res!: rt.Result<Point.Point, rt.u8>;
let first!: Point.Point;
let fail!: rt.Result<rt.u8, Point.Point>;
let err!: Point.Point;
let _195!: Moved.Moved;
let _198!: Moved.Moved;
p = Point.new(rt.optionUnwrapOr(rt.sliceFirst(data), 0) as rt.i32, 7);
q = rt.copy(p);
_9 = rt.i32Add(q.x, 100);
Expand Down Expand Up @@ -175,14 +180,22 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void {
const swapped = a;
a = b;
b = swapped;
undefined;
_66 = Point.new(5, 6);
const old2 = a;
a = rt.copy(_66);
old = old2;
_71 = a.x & 0xff;
_73 = b.x & 0xff;
rt.byteVecExtendFromSlice(out, Uint8Array.of(_71, _73, old.x & 0xff));
boxed = { _0: data.length & 0xff, _1: 0 };
_81 = rt.u16Add(boxed._1, 1);
_198 = boxed;
_198._1 = _81;
_83 = rt.u16Add(boxed._1, 2);
_195 = boxed;
_195._1 = _83;
rt.byteVecExtendFromSlice(out, Uint8Array.of(boxed._0));
rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(boxed._1));
n = data.length as rt.u32;
both = [n, n] as [rt.u32, rt.u32];
n = 9;
Expand All @@ -196,8 +209,8 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void {
source = Uint8Array.of(data.length & 0xff);
returned = same(rt.copy(source));
source[0] = 9;
_128 = returned[0];
rt.byteVecExtendFromSlice(out, Uint8Array.of(_128, source[0]));
_145 = returned[0];
rt.byteVecExtendFromSlice(out, Uint8Array.of(_145, source[0]));
rt.byteVecPush(out, copyThenWrite([data.length & 0xff, 0] as [rt.u8, rt.u8]));
marked = mark(out, 1) === 0;
mark(out, 2);
Expand Down Expand Up @@ -1505,4 +1518,165 @@ export function library(data: Uint8Array, out: rt.ByteVec): void {
}
}

/** Steps a total by `x`: breaks with what it can't take, or continues with the new total. */
export function step(total: rt.u16, x: rt.u8): rt.Result<rt.u16, rt.u8 | undefined> {
let _3!: rt.u16 | undefined;
_3 = rt.u16CheckedAdd(total, rt.u16Mul(x as rt.u16, 64));
if (!(x === 0)) {
if (_3 === undefined) {
return rt.Err(255);
} else if (!(_3 > 8192)) {
return rt.Ok(_3);
} else {
return rt.Err(x);
}
} else {
return rt.Err(undefined);
}
}

/** A step that may be pending, as a polled read is. */
export function polled(x: rt.u8): rt.Poll<rt.Result<rt.Result<undefined, undefined>, rt.u8>> {
let _2!: rt.u8;
_2 = rt.u8Rem(x, 4);
if (_2 === 0) {
return rt.Pending;
} else if (_2 === 1) {
return rt.Err(x);
} else if (_2 === 2) {
return rt.Ok(rt.Err(undefined));
} else {
return rt.Ok(rt.Ok(undefined));
}
}

/**
* `ControlFlow`s made by hand rather than by `?`, and a value replaced through a
* `MutexGuard`.
*/
export function flows(data: Uint8Array, out: rt.ByteVec): void {
let total!: rt.u16;
let iterS!: Uint8Array;
let iterI!: number;
let _7!: rt.u8 | rt.Done;
let x!: rt.u8;
let flow!: rt.Result<rt.u16, rt.u8 | undefined>;
let _28!: rt.Poll<rt.Result<rt.Result<undefined, undefined>, rt.u8>>;
let a!: rt.u8;
let result!: rt.Result<rt.u16, rt.u8>;
let option!: rt.u8 | undefined;
let original!: rt.Result<Uint8Array, undefined>;
let copied!: rt.Result<Uint8Array, undefined>;
let _83!: rt.u8;
let iter2!: rt.Iter<rt.Result<Uint8Array, undefined>>;
let _93!: rt.Result<Uint8Array, undefined> | rt.Done;
let flow3!: rt.Result<Uint8Array, undefined>;
let slot!: rt.Mutex<rt.u8 | undefined>;
let iterS2!: Uint8Array;
let iterI2!: number;
let _106!: rt.u8 | rt.Done;
let x2!: rt.u8;
let held!: rt.Mutex<rt.u8 | undefined>;
let _113!: boolean;
let _114!: rt.u8 | undefined;
let _129!: rt.Mutex<rt.u8 | undefined>;
total = 0;
iterS = data;
iterI = 0;
while (true) {
_7 = iterI < iterS.length ? iterS[iterI++] : rt.DONE;
if (_7 === rt.DONE) {
rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(total));
a = rt.optionUnwrapOr(rt.sliceFirst(data), 0);
if (rt.u8Rem(a, 3) === 0) {
result = rt.Err(a);
} else {
result = rt.Ok(rt.u16Add(a as rt.u16, 256));
}
rt.byteVecPush(out, result.ok ? 1 : 0);
if (result.ok) {
rt.byteVecExtendFromSlice(out, rt.u16ToBeBytes(result.value));
} else {
rt.byteVecPush(out, (result as { ok: false; error: rt.u8 }).error);
}
if (rt.u8Rem(a, 5) === 0) {
option = undefined;
} else {
option = rt.u8Div(a, 5);
}
rt.byteVecPush(out, option === undefined ? 1 : 0);
if (option !== undefined) {
rt.byteVecPush(out, option);
} else {
rt.byteVecPush(out, 253);
}
original = rt.Ok(Uint8Array.of(a, 1));
copied = rt.copy(original);
if (copied.ok) {
_83 = rt.u8WrappingAdd(copied.value[0], 1);
copied.value[0] = _83;
}
iter2 = rt.iterSlice([original, rt.copy(copied)]);
while (true) {
_93 = iter2.next();
if (_93 === rt.DONE) {
slot = new rt.Mutex(undefined);
iterS2 = data;
iterI2 = 0;
while (true) {
_106 = iterI2 < iterS2.length ? iterS2[iterI2++] : rt.DONE;
if (_106 === rt.DONE) {
_129 = slot;
rt.byteVecPush(out, rt.optionUnwrapOr(_129.value, 252));
return;
} else {
x2 = _106;
held = slot;
_114 = held.value;
b9: {
if (_114 !== undefined) {
if (_114 >= x2) {
_113 = true;
break b9;
}
}
_113 = false;
}
if (!_113) {
held.value = x2;
}
}
}
} else {
flow3 = _93;
if (flow3.ok) {
rt.byteVecExtendFromSlice(out, flow3.value);
}
}
}
} else {
x = _7;
flow = step(total, x);
rt.byteVecExtendFromSlice(out, Uint8Array.of(!flow.ok ? 1 : 0, flow.ok ? 1 : 0));
if (flow.ok) {
total = flow.value;
} else if (flow.error === undefined) {
rt.byteVecPush(out, 254);
} else {
rt.byteVecPush(out, flow.error);
}
_28 = polled(x);
if (_28 !== rt.Pending) {
if (_28.ok) {
rt.byteVecPush(out, rt.u8Add(2, !_28.value.ok ? 1 : 0));
} else {
rt.byteVecPush(out, _28.error);
}
} else {
rt.byteVecPush(out, 0);
}
}
}
}

//# sourceMappingURL=shapes.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 @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec<u8> {
return out;
};
let (op, kind) = (*op, *kind);
match op % 38 {
match op % 39 {
0 => ints::u8_op(kind, data, &mut out),
1 => ints::u16_op(kind, data, &mut out),
2 => ints::u32_op(kind, data, &mut out),
Expand Down Expand Up @@ -67,7 +67,8 @@ pub fn run(input: &[u8]) -> Vec<u8> {
34 => collections::hash_maps(kind, data, &mut out),
35 => collections::sets(kind, data, &mut out),
36 => collections::btree_maps(kind, data, &mut out),
_ => collections::deques(data, &mut out),
37 => collections::deques(data, &mut out),
_ => shapes::flows(data, &mut out),
}
out
}
Loading