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 @@ -20,6 +20,5 @@ generic std gap is planned here even when moq never calls it.
- [Trait objects](/quest/m3/ts-dyn.md) - `dyn Trait` and `Box<dyn Future>` translate, so a consumer neither rewrites nor binds them
- [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
- [An inclusive range folded through an adaptor](/quest/m3/ts-range-fold.md) - a `RangeInclusive` folded through `map`, `filter`, or `rev` ends in core's state
- [bool's combinators from core's MIR](/quest/m3/ts-bool-core.md) - `bool::then` lowers from core, retiring `rt.boolThen`
- [Binding gaps](/quest/m3/ts-bind-gaps.md) - bound types as keys, unit returns checked, renamed dependencies
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do
17 changes: 0 additions & 17 deletions quest/m3/ts-bool-core.md

This file was deleted.

2 changes: 2 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
`ownedStepBy`: `iterNth`, `iterNthBack`, `iterSkip`, `iterTake`, and `iterStepBy` take
what drops an item last. `rt.Iter`'s `nthItem` and `nthBackItem` are `nth` and
`nthBack`, which return `rt.DONE` past the end.
- `bool::then` and `then_some` lower from core's MIR into `core/bool.ts`, so the runtime
no longer exports `boolThen` or `thenSome`.
- Translation builds std from source for `wasm32-unknown-unknown`, so the toolchain needs
its `rust-src` component, as the flake's has, and the first run compiles std.
- `Option`'s and `Result`'s combinators lower from core's MIR into `core/option.ts` and
Expand Down
14 changes: 7 additions & 7 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ elaboration put it. A panic unwinds: a function with cleanup to run catches `rt.
runs the cleanup blocks MIR has under `-C panic=unwind`, and throws it on, so what a
panic drops matches native Rust's. A value without `[Symbol.dispose]` of its own, such as
an enum or a tuple, drops through glue lowered from rustc's `drop_in_place` shim, a
function of its type's own (`drop$Held`). `Option`'s, `Result`'s, and `Poll`'s methods lower
from core's MIR, so they drop what core's do, where core's do. The runtime functions for
std's collections, `Arc`, and the std functions that may discard an operand
(`then_some`, a map's `insert`) take what drops each value they may drop, and drop it
where std's do. So do iterators: one that owns its items, as a `Vec`'s `into_iter` or a
function of its type's own (`drop$Held`). `bool`'s, `Option`'s, `Result`'s, and `Poll`'s
methods lower from core's MIR, so they drop what core's do, where core's do. The runtime
functions for std's collections, `Arc`, and the std functions that may discard an operand
(`OnceCell::get_or_init`, a map's `insert`) take what drops each value they may drop, and
drop it where std's do. So do iterators: one that owns its items, as a `Vec`'s `into_iter` or a
map's `drain` does, drops those it still holds by `[Symbol.dispose]`, an adaptor drops
what it skips or rejects, and a consumer that takes an iterator by value drops it, a
panic included: through each `rt.Iter`'s own `fold` where std's folds, which drops each
Expand Down Expand Up @@ -490,8 +490,8 @@ a pointer's address (`{:p}`), writing to a
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 switch on or a field of another crate's type without a mapping, and std
functions without a mapping in `src/lower/library.rs`, but for `Option`'s and `Result`'s
methods that take no `&mut`, which lower from core's MIR.
functions without a mapping in `src/lower/library.rs`, but for `bool`'s, `Option`'s,
`Result`'s, and `Poll`'s methods that take no `&mut`, which lower from core's MIR.

## Tests

Expand Down
12 changes: 12 additions & 0 deletions ts/fixtures/codec/expected/core/bool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Generated by rust2-ts. Do not edit.

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

export function thenSome$bool_u64(self: boolean, t: rt.u64): rt.u64 | undefined {
if (!self) {
return undefined;
}
return t;
}

//# sourceMappingURL=bool.ts.map
3 changes: 2 additions & 1 deletion ts/fixtures/codec/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { size, zigzag as varint_zigzag, unzigzag } from "./coding/varint.ts";
import * as BoundsExceeded from "./coding/varint.BoundsExceeded.ts";
import * as Form from "./coding/varint.Form.ts";
import * as Versions from "./coding/version.Versions.ts";
import { thenSome$bool_u64 } from "./core/bool.ts";
import type * as SessionError from "./lib.SessionError.ts";
import * as Group from "./lite/group.Group.ts";
import * as Probe from "./lite/probe.Probe.ts";
Expand Down Expand Up @@ -492,7 +493,7 @@ export function encodeMessages(data: rt.ByteSlice, out: rt.ByteVec): void {
const bitrate: rt.u64 = _19[0];
const rtt: rt.u64 = takeU64(_19[1])[0];
encodeMessage$Group({ subscribe, sequence, frameStart: rt.u64Rem(frameStart, 4) }, version, out);
encodeMessage$Probe({ bitrate: rt.u64CheckedSub(bitrate, 1), rtt: rt.thenSome(rt.u64Rem(rtt, 3) !== 0, rtt) }, version, out);
encodeMessage$Probe({ bitrate: rt.u64CheckedSub(bitrate, 1), rtt: thenSome$bool_u64(rt.u64Rem(rtt, 3) !== 0, rtt) }, version, out);
const versions: Versions.Versions = Versions.from$From_Versions([{ _0: subscribe }, { _0: sequence }]);
const buf: rt.ByteVec = new rt.ByteVec();
const _45: Form.Form = Form.from$From_Version(version);
Expand Down
21 changes: 11 additions & 10 deletions ts/fixtures/lang/expected/atomics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as rt from "./rt.ts";
import * as Stats from "./atomics.Stats.ts";
import { thenSome$bool_i16, thenSome$bool_i32, thenSome$bool_i64, thenSome$bool_i8, thenSome$bool_isize, thenSome$bool_u16, thenSome$bool_u32$2, thenSome$bool_u64, thenSome$bool_u8, thenSome$bool_usize } from "./core/bool.ts";
import { isSomeAnd$Option_u8_bools_closure0 } from "./core/option.ts";
import { unwrapOr$Result_i16_i16, unwrapOr$Result_i32_i32, unwrapOr$Result_i64_i64, unwrapOr$Result_i8_i8, unwrapOr$Result_isize_isize, unwrapOr$Result_u16_u16, unwrapOr$Result_u32_u32, unwrapOr$Result_u64_u64, unwrapOr$Result_u8_u8, unwrapOr$Result_usize_usize } from "./core/result.ts";

Expand Down Expand Up @@ -120,7 +121,7 @@ export function i16s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_i16_i16(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.i16): rt.i16 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_i16(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.i16> = atomic;
Expand Down Expand Up @@ -233,7 +234,7 @@ export function i32s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_i32_i32(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.i32): rt.i32 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_i32(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.i32> = atomic;
Expand Down Expand Up @@ -346,7 +347,7 @@ export function i64s(data: rt.ByteSlice, out: rt.ByteVec): void {
}, rt.i64Eq);
} else if (_60 === 14) {
old = unwrapOr$Result_i64_i64(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.i64): rt.i64 | undefined => {
return rt.thenSome(rt.i64Ne(x4, v), v);
return thenSome$bool_i64(rt.i64Ne(x4, v), v);
}, rt.i64Eq), v);
} else {
const _116: rt.Place<rt.i64> = atomic;
Expand Down Expand Up @@ -459,7 +460,7 @@ export function i8s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_i8_i8(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.i8): rt.i8 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_i8(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.i8> = atomic;
Expand Down Expand Up @@ -572,7 +573,7 @@ export function isizes(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_isize_isize(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.isize): rt.isize | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_isize(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.isize> = atomic;
Expand Down Expand Up @@ -685,7 +686,7 @@ export function u16s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_u16_u16(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.u16): rt.u16 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_u16(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.u16> = atomic;
Expand Down Expand Up @@ -798,7 +799,7 @@ export function u32s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_u32_u32(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.u32): rt.u32 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_u32$2(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.u32> = atomic;
Expand Down Expand Up @@ -911,7 +912,7 @@ export function u64s(data: rt.ByteSlice, out: rt.ByteVec): void {
}, rt.u64Eq);
} else if (_60 === 14) {
old = unwrapOr$Result_u64_u64(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.u64): rt.u64 | undefined => {
return rt.thenSome(rt.u64Ne(x4, v), v);
return thenSome$bool_u64(rt.u64Ne(x4, v), v);
}, rt.u64Eq), v);
} else {
const _116: rt.Place<rt.u64> = atomic;
Expand Down Expand Up @@ -1024,7 +1025,7 @@ export function u8s(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_u8_u8(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.u8): rt.u8 | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_u8(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.u8> = atomic;
Expand Down Expand Up @@ -1137,7 +1138,7 @@ export function usizes(data: rt.ByteSlice, out: rt.ByteVec): void {
});
} else if (_60 === 14) {
old = unwrapOr$Result_usize_usize(rt.atomicTryUpdate(atomic, any, failure, (x4: rt.usize): rt.usize | undefined => {
return rt.thenSome(x4 !== v, v);
return thenSome$bool_usize(x4 !== v, v);
}), v);
} else {
const _116: rt.Place<rt.usize> = atomic;
Expand Down
3 changes: 2 additions & 1 deletion ts/fixtures/lang/expected/cells.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { thenSome$bool_u8 } from "./core/bool.ts";

/** Steps of an operation and an operand on one cell, each putting what it read. */
export function cellOption(data: rt.ByteSlice, out: rt.ByteVec): void {
Expand Down Expand Up @@ -1017,7 +1018,7 @@ export function wide(v: rt.u8): rt.u64 {

/** `None` for every third byte. */
export function maybe(v: rt.u8): rt.u8 | undefined {
return rt.thenSome(rt.u8Rem(v, 3) !== 0, v);
return thenSome$bool_u8(rt.u8Rem(v, 3) !== 0, v);
}

export function putMaybe(out: rt.ByteVec, t: rt.u8 | undefined): void {
Expand Down
124 changes: 124 additions & 0 deletions ts/fixtures/lang/expected/core/bool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Generated by rust2-ts. Do not edit.

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

export function thenSome$bool_Duration(self: boolean, t: rt.Duration): rt.Duration | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_i16(self: boolean, t: rt.i16): rt.i16 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_i32(self: boolean, t: rt.i32): rt.i32 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_i64(self: boolean, t: rt.i64): rt.i64 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_i8(self: boolean, t: rt.i8): rt.i8 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_isize(self: boolean, t: rt.isize): rt.isize | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_u16(self: boolean, t: rt.u16): rt.u16 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_u32(self: boolean, t: rt.Place<rt.u32>): rt.Place<rt.u32> | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_u32$2(self: boolean, t: rt.u32): rt.u32 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_u64(self: boolean, t: rt.u64): rt.u64 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_u8(self: boolean, t: rt.u8): rt.u8 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$bool_unit(self: boolean, _: undefined): undefined | rt.None {
if (!self) {
return rt.None;
}
return undefined;
}

export function thenSome$bool_usize(self: boolean, t: rt.usize): rt.usize | undefined {
if (!self) {
return undefined;
}
return t;
}

export function then$bool_Option_u8_iters_closure2(self: boolean, f: () => rt.u8 | undefined): rt.u8 | undefined | rt.None {
if (!self) {
return rt.None;
}
return f();
}

export function then$bool_Vec_u8_new(self: boolean, _: () => rt.ByteVec): rt.ByteVec | undefined {
if (!self) {
return undefined;
}
return new rt.ByteVec();
}

export function then$bool_str_slices_closure1_closure0(self: boolean, f: () => string): string | undefined {
if (!self) {
return undefined;
}
return f();
}

export function then$bool_u8_library_closure4(self: boolean, f: () => rt.u8): rt.u8 | undefined {
if (!self) {
return undefined;
}
return f();
}

//# sourceMappingURL=bool.ts.map
3 changes: 2 additions & 1 deletion ts/fixtures/lang/expected/durations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as rt from "./rt.ts";
import { copy$Window } from "./lib.ts";
import { thenSome$bool_Duration } from "./core/bool.ts";
import type * as Twice from "./durations.Twice.ts";
import * as Window from "./durations.Window.ts";
import { put } from "./fmt.ts";
Expand Down Expand Up @@ -225,7 +226,7 @@ export function durations(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): voi
putDuration(out, { secs: 1, nanos: 500000000 });
putDuration(out, { secs: 0, nanos: 0 });
putOpt(out, rt.durationCheckedAdd({ secs: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64, nanos: 999999999 }, rt.durationFromNanos(1)));
const _379: rt.Duration | undefined = rt.thenSome(rt.durationCmp(b, { secs: 1, nanos: 500000000 }) === 1, b);
const _379: rt.Duration | undefined = thenSome$bool_Duration(rt.durationCmp(b, { secs: 1, nanos: 500000000 }) === 1, b);
const w2: Window.Window = { start: a, len: _379 };
const _388: Window.Window = Window.default$Default();
rt.byteVecPush(out, Window.eq$PartialEq(w2, _388) ? 1 : 0);
Expand Down
3 changes: 2 additions & 1 deletion ts/fixtures/lang/expected/iters.Halving.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { thenSome$bool_u8 } from "./core/bool.ts";

/** A value halved until it is zero: generic, with an `impl Iterator` per instance. */
export class Halving<T> {
Expand All @@ -14,7 +15,7 @@ export class Halving<T> {
export function next$Iterator_u8(self: Halving<rt.u8>): rt.u8 | rt.Done {
const value: rt.u8 = self.value;
self.value = rt.u8Div(self.value, 2);
return rt.iterFromOption(rt.thenSome(value !== 0, value));
return rt.iterFromOption(thenSome$bool_u8(value !== 0, value));
}

export function next$Iterator_u64(self: Halving<rt.u64>): rt.u64 | rt.Done {
Expand Down
Loading