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
2 changes: 1 addition & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's consumers, flattens, and collects drop as std's do
- [Fresh writes in a body generic over a type](/quest/m3/ts-fresh-type-params.md) - a whole write into fresh memory holding a type parameter's values fills it, as one generic over a length alone does
- [A generic type's bytes at u8](/quest/m3/ts-generic-byte-fields.md) - a `[T; N]`, `Vec<T>`, or `&[T]` field of a generic type is typed as its `u8` instance holds it, or refused
- [std's conversions of a reference](/quest/m3/ts-ref-conversions.md) - `to_owned`, `clone_from`, `binary_search`, `size_of_val`, `from_ref`/`from_mut`, and `AsRef`/`Borrow` as a slice translate
- [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
- [Places through an adaptor's argument](/quest/m3/ts-adaptor-places.md) - `iter.zip(&mut v)` of values JS copies lends places as `for x in &mut v` does
- [std's sorts call their tests in std's order](/quest/m3/ts-sort-order.md) - `slice::sort` and a B-tree's `collect` call `lt` or `cmp` as std's driftsort does past 16 elements
- [A B-tree's searches call Ord as std's do](/quest/m3/ts-btree-search-order.md) - a B-tree's lookups and inserts call a key's own `Ord` in std's order and number
- [Rc and Arc of a slice](/quest/m3/ts-shared-slices.md) - `Rc<[T]>` and `Arc<[T]>` from a `Vec`, a slice, or an iterator translate
- [The rest of a boxed slice's impls](/quest/m3/ts-boxed-slice-rest.md) - `clone_from`, `AsRef`, `AsMut`, `TryFrom` into a boxed array, and `Box<str>` into bytes translate for boxed slices
- [The rest of a guard's methods](/quest/m3/ts-guard-rest.md) - `Debug` of `RefCell` and `RwLock` guards, `MutexGuard::map`, and the guards' `try_map` translate
- [Aborts in the differential](/quest/m3/ts-abort-differential.md) - the lang differential compares wasm32's aborts, so an `RwLock` locked again while held is tested
Expand Down
22 changes: 0 additions & 22 deletions quest/m3/ts-generic-byte-fields.md

This file was deleted.

17 changes: 17 additions & 0 deletions quest/m3/ts-shared-slices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [S] Rc and Arc of a slice

## Goal

[rust2-ts](/ts/README.md) translates an `Rc<[T]>` and an `Arc<[T]>` made from a `Vec`, a
slice, or an iterator, read as the slice, cloned, and dropped, proven by a differential
test against native Rust at `u8`, at another element, and at one that drops.

## Plan

Found writing [a generic type's byte fields](https://github.com/moq-dev/rust2/pull/375)'
fixture: `Rc::from(vec)` and `Rc::from(slice)` are refused as unsupported calls to
`From`. A shared slice is what a generic type's `[T]` already is, so the form of a
`u8` instance is the open question: an `rt.ByteSlice` as a `Box<[u8]>` is, or one that
counts its owners as `rt.Arc` does.

Public API: the translator's output.
5 changes: 5 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
the form of, such as `*mut T`, `NonNull<T>`, or `&'a mut T`, is an `rt.Ptr<T>`, the
object, an `rt.Place<T>`, or an `rt.ByteSlice`, rather than `rt.Place<T>` or `T`: a
caller reading one casts it to what its instance holds, as the output does.
- A generic type's field holding a run of a type parameter is an `rt.ArrayOf<T>` for
`[T; N]`, an `rt.SliceOf<T>` for `[T]` behind a reference or a `Box`, an `rt.VecOf<T>`
for `Vec<T>`, or an `rt.CowOf<T>` for `Cow<[T]>`, rather than `T[]` or `rt.Cow<T>`:
each also holds the byte form of its `u8` instance, which a caller reading one casts
it to, as the output does.
- A closure, a `fn` pointer, a `dyn Fn`, or a function item as a value returns
`undefined` for `()`, not `void`, as in `(a0: rt.u8) => undefined`: a caller passes such
a parameter a function typed `=> undefined`.
Expand Down
12 changes: 8 additions & 4 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ type is one instance's, declaring the instance it takes as `self`:
`fmt$fmt_Debug_fmt_Pair(self: Wrap<Pair.Pair>, f: rt.Formatter)`. A reference or pointer
in a generic type to what only an instance decides the form of, such as `*mut T` or
`&'a mut T`, is an `rt.Ptr<T>`: the object, an `rt.Place<T>`, or an `rt.ByteSlice`,
which each read of an instance's field casts to what it holds. A type's module exports the
which each read of an instance's field casts to what it holds. So is a run of a
parameter, whose `u8` instance holds bytes: `[T; N]` is an `rt.ArrayOf<T>`, a `T[]` or a
`Uint8Array`, and `[T]`, `Vec<T>`, and `Cow<[T]>` an `rt.SliceOf<T>`, an `rt.VecOf<T>`,
and an `rt.CowOf<T>`. A type's module exports the
type by its own name, which a caller writes `Decoder.Decoder`, and a function whose name
and exports it as its own: `function new_` is `Decoder.new`. A module imports a function
or value by its name, and a type's module whole by the type's, `import * as Decoder`,
Expand Down Expand Up @@ -846,7 +849,9 @@ built natively for wasm32 and run beside its translation on the same inputs by
`NonZero`, and raw pointers: a linked list of boxed nodes as `hashlink` keeps one, through a union and a
`MaybeUninit` entry, pointers to locals, fields, and whole structs, those
`UnsafeCell::get` gives, as crossbeam-epoch's own `OnceLock` keeps its collector, and
those a generic type holds to its parameter, at each form a pointer takes. Its
those a generic type holds to its parameter, at each form a pointer takes, and a
generic type's arrays, slices, `Vec`s, and `Cow`s of its parameter at bytes, at
`u16`, and at values that drop. Its
differential test runs through `caller.ts`, a
hand-written caller that also prints a `printable` error nothing translated prints,
and adds every 64- and 128-bit case over each pair of values next to a power of two,
Expand Down Expand Up @@ -889,8 +894,7 @@ built natively for wasm32 and run beside its translation on the same inputs by
from either end, and its `shared` feature adds a module of the dependency's name, with
the errors in `refused.txt`, `rev.txt`, and `shared.txt`.
- `reject` holds constructs outside the subset; its expected errors are `expected.txt`,
and its expected census is `census.md`. `mistyped.toml` translates a typing gap that
`tsc` rejects, with the errors in `mistyped.txt`.
and its expected census is `census.md`.

`tests/spawn.ts` checks that `rt.spawn` yields to a timer after its 128-poll budget, and
rejects when a future panics as it drops. `tests/retain.ts` runs a collection's `retain`
Expand Down
7 changes: 7 additions & 0 deletions ts/fixtures/lang/expected/core/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ export function then$0afp4no(self: boolean, f: () => rt.Result<rt.u8, rt.ParseIn
return f();
}

export function then$0h950d8(self: boolean, _: () => rt.u16[]): rt.u16[] | undefined {
if (!self) {
return undefined;
}
return [];
}

export function then$1i9qaz4(self: boolean, _: () => rt.ByteVec): rt.ByteVec | undefined {
if (!self) {
return undefined;
Expand Down
29 changes: 29 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type * as cycles_Logged from "../cycles.Logged.ts";
import * as defaults_Made from "../defaults.Made.ts";
import type * as dyns_Shape from "../dyns.Shape.ts";
import * as edits_Named from "../edits.Named.ts";
import type * as Ticked from "../generics.Ticked.ts";
import type * as hints_Unit from "../hints.Unit.ts";
import type * as Badge from "../iters.Badge.ts";
import type * as Quarter from "../iters.Quarter.ts";
Expand Down Expand Up @@ -248,6 +249,13 @@ export function unwrapOrDefault$0k1p6nh(self: [rt.u64 | undefined, defaults_Made
return self;
}

export function unwrapOrDefault$001fvl5(self: rt.u16 | undefined): rt.u16 {
if (self === undefined) {
return 0;
}
return self;
}

export function unwrapOrDefault$1q0ps0j(self: rt.u8 | undefined): rt.u8 {
if (self === undefined) {
return 0;
Expand Down Expand Up @@ -621,6 +629,13 @@ export function map$0rbsrz6(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8 | u
return f(self);
}

export function map$12l9avg(self: rt.u8 | undefined, f: (a0: rt.u8) => Ticked.Ticked[]): Ticked.Ticked[] | undefined {
if (self === undefined) {
return undefined;
}
return f(self);
}

export function map$1qp1ym6(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u32): rt.u32 | undefined {
if (self === undefined) {
return undefined;
Expand Down Expand Up @@ -1856,6 +1871,20 @@ export function clone$14nprly(self: string | undefined): string | undefined {
return self;
}

export function clone$096c3ul(self: rt.u16[] | undefined): rt.u16[] | undefined {
if (self === undefined) {
return undefined;
}
return self.slice();
}

export function clone$1grnave(self: rt.ByteVec | undefined): rt.ByteVec | undefined {
if (self === undefined) {
return undefined;
}
return rt.byteVecFrom(rt.byteVecView(self));
}

export function clone$0vcwlo5(self: edits_Named.Named | undefined): edits_Named.Named | undefined {
if (self === undefined) {
return undefined;
Expand Down
36 changes: 36 additions & 0 deletions ts/fixtures/lang/expected/generics.Fixed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Generated by rust2-ts. Do not edit.

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

export function fmt$fmt_Debug_u16(self: Fixed<rt.u16>, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
const arg = self.pair as rt.u16[];
const _3: string = "Fixed";
const _4: string = "pair";
const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtList(arg, f, rt.u16Debug);
const _7: string = "tag";
const _8: rt.Fmt = (f: rt.Formatter) => rt.u8Debug(self.tag, f);
return rt.debugStructFinish(rt.debugStructField(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5), _7, _8));
}

export function fmt$fmt_Debug_u8(self: Fixed<rt.u8>, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
const _3: string = "Fixed";
const _4: string = "pair";
const _6: rt.ByteSlice = rt.byteSliceFrom(self.pair as Uint8Array);
const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_6), f, rt.u8Debug);
const _7: string = "tag";
const _8: rt.Fmt = (f: rt.Formatter) => rt.u8Debug(self.tag, f);
return rt.debugStructFinish(rt.debugStructField(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5), _7, _8));
}

/** A generic type JS copies, holding an array of its parameter. */
export class Fixed<T> {
pair: rt.ArrayOf<T>;
tag: rt.u8;

constructor(pair: rt.ArrayOf<T>, tag: rt.u8) {
this.pair = pair;
this.tag = tag;
}
}

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

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

/**
* A generic type lending a run of its parameter, which it writes through, and a function
* of one.
*/
export interface Lends<T> {
run: rt.SliceOf<T>;
last: (a0: rt.SliceOf<T>) => rt.Ptr<T> | undefined;
}

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

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

export function fmt$fmt_Debug_u16(self: Run<rt.u16>, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
if (self.tag === "Listed") {
const arg2 = self._0 as rt.u16[];
const _5: string = "Listed";
const _6: rt.Fmt = (f: rt.Formatter) => rt.fmtList(arg2, f, rt.u16Debug);
return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _5), _6));
}
if (self.tag === "Fixed") {
const arg = self.array as rt.u16[];
const _9: string = "Fixed";
const _10: string = "array";
const _11: rt.Fmt = (f: rt.Formatter) => rt.fmtList(arg, f, rt.u16Debug);
return rt.debugStructFinish(rt.debugStructField(rt.fmtDebugStruct(f, _9), _10, _11));
}
return rt.fmtWriteStr(f, "Empty");
}

export function fmt$fmt_Debug_u8(self: Run<rt.u8>, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
if (self.tag === "Listed") {
const arg = self._0 as rt.ByteVec;
const _5: string = "Listed";
const _6: rt.Fmt = (f: rt.Formatter) => rt.fmtList(rt.byteVecView(arg), f, rt.u8Debug);
return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _5), _6));
}
if (self.tag === "Fixed") {
const __self0: rt.ByteSlice = rt.byteSliceFrom(self.array as Uint8Array);
const _9: string = "Fixed";
const _10: string = "array";
const _11: rt.Fmt = (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(__self0), f, rt.u8Debug);
return rt.debugStructFinish(rt.debugStructField(rt.fmtDebugStruct(f, _9), _10, _11));
}
return rt.fmtWriteStr(f, "Empty");
}

/** An enum holding a run of its parameter in a variant. */
export type Run<T> =
| { tag: "Listed"; _0: rt.VecOf<T> }
| { tag: "Fixed"; array: rt.ArrayOf<T> }
| { tag: "Empty" };

export function first$u16(self: Run<rt.u16>): rt.u16 | undefined {
if (self.tag === "Listed") {
return rt.sliceFirst(self._0 as rt.u16[]);
}
if (self.tag === "Fixed") {
return (self.array as rt.u16[])[0];
}
return undefined;
}

export function first$u8(self: Run<rt.u8>): rt.u8 | undefined {
if (self.tag === "Listed") {
return rt.byteSliceFirst(rt.byteVecSlice(self._0 as rt.ByteVec));
}
if (self.tag === "Fixed") {
const array: rt.ByteSlice = rt.byteSliceFrom(self.array as Uint8Array);
return array.data[array.start];
}
return undefined;
}

//# sourceMappingURL=generics.Run.ts.map
Loading