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/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [A deque's two slices](/quest/m3/ts-deque-slices.md) - `VecDeque::as_slices` and `{:?}` of a deque's `Iter`, `IterMut`, and `Drain` translate, split where std's are
- [Cow of a slice, and Wrapping](/quest/m3/ts-cow-slices.md) - `Cow<[T]>` and `Wrapping<T>` translate, `PartialEq` included
- [LinkedList](/quest/m3/ts-linked-list.md) - `LinkedList` and its methods translate
- [Zip's next_back in constant time](/quest/m3/ts-zip-back.md) - a reversed zip of random-access iterators skips the longer side's excess at once
- [Debug of Bound](/quest/m3/ts-bound-debug.md) - `{:?}` of a `Bound`, as a range's `start_bound` gives, translates
Expand Down
14 changes: 0 additions & 14 deletions quest/m3/ts-cow-slices.md

This file was deleted.

14 changes: 11 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `char` | `rt.char`: a `number` branded so, its Unicode scalar value |
| `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics |
| `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way |
| `Wrapping<T>` | the integer, whose operators wrap, and mask a shift's amount to the width, as std's do |
| `f64` | `rt.f64`: a `number` branded so, which is the same IEEE 754 double |
| `f32` | `rt.f32`: a `number` branded so, which a single holds exactly |
| `()`, `PhantomData<T>`, `PhantomPinned`, `..` | `undefined`, every value equal and hashing nothing; a type parameter only a `PhantomData` holds is `_T` in its struct's interface |
Expand All @@ -91,6 +92,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `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, but for a `Poll`'s `Pending` and `Ready(None)`, which continue as `Ok` of themselves |
| 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>` |
| `Cow<[T]>` | `rt.Cow<T>`: the `Vec` it owns, or an `rt.Borrowed` holding the slice it borrows; `rt.ByteCow` for bytes, an `rt.ByteVec` or an `rt.ByteSlice` |
| `&T`, `&mut T`, `Box<T>`, `Reverse<T>`, `NonZero<T>` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, a `String`, or a reference, or to an `Arc` or a `Waker`, is an `rt.Place<T>` |
| `*const T`, `*mut T`, `NonNull<T>` | what a `&mut T` is: the object, or an `rt.Place<T>` to a value JS copies and to a library type such as a `Vec` or an `Arc`; `rt.NULL` for null and `rt.DANGLING` for dangling. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there; a read copies what the crate writes into in place |
| `MaybeUninit<T>` | `T`: `undefined` until written, or an object whose parts kept as objects are there, holding `undefined` |
Expand Down Expand Up @@ -267,7 +269,9 @@ place and writes the string without the drained text as it drops, so one that
`mem::forget` leaks leaves it as it was, as std's does. A `String` keeps no capacity:
`with_capacity`, `reserve`, and `shrink_to_fit` do nothing, and `capacity` is refused. A `Cow<str>` is its text, borrowed or owned, so
`to_mut` borrows the `Cow`'s own place, and code that tells its variants apart, a `match`
on them or `Cow::is_borrowed`, is refused.
on them or `Cow::is_borrowed`, is refused. A `Cow<[T]>` keeps its variant in its class,
so a `match` reads it, and `to_mut` of a borrowed one stores a clone of its slice in the
`Cow`'s place before lending it.

Functions and members are camelCase. Functions are monomorphized: each instance is its
own function, suffixed after a `$` by its trait, then by its type's type arguments and
Expand Down Expand Up @@ -584,6 +588,10 @@ they need.
- A `Cow<str>` is a JS string, as `str` and `String` are, rather than an object tagged by
its variant: no `Cow<str>` in moq-net or kio tells its variants apart, and a tag would
wrap every value and unwrap it at every read.
- A `Cow<[T]>` is told apart by class, an owned one bare and a borrowed one in an
`rt.Borrowed`, so it clones and drops as std's does and only the borrowed side pays a
wrapper. Untagged, as `Cow<str>` is, `to_mut` would clone on every call and a `match`
would be refused; tagged, every `Cow` would be wrapped.
- A `Duration` keeps std's fields, whole seconds and nanoseconds, rather than one count
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.
Expand Down Expand Up @@ -672,7 +680,7 @@ hand-written TS ([bindings](#bindings)).
These fail translation: `f16` and `f128`, async closures, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, an instance of a generic type whose field is a `Poll` of a type parameter that can be pending, a closure that owns a value
that drops given to a std function that drops it beside another value that drops, other
than `for_each` and `fold`, as `reduce` of items that drop does, or keeps it other than in
an iterator adaptor, and values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str`, a std
an iterator adaptor, and values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str` or a slice, a std
function without a mapping of its own that makes or reads an `Option` whose `None` is
`rt.None`, as `Iterator::scan` of `Option`s does, an `Option` of an `Option` of `()` or another
`Option`, an instance of a generic type whose field is an `Option` of a type parameter
Expand Down Expand Up @@ -712,7 +720,7 @@ built natively for wasm32 and run beside its translation on the same inputs by
Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`,
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, `Cow<str>` borrowed and owned, `Duration`s whose
encoding's edges and the surrogates, `Cow<str>` and `Cow<[T]>` borrowed and owned, `Wrapping` at every width, `Duration`s whose
seconds pass 2^53 or reach `u64::MAX`, control flow,
patterns, `Copy` aggregates, those a container stores included and those written into
only in another module, behind a type parameter, or through a box, formatting, methods
Expand Down
32 changes: 31 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,34 @@ const compares = [[], [5], [1, 2, 3], [250, 251, 252, 253, 254, 255], [0xff, 3,
Array.from({ length: 256 }, (_, kind) => Uint8Array.of(comparesOp, kind, ...data)),
);

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods];
/**
* `wraps::*` of every kind at every width, over operands at the edges of its range: 0, 1,
* either end, the sign bit's neighbors, which make `MIN / -1`, and at 128 bits values past
* 2^64. Shift amounts are at, past, and many times past the width, which std masks.
*/
function wraps(): Uint8Array[] {
const widths: [string, number][] = [["u8s", 8], ["u16s", 16], ["u32s", 32], ["u64s", 64], ["u128s", 128], ["usizes", 32], ["i8s", 8], ["i16s", 16], ["i32s", 32], ["i64s", 64], ["i128s", 128], ["isizes", 32]];
const cases: Uint8Array[] = [];
for (const [name, bits] of widths) {
const o = op(`wraps::${name}`);
const width = BigInt(bits);
const mask = (1n << width) - 1n;
const sign = 1n << (width - 1n);
const edges = [0n, 1n, 3n, mask, mask - 1n, sign, sign - 1n, sign + 1n];
if (bits === 128) edges.push(1n << 64n, (1n << 64n) + 3n, 0x9e3779b97f4a7c150123456789abcdefn);
const be = (v: bigint) => Array.from({ length: bits / 8 }, (_, i) => Number((v >> BigInt(bits - 8 - 8 * i)) & 0xffn));
// The amount's low byte and its high byte, which reads as `high << 24`.
const shifts = [[0, 0], [1, 0], [bits - 1, 0], [bits, 0], [bits + 1, 0], [2 * bits + 3, 0], [5, 1]];
let i = 0;
for (const a of edges) {
for (const b of edges) {
const c = edges[(i * 5 + 3) % edges.length];
const [low, high] = shifts[i++ % shifts.length];
for (let kind = 0; kind < 24; kind++) cases.push(Uint8Array.of(o, kind, ...be(a), ...be(b), ...be(c), low, high));
}
}
}
return cases;
}

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps()];
52 changes: 49 additions & 3 deletions ts/fixtures/lang/expected/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3839,6 +3839,11 @@ export function each$Picky_Box_Picky_own_nes_closure15(v: Picky.Picky[], f: (a0:
return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 4, true);
}

/** `f` of each of `v`. */
export function each$Picky_Cow_Pickys_own_nes_closure18(v: Picky.Picky[], f: (a0: Picky.Picky) => rt.Cow<Picky.Picky>): rt.Cow<Picky.Picky>[] {
return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 12, true);
}

/** `f` of each of `v`. */
export function each$Picky_Option_Picky_own_nes_closure10(v: Picky.Picky[], f: (a0: Picky.Picky) => Picky.Picky | undefined): Array<Picky.Picky | undefined> {
return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 8, true);
Expand Down Expand Up @@ -3901,9 +3906,10 @@ export function each$Quirky_RefCell_Quirky_cell_eqs_closure5(v: Quirky.Quirky[],

/**
* `==` and `!=` of what holds a `Picky`, whose `ne` std's of tuples, `Arc`s, `Rc`s, and
* `Box`es call, and std's `==` of slices calls of each item, but which an `Option`'s and
* a `Reverse`'s `ne`, as `!eq`, does not: of unequal lengths, empty, nested, and with
* items `eq` and `ne` disagree on at the positions `kind` picks.
* `Box`es call, and std's `==` of slices and `Cow`s of them calls of each item, but which
* an `Option`'s, a `Reverse`'s, and a `Wrapping`'s `ne`, as `!eq`, does not: of unequal
* lengths, empty, nested, and with items `eq` and `ne` disagree on at the positions
* `kind` picks.
*/
export function ownNes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const _34: (a0: Picky.Picky[], a1: rt.usize) => rt.u16 = (v: Picky.Picky[], i: rt.usize): rt.u16 => {
Expand Down Expand Up @@ -4138,6 +4144,46 @@ export function ownNes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
putEq(rt.eqSeq((a41: Picky.Picky, b33: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a41, b33);
})(_485, _490), log, out);
const _496: [Picky.Picky] = [one(a, 0)];
const _504: [Picky.Picky] = [one(b, 0)];
putEq(!rt.eqTuple([Picky.eq$PartialEq])(_496, _504), log, out);
putEq(Picky.eq$PartialEq(one(a, 1), one(b, 1)), log, out);
const _531: [rt.Cow<Picky.Picky>, rt.Cow<Picky.Picky>] = [new rt.Borrowed(rt.sliceRange(a, 0)), b.map(Picky.clone$Clone)];
const ca: rt.Cow<Picky.Picky> = _531[0];
const cb: rt.Cow<Picky.Picky> = _531[1];
putEq(rt.eqSlice((a42: Picky.Picky, b34: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a42, b34);
})(rt.cowSlice(ca), rt.cowSlice(cb)), log, out);
putEq(!rt.eqSlice((a43: Picky.Picky, b35: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a43, b35);
})(rt.cowSlice(ca), rt.cowSlice(cb)), log, out);
const _553: Picky.Picky[] = rt.sliceRange(b, 0);
putEq(rt.eqSlice((a44: Picky.Picky, b36: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a44, b36);
})(rt.cowSlice(ca), _553), log, out);
putEq(!rt.eqSlice((a45: Picky.Picky, b37: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a45, b37);
})(rt.cowSlice(cb), a), log, out);
putEq(rt.eqSlice((a46: Picky.Picky, b38: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a46, b38);
})(b, rt.cowSlice(ca)), log, out);
const _570: Picky.Picky[] = rt.sliceRange(a, 0);
putEq(!rt.eqSlice((a47: Picky.Picky, b39: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a47, b39);
})(_570, rt.cowSlice(cb)), log, out);
const _576: Picky.Picky[] = rt.cowSlice(cb);
putEq(rt.eqSlice((a48: Picky.Picky, b40: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a48, b40);
})(_576, pa), log, out);
const owned: rt.Cow<Picky.Picky>[] = each$Picky_Cow_Pickys_own_nes_closure18(a, (p14: Picky.Picky): rt.Cow<Picky.Picky> => {
return [Picky.clone$Clone(p14)];
});
const borrowed: rt.Cow<Picky.Picky>[] = rt.iterToArray(rt.iterMap(rt.sliceChunks(b, 1), (a059: Picky.Picky[]): rt.Cow<Picky.Picky> => {
return new rt.Borrowed(a059);
}), undefined, 12, true);
putEq(!rt.eqSlice(rt.cowBy(rt.eqSlice((a49: Picky.Picky, b41: Picky.Picky): boolean => {
return !Picky.ne$PartialEq(a49, b41);
})))(owned, borrowed), log, out);
rt.dropAll(shared);
floated[Symbol.dispose]();
arc[Symbol.dispose]();
Expand Down
7 changes: 7 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ import type * as Short from "../splits.Short.ts";
import type * as Loud from "../zeros.Loud.ts";
import * as Tagged from "../zeros.Tagged.ts";

export function isSomeAnd$08u1px1(self: rt.Ordering | undefined, f: (a0: rt.Ordering) => boolean): boolean {
if (self === undefined) {
return false;
}
return f(self);
}

export function isSomeAnd$09tpccf(self: rt.u8 | undefined, f: (a0: rt.u8) => boolean): boolean {
if (self === undefined) {
return false;
Expand Down
48 changes: 48 additions & 0 deletions ts/fixtures/lang/expected/cows.Run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

export function clone$Clone(self: Run): Run {
return { words: rt.cowClone(self.words) };
}

export function fmt$Debug(self: Run, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
const _3: string = "Run";
const _4: string = "words";
const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtList(rt.cowSlice(self.words), f, rt.u16Debug);
return rt.debugStructFinish(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5));
}

export function default$Default(): Run {
const _1: rt.Cow<rt.u16> = [];
return { words: _1 };
}

export function eq$PartialEq(self: Run, other: Run): boolean {
return rt.eqSlice(rt.same)(rt.cowSlice(self.words), rt.cowSlice(other.words));
}

export function hash$Hash_DefaultHasher(self: Run, state: rt.Hasher): void {
rt.hashCow(rt.hashSlice(rt.hash16))(self.words, state);
}

/** A `Cow<[T]>` in a field, with each derived impl reading it. */
export interface Run {
words: rt.Cow<rt.u16>;
}

/** Through `to_mut` of the field. */
export function bump(self: Run): void {
const owned = rt.cowIntoOwned(self.words);
self.words = owned;
const iter: rt.Iter<rt.Place<rt.u16>> = rt.iterSliceMut(owned);
while (true) {
const _8: rt.Place<rt.u16> | rt.Done = iter.next();
if (_8 === rt.DONE) {
break;
}
_8.v = rt.u16WrappingAdd(_8.v, 1);
}
}

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

import * as rt from "./rt.ts";

/** An item whose `Clone` and `Drop` log, so what a `Cow` clones and drops shows. */
export class Tally {
_0: rt.u8;
_1: rt.Cell<rt.u32>;

constructor(_0: rt.u8, _1: rt.Cell<rt.u32>) {
this._0 = _0;
this._1 = _1;
}

[Symbol.dispose](): void {
drop$Drop(this);
}
}

export function clone$Clone(self: Tally): Tally {
rt.cellSet(self._1, rt.u32Add(rt.u32Add(rt.u32Mul(self._1.v, 7), self._0 as rt.u32), 1));
return new Tally(rt.u8WrappingAdd(self._0, 100), self._1);
}

export function drop$Drop(self: Tally): void {
rt.cellSet(self._1, rt.u32Add(rt.u32Mul(self._1.v, 3), self._0 as rt.u32));
}

//# sourceMappingURL=cows.Tally.ts.map
Loading