diff --git a/quest/m3/README.md b/quest/m3/README.md index 5640871a9..c8bf71a1d 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -28,7 +28,6 @@ generic std gap is planned here even when moq never calls it. - [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does - [A deque's two slices](/quest/m3/ts-deque-slices.md) - `VecDeque::as_slices` and `{:?}` of a deque's `Iter`, `IterMut`, and `Drain` translate, split where std's are -- [Cow of a slice, and Wrapping](/quest/m3/ts-cow-slices.md) - `Cow<[T]>` and `Wrapping` translate, `PartialEq` included - [LinkedList](/quest/m3/ts-linked-list.md) - `LinkedList` and its methods translate - [Zip's next_back in constant time](/quest/m3/ts-zip-back.md) - a reversed zip of random-access iterators skips the longer side's excess at once - [Debug of Bound](/quest/m3/ts-bound-debug.md) - `{:?}` of a `Bound`, as a range's `start_bound` gives, translates diff --git a/quest/m3/ts-cow-slices.md b/quest/m3/ts-cow-slices.md deleted file mode 100644 index 43de1a9a9..000000000 --- a/quest/m3/ts-cow-slices.md +++ /dev/null @@ -1,14 +0,0 @@ -# [M] Cow of a slice, and Wrapping - -## Goal - -[rust2-ts](/ts/README.md) translates `Cow<[T]>` and `Wrapping` and their std impls, -`PartialEq` included, proven by differential tests against native Rust. - -## Plan - -Found auditing std's `PartialEq` impls that forward `ne`: constructing a `Cow<[T]>` -refuses, as `Cow` does not, and any `Wrapping` refuses as an unsupported type from -another crate. No consumer uses either yet; they are planned here as part of std. A -`Cow`'s and a `Wrapping`'s `ne` are `!eq`, though a `Cow<[T]>`'s `eq` still calls each -item's `ne`. diff --git a/ts/README.md b/ts/README.md index 4c5ed325b..89c520ac4 100644 --- a/ts/README.md +++ b/ts/README.md @@ -81,6 +81,7 @@ crate translation reaches is refused, and so are two versions of one crate it re | `char` | `rt.char`: a `number` branded so, its Unicode scalar value | | `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics | | `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way | +| `Wrapping` | the integer, whose operators wrap, and mask a shift's amount to the width, as std's do | | `f64` | `rt.f64`: a `number` branded so, which is the same IEEE 754 double | | `f32` | `rt.f32`: a `number` branded so, which a single holds exactly | | `()`, `PhantomData`, `PhantomPinned`, `..` | `undefined`, every value equal and hashing nothing; a type parameter only a `PhantomData` holds is `_T` in its struct's interface | @@ -91,6 +92,7 @@ crate translation reaches is refused, and so are two versions of one crate it re | `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, but for a `Poll`'s `Pending` and `Ready(None)`, which continue as `Ok` of themselves | | 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` | +| `Cow<[T]>` | `rt.Cow`: the `Vec` it owns, or an `rt.Borrowed` holding the slice it borrows; `rt.ByteCow` for bytes, an `rt.ByteVec` or an `rt.ByteSlice` | | `&T`, `&mut T`, `Box`, `Reverse`, `NonZero` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, a `String`, or a reference, or to an `Arc` or a `Waker`, is an `rt.Place` | | `*const T`, `*mut T`, `NonNull` | what a `&mut T` is: the object, or an `rt.Place` to a value JS copies and to a library type such as a `Vec` or an `Arc`; `rt.NULL` for null and `rt.DANGLING` for dangling. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there; a read copies what the crate writes into in place | | `MaybeUninit` | `T`: `undefined` until written, or an object whose parts kept as objects are there, holding `undefined` | @@ -267,7 +269,9 @@ place and writes the string without the drained text as it drops, so one that `mem::forget` leaks leaves it as it was, as std's does. A `String` keeps no capacity: `with_capacity`, `reserve`, and `shrink_to_fit` do nothing, and `capacity` is refused. A `Cow` is its text, borrowed or owned, so `to_mut` borrows the `Cow`'s own place, and code that tells its variants apart, a `match` -on them or `Cow::is_borrowed`, is refused. +on them or `Cow::is_borrowed`, is refused. A `Cow<[T]>` keeps its variant in its class, +so a `match` reads it, and `to_mut` of a borrowed one stores a clone of its slice in the +`Cow`'s place before lending it. Functions and members are camelCase. Functions are monomorphized: each instance is its own function, suffixed after a `$` by its trait, then by its type's type arguments and @@ -584,6 +588,10 @@ they need. - A `Cow` is a JS string, as `str` and `String` are, rather than an object tagged by its variant: no `Cow` in moq-net or kio tells its variants apart, and a tag would wrap every value and unwrap it at every read. +- A `Cow<[T]>` is told apart by class, an owned one bare and a borrowed one in an + `rt.Borrowed`, so it clones and drops as std's does and only the borrowed side pays a + wrapper. Untagged, as `Cow` is, `to_mut` would clone on every call and a `match` + would be refused; tagged, every `Cow` would be wrapped. - A `Duration` keeps std's fields, whole seconds and nanoseconds, rather than one count of nanoseconds, so its overflow, `checked_*`, and ordering are std's exactly, and a lowering of its methods from core's MIR would read the same fields. @@ -672,7 +680,7 @@ hand-written TS ([bindings](#bindings)). These fail translation: `f16` and `f128`, async closures, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, an instance of a generic type whose field is a `Poll` of a type parameter that can be pending, a closure that owns a value that drops given to a std function that drops it beside another value that drops, other than `for_each` and `fold`, as `reduce` of items that drop does, or keeps it other than in -an iterator adaptor, and values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str`, a std +an iterator adaptor, and values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str` or a slice, a std function without a mapping of its own that makes or reads an `Option` whose `None` is `rt.None`, as `Iterator::scan` of `Option`s does, an `Option` of an `Option` of `()` or another `Option`, an instance of a generic type whose field is an `Option` of a type parameter @@ -712,7 +720,7 @@ built natively for wasm32 and run beside its translation on the same inputs by Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`, which must keep only those and what they call. - `lang` covers every integer width's arithmetic and casts, `char`s next to each - encoding's edges and the surrogates, `Cow` borrowed and owned, `Duration`s whose + encoding's edges and the surrogates, `Cow` and `Cow<[T]>` borrowed and owned, `Wrapping` at every width, `Duration`s whose seconds pass 2^53 or reach `u64::MAX`, control flow, patterns, `Copy` aggregates, those a container stores included and those written into only in another module, behind a type parameter, or through a box, formatting, methods diff --git a/ts/fixtures/lang/caller.ts b/ts/fixtures/lang/caller.ts index eac5b3a09..c78cf57e8 100644 --- a/ts/fixtures/lang/caller.ts +++ b/ts/fixtures/lang/caller.ts @@ -588,4 +588,34 @@ const compares = [[], [5], [1, 2, 3], [250, 251, 252, 253, 254, 255], [0xff, 3, Array.from({ length: 256 }, (_, kind) => Uint8Array.of(comparesOp, kind, ...data)), ); -export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods]; +/** + * `wraps::*` of every kind at every width, over operands at the edges of its range: 0, 1, + * either end, the sign bit's neighbors, which make `MIN / -1`, and at 128 bits values past + * 2^64. Shift amounts are at, past, and many times past the width, which std masks. + */ +function wraps(): Uint8Array[] { + const widths: [string, number][] = [["u8s", 8], ["u16s", 16], ["u32s", 32], ["u64s", 64], ["u128s", 128], ["usizes", 32], ["i8s", 8], ["i16s", 16], ["i32s", 32], ["i64s", 64], ["i128s", 128], ["isizes", 32]]; + const cases: Uint8Array[] = []; + for (const [name, bits] of widths) { + const o = op(`wraps::${name}`); + const width = BigInt(bits); + const mask = (1n << width) - 1n; + const sign = 1n << (width - 1n); + const edges = [0n, 1n, 3n, mask, mask - 1n, sign, sign - 1n, sign + 1n]; + if (bits === 128) edges.push(1n << 64n, (1n << 64n) + 3n, 0x9e3779b97f4a7c150123456789abcdefn); + const be = (v: bigint) => Array.from({ length: bits / 8 }, (_, i) => Number((v >> BigInt(bits - 8 - 8 * i)) & 0xffn)); + // The amount's low byte and its high byte, which reads as `high << 24`. + const shifts = [[0, 0], [1, 0], [bits - 1, 0], [bits, 0], [bits + 1, 0], [2 * bits + 3, 0], [5, 1]]; + let i = 0; + for (const a of edges) { + for (const b of edges) { + const c = edges[(i * 5 + 3) % edges.length]; + const [low, high] = shifts[i++ % shifts.length]; + for (let kind = 0; kind < 24; kind++) cases.push(Uint8Array.of(o, kind, ...be(a), ...be(b), ...be(c), low, high)); + } + } + } + return cases; +} + +export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps()]; diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 5a905f3a2..bcf94c650 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -3839,6 +3839,11 @@ export function each$Picky_Box_Picky_own_nes_closure15(v: Picky.Picky[], f: (a0: return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 4, true); } +/** `f` of each of `v`. */ +export function each$Picky_Cow_Pickys_own_nes_closure18(v: Picky.Picky[], f: (a0: Picky.Picky) => rt.Cow): rt.Cow[] { + return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 12, true); +} + /** `f` of each of `v`. */ export function each$Picky_Option_Picky_own_nes_closure10(v: Picky.Picky[], f: (a0: Picky.Picky) => Picky.Picky | undefined): Array { return rt.iterToArray(rt.iterMap(rt.iterSlice(v), f), undefined, 8, true); @@ -3901,9 +3906,10 @@ export function each$Quirky_RefCell_Quirky_cell_eqs_closure5(v: Quirky.Quirky[], /** * `==` and `!=` of what holds a `Picky`, whose `ne` std's of tuples, `Arc`s, `Rc`s, and - * `Box`es call, and std's `==` of slices calls of each item, but which an `Option`'s and - * a `Reverse`'s `ne`, as `!eq`, does not: of unequal lengths, empty, nested, and with - * items `eq` and `ne` disagree on at the positions `kind` picks. + * `Box`es call, and std's `==` of slices and `Cow`s of them calls of each item, but which + * an `Option`'s, a `Reverse`'s, and a `Wrapping`'s `ne`, as `!eq`, does not: of unequal + * lengths, empty, nested, and with items `eq` and `ne` disagree on at the positions + * `kind` picks. */ export function ownNes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _34: (a0: Picky.Picky[], a1: rt.usize) => rt.u16 = (v: Picky.Picky[], i: rt.usize): rt.u16 => { @@ -4138,6 +4144,46 @@ export function ownNes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { putEq(rt.eqSeq((a41: Picky.Picky, b33: Picky.Picky): boolean => { return !Picky.ne$PartialEq(a41, b33); })(_485, _490), log, out); + const _496: [Picky.Picky] = [one(a, 0)]; + const _504: [Picky.Picky] = [one(b, 0)]; + putEq(!rt.eqTuple([Picky.eq$PartialEq])(_496, _504), log, out); + putEq(Picky.eq$PartialEq(one(a, 1), one(b, 1)), log, out); + const _531: [rt.Cow, rt.Cow] = [new rt.Borrowed(rt.sliceRange(a, 0)), b.map(Picky.clone$Clone)]; + const ca: rt.Cow = _531[0]; + const cb: rt.Cow = _531[1]; + putEq(rt.eqSlice((a42: Picky.Picky, b34: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a42, b34); + })(rt.cowSlice(ca), rt.cowSlice(cb)), log, out); + putEq(!rt.eqSlice((a43: Picky.Picky, b35: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a43, b35); + })(rt.cowSlice(ca), rt.cowSlice(cb)), log, out); + const _553: Picky.Picky[] = rt.sliceRange(b, 0); + putEq(rt.eqSlice((a44: Picky.Picky, b36: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a44, b36); + })(rt.cowSlice(ca), _553), log, out); + putEq(!rt.eqSlice((a45: Picky.Picky, b37: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a45, b37); + })(rt.cowSlice(cb), a), log, out); + putEq(rt.eqSlice((a46: Picky.Picky, b38: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a46, b38); + })(b, rt.cowSlice(ca)), log, out); + const _570: Picky.Picky[] = rt.sliceRange(a, 0); + putEq(!rt.eqSlice((a47: Picky.Picky, b39: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a47, b39); + })(_570, rt.cowSlice(cb)), log, out); + const _576: Picky.Picky[] = rt.cowSlice(cb); + putEq(rt.eqSlice((a48: Picky.Picky, b40: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a48, b40); + })(_576, pa), log, out); + const owned: rt.Cow[] = each$Picky_Cow_Pickys_own_nes_closure18(a, (p14: Picky.Picky): rt.Cow => { + return [Picky.clone$Clone(p14)]; + }); + const borrowed: rt.Cow[] = rt.iterToArray(rt.iterMap(rt.sliceChunks(b, 1), (a059: Picky.Picky[]): rt.Cow => { + return new rt.Borrowed(a059); + }), undefined, 12, true); + putEq(!rt.eqSlice(rt.cowBy(rt.eqSlice((a49: Picky.Picky, b41: Picky.Picky): boolean => { + return !Picky.ne$PartialEq(a49, b41); + })))(owned, borrowed), log, out); rt.dropAll(shared); floated[Symbol.dispose](); arc[Symbol.dispose](); diff --git a/ts/fixtures/lang/expected/core/option.ts b/ts/fixtures/lang/expected/core/option.ts index 9a2537d4d..dae8d05e2 100644 --- a/ts/fixtures/lang/expected/core/option.ts +++ b/ts/fixtures/lang/expected/core/option.ts @@ -43,6 +43,13 @@ import type * as Short from "../splits.Short.ts"; import type * as Loud from "../zeros.Loud.ts"; import * as Tagged from "../zeros.Tagged.ts"; +export function isSomeAnd$08u1px1(self: rt.Ordering | undefined, f: (a0: rt.Ordering) => boolean): boolean { + if (self === undefined) { + return false; + } + return f(self); +} + export function isSomeAnd$09tpccf(self: rt.u8 | undefined, f: (a0: rt.u8) => boolean): boolean { if (self === undefined) { return false; diff --git a/ts/fixtures/lang/expected/cows.Run.ts b/ts/fixtures/lang/expected/cows.Run.ts new file mode 100644 index 000000000..ddb669171 --- /dev/null +++ b/ts/fixtures/lang/expected/cows.Run.ts @@ -0,0 +1,48 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function clone$Clone(self: Run): Run { + return { words: rt.cowClone(self.words) }; +} + +export function fmt$Debug(self: Run, f: rt.Formatter): rt.Result { + const _3: string = "Run"; + const _4: string = "words"; + const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtList(rt.cowSlice(self.words), f, rt.u16Debug); + return rt.debugStructFinish(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5)); +} + +export function default$Default(): Run { + const _1: rt.Cow = []; + return { words: _1 }; +} + +export function eq$PartialEq(self: Run, other: Run): boolean { + return rt.eqSlice(rt.same)(rt.cowSlice(self.words), rt.cowSlice(other.words)); +} + +export function hash$Hash_DefaultHasher(self: Run, state: rt.Hasher): void { + rt.hashCow(rt.hashSlice(rt.hash16))(self.words, state); +} + +/** A `Cow<[T]>` in a field, with each derived impl reading it. */ +export interface Run { + words: rt.Cow; +} + +/** Through `to_mut` of the field. */ +export function bump(self: Run): void { + const owned = rt.cowIntoOwned(self.words); + self.words = owned; + const iter: rt.Iter> = rt.iterSliceMut(owned); + while (true) { + const _8: rt.Place | rt.Done = iter.next(); + if (_8 === rt.DONE) { + break; + } + _8.v = rt.u16WrappingAdd(_8.v, 1); + } +} + +//# sourceMappingURL=cows.Run.ts.map diff --git a/ts/fixtures/lang/expected/cows.Tally.ts b/ts/fixtures/lang/expected/cows.Tally.ts new file mode 100644 index 000000000..e4082ea36 --- /dev/null +++ b/ts/fixtures/lang/expected/cows.Tally.ts @@ -0,0 +1,29 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** An item whose `Clone` and `Drop` log, so what a `Cow` clones and drops shows. */ +export class Tally { + _0: rt.u8; + _1: rt.Cell; + + constructor(_0: rt.u8, _1: rt.Cell) { + this._0 = _0; + this._1 = _1; + } + + [Symbol.dispose](): void { + drop$Drop(this); + } +} + +export function clone$Clone(self: Tally): Tally { + rt.cellSet(self._1, rt.u32Add(rt.u32Add(rt.u32Mul(self._1.v, 7), self._0 as rt.u32), 1)); + return new Tally(rt.u8WrappingAdd(self._0, 100), self._1); +} + +export function drop$Drop(self: Tally): void { + rt.cellSet(self._1, rt.u32Add(rt.u32Mul(self._1.v, 3), self._0 as rt.u32)); +} + +//# sourceMappingURL=cows.Tally.ts.map diff --git a/ts/fixtures/lang/expected/cows.ts b/ts/fixtures/lang/expected/cows.ts index 33f8f7ab8..c0dca6156 100644 --- a/ts/fixtures/lang/expected/cows.ts +++ b/ts/fixtures/lang/expected/cows.ts @@ -1,8 +1,10 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { unwrapOr$1iemzn8, unwrapOr$0r2bmpr, map$1uo1d4o } from "./core/option.ts"; +import { unwrapOr$1iemzn8, unwrapOr$1j4op5y, unwrapOr$0r2bmpr, map$1uo1d4o } from "./core/option.ts"; import * as Named from "./cows.Named.ts"; +import * as Run from "./cows.Run.ts"; +import * as Tally from "./cows.Tally.ts"; import { put } from "./fmt.ts"; import { text } from "./strs.ts"; @@ -144,4 +146,425 @@ export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } } +/** A slice of `u16`s read from `data`, two bytes each. */ +export function words(data: rt.ByteSlice): rt.u16[] { + return rt.iterToArray(rt.iterMap(rt.byteSliceChunks(data, 2), (c: rt.ByteSlice): rt.u16 => { + rt.idx(c, 0); + return ((((c.data[c.start] as rt.u16)) << 8) & 0xffff) | rt.optionUnwrap(rt.byteSliceLast(c)) as rt.u16; + }), undefined, 2, true); +} + +export function cowOf(v: rt.u16[], owned: boolean): rt.Cow { + if (!owned) { + return new rt.Borrowed(v); + } + return v.slice(); +} + +export function putWords(out: rt.ByteVec, v: rt.u16[]): void { + rt.byteVecPush(out, v.length & 0xff); + for (const _8 of v) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(_8))); + } +} + +export function hashed$Cow_u16s(v: rt.Cow): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hashCow(rt.hashSlice(rt.hash16))(v, h); + return rt.hashFinish(h); +} + +export function hashed$Cow_u8s(v: rt.ByteCow): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hashBytes(v, h); + return rt.hashFinish(h); +} + +export function hashed$Vec_u8(v: rt.ByteVec): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hashBytes(v, h); + return rt.hashFinish(h); +} + +export function hashed$u16s(v: rt.u16[]): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hashSlice(rt.hash16)(v, h); + return rt.hashFinish(h); +} + +export function hashed$u8s(v: rt.ByteSlice): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hashBytes(v, h); + return rt.hashFinish(h); +} + +/** + * `Cow<[u16]>`: made each way, collected, and read, changed through `to_mut`, compared, + * ordered, and hashed against each sequence, matched on, and held in a field and as a key. + */ +export function slices(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + let made_!: rt.u16[]; + let _359!: rt.Cow; + let c4!: rt.Cow; + const v: rt.u16[] = words(data); + const owned: boolean = (kind & 128) !== 0; + const half: rt.u16[] = rt.sliceRange(v, 0, rt.usizeDiv(v.length, 2)); + const _15: rt.u8 = rt.u8Rem(kind, 6); + if (_15 === 0) { + const c: rt.Cow = cowOf(v, owned); + rt.byteVecPush(out, rt.cowSlice(c).length & 0xff); + rt.byteVecPush(out, rt.cowSlice(c).length === 0 ? 1 : 0); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(rt.iterFold(rt.iterSlice(rt.cowSlice(c)), 0, (a2: rt.u16, w: rt.u16): rt.u16 => { + return rt.u16WrappingAdd(a2, w); + })))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(unwrapOr$1j4op5y(rt.sliceFirst(rt.cowSlice(c)), 65535)))); + putWords(out, rt.cowSlice(c)); + putWords(out, rt.cowSlice(c)); + putWords(out, rt.cowSlice(rt.cowClone(c))); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.cowSlice(c), f, rt.u16Debug)]; + put(out, rt.fmtFormat([args2[0]])); + putWords(out, rt.cowIntoOwned(c)); + const empty: rt.Cow = []; + putWords(out, rt.cowSlice(empty)); + const iter: rt.Iter> = rt.iterSlice([new rt.Borrowed(half), v.slice(), new rt.Borrowed(v), new rt.Borrowed([3, 1, 4]), rt.iterToArray(rt.iterRev(rt.iterSlice(v)), undefined, 2, true)]); + while (true) { + const _100: rt.Cow | rt.Done = iter.next(); + if (_100 === rt.DONE) { + break; + } + putWords(out, rt.cowSlice(_100)); + } + putWords(out, rt.cowIntoOwned(cowOf(half, owned))); + } else if (_15 === 1) { + let c2: rt.Cow = cowOf(v, owned); + const owned4 = rt.cowIntoOwned(c2); + c2 = owned4; + owned4.push(7); + const owned5 = rt.cowIntoOwned(c2); + c2 = owned5; + const m: rt.u16[] = owned5; + const _119: rt.Place | undefined = rt.sliceFirstMut(m); + if (_119 !== undefined) { + _119.v = _119.v ^ 65535; + } + m.push(9); + putWords(out, rt.cowSlice(c2)); + putWords(out, v); + const cs: rt.Cow[] = [cowOf(half, owned), cowOf(v, !owned)]; + const at = rt.idx(cs, 1); + const owned6 = rt.cowIntoOwned(cs[at]); + cs[at] = owned6; + rt.vecTruncate(owned6, 1); + for (const _144 of cs) { + putWords(out, rt.cowSlice(_144)); + } + const run: Run.Run = { words: cowOf(half, owned) }; + const before: Run.Run = Run.clone$Clone(run); + Run.bump(run); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Run.fmt$Debug(run, f), (f: rt.Formatter) => Run.fmt$Debug(before, f)]; + put(out, rt.fmtFormat([args4[0], " ", args4[1]])); + putWords(out, half); + putWords(out, rt.cowIntoOwned(c2)); + } else if (_15 === 2) { + const a: rt.Cow = cowOf(v, owned); + const b: rt.Cow = cowOf(half, !owned); + const _182: rt.u16 = unwrapOr$1j4op5y(rt.sliceFirst(v), 0); + const array: rt.u16[] = Array.from({ length: 2 }, (): rt.u16 => { + return _182; + }); + const _188: boolean = rt.eqSlice(rt.same)(rt.cowSlice(a), rt.cowSlice(b)); + const _191: boolean = !rt.eqSlice(rt.same)(rt.cowSlice(a), rt.cowSlice(b)); + const _194: boolean = rt.eqSlice(rt.same)(rt.cowSlice(a), half); + const _201: rt.u16[] = rt.sliceRange(v, 0); + const _197: boolean = rt.eqSlice(rt.same)(rt.cowSlice(a), _201); + const _203: boolean = rt.eqSlice(rt.same)(rt.cowSlice(a), v); + const _209: rt.u16[] = half.slice(); + const _206: boolean = !rt.eqSlice(rt.same)(rt.cowSlice(a), _209); + const _210: boolean = rt.eqSlice(rt.same)(half, rt.cowSlice(b)); + const _213: boolean = rt.eqSlice(rt.same)(v, rt.cowSlice(a)); + const _219: rt.u16[] = rt.sliceRange(v, 0); + const _216: boolean = !rt.eqSlice(rt.same)(_219, rt.cowSlice(a)); + const _223: rt.u16[] = rt.cowSlice(a); + const _222: boolean = rt.eqSlice(rt.same)(_223, array); + const _227: rt.u16[] = rt.cowSlice(b); + const _229: rt.u16[] = rt.sliceRange(array, 0, rt.min(half.length, 2)); + const _226: boolean = rt.eqSlice(rt.same)(_227, _229); + const _234: boolean = rt.cowBy(rt.cmpSlice(rt.cmp))(a, b) < 0; + const _238: boolean = rt.cowBy(rt.cmpSlice(rt.cmp))(a, b) === 1; + const _244: boolean = rt.cowBy(rt.cmpSlice(rt.cmp))(a, b) === -1; + const order = rt.cowBy(rt.cmpSlice(rt.cmp))(a, b); + const _247: boolean = order !== undefined && order >= 0; + const _250: boolean = rt.u64Eq(hashed$Cow_u16s(a), hashed$u16s(rt.sliceRange(v, 0))); + const _256: boolean = rt.u64Eq(hashed$Cow_u16s(b), hashed$u16s(half)); + const _262: rt.Cow = rt.ordMax(rt.cowClone(a), rt.cowClone(b), rt.cmpLt(rt.cowBy(rt.cmpSlice(rt.cmp)))); + const iter3: rt.Iter = rt.iterSlice([_188, _191, _194, _197, _203, _206, _210, _213, _216, _222, _226, _234, _238, _244, _247, _250, _256, rt.eqSlice(rt.same)(rt.cowSlice(_262), rt.cowSlice(b))]); + while (true) { + const _270: boolean | rt.Done = iter3.next(); + if (_270 === rt.DONE) { + break; + } + rt.byteVecPush(out, _270 ? 1 : 0); + } + } else if (_15 === 3) { + let c3: rt.Cow = cowOf(v, owned); + if (c3 instanceof rt.Borrowed) { + putWords(out, (c3 as rt.Borrowed).slice); + } else { + rt.byteVecPush(out, 238); + putWords(out, c3 as rt.u16[]); + } + if (!(c3 instanceof rt.Borrowed)) { + (c3 as rt.u16[]).push(5); + } + putWords(out, rt.cowSlice(c3)); + const kept: rt.Cow = rt.cowClone(c3); + if (c3 instanceof rt.Borrowed) { + (c3 as rt.Borrowed).slice = half; + } + if (!(c3 instanceof rt.Borrowed)) { + const _302: rt.u16[] = rt.iterToArray(rt.iterRev(rt.iterSlice(half)), undefined, 2, true); + (c3 as rt.u16[]) = _302; + } + putWords(out, rt.cowSlice(c3)); + putWords(out, rt.cowSlice(kept)); + let e: rt.Cow = cowOf(v, !owned); + const kept2: rt.Cow = rt.cowClone(e); + if (e instanceof rt.Borrowed) { + const borrowed = e as rt.Borrowed; + repoint$u16(rt.place(() => borrowed.slice as rt.u16[], (value5) => borrowed.slice = value5), half); + rt.byteVecPush(out, borrowed.slice.length & 0xff); + borrowed.slice = rt.sliceRange(v, 0, rt.min(v.length, 1)); + rt.byteVecPush(out, borrowed.slice.length & 0xff); + } else { + rt.vecTruncate(e as rt.u16[], 1); + const _336: rt.u16[] = half.slice(); + (e as rt.u16[]) = _336; + rt.byteVecPush(out, (e as rt.u16[]).length & 0xff); + } + putWords(out, rt.cowSlice(e)); + putWords(out, rt.cowSlice(kept2)); + if (c3 instanceof rt.Borrowed) { + made_ = rt.iterToArray(rt.iterRev(rt.iterSlice((c3 as rt.Borrowed).slice)), undefined, 2, true); + } else { + made_ = c3 as rt.u16[]; + } + putWords(out, made_); + let d: rt.Cow = cowOf(half, !owned); + b16: { + if (d instanceof rt.Borrowed) { + if ((d as rt.Borrowed).slice.length > 1) { + _359 = rt.sliceRange((d as rt.Borrowed).slice, 1).slice(); + break b16; + } + } + _359 = d; + } + d = _359; + putWords(out, rt.cowSlice(d)); + } else if (_15 === 4) { + const counts: rt.BTreeMap, rt.u8> = rt.btreeNew(rt.cowBy(rt.cmpSlice(rt.cmp))) as rt.BTreeMap, rt.u8>; + const iter4: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.sliceChunks(v, 2)); + while (true) { + const _379: [rt.usize, rt.u16[]] | rt.Done = iter4.next(); + if (_379 === rt.DONE) { + break; + } + const _387: rt.Cow = cowOf(_379[1], rt.usizeRem(_379[0], 2) === 1 === owned); + const _384: rt.Place = rt.entryOrInsertMut(rt.entry(counts, _387), 0); + _384.v = rt.u8Add(_384.v, 1); + } + const iter5: rt.Iter<[rt.Cow, rt.u8]> = rt.btreeIter(counts); + while (true) { + const _396: [rt.Cow, rt.u8] | rt.Done = iter5.next(); + if (_396 === rt.DONE) { + break; + } + putWords(out, rt.cowSlice(_396[0])); + rt.byteVecPush(out, _396[1]); + } + const _411: rt.Cow = cowOf(half, owned); + rt.byteVecPush(out, unwrapOr$0r2bmpr(rt.btreeGet(counts, _411), 255)); + const runs: rt.HashSet = rt.hashNew(rt.hashing(Run.hash$Hash_DefaultHasher as (a0: Run.Run, a1: rt.Hasher) => undefined, Run.eq$PartialEq)) as rt.HashSet; + const iter6: rt.Iter = rt.sliceChunks(v, 3); + while (true) { + const _418: rt.u16[] | rt.Done = iter6.next(); + if (_418 === rt.DONE) { + break; + } + const _424: Run.Run = { words: cowOf(_418, owned) }; + rt.hashAdd(runs, _424); + } + rt.byteVecPush(out, rt.hashLen(runs) & 0xff); + const _435: Run.Run = { words: cowOf(rt.sliceRange(v, 0, rt.min(v.length, 3)), !owned) }; + rt.byteVecPush(out, rt.hashContains(runs, _435) ? 1 : 0); + const part4 = Run.default$Default(); + const args6: rt.Fmt[] = [(f: rt.Formatter) => Run.fmt$Debug(part4, f)]; + put(out, rt.fmtFormat([args6[0]])); + } else { + const log: rt.Cell = new rt.Cell(0); + const items: Tally.Tally[] = rt.iterToArray(rt.iterMap(rt.iterTake(rt.iterSlice(rt.byteSliceView(data)), 4), (_2: rt.u8): Tally.Tally => { + return new Tally.Tally(_2, log); + }), undefined, 8, true); + if (!owned) { + c4 = new rt.Borrowed(rt.sliceRange(items, 0)); + } else { + c4 = items.map(Tally.clone$Clone); + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const copy: rt.Cow = rt.cowClone(c4, Tally.clone$Clone); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + rt.cowDrop(copy); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const _490: rt.Place> = rt.place(() => c4, (value) => c4 = value); + if (_490.v instanceof rt.Borrowed) { + const _493: Tally.Tally[] = rt.sliceRange(items, rt.min(items.length, 1)); + (_490.v as rt.Borrowed).slice = _493; + } + rt.byteVecPush(out, rt.cowSlice(c4).length & 0xff); + const _506: rt.Place> = rt.place(() => c4, (value2) => c4 = value2); + const owned2 = rt.cowIntoOwned(_506.v, Tally.clone$Clone); + _506.v = owned2; + rt.drop(owned2.pop()); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const _515: rt.Place> = rt.place(() => c4, (value3) => c4 = value3); + const owned3 = rt.cowIntoOwned(_515.v, Tally.clone$Clone); + _515.v = owned3; + owned3.push(new Tally.Tally(9, log)); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const _524: rt.Place> = rt.place(() => c4, (value4) => c4 = value4); + if (!(_524.v instanceof rt.Borrowed)) { + const _527: Tally.Tally[] = [new Tally.Tally(7, log), new Tally.Tally(8, log)]; + rt.dropAll(_524.v as Tally.Tally[]); + (_524.v as Tally.Tally[]) = _527; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const kept3: Tally.Tally[] = rt.cowIntoOwned(c4, Tally.clone$Clone); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(kept3), (t: Tally.Tally): rt.u8 => { + return t._0; + }), undefined, true); + rt.dropAll(kept3); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + const cloned: Tally.Tally[] = rt.cowIntoOwned(new rt.Borrowed(rt.sliceRange(items, 0)), Tally.clone$Clone); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.cellReplace(log, 0)))); + rt.dropAll(cloned); + rt.dropAll(items); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(log.v))); + } +} + +/** Point `s` at `to`, through the `&mut` a caller passes. */ +export function repoint$u16(s: rt.Place, to: rt.u16[]): void { + s.v = to; +} + +/** Point `s` at `to`, through the `&mut` a caller passes. */ +export function repoint$u8(s: rt.Place, to: rt.ByteSlice): void { + s.v = to; +} + +export function made(s: rt.ByteSlice, owned: boolean): rt.ByteCow { + if (!owned) { + return s; + } + return rt.byteSliceToByteVec(s); +} + +/** + * `Cow<[u8]>` as bytes: made and collected, read, changed through `to_mut` without + * touching what it borrowed, compared against each form of bytes, hashed, printed, and + * matched on. + */ +export function bytes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + let _85!: boolean; + const owned: boolean = (kind & 128) !== 0; + const half: rt.ByteSlice = rt.byteSliceRange(data, 0, rt.usizeDiv(data.length, 2)); + let c: rt.ByteCow = made(data, owned); + rt.byteVecPush(out, rt.byteCowSlice(c).length & 0xff); + const part2 = rt.min(rt.byteCowSlice(c).length, 3); + rt.byteVecExtendFromSlice(out, rt.byteSliceRange(rt.byteCowSlice(c), 0, part2)); + const _35: rt.ByteCow = made(half, !owned); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(rt.byteCowSlice(c)), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(rt.byteCowSlice(_35)), f, rt.u8Debug)]; + put(out, rt.fmtFormat([args2[0], " ", args2[1]])); + const _47: rt.ByteCow = made(half, !owned); + const _44: boolean = rt.eqBytes(c, _47); + const _49: boolean = rt.eqBytes(c, data); + const _55: rt.ByteVec = rt.byteSliceToByteVec(data); + const _52: boolean = rt.eqBytes(c, _55); + const _56: boolean = !rt.eqBytes(c, half); + const _59: boolean = rt.eqBytes(rt.byteCowSlice(c), rt.byteSliceFrom(Uint8Array.of(0, 0))); + const _63: boolean = rt.eqBytes(data, c); + const _66: boolean = !rt.eqBytes(rt.byteSliceToByteVec(data), c); + const _74: rt.ByteCow = made(half, owned); + const _70: boolean = rt.cmpBytes(c, _74) > 0; + const _75: boolean = rt.u64Eq(hashed$Cow_u8s(c), hashed$u8s(data)); + const _79: boolean = rt.u64Eq(hashed$Cow_u8s(c), hashed$Vec_u8(rt.byteSliceToByteVec(data))); + if (c instanceof rt.ByteSlice) { + _85 = true; + } else { + _85 = false; + } + const iter: rt.Iter = rt.iterSlice([_44, _49, _52, _56, _59, _63, _66, _70, _75, _79, _85]); + while (true) { + const _89: boolean | rt.Done = iter.next(); + if (_89 === rt.DONE) { + break; + } + rt.byteVecPush(out, _89 ? 1 : 0); + } + if ((kind & 64) !== 0) { + const kept: rt.ByteCow = rt.byteCowClone(c); + if (c instanceof rt.ByteSlice) { + (c as rt.ByteSlice) = half; + } else { + const _103: rt.ByteVec = rt.byteSliceToByteVec(half); + (c as rt.ByteVec) = _103; + } + rt.byteVecExtendFromSlice(out, rt.byteCowSlice(kept)); + let e: rt.ByteCow = made(data, !owned); + if (e instanceof rt.ByteSlice) { + repoint$u8(rt.place(() => (e as rt.ByteSlice) as rt.ByteSlice, (value) => (e as rt.ByteSlice) = value), half); + } else { + rt.byteVecTruncate(e as rt.ByteVec, 1); + } + rt.byteVecExtendFromSlice(out, rt.byteCowSlice(e)); + } + const _118: rt.u8 = rt.u8Rem(kind, 3); + if (_118 === 0) { + const owned3 = rt.byteCowIntoOwned(c); + c = owned3; + rt.byteVecPush(owned3, kind); + const owned4 = rt.byteCowIntoOwned(c); + c = owned4; + rt.byteVecExtendFromSlice(owned4, half); + rt.byteVecExtendFromSlice(out, rt.byteCowSlice(c)); + } else if (_118 === 1) { + const owned2 = rt.byteCowIntoOwned(c); + c = owned2; + const _129: rt.Place | undefined = rt.sliceFirstMut(rt.byteSliceView(rt.byteVecSlice(owned2))); + if (_129 !== undefined) { + _129.v = rt.u8WrappingAdd(_129.v, 1); + } + rt.byteVecExtendFromSlice(out, rt.byteVecSlice(rt.byteCowIntoOwned(c))); + } else if (c instanceof rt.ByteSlice) { + rt.iterExtendBytes(out, rt.iterRev(rt.iterSlice(rt.byteSliceView(c as rt.ByteSlice))), undefined, true); + } else { + const v2: rt.ByteVec = c as rt.ByteVec; + rt.byteSliceView(rt.byteVecSlice(v2)).reverse(); + rt.byteVecExtendFromSlice(out, rt.byteVecSlice(v2)); + } + rt.byteVecExtendFromSlice(out, data); + rt.byteVecPush(out, rt.byteCowSlice(new rt.ByteVec()).length & 0xff); + const iter2: rt.Iter = rt.iterSlice([rt.byteVecSlice(rt.byteSliceToByteVec(data)), rt.byteSliceFrom(Uint8Array.of(7, 8)), rt.iterToByteVec(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (b: rt.u8): rt.u8 => { + return b ^ 1; + }), undefined, true)]); + while (true) { + const _174: rt.ByteCow | rt.Done = iter2.next(); + if (_174 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteCowSlice(_174)); + } +} + //# sourceMappingURL=cows.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 465a7a565..99af9b2f2 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -13,12 +13,12 @@ import { iters } from "./clones.ts"; import { hashMaps, sets, btreeMaps, deques, vecs, stores, optionals, setOps, unlikeEqs, ownNes, cellEqs, unlikeCompares } from "./collections.ts"; import { combinators } from "./combinators.ts"; import { arcs, clonedArcs, cyclicArcs, uniqueArcs, clonedRcs, cyclicRcs, rcs, uniqueRcs, copies } from "./counts.ts"; -import { cows } from "./cows.ts"; +import { cows, slices, bytes } from "./cows.ts"; import { cycles } from "./cycles.ts"; import { defaults } from "./defaults.ts"; import { durations } from "./durations.ts"; import { dyns, shared, anys, fns } from "./dyns.ts"; -import { edits, bytes } from "./edits.ts"; +import { edits, bytes as edits_bytes } from "./edits.ts"; import { eqs } from "./errors.ts"; import { floats, mulAdds, formats, parses } from "./floats.ts"; import { ints, strings, derived, written, counts, rounding, panics, wrapped, collections, iters as fmt_iters, writes } from "./fmt.ts"; @@ -42,9 +42,10 @@ import { singles, mulAdds as singles_mulAdds, formats as singles_formats, parses import { parts, chunked, subslices, drains, ranges as slices_ranges, edits as slices_edits } from "./slices.ts"; import { splits } from "./splits.ts"; import { statics, cells as statics_cells, onces } from "./statics.ts"; -import { strs, slices, edits as strs_edits, parses as strs_parses, iters as strs_iters, drains as strs_drains, hinted } from "./strs.ts"; +import { strs, slices as strs_slices, edits as strs_edits, parses as strs_parses, iters as strs_iters, drains as strs_drains, hinted } from "./strs.ts"; import { decodes } from "./utf8.ts"; import { wrappers } from "./wrappers.ts"; +import { u8s, u16s, u32s, u64s, u128s, usizes, i8s, i16s, i32s, i64s, i128s, isizes } from "./wraps.ts"; import { zeros, impls, keys as zeros_keys, unread } from "./zeros.ts"; /** @@ -90,7 +91,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) flows(data18, out18); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["keys::keys", keys as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["chars::chars", chars as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["strs::strs", strs as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::vecs", (_2118: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): undefined => { vecs(data19, out19); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["strs::slices", slices as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::stores", (_2119: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): undefined => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["strs::slices", strs_slices as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::stores", (_2119: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): undefined => { stores(data20, out20); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["chunks::chunks", chunks as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["cows::cows", cows as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["durations::durations", durations as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["combinators::combinators", combinators as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["splits::splits", splits as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["nested::nested", nested as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["refs::refs", (_2120: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): undefined => { refs(data21, out21); @@ -146,7 +147,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) pointers_shared(data45, out46); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["pointers::unchecked", (_2146: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): undefined => { unchecked(data46, out47); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["edits::bytes", bytes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["arrays::from_fns", (_2147: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): undefined => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["edits::bytes", edits_bytes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["arrays::from_fns", (_2147: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): undefined => { fromFns(data47, out48); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::optionals", optionals as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["objects::objects", (_2148: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): undefined => { objects(data48, out49); @@ -200,7 +201,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) fmt_iters(data72, out73); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::unread", unread as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["iters::range_froms", rangeFroms as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["iters::range_methods", rangeMethods as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["clones::iters", iters as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::cell_eqs", cellEqs as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["iters::compares", compares as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::unlike_compares", unlikeCompares as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["cycles::cycles", cycles as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["pointers::lapsed", (_2173: rt.u8, data73: rt.ByteSlice, out74: rt.ByteVec): undefined => { lapsed(data73, out74); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["cows::slices", slices as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["cows::bytes", bytes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::u8s", u8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::u16s", u16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::u32s", u32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::u64s", u64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::u128s", u128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::usizes", usizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::i8s", i8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::i16s", i16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::i32s", i32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::i64s", i64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::i128s", i128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["wraps::isizes", isizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index cc63a036f..94bc44e7f 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -38,6 +38,7 @@ import type * as Point from "./shapes.Point.ts"; import type * as Shape from "./shapes.Shape.ts"; import type * as slices_Pair from "./slices.Pair.ts"; import * as Lock from "./statics.Lock.ts"; +import * as Tick from "./wraps.Tick.ts"; import * as zeros_Lock from "./zeros.Lock.ts"; import type * as Loud from "./zeros.Loud.ts"; @@ -263,6 +264,54 @@ export function copy$Tally(v: Tally.Tally): Tally.Tally { return { n: v.n }; } +export function copy$Tick_i128(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_i16(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_i32(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_i64(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_i8(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_isize(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_u128(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_u16(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_u32(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_u64(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_u8(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + +export function copy$Tick_usize(v: Tick.Tick): Tick.Tick { + return new Tick.Tick(v._0); +} + export function copy$Twin(v: Twin.Twin): Twin.Twin { return { _0: v._0, _1: v._1 }; } diff --git a/ts/fixtures/lang/expected/wraps.Tick.ts b/ts/fixtures/lang/expected/wraps.Tick.ts new file mode 100644 index 000000000..7670c8845 --- /dev/null +++ b/ts/fixtures/lang/expected/wraps.Tick.ts @@ -0,0 +1,278 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function fmt$Debug_i128(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i128Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_i16(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i16Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_i32(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i32Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_i64(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i64Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_i8(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i8Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_isize(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.isizeDebug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_u128(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u128Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_u16(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u16Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_u32(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u32Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_u64(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u64Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_u8(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u8Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$Debug_usize(self: Tick, f: rt.Formatter): rt.Result { + const _3: string = "Tick"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.usizeDebug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function default$Default_i128(): Tick { + return new Tick(0); +} + +export function default$Default_i16(): Tick { + return new Tick(0); +} + +export function default$Default_i32(): Tick { + return new Tick(0); +} + +export function default$Default_i64(): Tick { + return new Tick(0); +} + +export function default$Default_i8(): Tick { + return new Tick(0); +} + +export function default$Default_isize(): Tick { + return new Tick(0); +} + +export function default$Default_u128(): Tick { + return new Tick(0); +} + +export function default$Default_u16(): Tick { + return new Tick(0); +} + +export function default$Default_u32(): Tick { + return new Tick(0); +} + +export function default$Default_u64(): Tick { + return new Tick(0); +} + +export function default$Default_u8(): Tick { + return new Tick(0); +} + +export function default$Default_usize(): Tick { + return new Tick(0); +} + +export function eq$PartialEq_i128(self: Tick, other: Tick): boolean { + return rt.i128Eq(self._0, other._0); +} + +export function eq$PartialEq_i16(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_i32(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_i64(self: Tick, other: Tick): boolean { + return rt.i64Eq(self._0, other._0); +} + +export function eq$PartialEq_i8(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_isize(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_u128(self: Tick, other: Tick): boolean { + return rt.u128Eq(self._0, other._0); +} + +export function eq$PartialEq_u16(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_u32(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_u64(self: Tick, other: Tick): boolean { + return rt.u64Eq(self._0, other._0); +} + +export function eq$PartialEq_u8(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function eq$PartialEq_usize(self: Tick, other: Tick): boolean { + return self._0 === other._0; +} + +export function hash$Hash_i128_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash128(self._0, state); +} + +export function hash$Hash_i16_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash16(self._0, state); +} + +export function hash$Hash_i32_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_i64_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash64(self._0, state); +} + +export function hash$Hash_i8_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash8(self._0, state); +} + +export function hash$Hash_isize_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_u128_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash128(self._0, state); +} + +export function hash$Hash_u16_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash16(self._0, state); +} + +export function hash$Hash_u32_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_u64_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash64(self._0, state); +} + +export function hash$Hash_u8_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash8(self._0, state); +} + +export function hash$Hash_usize_DefaultHasher(self: Tick, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function cmp$Ord_i128(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_i16(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_i32(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_i64(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_i8(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_isize(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_u128(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_u16(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_u32(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_u64(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_u8(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$Ord_usize(self: Tick, other: Tick): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** A `Wrapping` in a field, with each derived impl reading it. */ +export class Tick { + _0: T; + + constructor(_0: T) { + this._0 = _0; + } +} + +//# sourceMappingURL=wraps.Tick.ts.map diff --git a/ts/fixtures/lang/expected/wraps.ts b/ts/fixtures/lang/expected/wraps.ts new file mode 100644 index 000000000..b414a151f --- /dev/null +++ b/ts/fixtures/lang/expected/wraps.ts @@ -0,0 +1,2432 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { copy$Tick_i128, copy$Tick_i16, copy$Tick_i32, copy$Tick_i64, copy$Tick_i8, copy$Tick_isize, copy$Tick_u128, copy$Tick_u16, copy$Tick_u32, copy$Tick_u64, copy$Tick_u8, copy$Tick_usize } from "./lib.ts"; +import { isSomeAnd$08u1px1, unwrapOr$0r2bmpr } from "./core/option.ts"; +import * as Tick from "./wraps.Tick.ts"; + +export function hashed$Tick_i128(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_i128_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_i16(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_i16_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_i32(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_i32_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_i64(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_i64_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_i8(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_i8_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_isize(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_isize_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_u128(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_u128_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_u16(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_u16_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_u32(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_u32_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_u64(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_u64_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_u8(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_u8_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Tick_usize(v: Tick.Tick): rt.u64 { + const h: rt.Hasher = rt.hasher(); + Tick.hash$Hash_usize_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_i128(v: rt.i128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_i16(v: rt.i16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_i32(v: rt.i32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_i64(v: rt.i64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_i8(v: rt.i8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_isize(v: rt.isize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_u128(v: rt.u128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_u16(v: rt.u16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_u32(v: rt.u32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_u64(v: rt.u64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_u8(v: rt.u8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$Wrapping_usize(v: rt.usize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$i128(v: rt.i128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$i16(v: rt.i16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$i32(v: rt.i32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$i64(v: rt.i64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$i8(v: rt.i8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$isize(v: rt.isize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$u128(v: rt.u128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$u16(v: rt.u16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$u32(v: rt.u32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$u64(v: rt.u64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$u8(v: rt.u8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$usize(v: rt.usize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function u8s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.u8) => undefined = (out2: rt.ByteVec, v: rt.u8): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u8ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u8 = (at: rt.usize): rt.u8 => { + const buf: Uint8Array = Uint8Array.of(0); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u8FromBeBytes(buf); + }; + const _8: [rt.u8, rt.u8, rt.u8] = [take(0), take(1), take(2 * 1)]; + const a: rt.u8 = _8[0]; + const b: rt.u8 = _8[1]; + const c: rt.u8 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 1, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.u8WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.u8WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.u8WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.u8Div(a, b)); + } else if (_31 === 4) { + _30(out, rt.u8Rem(a, b)); + } else if (_31 === 5) { + const part40 = rt.u8WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a & 0xff); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.u8Shl(a, n & 7)); + } else if (_31 === 11) { + _30(out, rt.u8Shr(a, n & 7)); + } else if (_31 === 12) { + let x: rt.u8 = a; + x = rt.u8WrappingAdd(x, b); + _30(out, x); + x = rt.u8WrappingMul(x, c); + _30(out, x); + x = rt.u8WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.u8 = a; + x2 = rt.u8Div(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.u8 = a; + x3 = rt.u8Rem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.u8 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.u8 = a; + x5 = rt.u8Shl(x5, n & 7); + _30(out, x5); + x5 = rt.u8Shr(x5, n & 7); + _30(out, x5); + _30(out, (a << 3) & 0xff); + _30(out, rt.u8Shr(a, rt.usizeAdd(8, 1) & 7)); + } else if (_31 === 17) { + const part15 = rt.u8WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.u8WrappingSub(a, b); + _30(out, part16); + const part17 = rt.u8WrappingMul(a, c); + _30(out, part17); + const part18 = rt.u8WrappingSub(0, a); + _30(out, part18); + _30(out, ~b & 0xff); + _30(out, rt.u8Shl(a, n & 7)); + _30(out, rt.u8Shr(a, n & 7)); + _30(out, a ^ c); + let x6: rt.u8 = a; + x6 = rt.u8WrappingAdd(x6, b); + x6 = rt.u8Shl(x6, n & 7); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.u8 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.u8 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_u8(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_u8(a), hashed$u8(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 1, true)); + while (true) { + const _258: rt.u8 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash8, rt.same)) as rt.HashSet, _267, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u8Display(a, f), (f: rt.Formatter) => rt.u8Debug(b, f), (f: rt.Formatter) => rt.u8LowerHex(a, f), (f: rt.Formatter) => rt.u8UpperHex(b, f), (f: rt.Formatter) => rt.u8Octal(c, f), (f: rt.Formatter) => rt.u8Binary(a, f), (f: rt.Formatter) => rt.u8Display(b, f), (f: rt.Formatter) => rt.u8LowerHex(c, f), (f: rt.Formatter) => rt.u8Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.u8[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.u8WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.u8WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.u8WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.u8WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u8WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u8WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_u8(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_u8(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_u8(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_u8(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_u8(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_u8(x7), hashed$Wrapping_u8(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_u8(x7); + z._0 = rt.u8WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function u16s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.u16) => undefined = (out2: rt.ByteVec, v: rt.u16): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u16ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u16 = (at: rt.usize): rt.u16 => { + const buf: Uint8Array = rt.bytes(2); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u16FromBeBytes(buf); + }; + const _8: [rt.u16, rt.u16, rt.u16] = [take(0), take(2), take(2 * 2)]; + const a: rt.u16 = _8[0]; + const b: rt.u16 = _8[1]; + const c: rt.u16 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 2, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.u16WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.u16WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.u16WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.u16Div(a, b)); + } else if (_31 === 4) { + _30(out, rt.u16Rem(a, b)); + } else if (_31 === 5) { + const part40 = rt.u16WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a & 0xffff); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.u16Shl(a, n & 15)); + } else if (_31 === 11) { + _30(out, rt.u16Shr(a, n & 15)); + } else if (_31 === 12) { + let x: rt.u16 = a; + x = rt.u16WrappingAdd(x, b); + _30(out, x); + x = rt.u16WrappingMul(x, c); + _30(out, x); + x = rt.u16WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.u16 = a; + x2 = rt.u16Div(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.u16 = a; + x3 = rt.u16Rem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.u16 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.u16 = a; + x5 = rt.u16Shl(x5, n & 15); + _30(out, x5); + x5 = rt.u16Shr(x5, n & 15); + _30(out, x5); + _30(out, (a << 3) & 0xffff); + _30(out, rt.u16Shr(a, rt.usizeAdd(16, 1) & 15)); + } else if (_31 === 17) { + const part15 = rt.u16WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.u16WrappingSub(a, b); + _30(out, part16); + const part17 = rt.u16WrappingMul(a, c); + _30(out, part17); + const part18 = rt.u16WrappingSub(0, a); + _30(out, part18); + _30(out, ~b & 0xffff); + _30(out, rt.u16Shl(a, n & 15)); + _30(out, rt.u16Shr(a, n & 15)); + _30(out, a ^ c); + let x6: rt.u16 = a; + x6 = rt.u16WrappingAdd(x6, b); + x6 = rt.u16Shl(x6, n & 15); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.u16 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.u16 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_u16(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_u16(a), hashed$u16(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 2, true)); + while (true) { + const _258: rt.u16 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash16, rt.same)) as rt.HashSet, _267, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u16Display(a, f), (f: rt.Formatter) => rt.u16Debug(b, f), (f: rt.Formatter) => rt.u16LowerHex(a, f), (f: rt.Formatter) => rt.u16UpperHex(b, f), (f: rt.Formatter) => rt.u16Octal(c, f), (f: rt.Formatter) => rt.u16Binary(a, f), (f: rt.Formatter) => rt.u16Display(b, f), (f: rt.Formatter) => rt.u16LowerHex(c, f), (f: rt.Formatter) => rt.u16Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.u16[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.u16WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.u16WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.u16WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.u16WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u16WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u16WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_u16(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_u16(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_u16(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_u16(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_u16(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_u16(x7), hashed$Wrapping_u16(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_u16(x7); + z._0 = rt.u16WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function u32s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.u32) => undefined = (out2: rt.ByteVec, v: rt.u32): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u32ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u32 = (at: rt.usize): rt.u32 => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u32FromBeBytes(buf); + }; + const _8: [rt.u32, rt.u32, rt.u32] = [take(0), take(4), take(2 * 4)]; + const a: rt.u32 = _8[0]; + const b: rt.u32 = _8[1]; + const c: rt.u32 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 4, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.u32WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.u32WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.u32WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.u32Div(a, b)); + } else if (_31 === 4) { + _30(out, rt.u32Rem(a, b)); + } else if (_31 === 5) { + const part40 = rt.u32WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a >>> 0); + } else if (_31 === 7) { + _30(out, (a & b) >>> 0); + } else if (_31 === 8) { + _30(out, (a | b) >>> 0); + } else if (_31 === 9) { + _30(out, (a ^ b) >>> 0); + } else if (_31 === 10) { + _30(out, rt.u32Shl(a, n & 31)); + } else if (_31 === 11) { + _30(out, rt.u32Shr(a, n & 31)); + } else if (_31 === 12) { + let x: rt.u32 = a; + x = rt.u32WrappingAdd(x, b); + _30(out, x); + x = rt.u32WrappingMul(x, c); + _30(out, x); + x = rt.u32WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.u32 = a; + x2 = rt.u32Div(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.u32 = a; + x3 = rt.u32Rem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.u32 = a; + x4 = (x4 & b) >>> 0; + x4 = (x4 | c) >>> 0; + x4 = (x4 ^ b) >>> 0; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.u32 = a; + x5 = rt.u32Shl(x5, n & 31); + _30(out, x5); + x5 = rt.u32Shr(x5, n & 31); + _30(out, x5); + _30(out, (a << 3) >>> 0); + _30(out, rt.u32Shr(a, rt.usizeAdd(32, 1) & 31)); + } else if (_31 === 17) { + const part15 = rt.u32WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.u32WrappingSub(a, b); + _30(out, part16); + const part17 = rt.u32WrappingMul(a, c); + _30(out, part17); + const part18 = rt.u32WrappingSub(0, a); + _30(out, part18); + _30(out, ~b >>> 0); + _30(out, rt.u32Shl(a, n & 31)); + _30(out, rt.u32Shr(a, n & 31)); + _30(out, (a ^ c) >>> 0); + let x6: rt.u32 = a; + x6 = rt.u32WrappingAdd(x6, b); + x6 = rt.u32Shl(x6, n & 31); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.u32 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.u32 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_u32(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_u32(a), hashed$u32(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 4, true)); + while (true) { + const _258: rt.u32 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _267, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(a, f), (f: rt.Formatter) => rt.u32Debug(b, f), (f: rt.Formatter) => rt.u32LowerHex(a, f), (f: rt.Formatter) => rt.u32UpperHex(b, f), (f: rt.Formatter) => rt.u32Octal(c, f), (f: rt.Formatter) => rt.u32Binary(a, f), (f: rt.Formatter) => rt.u32Display(b, f), (f: rt.Formatter) => rt.u32LowerHex(c, f), (f: rt.Formatter) => rt.u32Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.u32[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.u32WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.u32WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.u32WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.u32WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u32WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u32WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_u32(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_u32(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_u32(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_u32(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_u32(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_u32(x7), hashed$Wrapping_u32(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_u32(x7); + z._0 = rt.u32WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function u64s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.u64) => undefined = (out2: rt.ByteVec, v: rt.u64): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u64ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u64 = (at: rt.usize): rt.u64 => { + const buf: Uint8Array = rt.bytes(8); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u64FromBeBytes(buf); + }; + const _8: [rt.u64, rt.u64, rt.u64] = [take(0), take(8), take(2 * 8)]; + const a: rt.u64 = _8[0]; + const b: rt.u64 = _8[1]; + const c: rt.u64 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 8, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.u64WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.u64WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.u64WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.u64Div(a, b)); + } else if (_31 === 4) { + _30(out, rt.u64Rem(a, b)); + } else if (_31 === 5) { + const part40 = rt.u64WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, rt.u64Not(a)); + } else if (_31 === 7) { + _30(out, rt.u64And(a, b)); + } else if (_31 === 8) { + _30(out, rt.u64Or(a, b)); + } else if (_31 === 9) { + _30(out, rt.u64Xor(a, b)); + } else if (_31 === 10) { + _30(out, rt.u64Shl(a, n & 63)); + } else if (_31 === 11) { + _30(out, rt.u64Shr(a, n & 63)); + } else if (_31 === 12) { + let x: rt.u64 = a; + x = rt.u64WrappingAdd(x, b); + _30(out, x); + x = rt.u64WrappingMul(x, c); + _30(out, x); + x = rt.u64WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.u64 = a; + x2 = rt.u64Div(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.u64 = a; + x3 = rt.u64Rem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.u64 = a; + x4 = rt.u64And(x4, b); + x4 = rt.u64Or(x4, c); + x4 = rt.u64Xor(x4, b); + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.u64 = a; + x5 = rt.u64Shl(x5, n & 63); + _30(out, x5); + x5 = rt.u64Shr(x5, n & 63); + _30(out, x5); + _30(out, rt.u64Shl(a, 3)); + _30(out, rt.u64Shr(a, rt.usizeAdd(64, 1) & 63)); + } else if (_31 === 17) { + const part15 = rt.u64WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.u64WrappingSub(a, b); + _30(out, part16); + const part17 = rt.u64WrappingMul(a, c); + _30(out, part17); + const part18 = rt.u64WrappingSub(0, a); + _30(out, part18); + _30(out, rt.u64Not(b)); + _30(out, rt.u64Shl(a, n & 63)); + _30(out, rt.u64Shr(a, n & 63)); + _30(out, rt.u64Xor(a, c)); + let x6: rt.u64 = a; + x6 = rt.u64WrappingAdd(x6, b); + x6 = rt.u64Shl(x6, n & 63); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = rt.u64Eq(a, b); + const _194: boolean = !rt.u64Eq(a, b); + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.u64 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.u64 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_u64(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_u64(a), hashed$u64(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 8, true)); + while (true) { + const _258: rt.u64 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash64, rt.u64Eq)) as rt.HashSet, _267, undefined, undefined, 117440512); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(a, f), (f: rt.Formatter) => rt.u64Debug(b, f), (f: rt.Formatter) => rt.u64LowerHex(a, f), (f: rt.Formatter) => rt.u64UpperHex(b, f), (f: rt.Formatter) => rt.u64Octal(c, f), (f: rt.Formatter) => rt.u64Binary(a, f), (f: rt.Formatter) => rt.u64Display(b, f), (f: rt.Formatter) => rt.u64LowerHex(c, f), (f: rt.Formatter) => rt.u64Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.u64[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.u64WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.u64WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.u64WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.u64WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u64WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u64WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_u64(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_u64(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_u64(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_u64(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_u64(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_u64(x7), hashed$Wrapping_u64(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_u64(x7); + z._0 = rt.u64WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function u128s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.u128) => undefined = (out2: rt.ByteVec, v: rt.u128): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u128 = (at: rt.usize): rt.u128 => { + const buf: Uint8Array = rt.bytes(16); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u128FromBeBytes(buf); + }; + const _8: [rt.u128, rt.u128, rt.u128] = [take(0), take(16), take(2 * 16)]; + const a: rt.u128 = _8[0]; + const b: rt.u128 = _8[1]; + const c: rt.u128 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 16, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.u128WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.u128WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.u128WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.u128Div(a, b)); + } else if (_31 === 4) { + _30(out, rt.u128Rem(a, b)); + } else if (_31 === 5) { + const part40 = rt.u128WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, rt.u128Not(a)); + } else if (_31 === 7) { + _30(out, rt.u128And(a, b)); + } else if (_31 === 8) { + _30(out, rt.u128Or(a, b)); + } else if (_31 === 9) { + _30(out, rt.u128Xor(a, b)); + } else if (_31 === 10) { + _30(out, rt.u128Shl(a, n & 127)); + } else if (_31 === 11) { + _30(out, rt.u128Shr(a, n & 127)); + } else if (_31 === 12) { + let x: rt.u128 = a; + x = rt.u128WrappingAdd(x, b); + _30(out, x); + x = rt.u128WrappingMul(x, c); + _30(out, x); + x = rt.u128WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.u128 = a; + x2 = rt.u128Div(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.u128 = a; + x3 = rt.u128Rem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.u128 = a; + x4 = rt.u128And(x4, b); + x4 = rt.u128Or(x4, c); + x4 = rt.u128Xor(x4, b); + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.u128 = a; + x5 = rt.u128Shl(x5, n & 127); + _30(out, x5); + x5 = rt.u128Shr(x5, n & 127); + _30(out, x5); + _30(out, rt.u128Shl(a, 3)); + _30(out, rt.u128Shr(a, rt.usizeAdd(128, 1) & 127)); + } else if (_31 === 17) { + const part15 = rt.u128WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.u128WrappingSub(a, b); + _30(out, part16); + const part17 = rt.u128WrappingMul(a, c); + _30(out, part17); + const part18 = rt.u128WrappingSub(0, a); + _30(out, part18); + _30(out, rt.u128Not(b)); + _30(out, rt.u128Shl(a, n & 127)); + _30(out, rt.u128Shr(a, n & 127)); + _30(out, rt.u128Xor(a, c)); + let x6: rt.u128 = a; + x6 = rt.u128WrappingAdd(x6, b); + x6 = rt.u128Shl(x6, n & 127); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = rt.u128Eq(a, b); + const _194: boolean = !rt.u128Eq(a, b); + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.u128 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.u128 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_u128(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_u128(a), hashed$u128(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 16, true)); + while (true) { + const _258: rt.u128 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash128, rt.u128Eq)) as rt.HashSet, _267, undefined, undefined, 58720256); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u128Display(a, f), (f: rt.Formatter) => rt.u128Debug(b, f), (f: rt.Formatter) => rt.u128LowerHex(a, f), (f: rt.Formatter) => rt.u128UpperHex(b, f), (f: rt.Formatter) => rt.u128Octal(c, f), (f: rt.Formatter) => rt.u128Binary(a, f), (f: rt.Formatter) => rt.u128Display(b, f), (f: rt.Formatter) => rt.u128LowerHex(c, f), (f: rt.Formatter) => rt.u128Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.u128[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.u128WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.u128WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.u128WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.u128WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u128WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u128WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_u128(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_u128(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_u128(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_u128(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_u128(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_u128(x7), hashed$Wrapping_u128(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_u128(x7); + z._0 = rt.u128WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function usizes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.usize) => undefined = (out2: rt.ByteVec, v: rt.usize): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.usizeToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.usize = (at: rt.usize): rt.usize => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.usizeFromBeBytes(buf); + }; + const _8: [rt.usize, rt.usize, rt.usize] = [take(0), take(4), take(2 * 4)]; + const a: rt.usize = _8[0]; + const b: rt.usize = _8[1]; + const c: rt.usize = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 4, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.usizeWrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.usizeWrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.usizeWrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + _30(out, rt.usizeDiv(a, b)); + } else if (_31 === 4) { + _30(out, rt.usizeRem(a, b)); + } else if (_31 === 5) { + const part40 = rt.usizeWrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a >>> 0); + } else if (_31 === 7) { + _30(out, (a & b) >>> 0); + } else if (_31 === 8) { + _30(out, (a | b) >>> 0); + } else if (_31 === 9) { + _30(out, (a ^ b) >>> 0); + } else if (_31 === 10) { + _30(out, rt.usizeShl(a, n & 31)); + } else if (_31 === 11) { + _30(out, rt.usizeShr(a, n & 31)); + } else if (_31 === 12) { + let x: rt.usize = a; + x = rt.usizeWrappingAdd(x, b); + _30(out, x); + x = rt.usizeWrappingMul(x, c); + _30(out, x); + x = rt.usizeWrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.usize = a; + x2 = rt.usizeDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.usize = a; + x3 = rt.usizeRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.usize = a; + x4 = (x4 & b) >>> 0; + x4 = (x4 | c) >>> 0; + x4 = (x4 ^ b) >>> 0; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.usize = a; + x5 = rt.usizeShl(x5, n & 31); + _30(out, x5); + x5 = rt.usizeShr(x5, n & 31); + _30(out, x5); + _30(out, (a << 3) >>> 0); + _30(out, rt.usizeShr(a, rt.usizeAdd(32, 1) & 31)); + } else if (_31 === 17) { + const part15 = rt.usizeWrappingAdd(a, b); + _30(out, part15); + const part16 = rt.usizeWrappingSub(a, b); + _30(out, part16); + const part17 = rt.usizeWrappingMul(a, c); + _30(out, part17); + const part18 = rt.usizeWrappingSub(0, a); + _30(out, part18); + _30(out, ~b >>> 0); + _30(out, rt.usizeShl(a, n & 31)); + _30(out, rt.usizeShr(a, n & 31)); + _30(out, (a ^ c) >>> 0); + let x6: rt.usize = a; + x6 = rt.usizeWrappingAdd(x6, b); + x6 = rt.usizeShl(x6, n & 31); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.usize = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.usize = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_usize(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_usize(a), hashed$usize(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 4, true)); + while (true) { + const _258: rt.usize | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _267, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.usizeDisplay(a, f), (f: rt.Formatter) => rt.usizeDebug(b, f), (f: rt.Formatter) => rt.usizeLowerHex(a, f), (f: rt.Formatter) => rt.usizeUpperHex(b, f), (f: rt.Formatter) => rt.usizeOctal(c, f), (f: rt.Formatter) => rt.usizeBinary(a, f), (f: rt.Formatter) => rt.usizeDisplay(b, f), (f: rt.Formatter) => rt.usizeLowerHex(c, f), (f: rt.Formatter) => rt.usizeDebug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.usize[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.usizeWrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.usizeWrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.usizeWrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.usizeWrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.usizeWrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.usizeWrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_usize(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_usize(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_usize(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_usize(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_usize(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_usize(x7), hashed$Wrapping_usize(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_usize(x7); + z._0 = rt.usizeWrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function i8s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.i8) => undefined = (out2: rt.ByteVec, v: rt.i8): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i8ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i8 = (at: rt.usize): rt.i8 => { + const buf: Uint8Array = Uint8Array.of(0); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i8FromBeBytes(buf); + }; + const _8: [rt.i8, rt.i8, rt.i8] = [take(0), take(1), take(2 * 1)]; + const a: rt.i8 = _8[0]; + const b: rt.i8 = _8[1]; + const c: rt.i8 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 1, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.i8WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.i8WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.i8WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.i8WrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.i8WrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.i8WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.i8Shl(a, n & 7)); + } else if (_31 === 11) { + _30(out, rt.i8Shr(a, n & 7)); + } else if (_31 === 12) { + let x: rt.i8 = a; + x = rt.i8WrappingAdd(x, b); + _30(out, x); + x = rt.i8WrappingMul(x, c); + _30(out, x); + x = rt.i8WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.i8 = a; + x2 = rt.i8WrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.i8 = a; + x3 = rt.i8WrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.i8 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.i8 = a; + x5 = rt.i8Shl(x5, n & 7); + _30(out, x5); + x5 = rt.i8Shr(x5, n & 7); + _30(out, x5); + _30(out, (a << 3 << 24) >> 24); + _30(out, rt.i8Shr(a, rt.usizeAdd(8, 1) & 7)); + } else if (_31 === 17) { + const part15 = rt.i8WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.i8WrappingSub(a, b); + _30(out, part16); + const part17 = rt.i8WrappingMul(a, c); + _30(out, part17); + const part18 = rt.i8WrappingSub(0, a); + _30(out, part18); + _30(out, ~b); + _30(out, rt.i8Shl(a, n & 7)); + _30(out, rt.i8Shr(a, n & 7)); + _30(out, a ^ c); + let x6: rt.i8 = a; + x6 = rt.i8WrappingAdd(x6, b); + x6 = rt.i8Shl(x6, n & 7); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.i8 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.i8 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_i8(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_i8(a), hashed$i8(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 1, true)); + while (true) { + const _258: rt.i8 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash8, rt.same)) as rt.HashSet, _267, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i8Display(a, f), (f: rt.Formatter) => rt.i8Debug(b, f), (f: rt.Formatter) => rt.i8LowerHex(a, f), (f: rt.Formatter) => rt.i8UpperHex(b, f), (f: rt.Formatter) => rt.i8Octal(c, f), (f: rt.Formatter) => rt.i8Binary(a, f), (f: rt.Formatter) => rt.i8Display(b, f), (f: rt.Formatter) => rt.i8LowerHex(c, f), (f: rt.Formatter) => rt.i8Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.i8[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.i8WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.i8WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.i8WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.i8WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i8WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i8WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_i8(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_i8(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_i8(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_i8(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_i8(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_i8(x7), hashed$Wrapping_i8(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_i8(x7); + z._0 = rt.i8WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function i16s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.i16) => undefined = (out2: rt.ByteVec, v: rt.i16): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i16ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i16 = (at: rt.usize): rt.i16 => { + const buf: Uint8Array = rt.bytes(2); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i16FromBeBytes(buf); + }; + const _8: [rt.i16, rt.i16, rt.i16] = [take(0), take(2), take(2 * 2)]; + const a: rt.i16 = _8[0]; + const b: rt.i16 = _8[1]; + const c: rt.i16 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 2, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.i16WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.i16WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.i16WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.i16WrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.i16WrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.i16WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.i16Shl(a, n & 15)); + } else if (_31 === 11) { + _30(out, rt.i16Shr(a, n & 15)); + } else if (_31 === 12) { + let x: rt.i16 = a; + x = rt.i16WrappingAdd(x, b); + _30(out, x); + x = rt.i16WrappingMul(x, c); + _30(out, x); + x = rt.i16WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.i16 = a; + x2 = rt.i16WrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.i16 = a; + x3 = rt.i16WrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.i16 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.i16 = a; + x5 = rt.i16Shl(x5, n & 15); + _30(out, x5); + x5 = rt.i16Shr(x5, n & 15); + _30(out, x5); + _30(out, (a << 3 << 16) >> 16); + _30(out, rt.i16Shr(a, rt.usizeAdd(16, 1) & 15)); + } else if (_31 === 17) { + const part15 = rt.i16WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.i16WrappingSub(a, b); + _30(out, part16); + const part17 = rt.i16WrappingMul(a, c); + _30(out, part17); + const part18 = rt.i16WrappingSub(0, a); + _30(out, part18); + _30(out, ~b); + _30(out, rt.i16Shl(a, n & 15)); + _30(out, rt.i16Shr(a, n & 15)); + _30(out, a ^ c); + let x6: rt.i16 = a; + x6 = rt.i16WrappingAdd(x6, b); + x6 = rt.i16Shl(x6, n & 15); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.i16 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.i16 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_i16(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_i16(a), hashed$i16(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 2, true)); + while (true) { + const _258: rt.i16 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash16, rt.same)) as rt.HashSet, _267, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i16Display(a, f), (f: rt.Formatter) => rt.i16Debug(b, f), (f: rt.Formatter) => rt.i16LowerHex(a, f), (f: rt.Formatter) => rt.i16UpperHex(b, f), (f: rt.Formatter) => rt.i16Octal(c, f), (f: rt.Formatter) => rt.i16Binary(a, f), (f: rt.Formatter) => rt.i16Display(b, f), (f: rt.Formatter) => rt.i16LowerHex(c, f), (f: rt.Formatter) => rt.i16Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.i16[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.i16WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.i16WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.i16WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.i16WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i16WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i16WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_i16(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_i16(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_i16(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_i16(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_i16(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_i16(x7), hashed$Wrapping_i16(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_i16(x7); + z._0 = rt.i16WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function i32s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.i32) => undefined = (out2: rt.ByteVec, v: rt.i32): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i32ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i32 = (at: rt.usize): rt.i32 => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i32FromBeBytes(buf); + }; + const _8: [rt.i32, rt.i32, rt.i32] = [take(0), take(4), take(2 * 4)]; + const a: rt.i32 = _8[0]; + const b: rt.i32 = _8[1]; + const c: rt.i32 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 4, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.i32WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.i32WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.i32WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.i32WrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.i32WrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.i32WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.i32Shl(a, n & 31)); + } else if (_31 === 11) { + _30(out, rt.i32Shr(a, n & 31)); + } else if (_31 === 12) { + let x: rt.i32 = a; + x = rt.i32WrappingAdd(x, b); + _30(out, x); + x = rt.i32WrappingMul(x, c); + _30(out, x); + x = rt.i32WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.i32 = a; + x2 = rt.i32WrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.i32 = a; + x3 = rt.i32WrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.i32 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.i32 = a; + x5 = rt.i32Shl(x5, n & 31); + _30(out, x5); + x5 = rt.i32Shr(x5, n & 31); + _30(out, x5); + _30(out, (a << 3) | 0); + _30(out, rt.i32Shr(a, rt.usizeAdd(32, 1) & 31)); + } else if (_31 === 17) { + const part15 = rt.i32WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.i32WrappingSub(a, b); + _30(out, part16); + const part17 = rt.i32WrappingMul(a, c); + _30(out, part17); + const part18 = rt.i32WrappingSub(0, a); + _30(out, part18); + _30(out, ~b); + _30(out, rt.i32Shl(a, n & 31)); + _30(out, rt.i32Shr(a, n & 31)); + _30(out, a ^ c); + let x6: rt.i32 = a; + x6 = rt.i32WrappingAdd(x6, b); + x6 = rt.i32Shl(x6, n & 31); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.i32 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.i32 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_i32(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_i32(a), hashed$i32(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 4, true)); + while (true) { + const _258: rt.i32 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _267, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i32Display(a, f), (f: rt.Formatter) => rt.i32Debug(b, f), (f: rt.Formatter) => rt.i32LowerHex(a, f), (f: rt.Formatter) => rt.i32UpperHex(b, f), (f: rt.Formatter) => rt.i32Octal(c, f), (f: rt.Formatter) => rt.i32Binary(a, f), (f: rt.Formatter) => rt.i32Display(b, f), (f: rt.Formatter) => rt.i32LowerHex(c, f), (f: rt.Formatter) => rt.i32Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.i32[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.i32WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.i32WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.i32WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.i32WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i32WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i32WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_i32(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_i32(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_i32(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_i32(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_i32(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_i32(x7), hashed$Wrapping_i32(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_i32(x7); + z._0 = rt.i32WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function i64s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.i64) => undefined = (out2: rt.ByteVec, v: rt.i64): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i64ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i64 = (at: rt.usize): rt.i64 => { + const buf: Uint8Array = rt.bytes(8); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i64FromBeBytes(buf); + }; + const _8: [rt.i64, rt.i64, rt.i64] = [take(0), take(8), take(2 * 8)]; + const a: rt.i64 = _8[0]; + const b: rt.i64 = _8[1]; + const c: rt.i64 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 8, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.i64WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.i64WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.i64WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.i64WrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.i64WrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.i64WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, rt.i64Not(a)); + } else if (_31 === 7) { + _30(out, rt.i64And(a, b)); + } else if (_31 === 8) { + _30(out, rt.i64Or(a, b)); + } else if (_31 === 9) { + _30(out, rt.i64Xor(a, b)); + } else if (_31 === 10) { + _30(out, rt.i64Shl(a, n & 63)); + } else if (_31 === 11) { + _30(out, rt.i64Shr(a, n & 63)); + } else if (_31 === 12) { + let x: rt.i64 = a; + x = rt.i64WrappingAdd(x, b); + _30(out, x); + x = rt.i64WrappingMul(x, c); + _30(out, x); + x = rt.i64WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.i64 = a; + x2 = rt.i64WrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.i64 = a; + x3 = rt.i64WrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.i64 = a; + x4 = rt.i64And(x4, b); + x4 = rt.i64Or(x4, c); + x4 = rt.i64Xor(x4, b); + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.i64 = a; + x5 = rt.i64Shl(x5, n & 63); + _30(out, x5); + x5 = rt.i64Shr(x5, n & 63); + _30(out, x5); + _30(out, rt.i64Shl(a, 3)); + _30(out, rt.i64Shr(a, rt.usizeAdd(64, 1) & 63)); + } else if (_31 === 17) { + const part15 = rt.i64WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.i64WrappingSub(a, b); + _30(out, part16); + const part17 = rt.i64WrappingMul(a, c); + _30(out, part17); + const part18 = rt.i64WrappingSub(0, a); + _30(out, part18); + _30(out, rt.i64Not(b)); + _30(out, rt.i64Shl(a, n & 63)); + _30(out, rt.i64Shr(a, n & 63)); + _30(out, rt.i64Xor(a, c)); + let x6: rt.i64 = a; + x6 = rt.i64WrappingAdd(x6, b); + x6 = rt.i64Shl(x6, n & 63); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = rt.i64Eq(a, b); + const _194: boolean = !rt.i64Eq(a, b); + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.i64 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.i64 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_i64(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_i64(a), hashed$i64(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 8, true)); + while (true) { + const _258: rt.i64 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash64, rt.i64Eq)) as rt.HashSet, _267, undefined, undefined, 117440512); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i64Display(a, f), (f: rt.Formatter) => rt.i64Debug(b, f), (f: rt.Formatter) => rt.i64LowerHex(a, f), (f: rt.Formatter) => rt.i64UpperHex(b, f), (f: rt.Formatter) => rt.i64Octal(c, f), (f: rt.Formatter) => rt.i64Binary(a, f), (f: rt.Formatter) => rt.i64Display(b, f), (f: rt.Formatter) => rt.i64LowerHex(c, f), (f: rt.Formatter) => rt.i64Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.i64[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.i64WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.i64WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.i64WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.i64WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i64WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i64WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_i64(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_i64(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_i64(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_i64(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_i64(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_i64(x7), hashed$Wrapping_i64(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_i64(x7); + z._0 = rt.i64WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function i128s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.i128) => undefined = (out2: rt.ByteVec, v: rt.i128): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i128 = (at: rt.usize): rt.i128 => { + const buf: Uint8Array = rt.bytes(16); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i128FromBeBytes(buf); + }; + const _8: [rt.i128, rt.i128, rt.i128] = [take(0), take(16), take(2 * 16)]; + const a: rt.i128 = _8[0]; + const b: rt.i128 = _8[1]; + const c: rt.i128 = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 16, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.i128WrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.i128WrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.i128WrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.i128WrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.i128WrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.i128WrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, rt.i128Not(a)); + } else if (_31 === 7) { + _30(out, rt.i128And(a, b)); + } else if (_31 === 8) { + _30(out, rt.i128Or(a, b)); + } else if (_31 === 9) { + _30(out, rt.i128Xor(a, b)); + } else if (_31 === 10) { + _30(out, rt.i128Shl(a, n & 127)); + } else if (_31 === 11) { + _30(out, rt.i128Shr(a, n & 127)); + } else if (_31 === 12) { + let x: rt.i128 = a; + x = rt.i128WrappingAdd(x, b); + _30(out, x); + x = rt.i128WrappingMul(x, c); + _30(out, x); + x = rt.i128WrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.i128 = a; + x2 = rt.i128WrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.i128 = a; + x3 = rt.i128WrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.i128 = a; + x4 = rt.i128And(x4, b); + x4 = rt.i128Or(x4, c); + x4 = rt.i128Xor(x4, b); + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.i128 = a; + x5 = rt.i128Shl(x5, n & 127); + _30(out, x5); + x5 = rt.i128Shr(x5, n & 127); + _30(out, x5); + _30(out, rt.i128Shl(a, 3)); + _30(out, rt.i128Shr(a, rt.usizeAdd(128, 1) & 127)); + } else if (_31 === 17) { + const part15 = rt.i128WrappingAdd(a, b); + _30(out, part15); + const part16 = rt.i128WrappingSub(a, b); + _30(out, part16); + const part17 = rt.i128WrappingMul(a, c); + _30(out, part17); + const part18 = rt.i128WrappingSub(0, a); + _30(out, part18); + _30(out, rt.i128Not(b)); + _30(out, rt.i128Shl(a, n & 127)); + _30(out, rt.i128Shr(a, n & 127)); + _30(out, rt.i128Xor(a, c)); + let x6: rt.i128 = a; + x6 = rt.i128WrappingAdd(x6, b); + x6 = rt.i128Shl(x6, n & 127); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = rt.i128Eq(a, b); + const _194: boolean = !rt.i128Eq(a, b); + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.i128 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.i128 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_i128(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_i128(a), hashed$i128(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 16, true)); + while (true) { + const _258: rt.i128 | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash128, rt.i128Eq)) as rt.HashSet, _267, undefined, undefined, 58720256); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i128Display(a, f), (f: rt.Formatter) => rt.i128Debug(b, f), (f: rt.Formatter) => rt.i128LowerHex(a, f), (f: rt.Formatter) => rt.i128UpperHex(b, f), (f: rt.Formatter) => rt.i128Octal(c, f), (f: rt.Formatter) => rt.i128Binary(a, f), (f: rt.Formatter) => rt.i128Display(b, f), (f: rt.Formatter) => rt.i128LowerHex(c, f), (f: rt.Formatter) => rt.i128Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.i128[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.i128WrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.i128WrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.i128WrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.i128WrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i128WrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.i128WrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_i128(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_i128(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_i128(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_i128(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_i128(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_i128(x7), hashed$Wrapping_i128(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_i128(x7); + z._0 = rt.i128WrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +/** + * Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + * shift amount, which may pass the width many times over. + */ +export function isizes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _30: (a0: rt.ByteVec, a1: rt.isize) => undefined = (out2: rt.ByteVec, v: rt.isize): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.isizeToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.isize = (at: rt.usize): rt.isize => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.isizeFromBeBytes(buf); + }; + const _8: [rt.isize, rt.isize, rt.isize] = [take(0), take(4), take(2 * 4)]; + const a: rt.isize = _8[0]; + const b: rt.isize = _8[1]; + const c: rt.isize = _8[2]; + const byte: (a0: rt.usize) => rt.u8 = (i2: rt.usize): rt.u8 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(3 * 4, i2)), 0); + }; + const n: rt.usize = ((byte(1) << 24) | byte(0)) >>> 0 as rt.usize; + const _31: rt.u8 = rt.u8Rem(kind, 24); + if (_31 === 0) { + const part45 = rt.isizeWrappingAdd(a, b); + _30(out, part45); + } else if (_31 === 1) { + const part44 = rt.isizeWrappingSub(a, b); + _30(out, part44); + } else if (_31 === 2) { + const part43 = rt.isizeWrappingMul(a, b); + _30(out, part43); + } else if (_31 === 3) { + const part42 = rt.isizeWrappingDiv(a, b); + _30(out, part42); + } else if (_31 === 4) { + const part41 = rt.isizeWrappingRem(a, b); + _30(out, part41); + } else if (_31 === 5) { + const part40 = rt.isizeWrappingSub(0, a); + _30(out, part40); + } else if (_31 === 6) { + _30(out, ~a); + } else if (_31 === 7) { + _30(out, a & b); + } else if (_31 === 8) { + _30(out, a | b); + } else if (_31 === 9) { + _30(out, a ^ b); + } else if (_31 === 10) { + _30(out, rt.isizeShl(a, n & 31)); + } else if (_31 === 11) { + _30(out, rt.isizeShr(a, n & 31)); + } else if (_31 === 12) { + let x: rt.isize = a; + x = rt.isizeWrappingAdd(x, b); + _30(out, x); + x = rt.isizeWrappingMul(x, c); + _30(out, x); + x = rt.isizeWrappingSub(x, b); + _30(out, x); + } else if (_31 === 13) { + let x2: rt.isize = a; + x2 = rt.isizeWrappingDiv(x2, b); + _30(out, x2); + } else if (_31 === 14) { + let x3: rt.isize = a; + x3 = rt.isizeWrappingRem(x3, b); + _30(out, x3); + } else if (_31 === 15) { + let x4: rt.isize = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _30(out, x4); + } else if (_31 === 16) { + let x5: rt.isize = a; + x5 = rt.isizeShl(x5, n & 31); + _30(out, x5); + x5 = rt.isizeShr(x5, n & 31); + _30(out, x5); + _30(out, (a << 3) | 0); + _30(out, rt.isizeShr(a, rt.usizeAdd(32, 1) & 31)); + } else if (_31 === 17) { + const part15 = rt.isizeWrappingAdd(a, b); + _30(out, part15); + const part16 = rt.isizeWrappingSub(a, b); + _30(out, part16); + const part17 = rt.isizeWrappingMul(a, c); + _30(out, part17); + const part18 = rt.isizeWrappingSub(0, a); + _30(out, part18); + _30(out, ~b); + _30(out, rt.isizeShl(a, n & 31)); + _30(out, rt.isizeShr(a, n & 31)); + _30(out, a ^ c); + let x6: rt.isize = a; + x6 = rt.isizeWrappingAdd(x6, b); + x6 = rt.isizeShl(x6, n & 31); + _30(out, x6); + } else if (_31 === 18) { + const _191: boolean = a === b; + const _194: boolean = a !== b; + const _197: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _200: boolean = order !== undefined && order <= 0; + const _203: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_191, _194, _197, _200, _203, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _219: boolean | rt.Done = iter.next(); + if (_219 === rt.DONE) { + break; + } + rt.byteVecPush(out, _219 ? 1 : 0); + } + const part12 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _30(out, part12); + const part13 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _30(out, part13); + const _237: rt.isize = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _238: rt.isize = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part14 = rt.ordClamp(a, _237, _238, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _30(out, part14); + } else if (_31 === 19) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$Wrapping_isize(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$Wrapping_isize(a), hashed$isize(a)) ? 1 : 0); + const _253: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _253, true, undefined, undefined, 4, true)); + while (true) { + const _258: rt.isize | rt.Done = iter2.next(); + if (_258 === rt.DONE) { + break; + } + _30(out, _258); + } + const _267: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _267, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_31 === 20) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.isizeDisplay(a, f), (f: rt.Formatter) => rt.isizeDebug(b, f), (f: rt.Formatter) => rt.isizeLowerHex(a, f), (f: rt.Formatter) => rt.isizeUpperHex(b, f), (f: rt.Formatter) => rt.isizeOctal(c, f), (f: rt.Formatter) => rt.isizeBinary(a, f), (f: rt.Formatter) => rt.isizeDisplay(b, f), (f: rt.Formatter) => rt.isizeLowerHex(c, f), (f: rt.Formatter) => rt.isizeDebug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_31 === 21) { + const all: rt.isize[] = [a, b, c]; + const part6 = rt.iterSum(rt.iterSlice(all), rt.isizeWrappingAdd, 0); + _30(out, part6); + const part7 = rt.iterSum(rt.iterSlice(all), rt.isizeWrappingAdd, 0); + _30(out, part7); + const part8 = rt.iterProduct(rt.iterSlice(all), rt.isizeWrappingMul, 1); + _30(out, part8); + const part9 = rt.iterProduct(rt.iterSlice(all), rt.isizeWrappingMul, 1); + _30(out, part9); + const part10 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.isizeWrappingAdd, 0); + _30(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.isizeWrappingMul, 1); + _30(out, part11); + } else if (_31 === 22) { + _30(out, 0); + _30(out, a); + _30(out, a); + } else { + const _357: [Tick.Tick, Tick.Tick] = [new Tick.Tick(a), new Tick.Tick(b)]; + const x7: Tick.Tick = _357[0]; + const y: Tick.Tick = _357[1]; + const _365: Tick.Tick = Tick.default$Default_isize(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => Tick.fmt$Debug_isize(x7, f), (f: rt.Formatter) => Tick.fmt$Debug_isize(_365, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, Tick.eq$PartialEq_isize(x7, y) ? 1 : 0); + rt.byteVecPush(out, Tick.cmp$Ord_isize(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$Tick_isize(x7), hashed$Wrapping_isize(a)) ? 1 : 0); + const z: Tick.Tick = copy$Tick_isize(x7); + z._0 = rt.isizeWrappingSub(z._0, y._0); + _30(out, z._0); + } +} + +//# sourceMappingURL=wraps.ts.map diff --git a/ts/fixtures/lang/src/collections.rs b/ts/fixtures/lang/src/collections.rs index cbc40a739..0fd419bf5 100644 --- a/ts/fixtures/lang/src/collections.rs +++ b/ts/fixtures/lang/src/collections.rs @@ -3,9 +3,11 @@ //! found through their translated `Hash` and `Eq` or ordered by their `Ord`. A hash //! map's iteration order is unspecified, so only what does not depend on it is written. +use std::borrow::Cow; use std::cmp::{Ordering, Reverse}; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque, btree_map, hash_map}; use std::hash::{DefaultHasher, Hash, Hasher}; +use std::num::Wrapping; use std::ops::Bound; use crate::generics::Wrap; @@ -1431,9 +1433,10 @@ impl PartialEq for Picky<'_> { impl Eq for Picky<'_> {} /// `==` and `!=` of what holds a `Picky`, whose `ne` std's of tuples, `Arc`s, `Rc`s, and -/// `Box`es call, and std's `==` of slices calls of each item, but which an `Option`'s and -/// a `Reverse`'s `ne`, as `!eq`, does not: of unequal lengths, empty, nested, and with -/// items `eq` and `ne` disagree on at the positions `kind` picks. +/// `Box`es call, and std's `==` of slices and `Cow`s of them calls of each item, but which +/// an `Option`'s, a `Reverse`'s, and a `Wrapping`'s `ne`, as `!eq`, does not: of unequal +/// lengths, empty, nested, and with items `eq` and `ne` disagree on at the positions +/// `kind` picks. pub fn own_nes(kind: u8, data: &[u8], out: &mut Vec) { use std::rc::Rc; use std::sync::Arc; @@ -1524,6 +1527,23 @@ pub fn own_nes(kind: u8, data: &[u8], out: &mut Vec) { put_eq(wrapped(&a) != wrapped(&b), &log, out); put_eq(wrapped(&a) == b, &log, out); put_eq(wrapped(&a) == &b[..], &log, out); + + // A `Wrapping`'s `ne` is `!eq`, and a `Cow<[T]>`, borrowed or owned, compares as its + // slice, whose `==` and `!=` call each item's `ne`, against a `Cow`, a slice, a `Vec`, + // and an array. + put_eq((Wrapping(one(&a, 0)),) != (Wrapping(one(&b, 0)),), &log, out); + put_eq(Wrapping(one(&a, 1)) == Wrapping(one(&b, 1)), &log, out); + let (ca, cb) = (Cow::Borrowed(&a[..]), Cow::<[Picky]>::Owned(b.clone())); + put_eq(ca == cb, &log, out); + put_eq(ca != cb, &log, out); + put_eq(ca == &b[..], &log, out); + put_eq(cb != a, &log, out); + put_eq(b == ca, &log, out); + put_eq(&a[..] != cb, &log, out); + put_eq(*cb == pa, &log, out); + let owned: Vec> = each(&a, |p| Cow::Owned(vec![p.clone()])); + let borrowed: Vec> = b.chunks(1).map(Cow::Borrowed).collect(); + put_eq(owned != borrowed, &log, out); } /// An item whose `ne` and `PartialOrd`'s tests see other remainders than its `eq` and diff --git a/ts/fixtures/lang/src/cows.rs b/ts/fixtures/lang/src/cows.rs index 4632867e6..d51dc5ad3 100644 --- a/ts/fixtures/lang/src/cows.rs +++ b/ts/fixtures/lang/src/cows.rs @@ -1,10 +1,13 @@ -//! `Cow`, borrowed and owned alike: made, read through `Deref`, compared, ordered, -//! hashed, printed, and held in a field and as a key, and changed through `to_mut`, which -//! leaves the text it borrowed as it was. Each case runs once borrowed and once owned. +//! `Cow` and `Cow<[T]>`, borrowed and owned alike: made, read through `Deref`, +//! compared, ordered, hashed, printed, and held in a field and as a key, and changed +//! through `to_mut`, which leaves what it borrowed as it was. Each case runs once borrowed +//! and once owned. -use std::borrow::Cow; +use std::borrow::{Borrow, Cow}; +use std::cell::Cell; use std::cmp::Ordering; use std::collections::{BTreeMap, HashSet}; +use std::hash::{DefaultHasher, Hash, Hasher}; use std::sync::Arc; use crate::fmt::put; @@ -175,3 +178,355 @@ pub fn cows(kind: u8, data: &[u8], out: &mut Vec) { } } } + +/// A slice of `u16`s read from `data`, two bytes each. +fn words(data: &[u8]) -> Vec { + data.chunks(2) + .map(|c| u16::from(c[0]) << 8 | u16::from(*c.last().unwrap())) + .collect() +} + +fn cow_of(v: &[u16], owned: bool) -> Cow<'_, [u16]> { + match owned { + true => Cow::Owned(v.to_vec()), + false => Cow::Borrowed(v), + } +} + +fn put_words(out: &mut Vec, v: &[u16]) { + out.push(v.len() as u8); + for w in v { + out.extend_from_slice(&w.to_be_bytes()); + } +} + +fn hashed(v: &T) -> u64 { + let mut h = DefaultHasher::new(); + v.hash(&mut h); + h.finish() +} + +/// A `Cow<[T]>` in a field, with each derived impl reading it. +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct Run<'a> { + words: Cow<'a, [u16]>, +} + +impl Run<'_> { + /// Through `to_mut` of the field. + fn bump(&mut self) { + for w in self.words.to_mut().iter_mut() { + *w = w.wrapping_add(1); + } + } +} + +/// An item whose `Clone` and `Drop` log, so what a `Cow` clones and drops shows. +struct Tally<'a>(u8, &'a Cell); + +impl Clone for Tally<'_> { + fn clone(&self) -> Self { + self.1.set(self.1.get() * 7 + u32::from(self.0) + 1); + Tally(self.0.wrapping_add(100), self.1) + } +} + +impl Drop for Tally<'_> { + fn drop(&mut self) { + self.1.set(self.1.get() * 3 + u32::from(self.0)); + } +} + +/// `Cow<[u16]>`: made each way, collected, and read, changed through `to_mut`, compared, +/// ordered, and hashed against each sequence, matched on, and held in a field and as a key. +pub fn slices(kind: u8, data: &[u8], out: &mut Vec) { + let v = words(data); + let owned = kind & 0x80 != 0; + let half = &v[..v.len() / 2]; + match kind % 6 { + 0 => { + // What reads the slice, and what makes one from it or out of it. + let c = cow_of(&v, owned); + out.push(c.len() as u8); + out.push(c.is_empty() as u8); + out.extend_from_slice(&c.iter().fold(0u16, |a, w| a.wrapping_add(*w)).to_be_bytes()); + out.extend_from_slice(&c.first().copied().unwrap_or(0xffff).to_be_bytes()); + put_words(out, c.as_ref()); + put_words(out, c.borrow()); + put_words(out, &c.clone()); + put(out, &format!("{c:?}")); + let held: Vec = c.into_owned(); + put_words(out, &held); + let empty: Cow<'_, [u16]> = Default::default(); + put_words(out, &empty); + let from_slice: Cow<'_, [u16]> = Cow::from(half); + let from_vec: Cow<'_, [u16]> = Cow::from(v.clone()); + let from_ref: Cow<'_, [u16]> = Cow::from(&v); + let from_array: Cow<'_, [u16]> = Cow::from(&[3u16, 1, 4]); + let collected: Cow<'_, [u16]> = v.iter().rev().copied().collect(); + for c in [&from_slice, &from_vec, &from_ref, &from_array, &collected] { + put_words(out, c); + } + put_words(out, &Vec::from(cow_of(half, owned))); + } + 1 => { + // `to_mut` of a local, twice, of a vector's element, and of a field, each of + // which leaves the slice it borrowed as it was. + let mut c = cow_of(&v, owned); + c.to_mut().push(7); + let m = c.to_mut(); + if let Some(w) = m.first_mut() { + *w ^= 0xffff; + } + m.push(9); + put_words(out, &c); + put_words(out, &v); + let mut cs = vec![cow_of(half, owned), cow_of(&v, !owned)]; + cs[1].to_mut().truncate(1); + for c in &cs { + put_words(out, c); + } + let mut run = Run { + words: cow_of(half, owned), + }; + let before = run.clone(); + run.bump(); + put(out, &format!("{run:?} {before:?}")); + put_words(out, half); + put_words(out, &c.into_owned()); + } + 2 => { + // Comparisons with each sequence, either way around, and ordering and hashing. + let a = cow_of(&v, owned); + let b = cow_of(half, !owned); + let array = [v.first().copied().unwrap_or(0); 2]; + let bits = [ + a == b, + a != b, + a == half, + a == &v[..], + a == v, + a != half.to_vec(), + half == b, + v == a, + &v[..] != a, + *a == array, + *b == array[..half.len().min(2)], + a.cmp(&b).is_lt(), + a.partial_cmp(&b) == Some(Ordering::Greater), + a < b, + a >= b, + hashed(&a) == hashed(&v[..]), + hashed(&b) == hashed(half), + a.clone().max(b.clone()) == b, + ]; + for bit in bits { + out.push(bit as u8); + } + } + 3 => { + // Matched on, by reference, in place, and by value. + let mut c = cow_of(&v, owned); + match &c { + Cow::Borrowed(s) => put_words(out, s), + Cow::Owned(o) => { + out.push(0xee); + put_words(out, o); + } + } + if let Cow::Owned(o) = &mut c { + o.push(5); + } + put_words(out, &c); + // A payload replaced whole, which leaves a clone as it was. + let kept = c.clone(); + if let Cow::Borrowed(s) = &mut c { + *s = half; + } + if let Cow::Owned(o) = &mut c { + *o = half.iter().rev().copied().collect(); + } + put_words(out, &c); + put_words(out, &kept); + // A payload passed on as a `&mut`, then replaced and read through the same + // borrow, which leaves a clone as it was too. + let mut e = cow_of(&v, !owned); + let kept = e.clone(); + match &mut e { + Cow::Borrowed(s) => { + repoint(s, half); + out.push(s.len() as u8); + *s = &v[..v.len().min(1)]; + out.push(s.len() as u8); + } + Cow::Owned(o) => { + o.truncate(1); + *o = half.to_vec(); + out.push(o.len() as u8); + } + } + put_words(out, &e); + put_words(out, &kept); + let made: Vec = match c { + Cow::Borrowed(s) => s.iter().rev().copied().collect(), + Cow::Owned(o) => o, + }; + put_words(out, &made); + let mut d = cow_of(half, !owned); + d = match d { + Cow::Borrowed(s) if s.len() > 1 => Cow::Owned(s[1..].to_vec()), + d => d, + }; + put_words(out, &d); + } + 4 => { + // Keys: counted in a B-tree, found by a `Cow`, and a field's hash in a set. + let mut counts: BTreeMap, u8> = BTreeMap::new(); + for (i, part) in v.chunks(2).enumerate() { + *counts.entry(cow_of(part, (i % 2 == 1) == owned)).or_insert(0) += 1; + } + for (k, n) in &counts { + put_words(out, k); + out.push(*n); + } + out.push(counts.get(&cow_of(half, owned)).copied().unwrap_or(0xff)); + let mut runs = HashSet::new(); + for part in v.chunks(3) { + runs.insert(Run { + words: cow_of(part, owned), + }); + } + out.push(runs.len() as u8); + out.push(runs.contains(&Run { + words: cow_of(&v[..v.len().min(3)], !owned), + }) as u8); + put(out, &format!("{:?}", Run::default())); + } + _ => { + // What a `Cow` of items whose `Clone` and `Drop` log clones and drops: a borrowed + // one clones each item it changes or gives up, and an owned one drops them. + let log = Cell::new(0); + { + let items: Vec = data.iter().take(4).map(|&b| Tally(b, &log)).collect(); + let mut c = match owned { + true => Cow::Owned(items.clone()), + false => Cow::Borrowed(&items[..]), + }; + out.extend_from_slice(&log.replace(0).to_be_bytes()); + let copy = c.clone(); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + drop(copy); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + if let Cow::Borrowed(s) = &mut c { + *s = &items[items.len().min(1)..]; + } + out.push(c.len() as u8); + c.to_mut().pop(); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + c.to_mut().push(Tally(9, &log)); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + // The `Vec` it owned drops as its payload is replaced. + if let Cow::Owned(o) = &mut c { + *o = vec![Tally(7, &log), Tally(8, &log)]; + } + out.extend_from_slice(&log.replace(0).to_be_bytes()); + let kept = c.into_owned(); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + out.extend(kept.iter().map(|t| t.0)); + drop(kept); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + let shared = Cow::Borrowed(&items[..]); + let cloned = shared.into_owned(); + out.extend_from_slice(&log.replace(0).to_be_bytes()); + drop(cloned); + } + out.extend_from_slice(&log.get().to_be_bytes()); + } + } +} + +/// Point `s` at `to`, through the `&mut` a caller passes. +fn repoint<'a, T>(s: &mut &'a [T], to: &'a [T]) { + *s = to; +} + +fn made(s: &[u8], owned: bool) -> Cow<'_, [u8]> { + match owned { + true => Cow::Owned(s.to_vec()), + false => Cow::Borrowed(s), + } +} + +/// `Cow<[u8]>` as bytes: made and collected, read, changed through `to_mut` without +/// touching what it borrowed, compared against each form of bytes, hashed, printed, and +/// matched on. +pub fn bytes(kind: u8, data: &[u8], out: &mut Vec) { + let owned = kind & 0x80 != 0; + let half = &data[..data.len() / 2]; + let mut c = made(data, owned); + out.push(c.len() as u8); + out.extend_from_slice(&c[..c.len().min(3)]); + put(out, &format!("{c:?} {:?}", made(half, !owned))); + let bits = [ + c == made(half, !owned), + c == data, + c == data.to_vec(), + c != half, + *c == [0u8; 2], + data == c, + data.to_vec() != c, + c.cmp(&made(half, owned)).is_gt(), + hashed(&c) == hashed(data), + hashed(&c) == hashed(&data.to_vec()), + matches!(c, Cow::Borrowed(_)), + ]; + for bit in bits { + out.push(bit as u8); + } + // A payload replaced whole, which leaves a clone as it was. + if kind & 0x40 != 0 { + let kept = c.clone(); + match &mut c { + Cow::Borrowed(s) => *s = half, + Cow::Owned(o) => *o = half.to_vec(), + } + out.extend_from_slice(&kept); + let mut e = made(data, !owned); + match &mut e { + Cow::Borrowed(s) => repoint(s, half), + Cow::Owned(o) => o.truncate(1), + } + out.extend_from_slice(&e); + } + match kind % 3 { + 0 => { + c.to_mut().push(kind); + c.to_mut().extend_from_slice(half); + out.extend_from_slice(&c); + } + 1 => { + if let Some(b) = c.to_mut().first_mut() { + *b = b.wrapping_add(1); + } + let v: Vec = c.into_owned(); + out.extend_from_slice(&v); + } + _ => match c { + Cow::Borrowed(s) => out.extend(s.iter().rev()), + Cow::Owned(mut v) => { + v.reverse(); + out.extend_from_slice(&v); + } + }, + } + out.extend_from_slice(data); + let empty: Cow<'_, [u8]> = Cow::default(); + out.push(empty.len() as u8); + let held = data.to_vec(); + let from_ref: Cow<'_, [u8]> = Cow::from(&held); + let from_array: Cow<'_, [u8]> = Cow::from(&[7u8, 8]); + let collected: Cow<'_, [u8]> = data.iter().map(|b| b ^ 1).collect(); + for c in [&from_ref, &from_array, &collected] { + out.extend_from_slice(c); + } +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index d350073ef..d01daaa50 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -5,7 +5,7 @@ use crate::{ arrays, atomics, borrows, bounds, captures, cells, chars, chunks, clones, collections, combinators, counts, cows, cycles, defaults, durations, dyns, edits, errors, floats, fmt, folds, generics, hashes, hints, holds, ints, iters, keys, locals, locks, nested, objects, orders, pointers, refs, shapes, singles, slices, splits, statics, strs, utf8, - wrappers, zeros, + wrappers, wraps, zeros, }; /// The native side's entry: [`run`], except that a case starting with 0xff prints a @@ -189,6 +189,20 @@ fn cases() -> Vec<(&'static str, Case)> { ("collections::unlike_compares", collections::unlike_compares), ("cycles::cycles", cycles::cycles), ("pointers::lapsed", |_, data, out| pointers::lapsed(data, out)), + ("cows::slices", cows::slices), + ("cows::bytes", cows::bytes), + ("wraps::u8s", wraps::u8s), + ("wraps::u16s", wraps::u16s), + ("wraps::u32s", wraps::u32s), + ("wraps::u64s", wraps::u64s), + ("wraps::u128s", wraps::u128s), + ("wraps::usizes", wraps::usizes), + ("wraps::i8s", wraps::i8s), + ("wraps::i16s", wraps::i16s), + ("wraps::i32s", wraps::i32s), + ("wraps::i64s", wraps::i64s), + ("wraps::i128s", wraps::i128s), + ("wraps::isizes", wraps::isizes), ] } diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index 70d099d87..da6705311 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -71,6 +71,7 @@ mod utf8; #[path = "../../wasm.rs"] mod wasm; mod wrappers; +mod wraps; mod zeros; #[cfg(target_arch = "wasm32")] use harness::entry; diff --git a/ts/fixtures/lang/src/wraps.rs b/ts/fixtures/lang/src/wraps.rs new file mode 100644 index 000000000..93287174f --- /dev/null +++ b/ts/fixtures/lang/src/wraps.rs @@ -0,0 +1,177 @@ +//! `Wrapping` of every integer width: its operators and their assign forms, which wrap +//! where the integer's would overflow and mask a shift's amount to the width, its +//! comparisons, hash, and formatting, its `Sum` and `Product`, and a field of one. + +use std::collections::{BTreeSet, HashSet}; +use std::hash::{DefaultHasher, Hash, Hasher}; +use std::num::Wrapping; + +/// A `Wrapping` in a field, with each derived impl reading it. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct Tick(Wrapping); + +fn hashed(v: &T) -> u64 { + let mut h = DefaultHasher::new(); + v.hash(&mut h); + h.finish() +} + +macro_rules! wraps { + ($name:ident, $t:ty) => { + /// Apply operation `kind` to `Wrapping`s taken from `data`: three operands, then a + /// shift amount, which may pass the width many times over. + pub fn $name(kind: u8, data: &[u8], out: &mut Vec) { + const N: usize = core::mem::size_of::<$t>(); + let take = |at: usize| { + let mut buf = [0u8; N]; + for (i, b) in buf.iter_mut().enumerate() { + *b = data.get(at + i).copied().unwrap_or(0); + } + Wrapping(<$t>::from_be_bytes(buf)) + }; + let (a, b, c) = (take(0), take(N), take(2 * N)); + let byte = |i: usize| data.get(3 * N + i).copied().unwrap_or(0); + let n = u32::from_be_bytes([byte(1), 0, 0, byte(0)]) as usize; + let put = |out: &mut Vec, v: Wrapping<$t>| out.extend_from_slice(&v.0.to_be_bytes()); + match kind % 24 { + 0 => put(out, a + b), + 1 => put(out, a - b), + 2 => put(out, a * b), + 3 => put(out, a / b), + 4 => put(out, a % b), + 5 => put(out, -a), + 6 => put(out, !a), + 7 => put(out, a & b), + 8 => put(out, a | b), + 9 => put(out, a ^ b), + 10 => put(out, a << n), + 11 => put(out, a >> n), + 12 => { + let mut x = a; + x += b; + put(out, x); + x *= c; + put(out, x); + x -= b; + put(out, x); + } + 13 => { + let mut x = a; + x /= b; + put(out, x); + } + 14 => { + let mut x = a; + x %= b; + put(out, x); + } + 15 => { + let mut x = a; + x &= b; + x |= c; + x ^= b; + put(out, x); + } + 16 => { + let mut x = a; + x <<= n; + put(out, x); + x >>= n; + put(out, x); + // Constant amounts, one past the width. + put(out, a << 3); + put(out, a >> (<$t>::BITS as usize + 1)); + } + 17 => { + // Through references, which std's impls forward. + put(out, &a + b); + put(out, a - &b); + put(out, &a * &c); + put(out, -&a); + put(out, !&b); + put(out, &a << n); + put(out, a >> &n); + put(out, &a ^ &c); + let mut x = a; + x += &b; + x <<= &n; + put(out, x); + } + 18 => { + let bits = [ + a == b, + a != b, + a < b, + a <= b, + a > b, + a >= b, + a.cmp(&b).is_lt(), + a.partial_cmp(&c).is_some_and(|o| o.is_gt()), + ]; + for bit in bits { + out.push(bit as u8); + } + put(out, a.max(b)); + put(out, a.min(c)); + put(out, a.clamp(b.min(c), b.max(c))); + } + 19 => { + out.extend_from_slice(&hashed(&a).to_be_bytes()); + out.push((hashed(&a) == hashed(&a.0)) as u8); + let set: BTreeSet> = [a, b, c, a].into_iter().collect(); + for v in &set { + put(out, *v); + } + let seen: HashSet> = [a, b].into_iter().collect(); + out.push(seen.contains(&c) as u8); + out.push(seen.len() as u8); + } + 20 => { + let text = format!("{a} {b:?} {a:x} {b:X} {c:o} {a:b} {b:>6} {c:#x} {a:08?} {b:+}"); + out.extend_from_slice(text.as_bytes()); + } + 21 => { + let all = [a, b, c]; + put(out, all.iter().sum::>()); + put(out, all.into_iter().sum::>()); + put(out, all.iter().product::>()); + put(out, all.into_iter().product::>()); + put(out, all[..0].iter().sum::>()); + put(out, all[..0].iter().product::>()); + } + 22 => { + let zero = Wrapping::<$t>::default(); + put(out, zero); + #[allow(clippy::clone_on_copy, reason = "the clone `Clone` makes")] + let copy = a.clone(); + put(out, copy); + put(out, Wrapping(a.0)); + } + _ => { + let (x, y) = (Tick(a), Tick(b)); + let text = format!("{x:?} {:?}", Tick::<$t>::default()); + out.extend_from_slice(text.as_bytes()); + out.push((x == y) as u8); + out.push(x.cmp(&y) as i8 as u8); + out.push((hashed(&x) == hashed(&a)) as u8); + let mut z = x; + z.0 -= y.0; + put(out, z.0); + } + } + } + }; +} + +wraps!(u8s, u8); +wraps!(u16s, u16); +wraps!(u32s, u32); +wraps!(u64s, u64); +wraps!(u128s, u128); +wraps!(usizes, usize); +wraps!(i8s, i8); +wraps!(i16s, i16); +wraps!(i32s, i32); +wraps!(i64s, i64); +wraps!(i128s, i128); +wraps!(isizes, isize); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index d90469c2c..65ef2f03c 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,6 +1,6 @@ # Census of `reject-fixture` -- Refusals: 126 +- Refusals: 125 - Function instances: 154 - Generic functions no instance reached, lowered over their type parameters: 10 @@ -31,7 +31,6 @@ | 1 | `BufMut::put` of `_` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported | fixtures/reject/src/lib.rs:402:2 | | 1 | `Bytes::from_owner` of `_`, which would drop with the last clone of what it makes, which is not supported | fixtures/reject/src/lib.rs:387:2 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:56:2 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:355:18 | | 1 | `_` is not supported: its `Pending` and `Ready` would both be `rt.OuterPending` | fixtures/reject/src/lib.rs:79:20 | | 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | fixtures/reject/src/lib.rs:31:2 | | 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `Pending` would be `rt.OuterPending` as `_` | fixtures/reject/src/lib.rs:510:2 | @@ -78,8 +77,8 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | | 22 | `(u32, u32)` | fixtures/reject/src/lib.rs:623:10 | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:344:2 | | 6 | `f16` | fixtures/reject/src/lib.rs:7:14 | +| 6 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:344:2 | | 5 | `Gap` | fixtures/reject/src/lib.rs:928:10 | | 5 | `Option` | fixtures/reject/src/lib.rs:16:15 | | 5 | `u32` | fixtures/reject/src/lib.rs:570:27 | @@ -175,7 +174,6 @@ The type or module each refused type or path belongs to. | 1 | `Buf::copy_to_bytes` of `_`, a value JS copies, which is not supported | `Blank` | fixtures/reject/src/lib.rs:776:2 | | 1 | `BufMut::put` of `_` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported | `Counted` | fixtures/reject/src/lib.rs:402:2 | | 1 | `Bytes::from_owner` of `_`, which would drop with the last clone of what it makes, which is not supported | `std::sync::Arc` | fixtures/reject/src/lib.rs:387:2 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:355:18 | | 1 | `_` is not supported: its `Pending` and `Ready` would both be `rt.OuterPending` | `Poll` | fixtures/reject/src/lib.rs:79:20 | | 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:31:2 | | 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `Pending` would be `rt.OuterPending` as `_` | `Waiting`, `poll`, `Poll`, `rt.Poll`, `Poll` | fixtures/reject/src/lib.rs:510:2 | @@ -233,13 +231,13 @@ The type or module each refused type or path belongs to. | 1 | replacing the value behind a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:119:2 | | 1 | union `_`, whose fields overlap in `_` and `f64`, which JS keeps apart | `Bits`, `u32` | fixtures/reject/src/lib.rs:597:1 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:553:2 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:356:2 | | 1 | unsupported call to `_` | `::contains` | fixtures/reject/src/lib.rs:1009:32 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:382:2 | | 1 | unsupported call to `_` | `::is_sorted` | fixtures/reject/src/lib.rs:781:15 | | 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:906:10 | | 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:314:10 | | 1 | unsupported call to `_` | `std::any::TypeId::of` | fixtures/reject/src/lib.rs:553:17 | +| 1 | unsupported call to `_` | `std::borrow::Cow::is_borrowed` | fixtures/reject/src/lib.rs:356:2 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:167:8 | | 1 | unsupported call to `_` | `std::ops::Range::is_empty` | fixtures/reject/src/lib.rs:1014:9 | | 1 | unsupported call to `_` | `std::ops::RangeTo::contains` | fixtures/reject/src/lib.rs:1009:11 | @@ -256,7 +254,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:167:8: unsupported call to `std::ops::Range::::contains::` - fixtures/reject/src/lib.rs:314:10: unsupported call to `::hash::` -- fixtures/reject/src/lib.rs:356:2: unsupported call to ` as std::ops::Deref>::deref` +- fixtures/reject/src/lib.rs:356:2: unsupported call to `std::borrow::Cow::<'_, [u8]>::is_borrowed` - fixtures/reject/src/lib.rs:382:2: unsupported call to ` as std::cmp::PartialEq>::eq` - fixtures/reject/src/lib.rs:442:17: unsupported call to ` as std::iter::Iterator>::sum::` - fixtures/reject/src/lib.rs:442:38: unsupported call to ` as std::iter::Iterator>::sum::` @@ -454,12 +452,6 @@ The type or module each refused type or path belongs to. -
`_` is not supported yet (1) - -- fixtures/reject/src/lib.rs:355:18: `std::borrow::Cow<'_, [u8]>` is not supported yet - -
-
`_` is not supported: its `Pending` and `Ready` would both be `rt.OuterPending` (1) - fixtures/reject/src/lib.rs:79:20: `Poll>>>` is not supported: its `Pending` and `Ready` would both be `rt.OuterPending` diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 7c0ba0210..cc038d428 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -45,8 +45,7 @@ a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:346:27 a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:345:30 a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:351:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:355:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:356:2 +unsupported call to `std::borrow::Cow::<'_, [u8]>::is_borrowed` at fixtures/reject/src/lib.rs:356:2 constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:362:53 hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet at fixtures/reject/src/lib.rs:323:16 passing `{closure@fixtures/reject/src/lib.rs:332:28: 332: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:332:13 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 7da1fba03..183372dda 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -351,9 +351,9 @@ pub fn cow_borrowed(c: &std::borrow::Cow<'_, str>) -> bool { std::borrow::Cow::is_borrowed(c) } -/// Only a `Cow` has a JS value yet. -pub fn cow_bytes(c: std::borrow::Cow<'_, [u8]>) -> usize { - c.len() +/// A slice's tells its variants apart, but asking is unstable. +pub fn cow_bytes(c: &std::borrow::Cow<'_, [u8]>) -> bool { + std::borrow::Cow::is_borrowed(c) } /// Made where its type goes unchecked, as a local's, it is refused where it is made. diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 41f1c332b..3e6b1e452 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -1151,6 +1151,74 @@ export function byteVecDedupByKeyMut(v: ByteVec, key: (byte: Place) = byteVecDedupByMut(v, (a, b) => eq(key(a), key(b))); } +// Cows of slices. An owned one is its `Vec` and a borrowed one its slice, told apart by +// class: a `Cow<[u8]>` is an `rt.ByteVec` or an `rt.ByteSlice`, and any other is an array +// or the `rt.Borrowed` wrapping the array it borrows. + +/** + * The slice a `Cow<[T]>` borrows, which it clones before it changes. A `&mut` to the + * borrow writes `slice`, so no two `Cow`s share one. + */ +export class Borrowed { + slice: T[]; + + constructor(slice: T[]) { + this.slice = slice; + } +} + +/** `Cow<[T]>`: the `Vec` it owns, or the slice it borrows. */ +export type Cow = T[] | Borrowed; +/** `Cow<[u8]>`: the `Vec` it owns, or the bytes it borrows. */ +export type ByteCow = ByteVec | ByteSlice; + +/** `Deref` of a `Cow<[T]>`: its slice. */ +export function cowSlice(c: Cow): T[] { + return c instanceof Borrowed ? c.slice : c; +} + +/** `Deref` of a `Cow<[u8]>`: its bytes. */ +export function byteCowSlice(c: ByteCow): ByteSlice { + return c instanceof ByteVec ? byteVecSlice(c) : c; +} + +/** `Cow::into_owned` of a `Cow<[T]>`: its `Vec`, or a clone of what it borrows, each item by `clone` if given. */ +export function cowIntoOwned(c: Cow, clone?: (item: T) => T): T[] { + if (!(c instanceof Borrowed)) return c; + return clone === undefined ? c.slice.slice() : c.slice.map(clone); +} + +/** `Cow::into_owned` of a `Cow<[u8]>`. */ +export function byteCowIntoOwned(c: ByteCow): ByteVec { + return c instanceof ByteVec ? c : byteSliceToByteVec(c); +} + +/** `Clone` of a `Cow<[T]>`: a borrow of the same slice, or a clone of its `Vec`. */ +export function cowClone(c: Cow, clone?: (item: T) => T): Cow { + if (c instanceof Borrowed) return new Borrowed(c.slice); + return clone === undefined ? c.slice() : c.map(clone); +} + +/** `Clone` of a `Cow<[u8]>`. */ +export function byteCowClone(c: ByteCow): ByteCow { + return c instanceof ByteVec ? byteSliceToByteVec(byteVecSlice(c)) : c; +} + +/** Drop a `Cow<[T]>`: the items it owns, by `f` if given. */ +export function cowDrop(c: Cow, f?: (item: T) => void): void { + if (!(c instanceof Borrowed)) dropAll(c, f); +} + +/** `f` of the slices two `Cow<[T]>`s deref to, as their `PartialEq` and `Ord` compare them. */ +export function cowBy(f: (a: T[], b: T[]) => R): (a: Cow, b: Cow) => R { + return (a, b) => f(cowSlice(a), cowSlice(b)); +} + +/** `Hash::hash` of a `Cow<[T]>`: its slice's. */ +export function hashCow(hash: (value: T[], s: S) => void): (value: Cow, s: S) => void { + return (value, s) => hash(cowSlice(value), s); +} + // Strings const encoder = /* @__PURE__ */ new TextEncoder(); diff --git a/ts/runtime/rt/int.ts b/ts/runtime/rt/int.ts index 2905e6b41..ad1f221b6 100644 --- a/ts/runtime/rt/int.ts +++ b/ts/runtime/rt/int.ts @@ -542,6 +542,10 @@ export const i8WrappingSub = (a: i8, b: i8): i8 => ((a - b) << 24) >> 24; 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const i8WrappingDiv = (a: i8, b: i8): i8 => (b === -1 ? i8WrappingSub(0, a) : i8Div(a, b)); +/** `i8`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const i8WrappingRem = (a: i8, b: i8): i8 => (b === -1 ? 0 : i8Rem(a, b)); /** `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. */ @@ -605,6 +609,10 @@ export const i16WrappingSub = (a: i16, b: i16): i16 => ((a - b) << 16) >> 16; 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const i16WrappingDiv = (a: i16, b: i16): i16 => (b === -1 ? i16WrappingSub(0, a) : i16Div(a, b)); +/** `i16`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const i16WrappingRem = (a: i16, b: i16): i16 => (b === -1 ? 0 : i16Rem(a, b)); /** `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. */ @@ -668,6 +676,10 @@ export const i32WrappingSub = (a: i32, b: i32): i32 => (a - b) | 0; 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const i32WrappingDiv = (a: i32, b: i32): i32 => (b === -1 ? i32WrappingSub(0, a) : i32Div(a, b)); +/** `i32`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const i32WrappingRem = (a: i32, b: i32): i32 => (b === -1 ? 0 : i32Rem(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. */ @@ -806,6 +818,10 @@ export const isizeWrappingSub: (a: isize, b: isize) => isize = i32WrappingSub as 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const isizeWrappingDiv: (a: isize, b: isize) => isize = i32WrappingDiv as never; +/** `isize`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const isizeWrappingRem: (a: isize, b: isize) => isize = i32WrappingRem 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. */ @@ -1593,6 +1609,10 @@ export const i64WrappingSub = (a: i64, b: i64): i64 => (typeof a === "number" && 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const i64WrappingDiv = (a: i64, b: i64): i64 => (b === -1 ? i64WrappingSub(0, a) : i64Div(a, b)); +/** `i64`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const i64WrappingRem = (a: i64, b: i64): i64 => (b === -1 ? 0 : i64Rem(a, b)); /** `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. */ @@ -1807,6 +1827,10 @@ export const i128WrappingSub = (a: i128, b: i128): i128 => (typeof a === "number 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 `wrapping_div`: `a / b`, truncated and wrapped into the type's range, panicking on a zero divisor. */ +export const i128WrappingDiv = (a: i128, b: i128): i128 => (b === -1 ? i128WrappingSub(0, a) : i128Div(a, b)); +/** `i128`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ +export const i128WrappingRem = (a: i128, b: i128): i128 => (b === -1 ? 0 : i128Rem(a, b)); /** `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. */ diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 3944cedce..342fb9f00 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -179,8 +179,11 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { return match (std, variant.index()) { (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::Cow, _) if let Some(elem) = library::cow_slice(tcx, Ty::new_adt(tcx, adt, gargs)) => { + library::cow_made(elem, variant, values.pop().unwrap()) + } (library::Std::Result, i) => Expr::result(i == 0, values.pop().unwrap()), - (library::Std::Reverse, _) => values.pop().unwrap(), + (library::Std::Reverse | library::Std::Wrapping, _) => values.pop().unwrap(), (library::Std::Bound | library::Std::TryLockError, _) => { let ts_ty = self.t.ty(Ty::new_adt(tcx, adt, gargs), span); library::tagged(adt.variant(variant).name.as_str(), values.pop(), ts_ty) diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 98b19c7d0..4408ea605 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -105,6 +105,9 @@ pub fn call<'tcx>( ("PartialEq", "eq" | "ne", ..) if let Some(t) = self_ty => { // The library maps the integers', `bool`'s, and byte slices'. let rhs = library::targ(call.args, 1); + // A `Cow<[T]>` compares as the slice it derefs to: its `ne` is `!eq`, or the + // slice's, which is too. + let (t, rhs) = (cow_deref(b, t, &mut args, 0), cow_deref(b, rhs, &mut args, 1)); let slice = |t: Ty<'tcx>| matches!(t.kind(), ty::Slice(_)) && bytes(b, t); if slice(t) && slice(rhs) { return Err(args); @@ -824,9 +827,12 @@ fn hashing<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, key: Ty<'tcx>, span let mut values = vec![hash_fn(b, key, hasher, span), eq_fn(b, key, span)]; // A fieldless enum is a JS string, and a bound value may be any primitive, which its // own `Eq` may tell apart where JS can't, as is the `Some` of an `Option` of one, and a - // `Reverse` of one. + // `Reverse` or a `Wrapping` of one. let mut held = key; - while let Some(inner) = option_of(b, held).or_else(|| reverse_of(b, held)) { + while let Some(inner) = option_of(b, held) + .or_else(|| reverse_of(b, held)) + .or_else(|| wrapping_of(b, held)) + { held = peel(b, inner); } if matches!(held.kind(), ty::Adt(adt, _) if fieldless(*adt) || b.t.bound_drops(adt.did()).is_some()) { @@ -1588,7 +1594,13 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(tys) => tys.iter().all(held), _ if let Some(elem) = elements_of(b, ty) => held(elem), _ if bytes(b, ty) => true, - ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)).or_else(|| reverse_of(b, ty)) => { + ty::Adt(..) + if let Some(inner) = option_of(b, ty) + .or_else(|| arc_of(b, ty)) + .or_else(|| reverse_of(b, ty)) + .or_else(|| wrapping_of(b, ty)) + .or_else(|| cow_of(b, ty)) => + { held(inner) } ty::Adt(..) if let Some(bound) = range_of(b, ty) => held(bound), @@ -1620,6 +1632,30 @@ fn reverse_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Reverse)).then(|| arg(ty, 0)) } +/// What `ty` holds if it is a `Wrapping`, which compares, orders, and hashes as it, but for +/// its `ne`, which is `!eq`. +fn wrapping_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + (b.t.std_of(ty) == Some(Std::Wrapping)).then(|| arg(ty, 0)) +} + +/// What `ty` holds if it is a `Cow<[T]>` other than of bytes, `T`, which compares, orders, +/// and hashes as its slice. A `Cow<[u8]>` is bytes already. +fn cow_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + library::cow_slice(b.t.tcx, ty).filter(|elem| !matches!(elem.kind(), ty::Uint(ty::UintTy::U8))) +} + +/// `ty`, the type of `args[n]`, as the slice it derefs to if it is a `Cow<[T]>` other than +/// of bytes, whose value in `args` becomes that slice. +fn cow_deref<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>, args: &mut [Expr], n: usize) -> Ty<'tcx> { + let Some(elem) = cow_of(b, peel(b, ty)) else { + return ty; + }; + if let Some(at) = args.get_mut(n) { + *at = library::cow_deref(std::mem::replace(at, Expr::undefined()), elem); + } + Ty::new_slice(b.t.tcx, elem) +} + /// 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> { @@ -1631,12 +1667,13 @@ fn elements_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (!matches!(elem.kind(), ty::Uint(ty::UintTy::U8))).then_some(elem) } -/// Whether `ty` is a `Vec`, a slice, or an array of bytes: a typed array, an `rt.ByteSlice` -/// behind a reference, or an `rt.ByteVec`. +/// Whether `ty` is a `Vec`, a slice, an array, or a `Cow` of bytes: a typed array, an +/// `rt.ByteSlice` behind a reference, or an `rt.ByteVec`, or either of the last two. fn bytes<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { 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), + _ if let Some(elem) = library::cow_slice(b.t.tcx, ty) => elem, _ => return false, }; matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) @@ -1793,6 +1830,10 @@ pub fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, spa ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => { Expr::rt("cmpReverse", vec![cmp_fn(b, inner, partial, span)]) } + ty::Adt(..) if let Some(inner) = wrapping_of(b, ty) => cmp_fn(b, inner, partial, span), + ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { + Expr::rt("cowBy", vec![cmp_fn(b, Ty::new_slice(tcx, elem), partial, span)]) + } _ if let Some(elem) = elements_of(b, ty) => Expr::rt("cmpSlice", vec![cmp_fn(b, elem, partial, span)]), // Whichever form it has, as the key it is or the operand a reference passes. _ if bytes(b, ty) => Expr::Rt("cmpBytes".into()), @@ -1836,7 +1877,10 @@ pub 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), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| wrapping_of(b, ty)) => eq_fn(b, inner, span), + ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { + Expr::rt("cowBy", vec![eq_fn(b, Ty::new_slice(tcx, elem), span)]) + } ty::Adt(..) if let Some(bound) = range_of(b, ty) => Expr::rt("rangeEq", vec![eq_fn(b, bound, span)]), // A slice compares its elements by `!=`. _ if let Some(elem) = elements_of(b, ty) => Expr::rt("eqSlice", vec![not_ne_fn(b, elem, span)]), @@ -2063,7 +2107,12 @@ 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), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| wrapping_of(b, ty)) => { + hash_fn(b, inner, hasher, span) + } + ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { + Expr::rt("hashCow", vec![hash_fn(b, Ty::new_slice(tcx, elem), hasher, span)]) + } ty::Adt(..) if let Some(bound) = range_of(b, ty) => { Expr::rt("rangeHash", vec![hash_fn(b, bound, hasher, span)]) } diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index 85e7bbfd6..63fe83fe0 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -128,6 +128,9 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { (Std::Option, 0) => self.t.none(args.type_at(0)), (Std::Option, _) => values.pop().unwrap(), (Std::Cow, _) if crate::lower::library::string(tcx, ty) => values.pop().unwrap(), + (Std::Cow, _) if let Some(elem) = super::library::cow_slice(tcx, ty) => { + super::library::cow_made(elem, variant, values.pop().unwrap()) + } (Std::Result, i) => Expr::result(i == 0, values.pop().unwrap()), // `start..=end`, not yet stepped past its end. (Std::RangeInclusive, _) diff --git a/ts/src/lower/copy.rs b/ts/src/lower/copy.rs index 4b9cb9c46..e040f25e7 100644 --- a/ts/src/lower/copy.rs +++ b/ts/src/lower/copy.rs @@ -38,7 +38,7 @@ 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 | Std::Reverse) => { + Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow | Std::Reverse | Std::Wrapping) => { (false, args.types().collect()) } Some(Std::Bound) => (true, args.types().collect()), @@ -182,7 +182,7 @@ 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(self.pending(args.type_at(0)), 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.snapshot(v(), args.type_at(0), span)), + Some(Std::Reverse | Std::Wrapping) => ret(self.snapshot(v(), args.type_at(0), span)), Some(Std::Bound) => { let ts_ty = self.ty(ty, span); let held = self.snapshot(v().member("_0"), args.type_at(0), span); diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index 390f808eb..f4deac821 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -62,6 +62,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::Bound | Std::TryLockError | Std::Reverse + | Std::Wrapping | Std::Range | Std::RangeInclusive | Std::RangeFrom @@ -70,6 +71,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ) => 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)), + // The items of the `Vec` it owns. + Some(Std::Cow) => library::cow_slice(tcx, ty).is_some_and(|elem| self.drops(elem)), // A `Vec`'s drain moves the vector's tail back as it drops, and a `String`'s takes // the drained text out of it. None if { @@ -158,7 +161,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::Option | Std::Box | Std::Pin - | Std::Reverse, + | Std::Reverse + | Std::Wrapping, ) => self.disposable(args.type_at(0), span), // An `rt.Iter` drops what it was given to. None | Some(Std::Peekable) if self.std_iter(ty) => self.closures_held(ty), @@ -191,7 +195,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { }; match Std::of(self.tcx, adt.did()) { _ if self.bound_drops(adt.did()).is_some() => true, - Some(Std::Box | Std::Pin | Std::Reverse | Std::PoisonError) => self.always_disposes(args.type_at(0)), + Some(Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::PoisonError) => { + self.always_disposes(args.type_at(0)) + } Some( Std::Waker | Std::PollFn @@ -253,7 +259,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::OnceLock | Std::Poll | Std::Pin - | Std::Reverse, + | Std::Reverse + | Std::Wrapping, ) => args.types().all(|t| self.inert(t)), // Its waker. Some(Std::Context) => false, @@ -310,7 +317,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { let option = Ty::new_option(self.tcx, args.type_at(0)); return self.drop_value(value.member("v"), option, span); } - Std::Box | Std::Pin | Std::Reverse | Std::PoisonError => { + Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::PoisonError => { return self.drop_value(value, args.type_at(0), span); } // Its value, or the function that never made one. @@ -322,6 +329,15 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Std::VecDeque => ("dequeDrop", vec![value, each(self, 0)?]), Std::BinaryHeap => ("heapDrop", vec![value, each(self, 0)?]), Std::PeekMut => ("peekMutDrop", vec![value]), + // What it owns, and nothing it borrows. + Std::Cow => { + let elem = library::cow_slice(self.tcx, ty)?; + let mut args = vec![value]; + if !self.disposable(elem, span) { + args.push(self.drop_fn(elem, span)?); + } + ("cowDrop", args) + } // Its bounds, in the order std's fields are, `rt.RangeInclusive`'s by its own names. Std::Range | Std::RangeInclusive => { let (lo, hi) = match std { @@ -457,7 +473,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 | Std::Reverse => self.elements(args.type_at(0)), + Std::Option | Std::Box | Std::Pin | Std::Reverse | Std::Wrapping => self.elements(args.type_at(0)), _ => None, }, _ => None, diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 9b668d56a..58de0b8c6 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -295,8 +295,12 @@ 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]), - // A `NonZero` writes its integer, by each trait. - (Std::Box | Std::NonZero, _) => b.fmt_call(tr, args.type_at(0), value, f, span), + // A `NonZero` and a `Wrapping` write their integer, by each trait. + (Std::Box | Std::NonZero | Std::Wrapping, _) => b.fmt_call(tr, args.type_at(0), value, f, span), + // A `Cow<[T]>` writes its slice. + (Std::Cow, Trait::Debug) if let Some(elem) = library::cow_slice(tcx, ty) => { + b.fmt_call(tr, Ty::new_slice(tcx, elem), library::cow_deref(value, elem), f, span) + } (Std::Arc, Trait::Display | Trait::Debug) => { b.fmt_call(tr, args.type_at(0), value.member("value"), f, span) } diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index 6e1db5687..0a46d31e5 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -501,11 +501,15 @@ pub fn call<'tcx>( tail(vec![Expr::rt_of(float.name(), op), float.lit(unit)], vec![drops]), ) } + // A `Wrapping`'s wraps, as its `+` and `*` do. "sum" | "product" => { - let int = Int::of(targ(1)?)?; - let (op, unit) = match name { - "sum" => ("add", 0), - _ => ("mul", 1), + let wrapping = super::library::wrapping_of(b.t.tcx, targ(1)?); + let int = Int::of(wrapping.unwrap_or(targ(1)?))?; + let (op, unit) = match (name, wrapping.is_some()) { + ("sum", false) => ("add", 0), + ("sum", true) => ("wrappingAdd", 0), + (_, false) => ("mul", 1), + (_, true) => ("wrappingMul", 1), }; let drops = iter_drops(b, self_ty, span); method(name, tail(vec![int.func(op), int.lit(unit)], vec![drops])) @@ -1128,18 +1132,25 @@ fn collect<'tcx>( return None; }; let std = Std::of(tcx, adt.did())?; - match std { - Std::Vec => Some(match args.type_at(0).kind() { + // A `Cow<[T]>` owns the `Vec` std's collects. + let elem = match std { + Std::Vec => Some(args.type_at(0)), + _ => library::cow_slice(tcx, ty), + }; + if let Some(elem) = elem { + return Some(match elem.kind() { ty::Uint(ty::UintTy::U8) => { - let (folds, by_index) = collect_folds(b, from, args.type_at(0), span); + let (folds, by_index) = collect_folds(b, from, elem, span); let take = iter_take(b, from, folds, span); Expr::rt( "iterToByteVec", tail(vec![iter], vec![take, Expr::lit((trusted || by_index).to_string())]), ) } - _ => to_array(b, iter, from, args.type_at(0), trusted, span), - }), + _ => to_array(b, iter, from, elem, trusted, span), + }); + } + match std { // The values, collected as the `Ok` or `Some` type is, until the first `Err` or `None`. std @ (Std::Result | Std::Option) => { let ty::Adt(_, item_args) = item.kind() else { diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 901d19bb0..7b7e764c1 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -124,6 +124,8 @@ pub enum Std { Reverse, /// Its integer, which is never 0. NonZero, + /// What it holds, whose arithmetic wraps. + Wrapping, /// A `format_args!` argument: a function writing its value, `rt.Fmt`. Argument, /// A raw pointer to its pointee, as `pointer` has it. @@ -300,6 +302,7 @@ impl Std { ["collections", "binary_heap", "PeekMut"] => Some(Self::PeekMut), ["ops", "range", "Bound"] => Some(Self::Bound), ["num", "nonzero", "NonZero"] => Some(Self::NonZero), + ["num", "wrapping", "Wrapping"] => Some(Self::Wrapping), ["hash", "random", "DefaultHasher"] => Some(Self::Hasher), ["hash", "random", "RandomState"] => Some(Self::RandomState), ["collections", "hash", "map", "Entry" | "OccupiedEntry" | "VacantEntry"] @@ -389,14 +392,15 @@ 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. +/// What a value of `ty` is in JS if `ty` wraps one value it is represented as: `Reverse`'s, +/// `NonZero`'s, and `Wrapping`'s `T`, which differ only in their order, range, and +/// arithmetic, 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(Std::Reverse | Std::NonZero | Std::Wrapping) => Some(args.type_at(0)), Some(_) => None, None => { let path = std_path(tcx, adt.did()); @@ -428,6 +432,44 @@ pub fn range_to(end: Expr, inclusive: bool) -> Expr { Expr::Object(props) } +/// What a `Cow<[T]>` of type `ty` holds, `T`, or `None` for any other type. +pub fn cow_slice<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + // Its first argument is its lifetime. + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Cow) => match args.types().next()?.kind() { + ty::Slice(elem) => Some(*elem), + _ => None, + }, + _ => None, + } +} + +/// The slice `cow`, a `Cow<[elem]>`, derefs to: an `rt.ByteSlice` of bytes, or an array. +pub fn cow_deref(cow: Expr, elem: Ty<'_>) -> Expr { + match elem.kind() { + ty::Uint(ty::UintTy::U8) => Expr::rt("byteCowSlice", vec![cow]), + _ => Expr::rt("cowSlice", vec![cow]), + } +} + +/// A `Cow<[elem]>` made by its variant `variant` of `value`: the `Vec` it owns, or the +/// slice it borrows, wrapped in an `rt.Borrowed` unless it is bytes. +pub fn cow_made(elem: Ty<'_>, variant: rustc_abi::VariantIdx, value: Expr) -> Expr { + match variant.index() == 0 && !matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) { + true => Expr::New(Box::new(Expr::Rt("Borrowed".into())), vec![value]), + false => value, + } +} + +/// Whether `cow`, a `Cow<[elem]>`, borrows: whether it is of the class its borrowed variant is. +pub fn cow_borrows(cow: Expr, elem: Ty<'_>) -> Expr { + let class = match elem.kind() { + ty::Uint(ty::UintTy::U8) => "ByteSlice", + _ => "Borrowed", + }; + cow.binary("instanceof", Expr::Rt(class.into())) +} + /// 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") @@ -1207,6 +1249,20 @@ fn mapping<'tcx>( if to == from || some || (string(tcx, to) && string(tcx, from.peel_refs())) { return Some(value); } + // A `Vec` is owned, and a reference to a slice, an array, or a `Vec` borrows its slice. + if let Some(elem) = cow_slice(tcx, to) { + let owned = b.t.std_of(targ(gargs, 1)) == Some(Std::Vec); + let value = match b.t.std_of(from) == Some(Std::Vec) && !owned { + true => vec_view(value, elem), + false => value, + }; + return Some(cow_made(elem, rustc_abi::VariantIdx::from_u32(owned.into()), value)); + } + if let Some(elem) = cow_slice(tcx, from) + && b.t.std_of(to) == Some(Std::Vec) + { + return Some(cow_cloned(b, "IntoOwned", value, elem, span)); + } // A heap's `Vec` is its elements. if let ty::Adt(adt, args) = from.kind() && Std::of(tcx, adt.did()) == Some(Std::BinaryHeap) @@ -1253,22 +1309,38 @@ fn mapping<'tcx>( int.method("tryFrom", values) } - // Operators on references to primitives. - ("Add" | "Sub" | "Mul" | "Div" | "Rem" | "BitAnd" | "BitOr" | "BitXor" | "Shl" | "Shr", _) - if primitive(targ(gargs, 0).peel_refs()) => + // A `Wrapping`'s operators, which wrap as its integer's `wrapping_*` do. + (_, _) + if let Some(op) = operator(&owner) + && let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => { - let op = match owner.as_str() { - "Add" => rustc_middle::mir::BinOp::Add, - "Sub" => rustc_middle::mir::BinOp::Sub, - "Mul" => rustc_middle::mir::BinOp::Mul, - "Div" => rustc_middle::mir::BinOp::Div, - "Rem" => rustc_middle::mir::BinOp::Rem, - "BitAnd" => rustc_middle::mir::BinOp::BitAnd, - "BitOr" => rustc_middle::mir::BinOp::BitOr, - "BitXor" => rustc_middle::mir::BinOp::BitXor, - "Shl" => rustc_middle::mir::BinOp::Shl, - _ => rustc_middle::mir::BinOp::Shr, + let [l, r] = <[Expr; 2]>::try_from(args).ok()?; + // A constant shift amount, which masks to a constant. + let value = match &r { + Expr::Lit(l) => l.parse().ok(), + _ => None, }; + num::wrapping( + b, + op, + Operand { expr: l, value: None }, + Operand { expr: r, value }, + int, + span, + ) + } + ("Neg", "neg") if let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => { + let zero = Int::of(int)?.lit(0); + Int::of(int)?.method("wrappingSub", vec![zero, args.pop()?]) + } + ("Not", "not") if let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => { + num::unary(b, rustc_middle::mir::UnOp::Not, args.pop()?, int, span) + } + // Operators on references to primitives. + (_, _) + if let Some(op) = operator(&owner) + && primitive(targ(gargs, 0).peel_refs()) => + { let (lty, rty) = (targ(gargs, 0), targ(gargs, 1)); let [l, r] = <[Expr; 2]>::try_from(args).ok()?; num::binary( @@ -1328,6 +1400,7 @@ fn mapping<'tcx>( ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Vec) => { return vec_clone(b, value, args.type_at(0), span); } + _ if let Some(elem) = cow_slice(tcx, ty) => cow_cloned(b, "Clone", value, elem, span), ty::Tuple(tys) if !clone_copies(b.t, ty) => { let clones = tys.iter().map(|t| super::collections::clone_fn(b, t, span)).collect(); Expr::rt("tupleClone", vec![value, Expr::Array(clones)]) @@ -1875,6 +1948,7 @@ fn mapping<'tcx>( Some(Std::Vec) => vec_view(v, vargs.type_at(0)), Some(Std::String | Std::Box) => v, Some(Std::Cow) if string(tcx, ty) => v, + Some(Std::Cow) if let Some(elem) = cow_slice(tcx, ty) => cow_deref(v, elem), // The greatest element of a heap, which `DerefMut` marks to sift once lent. Some(Std::PeekMut) => { let p = match v.is_path() { @@ -1941,7 +2015,16 @@ fn mapping<'tcx>( // A `Cow` is its text, whichever variant holds it. ("Cow", "into_owned") if targ(gargs, 0).is_str() => args.pop()?, ("AsRef", "as_ref") if string(tcx, targ(gargs, 0)) && targ(gargs, 1).is_str() => args.pop()?, - ("Cow", "is_borrowed" | "is_owned") => { + // A `Cow<[T]>` borrows its slice, and its `Vec` is its own or a clone of what it + // borrows, so it drops nothing. + ("Cow", "into_owned") if let ty::Slice(elem) = targ(gargs, 0).kind() => { + return Some(cow_cloned(b, "IntoOwned", args.pop()?, *elem, span)); + } + ("AsRef", "as_ref") | ("Borrow", "borrow") if let Some(elem) = cow_slice(tcx, targ(gargs, 0)) => { + cow_deref(args.pop()?, elem) + } + // A slice's are unstable, and left to the refusal of any other call. + ("Cow", "is_borrowed" | "is_owned") if !targ(gargs, 0).is_slice() => { let cow = b.t.sig(call.def_id, gargs).inputs()[0].peel_refs(); return Some(b.err(span, cow_variant(cow))); } @@ -2201,6 +2284,20 @@ fn clone_from_clones<'tcx>(t: &mut Translator<'_, 'tcx>, ty: Ty<'tcx>) -> bool { (t.std_of(ty) == Some(Std::Option) || !t.drops(ty)) && inner.into_iter().all(|arg| clone_from_clones(t, arg)) } +/// `cow`, a `Cow<[elem]>`, through the runtime's `cow{op}`, `IntoOwned` or `Clone`, which +/// clones what it borrows, or for `Clone` what it owns, by each item's `Clone`. +pub fn cow_cloned<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: &str, cow: Expr, elem: Ty<'tcx>, span: Span) -> Expr { + if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) { + return Expr::rt(format!("byteCow{op}"), vec![cow]); + } + let mut args = vec![cow]; + match super::collections::clone_fn(b, elem, span) { + Expr::Lit(l) if l == "undefined" => {} + clone => args.push(clone), + } + Expr::rt(format!("cow{op}"), args) +} + /// 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 else each element cloned. fn vec_clone<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, elem: Ty<'tcx>, span: Span) -> Option { @@ -2211,6 +2308,34 @@ fn vec_clone<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, elem: Ty<'tcx>, span Some(value.method("map", vec![clone])) } +/// The operator a binary operator trait, `Add` or another, applies. +pub fn operator(owner: &str) -> Option { + use rustc_middle::mir::BinOp; + Some(match owner { + "Add" => BinOp::Add, + "Sub" => BinOp::Sub, + "Mul" => BinOp::Mul, + "Div" => BinOp::Div, + "Rem" => BinOp::Rem, + "BitAnd" => BinOp::BitAnd, + "BitOr" => BinOp::BitOr, + "BitXor" => BinOp::BitXor, + "Shl" => BinOp::Shl, + "Shr" => BinOp::Shr, + _ => return None, + }) +} + +/// The integer a `Wrapping` of type `ty` holds, if it is one of an integer. +pub fn wrapping_of<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Wrapping) => { + Some(args.type_at(0)).filter(|&t| Int::of(t).is_some()) + } + _ => None, + } +} + /// 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. @@ -2407,13 +2532,18 @@ pub fn default_value<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span, }, Std::String => Expr::Str(String::new()), Std::Cow if string(tcx, ty) => Expr::Str(String::new()), + // An owned empty `Vec`. + Std::Cow if let Some(elem) = cow_slice(tcx, ty) => match elem.kind() { + ty::Uint(ty::UintTy::U8) => Expr::New(Box::new(Expr::Rt("ByteVec".into())), Vec::new()), + _ => Expr::Array(Vec::new()), + }, Std::Duration => super::time::zero(), Std::Atomic => Expr::New( Box::new(Expr::Rt("Atomic".into())), vec![default_value(b, args.type_at(0), span, out)?], ), Std::OnceCell | Std::OnceLock => super::task::once_new(b, ty), - Std::Box => part(b, args.type_at(0), out), + Std::Box | Std::Wrapping => part(b, args.type_at(0), out), Std::Arc => Expr::New(Box::new(Expr::Rt("Arc".into())), vec![part(b, args.type_at(0), out)]), Std::Mutex => Expr::New(Box::new(Expr::Rt("Mutex".into())), vec![part(b, args.type_at(0), out)]), Std::RefCell => Expr::New( diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index d57c61b83..5b93b0343 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -679,6 +679,35 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { None => done(place, true), } } + // A `Wrapping` is its integer, so what the `&mut` borrows gets the wrapped result. + (_, _) + if let Some(op) = owner.strip_suffix("Assign").and_then(library::operator) + && let Some(int) = targ(0).and_then(|t| library::wrapping_of(tcx, t)) => + { + let place = self.borrowed_place(&args[0].node, span, out)?; + let by = self.operand(&args[1].node, span, out); + let l = crate::lower::num::Operand { + expr: place.0.clone(), + value: None, + }; + let r = crate::lower::num::Operand { + expr: by, + value: self.const_int(&args[1].node), + }; + let value = crate::lower::num::wrapping(self.b, op, l, r, int, span); + self.set_borrowed(&place, value, span, out); + done(Expr::undefined(), false) + } + // A `Cow<[T]>` that borrows takes a clone of its slice, whose `Vec` the `&mut` lends. + ("Cow", "to_mut") if let ty::Slice(elem) = targ(0)?.kind() => { + let place = self.borrowed_place(&args[0].node, span, out)?; + // Read twice, by the clone and by the store. + self.materialize(&place.0, out); + let owned = library::cow_cloned(self.b, "IntoOwned", place.0.clone(), *elem, span); + let owned = self.path(owned, "owned", out); + self.set_borrowed(&place, owned.clone(), span, out); + done(owned, true) + } ("Option", "take") => { let place = self.borrowed_place(&args[0].node, span, out)?; let none = self.b.t.none(targ(0)?); diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 58622cde1..551e8f6b1 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -3316,16 +3316,16 @@ fn scan_reads(stmt: &Stmt, out: &mut Vec) { } } -/// The names `stmts` assign, anywhere in them. +/// The names `stmts` assign, anywhere in them, as themselves or cast to a variant's type. fn assigned(stmts: &[Stmt]) -> FxHashSet { let mut names = FxHashSet::default(); for stmt in stmts { visit_stmt(stmt, &mut |e| { visit_expr(e, &mut |e| { if let Expr::Assign(target, _) | Expr::Postfix(target, _) = e - && let Expr::Ident(name) = &**target + && let Some(name) = assigned_name(target) { - names.insert(name.clone()); + names.insert(name.to_string()); } }) }); @@ -3492,7 +3492,7 @@ fn writes_of(e: &Expr, name: &str) -> usize { let mut n = 0; visit_expr(e, &mut |e| { if let Expr::Assign(target, _) | Expr::Postfix(target, _) = e - && matches!(&**target, Expr::Ident(i) if i == name) + && assigned_name(target) == Some(name) { n += 1; } @@ -3500,6 +3500,18 @@ fn writes_of(e: &Expr, name: &str) -> usize { n } +/// The name an assignment to `target` writes whole: itself, or cast to the type of a +/// variant it holds, as a `Cow`'s payload is. +fn assigned_name(mut target: &Expr) -> Option<&str> { + while let Expr::As(inner, _) = target { + target = inner; + } + match target { + Expr::Ident(name) => Some(name), + _ => None, + } +} + /// Call `f` on each expression the statement holds directly, and in its blocks. fn visit_stmt(stmt: &Stmt, f: &mut dyn FnMut(&Expr)) { match &stmt.kind { diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index aa46769c2..38997a0b6 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -544,7 +544,14 @@ 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 | Std::Reverse | Std::NonZero | Std::PoisonError, + Std::Option + | Std::Poll + | Std::Box + | Std::Pin + | Std::Reverse + | Std::NonZero + | Std::Wrapping + | Std::PoisonError, ) => base, // Cast to its variant, which a test narrows only where it reads the field. Some(Std::Bound | Std::TryLockError) => { @@ -571,6 +578,22 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Some(std) if std.error() => { base.member(crate::lower::camel(adt.non_enum_variant().fields[field].name.as_str())) } + // Cast to its variant's class: the slice an `rt.Borrowed` wraps, or the `Vec`. + Some(Std::Cow) if let Some(elem) = crate::lower::library::cow_slice(tcx, ty) => { + let bytes = matches!(elem.kind(), ty::Uint(ty::UintTy::U8)); + let owned = variant.is_some_and(|v| v.index() == 1); + let class = match (bytes, owned) { + (true, false) => crate::ts::Type::Rt("ByteSlice", Vec::new()), + (true, true) => crate::ts::Type::Rt("ByteVec", Vec::new()), + (false, false) => crate::ts::Type::Rt("Borrowed", vec![self.b.t.ty(elem, span)]), + (false, true) => crate::ts::Type::Array(Box::new(self.b.t.ty(elem, span))), + }; + let cast = Expr::As(Box::new(base), class); + match bytes || owned { + true => cast, + false => cast.member("slice"), + } + } 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) || crate::lower::library::wrapped(tcx, ty).is_some() => base, @@ -1081,6 +1104,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } Some(Std::ControlFlow) => super::call::control_flow_test(self, scrut, ty, index), Some(Std::Entry) => crate::lower::collections::entry_test(*adt, index, scrut.clone()), + Some(Std::Cow) if let Some(elem) = crate::lower::library::cow_slice(tcx, ty) => { + let borrows = crate::lower::library::cow_borrows(scrut.clone(), elem); + match index.index() { + 0 => borrows, + _ => borrows.not(), + } + } Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(Std::Ordering) => scrut .clone() diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index 88cd07f15..d22aecd02 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -379,6 +379,14 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // The value is its discriminant. Some(Std::Ordering | Std::AtomicOrdering) => scrut, + Some(Std::Cow) if let Some(elem) = crate::lower::library::cow_slice(tcx, ty) => { + let borrows = crate::lower::library::cow_borrows(scrut, elem); + Expr::Cond( + Box::new(borrows), + Box::new(int.lit(discrs[0].1 as i128)), + Box::new(int.lit(discrs[1].1 as i128)), + ) + } Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(std @ (Std::Bound | Std::TryLockError | Std::ErrorKind)) => { let table = discrs @@ -572,6 +580,9 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::Option | Std::Poll | Std::Pin, _) => values.pop().unwrap(), // Either variant is its text. (Std::Cow, _) if crate::lower::library::string(tcx, ty) => values.pop().unwrap(), + (Std::Cow, _) if let Some(elem) = crate::lower::library::cow_slice(tcx, ty) => { + crate::lower::library::cow_made(elem, variant, values.pop().unwrap()) + } (Std::Result, i) => Expr::result(i == 0, values.pop().unwrap()), (Std::FmtError, _) => Expr::New(Box::new(Expr::Rt("FmtError".into())), Vec::new()), (Std::ParseBoolError, _) => Expr::New(Box::new(Expr::Rt("ParseBoolError".into())), Vec::new()), @@ -580,7 +591,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::RangeTo | Std::RangeToInclusive, _) => { crate::lower::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) } - (Std::Reverse, _) => values.pop().unwrap(), + (Std::Reverse | Std::Wrapping, _) => values.pop().unwrap(), (Std::Bound | Std::TryLockError, _) => { let ts_ty = self.b.t.ty(ty, span); crate::lower::library::tagged(def.name.as_str(), values.pop(), ts_ty) diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 2ca0e24f0..2f931511e 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -1455,13 +1455,21 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { }, library::Std::String => Type::Builtin("string"), library::Std::Cow if library::string(tcx, Ty::new_adt(tcx, adt, args)) => Type::Builtin("string"), + library::Std::Cow if let Some(elem) = library::cow_slice(tcx, Ty::new_adt(tcx, adt, args)) => { + match elem.kind() { + ty::Uint(ty::UintTy::U8) => Type::Rt("ByteCow", vec![]), + _ => Type::Rt("Cow", vec![self.ty(elem, span)]), + } + } library::Std::Cow => { self.unrepresented(span, format!("`{}` is not supported yet", Ty::new_adt(tcx, adt, args))); Type::Builtin("unknown") } - library::Std::Box | library::Std::Reverse | library::Std::NonZero | library::Std::PoisonError => { - self.ty(args.type_at(0), span) - } + library::Std::Box + | library::Std::Reverse + | library::Std::NonZero + | library::Std::Wrapping + | library::Std::PoisonError => self.ty(args.type_at(0), span), library::Std::Bound => Type::Rt("RangeBound", vec![self.ty(args.type_at(0), span)]), library::Std::TryLockError => Type::Rt("TryLockError", vec![self.ty(args.type_at(0), span)]), library::Std::FromUtf8Error => Type::Rt("FromUtf8Error", vec![]), @@ -1758,6 +1766,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | library::Std::Pin | library::Std::Reverse | library::Std::NonZero + | library::Std::Wrapping | library::Std::PoisonError, ) => self.erases_to(args.type_at(0)), // `undefined` while it holds nothing. diff --git a/ts/src/lower/num.rs b/ts/src/lower/num.rs index beb8405b1..8c4729030 100644 --- a/ts/src/lower/num.rs +++ b/ts/src/lower/num.rs @@ -342,6 +342,38 @@ pub fn binary<'tcx>( } } +/// `l op r` of `Wrapping`s, as the integer's `wrapping_*` computes it: arithmetic +/// wraps, a shift masks its amount to the width, and only a zero divisor panics. +pub fn wrapping<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: BinOp, l: Operand, r: Operand, ty: Ty<'tcx>, span: Span) -> Expr { + let Some(int) = Int::of(ty) else { + return b.err(span, format!("arithmetic on `Wrapping<{ty}>`")); + }; + let name = match op { + BinOp::Add => "wrappingAdd", + BinOp::Sub => "wrappingSub", + BinOp::Mul => "wrappingMul", + BinOp::Div if int.signed => "wrappingDiv", + BinOp::Rem if int.signed => "wrappingRem", + BinOp::Shl | BinOp::Shr => { + let mask = i128::from(int.bits - 1); + let r = match r.value { + Some(c) => Operand { + expr: Expr::lit((c & mask).to_string()), + value: Some(c & mask), + }, + None => Operand { + expr: r.expr.binary("&", Expr::lit(mask.to_string())), + value: None, + }, + }; + return binary(b, op, l, r, ty, b.t.tcx.types.usize, span); + } + // Neither overflows. + _ => return binary(b, op, l, r, ty, ty, span), + }; + int.method(name, vec![l.expr, r.expr]) +} + pub fn unary<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: UnOp, value: Expr, ty: Ty<'tcx>, span: Span) -> Expr { let ty = ty.peel_refs(); if let Some(float) = float::Float::of(ty) {