diff --git a/quest/m2/ts-model/README.md b/quest/m2/ts-model/README.md index 3006aee83..0288800ef 100644 --- a/quest/m2/ts-model/README.md +++ b/quest/m2/ts-model/README.md @@ -48,7 +48,6 @@ Public API: the translator's output for moq-net's model. - [Shared ownership](/quest/m2/ts-shared.md) - kio's waiters are `Arc`/`Weak` with observable counts, and its atomics and locks are plain values - [Translate safe dependencies with the package](/quest/m2/ts-model/crates.md) - kio, moq-clock, moq-pattern, and rangemap translate as one program with moq-net -- [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods - [Floats](/quest/m2/ts-model/floats.md) - `f64` translates, so `Bandwidth::scaled` and `Duration::mul_f64` do - [Std's mutable references to values JS copies](/quest/m2/ts-model/std-places.md) - `as_mut`, `get_or_insert`, `iter_mut`, and the rest give an `rt.Place` - [The rest of std the model reaches](/quest/m2/ts-model/std-rest.md) - the std calls the census still refuses diff --git a/quest/m2/ts-model/std-more.md b/quest/m2/ts-model/std-more.md deleted file mode 100644 index 8a0a4b1b4..000000000 --- a/quest/m2/ts-model/std-more.md +++ /dev/null @@ -1,19 +0,0 @@ -# [M] Std gaps the model reaches - -## Goal - -rust2-ts translates the std ranges, wrappers, and methods moq-net's model and moq-pattern -call: `Bound` and `RangeBounds`, `Reverse`, `NonZero`, wrapping and saturating arithmetic, -`div_ceil`, tuples' comparisons and `Clone`, `Vec`'s and slices' editing and sorting -methods (`retain`, `swap_remove`, `dedup`, `sort_by_key`, `last_mut`), `Clone` and -`PartialEq` of a `Vec` that is not `Copy`, `BTreeMap::split_off`, `mem::take`, `Ord`'s -`min`, `max`, and `clamp`, and `str`'s byte searches, proven by differential tests against -native Rust. - -## Plan - -Found by the [model's](/quest/m2/ts-model/README.md) census on 2026-10-27: 246 refusals -over 121 items in the model, and 62 in moq-pattern. `capacity` (cache.rs, group.rs) stays -refused unless the maintainer decides otherwise. Report the census before and after. - -Public API: the translator's output. diff --git a/quest/m2/ts-model/std-rest.md b/quest/m2/ts-model/std-rest.md index 1d5e288a9..ca2221d9f 100644 --- a/quest/m2/ts-model/std-rest.md +++ b/quest/m2/ts-model/std-rest.md @@ -3,7 +3,7 @@ ## Goal rust2-ts translates the std calls the model's census still refuses after -[std gaps](/quest/m2/ts-model/std-more.md) and [core's MIR](https://github.com/kixelated/rust2/pull/129), +[std gaps](https://github.com/kixelated/rust2/pull/124) and [core's MIR](https://github.com/kixelated/rust2/pull/129), outside [Places](/quest/m2/ts-model/std-places.md), proven by differential tests against native Rust. @@ -19,7 +19,3 @@ calls core's bodies reach (`Default::default`, a payload's `Clone`). refuses in std rather than only this list. Public API: the translator's output. - -## Required - -- [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods diff --git a/ts/README.md b/ts/README.md index 9897cb7db..30f8d8dad 100644 --- a/ts/README.md +++ b/ts/README.md @@ -78,9 +78,10 @@ in `rt/str.ts`, collections in `rt/collections.ts`, ownership and async in | `Result` | `rt.Result`: `{ ok: true, value }` or `{ ok: false, error }`; `rt.OK` or `rt.ERR` where the payload is `undefined`, as in `Ok(())` | | `ControlFlow` | `rt.Result`, `Ok` to continue; what `?` branches on is the value it was applied to | | tuple, `[T; N]`, `&[T]`, `Vec` | an array; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec` | -| `&T`, `&mut T`, `Box` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, is an `rt.Place` | +| `&T`, `&mut T`, `Box`, `Reverse`, `NonZero` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, is an `rt.Place` | | an iterator | `rt.Iter`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` | | `a..b`, `a..=b` | `rt.Range`, `rt.RangeInclusive`, which are iterators too | +| `a..`, `..b`, `..=b`, `Bound` | `{ start }`, `{ end }`, `{ end, inclusive: true }`; `rt.RangeBound`, a union tagged by variant | | `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque` | `rt.HashMap` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` | | `Ordering`, `DefaultHasher` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher` | | `Duration` | `rt.Duration`: `{ secs, nanos }`, std's whole seconds as an `rt.u64` and the nanoseconds past them, never changed once made | @@ -143,7 +144,7 @@ std's adaptors through `rt.iterFrom`. A caller calls `next()` for one item, or i an `rt.Iter` with `for ... of`. A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a search by a -`char`, a `&str`, or a predicate, as in `rt.strSplit(s, "/")`, takes the text or the +`char`, a `&str`, a predicate, or an array or slice of chars, as in `rt.strSplit(s, "/")`, takes the text or the closure, which it calls on each char it reads, in the order std reads them. An offset it returns, from `rfind` or `match_indices`, counts UTF-8 bytes, as Rust's does, and so does one `&s[a..b]` takes, which reads the string up to it and panics as std does inside a @@ -391,6 +392,11 @@ they need. are a JS `Map`'s, the engine's own hash table; its other keys go into a second `Map` by their translated hash, chained by `Eq`. `VecDeque` is a ring buffer over an array whose length is a power of two. +- A slice's `sort` and `sort_unstable` are one stable merge sort of the runtime's own, + calling only the comparator, as std permits of an unstable sort: JS's `sort` moves + `undefined`, a `None`, to the end without comparing it, and each engine orders its + comparisons differently. A comparator that panics leaves each element once, in an + order std's sort would not match. - Iterators are the runtime's lazy classes rather than generators or ES iterator helpers: std's adaptors would lower from std's own bodies, whose slice iterators are raw pointers, ES helpers lack most of them @@ -442,7 +448,7 @@ without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partiti own `impl Iterator` with `next_back`, `len`, or another provided method of its own, a pointer's address (`{:p}`), writing to a `String` with `write!`, a `str` pattern other than a -`char`, a `&str`, or a predicate, a mutable `str` slice, a copy of a closure that changes +`char`, a `&str`, a predicate, or chars, a mutable `str` slice, a copy of a closure that changes 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 @@ -477,9 +483,11 @@ built natively for wasm32 and run beside its translation on the same inputs by closures that log what each adaptor reads, `Option`'s and `Result`'s combinators, with closures that log each call, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` - disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, and `&mut` + disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, `&mut` to values JS copies, of locals, fields, elements, and a map's values, passed on, - returned, kept in a struct, and captured. Its differential test runs through `caller.ts`, a + returned, kept in a struct, and captured, a `Vec`'s edits and sorts, with closures + that log what each is called with, and std's `Bound`, `Reverse`, and `NonZero`. 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, where the runtime switches between numbers and limbs, and its limbs carry and borrow, @@ -507,7 +515,8 @@ built natively for wasm32 and run beside its translation on the same inputs by `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` panics in a collection's -`retain` at each item, and `retain_unwinds` checks that it leaves what std's leaves. +`retain` and `Vec::dedup_by` at each item, and `retain_unwinds` checks that each leaves and +drops what std's does; a sort whose comparator panics must leave each item once. ## Bench diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index fff48b8f9..3a0f3721d 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -1124,12 +1124,12 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void { const hash: rt.HashMap = rt.hashNew() as rt.HashMap; rt.hashInsert(hash, 0, copy$u8_u8(pair)); rt.hashInsert(hash, 1, copy$u8_u8(pair)); - const _88: rt.Place<[rt.u8, rt.u8]> | undefined = rt.hashGetMut(hash, 0); + const _88: [rt.u8, rt.u8] | undefined = rt.hashGet(hash, 0); if (_88 !== undefined) { - _88.v[0] = _88.v[0] ^ 1; + _88[0] = _88[0] ^ 1; } - const _93: rt.Place<[rt.u8, rt.u8]> = rt.entryOrInsertMut(rt.entry(hash, 2), copy$u8_u8(pair)); - _93.v[1] = _93.v[1] ^ 2; + const _93: [rt.u8, rt.u8] = rt.entryOrInsert(rt.entry(hash, 2), copy$u8_u8(pair)); + _93[1] = _93[1] ^ 2; rt.iterExtendBytes(out, rt.iterFlatMap(new rt.Range(0, 3), (k: rt.u8): Uint8Array => { return mapOr$Option_u8_u8_u8s_stores_closure2_closure0(rt.hashGet(hash, k), rt.bytes(2).fill(255), (p2: [rt.u8, rt.u8]): Uint8Array => { return Uint8Array.of(p2[0], p2[1]); @@ -1138,9 +1138,9 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void { const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; rt.btreeInsert(tree, 0, copy$u8_u8(pair)); rt.btreeInsert(tree, 1, copy$u8_u8(pair)); - const _106: rt.Place<[rt.u8, rt.u8]> | undefined = rt.btreeGetMut(tree, 1); + const _106: [rt.u8, rt.u8] | undefined = rt.btreeGet(tree, 1); if (_106 !== undefined) { - _106.v[1] = _106.v[1] ^ 1; + _106[1] = _106[1] ^ 1; } rt.iterExtendBytes(out, rt.iterFlatMap(rt.btreeValues(tree), (p3: [rt.u8, rt.u8]): Uint8Array => { return Uint8Array.of(p3[0], p3[1]); diff --git a/ts/fixtures/lang/expected/core/option.ts b/ts/fixtures/lang/expected/core/option.ts index ca2ea7157..c93c42ef2 100644 --- a/ts/fixtures/lang/expected/core/option.ts +++ b/ts/fixtures/lang/expected/core/option.ts @@ -37,28 +37,28 @@ export function unwrapOr$Option_Cow_str(self: string | undefined, default_: stri return self; } -export function unwrapOr$Option_char(self: rt.char | undefined, default_: rt.char): rt.char { +export function unwrapOr$Option_NonZero_u64(self: rt.u64 | undefined, default_: rt.u64): rt.u64 { if (self === undefined) { return default_; } return self; } -export function unwrapOr$Option_i64(self: rt.i64 | undefined, default_: rt.i64): rt.i64 { +export function unwrapOr$Option_char(self: rt.char | undefined, default_: rt.char): rt.char { if (self === undefined) { return default_; } return self; } -export function unwrapOr$Option_u16(self: rt.u16 | undefined, default_: rt.u16): rt.u16 { +export function unwrapOr$Option_i64(self: rt.i64 | undefined, default_: rt.i64): rt.i64 { if (self === undefined) { return default_; } return self; } -export function unwrapOr$Option_u64(self: rt.u64 | undefined, default_: rt.u64): rt.u64 { +export function unwrapOr$Option_u16(self: rt.u16 | undefined, default_: rt.u16): rt.u16 { if (self === undefined) { return default_; } @@ -303,6 +303,13 @@ export function mapOr$Option_Vec_u8_u8_library_closure5(self: rt.ByteVec | undef return f(self); } +export function mapOr$Option_u16_u16_edits_closure21(self: rt.u16 | undefined, default_: rt.u16, f: (a0: rt.u16) => rt.u16): rt.u16 { + if (self === undefined) { + return default_; + } + return f(self); +} + export function mapOr$Option_u16_u8_hash_maps_closure0(self: rt.u16 | undefined, default_: rt.u8, f: (a0: rt.u16) => rt.u8): rt.u8 { if (self === undefined) { return default_; diff --git a/ts/fixtures/lang/expected/edits.Lean.ts b/ts/fixtures/lang/expected/edits.Lean.ts new file mode 100644 index 000000000..b74e1ba26 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Lean.ts @@ -0,0 +1,20 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** + * An order whose `partial_cmp` leans on its first operand, an odd one less than any, and + * whose `cmp` is by value, so what `Ord`'s defaults call, with which operand first, shows. + */ +export interface Lean { + _0: rt.u8; +} + +export function partialCmp$PartialOrd(self: Lean, other: Lean): rt.Ordering | undefined { + if (rt.u8Rem(self._0, 2) === 1) { + return -1; + } + return rt.cmp(self._0, other._0); +} + +//# sourceMappingURL=edits.Lean.ts.map diff --git a/ts/fixtures/lang/expected/edits.Named.ts b/ts/fixtures/lang/expected/edits.Named.ts new file mode 100644 index 000000000..4b9e5c9fa --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Named.ts @@ -0,0 +1,32 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function clone$Clone(self: Named): Named { + return { id: self.id, name: self.name }; +} + +export function eq$PartialEq(self: Named, other: Named): boolean { + if (!(self.id === other.id)) { + return false; + } + return self.name === other.name; +} + +export function partialCmp$PartialOrd(self: Named, other: Named): rt.Ordering | undefined { + const cmp: rt.Ordering | undefined = rt.cmp(self.id, other.id); + if (cmp !== undefined) { + if (cmp === 0) { + return rt.cmpStr(self.name, other.name); + } + } + return cmp; +} + +/** An element that is not `Copy`, cloned and compared field by field. */ +export interface Named { + id: rt.u16; + name: string; +} + +//# sourceMappingURL=edits.Named.ts.map diff --git a/ts/fixtures/lang/expected/edits.Stamp.ts b/ts/fixtures/lang/expected/edits.Stamp.ts new file mode 100644 index 000000000..9c2dee638 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Stamp.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function partialCmp$PartialOrd(self: Stamp, other: Stamp): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + +export function cmp$Ord(self: Stamp, other: Stamp): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** The crate's own order, whose `min`, `max`, and `clamp` are `Ord`'s defaults. */ +export interface Stamp { + _0: rt.u8; +} + +//# sourceMappingURL=edits.Stamp.ts.map diff --git a/ts/fixtures/lang/expected/edits.Tally.ts b/ts/fixtures/lang/expected/edits.Tally.ts new file mode 100644 index 000000000..9a1bcb6cc --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Tally.ts @@ -0,0 +1,15 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** What `mem::take` leaves its own `Default` in place of. */ +export interface Tally { + n: rt.u8; + names: string[]; +} + +export function default$Default(): Tally { + return { n: 7, names: ["fresh"] }; +} + +//# sourceMappingURL=edits.Tally.ts.map diff --git a/ts/fixtures/lang/expected/edits.ts b/ts/fixtures/lang/expected/edits.ts new file mode 100644 index 000000000..36f3fa6c5 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.ts @@ -0,0 +1,310 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { copy$chars } from "./lib.ts"; +import { unwrapOr$Option_u16, unwrapOr$Option_u8, mapOr$Option_u16_u16_edits_closure21 } from "./core/option.ts"; +import * as Lean from "./edits.Lean.ts"; +import * as Named from "./edits.Named.ts"; +import * as Stamp from "./edits.Stamp.ts"; +import * as Tally from "./edits.Tally.ts"; +import { put } from "./fmt.ts"; +import { text } from "./strs.ts"; + +export function putU16s(out: rt.ByteVec, v: rt.u16[]): void { + for (const _5 of v) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(_5))); + } + rt.byteVecPush(out, 254); +} + +export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _75: (a0: rt.u16) => Named.Named = (w: rt.u16): Named.Named => { + return { id: w, name: text(rt.byteSliceFrom(Uint8Array.of(rt.u8Div(w & 0xff, 16)))) }; + }; + const words: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_2: rt.u8): rt.u16 => { + return rt.u16Mul(_2 as rt.u16, 3); + })); + const at: (a0: rt.usize) => rt.u8 = (i3: rt.usize): rt.u8 => { + return unwrapOr$Option_u8(rt.byteSliceGet(data, i3), 0); + }; + const _8: rt.u8 = rt.u8Rem(kind, 7); + if (_8 === 0) { + const v: rt.u16[] = words.slice(); + const seen: rt.u16[] = []; + rt.vecRetain(v, (_225: rt.u16): boolean => { + const x3: rt.u16 = _225; + seen.push(x3); + return rt.u16Rem(x3, 4) !== 0; + }); + putU16s(out, seen); + putU16s(out, v); + const pairs: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_228: rt.u16): [rt.u16, rt.u16] => { + return [_228, 0] as [rt.u16, rt.u16]; + })); + rt.vecRetain(pairs, (p3: [rt.u16, rt.u16]): boolean => { + p3[1] = rt.u16Div(p3[0], 2); + return rt.u16Rem(p3[0], 3) === 0; + }); + for (const _33 of pairs) { + putU16s(out, [_33[0], _33[1]]); + } + const names: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_230: rt.u8): string => { + return text(rt.byteSliceFrom(Uint8Array.of(_230))); + })); + rt.vecRetain(names, (s2: string): boolean => { + return rt.stringLen(s2) > 1; + }); + rt.byteVecPush(out, names.length & 0xff); + const part2 = rt.usizeSaturatingSub(data.length, 1); + const stop: rt.u16 = rt.u16Mul(at(part2) as rt.u16, 3); + if ((kind & 128) !== 0) { + rt.vecRetain(v, (_232: rt.u16): boolean => { + const x4: rt.u16 = _232; + if (!(x4 === stop)) { + return true; + } + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u16Display(x4, f)]; + rt.panicFmt(["retain stopped at ", args2[0]]); + }); + } + } else if (_8 === 1) { + const v2: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_217: rt.u8): rt.u16 => { + return rt.u8Rem(_217, 4) as rt.u16; + })); + rt.vecDedupBy(v2, rt.same); + putU16s(out, v2); + const keyed: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_218: rt.u16): Named.Named => { + return _75(_218); + })); + rt.vecDedupByKey(keyed, (n: Named.Named): rt.u16 => { + return rt.u16Div(n.id, 24); + }, rt.same); + for (const _88 of keyed) { + putU16s(out, [_88.id]); + } + const tested: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_219: rt.u16): Named.Named => { + return _75(_219); + })); + const seen2: rt.u16[] = []; + rt.vecDedupBy(tested, (a3: Named.Named, b8: Named.Named): boolean => { + seen2.push(a3.id); + seen2.push(b8.id); + return a3.name === b8.name; + }); + putU16s(out, seen2); + for (const _115 of tested) { + put(out, _115.name); + } + const names2: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_221: rt.u8): string => { + return text(rt.byteSliceFrom(Uint8Array.of(rt.u8Rem(_221, 3)))); + })); + rt.vecDedupBy(names2, rt.same); + rt.byteVecPush(out, names2.length & 0xff); + } else if (_8 === 2) { + const v3: rt.u16[] = words.slice(); + rt.sliceSortBy(v3, rt.cmp); + putU16s(out, v3); + const v4: rt.u16[] = words.slice(); + rt.sliceSortBy(v4, (a: rt.u16, b4: rt.u16): rt.Ordering => { + return rt.cmp(b4, a); + }); + putU16s(out, v4); + const pairs2: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(words)), (_211: [rt.usize, rt.u16]): [rt.u16, rt.u16] => { + return [rt.u16Rem(_211[1], 5), _211[0] & 0xffff] as [rt.u16, rt.u16]; + })); + rt.sliceSortByKey(pairs2, (p2: [rt.u16, rt.u16]): rt.u16 => { + return p2[0]; + }, rt.cmp); + for (const _159 of pairs2) { + putU16s(out, [_159[0], _159[1]]); + } + rt.sliceSortByKey(pairs2, (_213: [rt.u16, rt.u16]): [rt.u16, rt.u16, rt.u16] => { + const a2: rt.u16 = _213[0]; + const b5: rt.u16 = _213[1]; + return [rt.u16Rem(b5, 3), a2, b5] as [rt.u16, rt.u16, rt.u16]; + }, rt.cmpTuple([rt.cmp, rt.cmp, rt.cmp])); + for (const _176 of pairs2) { + putU16s(out, [_176[0], _176[1]]); + } + rt.sliceSortBy(pairs2, (x2: [rt.u16, rt.u16], y: [rt.u16, rt.u16]): rt.Ordering => { + return rt.cmp(y[1], x2[1]); + }); + for (const _193 of pairs2) { + putU16s(out, [_193[0], _193[1]]); + } + const options: Array = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_214: rt.u16): rt.u16 | undefined => { + const w6: rt.u16 = _214; + if (!(rt.u16Rem(w6, 2) === 0)) { + return w6; + } + return undefined; + })); + rt.sliceSortBy(options, rt.cmpOption(rt.cmp)); + for (const _215 of options) { + putU16s(out, [mapOr$Option_u16_u16_edits_closure21(_215, 65535, (o: rt.u16): rt.u16 => { + return o; + })]); + } + const names3: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_216: rt.u8): string => { + const b6: rt.u8 = _216; + return text(rt.byteSliceFrom(Uint8Array.of(b6, rt.u8Div(b6, 16)))); + })); + rt.sliceSortBy(names3, rt.cmpStr); + for (const _234 of names3) { + put(out, _234); + } + } else if (_8 === 3) { + const v5: rt.u16[] = words.slice(); + putU16s(out, [unwrapOr$Option_u16(rt.sliceLast(v5), 65535)]); + const runs: [rt.u16, rt.u16 | undefined][] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_28: rt.u16): [rt.u16, rt.u16 | undefined] => { + return [_28, undefined] as [rt.u16, rt.u16 | undefined]; + })); + const _256: [rt.u16, rt.u16 | undefined] | undefined = rt.sliceLast(runs); + if (_256 !== undefined) { + _256[1] = _256[0]; + } + const _263: [rt.u16, rt.u16 | undefined] | undefined = rt.sliceFirst(runs); + if (_263 !== undefined) { + _263[0] = rt.u16Add(_263[0], 1); + } + for (const _272 of runs) { + putU16s(out, [_272[0], unwrapOr$Option_u16(_272[1], 65535)]); + } + rt.sliceReverse(v5); + putU16s(out, v5); + const named: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_29: rt.u16): Named.Named => { + const w4: rt.u16 = _29; + return { id: w4, name: text(rt.byteSliceFrom(Uint8Array.of(w4 & 0xff))) }; + })); + const probe: Named.Named = { id: rt.u16Mul(at(1) as rt.u16, 3), name: text(rt.byteSliceFrom(Uint8Array.of(rt.u8WrappingMul(at(1), 3)))) }; + rt.byteVecPush(out, rt.sliceContains(named, probe, Named.eq$PartialEq) ? 1 : 0); + rt.byteVecPush(out, rt.sliceContains(words, rt.u16Mul(at(2) as rt.u16, 3), rt.same) ? 1 : 0); + const _332: rt.u8 = at(3); + rt.byteVecPush(out, rt.byteSliceView(data).includes(_332) ? 1 : 0); + const _337: [rt.usize, rt.usize] = [rt.usizeRem(at(0) as rt.usize, 8), rt.usizeRem(at(1) as rt.usize, 8)]; + const i: rt.usize = _337[0]; + const j: rt.usize = _337[1]; + const moved: rt.u16[] = words.slice(); + putU16s(out, [rt.vecSwapRemove(moved, i)]); + putU16s(out, moved); + rt.sliceSwap(moved, i, j); + putU16s(out, moved); + } else if (_8 === 4) { + const named2: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_23: rt.u16): Named.Named => { + const w2: rt.u16 = _23; + return { id: w2, name: text(rt.byteSliceFrom(Uint8Array.of(w2 & 0xff))) }; + })); + const cloned: Named.Named[] = rt.vecClone(named2, Named.clone$Clone); + rt.byteVecPush(out, rt.eqSlice(Named.eq$PartialEq)(cloned, named2) ? 1 : 0); + const changed: Named.Named[] = rt.vecClone(named2, Named.clone$Clone); + const _382: Named.Named | undefined = rt.sliceFirst(changed); + if (_382 !== undefined) { + _382.name = _382.name + "!"; + } + rt.byteVecPush(out, rt.eqSlice(Named.eq$PartialEq)(changed, named2) ? 1 : 0); + rt.byteVecPush(out, !rt.eqSlice(Named.eq$PartialEq)(changed, named2) ? 1 : 0); + rt.byteVecPush(out, rt.cmpSlice(Named.partialCmp$PartialOrd)(changed, named2) === -1 ? 1 : 0); + const _406: Named.Named[] = rt.sliceRange(named2, 0, rt.usizeDiv(named2.length, 2)); + rt.vecExtendFromSlice(changed, _406, Named.clone$Clone); + rt.byteVecPush(out, changed.length & 0xff); + const nested: rt.u16[][] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_27: rt.u8): rt.u16[] => { + const b3: rt.u8 = _27; + return rt.iterToArray(rt.iterMap(new rt.Range(0, rt.u8Rem(b3, 3)), (i4: rt.u8): rt.u16 => { + return rt.u16Add(i4 as rt.u16, b3 as rt.u16); + })); + })); + const _424: rt.u16[][] = rt.vecClone(nested, (a014: rt.u16[]): rt.u16[] => { + return a014.slice(); + }); + rt.byteVecPush(out, rt.eqSlice(rt.eqSlice(rt.same))(_424, nested) ? 1 : 0); + const pair: [string, rt.u8] = [text(data), at(0)]; + const copy: [string, rt.u8] = rt.tupleClone(pair, [undefined, undefined], [undefined, undefined]); + put(out, copy[0]); + const _441: [rt.u8, string] = [copy[1], copy[0]]; + const _445: [rt.u8, string] = [at(1), pair[0]]; + rt.byteVecPush(out, rt.cmpTuple([rt.cmp, rt.cmpStr])(_441, _445) === 1 ? 1 : 0); + const _454: [rt.u8, rt.u8] = [at(0), at(1)]; + const _462: [rt.u8, rt.u8] = [at(1), at(0)]; + rt.byteVecPush(out, rt.cmpTuple([rt.cmp, rt.cmp])(_454, _462) === -1 ? 1 : 0); + const grown: rt.u16[] = words.slice(); + rt.vecExtendFromSlice(grown, words); + putU16s(out, grown); + } else if (_8 === 5) { + let tally: Tally.Tally = { n: at(0), names: [text(data)] }; + const default_ = Tally.default$Default(); + const taken3 = tally; + tally = default_; + rt.byteVecPush(out, taken3.n); + rt.byteVecPush(out, tally.n); + put(out, tally.names[rt.idx(tally.names, 0)]); + const _497: rt.Iter = rt.iterSlice(words); + let queue: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _497); + const default_2 = rt.dequeNew() as rt.VecDeque; + const taken4 = queue; + queue = default_2; + rt.byteVecPush(out, taken4.n & 0xff); + rt.byteVecPush(out, queue.n & 0xff); + const _512: rt.Iter = rt.iterSlice(words); + let set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _512, true); + const default_3 = rt.btreeNew(rt.cmp) as rt.BTreeSet; + const taken5 = set; + set = default_3; + rt.byteVecPush(out, rt.btreeLen(taken5) & 0xff); + rt.byteVecPush(out, rt.btreeLen(set) === 0 ? 1 : 0); + const _529: [Stamp.Stamp, Stamp.Stamp, Stamp.Stamp] = [{ _0: at(0) }, { _0: at(1) }, { _0: at(2) }]; + const x: Stamp.Stamp = _529[0]; + const lo: Stamp.Stamp = _529[1]; + const hi: Stamp.Stamp = _529[2]; + rt.byteVecPush(out, rt.ordMax(x, lo, Stamp.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordMin(x, lo, Stamp.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordClamp(x, lo, hi, Stamp.partialCmp$PartialOrd)._0); + const _554: [Lean.Lean, Lean.Lean, Lean.Lean] = [{ _0: at(0) }, { _0: at(1) }, { _0: at(2) }]; + const p: Lean.Lean = _554[0]; + const q: Lean.Lean = _554[1]; + const r: Lean.Lean = _554[2]; + rt.byteVecPush(out, rt.ordMax(p, q, Lean.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordMin(p, q, Lean.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordClamp(p, q, r, Lean.partialCmp$PartialOrd)._0); + } else { + const s: string = text(data); + const sep: rt.char[] = [47, 97]; + rt.byteVecPush(out, rt.strContains(s, rt.patternChars(sep)) ? 1 : 0); + rt.byteVecPush(out, rt.strContains(s, rt.patternChars(rt.sliceRange(sep, 0))) ? 1 : 0); + rt.byteVecPush(out, rt.iterCount(rt.strSplit(s, rt.patternChars(copy$chars(sep)))) & 0xff); + rt.byteVecPush(out, rt.strEndsWith(s, "/") ? 1 : 0); + rt.byteVecPush(out, rt.strEndsWith(s, "😀") ? 1 : 0); + rt.byteVecPush(out, rt.strEndsWith(s, (c: rt.char): boolean => { + return rt.charIsAsciiDigit(c); + }) ? 1 : 0); + const _612: [string, string] | undefined = rt.strSplitOnce(s, "/"); + if (_612 === undefined) { + rt.byteVecPush(out, 253); + } else { + put(out, _612[0]); + put(out, _612[1]); + } + const _621: [string, string] | undefined = rt.strSplitOnce(s, "a0"); + if (_621 === undefined) { + rt.byteVecPush(out, 253); + } else { + put(out, _621[0]); + put(out, _621[1]); + } + const iter10: rt.RangeInclusive = new rt.RangeInclusive(0, rt.usizeAdd(rt.stringLen(s), 1), rt.usizeStep); + while (true) { + const _636: rt.usize | rt.Done = iter10.next(); + if (_636 === rt.DONE) { + break; + } + rt.byteVecPush(out, rt.strIsCharBoundary(s, _636) ? 1 : 0); + } + rt.iterExtendBytes(out, rt.strBytes(s)); + rt.iterExtendBytes(out, rt.iterTake(rt.iterRev(rt.strBytes(s)), 3)); + rt.byteVecPush(out, rt.strBytes(s).len() & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterFilter(rt.strBytes(s), (_22: rt.u8): boolean => { + return _22 >= 128; + })) & 0xff); + } +} + +//# sourceMappingURL=edits.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index b84374bba..cb8e4ee7f 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -7,6 +7,7 @@ import { hashMaps, sets, btreeMaps, deques, vecs, stores } from "./collections.t import { combinators } from "./combinators.ts"; import { cows } from "./cows.ts"; import { durations } from "./durations.ts"; +import { edits } from "./edits.ts"; import { ints, strings, derived, written, counts, rounding, panics } from "./fmt.ts"; import { methods } from "./generics.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts"; @@ -17,6 +18,7 @@ import { refs } from "./refs.ts"; import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { splits } from "./splits.ts"; import { strs, slices } from "./strs.ts"; +import { wrappers } from "./wrappers.ts"; /** Run one case. */ export function run(input: rt.ByteSlice): rt.ByteVec { @@ -27,7 +29,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec { const _10: [rt.u8, rt.u8] = [input.data[input.start], input.data[input.start + 1]]; const op: rt.u8 = _10[0]; const kind: rt.u8 = _10[1]; - const _14: rt.u8 = rt.u8Rem(op, 55); + const _14: rt.u8 = rt.u8Rem(op, 57); if (_14 === 0) { u8Op(kind, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out); } else if (_14 === 1) { @@ -153,8 +155,12 @@ export function run(input: rt.ByteSlice): rt.ByteVec { counts(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out); } else if (_14 === 53) { rounding(out); - } else { + } else if (_14 === 54) { skips(kind, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out); + } else if (_14 === 55) { + wrappers(kind, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out); + } else { + edits(kind, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out); } return out; } diff --git a/ts/fixtures/lang/expected/ints.ts b/ts/fixtures/lang/expected/ints.ts index 9abf18060..a24b31931 100644 --- a/ts/fixtures/lang/expected/ints.ts +++ b/ts/fixtures/lang/expected/ints.ts @@ -5,17 +5,17 @@ import { unwrapOr$Option_u8 } from "./core/option.ts"; /** Apply operation `op` to operands taken from `data`. */ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u8) => void = (out2: rt.ByteVec, v: rt.u8): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u8FromBeBytes(rt.u8ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u8) => void = (out2: rt.ByteVec, v2: rt.u8): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u8FromBeBytes(rt.u8ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u8 | undefined) => void = (out3: rt.ByteVec, v2: rt.u8 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u8 | undefined) => void = (out3: rt.ByteVec, v3: rt.u8 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u8 = v2; + const v4: rt.u8 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = Uint8Array.of(0); @@ -30,69 +30,92 @@ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u8 = rt.u8FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u8 = _38; + const buf3: Uint8Array = Uint8Array.of(0); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u8 = ([rt.u8FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u8, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 8); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u8Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u8Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u8Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u8Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u8Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.u8Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u8Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a & 0xff); - } else if (_52 === 11) { - const part9 = rt.u8CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u8CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u8CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u8SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u8SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u8WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u8WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u8Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u8Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u8Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u8Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u8Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.u8Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u8Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a & 0xff); + } else if (_70 === 11) { + const part12 = rt.u8CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u8CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u8CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u8SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u8SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u8WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u8WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u8LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u8LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u8WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u8 = rt.u8Add(a, b); rt.u8Mul(x, b); rt.u8Mul(rt.u8Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u8SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u8WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u8 | undefined = rt.u8DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u8IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u8 = a; x2 = rt.u8Add(x2, b); @@ -105,23 +128,23 @@ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & (~(1 << 2) & 0xff); x2 = rt.u8Rem(x2, 7); x2 = rt.u8Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u16) => void = (out2: rt.ByteVec, v: rt.u16): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u16FromBeBytes(rt.u16ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u16) => void = (out2: rt.ByteVec, v2: rt.u16): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u16FromBeBytes(rt.u16ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u16 | undefined) => void = (out3: rt.ByteVec, v2: rt.u16 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u16 | undefined) => void = (out3: rt.ByteVec, v3: rt.u16 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u16 = v2; + const v4: rt.u16 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(2); @@ -136,69 +159,92 @@ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u16 = rt.u16FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u16 = _38; + const buf3: Uint8Array = rt.bytes(2); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u16 = ([rt.u16FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u16, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 16); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u16Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u16Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u16Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u16Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u16Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.u16Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u16Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a & 0xffff); - } else if (_52 === 11) { - const part9 = rt.u16CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u16CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u16CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u16SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u16SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u16WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u16WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u16Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u16Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u16Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u16Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u16Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.u16Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u16Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a & 0xffff); + } else if (_70 === 11) { + const part12 = rt.u16CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u16CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u16CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u16SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u16SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u16WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u16WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u16LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u16LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u16WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u16 = rt.u16Add(a, b); rt.u16Mul(x, b); rt.u16Mul(rt.u16Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u16SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u16WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u16 | undefined = rt.u16DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u16IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u16 = a; x2 = rt.u16Add(x2, b); @@ -211,23 +257,23 @@ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & (~(1 << 2) & 0xffff); x2 = rt.u16Rem(x2, 7); x2 = rt.u16Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u32) => void = (out2: rt.ByteVec, v: rt.u32): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u32FromBeBytes(rt.u32ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u32) => void = (out2: rt.ByteVec, v2: rt.u32): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u32FromBeBytes(rt.u32ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u32 | undefined) => void = (out3: rt.ByteVec, v2: rt.u32 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u32 | undefined) => void = (out3: rt.ByteVec, v3: rt.u32 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u32 = v2; + const v4: rt.u32 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -242,69 +288,92 @@ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u32 = rt.u32FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u32 = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u32 = ([rt.u32FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u32, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u32Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u32Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u32Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u32Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u32Rem(a, b)); - } else if (_52 === 5) { - _50(out, (a & b) >>> 0); - } else if (_52 === 6) { - _50(out, (a | b) >>> 0); - } else if (_52 === 7) { - _50(out, (a ^ b) >>> 0); - } else if (_52 === 8) { - _50(out, rt.u32Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u32Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a >>> 0); - } else if (_52 === 11) { - const part9 = rt.u32CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u32CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u32CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u32SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u32SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u32WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u32WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u32Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u32Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u32Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u32Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u32Rem(a, b)); + } else if (_70 === 5) { + _68(out, (a & b) >>> 0); + } else if (_70 === 6) { + _68(out, (a | b) >>> 0); + } else if (_70 === 7) { + _68(out, (a ^ b) >>> 0); + } else if (_70 === 8) { + _68(out, rt.u32Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u32Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a >>> 0); + } else if (_70 === 11) { + const part12 = rt.u32CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u32CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u32CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u32SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u32SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u32WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u32WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u32WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u32 = rt.u32Add(a, b); rt.u32Mul(x, b); rt.u32Mul(rt.u32Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u32SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u32WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u32 | undefined = rt.u32DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u32IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u32 = a; x2 = rt.u32Add(x2, b); @@ -317,23 +386,23 @@ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = (x2 & (~(1 << 2) >>> 0)) >>> 0; x2 = rt.u32Rem(x2, 7); x2 = rt.u32Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u64) => void = (out2: rt.ByteVec, v: rt.u64): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v)))); - rt.byteVecPush(out2, rt.u64Eq(rt.u64FromBeBytes(rt.u64ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u64) => void = (out2: rt.ByteVec, v2: rt.u64): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v2)))); + rt.byteVecPush(out2, rt.u64Eq(rt.u64FromBeBytes(rt.u64ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u64 | undefined) => void = (out3: rt.ByteVec, v2: rt.u64 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u64 | undefined) => void = (out3: rt.ByteVec, v3: rt.u64 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u64 = v2; + const v4: rt.u64 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v3)))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v4)))); } }; const buf: Uint8Array = rt.bytes(8); @@ -348,69 +417,92 @@ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u64 = rt.u64FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u64 = _38; + const buf3: Uint8Array = rt.bytes(8); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u64 = ([rt.u64FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u64, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 64); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u64Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u64Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u64Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u64Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u64Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.u64And(a, b)); - } else if (_52 === 6) { - _50(out, rt.u64Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.u64Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.u64Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u64Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.u64Not(a)); - } else if (_52 === 11) { - const part9 = rt.u64CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u64CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u64CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u64SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u64SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u64WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u64WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u64Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u64Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u64Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u64Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u64Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.u64And(a, b)); + } else if (_70 === 6) { + _68(out, rt.u64Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.u64Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.u64Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u64Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.u64Not(a)); + } else if (_70 === 11) { + const part12 = rt.u64CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u64CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u64CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u64SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u64SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u64WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u64WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u64LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u64LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.u64Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.u64Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.u64Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.u64Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.u64Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u64 = rt.u64Add(a, b); rt.u64Mul(x, b); rt.u64Mul(rt.u64Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u64SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u64WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.u64Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u64 | undefined = rt.u64DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u64IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u64 = a; x2 = rt.u64Add(x2, b); @@ -423,23 +515,23 @@ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.u64And(x2, rt.u64Not(4)); x2 = rt.u64Rem(x2, 7); x2 = rt.u64Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u128) => void = (out2: rt.ByteVec, v: rt.u128): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v))); - rt.byteVecPush(out2, rt.u128Eq(rt.u128FromBeBytes(rt.u128ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u128) => void = (out2: rt.ByteVec, v2: rt.u128): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2))); + rt.byteVecPush(out2, rt.u128Eq(rt.u128FromBeBytes(rt.u128ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u128 | undefined) => void = (out3: rt.ByteVec, v2: rt.u128 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u128 | undefined) => void = (out3: rt.ByteVec, v3: rt.u128 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u128 = v2; + const v4: rt.u128 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4))); } }; const buf: Uint8Array = rt.bytes(16); @@ -454,69 +546,92 @@ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u128 = rt.u128FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u128 = _38; + const buf3: Uint8Array = rt.bytes(16); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u128 = ([rt.u128FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u128, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 128); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u128Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u128Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u128Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u128Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u128Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.u128And(a, b)); - } else if (_52 === 6) { - _50(out, rt.u128Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.u128Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.u128Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u128Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.u128Not(a)); - } else if (_52 === 11) { - const part9 = rt.u128CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u128CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u128CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u128SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u128SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u128WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u128WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u128Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u128Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u128Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u128Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u128Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.u128And(a, b)); + } else if (_70 === 6) { + _68(out, rt.u128Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.u128Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.u128Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u128Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.u128Not(a)); + } else if (_70 === 11) { + const part12 = rt.u128CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u128CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u128CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u128SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u128SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u128WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u128WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u128LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u128LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.u128Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.u128Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.u128Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.u128Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.u128Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u128 = rt.u128Add(a, b); rt.u128Mul(x, b); rt.u128Mul(rt.u128Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u128SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u128WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.u128Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u128 | undefined = rt.u128DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u128IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u128 = a; x2 = rt.u128Add(x2, b); @@ -529,23 +644,23 @@ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.u128And(x2, rt.u128Not(rt.u128Shl(1, 2))); x2 = rt.u128Rem(x2, 7); x2 = rt.u128Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.usize) => void = (out2: rt.ByteVec, v: rt.usize): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.usizeFromBeBytes(rt.usizeToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.usize) => void = (out2: rt.ByteVec, v2: rt.usize): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.usizeFromBeBytes(rt.usizeToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.usize | undefined) => void = (out3: rt.ByteVec, v2: rt.usize | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.usize | undefined) => void = (out3: rt.ByteVec, v3: rt.usize | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.usize = v2; + const v4: rt.usize = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -560,69 +675,92 @@ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.usize = rt.usizeFromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.usize = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.usize = ([rt.usizeFromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.usize, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.usizeAdd(a, b)); - } else if (_52 === 1) { - _50(out, rt.usizeSub(a, b)); - } else if (_52 === 2) { - _50(out, rt.usizeMul(a, b)); - } else if (_52 === 3) { - _50(out, rt.usizeDiv(a, b)); - } else if (_52 === 4) { - _50(out, rt.usizeRem(a, b)); - } else if (_52 === 5) { - _50(out, (a & b) >>> 0); - } else if (_52 === 6) { - _50(out, (a | b) >>> 0); - } else if (_52 === 7) { - _50(out, (a ^ b) >>> 0); - } else if (_52 === 8) { - _50(out, rt.usizeShl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.usizeShr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a >>> 0); - } else if (_52 === 11) { - const part9 = rt.usizeCheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.usizeCheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.usizeCheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.usizeSaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.usizeSaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.usizeWrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.usizeWrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.usizeAdd(a, b)); + } else if (_70 === 1) { + _68(out, rt.usizeSub(a, b)); + } else if (_70 === 2) { + _68(out, rt.usizeMul(a, b)); + } else if (_70 === 3) { + _68(out, rt.usizeDiv(a, b)); + } else if (_70 === 4) { + _68(out, rt.usizeRem(a, b)); + } else if (_70 === 5) { + _68(out, (a & b) >>> 0); + } else if (_70 === 6) { + _68(out, (a | b) >>> 0); + } else if (_70 === 7) { + _68(out, (a ^ b) >>> 0); + } else if (_70 === 8) { + _68(out, rt.usizeShl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.usizeShr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a >>> 0); + } else if (_70 === 11) { + const part12 = rt.usizeCheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.usizeCheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.usizeCheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.usizeSaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.usizeSaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.usizeWrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.usizeWrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.usizeLeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.usizeLeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.usizeWrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.usize = rt.usizeAdd(a, b); rt.usizeMul(x, b); rt.usizeMul(rt.usizeSub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.usizeSaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.usizeWrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.usize | undefined = rt.usizeDivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.usizeIsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.usize = a; x2 = rt.usizeAdd(x2, b); @@ -635,23 +773,23 @@ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = (x2 & (~(1 << 2) >>> 0)) >>> 0; x2 = rt.usizeRem(x2, 7); x2 = rt.usizeDiv(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i8) => void = (out2: rt.ByteVec, v: rt.i8): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i8FromBeBytes(rt.i8ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i8) => void = (out2: rt.ByteVec, v2: rt.i8): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i8FromBeBytes(rt.i8ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i8 | undefined) => void = (out3: rt.ByteVec, v2: rt.i8 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i8 | undefined) => void = (out3: rt.ByteVec, v3: rt.i8 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i8 = v2; + const v4: rt.i8 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = Uint8Array.of(0); @@ -666,69 +804,92 @@ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i8 = rt.i8FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i8 = _38; + const buf3: Uint8Array = Uint8Array.of(0); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i8 = ([rt.i8FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i8, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 8); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i8Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i8Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i8Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i8Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i8Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i8Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i8Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i8CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i8CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i8CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i8SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i8SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i8WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i8WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i8Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i8Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i8Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i8Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i8Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i8Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i8Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i8CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i8CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i8CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i8SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i8SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i8WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i8WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i8LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i8LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i8WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i8 = rt.i8Add(a, b); rt.i8Mul(x, b); rt.i8Mul(rt.i8Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i8SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i8WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i8 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i8 = a; x2 = rt.i8Add(x2, b); @@ -741,23 +902,23 @@ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i8Rem(x2, 7); x2 = rt.i8Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i16) => void = (out2: rt.ByteVec, v: rt.i16): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i16FromBeBytes(rt.i16ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i16) => void = (out2: rt.ByteVec, v2: rt.i16): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i16FromBeBytes(rt.i16ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i16 | undefined) => void = (out3: rt.ByteVec, v2: rt.i16 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i16 | undefined) => void = (out3: rt.ByteVec, v3: rt.i16 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i16 = v2; + const v4: rt.i16 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(2); @@ -772,69 +933,92 @@ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i16 = rt.i16FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i16 = _38; + const buf3: Uint8Array = rt.bytes(2); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i16 = ([rt.i16FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i16, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 16); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i16Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i16Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i16Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i16Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i16Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i16Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i16Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i16CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i16CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i16CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i16SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i16SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i16WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i16WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i16Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i16Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i16Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i16Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i16Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i16Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i16Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i16CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i16CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i16CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i16SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i16SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i16WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i16WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i16LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i16LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i16WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i16 = rt.i16Add(a, b); rt.i16Mul(x, b); rt.i16Mul(rt.i16Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i16SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i16WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i16 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i16 = a; x2 = rt.i16Add(x2, b); @@ -847,23 +1031,23 @@ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i16Rem(x2, 7); x2 = rt.i16Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i32) => void = (out2: rt.ByteVec, v: rt.i32): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i32FromBeBytes(rt.i32ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i32) => void = (out2: rt.ByteVec, v2: rt.i32): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i32FromBeBytes(rt.i32ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i32 | undefined) => void = (out3: rt.ByteVec, v2: rt.i32 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i32 | undefined) => void = (out3: rt.ByteVec, v3: rt.i32 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i32 = v2; + const v4: rt.i32 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -878,69 +1062,92 @@ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i32 = rt.i32FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i32 = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i32 = ([rt.i32FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i32, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i32Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i32Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i32Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i32Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i32Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i32Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i32Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i32CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i32CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i32CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i32SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i32SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i32WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i32WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i32Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i32Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i32Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i32Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i32Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i32Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i32Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i32CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i32CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i32CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i32SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i32SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i32WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i32WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i32LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i32LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i32WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i32 = rt.i32Add(a, b); rt.i32Mul(x, b); rt.i32Mul(rt.i32Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i32SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i32WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i32 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i32 = a; x2 = rt.i32Add(x2, b); @@ -953,23 +1160,23 @@ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i32Rem(x2, 7); x2 = rt.i32Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i64) => void = (out2: rt.ByteVec, v: rt.i64): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v)))); - rt.byteVecPush(out2, rt.i64Eq(rt.i64FromBeBytes(rt.i64ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i64) => void = (out2: rt.ByteVec, v2: rt.i64): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v2)))); + rt.byteVecPush(out2, rt.i64Eq(rt.i64FromBeBytes(rt.i64ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i64 | undefined) => void = (out3: rt.ByteVec, v2: rt.i64 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i64 | undefined) => void = (out3: rt.ByteVec, v3: rt.i64 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i64 = v2; + const v4: rt.i64 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v3)))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v4)))); } }; const buf: Uint8Array = rt.bytes(8); @@ -984,69 +1191,92 @@ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i64 = rt.i64FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i64 = _38; + const buf3: Uint8Array = rt.bytes(8); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i64 = ([rt.i64FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i64, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 64); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i64Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i64Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i64Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i64Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i64Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.i64And(a, b)); - } else if (_52 === 6) { - _50(out, rt.i64Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.i64Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.i64Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i64Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.i64Not(a)); - } else if (_52 === 11) { - const part9 = rt.i64CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i64CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i64CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i64SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i64SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i64WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i64WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i64Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i64Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i64Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i64Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i64Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.i64And(a, b)); + } else if (_70 === 6) { + _68(out, rt.i64Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.i64Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.i64Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i64Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.i64Not(a)); + } else if (_70 === 11) { + const part12 = rt.i64CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i64CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i64CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i64SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i64SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i64WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i64WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i64LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i64LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.i64Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.i64Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.i64Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.i64Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.i64Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i64 = rt.i64Add(a, b); rt.i64Mul(x, b); rt.i64Mul(rt.i64Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i64SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i64WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.i64Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i64 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i64 = a; x2 = rt.i64Add(x2, b); @@ -1059,23 +1289,23 @@ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.i64And(x2, rt.i64Not(4)); x2 = rt.i64Rem(x2, 7); x2 = rt.i64Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i128) => void = (out2: rt.ByteVec, v: rt.i128): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v))); - rt.byteVecPush(out2, rt.i128Eq(rt.i128FromBeBytes(rt.i128ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i128) => void = (out2: rt.ByteVec, v2: rt.i128): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2))); + rt.byteVecPush(out2, rt.i128Eq(rt.i128FromBeBytes(rt.i128ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i128 | undefined) => void = (out3: rt.ByteVec, v2: rt.i128 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i128 | undefined) => void = (out3: rt.ByteVec, v3: rt.i128 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i128 = v2; + const v4: rt.i128 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4))); } }; const buf: Uint8Array = rt.bytes(16); @@ -1090,69 +1320,92 @@ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i128 = rt.i128FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i128 = _38; + const buf3: Uint8Array = rt.bytes(16); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i128 = ([rt.i128FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i128, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 128); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i128Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i128Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i128Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i128Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i128Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.i128And(a, b)); - } else if (_52 === 6) { - _50(out, rt.i128Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.i128Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.i128Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i128Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.i128Not(a)); - } else if (_52 === 11) { - const part9 = rt.i128CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i128CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i128CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i128SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i128SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i128WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i128WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i128Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i128Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i128Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i128Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i128Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.i128And(a, b)); + } else if (_70 === 6) { + _68(out, rt.i128Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.i128Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.i128Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i128Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.i128Not(a)); + } else if (_70 === 11) { + const part12 = rt.i128CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i128CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i128CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i128SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i128SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i128WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i128WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i128LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i128LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.i128Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.i128Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.i128Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.i128Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.i128Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i128 = rt.i128Add(a, b); rt.i128Mul(x, b); rt.i128Mul(rt.i128Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i128SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i128WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.i128Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i128 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i128 = a; x2 = rt.i128Add(x2, b); @@ -1165,23 +1418,23 @@ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.i128And(x2, rt.i128Not(rt.i128Shl(1, 2))); x2 = rt.i128Rem(x2, 7); x2 = rt.i128Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.isize) => void = (out2: rt.ByteVec, v: rt.isize): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.isizeFromBeBytes(rt.isizeToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.isize) => void = (out2: rt.ByteVec, v2: rt.isize): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.isizeFromBeBytes(rt.isizeToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.isize | undefined) => void = (out3: rt.ByteVec, v2: rt.isize | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.isize | undefined) => void = (out3: rt.ByteVec, v3: rt.isize | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.isize = v2; + const v4: rt.isize = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -1196,69 +1449,92 @@ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.isize = rt.isizeFromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.isize = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.isize = ([rt.isizeFromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.isize, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(unwrapOr$Option_u8(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.isizeAdd(a, b)); - } else if (_52 === 1) { - _50(out, rt.isizeSub(a, b)); - } else if (_52 === 2) { - _50(out, rt.isizeMul(a, b)); - } else if (_52 === 3) { - _50(out, rt.isizeDiv(a, b)); - } else if (_52 === 4) { - _50(out, rt.isizeRem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.isizeShl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.isizeShr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.isizeCheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.isizeCheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.isizeCheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.isizeSaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.isizeSaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.isizeWrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.isizeWrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.isizeAdd(a, b)); + } else if (_70 === 1) { + _68(out, rt.isizeSub(a, b)); + } else if (_70 === 2) { + _68(out, rt.isizeMul(a, b)); + } else if (_70 === 3) { + _68(out, rt.isizeDiv(a, b)); + } else if (_70 === 4) { + _68(out, rt.isizeRem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.isizeShl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.isizeShr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.isizeCheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.isizeCheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.isizeCheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.isizeSaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.isizeSaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.isizeWrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.isizeWrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.isizeLeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.isizeLeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.isizeWrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.isize = rt.isizeAdd(a, b); rt.isizeMul(x, b); rt.isizeMul(rt.isizeSub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.isizeSaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.isizeWrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.isize | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.isize = a; x2 = rt.isizeAdd(x2, b); @@ -1271,7 +1547,7 @@ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.isizeRem(x2, 7); x2 = rt.isizeDiv(x2, 3); - _50(out, x2); + _68(out, x2); } } diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index 2ca0d9413..2b8302b71 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; import { copy$Bumped, copy$u8_u8 } from "./lib.ts"; -import { unwrapOr$Option_i64, unwrapOr$Option_u64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_made_closure0_closure0, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_u8_u8_iters_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_ranges_closure0 } from "./core/option.ts"; +import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_i64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_made_closure0_closure0, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_u8_u8_iters_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_ranges_closure0 } from "./core/option.ts"; import * as Bumped from "./iters.Bumped.ts"; import * as Countdown from "./iters.Countdown.ts"; import * as Doubled from "./iters.Doubled.ts"; @@ -796,13 +796,13 @@ export function ranges(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.iterSum(new rt.Range(0, a as rt.u64, rt.u64Step), rt.u64Add, 0)))); const edge: rt.u64 = rt.u64Add(rt.u64Sub({ hi: 0x200000, lo: 0 } as rt.u64, 2), rt.u64Rem(a as rt.u64, 4)); const past: rt.Range = new rt.Range(edge, rt.u64Add(edge, 4), rt.u64Step); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_u64(rt.iterNth(past, rt.usizeRem(b as rt.usize, 3)), 0)))); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_u64(rt.iterToOption(past.nextBack()), 0)))); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_u64(rt.iterNth(new rt.RangeInclusive(edge, rt.u64Add(edge, 3), rt.u64Step), rt.usizeRem(b as rt.usize, 5)), 0)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_NonZero_u64(rt.iterNth(past, rt.usizeRem(b as rt.usize, 3)), 0)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_NonZero_u64(rt.iterToOption(past.nextBack()), 0)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_NonZero_u64(rt.iterNth(new rt.RangeInclusive(edge, rt.u64Add(edge, 3), rt.u64Step), rt.usizeRem(b as rt.usize, 5)), 0)))); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.iterSum(rt.iterMap(new rt.RangeInclusive(rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Rem(a as rt.u64, 3)), { hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Step), (n4: rt.u64): rt.u64 => { return rt.u64Rem(n4, 7); }), rt.u64Add, 0)))); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_u64(rt.iterMaxByKey(rt.iterRev(new rt.RangeInclusive(edge, rt.u64Add(edge, 2), rt.u64Step)), (_24: rt.u64): rt.u64 => { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_NonZero_u64(rt.iterMaxByKey(rt.iterRev(new rt.RangeInclusive(edge, rt.u64Add(edge, 2), rt.u64Step)), (_24: rt.u64): rt.u64 => { return _24; }), 0)))); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i64ToBeBytes(unwrapOr$Option_i64(rt.iterMin(new rt.Range(rt.i64Sub(rt.i64Neg({ hi: 0x200000, lo: 0 } as rt.i64), 1), rt.i64Add(rt.i64Neg({ hi: 0x200000, lo: 0 } as rt.i64), 1), rt.i64Step)), 0)))); diff --git a/ts/fixtures/lang/expected/keys.ts b/ts/fixtures/lang/expected/keys.ts index 0517eeb18..a8ff381f4 100644 --- a/ts/fixtures/lang/expected/keys.ts +++ b/ts/fixtures/lang/expected/keys.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; import { copy$Hop, copy$Horizon, copy$u8_Horizon } from "./lib.ts"; -import { unwrapOr$Option_u16, unwrapOr$Option_u64, unwrapOr$Option_u8, map$Option_Hop_u64_defaults_closure0, map$Option_Hop_u64_u64_options_closure0, map$Option_Way_bool_defaults_closure2, map$Option_u8_Side_side, mapOr$Option_Hop_u64_options_closure2, mapOr$Option_Ordering_u8_order } from "./core/option.ts"; +import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_u16, unwrapOr$Option_u8, map$Option_Hop_u64_defaults_closure0, map$Option_Hop_u64_u64_options_closure0, map$Option_Way_bool_defaults_closure2, map$Option_u8_Side_side, mapOr$Option_Hop_u64_options_closure2, mapOr$Option_Ordering_u8_order } from "./core/option.ts"; import * as Hop from "./keys.Hop.ts"; import * as Horizon from "./keys.Horizon.ts"; import * as Liar from "./keys.Liar.ts"; @@ -495,9 +495,9 @@ export function options(data: rt.ByteSlice, out: rt.ByteVec): void { const a: Hop.Hop | undefined = _27[0]; const b: Hop.Hop | undefined = _27[1]; rt.byteVecPush(out, (rt.eqOption(Hop.eq$PartialEq)(a, b) ? 1 : 0) | (((!rt.eqOption(Hop.eq$PartialEq)(a, b) ? 1 : 0) << 1) & 0xff) | ((order(rt.cmpOption(Hop.cmp$Ord)(a, b)) << 2) & 0xff)); - const _56: Hop.Hop | undefined = rt.ordMax(a, b, rt.cmpOption(Hop.cmp$Ord)); + const _56: Hop.Hop | undefined = rt.ordMax(a, b, rt.cmpOption(Hop.partialCmp$PartialOrd)); const _53: rt.u8 = rt.eqOption(Hop.eq$PartialEq)(_56, b) ? 1 : 0; - const _62: Hop.Hop | undefined = rt.ordMin(a, b, rt.cmpOption(Hop.cmp$Ord)); + const _62: Hop.Hop | undefined = rt.ordMin(a, b, rt.cmpOption(Hop.partialCmp$PartialOrd)); rt.byteVecPush(out, _53 | (((rt.eqOption(Hop.eq$PartialEq)(_62, a) ? 1 : 0) << 1) & 0xff)); rt.byteVecPush(out, rt.u64Eq(hashOf$Option_Hop(a), hashOf$Option_Hop(b)) ? 1 : 0); const _75: [rt.u8 | undefined, rt.u8 | undefined] = [small(c), small(d)]; @@ -850,10 +850,9 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { _132.v = (_132.v << 4) & 0xffff; } const _139: Hop.Hop = { _0: rt.u64Rem(b as rt.u64, 3) }; - const p: rt.Place<[rt.u8, rt.u8]> = rt.entryOrInsertMut(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); - const _144: rt.u8 = rt.u8WrappingAdd(p.v[0], b); - p.v[0] = _144; - p.v[1] = p.v[1] ^ p.v[0]; + const p: [rt.u8, rt.u8] = rt.entryOrInsert(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); + p[0] = rt.u8WrappingAdd(p[0], b); + p[1] = p[1] ^ p[0]; } const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; const _150: rt.usize = rt.usizeMul(data.length, 4); @@ -914,7 +913,7 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { let iterStart2: rt.u8 = 0; const iterEnd2: rt.u8 = 7; while ((_257 = iterStart2++) < iterEnd2) { - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_u64(rt.hashGet(wide, _257), 0)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(unwrapOr$Option_NonZero_u64(rt.hashGet(wide, _257), 0)))); } const iter6: rt.Range = new rt.Range(0, 6, rt.u64Step); while (true) { diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index b1670cb20..a2c3b3dfe 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -152,6 +152,10 @@ export function copy$Wrap_u8(v: Wrap.Wrap): Wrap.Wrap { return new Wrap.Wrap({ value: v.value, count: v.count }); } +export function copy$chars(v: rt.char[]): rt.char[] { + return v.slice(); +} + export function copy$u32s(v: rt.u32[]): rt.u32[] { return v.slice(); } diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 5318f70a2..f9f13d9a6 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -66,12 +66,11 @@ export function rebox(b: rt.Place, by: rt.u8): void { } } -export function swapPair(p: rt.Place<[rt.u8, rt.u8]>): void { - const swapped = p.v[0]; - p.v[0] = p.v[1]; - p.v[1] = swapped; - const _5: rt.u8 = rt.u8WrappingAdd(p.v[1], 1); - p.v[1] = _5; +export function swapPair(p: [rt.u8, rt.u8]): void { + const swapped = p[0]; + p[0] = p[1]; + p[1] = swapped; + p[1] = rt.u8WrappingAdd(p[1], 1); } export function refuse(f: rt.Place): void { @@ -205,15 +204,15 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { } rt.byteVecPush(out, unwrapOr$Option_u8(slot, 238)); let boxed: Pair.Pair = { n: by }; - let pair: [rt.u8, rt.u8] = [by, rt.u8WrappingAdd(by, 1)]; + const pair: [rt.u8, rt.u8] = [by, rt.u8WrappingAdd(by, 1)]; let fetch = { tag: "Idle" } as Fetch.Fetch; let text: string = ""; for (const b2 of rt.byteSliceView(data)) { rebox(rt.place(() => boxed, (value7) => boxed = value7), b2); - swapPair(rt.place(() => pair, (value8) => pair = value8)); - refuse(rt.place(() => fetch, (value9) => fetch = value9)); + swapPair(pair); + refuse(rt.place(() => fetch, (value8) => fetch = value8)); const _120: rt.char = rt.u8Add(97, rt.u8Rem(b2, 26)) as rt.char; - pushTo(rt.place(() => text, (value10) => text = value10), _120); + pushTo(rt.place(() => text, (value9) => text = value9), _120); } rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(boxed.n, pair[0], pair[1]))); if (fetch.tag === "Idle") { @@ -226,11 +225,11 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, _133); rt.byteVecExtendFromSlice(out, rt.stringAsBytes(text)); let empty: rt.u8 | undefined = undefined; - rt.byteVecPush(out, fill(rt.place(() => empty, (value11) => empty = value11), rt.place(() => text, (value12) => text = value12), by)); + rt.byteVecPush(out, fill(rt.place(() => empty, (value10) => empty = value10), rt.place(() => text, (value11) => text = value11), by)); const _148: rt.u8 = rt.u8WrappingAdd(by, 1); - rt.byteVecPush(out, fill(rt.place(() => empty, (value13) => empty = value13), rt.place(() => text, (value14) => text = value14), _148)); + rt.byteVecPush(out, fill(rt.place(() => empty, (value12) => empty = value12), rt.place(() => text, (value13) => text = value13), _148)); let at: rt.usize = 0; - const cursor: Cursor.Cursor = { at: rt.place(() => at, (value15) => at = value15), data }; + const cursor: Cursor.Cursor = { at: rt.place(() => at, (value14) => at = value14), data }; let sum: rt.u8 = 0; while (true) { const _153: rt.u8 | undefined = Cursor.next(cursor); @@ -247,14 +246,14 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, sum); rt.byteVecPush(out, at & 0xff); let remaining: rt.usize = rt.u8Rem(by, 5) as rt.usize; - rt.byteVecPush(out, skip(rt.place(() => remaining, (value16) => remaining = value16), data) & 0xff); + rt.byteVecPush(out, skip(rt.place(() => remaining, (value15) => remaining = value15), data) & 0xff); rt.byteVecPush(out, remaining & 0xff); const _177: [Pair.Pair, Pair.Pair] = [{ n: 1 }, { n: 2 }]; const a: Pair.Pair = _177[0]; const b4: Pair.Pair = _177[1]; let p: Pair.Pair = a; const borrowed = p; - const r: rt.Place = rt.place(() => borrowed.n, (value17) => borrowed.n = value17); + const r: rt.Place = rt.place(() => borrowed.n, (value16) => borrowed.n = value16); p = b4; bumpByte(r); p.n = rt.u8Add(p.n, 10); @@ -285,17 +284,17 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { } let total: rt.u32 = 0; for (const b6 of rt.byteSliceView(data)) { - _238(rt.place(() => total, (value18) => total = value18), b6); + _238(rt.place(() => total, (value17) => total = value17), b6); } rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(total))); const _256: [rt.u32, rt.u32] = [by as rt.u32, unwrapOr$Option_u8(rt.byteSliceGet(data, 1), 5) as rt.u32]; let x2: rt.u32 = _256[0]; let y: rt.u32 = _256[1]; - readThrough(rt.place(() => x2, (value19) => x2 = value19), rt.place(() => y, (value20) => y = value20), out); + readThrough(rt.place(() => x2, (value18) => x2 = value18), rt.place(() => y, (value19) => y = value19), out); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(x2 & 0xff, y & 0xff))); let boxed2: rt.u8 | undefined = undefined as rt.u8 | undefined; const _277: rt.u8 = total & 0xff; - derefBox(rt.place(() => boxed2, (value21) => boxed2 = value21), _277); + derefBox(rt.place(() => boxed2, (value20) => boxed2 = value20), _277); rt.byteVecPush(out, unwrapOr$Option_u8(boxed2, 238)); } diff --git a/ts/fixtures/lang/expected/wrappers.Scale.ts b/ts/fixtures/lang/expected/wrappers.Scale.ts new file mode 100644 index 000000000..c9ff4733c --- /dev/null +++ b/ts/fixtures/lang/expected/wrappers.Scale.ts @@ -0,0 +1,22 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function eq$PartialEq(self: Scale, other: Scale): boolean { + return rt.u64Eq(self._0, other._0); +} + +export function partialCmp$PartialOrd(self: Scale, other: Scale): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + +export function cmp$Ord(self: Scale, other: Scale): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** A rate that is never 0, as a timescale is. */ +export interface Scale { + _0: rt.u64; +} + +//# sourceMappingURL=wrappers.Scale.ts.map diff --git a/ts/fixtures/lang/expected/wrappers.ts b/ts/fixtures/lang/expected/wrappers.ts new file mode 100644 index 000000000..094af34ef --- /dev/null +++ b/ts/fixtures/lang/expected/wrappers.ts @@ -0,0 +1,442 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_u8 } from "./core/option.ts"; +import { put } from "./fmt.ts"; +import * as Scale from "./wrappers.Scale.ts"; + +export function putU64(out: rt.ByteVec, v: rt.u64): void { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(v))); +} + +export function putBound(out: rt.ByteVec, b: rt.RangeBound): void { + if (b.tag === "Included") { + rt.byteVecPush(out, 1); + putU64(out, (b as { tag: "Included"; _0: rt.u64 })._0); + } else if (b.tag === "Excluded") { + rt.byteVecPush(out, 2); + putU64(out, (b as { tag: "Excluded"; _0: rt.u64 })._0); + } else { + rt.byteVecPush(out, 3); + } +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$Bound_u64_Bound_u64(out: rt.ByteVec, r: [rt.RangeBound, rt.RangeBound]): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, r[0]); + putBound(out, r[1]); + const _10: rt.RangeBound = r[0]; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = r[1]; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeFrom_u64(out: rt.ByteVec, r: { start: rt.u64 }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Included", _0: r.start } as rt.RangeBound); + putBound(out, { tag: "Unbounded" } as rt.RangeBound); + const _10: rt.RangeBound = { tag: "Included", _0: r.start } as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = { tag: "Unbounded" } as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeFull(out: rt.ByteVec, _: undefined): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.RangeBound); + putBound(out, { tag: "Unbounded" } as rt.RangeBound); + const _10: rt.RangeBound = { tag: "Unbounded" } as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = { tag: "Unbounded" } as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeInclusive_u64(out: rt.ByteVec, r: rt.RangeInclusive): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, rt.rangeInclusiveStartBound(r) as rt.RangeBound); + putBound(out, rt.rangeInclusiveEndBound(r) as rt.RangeBound); + const _10: rt.RangeBound = rt.rangeInclusiveStartBound(r) as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = rt.rangeInclusiveEndBound(r) as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeToInclusive_u64(out: rt.ByteVec, r: { end: rt.u64; inclusive: true }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.RangeBound); + putBound(out, { tag: "Included", _0: r.end } as rt.RangeBound); + const _10: rt.RangeBound = { tag: "Unbounded" } as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = { tag: "Included", _0: r.end } as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeTo_u64(out: rt.ByteVec, r: { end: rt.u64 }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.RangeBound); + putBound(out, { tag: "Excluded", _0: r.end } as rt.RangeBound); + const _10: rt.RangeBound = { tag: "Unbounded" } as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = { tag: "Excluded", _0: r.end } as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$Range_u64(out: rt.ByteVec, r: rt.Range): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Included", _0: r.start } as rt.RangeBound); + putBound(out, { tag: "Excluded", _0: r.end } as rt.RangeBound); + const _10: rt.RangeBound = { tag: "Included", _0: r.start } as rt.RangeBound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.RangeBound = { tag: "Excluded", _0: r.end } as rt.RangeBound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, unwrapOr$Option_NonZero_u64(start, 0)); + putU64(out, unwrapOr$Option_NonZero_u64(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** A bound of `a` picked by `kind`, held by value. */ +export function boundOf(kind: rt.u8, a: rt.u64): rt.RangeBound { + const _3: rt.u8 = rt.u8Rem(kind, 3); + if (_3 === 0) { + return { tag: "Included", _0: a } as rt.RangeBound; + } + if (_3 === 1) { + return { tag: "Excluded", _0: a } as rt.RangeBound; + } + return { tag: "Unbounded" } as rt.RangeBound; +} + +export function wrappers(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + let scale!: Scale.Scale; + let name!: string; + const _5: (a0: rt.u8) => rt.u64 = (b3: rt.u8): rt.u64 => { + const _3: rt.u8 = rt.u8Rem(b3, 4); + if (_3 === 0) { + return b3 as rt.u64; + } + if (_3 === 1) { + return rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, b3 as rt.u64); + } + if (_3 === 2) { + return rt.u64Add({ hi: 0x200000, lo: 0 } as rt.u64, b3 as rt.u64); + } + return rt.u64Mul(b3 as rt.u64, 7); + }; + const at: (a0: rt.usize) => rt.u8 = (i3: rt.usize): rt.u8 => { + return unwrapOr$Option_u8(rt.byteSliceGet(data, i3), 0); + }; + const part = at(0); + const _9: rt.u64 = _5(part); + const part2 = at(1); + const _8: [rt.u64, rt.u64] = [_9, _5(part2)]; + const a: rt.u64 = _9; + const b: rt.u64 = _8[1]; + const _21: rt.u8 = rt.u8Rem(kind, 5); + if (_21 === 0) { + bounds$Range_u64(out, new rt.Range(a, b, rt.u64Step)); + bounds$RangeInclusive_u64(out, new rt.RangeInclusive(a, b, rt.u64Step)); + const stepped: rt.RangeInclusive = new rt.RangeInclusive(rt.u64Rem(a, 4), rt.u64Rem(b, 4), rt.u64Step); + while (rt.iterToOption(stepped.next()) !== undefined) { + } + bounds$RangeInclusive_u64(out, stepped); + const top: rt.RangeInclusive = new rt.RangeInclusive(rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Rem(a, 2)), { hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Step); + while (rt.iterToOption(top.next()) !== undefined) { + } + bounds$RangeInclusive_u64(out, top); + const down: rt.RangeInclusive = new rt.RangeInclusive(0, rt.u64Rem(b, 3), rt.u64Step); + while (rt.iterToOption(down.nextBack()) !== undefined) { + } + bounds$RangeInclusive_u64(out, down); + bounds$RangeTo_u64(out, { end: b }); + bounds$RangeToInclusive_u64(out, { end: b, inclusive: true }); + bounds$RangeFrom_u64(out, { start: a }); + bounds$RangeFull(out, undefined); + bounds$Bound_u64_Bound_u64(out, [boundOf(at(2), a), boundOf(at(3), b)] as [rt.RangeBound, rt.RangeBound]); + const held: [rt.RangeBound, rt.RangeBound] = [boundOf(at(3), b), { tag: "Unbounded" } as rt.RangeBound]; + bounds$Bound_u64_Bound_u64(out, held); + putBound(out, held[0]); + const _87: [{ end: rt.usize }, { start: rt.usize }] = [{ end: rt.usizeRem(at(2) as rt.usize, rt.usizeAdd(data.length, 1)) }, { start: rt.usizeRem(at(3) as rt.usize, rt.usizeAdd(data.length, 1)) }]; + const to: { end: rt.usize } = _87[0]; + const from: { start: rt.usize } = _87[1]; + putU64(out, rt.usizeAdd(to.end, from.start) as rt.u64); + putU64(out, b); + rt.byteVecPush(out, rt.byteSliceRange(data, 0, to.end).length & 0xff); + rt.byteVecPush(out, rt.byteSliceRange(data, from.start).length & 0xff); + } else if (_21 === 1) { + const map: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; + const iter: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))); + while (true) { + const _132: [rt.usize, rt.u8] | rt.Done = iter.next(); + if (_132 === rt.DONE) { + break; + } + rt.btreeInsert(map, _132[1] as rt.u64, _132[0] as rt.u64); + } + const _143: [rt.u64, rt.u64] = [at(0) as rt.u64, at(1) as rt.u64]; + const a2: rt.u64 = _143[0]; + const b2: rt.u64 = _143[1]; + const iter2: rt.Iter<[rt.u64, rt.u64]> = rt.btreeRange(map, { end: a2, inclusive: true }); + while (true) { + const _157: [rt.u64, rt.u64] | rt.Done = iter2.next(); + if (_157 === rt.DONE) { + break; + } + putU64(out, _157[0]); + putU64(out, _157[1]); + } + rt.byteVecPush(out, 254); + const _167: [rt.u64, rt.u64] | undefined = rt.iterToOption(rt.btreeRange(map, { end: b2, inclusive: true }).nextBack()); + if (_167 !== undefined) { + putU64(out, _167[0]); + } + rt.byteVecPush(out, rt.iterCount(rt.btreeRange(map, { end: a2 })) & 0xff); + const top2: rt.RangeInclusive = new rt.RangeInclusive(rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Rem(a2, 2)), { hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Step); + while (rt.iterToOption(top2.next()) !== undefined) { + } + const bottom: rt.RangeInclusive = new rt.RangeInclusive(0, rt.u64Rem(b2, 2), rt.u64Step); + while (rt.iterToOption(bottom.nextBack()) !== undefined) { + } + rt.byteVecPush(out, rt.iterCount(rt.btreeRange(map, top2)) & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.btreeRange(map, bottom)) & 0xff); + const above: rt.BTreeMap = rt.btreeSplitOff(map, b2); + const iter3: rt.Iter<[rt.u64, rt.u64]> = rt.iterChain(rt.btreeIter(map), rt.btreeIter(above)); + while (true) { + const _220: [rt.u64, rt.u64] | rt.Done = iter3.next(); + if (_220 === rt.DONE) { + break; + } + putU64(out, _220[0]); + putU64(out, _220[1]); + } + rt.byteVecPush(out, rt.btreeLen(map) & 0xff); + rt.byteVecPush(out, rt.btreeLen(above) & 0xff); + const _238: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _238, true); + const _243: rt.u8 = at(2); + const high: rt.BTreeSet = rt.btreeSplitOff(set, _243); + rt.iterExtendBytes(out, rt.iterChain(rt.btreeKeys(set), rt.btreeKeys(high))); + rt.byteVecPush(out, rt.btreeLen(high) & 0xff); + } else if (_21 === 2) { + const _258: [rt.u8, rt.u8] = [at(0), at(1)]; + const x2: rt.u8 = _258[0]; + const y: rt.u8 = _258[1]; + rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) & 0xff); + rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) === -1 ? 1 : 0); + rt.byteVecPush(out, rt.cmpReverse(rt.cmpOption(rt.cmp))(x2, undefined) === 1 ? 1 : 0); + rt.byteVecPush(out, rt.ordMax(x2, y, rt.cmpReverse(rt.cmp))); + const order = rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])([x2, y] as [rt.u8, rt.u8], [y, x2] as [rt.u8, rt.u8]); + rt.byteVecPush(out, order !== undefined && order <= 0 ? 1 : 0); + const _302: rt.Iter<[rt.u8, rt.usize]> = rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_2: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { + return [_2[1], _2[0]] as [rt.u8, rt.usize]; + }); + const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmpReverse(rt.cmp)) as rt.BTreeMap, _302, true)); + while (true) { + const _308: [rt.u8, rt.usize] | rt.Done = iter4.next(); + if (_308 === rt.DONE) { + break; + } + rt.byteVecPush(out, _308[0]); + rt.byteVecPush(out, _308[1] & 0xff); + } + const ranked: [rt.u8, rt.usize][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_23: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { + return [_23[1], _23[0]] as [rt.u8, rt.usize]; + })); + rt.sliceSortByKey(ranked, (_25: [rt.u8, rt.usize]): [rt.u8, rt.usize] => { + return [rt.u8Rem(_25[0], 4), _25[1]] as [rt.u8, rt.usize]; + }, rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])); + for (const _328 of ranked) { + const d: rt.u8 = _328[0]; + const i2: rt.usize = _328[1]; + rt.byteVecPush(out, d); + rt.byteVecPush(out, i2 & 0xff); + } + put(out, "held"); + } else if (_21 === 3) { + const n: rt.u64 | undefined = rt.nonZero(a); + if (n === undefined) { + rt.byteVecPush(out, 0); + } else { + const n2: rt.u64 = n; + putU64(out, n2); + putU64(out, n2); + const _360: rt.u64 = unwrapOr$Option_NonZero_u64(rt.nonZero(b), n2); + const _357: boolean = rt.u64Eq(n2, _360); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.u64Debug(n2, f), (f: rt.Formatter) => rt.fmtBool(_357, f)]; + put(out, rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2]])); + rt.byteVecPush(out, rt.u64Gt(n2, { _0: 1 }._0) ? 1 : 0); + rt.byteVecPush(out, rt.cmp(n2, { _0: 1000 }._0) & 0xff); + } + rt.byteVecPush(out, rt.nonZero(rt.u64And(a, 1)) !== undefined ? 1 : 0); + } else { + const _387: rt.u64 | undefined = rt.nonZero(a); + b1: { + if (_387 !== undefined) { + if (rt.u8Rem(at(2), 2) === 0) { + scale = { _0: _387 }; + break b1; + } + } + const _398: rt.usize = rt.usizeRem(at(3) as rt.usize, 3); + if (!(_398 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _398); + } + scale = [{ _0: 1 }, { _0: 1000 }, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }][_398]; + } + if (!rt.u64Eq(1, scale._0)) { + if (!rt.u64Eq(1000, scale._0)) { + if (!rt.u64Eq({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, scale._0)) { + name = "other"; + } else { + name = "wide"; + } + } else { + name = "milli"; + } + } else { + name = "one"; + } + put(out, name); + rt.byteVecPush(out, Scale.eq$PartialEq(scale, { _0: 1000 }) ? 1 : 0); + rt.byteVecPush(out, Scale.partialCmp$PartialOrd(scale, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }) === -1 ? 1 : 0); + putU64(out, scale._0); + } +} + +//# sourceMappingURL=wrappers.ts.map diff --git a/ts/fixtures/lang/src/edits.rs b/ts/fixtures/lang/src/edits.rs new file mode 100644 index 000000000..f85832c0c --- /dev/null +++ b/ts/fixtures/lang/src/edits.rs @@ -0,0 +1,298 @@ +//! `Vec`'s and slices' editing and sorting methods, with closures that log what they are +//! called with, `Clone` and comparisons of vectors and tuples that are not `Copy`, +//! `mem::take`, `Ord`'s defaults on the crate's own types, and `str`'s byte searches. + +use std::cmp::Ordering; +use std::collections::{BTreeSet, VecDeque}; + +use crate::fmt::put; +use crate::strs::text; + +/// The crate's own order, whose `min`, `max`, and `clamp` are `Ord`'s defaults. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] +struct Stamp(u8); + +/// An order whose `partial_cmp` leans on its first operand, an odd one less than any, and +/// whose `cmp` is by value, so what `Ord`'s defaults call, with which operand first, shows. +#[derive(Clone, Copy, PartialEq, Eq)] +struct Lean(u8); + +#[allow(clippy::non_canonical_partial_ord_impl)] +impl PartialOrd for Lean { + fn partial_cmp(&self, other: &Self) -> Option { + Some(match self.0 % 2 { + 1 => Ordering::Less, + _ => self.0.cmp(&other.0), + }) + } +} + +impl Ord for Lean { + fn cmp(&self, other: &Self) -> Ordering { + self.0.cmp(&other.0) + } +} + +/// What `mem::take` leaves its own `Default` in place of. +struct Tally { + n: u8, + names: Vec, +} + +impl Default for Tally { + fn default() -> Self { + Self { + n: 7, + names: vec![String::from("fresh")], + } + } +} + +/// An element that is not `Copy`, cloned and compared field by field. +#[derive(Clone, PartialEq, PartialOrd)] +struct Named { + id: u16, + name: String, +} + +fn put_u16s(out: &mut Vec, v: &[u16]) { + for x in v { + out.extend_from_slice(&x.to_be_bytes()); + } + out.push(0xfe); +} + +pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { + let words: Vec = data.iter().map(|&b| b as u16 * 3).collect(); + let at = |i: usize| data.get(i).copied().unwrap_or(0); + match kind % 7 { + 0 => { + // `retain` sees each element once, in order, and keeps what it returns true for. + let mut v = words.clone(); + let mut seen = Vec::new(); + v.retain(|&x| { + seen.push(x); + x % 4 != 0 + }); + put_u16s(out, &seen); + put_u16s(out, &v); + let mut pairs: Vec<(u16, u16)> = words.iter().map(|&w| (w, 0)).collect(); + pairs.retain_mut(|p| { + p.1 = p.0 / 2; + p.0 % 3 == 0 + }); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + let mut names: Vec = data.iter().map(|&b| text(&[b])).collect(); + names.retain(|s| s.len() > 1); + out.push(names.len() as u8); + // Panics on the element the last byte names, keeping what it decided. + let stop = at(data.len().saturating_sub(1)) as u16 * 3; + if kind & 0x80 != 0 { + v.retain(|&x| { + if x == stop { + panic!("retain stopped at {x}"); + } + true + }); + } + } + 1 => { + // Runs of equal neighbors, by value, by a key, and by a test that logs what it + // compares, current first. + let mut v: Vec = data.iter().map(|&b| (b % 4) as u16).collect(); + v.dedup(); + put_u16s(out, &v); + // By what each element's closure reads through its `&mut`. + let named = |w: u16| Named { + id: w, + name: text(&[w as u8 / 16]), + }; + let mut keyed: Vec = words.iter().map(|&w| named(w)).collect(); + keyed.dedup_by_key(|n| n.id / 24); + for n in &keyed { + put_u16s(out, &[n.id]); + } + let mut tested: Vec = words.iter().map(|&w| named(w)).collect(); + let mut seen = Vec::new(); + tested.dedup_by(|a, b| { + seen.push(a.id); + seen.push(b.id); + a.name == b.name + }); + put_u16s(out, &seen); + for n in &tested { + put(out, &n.name); + } + let mut names: Vec = data.iter().map(|&b| text(&[b % 3])).collect(); + names.dedup(); + out.push(names.len() as u8); + } + 2 => { + let mut v = words.clone(); + v.sort(); + put_u16s(out, &v); + let mut v = words.clone(); + v.sort_unstable_by(|a, b| b.cmp(a)); + put_u16s(out, &v); + // Stable: equal keys keep their order. + let mut pairs: Vec<(u16, u16)> = words.iter().enumerate().map(|(i, &w)| (w % 5, i as u16)).collect(); + pairs.sort_by_key(|p| p.0); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + pairs.sort_unstable_by_key(|&(a, b)| (b % 3, a, b)); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + pairs.sort_by(|x, y| y.1.cmp(&x.1)); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + // `None` first, as `Option`'s `Ord` puts it. + let mut options: Vec> = + words.iter().map(|&w| if w % 2 == 0 { None } else { Some(w) }).collect(); + options.sort_unstable(); + for o in &options { + put_u16s(out, &[o.map_or(0xffff, |o| o)]); + } + let mut names: Vec = data.iter().map(|&b| text(&[b, b / 16])).collect(); + names.sort(); + for name in &names { + put(out, name); + } + } + 3 => { + let mut v = words.clone(); + put_u16s(out, &[v.last().copied().unwrap_or(0xffff)]); + let mut runs: Vec<(u16, Option)> = words.iter().map(|&w| (w, None)).collect(); + if let Some(last) = runs.last_mut() { + last.1 = Some(last.0); + } + if let Some(first) = runs.first_mut() { + first.0 += 1; + } + for (a, b) in &runs { + put_u16s(out, &[*a, b.unwrap_or(0xffff)]); + } + v.reverse(); + put_u16s(out, &v); + let named: Vec = words + .iter() + .map(|&w| Named { + id: w, + name: text(&[w as u8]), + }) + .collect(); + let probe = Named { + id: at(1) as u16 * 3, + name: text(&[at(1).wrapping_mul(3)]), + }; + out.push(named.contains(&probe) as u8); + out.push(words.contains(&(at(2) as u16 * 3)) as u8); + out.push(data.contains(&at(3)) as u8); + // Each panics with std's message past the end. + let (i, j) = (at(0) as usize % 8, at(1) as usize % 8); + let mut moved = words.clone(); + let taken = moved.swap_remove(i); + put_u16s(out, &[taken]); + put_u16s(out, &moved); + moved.swap(i, j); + put_u16s(out, &moved); + } + 4 => { + // Clones and comparisons of what is not `Copy`, element by element. + let named: Vec = words + .iter() + .map(|&w| Named { + id: w, + name: text(&[w as u8]), + }) + .collect(); + let cloned = named.clone(); + out.push((cloned == named) as u8); + let mut changed = named.to_vec(); + if let Some(first) = changed.first_mut() { + first.name.push('!'); + } + out.push((changed == named) as u8); + out.push((changed != named) as u8); + out.push((changed < named) as u8); + changed.extend_from_slice(&named[..named.len() / 2]); + out.push(changed.len() as u8); + let nested: Vec> = data + .iter() + .map(|&b| (0..b % 3).map(|i| i as u16 + b as u16).collect()) + .collect(); + out.push((nested.clone() == nested) as u8); + let pair = (text(data), at(0)); + let copy = pair.clone(); + put(out, ©.0); + out.push(((copy.1, ©.0) > (at(1), &pair.0)) as u8); + out.push(((at(0), at(1)) < (at(1), at(0))) as u8); + let mut grown = words.clone(); + grown.extend_from_slice(&words); + put_u16s(out, &grown); + } + 5 => { + // Taken, leaving each type's own `Default`. + let mut tally = Tally { + n: at(0), + names: vec![text(data)], + }; + let taken = std::mem::take(&mut tally); + out.push(taken.n); + out.push(tally.n); + put(out, &tally.names[0]); + let mut queue: VecDeque = words.iter().copied().collect(); + let drained = std::mem::take(&mut queue); + out.push(drained.len() as u8); + out.push(queue.len() as u8); + let mut set: BTreeSet = words.iter().copied().collect(); + out.push(std::mem::take(&mut set).len() as u8); + out.push(set.is_empty() as u8); + // `Ord`'s defaults of the crate's own type; `clamp` panics on bounds out of order. + let (x, lo, hi) = (Stamp(at(0)), Stamp(at(1)), Stamp(at(2))); + out.push(x.max(lo).0); + out.push(x.min(lo).0); + out.push(x.clamp(lo, hi).0); + // By `<`, `<=`, and `>`, which call `partial_cmp`, `other` first in `max` and `min`. + let (p, q, r) = (Lean(at(0)), Lean(at(1)), Lean(at(2))); + out.push(p.max(q).0); + out.push(p.min(q).0); + out.push(p.clamp(q, r).0); + } + _ => { + let s = text(data); + let sep = ['/', 'a']; + out.push(s.contains(sep) as u8); + out.push(s.contains(&sep[..]) as u8); + out.push(s.split(sep).count() as u8); + out.push(s.ends_with("/") as u8); + out.push(s.ends_with('😀') as u8); + out.push(s.ends_with(|c: char| c.is_ascii_digit()) as u8); + match s.split_once('/') { + Some((head, tail)) => { + put(out, head); + put(out, tail); + } + None => out.push(0xfd), + } + match s.split_once("a0") { + Some((head, tail)) => { + put(out, head); + put(out, tail); + } + None => out.push(0xfd), + } + for i in 0..=s.len() + 1 { + out.push(s.is_char_boundary(i) as u8); + } + out.extend(s.bytes()); + out.extend(s.bytes().rev().take(3)); + out.push(s.bytes().len() as u8); + out.push(s.bytes().filter(|&b| b >= 0x80).count() as u8); + } + } +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index a463eb2ee..a7044df81 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -2,8 +2,8 @@ //! case and the rest is its input. use crate::{ - chars, chunks, collections, combinators, cows, durations, fmt, generics, ints, iters, keys, nested, refs, shapes, - splits, strs, + chars, chunks, collections, combinators, cows, durations, edits, fmt, generics, ints, iters, keys, nested, refs, + shapes, splits, strs, wrappers, }; /// The native side's entry: [`run`], except that a case starting with 0xff prints a @@ -22,7 +22,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 55 { + match op % 57 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -87,7 +87,9 @@ pub fn run(input: &[u8]) -> Vec { 51 => refs::refs(data, &mut out), 52 => fmt::counts(data, &mut out), 53 => fmt::rounding(&mut out), - _ => iters::skips(kind, data, &mut out), + 54 => iters::skips(kind, data, &mut out), + 55 => wrappers::wrappers(kind, data, &mut out), + _ => edits::edits(kind, data, &mut out), } out } diff --git a/ts/fixtures/lang/src/ints.rs b/ts/fixtures/lang/src/ints.rs index 3bd5d32ee..14606db57 100644 --- a/ts/fixtures/lang/src/ints.rs +++ b/ts/fixtures/lang/src/ints.rs @@ -11,12 +11,34 @@ macro_rules! take { }}; } +/// `a.div_ceil(b)` of an unsigned type, which a signed one lacks. +macro_rules! div_ceil { + (unsigned, $t:ty, $a:expr, $b:expr) => { + Some($a.div_ceil($b)) + }; + (signed, $t:ty, $a:expr, $b:expr) => { + None::<$t> + }; +} + +/// `a.is_multiple_of(b)` of an unsigned type, which a signed one lacks. +macro_rules! is_multiple_of { + (unsigned, $a:expr, $b:expr) => { + Some($a.is_multiple_of($b)) + }; + (signed, $a:expr, $b:expr) => { + None:: + }; +} + macro_rules! ops { - ($name:ident, $t:ty, $wide:ty) => { + ($name:ident, $t:ty, $wide:ty, $sign:ident) => { /// Apply operation `op` to operands taken from `data`. pub fn $name(op: u8, data: &[u8], out: &mut Vec) { let (a, data) = take!($t, data); let (b, data) = take!($t, data); + // A third operand, from the bytes the shift is read from. + let (c, _) = take!($t, data); let shift = data.first().copied().unwrap_or(0) as u32 % (2 * <$t>::BITS); let put = |out: &mut Vec, v: $t| { out.extend_from_slice(&(v as $wide).to_be_bytes()); @@ -30,7 +52,7 @@ macro_rules! ops { } None => out.push(0), }; - match op % 25 { + match op % 30 { 0 => put(out, a + b), 1 => put(out, a - b), 2 => put(out, a * b), @@ -67,6 +89,20 @@ macro_rules! ops { let _ = (x - b) * a; out.push(1); } + 24 => put(out, a.saturating_mul(b)), + 25 => put(out, a.wrapping_mul(b)), + // Panics unless `b <= c`. + 26 => put(out, a.clamp(b, c)), + 27 => { + if let Some(v) = div_ceil!($sign, $t, a, b) { + put(out, v); + } + } + 28 => { + if let Some(m) = is_multiple_of!($sign, a, b) { + out.push(m as u8); + } + } _ => { // Compound assignment, with constants folded beside variables. let mut x = a; @@ -88,18 +124,18 @@ macro_rules! ops { }; } -ops!(u8_op, u8, u128); -ops!(u16_op, u16, u128); -ops!(u32_op, u32, u128); -ops!(u64_op, u64, u128); -ops!(u128_op, u128, u128); -ops!(usize_op, usize, u128); -ops!(i8_op, i8, i128); -ops!(i16_op, i16, i128); -ops!(i32_op, i32, i128); -ops!(i64_op, i64, i128); -ops!(i128_op, i128, i128); -ops!(isize_op, isize, i128); +ops!(u8_op, u8, u128, unsigned); +ops!(u16_op, u16, u128, unsigned); +ops!(u32_op, u32, u128, unsigned); +ops!(u64_op, u64, u128, unsigned); +ops!(u128_op, u128, u128, unsigned); +ops!(usize_op, usize, u128, unsigned); +ops!(i8_op, i8, i128, signed); +ops!(i16_op, i16, i128, signed); +ops!(i32_op, i32, i128, signed); +ops!(i64_op, i64, i128, signed); +ops!(i128_op, i128, i128, signed); +ops!(isize_op, isize, i128, signed); macro_rules! neg { ($name:ident, $t:ty) => { diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index 029e20f99..d39396e18 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -14,6 +14,7 @@ mod collections; mod combinators; mod cows; mod durations; +mod edits; mod fmt; mod generics; pub mod harness; @@ -28,5 +29,6 @@ mod strs; #[cfg(target_arch = "wasm32")] #[path = "../../wasm.rs"] mod wasm; +mod wrappers; #[cfg(target_arch = "wasm32")] use harness::entry; diff --git a/ts/fixtures/lang/src/wrappers.rs b/ts/fixtures/lang/src/wrappers.rs new file mode 100644 index 000000000..4f0d39211 --- /dev/null +++ b/ts/fixtures/lang/src/wrappers.rs @@ -0,0 +1,202 @@ +//! std's bounds and wrappers: `Bound` and `RangeBounds` of each range, `..=` as a +//! B-tree's range, `split_off`, `Reverse` as an order and a key, and `NonZero`, made, read, +//! matched as a constant, compared, and printed. + +use std::cmp::Reverse; +use std::collections::{BTreeMap, BTreeSet}; +use std::num::NonZero; +use std::ops::{Bound, RangeBounds}; + +use crate::fmt::put; + +/// A rate that is never 0, as a timescale is. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +struct Scale(NonZero); + +impl Scale { + const ONE: Self = Self(NonZero::new(1).unwrap()); + const MILLI: Self = Self(NonZero::new(1000).unwrap()); + const WIDE: Self = Self(NonZero::new(u64::MAX).unwrap()); +} + +fn put_u64(out: &mut Vec, v: u64) { + out.extend_from_slice(&v.to_be_bytes()); +} + +fn put_bound(out: &mut Vec, b: Bound<&u64>) { + match b { + Bound::Included(v) => { + out.push(1); + put_u64(out, *v); + } + Bound::Excluded(v) => { + out.push(2); + put_u64(out, *v); + } + Bound::Unbounded => out.push(3), + } +} + +/// The bounds of `r`, written, then the first sequence and the end past the last it holds, +/// as a range of groups reads them. +fn bounds(out: &mut Vec, r: impl RangeBounds) { + put_bound(out, r.start_bound()); + put_bound(out, r.end_bound()); + let start = match r.start_bound().cloned() { + Bound::Included(s) => Some(s), + Bound::Excluded(s) => s.checked_add(1), + Bound::Unbounded => Some(0), + }; + let end = match r.end_bound().cloned() { + Bound::Included(e) => e.checked_add(1), + Bound::Excluded(e) => Some(e), + Bound::Unbounded => None, + }; + put_u64(out, start.unwrap_or(0)); + put_u64(out, end.unwrap_or(0)); + out.push(start.is_some() as u8 + 2 * end.is_some() as u8); +} + +/// A bound of `a` picked by `kind`, held by value. +fn bound_of(kind: u8, a: u64) -> Bound { + match kind % 3 { + 0 => Bound::Included(a), + 1 => Bound::Excluded(a), + _ => Bound::Unbounded, + } +} + +pub fn wrappers(kind: u8, data: &[u8], out: &mut Vec) { + let at = |i: usize| data.get(i).copied().unwrap_or(0); + // Wide values next to the ends, so `checked_add` and the limbs past 2^53 show. + let wide = |b: u8| match b % 4 { + 0 => b as u64, + 1 => u64::MAX - b as u64, + 2 => (1 << 53) + b as u64, + _ => b as u64 * 7, + }; + let (a, b) = (wide(at(0)), wide(at(1))); + match kind % 5 { + 0 => { + bounds(out, a..b); + bounds(out, a..=b); + // Drained, an inclusive range's start passes its end, and only wrapping exhausts it, + // which leaves it excluding its start. + let mut stepped = (a % 4)..=(b % 4); + while stepped.next().is_some() {} + bounds(out, stepped); + let mut top = (u64::MAX - a % 2)..=u64::MAX; + while top.next().is_some() {} + bounds(out, top); + let mut down = 0..=(b % 3); + while down.next_back().is_some() {} + bounds(out, down); + bounds(out, ..b); + bounds(out, ..=b); + bounds(out, a..); + bounds(out, ..); + bounds(out, (bound_of(at(2), a), bound_of(at(3), b))); + let held = (bound_of(at(3), b), Bound::Unbounded); + bounds(out, held); + put_bound(out, held.0.as_ref()); + // Each one-sided range's field, read and through struct update syntax. + let (to, from) = ( + ..(at(2) as usize % (data.len() + 1)), + (at(3) as usize % (data.len() + 1)).., + ); + let through = ..=b; + put_u64(out, (to.end + from.start) as u64); + put_u64(out, through.end); + out.push(data[std::ops::RangeTo { ..to }].len() as u8); + out.push(data[std::ops::RangeFrom { ..from }].len() as u8); + } + 1 => { + let mut map = BTreeMap::new(); + for (i, &x) in data.iter().enumerate() { + map.insert(x as u64, i as u64); + } + let (a, b) = (at(0) as u64, at(1) as u64); + for (k, v) in map.range(..=a) { + put_u64(out, *k); + put_u64(out, *v); + } + out.push(0xfe); + if let Some((k, _)) = map.range(..=b).next_back() { + put_u64(out, *k); + } + out.push(map.range(..a).count() as u8); + // Exhausted by wrapping either way, an inclusive range holds nothing. + let mut top = (u64::MAX - a % 2)..=u64::MAX; + while top.next().is_some() {} + let mut bottom = 0..=(b % 2); + while bottom.next_back().is_some() {} + out.push(map.range(top).count() as u8); + out.push(map.range(bottom).count() as u8); + let above = map.split_off(&b); + for (k, v) in map.iter().chain(above.iter()) { + put_u64(out, *k); + put_u64(out, *v); + } + out.push(map.len() as u8); + out.push(above.len() as u8); + let mut set: BTreeSet = data.iter().copied().collect(); + let high = set.split_off(&at(2)); + out.extend(set.iter().chain(high.iter())); + out.push(high.len() as u8); + } + 2 => { + // Ordered the other way, alone and in tuples, as keys and as sort keys. + let (x, y) = (at(0), at(1)); + out.push(Reverse(x).cmp(&Reverse(y)) as i8 as u8); + out.push((Reverse(x) < Reverse(y)) as u8); + out.push((Reverse(Some(x)) > Reverse(None)) as u8); + out.push(Reverse(x).max(Reverse(y)).0); + out.push(((Reverse(x), y) <= (Reverse(y), x)) as u8); + let keyed: BTreeMap, usize> = data.iter().enumerate().map(|(i, &d)| (Reverse(d), i)).collect(); + for (Reverse(k), i) in &keyed { + out.push(*k); + out.push(*i as u8); + } + let mut ranked: Vec<(u8, usize)> = data.iter().enumerate().map(|(i, &d)| (d, i)).collect(); + ranked.sort_by_key(|&(d, i)| (Reverse(d % 4), i)); + for (d, i) in ranked { + out.push(d); + out.push(i as u8); + } + let wrapped = Reverse(String::from("held")); + put(out, &wrapped.0); + } + 3 => { + let n = NonZero::new(a); + match n { + Some(n) => { + put_u64(out, n.get()); + put_u64(out, u64::from(n)); + put(out, &format!("{n} {n:?} {}", n == NonZero::new(b).unwrap_or(n))); + out.push((n > Scale::ONE.0) as u8); + out.push(n.cmp(&Scale::MILLI.0) as i8 as u8); + } + None => out.push(0), + } + let none: Option> = NonZero::new(a & 1); + out.push(none.is_some() as u8); + } + _ => { + // Matched against constants, as derived `PartialEq` and patterns read them. + let scale = match NonZero::new(a) { + Some(n) if at(2) % 2 == 0 => Scale(n), + _ => [Scale::ONE, Scale::MILLI, Scale::WIDE][at(3) as usize % 3], + }; + let name = match scale { + Scale::ONE => "one", + Scale::MILLI => "milli", + Scale::WIDE => "wide", + Scale(_) => "other", + }; + put(out, name); + out.push((scale == Scale::MILLI) as u8); + out.push((scale < Scale::WIDE) as u8); + put_u64(out, scale.0.get()); + } + } +} diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index e9a66020f..c0a763020 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,54 +1,55 @@ # Census of `reject-fixture` -- Refusals: 72 -- Function instances: 75 -- Generic functions no instance reached, lowered over their type parameters: 4 +- Refusals: 74 +- Function instances: 80 +- Generic functions no instance reached, lowered over their type parameters: 6 ## By construct | Count | Construct | First | | ---: | --- | --- | | 10 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:393:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:424:2 | | 4 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:117:2 | | 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | | 3 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:17:2 | +| 3 | comparing `_` through its own `_`, which is not supported yet | fixtures/reject/src/lib.rs:381:4 | | 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:101:2 | | 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:121:20 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | fixtures/reject/src/lib.rs:23:15 | | 2 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:48:42 | | 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:268:16 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:284:7 | | 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:175:1 | | 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:161:23 | | 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:155:2 | -| 2 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:380:13 | +| 2 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:411:13 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:84:2 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:404:18 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:435:18 | | 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:312:6 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:307:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | fixtures/reject/src/lib.rs:69:13 | | 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | fixtures/reject/src/lib.rs:63:23 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:344:2 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:320:9 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:339:2 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:315:9 | | 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | fixtures/reject/src/lib.rs:237:26 | | 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:112:2 | | 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | fixtures/reject/src/lib.rs:242:30 | | 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:188:51 | -| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:367:2 | +| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:362:2 | | 1 | a constant of type `_` | fixtures/reject/src/lib.rs:96:2 | | 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:278:14 | | 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:247:13 | -| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:436:12 | +| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:467:12 | | 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:108:1 | | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:78:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:43:43 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:294:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:411:53 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:294:52 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:388:4 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:289:52 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:442:53 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:289:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | fixtures/reject/src/lib.rs:402:16 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:419:4 | ## By API @@ -56,28 +57,32 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:393:2 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:424:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:23:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | | 4 | `Iterator` | fixtures/reject/src/lib.rs:48:42 | +| 3 | `PartialOrd` | fixtures/reject/src/lib.rs:381:4 | | 3 | `std::iter::Map` | fixtures/reject/src/lib.rs:63:23 | | 3 | `std::slice` | fixtures/reject/src/lib.rs:28:4 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:117:2 | -| 3 | `{closure}` | fixtures/reject/src/lib.rs:380:13 | -| 2 | `HashMap` | fixtures/reject/src/lib.rs:289:6 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | +| 3 | `u8` | fixtures/reject/src/lib.rs:96:2 | +| 3 | `{closure}` | fixtures/reject/src/lib.rs:411:13 | +| 2 | `HashMap` | fixtures/reject/src/lib.rs:284:6 | +| 2 | `Lopsided` | fixtures/reject/src/lib.rs:381:4 | | 2 | `Meters` | fixtures/reject/src/lib.rs:101:2 | | 2 | `Poll` | fixtures/reject/src/lib.rs:121:20 | | 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:69:13 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:268:16 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:196:8 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:132:2 | -| 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:462:17 | -| 2 | `std::vec::Vec` | fixtures/reject/src/lib.rs:294:52 | -| 2 | `u8` | fixtures/reject/src/lib.rs:96:2 | +| 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:493:17 | +| 1 | `(i32, &Lopsided)` | fixtures/reject/src/lib.rs:382:13 | +| 1 | `Batched` | fixtures/reject/src/lib.rs:402:16 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:175:1 | -| 1 | `Entry` | fixtures/reject/src/lib.rs:380:13 | +| 1 | `Entry` | fixtures/reject/src/lib.rs:411:13 | | 1 | `FusedIterator` | fixtures/reject/src/lib.rs:229:1 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:320:9 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:315:9 | | 1 | `IntToFloat` | fixtures/reject/src/lib.rs:112:2 | | 1 | `Maybe` | fixtures/reject/src/lib.rs:38:2 | | 1 | `Noisy` | fixtures/reject/src/lib.rs:69:13 | @@ -86,19 +91,16 @@ The type or module each refused type or path belongs to. | 1 | `count` | fixtures/reject/src/lib.rs:63:23 | | 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | | 1 | `into_keys` | fixtures/reject/src/lib.rs:69:13 | -| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:426:15 | +| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:457:15 | | 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:188:51 | | 1 | `std::iter::Flatten` | fixtures/reject/src/lib.rs:237:26 | | 1 | `std::iter::IntoIterator` | fixtures/reject/src/lib.rs:17:2 | | 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:182:14 | -| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:284:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:284:7 | -| 1 | `std::option::Option` | fixtures/reject/src/lib.rs:443:2 | +| 1 | `std::option::Option` | fixtures/reject/src/lib.rs:474:2 | | 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:142:11 | -| 1 | `std::str` | fixtures/reject/src/lib.rs:373:4 | | 1 | `std::string::String` | fixtures/reject/src/lib.rs:90:10 | | 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:137:2 | -| 1 | `str` | fixtures/reject/src/lib.rs:388:4 | +| 1 | `str` | fixtures/reject/src/lib.rs:419:4 | | 1 | `u32` | fixtures/reject/src/lib.rs:247:13 | | 1 | `u64` | fixtures/reject/src/lib.rs:112:2 | | 1 | `value` | fixtures/reject/src/lib.rs:38:2 | @@ -108,35 +110,34 @@ The type or module each refused type or path belongs to. | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:393:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:424:2 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:121:20 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:23:15 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:132:2 | +| 2 | comparing `_` through its own `_`, which is not supported yet | `Lopsided`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:381:4 | | 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:101:2 | -| 2 | unsupported call to `_` | `::sum` | fixtures/reject/src/lib.rs:462:17 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:404:18 | +| 2 | unsupported call to `_` | `::sum` | fixtures/reject/src/lib.rs:493:17 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:435:18 | | 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | `Maybe`, `value`, `Option`, `T \| undefined`, `Option` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:312:6 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:307:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | `into_keys`, `std::collections::HashMap`, `Noisy` | fixtures/reject/src/lib.rs:69:13 | | 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | `count`, `std::iter::Map` | fixtures/reject/src/lib.rs:63:23 | -| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `HashMap::get`, `Option` | fixtures/reject/src/lib.rs:289:6 | +| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `HashMap::get`, `Option` | fixtures/reject/src/lib.rs:284:6 | | 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::find`, `Option` | fixtures/reject/src/lib.rs:48:42 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:268:38 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:268:16 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:344:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:426:15 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:339:2 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:457:15 | | 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::iter::IntoIterator::into_iter` | fixtures/reject/src/lib.rs:17:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:419:21 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:320:9 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:450:21 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:315:9 | | 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | `std::iter::Flatten` | fixtures/reject/src/lib.rs:237:26 | | 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:112:2 | | 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | `std::iter::Map`, `std::ops::Range` | fixtures/reject/src/lib.rs:242:30 | | 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:188:51 | -| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:367:2 | +| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:362:2 | | 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:96:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:284:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:284:7 | | 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:247:13 | | 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:78:2 | @@ -146,25 +147,27 @@ The type or module each refused type or path belongs to. | 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:229:1 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | `Option` | fixtures/reject/src/lib.rs:43:43 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:294:52 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:411:53 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | +| 1 | comparing `_` through its own `_`, which is not supported yet | `(i32, &Lopsided)`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:382:13 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:442:53 | | 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:161:23 | | 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:182:14 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:294:52 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | `std::vec::Vec`, `Batched` | fixtures/reject/src/lib.rs:402:16 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:155:2 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:209:2 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:380:13 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::for_each` | fixtures/reject/src/lib.rs:381:16 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | `{closure}`, `str::contains` | fixtures/reject/src/lib.rs:388:4 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:411:13 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::for_each` | fixtures/reject/src/lib.rs:412:16 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | `{closure}`, `str::contains` | fixtures/reject/src/lib.rs:419:4 | | 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:261:22 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:405:2 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:443:2 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:436:2 | +| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:474:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:142:11 | | 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:90:10 | +| 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:393:10 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:196:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:362:4 | +| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:357:4 | | 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:28:4 | -| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:373:4 | | 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | ## Spans @@ -175,21 +178,21 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:90:10: unsupported call to `::write_fmt` - fixtures/reject/src/lib.rs:142:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:196:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:362:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:373:4: unsupported call to `core::str::::split::<[char; 2]>` -- fixtures/reject/src/lib.rs:405:2: unsupported call to ` as std::ops::Deref>::deref` -- fixtures/reject/src/lib.rs:443:2: unsupported call to ` as std::cmp::PartialEq>::eq` -- fixtures/reject/src/lib.rs:462:17: unsupported call to ` as std::iter::Iterator>::sum::` -- fixtures/reject/src/lib.rs:462:38: unsupported call to ` as std::iter::Iterator>::sum::` +- fixtures/reject/src/lib.rs:357:4: unsupported call to `core::slice::::copy_within::>` +- fixtures/reject/src/lib.rs:393:10: unsupported call to `::hash::` +- fixtures/reject/src/lib.rs:436:2: unsupported call to ` as std::ops::Deref>::deref` +- fixtures/reject/src/lib.rs:474:2: unsupported call to ` as std::cmp::PartialEq>::eq` +- fixtures/reject/src/lib.rs:493:17: unsupported call to ` as std::iter::Iterator>::sum::` +- fixtures/reject/src/lib.rs:493:38: unsupported call to ` as std::iter::Iterator>::sum::`
a variant of `_`, which is not supported: either is the same JS string (4) -- fixtures/reject/src/lib.rs:393:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:394:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:395:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:400:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:424:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:425:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:426:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:431:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
@@ -214,8 +217,16 @@ The type or module each refused type or path belongs to.
`_` with a mutable reference to a value JS copies, which its mapping would copy (3) - fixtures/reject/src/lib.rs:17:2: `std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:419:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:426:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:450:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:457:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy + +
+ +
comparing `_` through its own `_`, which is not supported yet (3) + +- fixtures/reject/src/lib.rs:381:4: comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet +- fixtures/reject/src/lib.rs:382:13: comparing `(i32, &Lopsided)` through its own `PartialOrd::lt`, which is not supported yet +- fixtures/reject/src/lib.rs:383:12: comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet
@@ -244,7 +255,7 @@ The type or module each refused type or path belongs to.
`_` of `_`, whose `None` is `rt.None`, which is not supported yet (2) - fixtures/reject/src/lib.rs:48:42: `Iterator::find` of `Option>`, whose `None` is `rt.None`, which is not supported yet -- fixtures/reject/src/lib.rs:289:6: `HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet +- fixtures/reject/src/lib.rs:284:6: `HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet
@@ -255,13 +266,6 @@ The type or module each refused type or path belongs to. -
a field of `_` (2) - -- fixtures/reject/src/lib.rs:284:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:284:48: a field of `std::ops::RangeFrom` - -
-
an iterator of the crate implementing `_`, which is not supported yet (2) - fixtures/reject/src/lib.rs:175:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet @@ -285,8 +289,8 @@ The type or module each refused type or path belongs to.
passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:380:13: passing `{closure@fixtures/reject/src/lib.rs:380:28: 380:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet -- fixtures/reject/src/lib.rs:381:16: passing `{closure@fixtures/reject/src/lib.rs:381:25: 381:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet +- fixtures/reject/src/lib.rs:411:13: passing `{closure@fixtures/reject/src/lib.rs:411:28: 411:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet +- fixtures/reject/src/lib.rs:412:16: passing `{closure@fixtures/reject/src/lib.rs:412:25: 412:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet
@@ -298,7 +302,7 @@ The type or module each refused type or path belongs to.
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:404:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:435:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
@@ -310,7 +314,7 @@ The type or module each refused type or path belongs to.
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:312:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:307:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
@@ -328,13 +332,13 @@ The type or module each refused type or path belongs to.
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:344:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet +- fixtures/reject/src/lib.rs:339:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:320:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:315:9: `Hasher::write`, which is not supported yet
@@ -364,7 +368,7 @@ The type or module each refused type or path belongs to.
a coercion to `_` (1) -- fixtures/reject/src/lib.rs:367:2: a coercion to `std::sync::Arc<[u8]>` +- fixtures/reject/src/lib.rs:362:2: a coercion to `std::sync::Arc<[u8]>`
@@ -388,7 +392,7 @@ The type or module each refused type or path belongs to.
a mutable reference into a `Result`'s payload, passed on or kept (1) -- fixtures/reject/src/lib.rs:436:12: a mutable reference into a `Result`'s payload, passed on or kept +- fixtures/reject/src/lib.rs:467:12: a mutable reference into a `Result`'s payload, passed on or kept
@@ -424,24 +428,30 @@ The type or module each refused type or path belongs to.
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:294:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:289:52: comparing `std::vec::Vec` as a key, which is not supported yet
constructing `_` (1) -- fixtures/reject/src/lib.rs:411:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:442:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:294:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:289:52: hashing `std::vec::Vec` as a key, which is not supported yet + +
+ +
hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet (1) + +- fixtures/reject/src/lib.rs:402:16: hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet
passing `_`, which drops, to `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:388:4: passing `{closure@fixtures/reject/src/lib.rs:388:13: 388:27}`, which drops, to `str::contains`, which is not supported yet +- fixtures/reject/src/lib.rs:419:4: passing `{closure@fixtures/reject/src/lib.rs:419:13: 419:27}`, which drops, to `str::contains`, which is not supported yet
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 293e72324..7895ede34 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -39,33 +39,34 @@ replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib. `std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:268:16 `std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:268:38 a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:278:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:284:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:284:48 -`HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:289:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:294:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:294:52 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:312:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:362:4 -a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:367:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:393:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:395:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:394:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:400:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:404:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:405:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:411:53 -unsupported call to `core::str::::split::<[char; 2]>` at fixtures/reject/src/lib.rs:373:4 -passing `{closure@fixtures/reject/src/lib.rs:380:28: 380:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet at fixtures/reject/src/lib.rs:380:13 -passing `{closure@fixtures/reject/src/lib.rs:381:25: 381:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet at fixtures/reject/src/lib.rs:381:16 -passing `{closure@fixtures/reject/src/lib.rs:388:13: 388:27}`, which drops, to `str::contains`, which is not supported yet at fixtures/reject/src/lib.rs:388:4 -unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:462:17 -unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:462:38 -`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:419:21 -`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:426:15 -a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:436:12 -unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:443:2 +`HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:284:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:289:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:289:52 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:307:6 +unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:357:4 +a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:362:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:424:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:426:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:425:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:431:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:435:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:436:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:442:53 +comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:381:4 +comparing `(i32, &Lopsided)` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:382:13 +comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:383:12 +hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet at fixtures/reject/src/lib.rs:402:16 +passing `{closure@fixtures/reject/src/lib.rs:411:28: 411:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet at fixtures/reject/src/lib.rs:411:13 +passing `{closure@fixtures/reject/src/lib.rs:412:25: 412:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet at fixtures/reject/src/lib.rs:412:16 +passing `{closure@fixtures/reject/src/lib.rs:419:13: 419:27}`, which drops, to `str::contains`, which is not supported yet at fixtures/reject/src/lib.rs:419:4 +unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:493:17 +unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:493:38 +`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:450:21 +`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:457:15 +a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:467:12 +unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:474:2 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:155:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:175:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:209:2 an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:229:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:320:9 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:315:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 0823ee3ec..d7cf713b0 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -279,11 +279,6 @@ pub fn copied_closure(n: u8) -> u8 { g().wrapping_add(h()) } -/// Struct update syntax on a one-sided range reads its base's field, which is not supported. -pub fn one_sided(data: &[u8], to: std::ops::RangeTo, from: std::ops::RangeFrom) -> usize { - data[std::ops::RangeTo { ..to }].len() + data[std::ops::RangeFrom { ..from }].len() -} - /// `get`'s `None` and `Some(&None)` would both be `undefined`. pub fn optional(map: &std::collections::HashMap>) -> bool { map.get(&1).is_some() @@ -367,10 +362,46 @@ pub fn shared(b: std::sync::Arc<[u8; 2]>) -> std::sync::Arc<[u8]> { b } -/// A `str` pattern of several chars, where only a `char`, a `&str`, and a predicate are -/// supported. -pub fn split_chars(s: &str) -> usize { - s.split(['a', 'b']).count() +/// A `<` of its own, which `sort`, `max`, and a tuple's `<` would call where the +/// translation calls `partial_cmp`. +#[derive(PartialEq, Eq, Ord)] +pub struct Lopsided(u8); + +impl PartialOrd for Lopsided { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.0.cmp(&other.0)) + } + + fn lt(&self, other: &Self) -> bool { + self.0 > other.0 + } +} + +pub fn lopsided(v: &mut Vec, a: Lopsided, b: Lopsided) -> bool { + v.sort(); + let wins = (1, &a) < (2, &b); + wins && a.max(b).0 > 0 +} + +/// A `hash_slice` of its own, which a `Vec`'s `Hash` calls where the translation hashes each +/// element. +#[derive(PartialEq, Eq)] +pub struct Batched(u8); + +impl std::hash::Hash for Batched { + fn hash(&self, state: &mut H) { + self.0.hash(state); + } + + fn hash_slice(data: &[Self], state: &mut H) { + state.write_usize(data.len()); + } +} + +pub fn batched(v: Vec) -> usize { + let mut set = std::collections::HashSet::new(); + set.insert(v); + set.len() } /// Closures that own a value that drops, which `or_insert_with` would call but never drop diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 1442dcc07..27a6b6222 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -37,7 +37,6 @@ roots = [ "replace_captured", "filter_owned_bytes", "copied_closure", - "one_sided", "optional", "byte_keys", "borrowed", @@ -48,7 +47,8 @@ roots = [ "cow_borrowed", "cow_bytes", "cow_made", - "split_chars", + "lopsided", + "batched", "called_closure", "pattern_closure", "parts_summed", diff --git a/ts/fixtures/task/expected/drops.Key.ts b/ts/fixtures/task/expected/drops.Key.ts index 1dbed1d67..ed1011ea6 100644 --- a/ts/fixtures/task/expected/drops.Key.ts +++ b/ts/fixtures/task/expected/drops.Key.ts @@ -81,6 +81,10 @@ export function eq$PartialEq(self: Key, other: Key): boolean { return read(self) === read(other); } +export function partialCmp$PartialOrd(self: Key, other: Key): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + export function cmp$Ord(self: Key, other: Key): rt.Ordering { return rt.cmp(read(self), read(other)); } @@ -101,6 +105,15 @@ export function hash$Hash_DefaultHasher(self: Key, state: rt.Hasher): void { rt.hashInt(read(self), state); } +export function clone$Clone(self: Key): Key { + const id: rt.u32 = read(self); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(id, f)]; + const _5: string = rt.fmtFormat(["k", args2[0], " cloned"]); + Log.note(self.log, _5); + const _14: Log.Log = Log.clone$Clone(self.log); + return faulty(id, _14, self.fault); +} + export function fmt$Debug(self: Key, f: rt.Formatter): rt.Result { return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, "Key"), (f: rt.Formatter) => rt.u32Debug(self.id, f))); } diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index 1bef255ef..a1db9f3be 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -1,7 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Bomb_Guard, drop$Guard_Entries_Bomb_Guard_Held, drop$Held, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Guard_Guard, drop$Option_Held, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; +import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Bomb_Guard, drop$Guard_Entries_Bomb_Guard_Held, drop$Held, drop$Key_Key, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Guard_Guard, drop$Option_Held, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; import { isSomeAnd$Option_Guard_options_closure7, unwrapOr$Option_Guard, unwrapOr$Option_u64, mapOr$Option_u32_Guard_options_closure2, okOr$Option_Guard_Guard, filter$Option_Guard_options_closure4, orElse$Option_Guard_options_closure6, zip$Option_Guard_Guard, clone$Clone_Option_Arc_Guard } from "./core/option.ts"; import { ok$Result_Guard_Guard, err$Result_Guard_Guard, mapOrElse$Result_Guard_Guard_u32_options_closure9_options_closure10, inspectErr$Result_u8_Key_tripped_closure6, andThen$Result_Guard_Guard_Guard_options_closure8, unwrapOr$Result_Guard_Guard } from "./core/result.ts"; import { scoped, discarded, iterated, blasted } from "./drops/closures.ts"; @@ -2742,7 +2742,7 @@ export function tripped(log: Log.Log, id: rt.u32, at: rt.u8, tree: boolean): voi _155 = true; const _114: rt.Arc = new rt.Arc(trip(4)); _155 = false; - const _109: rt.Arc = rt.ordMax(_110, _114, rt.cmpArc(Key.cmp$Ord), rt.drop); + const _109: rt.Arc = rt.ordMax(_110, _114, rt.cmpArc(Key.partialCmp$PartialOrd), rt.drop); unwind = 100; _155 = false; rt.drop(_109); @@ -3296,4 +3296,592 @@ export function grown(log: Log.Log, id: rt.u32, at: rt.u8, tree: boolean): void } } +/** + * What a `Vec`'s edits, its and a tuple's `clone`, and `Ord`'s defaults drop, scenario + * `at`'s alone, and what is left to drop when a closure, a clone, a drop, or an index + * panics partway. + */ +export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { + let v!: Key.Key[]; + let v2!: Key.Key[]; + let _72!: Key.Key; + let _75!: Key.Key; + let v3!: Key.Key[]; + let v4!: Key.Key[]; + let v5!: Key.Key[]; + let v6!: Key.Key[]; + let _188!: Key.Key; + let _191!: Key.Key; + let v7!: Key.Key[]; + let v8!: Key.Key[]; + let v9!: Key.Key[]; + let v10!: Key.Key[]; + let v11!: Key.Key[]; + let v12!: Key.Key[]; + let _283!: Key.Key[]; + let tripped_!: Key.Key[]; + let v13!: Key.Key[]; + let pair!: [Key.Key, Key.Key]; + let _311!: Key.Key; + let tripped2!: [Key.Key, Key.Key]; + let _321!: Key.Key; + let _339!: Key.Key; + let _340!: Key.Key; + let _359!: Key.Key; + let _360!: Key.Key; + let _379!: Key.Key; + let _380!: Key.Key; + let _383!: Key.Key; + let _402!: Key.Key; + let _403!: Key.Key; + let _406!: Key.Key; + let _419!: Key.Key; + let _441!: boolean; + let _442!: boolean; + let _443!: boolean; + let _444!: boolean; + let _445!: boolean; + let _446!: boolean; + let _447!: boolean; + let _448!: boolean; + let _449!: boolean; + let _450!: boolean; + let _451!: boolean; + let unwind: number = 0; + try { + _451 = false; + _450 = false; + _449 = false; + _448 = false; + _447 = false; + _446 = false; + _445 = false; + _444 = false; + _443 = false; + _442 = false; + _441 = false; + const key: (a0: rt.u32) => Key.Key = (n: rt.u32): Key.Key => { + return Key.new(rt.u32Add(id, n), Log.clone$Clone(log)); + }; + const fault: (a0: rt.u32, a1: Fault.Fault) => Key.Key = (n2: rt.u32, fault2: Fault.Fault): Key.Key => { + return Key.faulty(rt.u32Add(id, n2), Log.clone$Clone(log), fault2); + }; + const ids: (a0: Key.Key[]) => string = (v14: Key.Key[]): string => { + return rt.iterToArray(rt.iterMap(rt.iterSlice(v14), (k: Key.Key): string => { + const _46: rt.u32 = rt.u32Sub(k.id, id); + return rt.fmtToString((f: rt.Formatter) => rt.u32Display(_46, f)); + })).join(","); + }; + if (at === 0) { + v2 = []; + unwind = 237; + const _14: Key.Key = key(1); + v2.push(_14); + const _19: Key.Key = key(2); + v2.push(_19); + const _24: Key.Key = key(3); + v2.push(_24); + const _29: Key.Key = key(4); + v2.push(_29); + unwind = 236; + v = v2; + rt.vecRetain(v, (k4: Key.Key): boolean => { + return rt.u32Rem(rt.u32Sub(k4.id, id), 2) === 1; + }, rt.drop); + const _42: string = ids(v); + unwind = 235; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _42)]; + const _38: string = rt.fmtFormat(["retained ", args2[0]]); + unwind = 236; + Log.note(log, _38); + rt.vecRetain(v, (k5: Key.Key): boolean => { + return k5.id !== rt.u32Add(id, 3); + }, rt.drop); + const _61: string = ids(v); + unwind = 234; + const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _61)]; + const _57: string = rt.fmtFormat(["retained ", args4[0]]); + unwind = 236; + Log.note(log, _57); + _72 = key(2); + unwind = 260; + _451 = true; + _75 = key(1); + unwind = 258; + _450 = true; + const _78: Key.Key = fault(3, "Blows" as Fault.Fault); + _451 = false; + _450 = false; + const _71: Key.Key = rt.ordClamp(_72, _75, _78, Key.partialCmp$PartialOrd, rt.drop); + unwind = 236; + _450 = false; + _451 = false; + rt.drop(_71); + unwind = 0; + rt.dropAll(v); + } else if (at === 1) { + v4 = []; + unwind = 233; + const _86: Key.Key = key(1); + v4.push(_86); + const _91: Key.Key = key(2); + v4.push(_91); + const _96: Key.Key = key(3); + v4.push(_96); + const _101: Key.Key = key(4); + v4.push(_101); + unwind = 232; + v3 = v4; + rt.vecRetain(v3, (k3: Key.Key): boolean => { + if (!(k3.id === rt.u32Add(id, 3))) { + return k3.id !== rt.u32Add(id, 2); + } + const arg = k3.id; + const args24: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg, f)]; + rt.panicFmt(["k", args24[0], " retained"]); + }, rt.drop); + unwind = 0; + rt.dropAll(v3); + } else if (at === 2) { + v6 = []; + unwind = 231; + const _112: Key.Key = key(1); + v6.push(_112); + const _117: Key.Key = key(1); + v6.push(_117); + const _122: Key.Key = key(2); + v6.push(_122); + const _127: Key.Key = key(2); + v6.push(_127); + const _132: Key.Key = key(3); + v6.push(_132); + unwind = 230; + v5 = v6; + rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); + const _143: string = ids(v5); + unwind = 229; + const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _143)]; + const _139: string = rt.fmtFormat(["deduped ", args6[0]]); + unwind = 230; + Log.note(log, _139); + rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { + return rt.u32Div(k2.id, 2); + }, rt.same, rt.drop); + const _160: string = ids(v5); + unwind = 228; + const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _160)]; + const _156: string = rt.fmtFormat(["deduped ", args8[0]]); + unwind = 230; + Log.note(log, _156); + rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { + return a.id > b.id; + }, rt.drop); + const _177: string = ids(v5); + unwind = 227; + const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _177)]; + const _173: string = rt.fmtFormat(["deduped ", args10[0]]); + unwind = 230; + Log.note(log, _173); + _188 = key(2); + unwind = 256; + _449 = true; + _191 = key(3); + unwind = 254; + _448 = true; + const _194: Key.Key = key(1); + _449 = false; + _448 = false; + const _187: Key.Key = rt.ordClamp(_188, _191, _194, Key.partialCmp$PartialOrd, rt.drop); + unwind = 230; + _448 = false; + _449 = false; + rt.drop(_187); + unwind = 0; + rt.dropAll(v5); + } else if (at === 3) { + v8 = []; + unwind = 226; + const _201: Key.Key = key(1); + v8.push(_201); + const _206: Key.Key = fault(1, "Blows" as Fault.Fault); + v8.push(_206); + const _212: Key.Key = key(1); + v8.push(_212); + const _217: Key.Key = key(2); + v8.push(_217); + unwind = 225; + v7 = v8; + rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); + unwind = 0; + rt.dropAll(v7); + } else if (at === 4) { + v10 = []; + unwind = 224; + const _226: Key.Key = key(1); + v10.push(_226); + const _231: Key.Key = key(2); + v10.push(_231); + const _236: Key.Key = key(3); + v10.push(_236); + unwind = 223; + v9 = v10; + rt.drop(rt.vecSwapRemove(v9, 0)); + const _248: string = ids(v9); + unwind = 222; + const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _248)]; + const _244: string = rt.fmtFormat(["swapped ", args12[0]]); + unwind = 223; + Log.note(log, _244); + rt.drop(rt.vecSwapRemove(v9, 3)); + unwind = 0; + rt.dropAll(v9); + } else if (at === 5) { + v12 = []; + unwind = 221; + const _264: Key.Key = key(1); + v12.push(_264); + const _269: Key.Key = key(2); + v12.push(_269); + unwind = 220; + v11 = v12; + _283 = rt.vecClone(v11, Key.clone$Clone, rt.drop); + unwind = 219; + const _278: string = ids(_283); + unwind = 218; + const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _278)]; + const _274: string = rt.fmtFormat(["cloned ", args14[0]]); + unwind = 220; + rt.dropAll(_283); + Log.note(log, _274); + v13 = []; + unwind = 217; + const _293: Key.Key = key(1); + v13.push(_293); + const _298: Key.Key = fault(2, "Trips" as Fault.Fault); + v13.push(_298); + const _304: Key.Key = key(3); + v13.push(_304); + unwind = 216; + tripped_ = v13; + rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); + unwind = 220; + rt.dropAll(tripped_); + unwind = 0; + rt.dropAll(v11); + } else if (at === 6) { + _311 = key(1); + unwind = 215; + const _314: Key.Key = key(2); + unwind = 214; + pair = [_311, _314] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + _321 = key(1); + unwind = 213; + const _324: Key.Key = fault(2, "Trips" as Fault.Fault); + unwind = 212; + tripped2 = [_321, _324] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + unwind = 214; + drop$Key_Key(tripped2); + unwind = 0; + drop$Key_Key(pair); + } else { + _447 = true; + _340 = key(1); + unwind = 252; + const _343: Key.Key = key(2); + _447 = false; + _339 = rt.ordMax(_340, _343, Key.partialCmp$PartialOrd, rt.drop); + unwind = 211; + _447 = false; + const part = rt.u32Sub(_339.id, id); + const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; + const _333: string = rt.fmtFormat(["max ", args16[0]]); + unwind = 0; + rt.drop(_339); + Log.note(log, _333); + _446 = true; + _360 = key(5); + unwind = 250; + const _363: Key.Key = key(4); + _446 = false; + _359 = rt.ordMin(_360, _363, Key.partialCmp$PartialOrd, rt.drop); + unwind = 210; + _446 = false; + const part2 = rt.u32Sub(_359.id, id); + const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; + const _353: string = rt.fmtFormat(["min ", args18[0]]); + unwind = 0; + rt.drop(_359); + Log.note(log, _353); + _445 = true; + _380 = key(2); + unwind = 248; + _383 = key(1); + unwind = 246; + _444 = true; + const _386: Key.Key = key(3); + _445 = false; + _444 = false; + _379 = rt.ordClamp(_380, _383, _386, Key.partialCmp$PartialOrd, rt.drop); + unwind = 209; + _444 = false; + _445 = false; + const part3 = rt.u32Sub(_379.id, id); + const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; + const _373: string = rt.fmtFormat(["clamped ", args20[0]]); + unwind = 0; + rt.drop(_379); + Log.note(log, _373); + _443 = true; + _403 = key(0); + unwind = 244; + _406 = key(1); + unwind = 242; + _442 = true; + const _409: Key.Key = key(3); + _443 = false; + _442 = false; + _402 = rt.ordClamp(_403, _406, _409, Key.partialCmp$PartialOrd, rt.drop); + unwind = 208; + _442 = false; + _443 = false; + const part4 = rt.u32Sub(_402.id, id); + const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; + const _396: string = rt.fmtFormat(["clamped ", args22[0]]); + unwind = 0; + rt.drop(_402); + Log.note(log, _396); + _441 = true; + _419 = key(1); + unwind = 240; + const _422: Key.Key = fault(2, "Trips" as Fault.Fault); + _441 = false; + const _418: Key.Key = rt.ordMax(_419, _422, Key.partialCmp$PartialOrd, rt.drop); + unwind = 0; + _441 = false; + rt.drop(_418); + } + Log.note(log, rt.fmtFormat(["unreached"])); + } catch (e) { + b1: { + b2: { + b3: { + b4: { + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + if (unwind === 0) { + throw e; + } + if (unwind === 208) { + rt.drop(_402); + break b1; + } + if (unwind === 209) { + rt.drop(_379); + break b1; + } + if (unwind === 210) { + rt.drop(_359); + break b1; + } + if (unwind === 211) { + rt.drop(_339); + break b1; + } + if (unwind === 212) { + drop$Key_Key(tripped2); + break b2; + } + if (unwind === 213) { + rt.drop(_321); + break b2; + } + if (unwind === 214) { + break b2; + } + if (unwind === 215) { + rt.drop(_311); + break b1; + } + if (unwind === 216) { + rt.dropAll(tripped_); + break b3; + } + if (unwind === 217) { + rt.dropAll(v13); + break b3; + } + if (unwind === 218) { + break b4; + } + if (unwind === 219) { + break b4; + } + if (unwind === 220) { + break b3; + } + if (unwind === 221) { + rt.dropAll(v12); + break b1; + } + if (unwind === 222) { + break b5; + } + if (unwind === 223) { + break b5; + } + if (unwind === 224) { + rt.dropAll(v10); + break b1; + } + if (unwind === 225) { + rt.dropAll(v7); + break b1; + } + if (unwind === 226) { + rt.dropAll(v8); + break b1; + } + if (unwind === 227) { + break b6; + } + if (unwind === 228) { + break b6; + } + if (unwind === 229) { + break b6; + } + if (unwind === 230) { + break b6; + } + if (unwind === 231) { + rt.dropAll(v6); + break b1; + } + if (unwind === 232) { + rt.dropAll(v3); + break b1; + } + if (unwind === 233) { + rt.dropAll(v4); + break b1; + } + if (unwind === 234) { + break b7; + } + if (unwind === 235) { + break b7; + } + if (unwind === 236) { + break b7; + } + if (unwind === 237) { + rt.dropAll(v2); + break b1; + } + if (unwind === 240) { + if (!_441) { + break b1; + } + rt.drop(_419); + break b1; + } + if (unwind === 242) { + if (!_442) { + break b8; + } + rt.drop(_406); + break b8; + } + if (unwind === 244) { + break b8; + } + if (unwind === 246) { + if (!_444) { + break b9; + } + rt.drop(_383); + break b9; + } + if (unwind === 248) { + break b9; + } + if (unwind === 250) { + if (!_446) { + break b1; + } + rt.drop(_360); + break b1; + } + if (unwind === 252) { + if (!_447) { + break b1; + } + rt.drop(_340); + break b1; + } + if (unwind === 254) { + if (!_448) { + break b10; + } + rt.drop(_191); + break b10; + } + if (unwind === 256) { + break b10; + } + if (unwind === 258) { + if (_450) { + rt.drop(_75); + } + } + if (!_451) { + break b7; + } + rt.drop(_72); + break b7; + } + if (!_449) { + break b6; + } + rt.drop(_188); + break b6; + } + if (!_445) { + break b1; + } + rt.drop(_380); + break b1; + } + if (!_443) { + break b1; + } + rt.drop(_403); + break b1; + } + rt.dropAll(v); + break b1; + } + rt.dropAll(v5); + break b1; + } + rt.dropAll(v9); + break b1; + } + rt.dropAll(_283); + } + rt.dropAll(v11); + break b1; + } + drop$Key_Key(pair); + } + throw e; + } +} + //# sourceMappingURL=drops.ts.map diff --git a/ts/fixtures/task/expected/lib.ts b/ts/fixtures/task/expected/lib.ts index be2d4be3a..628fc357d 100644 --- a/ts/fixtures/task/expected/lib.ts +++ b/ts/fixtures/task/expected/lib.ts @@ -135,6 +135,22 @@ export function drop$Key_Guard(_1: [Key.Key, Guard.Guard]): void { } } +export function drop$Key_Key(_1: [Key.Key, Key.Key]): void { + let unwind: number = 0; + try { + unwind = 4; + rt.drop(_1[0]); + unwind = 0; + rt.drop(_1[1]); + } catch (e) { + if (unwind === 0) { + throw e; + } + rt.drop(_1[1]); + throw e; + } +} + export function drop$Mutex_Held(value: rt.Mutex): void { drop$Held(value.value); } diff --git a/ts/fixtures/task/src/drops.rs b/ts/fixtures/task/src/drops.rs index 8c4a1c572..47708fcd9 100644 --- a/ts/fixtures/task/src/drops.rs +++ b/ts/fixtures/task/src/drops.rs @@ -327,6 +327,15 @@ impl Hash for Key { } } +/// The same key, logged, unless it trips. +impl Clone for Key { + fn clone(&self) -> Self { + let id = self.read(); + self.log.note(format!("k{id} cloned")); + Self::faulty(id, self.log.clone(), self.fault) + } +} + impl std::fmt::Debug for Key { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("Key").field(&self.id).finish() @@ -789,3 +798,74 @@ fn grown(log: &Log, id: u32, at: u8, tree: bool) { } log.note(format!("unreached")); } + +/// What a `Vec`'s edits, its and a tuple's `clone`, and `Ord`'s defaults drop, scenario +/// `at`'s alone, and what is left to drop when a closure, a clone, a drop, or an index +/// panics partway. +pub fn edited(log: &Log, id: u32, at: u8) { + let key = |n: u32| Key::new(id + n, log.clone()); + let fault = |n: u32, fault: Fault| Key::faulty(id + n, log.clone(), fault); + let ids = |v: &[Key]| v.iter().map(|k| (k.id - id).to_string()).collect::>().join(","); + match at { + 0 => { + let mut v = list![key(1), key(2), key(3), key(4)]; + v.retain(|k| (k.id - id) % 2 == 1); + log.note(format!("retained {}", ids(&v))); + v.retain_mut(|k| k.id != id + 3); + log.note(format!("retained {}", ids(&v))); + // `max` blows as `clamp` drops it, and `min` still drops. + drop(key(2).clamp(key(1), fault(3, Fault::Blows))); + } + 1 => { + let mut v = list![key(1), key(2), key(3), key(4)]; + v.retain(|k| { + if k.id == id + 3 { + panic!("k{} retained", k.id); + } + k.id != id + 2 + }); + } + 2 => { + let mut v = list![key(1), key(1), key(2), key(2), key(3)]; + v.dedup(); + log.note(format!("deduped {}", ids(&v))); + v.dedup_by_key(|k| k.id / 2); + log.note(format!("deduped {}", ids(&v))); + v.dedup_by(|a, b| a.id > b.id); + log.note(format!("deduped {}", ids(&v))); + // Bounds out of order, so `clamp`'s assertion panics holding all three. + drop(key(2).clamp(key(3), key(1))); + } + 3 => { + let mut v = list![key(1), fault(1, Fault::Blows), key(1), key(2)]; + v.dedup(); + } + 4 => { + let mut v = list![key(1), key(2), key(3)]; + drop(v.swap_remove(0)); + log.note(format!("swapped {}", ids(&v))); + drop(v.swap_remove(3)); + } + 5 => { + let v = list![key(1), key(2)]; + log.note(format!("cloned {}", ids(&v.clone()))); + let tripped = list![key(1), fault(2, Fault::Trips), key(3)]; + drop(tripped.clone()); + } + 6 => { + let pair = (key(1), key(2)); + drop(pair.clone()); + let tripped = (key(1), fault(2, Fault::Trips)); + drop(tripped.clone()); + } + _ => { + log.note(format!("max {}", key(1).max(key(2)).id - id)); + log.note(format!("min {}", key(5).min(key(4)).id - id)); + log.note(format!("clamped {}", key(2).clamp(key(1), key(3)).id - id)); + log.note(format!("clamped {}", key(0).clamp(key(1), key(3)).id - id)); + // A comparison that panics in `max`, holding both. + drop(key(1).max(fault(2, Fault::Trips))); + } + } + log.note(format!("unreached")); +} diff --git a/ts/fixtures/task/src/harness.rs b/ts/fixtures/task/src/harness.rs index 8dc34bc77..e41ca0443 100644 --- a/ts/fixtures/task/src/harness.rs +++ b/ts/fixtures/task/src/harness.rs @@ -48,7 +48,7 @@ pub fn run(input: &[u8]) -> Vec { /// Run one step of a script. fn run_step(log: &Log, exec: &mut Executor, channels: &mut Vec, op: u8, arg: u8) { let pick = |len: usize| (len > 0).then(|| usize::from(arg) % len); - match op % 13 { + match op % 14 { 0 => { log.note(format!("c{} open", channels.len())); channels.push(Channel::open()); @@ -104,11 +104,12 @@ fn run_step(log: &Log, exec: &mut Executor, channels: &mut Vec, op: u8, } } 11 => drops::run(log, 1000 * exec.len() as u32, arg), - _ => { + 12 => { if let Some(c) = pick(channels.len()) { let guard = Guard::new(exec.len() as u32, log.clone()); exec.spawn(drops::held(channels[c].consumer(), guard)); } } + _ => drops::edited(log, 1000 * exec.len() as u32, arg % 8), } } diff --git a/ts/fixtures/task/ts.toml b/ts/fixtures/task/ts.toml index 3891d2633..bcb1d420c 100644 --- a/ts/fixtures/task/ts.toml +++ b/ts/fixtures/task/ts.toml @@ -1,4 +1,4 @@ package = "task-fixture" # What the hand-written harness, tests/task.ts, calls: the futures it spawns, and the # channels and log it drives them with. -roots = ["log::Log", "model::Channel", "model::Guard", "model::sum", "model::drain", "model::blocks", "drops::run", "drops::held"] +roots = ["log::Log", "model::Channel", "model::Guard", "model::sum", "model::drain", "model::blocks", "drops::run", "drops::held", "drops::edited"] diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 2743d7ce3..8ab3185f0 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -5,6 +5,7 @@ // left only where a call dispatches on its receiver: an iterator's `next`, a writer's // `writeStr`, a future's `poll`, a waker's, and `[Symbol.dispose]`. +import type { Ordering } from "./rt/collections.ts"; import { type char, type TryFromIntError, type u32, u8Debug, usizeDebug, usizeDisplay } from "./rt/int.ts"; import type { Pending } from "./rt/task.ts"; @@ -264,6 +265,220 @@ export function sliceGet(s: ArrayLike, index: number, none?: None): T | un return index < s.length ? s[index] : none; } +/** `core::ops::Bound`, tagged as the crate's own enums are. */ +export type RangeBound = { readonly tag: "Included"; readonly _0: T } | { readonly tag: "Excluded"; readonly _0: T } | { readonly tag: "Unbounded" }; + +/** `Bound::cloned` and `copied`: `b` with `clone` of what it holds. */ +export function boundMap(b: RangeBound, clone: (value: T) => T): RangeBound { + return b.tag === "Unbounded" ? b : { tag: b.tag, _0: clone(b._0) }; +} + +/** `NonZero::new`: `n`, unless it is 0. */ +export function nonZero(n: T): T | undefined { + return n === 0 ? undefined : n; +} + +/** `reverse`, in place. */ +export function sliceReverse(s: T[]): void { + s.reverse(); +} + +/** `last` and `last_mut`: the last element, or `undefined` if empty. */ +export function sliceLast(s: ArrayLike): T | undefined { + return s.length === 0 ? undefined : s[s.length - 1]; +} + +/** `contains`, by `eq` of each element and then `x`, as std's `==` reads them. */ +export function sliceContains(s: ArrayLike, x: T, eq: (a: T, b: T) => boolean): boolean { + for (let i = 0; i < s.length; i++) if (eq(s[i], x)) return true; + return false; +} + +/** `swap`, panicking on either index past the end, `a` first, as std's indexing does. */ +export function sliceSwap(s: T[], a: number, b: number): void { + const x = s[idx(s, a)]; + s[a] = s[idx(s, b)]; + s[b] = x; +} + +/** + * `sort` and `sort_by`, and the unstable sorts, which may order equal elements either way + * and here keep them in order: stable, by `cmp`, which moves an element before another + * only if it orders `Less`, as std's sorts test `lt`. If `cmp` panics, the slice holds each + * element once, in an order std leaves unspecified, as std's does. + */ +export function sliceSortBy(s: T[], cmp: (a: T, b: T) => Ordering | undefined): void { + sort(s, (a, b) => cmp(a, b) === -1); +} + +/** `sort_by_key` and `sort_unstable_by_key`: by `cmp` of each element's `key`, as `sliceSortBy` sorts. */ +export function sliceSortByKey(s: T[], key: (item: T) => K, cmp: (a: K, b: K) => Ordering | undefined): void { + sort(s, (a, b) => cmp(key(a), key(b)) === -1); +} + +/** + * A stable merge sort of `s` by `less`, over runs that insertion sorts first. It calls only + * `less`, never JS's `sort`, which moves `undefined`, a `None`, to the end without + * comparing it, and orders its calls differently in each engine. + */ +function sort(s: T[], less: (a: T, b: T) => boolean): void { + const n = s.length; + const RUN = 16; + for (let lo = 0; lo < n; lo += RUN) { + const hi = Math.min(lo + RUN, n); + for (let i = lo + 1; i < hi; i++) { + const x = s[i]; + let j = i; + // Shifted elements leave a hole at `j`, which `x` fills if `less` panics. + try { + while (j > lo && less(x, s[j - 1])) { + s[j] = s[j - 1]; + j--; + } + } finally { + s[j] = x; + } + } + } + if (n <= RUN) return; + const left: T[] = []; + for (let width = RUN; width < n; width *= 2) { + for (let lo = 0; lo + width < n; lo += 2 * width) { + const mid = lo + width; + const hi = Math.min(mid + width, n); + if (!less(s[mid], s[mid - 1])) continue; + // The left run moves aside, and the merge fills `s` from `lo`, never past the + // right run's next element. If `less` panics, what is left of the left run fills + // the gap. + left.length = 0; + for (let i = lo; i < mid; i++) left.push(s[i]); + let i = 0; + let j = mid; + let k = lo; + try { + // `k` moves only once `less` returns, so a panic leaves no slot written twice. + while (i < left.length && j < hi) { + s[k] = less(s[j], left[i]) ? s[j++] : left[i++]; + k++; + } + } finally { + while (i < left.length) s[k++] = left[i++]; + } + } + } +} + +/** + * `Vec::retain` and `retain_mut`: keeps each element `f` returns true for, in order, and + * drops each other one once `f` rejects it. If `f` or a drop panics, what `f` kept and + * what it had not yet seen stay, as std's do. + */ +export function vecRetain(v: T[], f: (item: T) => boolean, drop?: (item: T) => void): void { + const n = v.length; + let read = 0; + let write = 0; + try { + while (read < n) { + const item = v[read]; + if (f(item)) { + v[write++] = item; + read++; + } else { + read++; + drop?.(item); + } + } + } finally { + v.copyWithin(write, read, n); + v.length = write + n - read; + } +} + +/** + * `Vec::dedup_by`: drops each element `same(element, previous kept)` is true for, in order. + * If `same` or a drop panics, what it kept and what it had not yet seen stay, as std's do. + */ +export function vecDedupBy(v: T[], same: (a: T, b: T) => boolean, drop?: (item: T) => void): void { + const n = v.length; + let first = 1; + while (first < n && !same(v[first], v[first - 1])) first++; + if (first >= n) return; + let read = first + 1; + let write = first; + try { + drop?.(v[first]); + while (read < n) { + const item = v[read]; + if (same(item, v[write - 1])) { + read++; + drop?.(item); + } else { + v[write++] = item; + read++; + } + } + } finally { + v.copyWithin(write, read, n); + v.length = write + n - read; + } +} + +/** `Vec::dedup_by_key`: as `vecDedupBy`, by `eq` of `key` of each element, then of the previous kept. */ +export function vecDedupByKey(v: T[], key: (item: T) => K, eq: (a: K, b: K) => boolean, drop?: (item: T) => void): void { + vecDedupBy(v, (a, b) => eq(key(a), key(b)), drop); +} + +/** `Vec::swap_remove`: the element at `i`, with the last moved into its place. */ +export function vecSwapRemove(v: T[], i: number): T { + if (i >= v.length) panic(`swap_remove index (is ${i}) should be < len (is ${v.length})`); + const item = v[i]; + v[i] = v[v.length - 1]; + v.pop(); + return item; +} + +/** + * `Clone` of a `Vec`, and `to_vec`, by `clone` of each element in order. If one panics, the + * clones made so far drop, in order, as std's do. + */ +export function vecClone(s: ArrayLike, clone: (item: T) => T, drop?: (item: T) => void): T[] { + const out: T[] = []; + try { + for (let i = 0; i < s.length; i++) out.push(clone(s[i])); + } catch (e) { + if (drop !== undefined) for (const item of out) drop(item); + throw e; + } + return out; +} + +/** `Vec::extend_from_slice`: a clone of each element of `s`, pushed in order, as far as they clone. */ +export function vecExtendFromSlice(v: T[], s: ArrayLike, clone?: (item: T) => T): void { + for (let i = 0; i < s.length; i++) v.push(clone === undefined ? s[i] : clone(s[i])); +} + +/** + * `Clone` of a tuple, by `clone` of each field in order, `undefined` for one whose value is + * itself. If one panics, the clones made so far drop, the last first, by `drops`. + */ +export function tupleClone( + t: T, + clones: readonly (((value: never) => unknown) | undefined)[], + drops: readonly (((value: never) => void) | undefined)[], +): T { + const out: unknown[] = []; + try { + for (let i = 0; i < clones.length; i++) { + const clone = clones[i] as ((value: unknown) => unknown) | undefined; + out.push(clone === undefined ? t[i] : clone(t[i])); + } + } catch (e) { + for (let i = out.length - 1; i >= 0; i--) (drops[i] as ((value: unknown) => void) | undefined)?.(out[i]); + throw e; + } + return out as unknown as T; +} + /** * `&[u8]` and `&mut [u8]`, and `&[u8; N]`: `length` bytes of `data` from `start`. It never changes, so a * split makes another, which costs an object where a `Uint8Array` view costs several diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index d819d7334..7301885fd 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -75,24 +75,65 @@ export function cmpOption( return (a, b) => (a === none ? (b === none ? 0 : -1) : b === none ? 1 : cmp(a as T, b as T)) as O; } +/** `Ord::cmp` of `Reverse`s, or `PartialOrd::partial_cmp`: their values', the other way. */ +export function cmpReverse(cmp: (a: T, b: T) => O): (a: T, b: T) => O { + return (a, b) => cmp(b, a); +} + +/** + * `Ord::cmp` of slices, or `PartialOrd::partial_cmp`, by their elements' in order, then + * by length. + */ +export function cmpSlice(cmp: (a: T, b: T) => O): (a: ArrayLike, b: ArrayLike) => O { + return (a, b) => { + const n = Math.min(a.length, b.length); + for (let i = 0; i < n; i++) { + const c = cmp(a[i], b[i]); + if (c !== 0) return c; + } + return (a.length < b.length ? -1 : a.length > b.length ? 1 : 0) as O; + }; +} + /** `Ord::cmp` of `Arc`s, or `PartialOrd::partial_cmp`: their values'. */ export function cmpArc(cmp: (a: T, b: T) => O): (a: Arc, b: Arc) => O { return (a, b) => cmp(a.value, b.value); } -/** `cmp(a, b)`, which drops `b` and then `a` if it panics, as `max_by`'s unwinding does. */ -function compare(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): Ordering { +/** + * `other < self` of `Ord::max` and `min`, by `cmp`, a `partial_cmp`, which drops `other` and + * then `self` if it panics, as their unwinding does. + */ +function less(self: T, other: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): boolean { try { - return cmp(a, b); + return cmp(other, self) === -1; } catch (e) { - dropPair(b, a, drop, drop); + dropPair(other, self, drop, drop); throw e; } } -/** `Ord::max`, by `cmp`: `b` unless `a` is greater, and the other drops. */ -export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): T { - if (compare(a, b, cmp, drop) > 0) { +/** + * `Ord::clamp`, by `cmp`, a `partial_cmp`: `min` if `a` is less, `max` if greater, or else + * `a`, once `min <= max` is asserted. The operands it does not return drop, the last + * first, as std's do. + */ +export function ordClamp(a: T, min: T, max: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + let out: 0 | 1 | 2 | undefined; + try { + const order = cmp(min, max); + if (order === undefined || order > 0) panic("assertion failed: min <= max"); + out = cmp(a, min) === -1 ? 1 : cmp(a, max) === 1 ? 2 : 0; + } finally { + // A panic in one drop still drops the rest, as unwinding does. + if (drop !== undefined) dropAll([max, min, a].filter((_, i) => 2 - i !== out), drop); + } + return out === 1 ? min : out === 2 ? max : a; +} + +/** `Ord::max`, by `cmp`, a `partial_cmp`: `a` if `b < a`, or else `b`, and the other drops. */ +export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + if (less(a, b, cmp, drop)) { drop?.(b); return a; } @@ -100,9 +141,9 @@ export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (val return b; } -/** `Ord::min`, by `cmp`: `a` unless it is greater, and the other drops. */ -export function ordMin(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): T { - if (compare(a, b, cmp, drop) > 0) { +/** `Ord::min`, by `cmp`, a `partial_cmp`: `b` if `b < a`, or else `a`, and the other drops. */ +export function ordMin(a: T, b: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + if (less(a, b, cmp, drop)) { drop?.(a); return b; } @@ -136,6 +177,15 @@ export function eqTuple(fields: readonly ((a: neve }; } +/** `PartialEq::eq` of slices: their lengths', then their elements' in order. */ +export function eqSlice(eq: (a: T, b: T) => boolean): (a: ArrayLike, b: ArrayLike) => boolean { + return (a, b) => { + if (a.length !== b.length) return false; + for (let i = 0; i < a.length; i++) if (!eq(a[i], b[i])) return false; + return true; + }; +} + /** `PartialEq::eq` of `Option`s, from their values'. */ export function eqOption(eq: (a: T, b: T) => boolean): (a: T | undefined, b: T | undefined) => boolean; export function eqOption(eq: (a: T, b: T) => boolean, none: None): (a: T | None, b: T | None) => boolean; @@ -203,6 +253,14 @@ export function hashTuple(fields: readonly ((value }; } +/** `Hash::hash` of a slice: its length, then its elements' in order. */ +export function hashSlice(hash: (value: T, s: Hasher) => void): (value: ArrayLike, s: Hasher) => void { + return (value, s) => { + mix(s, value.length); + for (let i = 0; i < value.length; i++) hash(value[i], s); + }; +} + /** `Hash::hash` of an `Option`: whether it is `Some`, then its value's. */ export function hashOption(hash: (value: T, s: Hasher) => void): (value: T | undefined, s: Hasher) => void; export function hashOption(hash: (value: T, s: Hasher) => void, none: None): (value: T | None, s: Hasher) => void; @@ -1169,6 +1227,23 @@ export function btreeClear(m: BTreeMap, k?: (key: K) => void, v?: (v m.r = false; } +/** + * `split_off` of a map or set: the entries from `key` on, moved in order into a tree of + * their own. It compares before it moves any, so a panic in `cmp` leaves `m` whole, as + * std's does. Like std's, the new tree has a root unless `m` was empty. + */ +export function btreeSplitOff(m: BTreeMap, key: K): BTreeMap { + const out = btreeNew(m.c); + if (m.n === 0) return out; + const [keys, values] = flatten(m); + const i = search(keys, key, m.c); + const at = i < 0 ? ~i : i; + build(out, keys.slice(at), values.slice(at)); + build(m, keys.slice(0, at), values.slice(0, at)); + out.r = true; + return out; +} + /** * `retain`, which visits the keys in order and keeps each entry `f` returns true for, * dropping each other one as `f` rejects it. A panic in `f` leaves the entries from the @@ -1339,15 +1414,20 @@ export function btreeValues(m: BTreeMap, k?: (key: K) => void, v?: ( * A range of keys or indices, as its value is: `a..b`, `a..=b`, `a..` as `{ start }`, `..b` * as `{ end }`, or `..` as `undefined`. */ -export type Bounds = { readonly start: K; readonly end: K } | RangeInclusive | { readonly start: K } | { readonly end: K } | undefined; - -/** `RangeBounds`: the start, the end, and whether the end is in the range. */ +export type Bounds = + | { readonly start: K; readonly end: K } + | RangeInclusive + | { readonly start: K } + | { readonly end: K; readonly inclusive?: true } + | undefined; + +/** `RangeBounds`: the start, the end, and whether the end is in the range, as `..=end`'s is. */ function bounds(r: Bounds): [{ key: K } | undefined, { key: K } | undefined, boolean] { if (r === undefined) return [undefined, undefined, false]; - // Exhausted, an inclusive range ends before its end, as its `end_bound` says. A field - // test, not `instanceof`, so a bundle without `a..=b` leaves the class out. - if ("exhausted" in r) return [{ key: r.lo }, { key: r.hi }, !r.exhausted]; - return ["start" in r ? { key: r.start } : undefined, "end" in r ? { key: r.end } : undefined, false]; + // Exhausted by wrapping, an inclusive range excludes its start, as its `end_bound` says. + // A field test, not `instanceof`, so a bundle without `a..=b` leaves the class out. + if ("exhausted" in r) return [{ key: r.lo }, { key: r.exhausted ? r.lo : r.hi }, !r.exhausted]; + return ["start" in r ? { key: r.start } : undefined, "end" in r ? { key: r.end } : undefined, "inclusive" in r]; } /** `BTreeMap::range` and `range_mut`: the entries within `r`. */ diff --git a/ts/runtime/rt/int.ts b/ts/runtime/rt/int.ts index 176f7f1cc..9f4c37b12 100644 --- a/ts/runtime/rt/int.ts +++ b/ts/runtime/rt/int.ts @@ -111,6 +111,12 @@ export function min(a: number, b: number): number { return a <= b ? a : b; } +/** `Ord::clamp` of integers in numbers: `a` within `[min, max]`, panicking unless `min <= max`. */ +export function clamp(a: number, min: number, max: number): number { + if (min > max) panic(`min > max. min = ${min}, max = ${max}`); + return a < min ? min : a > max ? max : a; +} + // Integers of 32 bits or less, in numbers. Sums, differences, and quotients are exact; a // product is inexact only past 2^53, far outside every type's range, so its check still // fails. JS's 32-bit operators do the rest. Each type's functions pass its bounds to @@ -125,10 +131,21 @@ function inRange(value: number, min: number, max: number): number | undefined { return value >= min && value <= max ? value : undefined; } -function clamp(value: number, min: number, max: number): number { +function saturate(value: number, min: number, max: number): number { return value < min ? min : value > max ? max : value; } +/** An unsigned `a / b`, rounded up, panicking on a zero divisor. */ +function ceilDivide(a: number, b: number): number { + if (b === 0) panic("attempt to divide by zero"); + return a % b === 0 ? a / b : Math.trunc(a / b) + 1; +} + +/** Whether `a` is a multiple of `b`: of 0, only 0 is. */ +function multipleOf(a: number, b: number): boolean { + return b === 0 ? a === 0 : a % b === 0; +} + function divide(a: number, b: number, min: number, max: number): number { if (b === 0) panic("attempt to divide by zero"); return checked(Math.trunc(a / b), min, max, "divide"); @@ -254,13 +271,21 @@ export const u8CheckedSub = (a: u8, b: u8): u8 | undefined => inRange(a - b, 0, /** `u8`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u8CheckedMul = (a: u8, b: u8): u8 | undefined => inRange(a * b, 0, 0xff); /** `u8`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u8SaturatingAdd = (a: u8, b: u8): u8 => clamp(a + b, 0, 0xff); +export const u8SaturatingAdd = (a: u8, b: u8): u8 => saturate(a + b, 0, 0xff); /** `u8`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u8SaturatingSub = (a: u8, b: u8): u8 => clamp(a - b, 0, 0xff); +export const u8SaturatingSub = (a: u8, b: u8): u8 => saturate(a - b, 0, 0xff); /** `u8`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u8WrappingAdd = (a: u8, b: u8): u8 => (a + b) & 0xff; /** `u8`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u8WrappingSub = (a: u8, b: u8): u8 => (a - b) & 0xff; +/** `u8`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u8SaturatingMul = (a: u8, b: u8): u8 => saturate(a * b, 0, 0xff); +/** `u8`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u8WrappingMul = (a: u8, b: u8): u8 => Math.imul(a, b) & 0xff; +/** `u8`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u8DivCeil = (a: u8, b: u8): u8 => ceilDivide(a, b); +/** `u8`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u8IsMultipleOf = (a: u8, b: u8): boolean => multipleOf(a, b); /** `u8`'s `leading_ones`: the count of leading one bits. */ export const u8LeadingOnes = (a: u8): number => Math.clz32(~(a << 24)); /** `u8`'s `leading_zeros`: the count of leading zero bits. */ @@ -309,13 +334,21 @@ export const u16CheckedSub = (a: u16, b: u16): u16 | undefined => inRange(a - b, /** `u16`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u16CheckedMul = (a: u16, b: u16): u16 | undefined => inRange(a * b, 0, 0xffff); /** `u16`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u16SaturatingAdd = (a: u16, b: u16): u16 => clamp(a + b, 0, 0xffff); +export const u16SaturatingAdd = (a: u16, b: u16): u16 => saturate(a + b, 0, 0xffff); /** `u16`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u16SaturatingSub = (a: u16, b: u16): u16 => clamp(a - b, 0, 0xffff); +export const u16SaturatingSub = (a: u16, b: u16): u16 => saturate(a - b, 0, 0xffff); /** `u16`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u16WrappingAdd = (a: u16, b: u16): u16 => (a + b) & 0xffff; /** `u16`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u16WrappingSub = (a: u16, b: u16): u16 => (a - b) & 0xffff; +/** `u16`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u16SaturatingMul = (a: u16, b: u16): u16 => saturate(a * b, 0, 0xffff); +/** `u16`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u16WrappingMul = (a: u16, b: u16): u16 => Math.imul(a, b) & 0xffff; +/** `u16`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u16DivCeil = (a: u16, b: u16): u16 => ceilDivide(a, b); +/** `u16`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u16IsMultipleOf = (a: u16, b: u16): boolean => multipleOf(a, b); /** `u16`'s `leading_ones`: the count of leading one bits. */ export const u16LeadingOnes = (a: u16): number => Math.clz32(~(a << 16)); /** `u16`'s `leading_zeros`: the count of leading zero bits. */ @@ -364,13 +397,21 @@ export const u32CheckedSub = (a: u32, b: u32): u32 | undefined => inRange(a - b, /** `u32`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u32CheckedMul = (a: u32, b: u32): u32 | undefined => inRange(a * b, 0, 0xffffffff); /** `u32`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u32SaturatingAdd = (a: u32, b: u32): u32 => clamp(a + b, 0, 0xffffffff); +export const u32SaturatingAdd = (a: u32, b: u32): u32 => saturate(a + b, 0, 0xffffffff); /** `u32`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u32SaturatingSub = (a: u32, b: u32): u32 => clamp(a - b, 0, 0xffffffff); +export const u32SaturatingSub = (a: u32, b: u32): u32 => saturate(a - b, 0, 0xffffffff); /** `u32`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u32WrappingAdd = (a: u32, b: u32): u32 => (a + b) >>> 0; /** `u32`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u32WrappingSub = (a: u32, b: u32): u32 => (a - b) >>> 0; +/** `u32`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u32SaturatingMul = (a: u32, b: u32): u32 => saturate(a * b, 0, 0xffffffff); +/** `u32`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u32WrappingMul = (a: u32, b: u32): u32 => Math.imul(a, b) >>> 0; +/** `u32`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u32DivCeil = (a: u32, b: u32): u32 => ceilDivide(a, b); +/** `u32`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u32IsMultipleOf = (a: u32, b: u32): boolean => multipleOf(a, b); /** `u32`'s `leading_ones`: the count of leading one bits. */ export const u32LeadingOnes = (a: u32): number => Math.clz32(~a); /** `u32`'s `leading_zeros`: the count of leading zero bits. */ @@ -421,13 +462,17 @@ export const i8CheckedSub = (a: i8, b: i8): i8 | undefined => inRange(a - b, -0x /** `i8`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i8CheckedMul = (a: i8, b: i8): i8 | undefined => inRange(a * b, -0x80, 0x7f); /** `i8`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i8SaturatingAdd = (a: i8, b: i8): i8 => clamp(a + b, -0x80, 0x7f); +export const i8SaturatingAdd = (a: i8, b: i8): i8 => saturate(a + b, -0x80, 0x7f); /** `i8`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i8SaturatingSub = (a: i8, b: i8): i8 => clamp(a - b, -0x80, 0x7f); +export const i8SaturatingSub = (a: i8, b: i8): i8 => saturate(a - b, -0x80, 0x7f); /** `i8`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i8WrappingAdd = (a: i8, b: i8): i8 => ((a + b) << 24) >> 24; /** `i8`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i8WrappingSub = (a: i8, b: i8): i8 => ((a - b) << 24) >> 24; +/** `i8`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i8SaturatingMul = (a: i8, b: i8): i8 => saturate(a * b, -0x80, 0x7f); +/** `i8`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i8WrappingMul = (a: i8, b: i8): i8 => (Math.imul(a, b) << 24) >> 24; /** `i8`'s `leading_ones`: the count of leading one bits. */ export const i8LeadingOnes = (a: i8): number => Math.clz32(~(a << 24)); /** `i8`'s `leading_zeros`: the count of leading zero bits. */ @@ -478,13 +523,17 @@ export const i16CheckedSub = (a: i16, b: i16): i16 | undefined => inRange(a - b, /** `i16`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i16CheckedMul = (a: i16, b: i16): i16 | undefined => inRange(a * b, -0x8000, 0x7fff); /** `i16`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i16SaturatingAdd = (a: i16, b: i16): i16 => clamp(a + b, -0x8000, 0x7fff); +export const i16SaturatingAdd = (a: i16, b: i16): i16 => saturate(a + b, -0x8000, 0x7fff); /** `i16`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i16SaturatingSub = (a: i16, b: i16): i16 => clamp(a - b, -0x8000, 0x7fff); +export const i16SaturatingSub = (a: i16, b: i16): i16 => saturate(a - b, -0x8000, 0x7fff); /** `i16`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i16WrappingAdd = (a: i16, b: i16): i16 => ((a + b) << 16) >> 16; /** `i16`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i16WrappingSub = (a: i16, b: i16): i16 => ((a - b) << 16) >> 16; +/** `i16`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i16SaturatingMul = (a: i16, b: i16): i16 => saturate(a * b, -0x8000, 0x7fff); +/** `i16`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i16WrappingMul = (a: i16, b: i16): i16 => (Math.imul(a, b) << 16) >> 16; /** `i16`'s `leading_ones`: the count of leading one bits. */ export const i16LeadingOnes = (a: i16): number => Math.clz32(~(a << 16)); /** `i16`'s `leading_zeros`: the count of leading zero bits. */ @@ -535,13 +584,17 @@ export const i32CheckedSub = (a: i32, b: i32): i32 | undefined => inRange(a - b, /** `i32`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i32CheckedMul = (a: i32, b: i32): i32 | undefined => inRange(a * b, -0x80000000, 0x7fffffff); /** `i32`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i32SaturatingAdd = (a: i32, b: i32): i32 => clamp(a + b, -0x80000000, 0x7fffffff); +export const i32SaturatingAdd = (a: i32, b: i32): i32 => saturate(a + b, -0x80000000, 0x7fffffff); /** `i32`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i32SaturatingSub = (a: i32, b: i32): i32 => clamp(a - b, -0x80000000, 0x7fffffff); +export const i32SaturatingSub = (a: i32, b: i32): i32 => saturate(a - b, -0x80000000, 0x7fffffff); /** `i32`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i32WrappingAdd = (a: i32, b: i32): i32 => (a + b) | 0; /** `i32`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i32WrappingSub = (a: i32, b: i32): i32 => (a - b) | 0; +/** `i32`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i32SaturatingMul = (a: i32, b: i32): i32 => saturate(a * b, -0x80000000, 0x7fffffff); +/** `i32`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i32WrappingMul = (a: i32, b: i32): i32 => Math.imul(a, b); /** `i32`'s `leading_ones`: the count of leading one bits. */ export const i32LeadingOnes = (a: i32): number => Math.clz32(~a); /** `i32`'s `leading_zeros`: the count of leading zero bits. */ @@ -608,6 +661,14 @@ export const usizeSaturatingSub: (a: usize, b: usize) => usize = u32SaturatingSu export const usizeWrappingAdd: (a: usize, b: usize) => usize = u32WrappingAdd as never; /** `usize`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const usizeWrappingSub: (a: usize, b: usize) => usize = u32WrappingSub as never; +/** `usize`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const usizeSaturatingMul: (a: usize, b: usize) => usize = u32SaturatingMul as never; +/** `usize`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const usizeWrappingMul: (a: usize, b: usize) => usize = u32WrappingMul as never; +/** `usize`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const usizeDivCeil: (a: usize, b: usize) => usize = u32DivCeil as never; +/** `usize`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const usizeIsMultipleOf: (a: usize, b: usize) => boolean = u32IsMultipleOf as never; /** `usize`'s `leading_ones`: the count of leading one bits. */ export const usizeLeadingOnes: (a: usize) => number = u32LeadingOnes as never; /** `usize`'s `leading_zeros`: the count of leading zero bits. */ @@ -664,6 +725,10 @@ export const isizeSaturatingSub: (a: isize, b: isize) => isize = i32SaturatingSu export const isizeWrappingAdd: (a: isize, b: isize) => isize = i32WrappingAdd as never; /** `isize`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const isizeWrappingSub: (a: isize, b: isize) => isize = i32WrappingSub as never; +/** `isize`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const isizeSaturatingMul: (a: isize, b: isize) => isize = i32SaturatingMul as never; +/** `isize`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const isizeWrappingMul: (a: isize, b: isize) => isize = i32WrappingMul as never; /** `isize`'s `leading_ones`: the count of leading one bits. */ export const isizeLeadingOnes: (a: isize) => number = i32LeadingOnes as never; /** `isize`'s `leading_zeros`: the count of leading zero bits. */ @@ -850,6 +915,37 @@ function saturated(v: Wide, bits: number, signed: boolean): Wide { return overflow === 0 ? v : extreme(overflow > 0, bits, signed); } +/** Whether a wide value is negative: only a signed type's can be. */ +function negative(v: Wide): boolean { + return typeof v === "number" ? v < 0 : v.hi < 0; +} + +/** `a * b`, clamped to the type's range: past it, toward the sign the product has. */ +function saturatingProduct(a: Wide, b: Wide, bits: number, signed: boolean): Wide { + return product(a, b, bits, signed) ?? extreme(negative(a) === negative(b), bits, signed); +} + +/** `a * b`, wrapped into the type's range. */ +function wrappingProduct(a: Wide, b: Wide, bits: number, signed: boolean): Wide { + return product(a, b, bits, signed) ?? one(box(exact(limbs(a, bits, signed)) * exact(limbs(b, bits, signed)), bits, signed)); +} + +/** Whether `a` is a multiple of `b`, unsigned: of 0, only 0 is. */ +function multiple(a: Wide, b: Wide, bits: number): boolean { + return b === 0 ? a === 0 : rem(a, b, bits, false) === 0; +} + +/** A wide value's decimal text, as its `Debug` writes it. */ +function decimal(v: Wide): string { + return typeof v === "number" ? String(v) : String(exact(v)); +} + +/** `Ord::clamp` of wide values: `a` within `[min, max]`, panicking unless `min <= max`. */ +function clampWide(a: Wide, min: Wide, max: Wide): Wide { + if (lt(max, min)) panic(`min > max. min = ${decimal(min)}, max = ${decimal(max)}`); + return lt(a, min) ? min : lt(max, a) ? max : a; +} + function mul(a: Wide, b: Wide, bits: number, signed: boolean): Wide { const v = product(a, b, bits, signed); if (v === undefined) panic("attempt to multiply with overflow"); @@ -925,6 +1021,18 @@ function product128(a: number, b: number): Limbs { return { hi: n3 | 0, w2: n2, w1: n1, lo } as Limbs; } +/** An unsigned 64-bit `a / b`, rounded up, panicking on a zero divisor. */ +function ceil64(a: Wide, b: Wide): Wide { + const q = div(a, b, 64, false); + return rem(a, b, 64, false) === 0 ? q : sum64(q, 1, 1, false); +} + +/** An unsigned 128-bit `a / b`, rounded up, panicking on a zero divisor. */ +function ceil128(a: Wide, b: Wide): Wide { + const q = div(a, b, 128, false); + return rem(a, b, 128, false) === 0 ? q : sum128(q, 1, 1, false); +} + function div(a: Wide, b: Wide, bits: number, signed: boolean): Wide { if (b === 0) panic("attempt to divide by zero"); return quotient(a, b, bits, signed, false); @@ -1262,6 +1370,14 @@ export const u64SaturatingSub = (a: u64, b: u64): u64 => (typeof a === "number" export const u64WrappingAdd = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && fits(a + b, false) ? a + b : sum64(a, b, 1, false)) as u64; /** `u64`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u64WrappingSub = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && fits(a - b, false) ? a - b : sum64(a, b, -1, false)) as u64; +/** `u64`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u64SaturatingMul = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 64, false)) as u64; +/** `u64`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u64WrappingMul = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 64, false)) as u64; +/** `u64`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u64DivCeil = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" ? ceilDivide(a, b) : ceil64(a, b)) as u64; +/** `u64`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u64IsMultipleOf = (a: u64, b: u64): boolean => (typeof a === "number" && typeof b === "number" ? multipleOf(a, b) : multiple(a, b, 64)); /** `u64`'s `leading_ones`: the count of leading one bits. */ export const u64LeadingOnes = (a: u64): number => leadingOnes64(a, false); /** `u64`'s `leading_zeros`: the count of leading zero bits. */ @@ -1312,6 +1428,8 @@ export const u64Ge = (a: u64, b: u64): boolean => typeof a === "number" && typeo export const u64Max = (a: u64, b: u64): u64 => (lt(b, a) ? a : b); /** `u64`'s `Ord::min`: the lesser, `a` if they are equal. */ export const u64Min = (a: u64, b: u64): u64 => (lt(b, a) ? b : a); +/** `u64`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const u64Clamp = (a: u64, min: u64, max: u64): u64 => clampWide(a, min, max) as u64; /** `u64`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const u64Step: Step = (n, by) => stepped(sum64(n, Math.abs(by), by < 0 ? -1 : 1, false)) as [u64, boolean]; @@ -1362,6 +1480,10 @@ export const i64SaturatingSub = (a: i64, b: i64): i64 => (typeof a === "number" export const i64WrappingAdd = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && fits(a + b, true) ? a + b : sum64(a, b, 1, true)) as i64; /** `i64`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i64WrappingSub = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && fits(a - b, true) ? a - b : sum64(a, b, -1, true)) as i64; +/** `i64`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i64SaturatingMul = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 64, true)) as i64; +/** `i64`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i64WrappingMul = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 64, true)) as i64; /** `i64`'s `leading_ones`: the count of leading one bits. */ export const i64LeadingOnes = (a: i64): number => leadingOnes64(a, true); /** `i64`'s `leading_zeros`: the count of leading zero bits. */ @@ -1410,6 +1532,8 @@ export const i64Ge = (a: i64, b: i64): boolean => typeof a === "number" && typeo export const i64Max = (a: i64, b: i64): i64 => (lt(b, a) ? a : b); /** `i64`'s `Ord::min`: the lesser, `a` if they are equal. */ export const i64Min = (a: i64, b: i64): i64 => (lt(b, a) ? b : a); +/** `i64`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const i64Clamp = (a: i64, min: i64, max: i64): i64 => clampWide(a, min, max) as i64; /** `i64`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const i64Step: Step = (n, by) => stepped(sum64(n, Math.abs(by), by < 0 ? -1 : 1, true)) as [i64, boolean]; @@ -1458,6 +1582,14 @@ export const u128SaturatingSub = (a: u128, b: u128): u128 => (typeof a === "numb export const u128WrappingAdd = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && fits(a + b, false) ? a + b : sum128(a, b, 1, false)) as u128; /** `u128`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u128WrappingSub = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && fits(a - b, false) ? a - b : sum128(a, b, -1, false)) as u128; +/** `u128`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u128SaturatingMul = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 128, false)) as u128; +/** `u128`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u128WrappingMul = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 128, false)) as u128; +/** `u128`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u128DivCeil = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" ? ceilDivide(a, b) : ceil128(a, b)) as u128; +/** `u128`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u128IsMultipleOf = (a: u128, b: u128): boolean => (typeof a === "number" && typeof b === "number" ? multipleOf(a, b) : multiple(a, b, 128)); /** `u128`'s `leading_ones`: the count of leading one bits. */ export const u128LeadingOnes = (a: u128): number => leadingOnes128(a, false); /** `u128`'s `leading_zeros`: the count of leading zero bits. */ @@ -1506,6 +1638,8 @@ export const u128Ge = (a: u128, b: u128): boolean => typeof a === "number" && ty export const u128Max = (a: u128, b: u128): u128 => (lt(b, a) ? a : b); /** `u128`'s `Ord::min`: the lesser, `a` if they are equal. */ export const u128Min = (a: u128, b: u128): u128 => (lt(b, a) ? b : a); +/** `u128`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const u128Clamp = (a: u128, min: u128, max: u128): u128 => clampWide(a, min, max) as u128; /** `u128`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const u128Step: Step = (n, by) => stepped(sum128(n, Math.abs(by), by < 0 ? -1 : 1, false)) as [u128, boolean]; @@ -1556,6 +1690,10 @@ export const i128SaturatingSub = (a: i128, b: i128): i128 => (typeof a === "numb export const i128WrappingAdd = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && fits(a + b, true) ? a + b : sum128(a, b, 1, true)) as i128; /** `i128`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i128WrappingSub = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && fits(a - b, true) ? a - b : sum128(a, b, -1, true)) as i128; +/** `i128`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i128SaturatingMul = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 128, true)) as i128; +/** `i128`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i128WrappingMul = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 128, true)) as i128; /** `i128`'s `leading_ones`: the count of leading one bits. */ export const i128LeadingOnes = (a: i128): number => leadingOnes128(a, true); /** `i128`'s `leading_zeros`: the count of leading zero bits. */ @@ -1604,5 +1742,7 @@ export const i128Ge = (a: i128, b: i128): boolean => typeof a === "number" && ty export const i128Max = (a: i128, b: i128): i128 => (lt(b, a) ? a : b); /** `i128`'s `Ord::min`: the lesser, `a` if they are equal. */ export const i128Min = (a: i128, b: i128): i128 => (lt(b, a) ? b : a); +/** `i128`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const i128Clamp = (a: i128, min: i128, max: i128): i128 => clampWide(a, min, max) as i128; /** `i128`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const i128Step: Step = (n, by) => stepped(sum128(n, Math.abs(by), by < 0 ? -1 : 1, true)) as [i128, boolean]; diff --git a/ts/runtime/rt/iter.ts b/ts/runtime/rt/iter.ts index 99261cc1a..1c57102c5 100644 --- a/ts/runtime/rt/iter.ts +++ b/ts/runtime/rt/iter.ts @@ -18,7 +18,7 @@ // of iterator has its own, the `owned` functions follow it, dispatching on the kind, so a // bundle that never drops an item carries none of it. -import { ByteVec, byteVecPush, Err, type None, Ok, panic, type Result } from "../rt.ts"; +import { ByteVec, byteVecPush, Err, type None, Ok, panic, type RangeBound, type Result } from "../rt.ts"; import { BTreeIter, HashIter } from "./collections.ts"; import { type Limbs, lt as wideLt, type Step } from "./int.ts"; import { drop as dispose, dropAll, dropRange } from "./task.ts"; @@ -2173,19 +2173,18 @@ export class RangeInclusive extends Iter { this.int = int; } + /** std's: `start` steps past the item, so it passes `end`, and only wrapping exhausts it. */ next(): T | Done { if (rangeInclusiveIsEmpty(this)) return DONE; const lo = this.lo; - if (lt(lo, this.hi)) this.lo = step(lo, 1, this.int)!; - else this.exhausted = true; + [this.lo, this.exhausted] = stepOverflowing(lo, 1, this.int); return lo; } override nextBack(): T | Done { if (rangeInclusiveIsEmpty(this)) return DONE; const hi = this.hi; - if (lt(this.lo, hi)) this.hi = step(hi, -1, this.int)!; - else this.exhausted = true; + [this.hi, this.exhausted] = stepOverflowing(hi, -1, this.int); return hi; } @@ -2242,7 +2241,23 @@ export function rangeInclusiveClone(r: RangeInclusive): RangeInclusive return range; } +/** `RangeInclusive::start_bound`: its start, included. */ +export function rangeInclusiveStartBound(r: RangeInclusive): RangeBound { + return { tag: "Included", _0: r.lo }; +} + +/** `RangeInclusive::end_bound`: its end, included, until wrapping exhausts it and it excludes its start, as std's. */ +export function rangeInclusiveEndBound(r: RangeInclusive): RangeBound { + return r.exhausted ? { tag: "Excluded", _0: r.lo } : { tag: "Included", _0: r.hi }; +} + /** `Step::forward_overflowing` and `backward_overflowing`: `n + by`, wrapped within `int`, and whether it wrapped. */ +/** `Step::forward_overflowing` by `by`, of an integer type's step or a safe number's. */ +function stepOverflowing(n: T, by: number, int: Step | undefined): [T, boolean] { + if (int !== undefined) return int(n, by); + return [step(n, by, int)!, false]; +} + function overflowing(n: T, by: number, int: Step | undefined): [T, boolean] { if (int === undefined) throw new Error("rust2-ts: stepping a range of no integer type"); return int(n, by); diff --git a/ts/runtime/rt/str.ts b/ts/runtime/rt/str.ts index eb7f40544..ba0e33dcd 100644 --- a/ts/runtime/rt/str.ts +++ b/ts/runtime/rt/str.ts @@ -7,8 +7,10 @@ // surrogate pair. import { fmtCharDebug, panic, panicFmt, stringLen } from "../rt.ts"; -import type { char, usize } from "./int.ts"; -import { DONE, type Done, Iter } from "./iter.ts"; +import type { char, u8, usize } from "./int.ts"; +import { DONE, type Done, Iter, iterSlice } from "./iter.ts"; + +const encoder = /* @__PURE__ */ new TextEncoder(); /** A pattern: a `char` or a `&str`, as its text, or a `FnMut(char) -> bool`. */ export type Pattern = string | ((c: char) => boolean); @@ -331,3 +333,33 @@ export function strRfind(s: string, p: Pattern): usize | undefined { const m = new Searcher(s, p); return m.nextMatchBack() ? (utf8Len(s, 0, m.start) as usize) : undefined; } + +/** A pattern of `[char; N]` or `&[char]`: whether a char is any of `cs`. */ +export function patternChars(cs: ArrayLike): (c: char) => boolean { + return (c) => { + for (let i = 0; i < cs.length; i++) if (cs[i] === c) return true; + return false; + }; +} + +/** `str::ends_with`. */ +export function strEndsWith(s: string, p: Pattern): boolean { + if (typeof p === "string") return s.endsWith(p); + return s.length > 0 && p(s.codePointAt(before(s, s.length)) as char); +} + +/** `str::split_once`: the text before the first match and after it. */ +export function strSplitOnce(s: string, p: Pattern): [string, string] | undefined { + const m = new Searcher(s, p); + return m.nextMatch() ? [s.slice(0, m.start), s.slice(m.end)] : undefined; +} + +/** `str::is_char_boundary`: whether byte `i` starts a char, or is the end. */ +export function strIsCharBoundary(s: string, i: number): boolean { + return unitAt(s, 0, 0, i) >= 0; +} + +/** `str::bytes`: its UTF-8 bytes. */ +export function strBytes(s: string): Iter { + return iterSlice(encoder.encode(s)); +} diff --git a/ts/src/census.rs b/ts/src/census.rs index dd8cdb383..4327b6ac4 100644 --- a/ts/src/census.rs +++ b/ts/src/census.rs @@ -148,6 +148,7 @@ const VERBATIM: &[&str] = &[ "Drop", "From", "From::from", + "Hash::hash_slice", "LowerExp", "None", "Octal", diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index ed1ffc61b..592f28d22 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -187,6 +187,11 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { (library::Std::Option, 1) | (library::Std::Poll, 0) => values.pop().unwrap(), (library::Std::Cow, _) if library::string(tcx, Ty::new_adt(tcx, adt, gargs)) => values.pop().unwrap(), (library::Std::Result, i) => Expr::result(i == 0, values.pop().unwrap()), + (library::Std::Reverse, _) => values.pop().unwrap(), + (library::Std::Bound, _) => { + let ts_ty = self.t.ty(Ty::new_adt(tcx, adt, gargs), span); + library::bound(adt.variant(variant).name.as_str(), values.pop(), ts_ty) + } _ => self.err(span, format!("constructing `{}`", tcx.def_path_str(adt_id))), }; } diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 64f078257..e10c3b2da 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -57,19 +57,50 @@ pub fn call<'tcx>( let f = hash_fn(b, t, hasher, span); return Ok(Some(f.call(args))); } - ("Ord", "max" | "min", ..) if let Some(t) = self_ty => { + // `Ord`'s defaults, of a std type or the crate's, which compare by `PartialOrd`'s `<`, + // `<=`, and `>`, and so by `partial_cmp` while those are the defaults. + ("Ord", "max" | "min" | "clamp", ..) if let Some(t) = self_ty => { let t = peel(b, t); - if !std_key(b, t) || Int::of(t).is_some() { + let local = matches!(t.kind(), ty::Adt(adt, _) if b.t.own(adt.did())); + if !(std_key(b, t) || local) || Int::of(t).is_some() { return Err(args); } + let tests: &[&str] = if name == "clamp" { &["le", "lt", "gt"] } else { &["lt"] }; + if let Some(test) = tests.iter().find(|test| own_test(b, t, test)) { + return Ok(Some(b.err(span, own_test_err(t, test)))); + } let mut values = args; - values.push(cmp_fn(b, t, false, span)); - // What drops the operand it does not return. + values.push(cmp_fn(b, t, true, span)); + // What drops the operands it does not return. let Some(droppers) = b.t.droppers(self_ty, span) else { return Ok(Some(Expr::undefined())); }; values.extend(droppers); - return Ok(Some(Expr::rt(if name == "max" { "ordMax" } else { "ordMin" }, values))); + let f = match name { + "max" => "ordMax", + "min" => "ordMin", + _ => "ordClamp", + }; + return Ok(Some(Expr::rt(f, values))); + } + // A std type's own comparisons, as a tuple's are, by its `partial_cmp`. The library + // maps the integers' and `bool`'s. + ("PartialOrd", "lt" | "le" | "gt" | "ge", ..) if let Some(t) = self_ty => { + let t = peel(b, t); + if matches!(t.kind(), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_)) || !std_key(b, t) { + return Err(args); + } + if own_test(b, t, name) { + return Ok(Some(b.err(span, own_test_err(t, name)))); + } + let order = cmp_fn(b, t, true, span).call(args); + let test = match name { + "lt" => library::Inherited::Lt, + "le" => library::Inherited::Le, + "gt" => library::Inherited::Gt, + _ => library::Inherited::Ge, + }; + return Ok(Some(test.test(b, order, out))); } ("PartialEq", "eq" | "ne", ..) if let Some(t) = self_ty => { // The library maps the integers' and `bool`'s. @@ -217,7 +248,7 @@ fn lookup_ty<'tcx>(b: &Body<'_, '_, 'tcx>, std: Std, call: &Call<'tcx>, owner: & ( _, "get" | "get_mut" | "get_key_value" | "contains_key" | "contains" | "remove" | "remove_entry" | "take" - | "range" | "range_mut", + | "range" | "range_mut" | "split_off", ) => { let tcx = b.t.tcx; let imp = tcx.inherent_impl_of_assoc(call.def_id)?; @@ -295,11 +326,13 @@ fn arg<'tcx>(coll: Ty<'tcx>, n: usize) -> Ty<'tcx> { } /// What a JS value of `ty` is: through references and boxes, which are their pointee, -/// up to a `&mut` that is an `rt.Place`. +/// up to a `&mut` that is an `rt.Place`, and a `NonZero`, which is its integer. fn peel<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { match ty.kind() { ty::Ref(_, inner, _) if b.t.place_pointee(ty).is_none() => peel(b, *inner), - ty::Adt(adt, args) if Std::of(b.t.tcx, adt.did()) == Some(Std::Box) => peel(b, args.type_at(0)), + ty::Adt(adt, args) if matches!(Std::of(b.t.tcx, adt.did()), Some(Std::Box | Std::NonZero)) => { + peel(b, args.type_at(0)) + } _ => ty, } } @@ -467,14 +500,16 @@ fn fieldless(adt: ty::AdtDef<'_>) -> bool { adt.is_enum() && adt.variants().iter().all(|v| v.fields.is_empty()) } -/// Whether `ty`'s `ne` reaches the crate's own `ne` of a type it holds: through tuples -/// and `Arc`s, but not an `Option`, whose `ne` is `!eq`. +/// Whether `ty`'s `ne` reaches the crate's own `ne` of a type it holds: through tuples, +/// `Arc`s, `Reverse`s, and the elements of slices, but not an `Option`, whose `ne` is +/// `!eq`. fn own_ne<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { ty::Tuple(tys) => tys.iter().any(|t| own_ne(b, t)), - ty::Adt(..) if let Some(inner) = arc_of(b, ty) => own_ne(b, inner), + _ if let Some(elem) = elements_of(b, ty) => own_ne(b, elem), + ty::Adt(..) if let Some(inner) = arc_of(b, ty).or_else(|| reverse_of(b, ty)) => own_ne(b, inner), ty::Adt(adt, _) if b.t.own(adt.did()) => { let ne = trait_fn(tcx, "PartialEq", "ne"); Instance::try_resolve(tcx, b.t.typing_env_pub(), ne, tcx.mk_args(&[ty.into(), ty.into()])) @@ -486,6 +521,31 @@ fn own_ne<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { } } +/// Whether `ty`'s `PartialOrd::{test}`, `lt` or another of its tests, reaches the crate's +/// own `test` of a type it holds, which `partial_cmp` stands for only while that is the +/// default: through a tuple's last element, `Arc`s, and `Reverse`s. +pub fn own_test<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>, test: &str) -> bool { + let tcx = b.t.tcx; + let ty = peel(b, ty); + match ty.kind() { + ty::Tuple(tys) => tys.last().is_some_and(|&t| own_test(b, t, test)), + ty::Adt(..) if let Some(inner) = arc_of(b, ty).or_else(|| reverse_of(b, ty)) => own_test(b, inner, test), + ty::Adt(adt, _) if b.t.own(adt.did()) => { + let f = trait_fn(tcx, "PartialOrd", test); + Instance::try_resolve(tcx, b.t.typing_env_pub(), f, tcx.mk_args(&[ty.into(), ty.into()])) + .ok() + .flatten() + .is_some_and(|instance| instance.def_id() != f) + } + _ => false, + } +} + +/// The refusal of a comparison that reaches the crate's own `test` of `ty`. +pub fn own_test_err(ty: Ty<'_>, test: &str) -> String { + format!("comparing `{ty}` through its own `PartialOrd::{test}`, which is not supported yet") +} + /// Whether `ty`'s `PartialEq` is derived, so it compares as JS compares its tags. fn derived_eq<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { let tcx = b.t.tcx; @@ -578,6 +638,7 @@ fn btree<'tcx>( (_, "range") if set => Expr::rt("btreeRangeKeys", values), (_, "range" | "range_mut") => Expr::rt("btreeRange", values), (_, "entry") => Expr::rt("entry", values), + (_, "split_off") => Expr::rt("btreeSplitOff", values), ("Index", "index") => Expr::rt("btreeIndex", values), ("Clone", "clone") => { let k = clone_fn(b, key, span); @@ -928,7 +989,10 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => true, ty::Tuple(tys) => !tys.is_empty() && tys.iter().all(held), - ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)) => held(inner), + _ if let Some(elem) = elements_of(b, ty) => held(elem), + ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)).or_else(|| reverse_of(b, ty)) => { + held(inner) + } ty::Adt(..) => library::string(b.t.tcx, ty) || matches!(b.t.std_of(ty), Some(Std::Ordering | Std::Duration)), _ => false, } @@ -939,6 +1003,22 @@ fn option_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Option)).then(|| arg(ty, 0)) } +/// What `ty` holds if it is a `Reverse`. +fn reverse_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + (b.t.std_of(ty) == Some(Std::Reverse)).then(|| arg(ty, 0)) +} + +/// The elements of `ty` if it is a `Vec`, a slice, or an array that is a JS array: of any +/// type but `u8`, whose bytes are typed arrays. +fn elements_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + let elem = match ty.kind() { + ty::Slice(elem) | ty::Array(elem, _) => *elem, + ty::Adt(..) if b.t.std_of(ty) == Some(Std::Vec) => arg(ty, 0), + _ => return None, + }; + (!matches!(elem.kind(), ty::Uint(ty::UintTy::U8))).then_some(elem) +} + /// What `ty` holds if it is an `Arc`. fn arc_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Arc)).then(|| arg(ty, 0)) @@ -946,7 +1026,7 @@ fn arc_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { /// `Ord::cmp` of `ty` as a function, or `PartialOrd::partial_cmp` if `partial`: the /// runtime's for a std type, which calls the same of what it holds, or the crate's. -fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: Span) -> Expr { +pub fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: Span) -> Expr { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { @@ -964,6 +1044,10 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S Expr::rt("cmpOption", [cmp].into_iter().chain(b.t.none_arg(inner)).collect()) } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("cmpArc", vec![cmp_fn(b, inner, partial, span)]), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => { + Expr::rt("cmpReverse", vec![cmp_fn(b, inner, partial, span)]) + } + _ if let Some(elem) = elements_of(b, ty) => Expr::rt("cmpSlice", vec![cmp_fn(b, elem, partial, span)]), ty::Adt(adt, _) if b.t.own(adt.did()) && partial => { let cmp = trait_fn(tcx, "PartialOrd", "partial_cmp"); b.fn_value(cmp, tcx.mk_args(&[ty.into(), ty.into()]), span) @@ -979,7 +1063,7 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S } /// `PartialEq::eq` of `ty`, as a function: the runtime's for a std type, or the crate's. -fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { +pub fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { @@ -1001,6 +1085,20 @@ fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { Expr::Rt(same) if same == "same" => Expr::Rt(same), eq => Expr::rt("eqOption", [eq].into_iter().chain(b.t.none_arg(inner)).collect()), }, + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => eq_fn(b, inner, span), + // A slice compares its elements by `!=`, which `!eq` stands for only while that is + // the default. + _ if let Some(elem) = elements_of(b, ty) + && own_ne(b, elem) => + { + b.err( + span, + format!( + "comparing `{ty}` by `<{elem} as PartialEq>::ne` through a held type's own, which is not supported yet" + ), + ) + } + _ if let Some(elem) = elements_of(b, ty) => Expr::rt("eqSlice", vec![eq_fn(b, elem, span)]), ty::Adt(..) if let Some(inner) = arc_of(b, ty) => { let mut values = vec![eq_fn(b, inner, span)]; // std's `Arc` finds itself equal before comparing a value that is `Eq`. @@ -1038,6 +1136,15 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa Expr::rt("hashOption", [hash].into_iter().chain(b.t.none_arg(inner)).collect()) } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("hashArc", vec![hash_fn(b, inner, hasher, span)]), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => hash_fn(b, inner, hasher, span), + _ if let Some(elem) = elements_of(b, ty) => { + if own_hash_slice(b, elem, hasher) { + let msg = + format!("hashing `{ty}` through `{elem}`'s own `Hash::hash_slice`, which is not supported yet"); + return b.err(span, msg); + } + Expr::rt("hashSlice", vec![hash_fn(b, elem, hasher, span)]) + } ty::Adt(adt, _) if b.t.own(adt.did()) => { let hash = trait_fn(tcx, "Hash", "hash"); b.fn_value(hash, tcx.mk_args(&[ty.into(), hasher.into()]), span) @@ -1047,6 +1154,22 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa } } +/// Whether the crate's own `Hash` of `elem` overrides `hash_slice`, which a slice of it +/// hashes through in place of each element's `hash`. +fn own_hash_slice<'tcx>(b: &Body<'_, '_, 'tcx>, elem: Ty<'tcx>, hasher: Ty<'tcx>) -> bool { + let tcx = b.t.tcx; + let elem = peel(b, elem); + let ty::Adt(adt, _) = elem.kind() else { + return false; + }; + let f = trait_fn(tcx, "Hash", "hash_slice"); + b.t.own(adt.did()) + && Instance::try_resolve(tcx, b.t.typing_env_pub(), f, tcx.mk_args(&[elem.into(), hasher.into()])) + .ok() + .flatten() + .is_some_and(|instance| instance.def_id() != f) +} + /// `Clone::clone` of `ty`, as a function, or `undefined` where it is the value itself. pub fn clone_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { let tcx = b.t.tcx; diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index ca357511c..f5b709373 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -89,6 +89,12 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { .map(|(t, v)| self.value(t, v, span)) .collect(), ), + // What core's wrappers of one value hold is that value, as is a pattern type's. + ty::Pat(base, _) => self.value(*base, valtree, span), + ty::Adt(..) if super::library::wrapped(tcx, ty).is_some() => match &children(valtree)[..] { + [(field_ty, field)] => self.value(*field_ty, *field, span), + _ => self.err(span, format!("a constant of type `{ty}` without one field")), + }, ty::Adt(adt, args) => { let fields = children(valtree); // Its nanoseconds are a pattern type, which only it reads. @@ -124,6 +130,14 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { Expr::New(Box::new(Expr::Rt("RangeInclusive".into())), values) } (Std::Ordering, _) => super::collections::ordering_variant(variant), + (Std::Bound, _) => { + let ts_ty = self.t.ty(ty, span); + super::library::bound(adt.variant(variant).name.as_str(), values.pop(), ts_ty) + } + (Std::RangeTo | Std::RangeToInclusive, _) => { + super::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) + } + (Std::RangeFrom, _) => Expr::Object(vec![(Key::Name("start".into()), values.pop().unwrap())]), _ => self.err(span, format!("a constant of type `{ty}`")), }; } diff --git a/ts/src/lower/copy.rs b/ts/src/lower/copy.rs index 502d6e66b..b02f9bb52 100644 --- a/ts/src/lower/copy.rs +++ b/ts/src/lower/copy.rs @@ -36,7 +36,10 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { // Their payload, or no object at all; a write into an `rt.Result`'s payload // replaces the result. - Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow) => (false, args.types().collect()), + Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow | Std::Reverse) => { + (false, args.types().collect()) + } + Some(Std::Bound) => (true, args.types().collect()), Some(_) => return false, None if self.own(adt.did()) && adt.all_fields().next().is_some() => { (true, adt.all_fields().map(|f| self.field_ty(f.did, args)).collect()) @@ -123,6 +126,20 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some(Std::Option) => ret(self.copy_unless(self.none(args.type_at(0)), args.type_at(0), span)), Some(Std::Poll) => ret(self.copy_unless(Expr::Rt("Pending".into()), args.type_at(0), span)), Some(Std::Result) => ret(self.copy_result(args.type_at(0), args.type_at(1), span)), + Some(Std::Reverse) => ret(self.copied(v(), args.type_at(0), span)), + Some(Std::Bound) => { + let ts_ty = self.ty(ty, span); + let held = self.copied(v().member("_0"), args.type_at(0), span); + let copy = Expr::Object(vec![ + (Key::Name("tag".into()), v().member("tag")), + (Key::Name("_0".into()), held), + ]); + ret(Expr::Cond( + Box::new(v().member("tag").binary("===", Expr::Str("Unbounded".into()))), + Box::new(v()), + Box::new(Expr::As(Box::new(copy), ts_ty)), + )) + } Some(Std::ControlFlow) => { let (residual, value) = (args.type_at(0), args.type_at(1)); ret(match (Flow::of(tcx, args), residual.kind()) { diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index 13672c5c6..99174180e 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -45,7 +45,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::HashSet | Std::BTreeMap | Std::BTreeSet - | Std::VecDeque, + | Std::VecDeque + | Std::Bound + | Std::Reverse, ) => args.types().any(|t| self.drops(t)), // An entry borrows its map, and holds only the key it was given. Some(Std::Entry) => args.types().next().is_some_and(|k| self.drops(k)), @@ -115,7 +117,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, _) if self.bound_drops(adt.did()).is_some() => true, ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { Some(Std::Waker) => true, - Some(Std::Arc | Std::Mutex | Std::Option | Std::Box | Std::Pin) => { + Some(Std::Arc | Std::Mutex | Std::Option | Std::Box | Std::Pin | Std::Reverse) => { self.disposable(args.type_at(0), span) } // An `rt.Iter` drops what it was given to. @@ -211,7 +213,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, _) if self.bound_drops(adt.did()).is_some() => true, ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { // Each is its contents in JS. - Some(Std::Option | Std::Box | Std::Mutex | Std::MutexGuard | Std::Poll | Std::Pin) => { + Some(Std::Option | Std::Box | Std::Mutex | Std::MutexGuard | Std::Poll | Std::Pin | Std::Reverse) => { args.types().all(|t| self.inert(t)) } // Its waker. @@ -257,7 +259,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { let (name, args) = match std { Std::Arc => ("arcDrop", vec![value, each(self, 0)?]), Std::Mutex => return self.drop_value(value.member("value"), args.type_at(0), span), - Std::Box | Std::Pin => return self.drop_value(value, args.type_at(0), span), + Std::Box | Std::Pin | Std::Reverse => return self.drop_value(value, args.type_at(0), span), Std::HashMap => ("hashDrop", vec![value, each(self, 0)?, each(self, 1)?]), Std::BTreeMap => ("btreeDrop", vec![value, each(self, 0)?, each(self, 1)?]), Std::HashSet => ("hashDrop", vec![value, each(self, 0)?]), @@ -383,7 +385,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did())? { Std::Vec => Some(args.type_at(0)), Std::Option if self.erases_to(args.type_at(0)).undefined => None, - Std::Option | Std::Box | Std::Pin => self.elements(args.type_at(0)), + Std::Option | Std::Box | Std::Pin | Std::Reverse => self.elements(args.type_at(0)), _ => None, }, _ => None, diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 3cbd5edd4..b90c4c693 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -274,7 +274,8 @@ pub fn std_impl<'tcx>( ty::Adt(adt, args) => match (Std::of(tcx, adt.did())?, tr) { (Std::String | Std::Cow, Trait::Display) if library::string(tcx, ty) => Expr::rt("fmtPad", vec![f, value]), (Std::String | Std::Cow, Trait::Debug) if library::string(tcx, ty) => rt("str", vec![value, f]), - (Std::Box, _) => b.fmt_call(tr, args.type_at(0), value, f, span), + // A `NonZero` writes its integer, by each trait. + (Std::Box | Std::NonZero, _) => b.fmt_call(tr, args.type_at(0), value, f, span), (Std::Vec, Trait::Debug) => { let item = b.fmt_fn(tr, args.type_at(0), span); rt("list", vec![library::elements(value, ty), f, item]) diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index a973f8ffc..c4e1ddd36 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -75,6 +75,14 @@ pub enum Std { RangeTo, RangeFrom, RangeFull, + /// `..=end`: `{ end, inclusive: true }`. + RangeToInclusive, + /// `rt.RangeBound`, tagged as the crate's own enums are: `{ tag: "Included", _0 }`. + Bound, + /// What it holds, which orders the other way. + Reverse, + /// Its integer, which is never 0. + NonZero, /// A `format_args!` argument: a function writing its value, `rt.Fmt`. Argument, /// Its pointee: what an async body passes its context in. @@ -150,6 +158,7 @@ impl Std { (rustc_attr_ir::LangItem::RangeTo, Self::RangeTo), (rustc_attr_ir::LangItem::RangeFrom, Self::RangeFrom), (rustc_attr_ir::LangItem::RangeFull, Self::RangeFull), + (rustc_attr_ir::LangItem::RangeToInclusive, Self::RangeToInclusive), ] { if tcx.is_lang_item(did, item) { return Some(std); @@ -180,6 +189,9 @@ impl Std { ["ptr", "non_null", "NonNull"] => Some(Self::NonNull), ["convert", "Infallible"] => Some(Self::Infallible), ["cmp", "Ordering"] => Some(Self::Ordering), + ["cmp", "Reverse"] => Some(Self::Reverse), + ["ops", "range", "Bound"] => Some(Self::Bound), + ["num", "nonzero", "NonZero"] => Some(Self::NonZero), ["hash", "random", "DefaultHasher"] => Some(Self::Hasher), ["collections", "hash", "map", "Entry" | "OccupiedEntry" | "VacantEntry"] | [ @@ -246,6 +258,45 @@ pub fn string<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } } +/// What a value of `ty` is in JS if `ty` wraps one value it is represented as: `Reverse`'s +/// and `NonZero`'s `T`, which differ only in their order and range, a pattern type's +/// base, and the field of each of core's `niche_types` structs that hold one. +pub fn wrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Pat(base, _) => Some(*base), + ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { + Some(Std::Reverse | Std::NonZero) => Some(args.type_at(0)), + Some(_) => None, + None => { + let path = std_path(tcx, adt.did()); + if !(path.len() == 3 && path[0] == "num" && path[1] == "niche_types" && adt.is_struct()) { + return None; + } + let field = adt.non_enum_variant().fields.iter().next()?; + Some(field.ty(tcx, args).skip_norm_wip()) + } + }, + _ => None, + } +} + +/// A `Bound` of type `ty`, an `rt.RangeBound`: its variant, by name, and the value it holds, if +/// any. +pub fn bound(variant: &str, value: Option, ty: crate::ts::Type) -> Expr { + let mut props = vec![(crate::ts::Key::Name("tag".into()), Expr::Str(variant.into()))]; + props.extend(value.map(|v| (crate::ts::Key::Name("_0".into()), v))); + Expr::As(Box::new(Expr::Object(props)), ty) +} + +/// `..end`, or `..=end` if `inclusive`: `{ end }`, or `{ end, inclusive: true }`. +pub fn range_to(end: Expr, inclusive: bool) -> Expr { + let mut props = vec![(crate::ts::Key::Name("end".into()), end)]; + if inclusive { + props.push((crate::ts::Key::Name("inclusive".into()), Expr::lit("true"))); + } + Expr::Object(props) +} + /// The refusal of code that tells a `Cow`'s variants apart. pub fn cow_variant(ty: Ty<'_>) -> String { format!("a variant of `{ty}`, which is not supported: either is the same JS string") @@ -468,6 +519,8 @@ fn discards(owner: &str, name: &str) -> Option<&'static [usize]> { // `unwrap` and `expect` drop the error they panic with, and `unwrap_err` the value. ("Result", "unwrap" | "expect") => &[1], ("Result", "unwrap_err") => &[0], + // `Vec` drops each element `retain` rejects and `dedup` removes. + ("Vec", "retain" | "retain_mut" | "dedup" | "dedup_by" | "dedup_by_key") => &[0], // `then_some::` drops its value when false, and `then::` its function. ("bool", "then_some") => &[0], ("bool", "then") => &[1], @@ -766,8 +819,12 @@ fn mapping<'tcx>( "checked_mul" => "checkedMul", "saturating_add" => "saturatingAdd", "saturating_sub" => "saturatingSub", + "saturating_mul" => "saturatingMul", "wrapping_add" => "wrappingAdd", "wrapping_sub" => "wrappingSub", + "wrapping_mul" => "wrappingMul", + "div_ceil" => "divCeil", + "is_multiple_of" => "isMultipleOf", _ => return None, }; return Some(int.method(method, args)); @@ -789,7 +846,8 @@ fn mapping<'tcx>( let e = match (owner.as_str(), name.as_str()) { // Conversions. ("From", "from") => { - let (to, from) = (targ(gargs, 0), targ(gargs, 1)); + // A `NonZero` converts as its integer. + let (to, from) = (targ(gargs, 0), unwrapped(tcx, targ(gargs, 1))); let mut values = args; let value = values.pop()?; // One between strings, such as into a `Cow` or out of one, keeps the text. @@ -854,7 +912,7 @@ fn mapping<'tcx>( ) } ("PartialEq", "eq" | "ne") | ("PartialOrd", "lt" | "le" | "gt" | "ge") - if primitive(targ(gargs, 0).peel_refs()) => + if primitive(unwrapped(tcx, targ(gargs, 0))) => { let js = match name.as_str() { "eq" => "===", @@ -866,18 +924,22 @@ fn mapping<'tcx>( }; let values = args; let [l, r] = <[Expr; 2]>::try_from(values).ok()?; - match Int::of(targ(gargs, 0).peel_refs()) { + match Int::of(unwrapped(tcx, targ(gargs, 0))) { Some(int) => int.compare(js, l, r), None => l.binary(js, r), } } - ("Ord", "max" | "min") if let Some(int) = Int::of(targ(gargs, 0)) => { + ("Ord", "max" | "min") if let Some(int) = Int::of(unwrapped(tcx, targ(gargs, 0))) => { let values = args; match int.big() { true => int.method(name.as_str(), values), false => Expr::rt(if name == "max" { "max" } else { "min" }, values), } } + ("Ord", "clamp") if let Some(int) = Int::of(targ(gargs, 0)) => match int.big() { + true => int.method("clamp", args), + false => Expr::rt("clamp", args), + }, ("Clone", "clone") => { let ty = targ(gargs, 0); let values = args; @@ -887,6 +949,18 @@ fn mapping<'tcx>( Expr::rt("byteVecFrom", vec![Expr::rt("byteVecView", vec![value])]) } ty::Adt(..) if string(tcx, ty) => value, + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Vec) => { + return vec_clone(b, value, args.type_at(0), span); + } + ty::Tuple(tys) if !(b.t.is_copy(ty) && clone_copies(b.t, ty)) => { + let mut clones = Vec::new(); + let mut drops = Vec::new(); + for t in tys.iter() { + clones.push(super::collections::clone_fn(b, t, span)); + drops.push(b.t.drop_fn(t, span).unwrap_or_else(Expr::undefined)); + } + Expr::rt("tupleClone", vec![value, Expr::Array(clones), Expr::Array(drops)]) + } // Through the reference, a slice of the bytes. _ if super::byte_array(ty) => Expr::rt("byteSliceToArray", vec![value]), ty::Adt(adt, _) if int_range(ty) => { @@ -942,6 +1016,50 @@ fn mapping<'tcx>( Expr::rt_of(of, &super::camel(&name)).call(args) } + // A `NonZero` is its integer. + ("NonZero", "get") => args.pop()?, + ("NonZero", "new") => Expr::rt("nonZero", args), + // `Bound<&T>::cloned::`: what it holds, cloned. + ("Bound", "cloned") => { + let value = args.pop()?; + let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); + let bound = tcx.instantiate_bound_regions_with_erased(sig).output(); + match super::collections::clone_fn(b, targ(gargs, 0), span) { + Expr::Lit(l) if l == "undefined" => b.t.copied(value, bound, span), + clone => Expr::rt("boundMap", vec![value, clone]), + } + } + ("Bound", "as_ref") => args.pop()?, + ("RangeBounds", "start_bound" | "end_bound") => { + let start = name == "start_bound"; + let range = targ(gargs, 0).peel_refs(); + let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); + let ts = b.t.ty(tcx.instantiate_bound_regions_with_erased(sig).output(), span); + let r = args.pop()?; + let (variant, field) = match (range.kind(), b.t.std_of(range)) { + // `(Bound, Bound)`, whose bounds are its own. + (ty::Tuple(_), _) => return Some(r.index(Expr::lit(if start { "0" } else { "1" }))), + (_, Some(Std::Range)) if start => ("Included", Some("start")), + (_, Some(Std::Range)) => ("Excluded", Some("end")), + (_, Some(Std::RangeFrom)) if start => ("Included", Some("start")), + (_, Some(Std::RangeTo)) if !start => ("Excluded", Some("end")), + (_, Some(Std::RangeToInclusive)) if !start => ("Included", Some("end")), + (_, Some(Std::RangeFrom | Std::RangeTo | Std::RangeToInclusive | Std::RangeFull)) => { + ("Unbounded", None) + } + // Exhausted, it ends before its end. + (_, Some(Std::RangeInclusive)) => { + let f = if start { + "rangeInclusiveStartBound" + } else { + "rangeInclusiveEndBound" + }; + return Some(Expr::As(Box::new(Expr::rt(f, vec![r])), ts)); + } + _ => return None, + }; + bound(variant, field.map(|f| r.member(f)), ts) + } ("bool", "then_some") => { let values = args; Expr::rt("thenSome", values) @@ -975,17 +1093,58 @@ fn mapping<'tcx>( } ("slice", "to_vec") => { let elem = targ(gargs, 0); - let values = args; + let slice = args.pop()?; + match is_u8(elem) { + true => Expr::rt("byteSliceToByteVec", vec![slice]), + false => return vec_clone(b, slice, elem, span), + } + } + ("slice", "first_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceFirst", args), + ("slice", "last" | "last_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceLast", args), + ("slice", "reverse") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceReverse", args), + ("slice", "swap") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceSwap", args), + ("slice", "contains") => { + let elem = targ(gargs, 0); + let [s, x] = <[Expr; 2]>::try_from(args).ok()?; match is_u8(elem) { - true => Expr::rt("byteSliceToByteVec", values), - false if b.t.is_copy(elem) => { - let slice = values.into_iter().next()?; - match b.t.copy_fn(elem, span) { - Some(copy) => slice.member("map").call(vec![copy]), - None => slice.member("slice").call(Vec::new()), + true => Expr::rt("byteSliceView", vec![s]).method("includes", vec![x]), + false => { + let eq = super::collections::eq_fn(b, elem, span); + Expr::rt("sliceContains", vec![s, x, eq]) + } + } + } + // Sorted by `lt` of `Ord`, or by a comparator, or by `lt` of the keys a function makes. + ( + "slice", + "sort" | "sort_unstable" | "sort_by" | "sort_unstable_by" | "sort_by_key" | "sort_unstable_by_key", + ) if !is_u8(targ(gargs, 0)) => { + let mut values = args; + match name.as_str() { + // By `<`, which is `partial_cmp`'s while it is the default. + "sort" | "sort_unstable" => { + let elem = targ(gargs, 0); + if super::collections::own_test(b, elem, "lt") { + return Some(b.err(span, super::collections::own_test_err(elem, "lt"))); } + values.push(super::collections::cmp_fn(b, elem, true, span)); + Expr::rt("sliceSortBy", values) + } + "sort_by" | "sort_unstable_by" => Expr::rt("sliceSortBy", values), + _ => { + let key = targ(gargs, 1); + if b.t.drops(key) { + return Some(b.err( + span, + format!("`slice::{name}` by `{key}`, which drops, which is not supported yet"), + )); + } + if super::collections::own_test(b, key, "lt") { + return Some(b.err(span, super::collections::own_test_err(key, "lt"))); + } + values.push(super::collections::cmp_fn(b, key, true, span)); + Expr::rt("sliceSortByKey", values) } - false => return None, } } // A boxed slice's elements, and `vec![a, b]`'s array once `mir::vec` took the box @@ -1054,6 +1213,45 @@ fn mapping<'tcx>( ("Vec", "truncate") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecTruncate", args), ("Vec", "clear") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecClear", args), ("Vec", "extend_from_slice") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecExtendFromSlice", args), + ("Vec", "extend_from_slice") => { + let mut values = args; + let clone = super::collections::clone_fn(b, targ(gargs, 0), span); + if !matches!(&clone, Expr::Lit(l) if l == "undefined") { + values.push(clone); + } + Expr::rt("vecExtendFromSlice", values) + } + ("Vec", "swap_remove") if !is_u8(targ(gargs, 0)) => Expr::rt("vecSwapRemove", args), + // What each takes by value is a closure, which it drops once done. + ("Vec", "retain" | "retain_mut" | "dedup" | "dedup_by" | "dedup_by_key") if !is_u8(targ(gargs, 0)) => { + if let Some(ty) = dropping_operand(b, call) { + return Some(b.err( + span, + format!("passing `{ty}`, which drops, to `{owner}::{name}`, which is not supported yet"), + )); + } + let mut values = args; + match name.as_str() { + "retain" | "retain_mut" => Expr::rt("vecRetain", values), + "dedup" => { + values.push(super::collections::eq_fn(b, targ(gargs, 0), span)); + Expr::rt("vecDedupBy", values) + } + "dedup_by" => Expr::rt("vecDedupBy", values), + _ => { + // `Vec::dedup_by_key::`. + let key = targ(gargs, 3); + if b.t.drops(key) { + return Some(b.err( + span, + format!("`Vec::{name}` by `{key}`, which drops, which is not supported yet"), + )); + } + values.push(super::collections::eq_fn(b, key, span)); + Expr::rt("vecDedupByKey", values) + } + } + } ("Vec", "as_slice" | "as_mut_slice") => { let v = args.pop()?; vec_view(v, targ(gargs, 0)) @@ -1080,8 +1278,10 @@ fn mapping<'tcx>( ("String", "new") => Expr::Str(String::new()), ("String" | "str", "is_empty") => args.pop()?.member("length").binary("===", Expr::lit("0")), ("str", "chars") => Expr::rt("strChars", args), + ("str", "bytes") => Expr::rt("strBytes", args), + ("str", "is_char_boundary") => Expr::rt("strIsCharBoundary", args), // Searches by a pattern. - ("str", "split" | "match_indices" | "contains" | "starts_with" | "rfind") + ("str", "split" | "match_indices" | "contains" | "starts_with" | "ends_with" | "rfind" | "split_once") | ("str", "trim_start_matches" | "trim_end_matches") => { let [s, p] = <[Expr; 2]>::try_from(args).ok()?; Expr::rt_of("str", &super::camel(&name)).call(vec![s, pattern(b.t, targ(gargs, 0), p)?]) @@ -1284,13 +1484,35 @@ fn owned<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, ty: Ty<'tcx>, span: Span } } -/// A `str` method's pattern as the runtime takes it, an `rt.Pattern`: a `char`'s text, -/// or a string or a predicate as it is. `None` for any other pattern. +/// A clone of `value`, a slice, array, or `Vec` of `elem` other than bytes, as a `Vec`: a +/// copy of the array if each element's clone is itself or a copy, or else each element +/// cloned, the clones dropping if one panics. +fn vec_clone<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, elem: Ty<'tcx>, span: Span) -> Option { + let clone = super::collections::clone_fn(b, elem, span); + if matches!(&clone, Expr::Lit(l) if l == "undefined") { + return Some(value.method("slice", Vec::new())); + } + if b.t.is_copy(elem) && clone_copies(b.t, elem) { + return Some(value.method("map", vec![clone])); + } + let mut values = vec![value, clone]; + values.extend(b.t.drop_fn(elem, span)); + Some(Expr::rt("vecClone", values)) +} + +/// A `str` method's pattern as the runtime takes it, an `rt.Pattern`: a `char`'s text, a +/// string or a predicate as it is, or a predicate for an array or slice of chars. `None` +/// for any other pattern. fn pattern<'tcx>(t: &Translator<'_, 'tcx>, ty: Ty<'tcx>, p: Expr) -> Option { match ty.kind() { ty::Char => Some(char_text(p)), ty::Closure(..) | ty::FnDef(..) => Some(p), ty::Ref(..) if is_text(t, ty) => Some(p), + // Any of the chars of an array or slice. + ty::Array(c, _) | ty::Slice(c) if c.is_char() => Some(Expr::rt("patternChars", vec![p])), + ty::Ref(_, inner, _) if matches!(inner.kind(), ty::Array(c, _) | ty::Slice(c) if c.is_char()) => { + Some(Expr::rt("patternChars", vec![p])) + } _ => None, } } @@ -1344,6 +1566,15 @@ fn int_named(name: &str) -> Option { Some(Int { bits, signed, pointer }) } +/// What a JS value of `ty` is through references and `NonZero`, which is its integer. +fn unwrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + let ty = ty.peel_refs(); + match ty.kind() { + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::NonZero) => args.type_at(0), + _ => ty, + } +} + fn primitive(ty: Ty<'_>) -> bool { matches!(ty.kind(), ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Char) } diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 3551e99f2..d43537683 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -408,10 +408,19 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let done = |e: Expr, effect: bool| Some(Some((e, effect))); match (owner.as_str(), name.as_str()) { // Replacing what a `&mut` borrows. + // What `Default::default` makes, a std type's or the crate's, before the swap. ("mem", "take") => { + let ty = targ(0)?; let place = self.borrowed_place(&args[0].node, span, out)?; - let default = library::default_value(self.b, targ(0)?)?; - done(self.swap_out(place, targ(0)?, default, "taken", span, out), true) + let default = match library::default_value(self.b, ty) { + Some(default) => default, + None => { + let f = crate::lower::collections::trait_fn(tcx, "Default", "default"); + let default = self.b.call_def(f, tcx.mk_args(&[ty.into()]), Vec::new(), span, out); + self.path(default, "default", out) + } + }; + done(self.swap_out(place, ty, default, "taken", span, out), true) } ("mem", "replace") => { let place = self.borrowed_place(&args[0].node, span, out)?; diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 80191db6e..26d931223 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -453,7 +453,20 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } ty::Adt(adt, _) => match Std::of(tcx, adt.did()) { - Some(Std::Option | Std::Poll | Std::Box | Std::Pin) => base, + Some(Std::Option | Std::Poll | Std::Box | Std::Pin | Std::Reverse | Std::NonZero) => base, + // Cast to its variant, which a test narrows only where it reads the field. + Some(Std::Bound) => { + let ty::Adt(_, args) = ty.kind() else { unreachable!() }; + let variant = variant.unwrap_or(rustc_abi::FIRST_VARIANT); + let fields = vec![ + ( + "tag".to_string(), + crate::ts::Type::StrLit(adt.variant(variant).name.to_string()), + ), + ("_0".to_string(), self.b.t.ty(args.type_at(0), span)), + ]; + Expr::As(Box::new(base), crate::ts::Type::Object(fields)).member("_0") + } // A variant MIR reads without a test, since the other can't be, is cast to it. Some(Std::Result) => { let ok = variant.map_or(0, VariantIdx::index) == 0; @@ -480,13 +493,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }; base.member(name) } - Some(Std::Range | Std::RangeInclusive) => { + Some(Std::Range | Std::RangeInclusive | Std::RangeTo | Std::RangeFrom | Std::RangeToInclusive) => { base.member(adt.non_enum_variant().fields[field].name.as_str()) } Some(Std::Context | Std::NonNull | Std::Entry) => base, Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(Std::ControlFlow) => super::call::control_flow_field(self, base, ty, variant), - _ if transparent(self.b.t, ty) => base, + _ if transparent(self.b.t, ty) || crate::lower::library::wrapped(tcx, ty).is_some() => base, None if self.b.t.own(adt.did()) => { let info = self.b.t.adt(*adt, span); match info.repr { @@ -895,6 +908,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Some(Std::Ordering) => scrut .clone() .binary("===", crate::lower::collections::ordering_variant(index)), + Some(Std::Bound) => scrut + .clone() + .member("tag") + .binary("===", Expr::Str(adt.variant(index).name.to_string())), _ => self.err(span, format!("a switch on `{ty}`")), } } diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index e90f57a0c..cafd7a457 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -230,6 +230,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }, // An async body's context passes through `ResumeTy` and `NonNull`. CastKind::Transmute if context_like(self, from) && context_like(self, to) => self.operand(op, span, out), + // A pattern type, as `NonZero` holds, is its base type's value. + CastKind::Transmute if peel_pat(from) == peel_pat(to) => self.operand(op, span, out), _ => self.err(span, format!("a `{kind:?}` cast from `{from}` to `{to}`")), } } @@ -263,6 +265,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { // The value is its discriminant. Some(Std::Ordering) => scrut, Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), + Some(Std::Bound) => { + let table = discrs + .iter() + .map(|(i, d)| (Key::Name(adt.variant(*i).name.to_string()), int.lit(*d as i128))) + .collect(); + Expr::Index(Box::new(Expr::Object(table)), Box::new(scrut.member("tag"))) + } None if self.b.t.own(adt.did()) => { let info = self.b.t.adt(*adt, span); let table = discrs @@ -436,7 +445,14 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::FmtError, _) => Expr::New(Box::new(Expr::Rt("FmtError".into())), Vec::new()), // `ResumeTy`, an async body's context. (Std::Context, _) => values.pop().unwrap_or_else(Expr::undefined), - (Std::RangeTo, _) => Expr::Object(vec![(Key::Name("end".into()), values.pop().unwrap())]), + (Std::RangeTo | Std::RangeToInclusive, _) => { + crate::lower::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) + } + (Std::Reverse, _) => values.pop().unwrap(), + (Std::Bound, _) => { + let ts_ty = self.b.t.ty(ty, span); + crate::lower::library::bound(def.name.as_str(), values.pop(), ts_ty) + } (Std::RangeFrom, _) => Expr::Object(vec![(Key::Name("start".into()), values.pop().unwrap())]), (Std::RangeFull, _) => Expr::undefined(), (Std::Ordering, _) => crate::lower::collections::ordering_variant(variant), @@ -460,7 +476,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { _ => self.err(span, format!("constructing `{ty}`")), }; } - if super::place::transparent(self.b.t, ty) { + if super::place::transparent(self.b.t, ty) || crate::lower::library::wrapped(tcx, ty).is_some() { return values.pop().unwrap_or_else(Expr::undefined); } match crate::lower::library::std_path(tcx, def_id) @@ -672,3 +688,11 @@ pub fn memory<'tcx>(rvalue: &Rvalue<'tcx>, fx: &Fx<'_, '_, '_, 'tcx>) -> bool { Rvalue::ThreadLocalRef(_) | Rvalue::WrapUnsafeBinder(..) | Rvalue::Reborrow(..) => true, } } + +/// A pattern type's base, or `ty` itself. +fn peel_pat(ty: Ty<'_>) -> Ty<'_> { + match ty.kind() { + ty::Pat(base, _) => *base, + _ => ty, + } +} diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 3980fe5f9..cd581f010 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -934,6 +934,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Uint(ty::UintTy::U8) => Some(ObjectKind::Bytes), _ => Some(ObjectKind::Array), }, + // A JS array, whose elements change in place as an array's do. + ty::Tuple(tys) if !tys.is_empty() => Some(ObjectKind::Array), // A binding's value: an object, unless Rust copies it, which JS can't. ty::Adt(adt, _) if self.bound_drops(adt.did()).is_some() => { (!self.is_copy(ty)).then_some(ObjectKind::Class) @@ -1059,6 +1061,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { self.fn_ty(&inputs, sig.output(), span) } ty::Adt(adt, args) => self.adt_ty(*adt, args, span), + ty::Pat(base, _) => self.ty(*base, span), ty::Coroutine(_, args) => Type::Rt("Future", vec![self.ty(args.as_coroutine().return_ty(), span)]), // `&dyn Debug` and `&dyn Display` are values ready to write. ty::Dynamic(preds, ..) @@ -1188,7 +1191,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { self.unrepresented(span, format!("`{}` is not supported yet", Ty::new_adt(tcx, adt, args))); Type::Builtin("unknown") } - library::Std::Box => self.ty(args.type_at(0), span), + library::Std::Box | library::Std::Reverse | library::Std::NonZero => self.ty(args.type_at(0), span), + library::Std::Bound => Type::Rt("RangeBound", vec![self.ty(args.type_at(0), span)]), library::Std::FromUtf8Error => Type::Rt("FromUtf8Error", vec![]), library::Std::TryFromIntError => Type::Rt("TryFromIntError", vec![]), library::Std::Formatter => Type::Rt("Formatter", vec![]), @@ -1218,6 +1222,10 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { library::Std::Range => Type::Rt("Range", vec![self.ty(args.type_at(0), span)]), library::Std::RangeInclusive => Type::Rt("RangeInclusive", vec![self.ty(args.type_at(0), span)]), library::Std::RangeTo => Type::Object(vec![("end".into(), self.ty(args.type_at(0), span))]), + library::Std::RangeToInclusive => Type::Object(vec![ + ("end".into(), self.ty(args.type_at(0), span)), + ("inclusive".into(), Type::Builtin("true")), + ]), library::Std::RangeFrom => Type::Object(vec![("start".into(), self.ty(args.type_at(0), span))]), library::Std::RangeFull => Type::Builtin("undefined"), library::Std::Argument => Type::Rt("Fmt", vec![]), @@ -1266,6 +1274,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } }; } + if let Some(inner) = library::wrapped(tcx, Ty::new_adt(tcx, adt, args)) { + return self.ty(inner, span); + } // Every other iterator std has is an `rt.Iter` of its items. if !adt.did().is_local() && let Some(item) = self.iter_item(Ty::new_adt(tcx, adt, args)) @@ -1371,7 +1382,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Ref(..) if self.place_pointee(ty).is_some() => Erased::default(), ty::Ref(_, inner, _) => self.erases_to(*inner), ty::Adt(adt, args) => match library::Std::of(self.tcx, adt.did()) { - Some(library::Std::Box | library::Std::Pin) => self.erases_to(args.type_at(0)), + Some(library::Std::Box | library::Std::Pin | library::Std::Reverse | library::Std::NonZero) => { + self.erases_to(args.type_at(0)) + } Some(library::Std::Option) => self.erases_to(args.type_at(0)).option(), Some(library::Std::Poll) => Erased { pending: true, diff --git a/ts/src/ts.rs b/ts/src/ts.rs index 47e472aa4..5fbbf783b 100644 --- a/ts/src/ts.rs +++ b/ts/src/ts.rs @@ -138,8 +138,15 @@ impl Expr { /// This without an outer `as`, where the context already gives the type. pub fn typed(self) -> Self { match self { - // Limbs keep theirs, which the brand of their type requires. - Self::As(e, ty) if matches!(*e, Self::Str(_) | Self::Array(_) | Self::Object(_)) && !wide(&ty) => *e, + // Limbs keep theirs, which the brand of their type requires, and an `rt.RangeBound` its + // own, without which a declaration narrows to the one variant it is made as. + Self::As(e, ty) + if matches!(*e, Self::Str(_) | Self::Array(_) | Self::Object(_)) + && !wide(&ty) + && !matches!(ty, Type::Rt("RangeBound", _)) => + { + *e + } Self::Located(loc, e) => Self::Located(loc, Box::new(e.typed())), // `rt.Ok(v)` and `rt.Err(e)` infer their type from the context too. Self::Call(f, args) if matches!(&*f, Self::Rt(name) if name == "Ok" || name == "Err") => { diff --git a/ts/tests/differential.ts b/ts/tests/differential.ts index b7c12d6ab..00631a4d6 100644 --- a/ts/tests/differential.ts +++ b/ts/tests/differential.ts @@ -132,23 +132,27 @@ if (wideArg === "wide") { const u = i % 3 === 0 ? x : values[(i * 7) % values.length]; const v = values[(i * 13 + 5) % values.length]; const shift = shifts[i++ % shifts.length]; - for (let kind = 0; kind < 25; kind++) { + for (let kind = 0; kind < 30; kind++) { for (const op of [3, 9]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), shift)); for (const op of [4, 10]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), ...be(u), ...be(v), shift)); } + // `clamp` between two values of the sweep, whose third operand follows the shift's place. + for (const op of [3, 9]) cases.push(Uint8Array.of(op, 26, ...be(x), ...be(y), ...be(u))); + for (const op of [4, 10]) cases.push(Uint8Array.of(op, 26, ...be(x), ...be(y), ...be(u), ...be(v), ...be(y), ...be(x))); // Negating an `i64` and an `i128`. cases.push(Uint8Array.of(12, 3, ...be(x)), Uint8Array.of(12, 4, ...be(x), ...be(y))); - // `x * y` and `x.checked_mul(y)` at 128 bits, extended in each type's sign: a product - // of two numbers, past 2^53, multiplies their halves. + // `x * y`, `checked_mul`, `saturating_mul`, and `wrapping_mul` at 128 bits, extended in + // each type's sign: a product of two numbers, past 2^53, multiplies their halves. const signs = (v: bigint) => (v >> 63n === 1n ? 0xffffffffffffffffn : 0n); - for (const kind of [2, 13]) { + for (const kind of [2, 13, 24, 25]) { cases.push(Uint8Array.of(4, kind, ...be(0n), ...be(x), ...be(0n), ...be(y))); cases.push(Uint8Array.of(10, kind, ...be(signs(x)), ...be(x), ...be(signs(y)), ...be(y))); } - // `x:y / d` and `x:y % d` at 128 bits by a divisor below 2^32 in magnitude, which - // divides limbs by a number, extended in each type's sign: -1 overflows `i128::MIN`. + // `x:y / d`, `x:y % d`, `div_ceil`, and `is_multiple_of` at 128 bits by a divisor + // below 2^32 in magnitude, which divides limbs by a number, extended in each type's + // sign: -1 overflows `i128::MIN`. for (const d of [3n, 1_000_000n, 0xffffffffn, -1n, -0xffffffffn]) { - for (const kind of [3, 4]) { + for (const kind of [3, 4, 27, 28]) { for (const op of [4, 10]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), ...be(signs(d & 0xffffffffffffffffn)), ...be(d & 0xffffffffffffffffn))); } } diff --git a/ts/tests/fixtures.rs b/ts/tests/fixtures.rs index e535faa9e..2b24929ae 100644 --- a/ts/tests/fixtures.rs +++ b/ts/tests/fixtures.rs @@ -257,10 +257,10 @@ fn shake(out: &Path) { "Panic", "byteSliceFrom", "checked", - "clamp", "idx", "max", "panic", + "saturate", "u32SaturatingAdd", "u32Sub", "usizeSaturatingAdd", diff --git a/ts/tests/retain.ts b/ts/tests/retain.ts index e8f8179ff..6724439c6 100644 --- a/ts/tests/retain.ts +++ b/ts/tests/retain.ts @@ -35,9 +35,45 @@ for (let n = 0; n <= 6; n++) { for (let i = n >> 1; i < n; i++) rt.dequePushBack(deque, i); caught(() => rt.dequeRetain(deque, keep)); + const vec = [...Array(n).keys()]; + const dropped: number[] = []; + caught(() => rt.vecRetain(vec, keep, (i) => dropped.push(i))); + + // A run ends at each item the mask clears, and `same` panics comparing `p`. + const runs: [number, number][] = []; + for (let i = 0, run = 0; i < n; i++) runs.push([i, ((mask >> i) & 1) === 1 ? run : ++run]); + const deduped: number[] = []; + caught(() => + rt.vecDedupBy( + runs, + (a, b) => { + if (a[0] === p) throw new Thrown(); + return a[1] === b[1]; + }, + (r) => deduped.push(r[0]), + ), + ); + const entries = rt.iterToArray(rt.btreeIter(tree)); const items = rt.iterToArray(rt.dequeIter(deque)); - console.log(`${n} ${mask} ${p} btree ${entries.join(";")} deque ${items.join(",")}`); + const ran = runs.map((r) => r[0]); + console.log( + `${n} ${mask} ${p} btree ${entries.join(";")} deque ${items.join(",")} vec ${vec.join(",")} dropped ${dropped.join(",")} dedup ${ran.join(",")} dropped ${deduped.join(",")}`, + ); + + // A sort whose comparator panics at its `2p`th call leaves each item once. + const sorted = [...Array(n).keys()].map((i) => (i * 5 + mask) % 7); + let calls = 0; + caught(() => + rt.sliceSortBy(sorted, (a, b) => { + if (calls++ === p * 2) throw new Thrown(); + return rt.cmp(a, b); + }), + ); + const unsorted = [...Array(n).keys()].map((i) => (i * 5 + mask) % 7); + if (sorted.slice().sort().join() !== unsorted.sort().join()) { + throw new Error(`sort of ${n} by ${mask} panicking at ${p}: ${sorted}`); + } // Keys that collide by twos, so `retain` unlinks within chains. type Key = { k: number }; @@ -67,3 +103,56 @@ for (let n = 0; n <= 6; n++) { } } } + +// Past one insertion-sorted run, so a comparator panics in merges too, at each of its calls. +for (const n of [17, 40, 70]) { + const unsorted = [...Array(n).keys()].map((i) => ((n - i) * 7) % 31); + const want = unsorted.slice().sort().join(); + for (let p = 0, thrown = true; thrown; p++) { + const sorted = unsorted.slice(); + let calls = 0; + thrown = false; + try { + rt.sliceSortBy(sorted, (a, b) => { + if (calls++ === p) throw new Thrown(); + return rt.cmp(a, b); + }); + } catch (err) { + if (!(err instanceof Thrown)) throw err; + thrown = true; + } + if (sorted.slice().sort().join() !== want) throw new Error(`sort of ${n} panicking at ${p}: ${sorted}`); + } +} + +// `split_off` whose key order panics at each of its calls leaves the map whole, as std's +// compares before it moves an entry. Past one leaf, so it splits branches too. +for (const n of [6, 70, 200]) { + for (const at of [0, n >> 1, n]) { + for (let p = 0, thrown = true; thrown; p++) { + let calls = -1; + const tree = rt.btreeNew((a, b) => { + if (calls >= 0 && calls++ === p) throw new Thrown(); + return rt.cmp(a, b); + }); + for (let i = 0; i < n; i++) rt.btreeInsert(tree, i, i); + calls = 0; + thrown = false; + let above: rt.BTreeMap | undefined; + try { + above = rt.btreeSplitOff(tree, at); + } catch (err) { + if (!(err instanceof Thrown)) throw err; + thrown = true; + } + calls = -1; + const kept = rt.iterToArray(rt.btreeKeys(tree)).join(); + const moved = above === undefined ? "" : rt.iterToArray(rt.btreeKeys(above)).join(); + const all = [...Array(n).keys()]; + const want = thrown ? [all.join(), ""] : [all.slice(0, at).join(), all.slice(at).join()]; + if (kept !== want[0] || moved !== want[1] || rt.btreeLen(tree) !== (thrown ? n : at)) { + throw new Error(`split_off of ${n} at ${at} panicking at ${p}: ${kept} | ${moved}`); + } + } + } +} diff --git a/ts/tests/runtime.rs b/ts/tests/runtime.rs index c79761277..3f066eb32 100644 --- a/ts/tests/runtime.rs +++ b/ts/tests/runtime.rs @@ -117,8 +117,18 @@ fn btree_script() { assert_eq!(got.lines().count(), want.len()); } -/// A `retain` whose predicate panics leaves a B-tree and a deque as std's do, which -/// `retain.ts` prints for every keep mask of up to 6 items and each item to panic on. +/// A value that logs itself when it drops. +struct Logged<'a, T: Copy>(T, &'a std::cell::RefCell>); + +impl Drop for Logged<'_, T> { + fn drop(&mut self) { + self.1.borrow_mut().push(self.0); + } +} + +/// A `retain` whose predicate panics leaves a B-tree, a deque, and a `Vec` as std's do, +/// and a `dedup_by` whose test panics leaves a `Vec`, each dropping what std's drops, +/// which `retain.ts` prints for every keep mask of up to 6 items and each item to panic on. #[test] fn retain_unwinds() { use std::collections::{BTreeMap, VecDeque}; @@ -152,9 +162,45 @@ fn retain_unwinds() { } deque.extend(n / 2..n); let _ = catch_unwind(AssertUnwindSafe(|| deque.retain(|&i| keep(i)))); + let dropped = std::cell::RefCell::new(Vec::new()); + let mut vec: Vec> = (0..n).map(|i| Logged(i, &dropped)).collect(); + let _ = catch_unwind(AssertUnwindSafe(|| vec.retain(|i| keep(i.0)))); + let vec: Vec = vec.iter().map(|i| i.0).collect(); + let dropped = std::mem::take(&mut *dropped.borrow_mut()); + // A run ends at each item the mask clears, and `same` panics comparing `p`. + let deduped = std::cell::RefCell::new(Vec::new()); + let mut run = 0; + let mut runs: Vec> = (0..n) + .map(|i| { + if (mask >> i) & 1 == 0 { + run += 1; + } + Logged((i, run), &deduped) + }) + .collect(); + let _ = catch_unwind(AssertUnwindSafe(|| { + runs.dedup_by(|a, b| { + assert!(a.0.0 != p); + a.0.1 == b.0.1 + }) + })); + let ran: Vec = runs.iter().map(|r| r.0.0).collect(); + let deduped: Vec = std::mem::take(&mut *deduped.borrow_mut()) + .into_iter() + .map(|r| r.0) + .collect(); let entries: Vec = tree.iter().map(|(k, v)| format!("{k},{v}")).collect(); let items: Vec = deque.iter().map(u32::to_string).collect(); - want += &format!("{n} {mask} {p} btree {} deque {}\n", entries.join(";"), items.join(",")); + let join = |v: &[u32]| v.iter().map(u32::to_string).collect::>().join(","); + want += &format!( + "{n} {mask} {p} btree {} deque {} vec {} dropped {} dedup {} dropped {}\n", + entries.join(";"), + items.join(","), + join(&vec), + join(&dropped), + join(&ran), + join(&deduped), + ); } } } diff --git a/ts/tests/task.ts b/ts/tests/task.ts index d8c6a2e62..76fce1de5 100644 --- a/ts/tests/task.ts +++ b/ts/tests/task.ts @@ -46,7 +46,11 @@ export interface Fixture { sum(rx: Consumer, guard: Guard): Future; drain(rx: Consumer, depth: number): Future; blocks(rx: Consumer, guard: Guard, moves: boolean): Future; - drops: { run(log: Log, id: number, arg: number): void; held(rx: Consumer, guard: Guard): Future }; + drops: { + run(log: Log, id: number, arg: number): void; + held(rx: Consumer, guard: Guard): Future; + edited(log: Log, id: number, at: number): void; + }; } /** What every waker of one task points at. */ @@ -197,7 +201,7 @@ export function harness(f: Fixture, unwind = false): (input: Uint8Array) = function step(op: number, arg: number): void { const pick = (len: number) => (len > 0 ? arg % len : undefined); const c = pick(channels.length); - switch (op % 13) { + switch (op % 14) { case 0: note(`c${channels.length} open`); channels.push(f.Channel.open()); @@ -250,8 +254,11 @@ export function harness(f: Fixture, unwind = false): (input: Uint8Array) = case 11: f.drops.run(log, 1000 * exec.tasks.length, arg); break; - default: + case 12: if (c !== undefined) exec.spawn(f.drops.held(f.Channel.consumer(channels[c]), f.Guard.new(exec.tasks.length, f.Log.clone$Clone(log)))); + break; + default: + f.drops.edited(log, 1000 * exec.tasks.length, arg % 8); } } }; @@ -282,4 +289,6 @@ export const cases: Uint8Array[] = [ [0, 0, 12, 0, 12, 1, 6, 0, 9, 1, 9, 0], // Each scenario of values std holds that drop, panicking at each point or none. ...Array.from({ length: 253 }, (_, arg) => [11, arg]), + // Each of a `Vec`'s edits, its and a tuple's `clone`, and `Ord`'s defaults, panicking at each point or none. + ...Array.from({ length: 8 }, (_, at) => [13, at]), ].map((script) => Uint8Array.from(script)); diff --git a/ts/tests/unwind.ts b/ts/tests/unwind.ts index 390580902..9f2fbc761 100644 --- a/ts/tests/unwind.ts +++ b/ts/tests/unwind.ts @@ -31,7 +31,7 @@ for (let i = 0; i < count; i++) { const steps = 4 + (next() % 20); const script = new Uint8Array(steps * 2); for (let s = 0; s < steps; s++) { - script[2 * s] = next() % 13; + script[2 * s] = next() % 14; // A send of 99 panics the `sum` reading it. script[2 * s + 1] = next() % 4 === 0 ? 99 : next() % 256; }