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 @@ -31,7 +31,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
- [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
- [Iterator skips that read as std's](/quest/m2/ts-iter-nth.md) - `nth` and `nth_back` of what drops nothing read the items std's do
- [Share constant aggregates](/quest/m2/ts-const-share.md) - `Ok(())` and other constants nothing writes into are one frozen object
- [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
- [Waiting: Swift 6.4 in nixpkgs-unstable](/quest/m2/uniffi-swift-arm.md) - the nightly UniFFI fixtures move back to arm
- [Waiting: ubrn reads UniFFI 0.32](/quest/m2/ubrn-release.md) - the binding benchmark's browser runner pins a ubrn release, not an open PR
36 changes: 0 additions & 36 deletions quest/m2/ts-const-share.md

This file was deleted.

11 changes: 8 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ in `rt/str.ts`, collections in `rt/collections.ts`, ownership and async in
| `enum` without data | a union of strings: `"Lite01" \| "Lite02"`, or `never` without variants |
| `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 }` |
| `Result<T, E>` | `rt.Result<T, E>`: `{ ok: true, value }` or `{ ok: false, error }`; `rt.OK` or `rt.ERR` where the payload is `undefined`, as in `Ok(())` |
| `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; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec<u8>` |
| `&T`, `&mut T`, `Box<T>` | the value: a `&mut` must point at an object JS can change in place, or at a map's value through an `rt.Place` |
Expand Down Expand Up @@ -285,8 +285,13 @@ they need.
of nanoseconds, so its overflow, `checked_*`, and ordering are std's exactly, and a
lowering of its methods from core's MIR would read the same fields.
- `Result` is a plain `{ ok, value } | { ok, error }` object rather than an exception, so
`?` and `match` keep Rust's control flow exactly. Making no `Ok` objects at all measured
no faster on `just ts bench`, in V8 or JavaScriptCore.
`?` and `match` keep Rust's control flow exactly. One whose payload is `undefined`, such
as `Ok(())`, is one frozen object every evaluation shares, since nothing writes into a
result in place and engines don't remove one returned through a call they don't inline:
`just ts bench` measured the codec's encode workloads at 0.90 times their time without
it in Chrome, 0.75 in Firefox, and 0.75 in Bun at the geometric mean, with A/A within
0.03 in Chrome and Node within its noise. Sharing a result of any other constant, such
as `Err(DecodeError::Short)`, measured no faster on the decodes that return it.
- A `&[u8]` is an `rt.ByteSlice` rather than a `Uint8Array` view, since a view costs
several times what an object does to make in V8 and JavaScriptCore, and a varint's
decode splits its slice once to four times. `just ts bench` measured the codec's decode
Expand Down
12 changes: 6 additions & 6 deletions ts/fixtures/codec/expected/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function encodeVarints(data: rt.ByteSlice, form_: Form.Form, out: rt.Byte
return _17;
}
}
return rt.Ok(undefined);
return rt.OK;
}

/** Every varint on the wire: how many, and the last. */
Expand All @@ -99,7 +99,7 @@ export function decodeVarints(wire: rt.ByteSlice, form_: Form.Form, out: rt.Byte
}
putUsize(out, count);
putU64(out, last);
return rt.Ok(undefined);
return rt.OK;
}

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ export function encodeFrames(data: rt.ByteSlice, version: Version.Version, out:
return _45;
}
}
return rt.Ok(undefined);
return rt.OK;
}

/** Every FRAME header on the wire: how many, their total size, and the last delta. */
Expand All @@ -183,7 +183,7 @@ export function decodeFrames(wire: rt.ByteSlice, version: Version.Version, out:
putUsize(out, count);
putU64(out, total);
putU64(out, rt.u64Cast(last));
return rt.Ok(undefined);
return rt.OK;
}

/**
Expand Down Expand Up @@ -231,7 +231,7 @@ export function decodeSplit(data: rt.ByteSlice, version: Version.Version, out: r
putU64(out, total);
putU64(out, rt.u64Cast(last));
putUsize(out, short);
return rt.Ok(undefined);
return rt.OK;
}
return rt.Err({ tag: "Short" } as DecodeError.DecodeError);
}
Expand Down Expand Up @@ -505,7 +505,7 @@ export function decodeGroup(wire: rt.ByteSlice, version: Version.Version, out: r
putU64(out, group.sequence);
putU64(out, group.frameStart);
putUsize(out, used);
return rt.Ok(undefined);
return rt.OK;
}
return _6;
}
Expand Down
8 changes: 4 additions & 4 deletions ts/fixtures/codec/expected/coding/encode.Encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function bool(self: Encoder, v: boolean): void {
/** Write a varint, or fail with [`EncodeError::BoundsExceeded`] if the form cannot carry it. */
export function varint(self: Encoder, v: rt.u64): rt.Result<undefined, EncodeError.EncodeError> {
if (write(v, self.form, self.buf).ok) {
return rt.Ok(undefined);
return rt.OK;
}
return rt.Err(EncodeError.from$From_BoundsExceeded({}));
}
Expand All @@ -73,7 +73,7 @@ export function bytes(self: Encoder, v: rt.ByteSlice): rt.Result<undefined, Enco
const _3: rt.Result<undefined, EncodeError.EncodeError> = varint(self, v.length as rt.u64);
if (_3.ok) {
slice(self, v);
return rt.Ok(undefined);
return rt.OK;
}
return _3;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ export function fill(self: Encoder, prefix: Prefix.Prefix): rt.Result<undefined,
const _79: rt.ByteVec = self.buf;
_79.data[rt.idx(_79, rt.usizeSub(body, 1))] = _35;
rt.byteVecTruncate(self.buf, end);
return rt.Ok(undefined);
return rt.OK;
}
} else {
return rt.Err(EncodeError.from$From_BoundsExceeded({}));
Expand All @@ -156,7 +156,7 @@ export function fill(self: Encoder, prefix: Prefix.Prefix): rt.Result<undefined,
return _7;
}
}
return rt.Ok(undefined);
return rt.OK;
}

