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 @@ -30,7 +30,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
- [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it
- [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
- [Share what the crate never changes in place](/quest/m2/ts-shared-read.md) - copies of `Copy` aggregates no one writes into in place go away, recovering #83's decode cost
- [Matches TypeScript has already narrowed](/quest/m2/ts-narrow-test.md) - an inner match on a value an outer match decided passes `tsc`
- [Small std gaps](/quest/m2/ts-std-gaps.md) - `bool::then`, `iter::successors`, `usize::from(bool)`, and `None.ok_or` narrowing
- [Copy-on-write strings](/quest/m2/ts-cow-str.md) - `Cow<str>` translates, finishing `ietf/namespace.rs`
Expand Down
31 changes: 0 additions & 31 deletions quest/m2/ts-shared-read.md

This file was deleted.

4 changes: 4 additions & 0 deletions ts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ and exports it as its own: `function new_` is `Decoder.new`. A `Copy` struct, en
or array, or an `Option`, `Result`, or `Poll` holding one, is copied where Rust copies
it, since JS would share the object: by a function of `lib.ts` made for its type, such
as `copy$Point`, which copies what it holds by value and shares what it holds by
reference.
reference. Only a type the crate writes into in place is copied, or one holding such a
type by value: a value of any other type never changes once made, so it is shared. A
write counts through a field, an element, a reference, or a box, and a mutable reference
a std function's parameters take, where the crate calls it or takes it as a value, or
one kept other than in a local, counts as a write into what it points at. A write over a type parameter counts for every type its bounds allow. A caller must
not change in place what it passes to or gets from the translation either.

A collection keeps Rust's key semantics. A hash map or set keeps a key that is a JS
number, string, or boolean in a JS `Map`, which compares those as Rust's `Eq` does, and
Expand Down Expand Up @@ -353,7 +358,8 @@ built natively for wasm32 and run beside its translation on the same inputs by
which must keep only those and what they call.
- `lang` covers every integer width's arithmetic and casts, `char`s next to each
encoding's edges and the surrogates, control flow, patterns, `Copy` aggregates, those
a container stores included, formatting, methods on generic types, iterators, with
a container stores included and those written into only in another module, behind a
type parameter, or through a box, formatting, methods on generic types, iterators, with
closures that log what each
adaptor reads, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord`
disagree with JS's, and `vec![x; n]` of types whose `Clone` counts its clones. Its differential test runs through `caller.ts`, a
Expand All @@ -363,6 +369,10 @@ built natively for wasm32 and run beside its translation on the same inputs by
with products of those values at 128 bits, 128-bit quotients by divisors below 2^32,
and their halves joined back.
`brands.ts`, another caller, mixes integer types where `tsc` must refuse them.
- `share` holds a `Copy` aggregate whose only write in the crate makes it copied, where
`lang`'s other writes into the same type would hide a write the analysis misses: a
byte array overwritten whole through a type parameter, or, under its features, by std
called directly or through a pointer a generic function calls.
- `task` trims moq's kio to a channel of `Arc`ed state, waiters, and wakers, under async
functions, beside values that drop inside std's types. Its caller is hand-written TS (`tests/task.ts`): a FIFO executor that runs a
script of spawns, sends, polls, and drops, and logs every poll, wake, and drop, as the
Expand Down
7 changes: 3 additions & 4 deletions ts/fixtures/codec/expected/coding/decode.Decoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "../rt.ts";
import { copy$Form } from "../lib.ts";
import * as DecodeError from "../coding/decode.DecodeError.ts";
import { read } from "../coding/varint.ts";
import type * as Form from "../coding/varint.Form.ts";
Expand Down Expand Up @@ -31,7 +30,7 @@ export interface Decoder {

/** Read `buf`, with varints in the given form. */
function new_(buf: rt.ByteSlice, form: Form.Form): Decoder {
return { buf, form: copy$Form(form), len: buf.length, need: 0, control: undefined, uncounted: 0 };
return { buf, form, len: buf.length, need: 0, control: undefined, uncounted: 0 };
}

/**
Expand Down Expand Up @@ -81,7 +80,7 @@ export function rest(self: Decoder): rt.ByteSlice {
export function sub(self: Decoder, len: rt.usize): rt.Result<Decoder, DecodeError.DecodeError> {
const _4: rt.Result<rt.ByteSlice, DecodeError.DecodeError> = slice(self, len);
if (_4.ok) {
return rt.Ok(new_(_4.value, copy$Form(self.form)));
return rt.Ok(new_(_4.value, self.form));
}
return _4;
}
Expand Down Expand Up @@ -127,7 +126,7 @@ export function bool(self: Decoder): rt.Result<boolean, DecodeError.DecodeError>
/** Read a varint. */
export function varint(self: Decoder): rt.Result<rt.u64, DecodeError.DecodeError> {
let _0!: rt.Result<rt.u64, DecodeError.DecodeError>;
const _2: rt.Result<[rt.u64, rt.ByteSlice], DecodeError.DecodeError> = read(self.buf, copy$Form(self.form));
const _2: rt.Result<[rt.u64, rt.ByteSlice], DecodeError.DecodeError> = read(self.buf, self.form);
if (_2.ok) {
const value: rt.u64 = _2.value[0];
self.buf = _2.value[1];
Expand Down
3 changes: 1 addition & 2 deletions ts/fixtures/codec/expected/coding/encode.Encoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "../rt.ts";
import { copy$Form } from "../lib.ts";
import * as EncodeError from "../coding/encode.EncodeError.ts";
import type * as Prefix from "../coding/encode.Prefix.ts";
import type * as PrefixKind from "../coding/encode.PrefixKind.ts";
Expand All @@ -22,7 +21,7 @@ export interface Encoder {

/** Append to `buf`, with varints in the given form. */
function new_(buf: rt.ByteVec, form: Form.Form): Encoder {
return { buf, form: copy$Form(form), control: undefined };
return { buf, form, control: undefined };
}

/** Write raw bytes. */
Expand Down
5 changes: 2 additions & 3 deletions ts/fixtures/codec/expected/coding/version.Versions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "../rt.ts";
import { copy$Version } from "../lib.ts";
import type * as DecodeError from "../coding/decode.DecodeError.ts";
import * as Decoder from "../coding/decode.Decoder.ts";
import type * as EncodeError from "../coding/encode.EncodeError.ts";
Expand Down Expand Up @@ -35,7 +34,7 @@ export function decode$Decode_Form(r: Decoder.Decoder, version: Form.Form): rt.R
while (iter.next() !== rt.DONE) {
const _15: rt.Result<Version.Version, DecodeError.DecodeError> = Version.decode$Decode_Form(r, version);
if (_15.ok) {
vs.push(copy$Version(_15.value));
vs.push(_15.value);
} else {
return _15;
}
Expand Down Expand Up @@ -76,7 +75,7 @@ export function encode$Encode_Version(self: Versions, w: Encoder.Encoder, versio
}

export function from$From_Versions(vs: Version.Version[]): Versions {
return { _0: vs.map(copy$Version) };
return { _0: vs.slice() };
}

//# sourceMappingURL=version.Versions.ts.map
13 changes: 0 additions & 13 deletions ts/fixtures/codec/expected/lib.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
// Generated by rust2-ts. Do not edit.

import type * as Timestamp from "./bench.Timestamp.ts";
import type * as Form from "./coding/varint.Form.ts";
import type * as Version from "./coding/version.Version.ts";

export function copy$Form(v: Form.Form): Form.Form {
if (v.tag === "LeadingOnes") {
return { tag: "LeadingOnes", seven: v.seven };
}
return v;
}

export function copy$Timestamp(v: Timestamp.Timestamp): Timestamp.Timestamp {
return { value: v.value, scale: v.scale };
}

export function copy$Version(v: Version.Version): Version.Version {
return { _0: v._0 };
}

//# sourceMappingURL=lib.ts.map
3 changes: 1 addition & 2 deletions ts/fixtures/lang/expected/chunks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$Option_u8s_u8s } from "./lib.ts";
import type * as Header from "./chunks.Header.ts";

export function header(data: rt.ByteSlice): Header.Header | undefined {
const _4: [rt.ByteSlice, rt.ByteSlice] | undefined = copy$Option_u8s_u8s(rt.byteSliceSplitFirstChunk(data, 2));
const _4: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitFirstChunk(data, 2);
if (_4 !== undefined) {
const val: [rt.ByteSlice, rt.ByteSlice] = _4;
return { tag: val[0], rest: val[1] };
Expand Down
25 changes: 12 additions & 13 deletions ts/fixtures/lang/expected/collections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$Bumped, copy$Clash, copy$Pair, copy$Rank, copy$Tally, copy$u8_Tally, copy$u8_str, copy$u8_u16, copy$u8_u16s, copy$u8_u8, copy$u8_u8s } from "./lib.ts";
import { copy$Bumped, copy$Tally, copy$u8_Tally, copy$u8_str, copy$u8_u16, copy$u8_u16s, copy$u8_u8, copy$u8_u8s } from "./lib.ts";
import * as Clash from "./collections.Clash.ts";
import * as Cloned from "./collections.Cloned.ts";
import * as Dir from "./collections.Dir.ts";
Expand Down Expand Up @@ -160,14 +160,14 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
const b3: rt.u8 = _167[1];
rt.byteVecPush(out, rt.optionUnwrapOr(rt.hashInsert(map3, { _0: a }, b3), 204));
const pair: Pair.Pair = { a: rt.u8Rem(a, 4), b: rt.u16Rem(b3 as rt.u16, 3) };
const t: Tally.Tally = rt.entryOrInsertWith(rt.entry(pairs, copy$Pair(pair)), Tally.default$Default);
const t: Tally.Tally = rt.entryOrInsertWith(rt.entry(pairs, pair), Tally.default$Default);
t.n = rt.u16Add(t.n, 1);
const r: Rank.Rank = rank(a, b3);
const _192: Tally.Tally | undefined = rt.hashGet(ranks, r);
if (_192 !== undefined) {
_192.n = rt.u16Add(_192.n, 1);
} else {
rt.hashInsert(ranks, copy$Rank(r), { n: i3 & 0xffff });
rt.hashInsert(ranks, r, { n: i3 & 0xffff });
}
const _203: rt.u8 = rt.u8Rem(a, 3);
const _207: rt.usize = rt.usizeRem(b3 as rt.usize, ["", "a", "ab", "b", "é", "", "￿", "𐀀"].length);
Expand Down Expand Up @@ -196,8 +196,7 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
}
const key: Pair.Pair = { a: 9, b: 9 };
const local: Tally.Tally = { n: 7 };
const _241: Tally.Tally = copy$Tally(local);
rt.hashInsert(pairs, copy$Pair(key), _241);
rt.hashInsert(pairs, key, copy$Tally(local));
local.n = 8;
const before: Tally.Tally = copy$Tally(rt.hashIndex(pairs, key));
const _246: Tally.Tally | undefined = rt.hashGet(pairs, key);
Expand Down Expand Up @@ -231,22 +230,22 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
const _292: [rt.u8, rt.u8] = [_293, data.data[data.start + i4]];
const a2: rt.u8 = _293;
const b4: rt.u8 = _292[1];
const _305: Rank.Rank = copy$Rank(rank(b4, a2));
const _305: Rank.Rank = rank(b4, a2);
const t4: Tally.Tally = rt.entryOrInsertWith(rt.entryAndModify(rt.entry(ranks, _305), (t9: Tally.Tally): void => {
t9.n = t9.n ^ 3;
}), (): Tally.Tally => {
return { n: b4 as rt.u16 };
});
t4.n = rt.u16WrappingAdd(t4.n, t4.n);
rt.idx(data, i4);
const _313: Rank.Rank = copy$Rank(rank(data.data[data.start + i4], 0));
const _313: Rank.Rank = rank(data.data[data.start + i4], 0);
const e: rt.Entry<Rank.Rank, Tally.Tally> = rt.entry(ranks, _313);
rt.byteVecPush(out, rankByte(rt.entryKey(e)));
rt.byteVecPush(out, rt.entryOrInsertWith(e, (k9: Rank.Rank): Tally.Tally => {
return { n: rankByte(k9) as rt.u16 };
}).n & 0xff);
}
const copy: rt.HashMap<Rank.Rank, Tally.Tally> = rt.hashClone(ranks, copy$Rank, copy$Tally);
const copy: rt.HashMap<Rank.Rank, Tally.Tally> = rt.hashClone(ranks, undefined, copy$Tally);
const _327: Tally.Tally | undefined = rt.hashGet(copy, { tag: "Low" } as Rank.Rank);
if (_327 !== undefined) {
_327.n = 119;
Expand Down Expand Up @@ -332,7 +331,7 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
return true;
});
const _473: rt.Iter<[Rank.Rank, rt.u16]> = rt.iterMap(rt.hashIter(ranks), (_224: [Rank.Rank, Tally.Tally]): [Rank.Rank, rt.u16] => {
return [copy$Rank(_224[0]), _224[1].n] as [Rank.Rank, rt.u16];
return [_224[0], _224[1].n] as [Rank.Rank, rt.u16];
});
const iter14: rt.Iter<[Rank.Rank, rt.u16]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(Rank.cmp$Ord) as rt.BTreeMap<Rank.Rank, rt.u16>, _473, true));
while (true) {
Expand Down Expand Up @@ -397,7 +396,7 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
return t6.n & 0xff;
}));
} else {
rt.byteVecPush(out, rt.optionMapOr(rt.hashInsert(clashes, copy$Clash(k6), { n: i5 & 0xffff }), 204, (t5: Tally.Tally): rt.u8 => {
rt.byteVecPush(out, rt.optionMapOr(rt.hashInsert(clashes, k6, { n: i5 & 0xffff }), 204, (t5: Tally.Tally): rt.u8 => {
return t5.n & 0xff;
}));
}
Expand All @@ -412,7 +411,7 @@ export function hashMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
return k8._0;
});
rt.iterExtendBytes(out, rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, _583, true)));
const copy3: rt.HashMap<Clash.Clash, Tally.Tally> = rt.hashClone(clashes, copy$Clash, copy$Tally);
const copy3: rt.HashMap<Clash.Clash, Tally.Tally> = rt.hashClone(clashes, undefined, copy$Tally);
rt.byteVecPush(out, rt.hashLen(copy3) & 0xff);
rt.byteVecPush(out, rt.hashContains(copy3, { _0: 1 }) ? 1 : 0);
}
Expand Down Expand Up @@ -676,7 +675,7 @@ export function btreeMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): voi
const _170: [rt.u8, rt.u8] = [_171, data.data[data.start + i2]];
const a: rt.u8 = _171;
const b: rt.u8 = _170[1];
const _182: Rank.Rank = copy$Rank(rank(a, b));
const _182: Rank.Rank = rank(a, b);
const t: Tally.Tally = rt.entryOrInsertWith(rt.entry(ranks, _182), Tally.default$Default);
t.n = rt.u16WrappingAdd(t.n, b as rt.u16);
const _188: [rt.u8, rt.u8] = [rt.u8Rem(a, 4), rt.u8Rem(b, 4)];
Expand All @@ -690,7 +689,7 @@ export function btreeMaps(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): voi
}
for (const b2 of rt.byteSliceView(data)) {
const r: Rank.Rank = rank(b2, rt.u8Div(b2, 3));
const _212: rt.Entry<Rank.Rank, Tally.Tally> = rt.entry(ranks, copy$Rank(r));
const _212: rt.Entry<Rank.Rank, Tally.Tally> = rt.entry(ranks, r);
if (!rt.entryOccupied(_212)) {
const e: rt.Entry<Rank.Rank, Tally.Tally> = _212;
rt.byteVecPush(out, rankByte(rt.entryKey(e)));
Expand Down
5 changes: 2 additions & 3 deletions ts/fixtures/lang/expected/fmt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$Pair$2 } from "./lib.ts";
import * as Bare from "./fmt.Bare.ts";
import * as Braced from "./fmt.Braced.ts";
import * as Fails from "./fmt.Fails.ts";
Expand Down Expand Up @@ -198,7 +197,7 @@ export function nested(data: rt.ByteSlice): Nested.Nested {
_22 = { tag: "Rect", corner: { x: 0, y: 0 }, width: at(3) as rt.u16, height: 9 } as Shape.Shape;
}
const _35: rt.ByteVec = rt.byteSliceToByteVec(rt.byteSliceRange(data, 0, rt.min(data.length, 4)));
const _40: Pair.Pair[] = [{ _0: at(4), _1: -1 }, { _0: 2, _1: { hi: -0x80000000, lo: 0 } as rt.i64 }].map(copy$Pair$2);
const _40: Pair.Pair[] = [{ _0: at(4), _1: -1 }, { _0: 2, _1: { hi: -0x80000000, lo: 0 } as rt.i64 }].slice();
if (!(rt.u8Rem(at(5), 2) === 0)) {
_49 = undefined;
} else {
Expand Down Expand Up @@ -303,7 +302,7 @@ export function written(data: rt.ByteSlice, out: rt.ByteVec): void {
const empty: Manual.Manual = { id: 0, list: [] };
const args6: rt.Fmt[] = [(f: rt.Formatter) => Manual.fmt$Debug(manual, f), (f: rt.Formatter) => Manual.fmt$Debug(empty, f)];
put(out, rt.fmtFormat([args6[0], " ", rt.fmtSpec({ alternate: true }, args6[0]), " ", args6[1]]));
const seq: Seq.Seq = { _0: [{ _0: at(3), _1: 0 }, { _0: 1, _1: -1 }].map(copy$Pair$2) };
const seq: Seq.Seq = { _0: [{ _0: at(3), _1: 0 }, { _0: 1, _1: -1 }].slice() };
const none: Seq.Seq = { _0: [] };
const args8: rt.Fmt[] = [(f: rt.Formatter) => Seq.fmt$Debug(seq, f), (f: rt.Formatter) => Seq.fmt$Debug(none, f)];
put(out, rt.fmtFormat([args8[0], " ", rt.fmtSpec({ alternate: true }, args8[0]), " ", args8[1], " ", rt.fmtSpec({ alternate: true }, args8[1])]));
Expand Down
28 changes: 27 additions & 1 deletion ts/fixtures/lang/expected/generics.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$Either_u8_Points, copy$Wrap_Point, copy$Wrap_i16, copy$Wrap_u8 } from "./lib.ts";
import { copy$Either_u8_Points, copy$Gauge, copy$Wrap_Point, copy$Wrap_i16, copy$Wrap_u8 } from "./lib.ts";
import { put } from "./fmt.ts";
import type * as Pair from "./fmt.Pair.ts";
import * as Either from "./generics.Either.ts";
import * as Tagged from "./generics.Tagged.ts";
import * as Wrap from "./generics.Wrap.ts";
import * as Gauge from "./shapes.Gauge.ts";
import type * as Meters from "./shapes.Meters.ts";
import * as Point from "./shapes.Point.ts";
import type * as Shape from "./shapes.Shape.ts";
import type * as Track from "./shapes.Track.ts";

/** Each method once per instance: `Wrap` of a struct, an enum, a number, and itself. */
export function methods(data: rt.ByteSlice, out: rt.ByteVec): void {
Expand Down Expand Up @@ -73,4 +75,28 @@ export function methods(data: rt.ByteSlice, out: rt.ByteVec): void {
rt.byteVecPush(out, rt.optionUnwrapOr(Either.left$u8_u16(tagged.key), 0));
}

/**
* Moves `track`'s mark on: the crate's only write into a `Mark`, in another module than
* the copy of one that must not see it.
*/
export function advance(track: Track.Track): void {
const _2: rt.u8 = rt.u8WrappingAdd(track.mark.at, 1);
track.mark.at = _2;
}

/**
* Resets each of `xs`, writing into each one in place, which only an instance knows the
* type of.
*/
export function reset$Gauge(xs: Gauge.Gauge[]): void {
const iter: rt.Iter<Gauge.Gauge> = rt.iterSlice(xs);
while (true) {
const _5: Gauge.Gauge | rt.Done = iter.next();
if (_5 === rt.DONE) {
break;
}
Object.assign(_5, copy$Gauge(Gauge.default$Default()));
}
}

//# sourceMappingURL=generics.ts.map
Loading