export { new_ as new };
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/coding/varint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function write(value: rt.u64, form: Form.Form, out: rt.ByteVec): rt.Resul
return writeQuic(value, out);
}
writeLeadingOnes(value, out);
return rt.Ok(undefined);
return rt.OK;
}

export function writeQuic(value: rt.u64, out: rt.ByteVec): rt.Result<undefined, BoundsExceeded.BoundsExceeded> {
Expand Down Expand Up @@ -135,7 +135,7 @@ export function writeQuic(value: rt.u64, out: rt.ByteVec): rt.Result<undefined,
const _48: Uint8Array = rt.u32ToBeBytes(lo);
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a, b, c, d, _48[0], _48[1], _48[2], _48[3])));
}
return rt.Ok(undefined);
return rt.OK;
}

export function writeLeadingOnes(value: rt.u64, out: rt.ByteVec): void {
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/coding/version.Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function decode$Decode_Form(r: Decoder.Decoder, _2: Form.Form): rt.Result
export function encode$Encode_Form(self: Version, w: Encoder.Encoder, _3: Form.Form): rt.Result<undefined, EncodeError.EncodeError> {
const _4: rt.Result<undefined, EncodeError.EncodeError> = Encoder.varint(w, self._0);
if (_4.ok) {
return rt.Ok(undefined);
return rt.OK;
}
return _4;
}
Expand All @@ -35,7 +35,7 @@ export function encode$Encode_Form(self: Version, w: Encoder.Encoder, _3: Form.F
export function encode$Encode_Version(self: Version, w: Encoder.Encoder, _3: version_Version.Version): rt.Result<undefined, EncodeError.EncodeError> {
const _4: rt.Result<undefined, EncodeError.EncodeError> = Encoder.varint(w, self._0);
if (_4.ok) {
return rt.Ok(undefined);
return rt.OK;
}
return _4;
}
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/coding/version.Versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function encode$Encode_Form(self: Versions, w: Encoder.Encoder, version:
return _18;
}
}
return rt.Ok(undefined);
return rt.OK;
}
return _4;
}
Expand All @@ -69,7 +69,7 @@ export function encode$Encode_Version(self: Versions, w: Encoder.Encoder, versio
return _18;
}
}
return rt.Ok(undefined);
return rt.OK;
}
return _4;
}
Expand Down
14 changes: 7 additions & 7 deletions ts/fixtures/codec/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export function decodeStep(r: Decoder.Decoder, step: rt.u8, out: rt.ByteVec): rt
} else {
putUsize(out, Decoder.rest(r).length);
}
return rt.Ok(undefined);
return rt.OK;
}

/** Write primitives as a script says, taking each value from the data that follows. */
Expand All @@ -323,13 +323,13 @@ export function encodeScript(data: rt.ByteSlice, out: rt.ByteVec): void {
const _33: rt.u8 = rt.u8Rem(step, 10);
if (_33 === 0) {
Encoder.u8(w, rt.u64Low(value) & 0xff);
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
} else if (_33 === 1) {
Encoder.u16(w, rt.u64Low(value) & 0xffff);
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
} else if (_33 === 2) {
Encoder.bool(w, rt.u64And(value, 1) === 1);
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
} else if (_33 === 3) {
result = Encoder.varint(w, value);
} else if (_33 === 4) {
Expand Down Expand Up @@ -360,11 +360,11 @@ export function encodeScript(data: rt.ByteSlice, out: rt.ByteVec): void {
_74 = Encoder.prefixU16(w);
}
prefixes.push(_74);
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
} else if (_33 === 8) {
const _79: Prefix.Prefix | undefined = prefixes.pop();
if (_79 === undefined) {
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
} else {
const prefix: Prefix.Prefix = _79;
putUsize(out, Encoder.since(w, prefix));
Expand All @@ -375,7 +375,7 @@ export function encodeScript(data: rt.ByteSlice, out: rt.ByteVec): void {
if (_88 !== undefined) {
Encoder.discard(w, _88);
}
result = rt.Ok(undefined);
result = rt.OK as rt.Result<undefined, EncodeError.EncodeError>;
}
if (!result.ok) {
encodeFailed(out, result.error);
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/lite/group.Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function encodeMsg$Message(self: Group, w: Encoder.Encoder, version: Vers
return _15;
}
}
return rt.Ok(undefined);
return rt.OK;
}
return _9;
}
Expand All @@ -84,7 +84,7 @@ export function encode$Encode_Version(self: Group, w: Encoder.Encoder, version:
const _49: rt.Result<undefined, EncodeError.EncodeError> = Encoder.fill(w, prefix);
if (_49.ok) {
w.control = undefined;
return rt.Ok(undefined);
return rt.OK;
}
return _49;
}
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/lite/probe.Probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function encode$Encode_Version(self: Probe, w: Encoder.Encoder, version:
const _49: rt.Result<undefined, EncodeError.EncodeError> = Encoder.fill(w, prefix);
if (_49.ok) {
w.control = "Probe" as Control.Control;
return rt.Ok(undefined);
return rt.OK;
}
return _49;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ export function encodeMsg$Message(self: Probe, w: Encoder.Encoder, version: Vers
return _17;
}
}
return rt.Ok(undefined);
return rt.OK;
}
return _9;
}
Expand Down
Loading