From 06e447d689c04082e6833896ec9f8cb534d476cc Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:29:56 -0700 Subject: [PATCH 01/11] chore(quest): claim quest/m2/ts-model/std-more.md Quest-Claim: 77c7f48059046821 From f04e960028270ea4a4dd9beab2afeb865067a2be Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:46:35 -0700 Subject: [PATCH 02/11] wip(ts): std wrappers, slices, and str gaps --- ts/runtime/rt.ts | 201 +++++++++++++++++++++++++++++++++++ ts/runtime/rt/collections.ts | 81 +++++++++++++- ts/runtime/rt/str.ts | 36 ++++++- ts/src/lower/body.rs | 5 + ts/src/lower/collections.rs | 83 +++++++++++++-- ts/src/lower/consts.rs | 14 +++ ts/src/lower/copy.rs | 19 +++- ts/src/lower/drop.rs | 12 ++- ts/src/lower/fmt.rs | 3 +- ts/src/lower/library.rs | 66 +++++++++++- ts/src/lower/mir/place.rs | 20 +++- ts/src/lower/mir/rvalue.rs | 28 ++++- ts/src/lower/mod.rs | 15 ++- 13 files changed, 549 insertions(+), 34 deletions(-) diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 158fa9ad2..d5e0e6d37 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -5,6 +5,7 @@ // left only where a call dispatches on its receiver: an iterator's `next`, a writer's // `writeStr`, a future's `poll`, a waker's, and `[Symbol.dispose]`. +import type { Ordering } from "./rt/collections.ts"; import { type char, type TryFromIntError, type u32, u8Display, usizeDisplay } from "./rt/int.ts"; export * from "./rt/collections.ts"; @@ -263,6 +264,206 @@ export function sliceGet(s: ArrayLike, index: number): T | undefined { return index < s.length ? s[index] : undefined; } +/** `core::ops::Bound`, tagged as the crate's own enums are. */ +export type Bound = { readonly tag: "Included"; readonly _0: T } | { readonly tag: "Excluded"; readonly _0: T } | { readonly tag: "Unbounded" }; + +/** `Bound::cloned` and `copied`: `b` with `clone` of what it holds. */ +export function boundMap(b: Bound, clone: (value: T) => T): Bound { + return b.tag === "Unbounded" ? b : { tag: b.tag, _0: clone(b._0) }; +} + +/** `last` and `last_mut`: the last element, or `undefined` if empty. */ +export function sliceLast(s: ArrayLike): T | undefined { + return s.length === 0 ? undefined : s[s.length - 1]; +} + +/** `contains`, by `eq` of each element and then `x`, as std's `==` reads them. */ +export function sliceContains(s: ArrayLike, x: T, eq: (a: T, b: T) => boolean): boolean { + for (let i = 0; i < s.length; i++) if (eq(s[i], x)) return true; + return false; +} + +/** `swap`, panicking on either index past the end, `a` first, as std's indexing does. */ +export function sliceSwap(s: T[], a: number, b: number): void { + const x = s[idx(s, a)]; + s[a] = s[idx(s, b)]; + s[b] = x; +} + +/** + * `sort` and `sort_by`, and the unstable sorts, which may order equal elements either way + * and here keep them in order: stable, by `cmp`, which moves an element before another + * only if it orders `Less`, as std's sorts test `lt`. If `cmp` panics, the slice holds each + * element once, in an order std leaves unspecified, as std's does. + */ +export function sliceSortBy(s: T[], cmp: (a: T, b: T) => Ordering | undefined): void { + sort(s, (a, b) => cmp(a, b) === -1); +} + +/** `sort_by_key` and `sort_unstable_by_key`: by `cmp` of each element's `key`, as `sliceSortBy` sorts. */ +export function sliceSortByKey(s: T[], key: (item: T) => K, cmp: (a: K, b: K) => Ordering | undefined): void { + sort(s, (a, b) => cmp(key(a), key(b)) === -1); +} + +/** + * A stable merge sort of `s` by `less`, over runs that insertion sorts first. It calls only + * `less`, never JS's `sort`, which moves `undefined`, a `None`, to the end without + * comparing it, and orders its calls differently in each engine. + */ +function sort(s: T[], less: (a: T, b: T) => boolean): void { + const n = s.length; + const RUN = 16; + for (let lo = 0; lo < n; lo += RUN) { + const hi = Math.min(lo + RUN, n); + for (let i = lo + 1; i < hi; i++) { + const x = s[i]; + let j = i; + // Shifted elements leave a hole at `j`, which `x` fills if `less` panics. + try { + while (j > lo && less(x, s[j - 1])) { + s[j] = s[j - 1]; + j--; + } + } finally { + s[j] = x; + } + } + } + if (n <= RUN) return; + const left: T[] = []; + for (let width = RUN; width < n; width *= 2) { + for (let lo = 0; lo + width < n; lo += 2 * width) { + const mid = lo + width; + const hi = Math.min(mid + width, n); + if (!less(s[mid], s[mid - 1])) continue; + // The left run moves aside, and the merge fills `s` from `lo`, never past the + // right run's next element. If `less` panics, what is left of the left run fills + // the gap. + left.length = 0; + for (let i = lo; i < mid; i++) left.push(s[i]); + let i = 0; + let j = mid; + let k = lo; + try { + while (i < left.length && j < hi) s[k++] = less(s[j], left[i]) ? s[j++] : left[i++]; + } finally { + while (i < left.length) s[k++] = left[i++]; + } + } + } +} + +/** + * `Vec::retain` and `retain_mut`: keeps each element `f` returns true for, in order, and + * drops each other one once `f` rejects it. If `f` or a drop panics, what `f` kept and + * what it had not yet seen stay, as std's do. + */ +export function vecRetain(v: T[], f: (item: T) => boolean, drop?: (item: T) => void): void { + const n = v.length; + let read = 0; + let write = 0; + try { + while (read < n) { + const item = v[read]; + if (f(item)) { + v[write++] = item; + read++; + } else { + read++; + drop?.(item); + } + } + } finally { + v.copyWithin(write, read, n); + v.length = write + n - read; + } +} + +/** + * `Vec::dedup_by`: drops each element `same(element, previous kept)` is true for, in order. + * If `same` or a drop panics, what it kept and what it had not yet seen stay, as std's do. + */ +export function vecDedupBy(v: T[], same: (a: T, b: T) => boolean, drop?: (item: T) => void): void { + const n = v.length; + let first = 1; + while (first < n && !same(v[first], v[first - 1])) first++; + if (first >= n) return; + let read = first + 1; + let write = first; + try { + drop?.(v[first]); + while (read < n) { + const item = v[read]; + if (same(item, v[write - 1])) { + read++; + drop?.(item); + } else { + v[write++] = item; + read++; + } + } + } finally { + v.copyWithin(write, read, n); + v.length = write + n - read; + } +} + +/** `Vec::dedup_by_key`: as `vecDedupBy`, by `eq` of `key` of each element, then of the previous kept. */ +export function vecDedupByKey(v: T[], key: (item: T) => K, eq: (a: K, b: K) => boolean, drop?: (item: T) => void): void { + vecDedupBy(v, (a, b) => eq(key(a), key(b)), drop); +} + +/** `Vec::swap_remove`: the element at `i`, with the last moved into its place. */ +export function vecSwapRemove(v: T[], i: number): T { + if (i >= v.length) panic(`swap_remove index (is ${i}) should be < len (is ${v.length})`); + const item = v[i]; + v[i] = v[v.length - 1]; + v.pop(); + return item; +} + +/** + * `Clone` of a `Vec`, and `to_vec`, by `clone` of each element in order. If one panics, the + * clones made so far drop, in order, as std's do. + */ +export function vecClone(s: ArrayLike, clone: (item: T) => T, drop?: (item: T) => void): T[] { + const out: T[] = []; + try { + for (let i = 0; i < s.length; i++) out.push(clone(s[i])); + } catch (e) { + if (drop !== undefined) for (const item of out) drop(item); + throw e; + } + return out; +} + +/** `Vec::extend_from_slice`: a clone of each element of `s`, pushed in order, as far as they clone. */ +export function vecExtendFromSlice(v: T[], s: ArrayLike, clone: (item: T) => T): void { + for (let i = 0; i < s.length; i++) v.push(clone(s[i])); +} + +/** + * `Clone` of a tuple, by `clone` of each field in order, `undefined` for one whose value is + * itself. If one panics, the clones made so far drop, the last first, by `drops`. + */ +export function tupleClone( + t: T, + clones: readonly (((value: never) => unknown) | undefined)[], + drops: readonly (((value: never) => void) | undefined)[], +): T { + const out: unknown[] = []; + try { + for (let i = 0; i < clones.length; i++) { + const clone = clones[i] as ((value: unknown) => unknown) | undefined; + out.push(clone === undefined ? t[i] : clone(t[i])); + } + } catch (e) { + for (let i = out.length - 1; i >= 0; i--) (drops[i] as ((value: unknown) => void) | undefined)?.(out[i]); + throw e; + } + return out as unknown as T; +} + /** * `&[u8]` and `&mut [u8]`, and `&[u8; N]`: `length` bytes of `data` from `start`. It never changes, so a * split makes another, which costs an object where a `Uint8Array` view costs several diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index e1b53884c..7d17d65f8 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -70,6 +70,26 @@ export function cmpOption(cmp: (a: T, b: T) = return (a, b) => (a === undefined ? (b === undefined ? 0 : -1) : b === undefined ? 1 : cmp(a, b)) as O; } +/** `Ord::cmp` of `Reverse`s, or `PartialOrd::partial_cmp`: their values', the other way. */ +export function cmpReverse(cmp: (a: T, b: T) => O): (a: T, b: T) => O { + return (a, b) => cmp(b, a); +} + +/** + * `Ord::cmp` of slices, or `PartialOrd::partial_cmp`, by their elements' in order, then + * by length. + */ +export function cmpSlice(cmp: (a: T, b: T) => O): (a: ArrayLike, b: ArrayLike) => O { + return (a, b) => { + const n = Math.min(a.length, b.length); + for (let i = 0; i < n; i++) { + const c = cmp(a[i], b[i]); + if (c !== 0) return c; + } + return (a.length < b.length ? -1 : a.length > b.length ? 1 : 0) as O; + }; +} + /** `Ord::cmp` of `Arc`s, or `PartialOrd::partial_cmp`: their values'. */ export function cmpArc(cmp: (a: T, b: T) => O): (a: Arc, b: Arc) => O { return (a, b) => cmp(a.value, b.value); @@ -85,6 +105,27 @@ function compare(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) } } +/** + * `Ord::clamp`, by `cmp`, a `partial_cmp`: `min` if `a` is less, `max` if greater, or else + * `a`, once `min <= max` is asserted. The operands it does not return drop, the last + * first, as std's do. + */ +export function ordClamp(a: T, min: T, max: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + let out: 0 | 1 | 2 | undefined; + try { + const order = cmp(min, max); + if (order === undefined || order > 0) panic("assertion failed: min <= max"); + out = cmp(a, min) === -1 ? 1 : cmp(a, max) === 1 ? 2 : 0; + } finally { + if (drop !== undefined) { + if (out !== 2) drop(max); + if (out !== 1) drop(min); + if (out !== 0) drop(a); + } + } + return out === 1 ? min : out === 2 ? max : a; +} + /** `Ord::max`, by `cmp`: `b` unless `a` is greater, and the other drops. */ export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): T { if (compare(a, b, cmp, drop) > 0) { @@ -131,6 +172,15 @@ export function eqTuple(fields: readonly ((a: neve }; } +/** `PartialEq::eq` of slices: their lengths', then their elements' in order. */ +export function eqSlice(eq: (a: T, b: T) => boolean): (a: ArrayLike, b: ArrayLike) => boolean { + return (a, b) => { + if (a.length !== b.length) return false; + for (let i = 0; i < a.length; i++) if (!eq(a[i], b[i])) return false; + return true; + }; +} + /** `PartialEq::eq` of `Option`s, from their values'. */ export function eqOption(eq: (a: T, b: T) => boolean): (a: T | undefined, b: T | undefined) => boolean { return (a, b) => (a === undefined || b === undefined ? a === b : eq(a, b)); @@ -193,6 +243,14 @@ export function hashTuple(fields: readonly ((value }; } +/** `Hash::hash` of a slice: its length, then its elements' in order. */ +export function hashSlice(hash: (value: T, s: Hasher) => void): (value: ArrayLike, s: Hasher) => void { + return (value, s) => { + mix(s, value.length); + for (let i = 0; i < value.length; i++) hash(value[i], s); + }; +} + /** `Hash::hash` of an `Option`: whether it is `Some`, then its value's. */ export function hashOption(hash: (value: T, s: Hasher) => void): (value: T | undefined, s: Hasher) => void { return (value, s) => { @@ -1095,6 +1153,16 @@ export function btreeClear(m: BTreeMap, k?: (key: K) => void, v?: (v m.r = false; } +/** `split_off` of a map or set: the entries from `key` on, moved in order into a tree of their own. */ +export function btreeSplitOff(m: BTreeMap, key: K): BTreeMap { + const out = btreeNew(m.c); + for (const [k, v] of iterToArray(btreeRange(m, { start: key }))) { + btreeRemove(m, k); + btreeInsert(out, k, v); + } + return out; +} + /** * `retain`, which visits the keys in order and keeps each entry `f` returns true for, * dropping each other one as `f` rejects it. A panic in `f` leaves the entries from the @@ -1222,15 +1290,20 @@ export function btreeValues(m: BTreeMap): Iter { * A range of keys or indices, as its value is: `a..b`, `a..=b`, `a..` as `{ start }`, `..b` * as `{ end }`, or `..` as `undefined`. */ -export type Bounds = { readonly start: K; readonly end: K } | RangeInclusive | { readonly start: K } | { readonly end: K } | undefined; - -/** `RangeBounds`: the start, the end, and whether the end is in the range. */ +export type Bounds = + | { readonly start: K; readonly end: K } + | RangeInclusive + | { readonly start: K } + | { readonly end: K; readonly inclusive?: true } + | undefined; + +/** `RangeBounds`: the start, the end, and whether the end is in the range, as `..=end`'s is. */ function bounds(r: Bounds): [{ key: K } | undefined, { key: K } | undefined, boolean] { if (r === undefined) return [undefined, undefined, false]; // Exhausted, an inclusive range ends before its end, as its `end_bound` says. A field // test, not `instanceof`, so a bundle without `a..=b` leaves the class out. if ("exhausted" in r) return [{ key: r.lo }, { key: r.hi }, !r.exhausted]; - return ["start" in r ? { key: r.start } : undefined, "end" in r ? { key: r.end } : undefined, false]; + return ["start" in r ? { key: r.start } : undefined, "end" in r ? { key: r.end } : undefined, "inclusive" in r]; } /** `BTreeMap::range` and `range_mut`: the entries within `r`. */ diff --git a/ts/runtime/rt/str.ts b/ts/runtime/rt/str.ts index eb7f40544..ba0e33dcd 100644 --- a/ts/runtime/rt/str.ts +++ b/ts/runtime/rt/str.ts @@ -7,8 +7,10 @@ // surrogate pair. import { fmtCharDebug, panic, panicFmt, stringLen } from "../rt.ts"; -import type { char, usize } from "./int.ts"; -import { DONE, type Done, Iter } from "./iter.ts"; +import type { char, u8, usize } from "./int.ts"; +import { DONE, type Done, Iter, iterSlice } from "./iter.ts"; + +const encoder = /* @__PURE__ */ new TextEncoder(); /** A pattern: a `char` or a `&str`, as its text, or a `FnMut(char) -> bool`. */ export type Pattern = string | ((c: char) => boolean); @@ -331,3 +333,33 @@ export function strRfind(s: string, p: Pattern): usize | undefined { const m = new Searcher(s, p); return m.nextMatchBack() ? (utf8Len(s, 0, m.start) as usize) : undefined; } + +/** A pattern of `[char; N]` or `&[char]`: whether a char is any of `cs`. */ +export function patternChars(cs: ArrayLike): (c: char) => boolean { + return (c) => { + for (let i = 0; i < cs.length; i++) if (cs[i] === c) return true; + return false; + }; +} + +/** `str::ends_with`. */ +export function strEndsWith(s: string, p: Pattern): boolean { + if (typeof p === "string") return s.endsWith(p); + return s.length > 0 && p(s.codePointAt(before(s, s.length)) as char); +} + +/** `str::split_once`: the text before the first match and after it. */ +export function strSplitOnce(s: string, p: Pattern): [string, string] | undefined { + const m = new Searcher(s, p); + return m.nextMatch() ? [s.slice(0, m.start), s.slice(m.end)] : undefined; +} + +/** `str::is_char_boundary`: whether byte `i` starts a char, or is the end. */ +export function strIsCharBoundary(s: string, i: number): boolean { + return unitAt(s, 0, 0, i) >= 0; +} + +/** `str::bytes`: its UTF-8 bytes. */ +export function strBytes(s: string): Iter { + return iterSlice(encoder.encode(s)); +} diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 51b121031..6c979b948 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -168,6 +168,11 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { (library::Std::Cow, _) if library::string(tcx, Ty::new_adt(tcx, adt, gargs)) => values.pop().unwrap(), (library::Std::Result, 0) => Expr::rt("Ok", values), (library::Std::Result, _) => Expr::rt("Err", values), + (library::Std::Reverse, _) => values.pop().unwrap(), + (library::Std::Bound, _) => { + let ts_ty = self.t.ty(Ty::new_adt(tcx, adt, gargs), span); + library::bound(adt.variant(variant).name.as_str(), values.pop(), ts_ty) + } _ => self.err(span, format!("constructing `{}`", tcx.def_path_str(adt_id))), }; } diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 0c311c7f8..9d2f463f4 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -57,19 +57,42 @@ pub fn call<'tcx>( let f = hash_fn(b, t, hasher, span); return Ok(Some(f.call(args))); } - ("Ord", "max" | "min", ..) if let Some(t) = self_ty => { + // `Ord`'s defaults, of a std type or the crate's: `clamp` compares by `PartialOrd`. + ("Ord", "max" | "min" | "clamp", ..) if let Some(t) = self_ty => { let t = peel(b, t); - if !std_key(b, t) || Int::of(t).is_some() { + let local = matches!(t.kind(), ty::Adt(adt, _) if adt.did().is_local()); + if !(std_key(b, t) || local) || Int::of(t).is_some() { return Err(args); } let mut values = args; - values.push(cmp_fn(b, t, false, span)); - // What drops the operand it does not return. + values.push(cmp_fn(b, t, name == "clamp", span)); + // What drops the operands it does not return. let Some(droppers) = b.t.droppers(self_ty, span) else { return Ok(Some(Expr::undefined())); }; values.extend(droppers); - return Ok(Some(Expr::rt(if name == "max" { "ordMax" } else { "ordMin" }, values))); + let f = match name { + "max" => "ordMax", + "min" => "ordMin", + _ => "ordClamp", + }; + return Ok(Some(Expr::rt(f, values))); + } + // A std type's own comparisons, as a tuple's are, by its `partial_cmp`. The library + // maps the integers' and `bool`'s. + ("PartialOrd", "lt" | "le" | "gt" | "ge", ..) if let Some(t) = self_ty => { + let t = peel(b, t); + if matches!(t.kind(), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_)) || !std_key(b, t) { + return Err(args); + } + let order = cmp_fn(b, t, true, span).call(args); + let test = match name { + "lt" => library::Inherited::Lt, + "le" => library::Inherited::Le, + "gt" => library::Inherited::Gt, + _ => library::Inherited::Ge, + }; + return Ok(Some(test.test(b, order, out))); } ("PartialEq", "eq" | "ne", ..) if let Some(t) = self_ty => { // The library maps the integers' and `bool`'s. @@ -293,11 +316,14 @@ fn arg<'tcx>(coll: Ty<'tcx>, n: usize) -> Ty<'tcx> { args.types().nth(n).expect("a collection's type argument") } -/// What a JS value of `ty` is: through references and boxes, which are their pointee. +/// What a JS value of `ty` is: through references and boxes, which are their pointee, and +/// a `NonZero`, which is its integer. fn peel<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = ty.peel_refs(); match ty.kind() { - ty::Adt(adt, args) if Std::of(b.t.tcx, adt.did()) == Some(Std::Box) => peel(b, args.type_at(0)), + ty::Adt(adt, args) if matches!(Std::of(b.t.tcx, adt.did()), Some(Std::Box | Std::NonZero)) => { + peel(b, args.type_at(0)) + } _ => ty, } } @@ -424,14 +450,16 @@ fn fieldless(adt: ty::AdtDef<'_>) -> bool { adt.is_enum() && adt.variants().iter().all(|v| v.fields.is_empty()) } -/// Whether `ty`'s `ne` reaches the crate's own `ne` of a type it holds: through tuples -/// and `Arc`s, but not an `Option`, whose `ne` is `!eq`. +/// Whether `ty`'s `ne` reaches the crate's own `ne` of a type it holds: through tuples, +/// `Arc`s, `Reverse`s, and the elements of slices, but not an `Option`, whose `ne` is +/// `!eq`. fn own_ne<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { ty::Tuple(tys) => tys.iter().any(|t| own_ne(b, t)), - ty::Adt(..) if let Some(inner) = arc_of(b, ty) => own_ne(b, inner), + _ if let Some(elem) = elements_of(b, ty) => own_ne(b, elem), + ty::Adt(..) if let Some(inner) = arc_of(b, ty).or_else(|| reverse_of(b, ty)) => own_ne(b, inner), ty::Adt(adt, _) if adt.did().is_local() => { let ne = trait_fn(tcx, "PartialEq", "ne"); Instance::try_resolve(tcx, b.t.typing_env_pub(), ne, tcx.mk_args(&[ty.into(), ty.into()])) @@ -793,7 +821,10 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => true, ty::Tuple(tys) => !tys.is_empty() && tys.iter().all(held), - ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)) => held(inner), + _ if let Some(elem) = elements_of(b, ty) => held(elem), + ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)).or_else(|| reverse_of(b, ty)) => { + held(inner) + } ty::Adt(..) => library::string(b.t.tcx, ty) || b.t.std_of(ty) == Some(Std::Ordering), _ => false, } @@ -804,6 +835,22 @@ fn option_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Option)).then(|| arg(ty, 0)) } +/// What `ty` holds if it is a `Reverse`. +fn reverse_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + (b.t.std_of(ty) == Some(Std::Reverse)).then(|| arg(ty, 0)) +} + +/// The elements of `ty` if it is a `Vec`, a slice, or an array that is a JS array: of any +/// type but `u8`, whose bytes are typed arrays. +fn elements_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + let elem = match ty.kind() { + ty::Slice(elem) | ty::Array(elem, _) => *elem, + ty::Adt(..) if b.t.std_of(ty) == Some(Std::Vec) => arg(ty, 0), + _ => return None, + }; + (!matches!(elem.kind(), ty::Uint(ty::UintTy::U8))).then_some(elem) +} + /// What `ty` holds if it is an `Arc`. fn arc_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Arc)).then(|| arg(ty, 0)) @@ -827,6 +874,10 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S Expr::rt("cmpOption", vec![cmp_fn(b, inner, partial, span)]) } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("cmpArc", vec![cmp_fn(b, inner, partial, span)]), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => { + Expr::rt("cmpReverse", vec![cmp_fn(b, inner, partial, span)]) + } + _ if let Some(elem) = elements_of(b, ty) => Expr::rt("cmpSlice", vec![cmp_fn(b, elem, partial, span)]), ty::Adt(adt, _) if adt.did().is_local() && partial => { let cmp = trait_fn(tcx, "PartialOrd", "partial_cmp"); b.fn_value(cmp, tcx.mk_args(&[ty.into(), ty.into()]), span) @@ -863,6 +914,14 @@ 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", vec![eq]), }, + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => eq_fn(b, inner, span), + // A slice compares its elements by `!=`, which `!eq` stands for only while that is + // the default. + _ if let Some(elem) = elements_of(b, ty) && own_ne(b, elem) => b.err( + span, + format!("comparing `{ty}` by `<{elem} as PartialEq>::ne` through a held type's own, which is not supported yet"), + ), + _ if let Some(elem) = elements_of(b, ty) => Expr::rt("eqSlice", vec![eq_fn(b, elem, span)]), ty::Adt(..) if let Some(inner) = arc_of(b, ty) => { let mut values = vec![eq_fn(b, inner, span)]; // std's `Arc` finds itself equal before comparing a value that is `Eq`. @@ -898,6 +957,8 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa Expr::rt("hashOption", vec![hash_fn(b, inner, hasher, span)]) } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("hashArc", vec![hash_fn(b, inner, hasher, span)]), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => hash_fn(b, inner, hasher, span), + _ if let Some(elem) = elements_of(b, ty) => Expr::rt("hashSlice", vec![hash_fn(b, elem, hasher, span)]), ty::Adt(adt, _) if adt.did().is_local() => { let hash = trait_fn(tcx, "Hash", "hash"); b.fn_value(hash, tcx.mk_args(&[ty.into(), hasher.into()]), span) diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index ae0ebab73..7758a08d7 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -89,6 +89,12 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { .map(|(t, v)| self.value(t, v, span)) .collect(), ), + // What core's wrappers of one value hold is that value, as is a pattern type's. + ty::Pat(base, _) => self.value(*base, valtree, span), + ty::Adt(..) if super::library::wrapped(tcx, ty).is_some() => match &children(valtree)[..] { + [(field_ty, field)] => self.value(*field_ty, *field, span), + _ => self.err(span, format!("a constant of type `{ty}` without one field")), + }, ty::Adt(adt, _) => { let fields = children(valtree); let (variant, fields) = match adt.is_enum() { @@ -121,6 +127,14 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { Expr::New(Box::new(Expr::Rt("RangeInclusive".into())), values) } (Std::Ordering, _) => super::collections::ordering_variant(variant), + (Std::Bound, _) => { + let ts_ty = self.t.ty(ty, span); + super::library::bound(adt.variant(variant).name.as_str(), values.pop(), ts_ty) + } + (Std::RangeTo | Std::RangeToInclusive, _) => { + super::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) + } + (Std::RangeFrom, _) => Expr::Object(vec![(Key::Name("start".into()), values.pop().unwrap())]), _ => self.err(span, format!("a constant of type `{ty}`")), }; } diff --git a/ts/src/lower/copy.rs b/ts/src/lower/copy.rs index e7743ff72..5ff33672d 100644 --- a/ts/src/lower/copy.rs +++ b/ts/src/lower/copy.rs @@ -36,7 +36,10 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { // Their payload, or no object at all; a write into an `rt.Result`'s payload // replaces the result. - Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow) => (false, args.types().collect()), + Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow | Std::Reverse) => { + (false, args.types().collect()) + } + Some(Std::Bound) => (true, args.types().collect()), Some(_) => return false, None if adt.did().is_local() && adt.all_fields().next().is_some() => { (true, adt.all_fields().map(|f| self.field_ty(f.did, args)).collect()) @@ -123,6 +126,20 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some(Std::Option) => ret(self.copy_unless(Expr::undefined(), args.type_at(0), span)), Some(Std::Poll) => ret(self.copy_unless(Expr::Rt("Pending".into()), args.type_at(0), span)), Some(Std::Result) => ret(self.copy_result(args.type_at(0), args.type_at(1), span)), + Some(Std::Reverse) => ret(self.copied(v(), args.type_at(0), span)), + Some(Std::Bound) => { + let ts_ty = self.ty(ty, span); + let held = self.copied(v().member("_0"), args.type_at(0), span); + let copy = Expr::Object(vec![ + (Key::Name("tag".into()), v().member("tag")), + (Key::Name("_0".into()), held), + ]); + ret(Expr::Cond( + Box::new(v().member("tag").binary("===", Expr::Str("Unbounded".into()))), + Box::new(v()), + Box::new(Expr::As(Box::new(copy), ts_ty)), + )) + } Some(Std::ControlFlow) => { let (residual, value) = (args.type_at(0), args.type_at(1)); ret(match (Flow::of(tcx, args), residual.kind()) { diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index 707cc0340..8167f56c5 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -43,7 +43,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::HashSet | Std::BTreeMap | Std::BTreeSet - | Std::VecDeque, + | Std::VecDeque + | Std::Bound + | Std::Reverse, ) => args.types().any(|t| self.drops(t)), // An entry borrows its map, and holds only the key it was given. Some(Std::Entry) => args.types().next().is_some_and(|k| self.drops(k)), @@ -94,7 +96,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { match ty.kind() { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { Some(Std::Waker) => true, - Some(Std::Arc | Std::Mutex | Std::Option | Std::Box | Std::Pin) => { + Some(Std::Arc | Std::Mutex | Std::Option | Std::Box | Std::Pin | Std::Reverse) => { self.disposable(args.type_at(0), span) } Some(_) => false, @@ -166,7 +168,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Ref(_, inner, _) => self.inert(*inner), ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { // Each is its contents in JS. - Some(Std::Option | Std::Box | Std::Mutex | Std::MutexGuard | Std::Poll | Std::Pin) => { + Some(Std::Option | Std::Box | Std::Mutex | Std::MutexGuard | Std::Poll | Std::Pin | Std::Reverse) => { args.types().all(|t| self.inert(t)) } // Its waker. @@ -209,7 +211,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { let (name, args) = match std { Std::Arc => ("arcDrop", vec![value, each(self, 0)?]), Std::Mutex => return self.drop_value(value.member("value"), args.type_at(0), span), - Std::Box | Std::Pin => return self.drop_value(value, args.type_at(0), span), + Std::Box | Std::Pin | Std::Reverse => return self.drop_value(value, args.type_at(0), span), Std::HashMap => ("hashDrop", vec![value, each(self, 0)?, each(self, 1)?]), Std::BTreeMap => ("btreeDrop", vec![value, each(self, 0)?, each(self, 1)?]), Std::HashSet => ("hashDrop", vec![value, each(self, 0)?]), @@ -314,7 +316,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Array(elem, _) => Some(*elem), ty::Adt(adt, args) => match Std::of(self.tcx, adt.did())? { Std::Vec => Some(args.type_at(0)), - Std::Option | Std::Box | Std::Pin => self.elements(args.type_at(0)), + Std::Option | Std::Box | Std::Pin | Std::Reverse => self.elements(args.type_at(0)), _ => None, }, _ => None, diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 2bac6375c..9f123982a 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -255,7 +255,8 @@ pub fn std_impl<'tcx>( ty::Adt(adt, args) => match (Std::of(tcx, adt.did())?, tr) { (Std::String | Std::Cow, Trait::Display) if library::string(tcx, ty) => Expr::rt("fmtPad", vec![f, value]), (Std::String | Std::Cow, Trait::Debug) if library::string(tcx, ty) => rt("str", vec![value, f]), - (Std::Box, _) => b.fmt_call(tr, args.type_at(0), value, f, span), + // A `NonZero` writes its integer, by each trait. + (Std::Box | Std::NonZero, _) => b.fmt_call(tr, args.type_at(0), value, f, span), (Std::Vec, Trait::Debug) => { let item = b.fmt_fn(tr, args.type_at(0), span); rt("list", vec![library::elements(value, ty), f, item]) diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index e6242ba6a..60f263eb1 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -74,6 +74,14 @@ pub enum Std { RangeTo, RangeFrom, RangeFull, + /// `..=end`: `{ end, inclusive: true }`. + RangeToInclusive, + /// `rt.Bound`, tagged as the crate's own enums are: `{ tag: "Included", _0 }`. + Bound, + /// What it holds, which orders the other way. + Reverse, + /// Its integer, which is never 0. + NonZero, /// A `format_args!` argument: a function writing its value, `rt.Fmt`. Argument, /// Its pointee: what an async body passes its context in. @@ -146,6 +154,7 @@ impl Std { (rustc_attr_ir::LangItem::RangeTo, Self::RangeTo), (rustc_attr_ir::LangItem::RangeFrom, Self::RangeFrom), (rustc_attr_ir::LangItem::RangeFull, Self::RangeFull), + (rustc_attr_ir::LangItem::RangeToInclusive, Self::RangeToInclusive), ] { if tcx.is_lang_item(did, item) { return Some(std); @@ -176,6 +185,9 @@ impl Std { ["ptr", "non_null", "NonNull"] => Some(Self::NonNull), ["convert", "Infallible"] => Some(Self::Infallible), ["cmp", "Ordering"] => Some(Self::Ordering), + ["cmp", "Reverse"] => Some(Self::Reverse), + ["ops", "range", "Bound"] => Some(Self::Bound), + ["num", "nonzero", "NonZero"] => Some(Self::NonZero), ["hash", "random", "DefaultHasher"] => Some(Self::Hasher), ["collections", "hash", "map", "Entry" | "OccupiedEntry" | "VacantEntry"] | [ @@ -242,6 +254,45 @@ pub fn string<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } } +/// What a value of `ty` is in JS if `ty` wraps one value it is represented as: `Reverse`'s +/// and `NonZero`'s `T`, which differ only in their order and range, a pattern type's +/// base, and the field of each of core's `niche_types` structs that hold one. +pub fn wrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Pat(base, _) => Some(*base), + ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { + Some(Std::Reverse | Std::NonZero) => Some(args.type_at(0)), + Some(_) => None, + None => { + let path = std_path(tcx, adt.did()); + if !(path.len() == 3 && path[0] == "num" && path[1] == "niche_types" && adt.is_struct()) { + return None; + } + let field = adt.non_enum_variant().fields.iter().next()?; + Some(field.ty(tcx, args).skip_norm_wip()) + } + }, + _ => None, + } +} + +/// A `Bound` of type `ty`, an `rt.Bound`: its variant, by name, and the value it holds, if +/// any. +pub fn bound(variant: &str, value: Option, ty: crate::ts::Type) -> Expr { + let mut props = vec![(crate::ts::Key::Name("tag".into()), Expr::Str(variant.into()))]; + props.extend(value.map(|v| (crate::ts::Key::Name("_0".into()), v))); + Expr::As(Box::new(Expr::Object(props)), ty) +} + +/// `..end`, or `..=end` if `inclusive`: `{ end }`, or `{ end, inclusive: true }`. +pub fn range_to(end: Expr, inclusive: bool) -> Expr { + let mut props = vec![(crate::ts::Key::Name("end".into()), end)]; + if inclusive { + props.push((crate::ts::Key::Name("inclusive".into()), Expr::lit("true"))); + } + Expr::Object(props) +} + /// The refusal of code that tells a `Cow`'s variants apart. pub fn cow_variant(ty: Ty<'_>) -> String { format!("a variant of `{ty}`, which is not supported: either is the same JS string") @@ -608,7 +659,7 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ) } ("PartialEq", "eq" | "ne") | ("PartialOrd", "lt" | "le" | "gt" | "ge") - if primitive(targ(gargs, 0).peel_refs()) => + if primitive(scalar(tcx, targ(gargs, 0))) => { let js = match name.as_str() { "eq" => "===", @@ -620,12 +671,12 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec }; let values = args; let [l, r] = <[Expr; 2]>::try_from(values).ok()?; - match Int::of(targ(gargs, 0).peel_refs()) { + match Int::of(scalar(tcx, targ(gargs, 0))) { Some(int) => int.compare(js, l, r), None => l.binary(js, r), } } - ("Ord", "max" | "min") if let Some(int) = Int::of(targ(gargs, 0)) => { + ("Ord", "max" | "min") if let Some(int) = Int::of(scalar(tcx, targ(gargs, 0))) => { let values = args; match int.big() { true => int.method(name.as_str(), values), @@ -1102,6 +1153,15 @@ fn int_named(name: &str) -> Option { Some(Int { bits, signed, pointer }) } +/// What a JS value of `ty` is through references and `NonZero`, which is its integer. +fn scalar<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + let ty = ty.peel_refs(); + match ty.kind() { + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::NonZero) => args.type_at(0), + _ => ty, + } +} + fn primitive(ty: Ty<'_>) -> bool { matches!(ty.kind(), ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Char) } diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 437add783..eab452825 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -292,7 +292,17 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } ty::Adt(adt, _) => match Std::of(tcx, adt.did()) { - Some(Std::Option | Std::Poll | Std::Box | Std::Pin) => base, + Some(Std::Option | Std::Poll | Std::Box | Std::Pin | Std::Reverse | Std::NonZero) => base, + // Cast to its variant, which a test narrows only where it reads the field. + Some(Std::Bound) => { + let ty::Adt(_, args) = ty.kind() else { unreachable!() }; + let variant = variant.unwrap_or(rustc_abi::FIRST_VARIANT); + let fields = vec![ + ("tag".to_string(), crate::ts::Type::StrLit(adt.variant(variant).name.to_string())), + ("_0".to_string(), self.b.t.ty(args.type_at(0), span)), + ]; + Expr::As(Box::new(base), crate::ts::Type::Object(fields)).member("_0") + } // A variant MIR reads without a test, since the other can't be, is cast to it. Some(Std::Result) => { let ok = variant.map_or(0, VariantIdx::index) == 0; @@ -319,13 +329,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }; base.member(name) } - Some(Std::Range | Std::RangeInclusive) => { + Some(Std::Range | Std::RangeInclusive | Std::RangeTo | Std::RangeFrom | Std::RangeToInclusive) => { base.member(adt.non_enum_variant().fields[field].name.as_str()) } Some(Std::Context | Std::NonNull | Std::Entry) => base, Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(Std::ControlFlow) => super::call::control_flow_field(self, base, ty, variant), - _ if transparent(self.b.t, ty) => base, + _ if transparent(self.b.t, ty) || crate::lower::library::wrapped(tcx, ty).is_some() => base, None if adt.did().is_local() => { let info = self.b.t.adt(*adt, span); match info.repr { @@ -591,6 +601,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Some(Std::Ordering) => scrut .clone() .binary("===", crate::lower::collections::ordering_variant(index)), + Some(Std::Bound) => scrut + .clone() + .member("tag") + .binary("===", Expr::Str(adt.variant(index).name.to_string())), _ => self.err(span, format!("a switch on `{ty}`")), } } diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index 1b9e441ae..6b80f5158 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -218,6 +218,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }, // An async body's context passes through `ResumeTy` and `NonNull`. CastKind::Transmute if context_like(self, from) && context_like(self, to) => self.operand(op, span, out), + // A pattern type, as `NonZero` holds, is its base type's value. + CastKind::Transmute if peel_pat(from) == peel_pat(to) => self.operand(op, span, out), _ => self.err(span, format!("a `{kind:?}` cast from `{from}` to `{to}`")), } } @@ -251,6 +253,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { // The value is its discriminant. Some(Std::Ordering) => scrut, Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), + Some(Std::Bound) => { + let table = discrs + .iter() + .map(|(i, d)| (Key::Name(adt.variant(*i).name.to_string()), int.lit(*d as i128))) + .collect(); + Expr::Index(Box::new(Expr::Object(table)), Box::new(scrut.member("tag"))) + } None if adt.did().is_local() => { let info = self.b.t.adt(*adt, span); let table = discrs @@ -349,7 +358,14 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::FmtError, _) => Expr::New(Box::new(Expr::Rt("FmtError".into())), Vec::new()), // `ResumeTy`, an async body's context. (Std::Context, _) => values.pop().unwrap_or_else(Expr::undefined), - (Std::RangeTo, _) => Expr::Object(vec![(Key::Name("end".into()), values.pop().unwrap())]), + (Std::RangeTo | Std::RangeToInclusive, _) => { + crate::lower::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) + } + (Std::Reverse, _) => values.pop().unwrap(), + (Std::Bound, _) => { + let ts_ty = self.b.t.ty(ty, span); + crate::lower::library::bound(def.name.as_str(), values.pop(), ts_ty) + } (Std::RangeFrom, _) => Expr::Object(vec![(Key::Name("start".into()), values.pop().unwrap())]), (Std::RangeFull, _) => Expr::undefined(), (Std::Ordering, _) => crate::lower::collections::ordering_variant(variant), @@ -373,7 +389,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { _ => self.err(span, format!("constructing `{ty}`")), }; } - if super::place::transparent(self.b.t, ty) { + if super::place::transparent(self.b.t, ty) || crate::lower::library::wrapped(tcx, ty).is_some() { return values.pop().unwrap_or_else(Expr::undefined); } match crate::lower::library::std_path(tcx, def_id) @@ -564,3 +580,11 @@ pub fn memory<'tcx>(rvalue: &Rvalue<'tcx>, fx: &Fx<'_, '_, '_, 'tcx>) -> bool { Rvalue::ThreadLocalRef(_) | Rvalue::WrapUnsafeBinder(..) | Rvalue::Reborrow(..) => true, } } + +/// A pattern type's base, or `ty` itself. +fn peel_pat(ty: Ty<'_>) -> Ty<'_> { + match ty.kind() { + ty::Pat(base, _) => *base, + _ => ty, + } +} diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index dcdc450f9..d81163749 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -916,6 +916,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { self.fn_ty(&inputs, sig.output(), span) } ty::Adt(adt, args) => self.adt_ty(*adt, args, span), + ty::Pat(base, _) => self.ty(*base, span), ty::Coroutine(_, args) => Type::Rt("Future", vec![self.ty(args.as_coroutine().return_ty(), span)]), // `&dyn Debug` and `&dyn Display` are values ready to write. ty::Dynamic(preds, ..) @@ -1042,7 +1043,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { self.unrepresented(span, format!("`{}` is not supported yet", Ty::new_adt(tcx, adt, args))); Type::Builtin("unknown") } - library::Std::Box => self.ty(args.type_at(0), span), + library::Std::Box | library::Std::Reverse | library::Std::NonZero => self.ty(args.type_at(0), span), + library::Std::Bound => Type::Rt("Bound", vec![self.ty(args.type_at(0), span)]), library::Std::FromUtf8Error => Type::Rt("FromUtf8Error", vec![]), library::Std::TryFromIntError => Type::Rt("TryFromIntError", vec![]), library::Std::Formatter => Type::Rt("Formatter", vec![]), @@ -1072,6 +1074,10 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { library::Std::Range => Type::Rt("Range", vec![self.ty(args.type_at(0), span)]), library::Std::RangeInclusive => Type::Rt("RangeInclusive", vec![self.ty(args.type_at(0), span)]), library::Std::RangeTo => Type::Object(vec![("end".into(), self.ty(args.type_at(0), span))]), + library::Std::RangeToInclusive => Type::Object(vec![ + ("end".into(), self.ty(args.type_at(0), span)), + ("inclusive".into(), Type::Builtin("true")), + ]), library::Std::RangeFrom => Type::Object(vec![("start".into(), self.ty(args.type_at(0), span))]), library::Std::RangeFull => Type::Builtin("undefined"), library::Std::Argument => Type::Rt("Fmt", vec![]), @@ -1119,6 +1125,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } }; } + if let Some(inner) = library::wrapped(tcx, Ty::new_adt(tcx, adt, args)) { + return self.ty(inner, span); + } // Every other iterator std has is an `rt.Iter` of its items. if !adt.did().is_local() && let Some(item) = self.iter_item(Ty::new_adt(tcx, adt, args)) @@ -1158,7 +1167,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { }, ty::Ref(_, inner, _) => self.erases_to(*inner), ty::Adt(adt, args) => match library::Std::of(self.tcx, adt.did()) { - Some(library::Std::Box | library::Std::Pin) => self.erases_to(args.type_at(0)), + Some(library::Std::Box | library::Std::Pin | library::Std::Reverse | library::Std::NonZero) => { + self.erases_to(args.type_at(0)) + } Some(library::Std::Option) => Erased { undefined: true, ..self.erases_to(args.type_at(0)) From 9961d745db3391f56de93e570c6b817ee023cdcb Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:45:24 -0700 Subject: [PATCH 03/11] feat(ts): translate saturating_mul, wrapping_mul, div_ceil, is_multiple_of, and clamp of integers Each integer type's `saturating_mul` and `wrapping_mul`, the unsigned types' `div_ceil` and `is_multiple_of`, and `Ord::clamp` of integers, as runtime functions with std's panics, `clamp`'s naming both bounds. The lang fixture runs each as its own case, and the wide sweep adds them near powers of two. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/expected/ints.ts | 1716 +++++++++++++++++------------ ts/fixtures/lang/src/ints.rs | 64 +- ts/runtime/rt/int.ts | 166 ++- ts/src/lower/library.rs | 8 + ts/tests/differential.ts | 18 +- ts/tests/fixtures.rs | 2 +- 6 files changed, 1219 insertions(+), 755 deletions(-) diff --git a/ts/fixtures/lang/expected/ints.ts b/ts/fixtures/lang/expected/ints.ts index fe76bf97b..0ba5a600c 100644 --- a/ts/fixtures/lang/expected/ints.ts +++ b/ts/fixtures/lang/expected/ints.ts @@ -4,17 +4,17 @@ import * as rt from "./rt.ts"; /** Apply operation `op` to operands taken from `data`. */ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u8) => void = (out2: rt.ByteVec, v: rt.u8): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u8FromBeBytes(rt.u8ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u8) => void = (out2: rt.ByteVec, v2: rt.u8): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u8FromBeBytes(rt.u8ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u8 | undefined) => void = (out3: rt.ByteVec, v2: rt.u8 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u8 | undefined) => void = (out3: rt.ByteVec, v3: rt.u8 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u8 = v2; + const v4: rt.u8 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = Uint8Array.of(0); @@ -29,69 +29,92 @@ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u8 = rt.u8FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u8 = _38; + const buf3: Uint8Array = Uint8Array.of(0); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u8 = ([rt.u8FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u8, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 8); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u8Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u8Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u8Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u8Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u8Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.u8Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u8Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a & 0xff); - } else if (_52 === 11) { - const part9 = rt.u8CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u8CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u8CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u8SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u8SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u8WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u8WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u8Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u8Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u8Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u8Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u8Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.u8Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u8Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a & 0xff); + } else if (_70 === 11) { + const part12 = rt.u8CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u8CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u8CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u8SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u8SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u8WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u8WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u8LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u8LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u8WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u8 = rt.u8Add(a, b); rt.u8Mul(x, b); rt.u8Mul(rt.u8Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u8SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u8WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u8 | undefined = rt.u8DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u8IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u8 = a; x2 = rt.u8Add(x2, b); @@ -104,23 +127,23 @@ export function u8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & (~(1 << 2) & 0xff); x2 = rt.u8Rem(x2, 7); x2 = rt.u8Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u16) => void = (out2: rt.ByteVec, v: rt.u16): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u16FromBeBytes(rt.u16ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u16) => void = (out2: rt.ByteVec, v2: rt.u16): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u16FromBeBytes(rt.u16ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u16 | undefined) => void = (out3: rt.ByteVec, v2: rt.u16 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u16 | undefined) => void = (out3: rt.ByteVec, v3: rt.u16 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u16 = v2; + const v4: rt.u16 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(2); @@ -135,69 +158,92 @@ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u16 = rt.u16FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u16 = _38; + const buf3: Uint8Array = rt.bytes(2); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u16 = ([rt.u16FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u16, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 16); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u16Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u16Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u16Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u16Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u16Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.u16Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u16Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a & 0xffff); - } else if (_52 === 11) { - const part9 = rt.u16CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u16CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u16CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u16SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u16SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u16WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u16WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u16Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u16Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u16Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u16Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u16Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.u16Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u16Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a & 0xffff); + } else if (_70 === 11) { + const part12 = rt.u16CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u16CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u16CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u16SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u16SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u16WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u16WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u16LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u16LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u16WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u16 = rt.u16Add(a, b); rt.u16Mul(x, b); rt.u16Mul(rt.u16Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u16SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u16WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u16 | undefined = rt.u16DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u16IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u16 = a; x2 = rt.u16Add(x2, b); @@ -210,23 +256,23 @@ export function u16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & (~(1 << 2) & 0xffff); x2 = rt.u16Rem(x2, 7); x2 = rt.u16Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u32) => void = (out2: rt.ByteVec, v: rt.u32): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.u32FromBeBytes(rt.u32ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u32) => void = (out2: rt.ByteVec, v2: rt.u32): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.u32FromBeBytes(rt.u32ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u32 | undefined) => void = (out3: rt.ByteVec, v2: rt.u32 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u32 | undefined) => void = (out3: rt.ByteVec, v3: rt.u32 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u32 = v2; + const v4: rt.u32 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -241,69 +287,92 @@ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u32 = rt.u32FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u32 = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u32 = ([rt.u32FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u32, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u32Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u32Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u32Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u32Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u32Rem(a, b)); - } else if (_52 === 5) { - _50(out, (a & b) >>> 0); - } else if (_52 === 6) { - _50(out, (a | b) >>> 0); - } else if (_52 === 7) { - _50(out, (a ^ b) >>> 0); - } else if (_52 === 8) { - _50(out, rt.u32Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u32Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a >>> 0); - } else if (_52 === 11) { - const part9 = rt.u32CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u32CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u32CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u32SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u32SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u32WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u32WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u32Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u32Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u32Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u32Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u32Rem(a, b)); + } else if (_70 === 5) { + _68(out, (a & b) >>> 0); + } else if (_70 === 6) { + _68(out, (a | b) >>> 0); + } else if (_70 === 7) { + _68(out, (a ^ b) >>> 0); + } else if (_70 === 8) { + _68(out, rt.u32Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u32Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a >>> 0); + } else if (_70 === 11) { + const part12 = rt.u32CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u32CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u32CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u32SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u32SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u32WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u32WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.u32WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u32 = rt.u32Add(a, b); rt.u32Mul(x, b); rt.u32Mul(rt.u32Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u32SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u32WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u32 | undefined = rt.u32DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u32IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u32 = a; x2 = rt.u32Add(x2, b); @@ -316,23 +385,23 @@ export function u32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = (x2 & (~(1 << 2) >>> 0)) >>> 0; x2 = rt.u32Rem(x2, 7); x2 = rt.u32Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u64) => void = (out2: rt.ByteVec, v: rt.u64): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v)))); - rt.byteVecPush(out2, rt.u64Eq(rt.u64FromBeBytes(rt.u64ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u64) => void = (out2: rt.ByteVec, v2: rt.u64): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v2)))); + rt.byteVecPush(out2, rt.u64Eq(rt.u64FromBeBytes(rt.u64ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u64 | undefined) => void = (out3: rt.ByteVec, v2: rt.u64 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u64 | undefined) => void = (out3: rt.ByteVec, v3: rt.u64 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u64 = v2; + const v4: rt.u64 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v3)))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128Cast(v4)))); } }; const buf: Uint8Array = rt.bytes(8); @@ -347,69 +416,92 @@ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u64 = rt.u64FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u64 = _38; + const buf3: Uint8Array = rt.bytes(8); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u64 = ([rt.u64FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u64, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 64); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u64Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u64Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u64Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u64Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u64Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.u64And(a, b)); - } else if (_52 === 6) { - _50(out, rt.u64Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.u64Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.u64Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u64Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.u64Not(a)); - } else if (_52 === 11) { - const part9 = rt.u64CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u64CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u64CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u64SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u64SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u64WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u64WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u64Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u64Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u64Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u64Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u64Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.u64And(a, b)); + } else if (_70 === 6) { + _68(out, rt.u64Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.u64Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.u64Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u64Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.u64Not(a)); + } else if (_70 === 11) { + const part12 = rt.u64CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u64CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u64CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u64SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u64SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u64WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u64WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u64LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u64LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.u64Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.u64Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.u64Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.u64Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.u64Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u64WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u64 = rt.u64Add(a, b); rt.u64Mul(x, b); rt.u64Mul(rt.u64Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u64SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u64WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.u64Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u64 | undefined = rt.u64DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u64IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u64 = a; x2 = rt.u64Add(x2, b); @@ -422,23 +514,23 @@ export function u64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.u64And(x2, rt.u64Not(4)); x2 = rt.u64Rem(x2, 7); x2 = rt.u64Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.u128) => void = (out2: rt.ByteVec, v: rt.u128): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v))); - rt.byteVecPush(out2, rt.u128Eq(rt.u128FromBeBytes(rt.u128ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.u128) => void = (out2: rt.ByteVec, v2: rt.u128): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2))); + rt.byteVecPush(out2, rt.u128Eq(rt.u128FromBeBytes(rt.u128ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.u128 | undefined) => void = (out3: rt.ByteVec, v2: rt.u128 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.u128 | undefined) => void = (out3: rt.ByteVec, v3: rt.u128 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.u128 = v2; + const v4: rt.u128 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4))); } }; const buf: Uint8Array = rt.bytes(16); @@ -453,69 +545,92 @@ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.u128 = rt.u128FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.u128 = _38; + const buf3: Uint8Array = rt.bytes(16); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.u128 = ([rt.u128FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.u128, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 128); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.u128Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.u128Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.u128Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.u128Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.u128Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.u128And(a, b)); - } else if (_52 === 6) { - _50(out, rt.u128Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.u128Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.u128Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.u128Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.u128Not(a)); - } else if (_52 === 11) { - const part9 = rt.u128CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.u128CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.u128CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.u128SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.u128SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.u128WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.u128WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.u128Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.u128Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.u128Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.u128Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.u128Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.u128And(a, b)); + } else if (_70 === 6) { + _68(out, rt.u128Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.u128Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.u128Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.u128Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.u128Not(a)); + } else if (_70 === 11) { + const part12 = rt.u128CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.u128CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.u128CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.u128SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.u128SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.u128WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.u128WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u128LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u128LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.u128Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.u128Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.u128Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.u128Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.u128Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.u128WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.u128 = rt.u128Add(a, b); rt.u128Mul(x, b); rt.u128Mul(rt.u128Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.u128SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.u128WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.u128Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.u128 | undefined = rt.u128DivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.u128IsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.u128 = a; x2 = rt.u128Add(x2, b); @@ -528,23 +643,23 @@ export function u128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.u128And(x2, rt.u128Not(rt.u128Shl(1, 2))); x2 = rt.u128Rem(x2, 7); x2 = rt.u128Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.usize) => void = (out2: rt.ByteVec, v: rt.usize): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v as rt.u128))); - rt.byteVecPush(out2, rt.usizeFromBeBytes(rt.usizeToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.usize) => void = (out2: rt.ByteVec, v2: rt.usize): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v2 as rt.u128))); + rt.byteVecPush(out2, rt.usizeFromBeBytes(rt.usizeToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.usize | undefined) => void = (out3: rt.ByteVec, v2: rt.usize | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.usize | undefined) => void = (out3: rt.ByteVec, v3: rt.usize | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.usize = v2; + const v4: rt.usize = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v3 as rt.u128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.u128ToBeBytes(v4 as rt.u128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -559,69 +674,92 @@ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.usize = rt.usizeFromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.usize = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.usize = ([rt.usizeFromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.usize, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.usizeAdd(a, b)); - } else if (_52 === 1) { - _50(out, rt.usizeSub(a, b)); - } else if (_52 === 2) { - _50(out, rt.usizeMul(a, b)); - } else if (_52 === 3) { - _50(out, rt.usizeDiv(a, b)); - } else if (_52 === 4) { - _50(out, rt.usizeRem(a, b)); - } else if (_52 === 5) { - _50(out, (a & b) >>> 0); - } else if (_52 === 6) { - _50(out, (a | b) >>> 0); - } else if (_52 === 7) { - _50(out, (a ^ b) >>> 0); - } else if (_52 === 8) { - _50(out, rt.usizeShl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.usizeShr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a >>> 0); - } else if (_52 === 11) { - const part9 = rt.usizeCheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.usizeCheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.usizeCheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.usizeSaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.usizeSaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.usizeWrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.usizeWrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.usizeAdd(a, b)); + } else if (_70 === 1) { + _68(out, rt.usizeSub(a, b)); + } else if (_70 === 2) { + _68(out, rt.usizeMul(a, b)); + } else if (_70 === 3) { + _68(out, rt.usizeDiv(a, b)); + } else if (_70 === 4) { + _68(out, rt.usizeRem(a, b)); + } else if (_70 === 5) { + _68(out, (a & b) >>> 0); + } else if (_70 === 6) { + _68(out, (a | b) >>> 0); + } else if (_70 === 7) { + _68(out, (a ^ b) >>> 0); + } else if (_70 === 8) { + _68(out, rt.usizeShl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.usizeShr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a >>> 0); + } else if (_70 === 11) { + const part12 = rt.usizeCheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.usizeCheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.usizeCheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.usizeSaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.usizeSaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.usizeWrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.usizeWrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.usizeLeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.usizeLeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.usizeWrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.usize = rt.usizeAdd(a, b); rt.usizeMul(x, b); rt.usizeMul(rt.usizeSub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.usizeSaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.usizeWrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _176: rt.usize | undefined = rt.usizeDivCeil(a, b); + if (_176 !== undefined) { + _68(out, _176); + } + } else if (_70 === 28) { + const _183: boolean | undefined = rt.usizeIsMultipleOf(a, b); + if (_183 !== undefined) { + rt.byteVecPush(out, _183 ? 1 : 0); + } } else { let x2: rt.usize = a; x2 = rt.usizeAdd(x2, b); @@ -634,23 +772,23 @@ export function usizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = (x2 & (~(1 << 2) >>> 0)) >>> 0; x2 = rt.usizeRem(x2, 7); x2 = rt.usizeDiv(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i8) => void = (out2: rt.ByteVec, v: rt.i8): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i8FromBeBytes(rt.i8ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i8) => void = (out2: rt.ByteVec, v2: rt.i8): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i8FromBeBytes(rt.i8ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i8 | undefined) => void = (out3: rt.ByteVec, v2: rt.i8 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i8 | undefined) => void = (out3: rt.ByteVec, v3: rt.i8 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i8 = v2; + const v4: rt.i8 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = Uint8Array.of(0); @@ -665,69 +803,92 @@ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i8 = rt.i8FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i8 = _38; + const buf3: Uint8Array = Uint8Array.of(0); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i8 = ([rt.i8FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i8, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 8); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i8Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i8Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i8Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i8Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i8Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i8Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i8Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i8CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i8CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i8CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i8SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i8SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i8WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i8WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i8Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i8Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i8Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i8Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i8Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i8Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i8Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i8CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i8CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i8CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i8SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i8SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i8WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i8WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i8LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i8LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i8WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i8 = rt.i8Add(a, b); rt.i8Mul(x, b); rt.i8Mul(rt.i8Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i8SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i8WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i8 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i8 = a; x2 = rt.i8Add(x2, b); @@ -740,23 +901,23 @@ export function i8Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i8Rem(x2, 7); x2 = rt.i8Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i16) => void = (out2: rt.ByteVec, v: rt.i16): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i16FromBeBytes(rt.i16ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i16) => void = (out2: rt.ByteVec, v2: rt.i16): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i16FromBeBytes(rt.i16ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i16 | undefined) => void = (out3: rt.ByteVec, v2: rt.i16 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i16 | undefined) => void = (out3: rt.ByteVec, v3: rt.i16 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i16 = v2; + const v4: rt.i16 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(2); @@ -771,69 +932,92 @@ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i16 = rt.i16FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i16 = _38; + const buf3: Uint8Array = rt.bytes(2); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i16 = ([rt.i16FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i16, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 16); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i16Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i16Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i16Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i16Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i16Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i16Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i16Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i16CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i16CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i16CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i16SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i16SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i16WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i16WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i16Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i16Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i16Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i16Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i16Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i16Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i16Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i16CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i16CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i16CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i16SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i16SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i16WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i16WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i16LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i16LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i16WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i16 = rt.i16Add(a, b); rt.i16Mul(x, b); rt.i16Mul(rt.i16Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i16SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i16WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i16 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i16 = a; x2 = rt.i16Add(x2, b); @@ -846,23 +1030,23 @@ export function i16Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i16Rem(x2, 7); x2 = rt.i16Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i32) => void = (out2: rt.ByteVec, v: rt.i32): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.i32FromBeBytes(rt.i32ToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i32) => void = (out2: rt.ByteVec, v2: rt.i32): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.i32FromBeBytes(rt.i32ToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i32 | undefined) => void = (out3: rt.ByteVec, v2: rt.i32 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i32 | undefined) => void = (out3: rt.ByteVec, v3: rt.i32 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i32 = v2; + const v4: rt.i32 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -877,69 +1061,92 @@ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i32 = rt.i32FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i32 = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i32 = ([rt.i32FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i32, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i32Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i32Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i32Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i32Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i32Rem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.i32Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i32Shr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.i32CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i32CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i32CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i32SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i32SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i32WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i32WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i32Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i32Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i32Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i32Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i32Rem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.i32Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i32Shr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.i32CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i32CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i32CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i32SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i32SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i32WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i32WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i32LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i32LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.i32WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i32 = rt.i32Add(a, b); rt.i32Mul(x, b); rt.i32Mul(rt.i32Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i32SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i32WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i32 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i32 = a; x2 = rt.i32Add(x2, b); @@ -952,23 +1159,23 @@ export function i32Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.i32Rem(x2, 7); x2 = rt.i32Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i64) => void = (out2: rt.ByteVec, v: rt.i64): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v)))); - rt.byteVecPush(out2, rt.i64Eq(rt.i64FromBeBytes(rt.i64ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i64) => void = (out2: rt.ByteVec, v2: rt.i64): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v2)))); + rt.byteVecPush(out2, rt.i64Eq(rt.i64FromBeBytes(rt.i64ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i64 | undefined) => void = (out3: rt.ByteVec, v2: rt.i64 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i64 | undefined) => void = (out3: rt.ByteVec, v3: rt.i64 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i64 = v2; + const v4: rt.i64 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v3)))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128Cast(v4)))); } }; const buf: Uint8Array = rt.bytes(8); @@ -983,69 +1190,92 @@ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i64 = rt.i64FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i64 = _38; + const buf3: Uint8Array = rt.bytes(8); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i64 = ([rt.i64FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i64, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 64); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i64Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i64Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i64Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i64Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i64Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.i64And(a, b)); - } else if (_52 === 6) { - _50(out, rt.i64Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.i64Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.i64Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i64Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.i64Not(a)); - } else if (_52 === 11) { - const part9 = rt.i64CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i64CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i64CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i64SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i64SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i64WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i64WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i64Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i64Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i64Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i64Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i64Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.i64And(a, b)); + } else if (_70 === 6) { + _68(out, rt.i64Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.i64Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.i64Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i64Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.i64Not(a)); + } else if (_70 === 11) { + const part12 = rt.i64CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i64CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i64CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i64SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i64SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i64WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i64WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i64LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i64LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.i64Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.i64Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.i64Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.i64Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.i64Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i64WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i64 = rt.i64Add(a, b); rt.i64Mul(x, b); rt.i64Mul(rt.i64Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i64SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i64WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.i64Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i64 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i64 = a; x2 = rt.i64Add(x2, b); @@ -1058,23 +1288,23 @@ export function i64Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.i64And(x2, rt.i64Not(4)); x2 = rt.i64Rem(x2, 7); x2 = rt.i64Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.i128) => void = (out2: rt.ByteVec, v: rt.i128): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v))); - rt.byteVecPush(out2, rt.i128Eq(rt.i128FromBeBytes(rt.i128ToBeBytes(v)), v) ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.i128) => void = (out2: rt.ByteVec, v2: rt.i128): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2))); + rt.byteVecPush(out2, rt.i128Eq(rt.i128FromBeBytes(rt.i128ToBeBytes(v2)), v2) ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.i128 | undefined) => void = (out3: rt.ByteVec, v2: rt.i128 | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.i128 | undefined) => void = (out3: rt.ByteVec, v3: rt.i128 | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.i128 = v2; + const v4: rt.i128 = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4))); } }; const buf: Uint8Array = rt.bytes(16); @@ -1089,69 +1319,92 @@ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.i128 = rt.i128FromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.i128 = _38; + const buf3: Uint8Array = rt.bytes(16); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.i128 = ([rt.i128FromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.i128, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 128); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.i128Add(a, b)); - } else if (_52 === 1) { - _50(out, rt.i128Sub(a, b)); - } else if (_52 === 2) { - _50(out, rt.i128Mul(a, b)); - } else if (_52 === 3) { - _50(out, rt.i128Div(a, b)); - } else if (_52 === 4) { - _50(out, rt.i128Rem(a, b)); - } else if (_52 === 5) { - _50(out, rt.i128And(a, b)); - } else if (_52 === 6) { - _50(out, rt.i128Or(a, b)); - } else if (_52 === 7) { - _50(out, rt.i128Xor(a, b)); - } else if (_52 === 8) { - _50(out, rt.i128Shl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.i128Shr(a, shift)); - } else if (_52 === 10) { - _50(out, rt.i128Not(a)); - } else if (_52 === 11) { - const part9 = rt.i128CheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.i128CheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.i128CheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.i128SaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.i128SaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.i128WrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.i128WrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.i128Add(a, b)); + } else if (_70 === 1) { + _68(out, rt.i128Sub(a, b)); + } else if (_70 === 2) { + _68(out, rt.i128Mul(a, b)); + } else if (_70 === 3) { + _68(out, rt.i128Div(a, b)); + } else if (_70 === 4) { + _68(out, rt.i128Rem(a, b)); + } else if (_70 === 5) { + _68(out, rt.i128And(a, b)); + } else if (_70 === 6) { + _68(out, rt.i128Or(a, b)); + } else if (_70 === 7) { + _68(out, rt.i128Xor(a, b)); + } else if (_70 === 8) { + _68(out, rt.i128Shl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.i128Shr(a, shift)); + } else if (_70 === 10) { + _68(out, rt.i128Not(a)); + } else if (_70 === 11) { + const part12 = rt.i128CheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.i128CheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.i128CheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.i128SaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.i128SaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.i128WrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.i128WrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i128LeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.i128LeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.i128Max(a, b)); - } else if (_52 === 21) { - _50(out, rt.i128Min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.i128Max(a, b)); + } else if (_70 === 21) { + _68(out, rt.i128Min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, rt.i128Eq(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128Lt(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128Ge(a, b) ? 1 : 0); rt.byteVecPush(out, rt.i128WrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.i128 = rt.i128Add(a, b); rt.i128Mul(x, b); rt.i128Mul(rt.i128Sub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.i128SaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.i128WrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.i128Clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.i128 | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.i128 = a; x2 = rt.i128Add(x2, b); @@ -1164,23 +1417,23 @@ export function i128Op(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = rt.i128And(x2, rt.i128Not(rt.i128Shl(1, 2))); x2 = rt.i128Rem(x2, 7); x2 = rt.i128Div(x2, 3); - _50(out, x2); + _68(out, x2); } } /** Apply operation `op` to operands taken from `data`. */ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { - const _50: (a0: rt.ByteVec, a1: rt.isize) => void = (out2: rt.ByteVec, v: rt.isize): void => { - rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v as rt.i128))); - rt.byteVecPush(out2, rt.isizeFromBeBytes(rt.isizeToBeBytes(v)) === v ? 1 : 0); + const _68: (a0: rt.ByteVec, a1: rt.isize) => void = (out2: rt.ByteVec, v2: rt.isize): void => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v2 as rt.i128))); + rt.byteVecPush(out2, rt.isizeFromBeBytes(rt.isizeToBeBytes(v2)) === v2 ? 1 : 0); }; - const _51: (a0: rt.ByteVec, a1: rt.isize | undefined) => void = (out3: rt.ByteVec, v2: rt.isize | undefined): void => { - if (v2 === undefined) { + const _69: (a0: rt.ByteVec, a1: rt.isize | undefined) => void = (out3: rt.ByteVec, v3: rt.isize | undefined): void => { + if (v3 === undefined) { rt.byteVecPush(out3, 0); } else { - const v3: rt.isize = v2; + const v4: rt.isize = v3; rt.byteVecPush(out3, 1); - rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v3 as rt.i128))); + rt.byteVecExtendFromSlice(out3, rt.byteSliceFrom(rt.i128ToBeBytes(v4 as rt.i128))); } }; const buf: Uint8Array = rt.bytes(4); @@ -1195,69 +1448,92 @@ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const _38: rt.isize = rt.isizeFromBeBytes(buf2); const _40: rt.ByteSlice = rt.byteSliceRange(_21, n2); const b: rt.isize = _38; + const buf3: Uint8Array = rt.bytes(4); + const n3: rt.usize = rt.min(_40.length, rt.byteSliceFrom(buf3).length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(rt.byteSliceFrom(buf3), 0, n3), rt.byteSliceRange(_40, 0, n3)); + const c: rt.isize = ([rt.isizeFromBeBytes(buf3), rt.byteSliceRange(_40, n3)] as [rt.isize, rt.ByteSlice])[0]; const shift: rt.u32 = rt.u32Rem(rt.optionUnwrapOr(rt.byteSliceFirst(_40), 0) as rt.u32, 2 * 32); - const _52: rt.u8 = rt.u8Rem(op, 25); - if (_52 === 0) { - _50(out, rt.isizeAdd(a, b)); - } else if (_52 === 1) { - _50(out, rt.isizeSub(a, b)); - } else if (_52 === 2) { - _50(out, rt.isizeMul(a, b)); - } else if (_52 === 3) { - _50(out, rt.isizeDiv(a, b)); - } else if (_52 === 4) { - _50(out, rt.isizeRem(a, b)); - } else if (_52 === 5) { - _50(out, a & b); - } else if (_52 === 6) { - _50(out, a | b); - } else if (_52 === 7) { - _50(out, a ^ b); - } else if (_52 === 8) { - _50(out, rt.isizeShl(a, shift)); - } else if (_52 === 9) { - _50(out, rt.isizeShr(a, shift)); - } else if (_52 === 10) { - _50(out, ~a); - } else if (_52 === 11) { - const part9 = rt.isizeCheckedAdd(a, b); - _51(out, part9); - } else if (_52 === 12) { - const part8 = rt.isizeCheckedSub(a, b); - _51(out, part8); - } else if (_52 === 13) { - const part7 = rt.isizeCheckedMul(a, b); - _51(out, part7); - } else if (_52 === 14) { - const part6 = rt.isizeSaturatingAdd(a, b); - _50(out, part6); - } else if (_52 === 15) { - const part5 = rt.isizeSaturatingSub(a, b); - _50(out, part5); - } else if (_52 === 16) { - const part4 = rt.isizeWrappingAdd(a, b); - _50(out, part4); - } else if (_52 === 17) { - const part3 = rt.isizeWrappingSub(a, b); - _50(out, part3); - } else if (_52 === 18) { + const _70: rt.u8 = rt.u8Rem(op, 30); + if (_70 === 0) { + _68(out, rt.isizeAdd(a, b)); + } else if (_70 === 1) { + _68(out, rt.isizeSub(a, b)); + } else if (_70 === 2) { + _68(out, rt.isizeMul(a, b)); + } else if (_70 === 3) { + _68(out, rt.isizeDiv(a, b)); + } else if (_70 === 4) { + _68(out, rt.isizeRem(a, b)); + } else if (_70 === 5) { + _68(out, a & b); + } else if (_70 === 6) { + _68(out, a | b); + } else if (_70 === 7) { + _68(out, a ^ b); + } else if (_70 === 8) { + _68(out, rt.isizeShl(a, shift)); + } else if (_70 === 9) { + _68(out, rt.isizeShr(a, shift)); + } else if (_70 === 10) { + _68(out, ~a); + } else if (_70 === 11) { + const part12 = rt.isizeCheckedAdd(a, b); + _69(out, part12); + } else if (_70 === 12) { + const part11 = rt.isizeCheckedSub(a, b); + _69(out, part11); + } else if (_70 === 13) { + const part10 = rt.isizeCheckedMul(a, b); + _69(out, part10); + } else if (_70 === 14) { + const part9 = rt.isizeSaturatingAdd(a, b); + _68(out, part9); + } else if (_70 === 15) { + const part8 = rt.isizeSaturatingSub(a, b); + _68(out, part8); + } else if (_70 === 16) { + const part7 = rt.isizeWrappingAdd(a, b); + _68(out, part7); + } else if (_70 === 17) { + const part6 = rt.isizeWrappingSub(a, b); + _68(out, part6); + } else if (_70 === 18) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.isizeLeadingOnes(a)))); - } else if (_52 === 19) { + } else if (_70 === 19) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.isizeLeadingZeros(a)))); - } else if (_52 === 20) { - _50(out, rt.max(a, b)); - } else if (_52 === 21) { - _50(out, rt.min(a, b)); - } else if (_52 === 22) { + } else if (_70 === 20) { + _68(out, rt.max(a, b)); + } else if (_70 === 21) { + _68(out, rt.min(a, b)); + } else if (_70 === 22) { rt.byteVecPush(out, a === b ? 1 : 0); rt.byteVecPush(out, a < b ? 1 : 0); rt.byteVecPush(out, a >= b ? 1 : 0); rt.byteVecPush(out, rt.isizeWrappingSub(a, b) === 0 ? 1 : 0); - } else if (_52 === 23) { + } else if (_70 === 23) { const x: rt.isize = rt.isizeAdd(a, b); rt.isizeMul(x, b); rt.isizeMul(rt.isizeSub(x, b), a); rt.byteVecPush(out, 1); + } else if (_70 === 24) { + const part3 = rt.isizeSaturatingMul(a, b); + _68(out, part3); + } else if (_70 === 25) { + const part2 = rt.isizeWrappingMul(a, b); + _68(out, part2); + } else if (_70 === 26) { + const part = rt.clamp(a, b, c); + _68(out, part); + } else if (_70 === 27) { + const _182 = undefined as rt.isize | undefined; + if (_182 !== undefined) { + _68(out, _182); + } + } else if (_70 === 28) { + const _188 = undefined as boolean | undefined; + if (_188 !== undefined) { + rt.byteVecPush(out, _188 ? 1 : 0); + } } else { let x2: rt.isize = a; x2 = rt.isizeAdd(x2, b); @@ -1270,7 +1546,7 @@ export function isizeOp(op: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { x2 = x2 & ~(1 << 2); x2 = rt.isizeRem(x2, 7); x2 = rt.isizeDiv(x2, 3); - _50(out, x2); + _68(out, x2); } } diff --git a/ts/fixtures/lang/src/ints.rs b/ts/fixtures/lang/src/ints.rs index 3bd5d32ee..14606db57 100644 --- a/ts/fixtures/lang/src/ints.rs +++ b/ts/fixtures/lang/src/ints.rs @@ -11,12 +11,34 @@ macro_rules! take { }}; } +/// `a.div_ceil(b)` of an unsigned type, which a signed one lacks. +macro_rules! div_ceil { + (unsigned, $t:ty, $a:expr, $b:expr) => { + Some($a.div_ceil($b)) + }; + (signed, $t:ty, $a:expr, $b:expr) => { + None::<$t> + }; +} + +/// `a.is_multiple_of(b)` of an unsigned type, which a signed one lacks. +macro_rules! is_multiple_of { + (unsigned, $a:expr, $b:expr) => { + Some($a.is_multiple_of($b)) + }; + (signed, $a:expr, $b:expr) => { + None:: + }; +} + macro_rules! ops { - ($name:ident, $t:ty, $wide:ty) => { + ($name:ident, $t:ty, $wide:ty, $sign:ident) => { /// Apply operation `op` to operands taken from `data`. pub fn $name(op: u8, data: &[u8], out: &mut Vec) { let (a, data) = take!($t, data); let (b, data) = take!($t, data); + // A third operand, from the bytes the shift is read from. + let (c, _) = take!($t, data); let shift = data.first().copied().unwrap_or(0) as u32 % (2 * <$t>::BITS); let put = |out: &mut Vec, v: $t| { out.extend_from_slice(&(v as $wide).to_be_bytes()); @@ -30,7 +52,7 @@ macro_rules! ops { } None => out.push(0), }; - match op % 25 { + match op % 30 { 0 => put(out, a + b), 1 => put(out, a - b), 2 => put(out, a * b), @@ -67,6 +89,20 @@ macro_rules! ops { let _ = (x - b) * a; out.push(1); } + 24 => put(out, a.saturating_mul(b)), + 25 => put(out, a.wrapping_mul(b)), + // Panics unless `b <= c`. + 26 => put(out, a.clamp(b, c)), + 27 => { + if let Some(v) = div_ceil!($sign, $t, a, b) { + put(out, v); + } + } + 28 => { + if let Some(m) = is_multiple_of!($sign, a, b) { + out.push(m as u8); + } + } _ => { // Compound assignment, with constants folded beside variables. let mut x = a; @@ -88,18 +124,18 @@ macro_rules! ops { }; } -ops!(u8_op, u8, u128); -ops!(u16_op, u16, u128); -ops!(u32_op, u32, u128); -ops!(u64_op, u64, u128); -ops!(u128_op, u128, u128); -ops!(usize_op, usize, u128); -ops!(i8_op, i8, i128); -ops!(i16_op, i16, i128); -ops!(i32_op, i32, i128); -ops!(i64_op, i64, i128); -ops!(i128_op, i128, i128); -ops!(isize_op, isize, i128); +ops!(u8_op, u8, u128, unsigned); +ops!(u16_op, u16, u128, unsigned); +ops!(u32_op, u32, u128, unsigned); +ops!(u64_op, u64, u128, unsigned); +ops!(u128_op, u128, u128, unsigned); +ops!(usize_op, usize, u128, unsigned); +ops!(i8_op, i8, i128, signed); +ops!(i16_op, i16, i128, signed); +ops!(i32_op, i32, i128, signed); +ops!(i64_op, i64, i128, signed); +ops!(i128_op, i128, i128, signed); +ops!(isize_op, isize, i128, signed); macro_rules! neg { ($name:ident, $t:ty) => { diff --git a/ts/runtime/rt/int.ts b/ts/runtime/rt/int.ts index 31c67ba2d..e8b94c5ed 100644 --- a/ts/runtime/rt/int.ts +++ b/ts/runtime/rt/int.ts @@ -111,6 +111,12 @@ export function min(a: number, b: number): number { return a <= b ? a : b; } +/** `Ord::clamp` of integers in numbers: `a` within `[min, max]`, panicking unless `min <= max`. */ +export function clamp(a: number, min: number, max: number): number { + if (min > max) panic(`min > max. min = ${min}, max = ${max}`); + return a < min ? min : a > max ? max : a; +} + // Integers of 32 bits or less, in numbers. Sums, differences, and quotients are exact; a // product is inexact only past 2^53, far outside every type's range, so its check still // fails. JS's 32-bit operators do the rest. Each type's functions pass its bounds to @@ -125,10 +131,21 @@ function inRange(value: number, min: number, max: number): number | undefined { return value >= min && value <= max ? value : undefined; } -function clamp(value: number, min: number, max: number): number { +function saturate(value: number, min: number, max: number): number { return value < min ? min : value > max ? max : value; } +/** An unsigned `a / b`, rounded up, panicking on a zero divisor. */ +function ceilDivide(a: number, b: number): number { + if (b === 0) panic("attempt to divide by zero"); + return a % b === 0 ? a / b : Math.trunc(a / b) + 1; +} + +/** Whether `a` is a multiple of `b`: of 0, only 0 is. */ +function multipleOf(a: number, b: number): boolean { + return b === 0 ? a === 0 : a % b === 0; +} + function divide(a: number, b: number, min: number, max: number): number { if (b === 0) panic("attempt to divide by zero"); return checked(Math.trunc(a / b), min, max, "divide"); @@ -213,13 +230,21 @@ export const u8CheckedSub = (a: u8, b: u8): u8 | undefined => inRange(a - b, 0, /** `u8`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u8CheckedMul = (a: u8, b: u8): u8 | undefined => inRange(a * b, 0, 0xff); /** `u8`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u8SaturatingAdd = (a: u8, b: u8): u8 => clamp(a + b, 0, 0xff); +export const u8SaturatingAdd = (a: u8, b: u8): u8 => saturate(a + b, 0, 0xff); /** `u8`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u8SaturatingSub = (a: u8, b: u8): u8 => clamp(a - b, 0, 0xff); +export const u8SaturatingSub = (a: u8, b: u8): u8 => saturate(a - b, 0, 0xff); /** `u8`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u8WrappingAdd = (a: u8, b: u8): u8 => (a + b) & 0xff; /** `u8`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u8WrappingSub = (a: u8, b: u8): u8 => (a - b) & 0xff; +/** `u8`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u8SaturatingMul = (a: u8, b: u8): u8 => saturate(a * b, 0, 0xff); +/** `u8`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u8WrappingMul = (a: u8, b: u8): u8 => Math.imul(a, b) & 0xff; +/** `u8`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u8DivCeil = (a: u8, b: u8): u8 => ceilDivide(a, b); +/** `u8`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u8IsMultipleOf = (a: u8, b: u8): boolean => multipleOf(a, b); /** `u8`'s `leading_ones`: the count of leading one bits. */ export const u8LeadingOnes = (a: u8): number => Math.clz32(~(a << 24)); /** `u8`'s `leading_zeros`: the count of leading zero bits. */ @@ -258,13 +283,21 @@ export const u16CheckedSub = (a: u16, b: u16): u16 | undefined => inRange(a - b, /** `u16`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u16CheckedMul = (a: u16, b: u16): u16 | undefined => inRange(a * b, 0, 0xffff); /** `u16`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u16SaturatingAdd = (a: u16, b: u16): u16 => clamp(a + b, 0, 0xffff); +export const u16SaturatingAdd = (a: u16, b: u16): u16 => saturate(a + b, 0, 0xffff); /** `u16`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u16SaturatingSub = (a: u16, b: u16): u16 => clamp(a - b, 0, 0xffff); +export const u16SaturatingSub = (a: u16, b: u16): u16 => saturate(a - b, 0, 0xffff); /** `u16`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u16WrappingAdd = (a: u16, b: u16): u16 => (a + b) & 0xffff; /** `u16`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u16WrappingSub = (a: u16, b: u16): u16 => (a - b) & 0xffff; +/** `u16`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u16SaturatingMul = (a: u16, b: u16): u16 => saturate(a * b, 0, 0xffff); +/** `u16`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u16WrappingMul = (a: u16, b: u16): u16 => Math.imul(a, b) & 0xffff; +/** `u16`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u16DivCeil = (a: u16, b: u16): u16 => ceilDivide(a, b); +/** `u16`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u16IsMultipleOf = (a: u16, b: u16): boolean => multipleOf(a, b); /** `u16`'s `leading_ones`: the count of leading one bits. */ export const u16LeadingOnes = (a: u16): number => Math.clz32(~(a << 16)); /** `u16`'s `leading_zeros`: the count of leading zero bits. */ @@ -303,13 +336,21 @@ export const u32CheckedSub = (a: u32, b: u32): u32 | undefined => inRange(a - b, /** `u32`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const u32CheckedMul = (a: u32, b: u32): u32 | undefined => inRange(a * b, 0, 0xffffffff); /** `u32`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const u32SaturatingAdd = (a: u32, b: u32): u32 => clamp(a + b, 0, 0xffffffff); +export const u32SaturatingAdd = (a: u32, b: u32): u32 => saturate(a + b, 0, 0xffffffff); /** `u32`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const u32SaturatingSub = (a: u32, b: u32): u32 => clamp(a - b, 0, 0xffffffff); +export const u32SaturatingSub = (a: u32, b: u32): u32 => saturate(a - b, 0, 0xffffffff); /** `u32`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const u32WrappingAdd = (a: u32, b: u32): u32 => (a + b) >>> 0; /** `u32`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u32WrappingSub = (a: u32, b: u32): u32 => (a - b) >>> 0; +/** `u32`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u32SaturatingMul = (a: u32, b: u32): u32 => saturate(a * b, 0, 0xffffffff); +/** `u32`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u32WrappingMul = (a: u32, b: u32): u32 => Math.imul(a, b) >>> 0; +/** `u32`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u32DivCeil = (a: u32, b: u32): u32 => ceilDivide(a, b); +/** `u32`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u32IsMultipleOf = (a: u32, b: u32): boolean => multipleOf(a, b); /** `u32`'s `leading_ones`: the count of leading one bits. */ export const u32LeadingOnes = (a: u32): number => Math.clz32(~a); /** `u32`'s `leading_zeros`: the count of leading zero bits. */ @@ -350,13 +391,17 @@ export const i8CheckedSub = (a: i8, b: i8): i8 | undefined => inRange(a - b, -0x /** `i8`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i8CheckedMul = (a: i8, b: i8): i8 | undefined => inRange(a * b, -0x80, 0x7f); /** `i8`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i8SaturatingAdd = (a: i8, b: i8): i8 => clamp(a + b, -0x80, 0x7f); +export const i8SaturatingAdd = (a: i8, b: i8): i8 => saturate(a + b, -0x80, 0x7f); /** `i8`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i8SaturatingSub = (a: i8, b: i8): i8 => clamp(a - b, -0x80, 0x7f); +export const i8SaturatingSub = (a: i8, b: i8): i8 => saturate(a - b, -0x80, 0x7f); /** `i8`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i8WrappingAdd = (a: i8, b: i8): i8 => ((a + b) << 24) >> 24; /** `i8`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i8WrappingSub = (a: i8, b: i8): i8 => ((a - b) << 24) >> 24; +/** `i8`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i8SaturatingMul = (a: i8, b: i8): i8 => saturate(a * b, -0x80, 0x7f); +/** `i8`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i8WrappingMul = (a: i8, b: i8): i8 => (Math.imul(a, b) << 24) >> 24; /** `i8`'s `leading_ones`: the count of leading one bits. */ export const i8LeadingOnes = (a: i8): number => Math.clz32(~(a << 24)); /** `i8`'s `leading_zeros`: the count of leading zero bits. */ @@ -397,13 +442,17 @@ export const i16CheckedSub = (a: i16, b: i16): i16 | undefined => inRange(a - b, /** `i16`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i16CheckedMul = (a: i16, b: i16): i16 | undefined => inRange(a * b, -0x8000, 0x7fff); /** `i16`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i16SaturatingAdd = (a: i16, b: i16): i16 => clamp(a + b, -0x8000, 0x7fff); +export const i16SaturatingAdd = (a: i16, b: i16): i16 => saturate(a + b, -0x8000, 0x7fff); /** `i16`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i16SaturatingSub = (a: i16, b: i16): i16 => clamp(a - b, -0x8000, 0x7fff); +export const i16SaturatingSub = (a: i16, b: i16): i16 => saturate(a - b, -0x8000, 0x7fff); /** `i16`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i16WrappingAdd = (a: i16, b: i16): i16 => ((a + b) << 16) >> 16; /** `i16`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i16WrappingSub = (a: i16, b: i16): i16 => ((a - b) << 16) >> 16; +/** `i16`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i16SaturatingMul = (a: i16, b: i16): i16 => saturate(a * b, -0x8000, 0x7fff); +/** `i16`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i16WrappingMul = (a: i16, b: i16): i16 => (Math.imul(a, b) << 16) >> 16; /** `i16`'s `leading_ones`: the count of leading one bits. */ export const i16LeadingOnes = (a: i16): number => Math.clz32(~(a << 16)); /** `i16`'s `leading_zeros`: the count of leading zero bits. */ @@ -444,13 +493,17 @@ export const i32CheckedSub = (a: i32, b: i32): i32 | undefined => inRange(a - b, /** `i32`'s `checked_mul`: `a * b`, or `undefined` on overflow. */ export const i32CheckedMul = (a: i32, b: i32): i32 | undefined => inRange(a * b, -0x80000000, 0x7fffffff); /** `i32`'s `saturating_add`: `a + b`, clamped to the type's range. */ -export const i32SaturatingAdd = (a: i32, b: i32): i32 => clamp(a + b, -0x80000000, 0x7fffffff); +export const i32SaturatingAdd = (a: i32, b: i32): i32 => saturate(a + b, -0x80000000, 0x7fffffff); /** `i32`'s `saturating_sub`: `a - b`, clamped to the type's range. */ -export const i32SaturatingSub = (a: i32, b: i32): i32 => clamp(a - b, -0x80000000, 0x7fffffff); +export const i32SaturatingSub = (a: i32, b: i32): i32 => saturate(a - b, -0x80000000, 0x7fffffff); /** `i32`'s `wrapping_add`: `a + b`, wrapped into the type's range. */ export const i32WrappingAdd = (a: i32, b: i32): i32 => (a + b) | 0; /** `i32`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i32WrappingSub = (a: i32, b: i32): i32 => (a - b) | 0; +/** `i32`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i32SaturatingMul = (a: i32, b: i32): i32 => saturate(a * b, -0x80000000, 0x7fffffff); +/** `i32`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i32WrappingMul = (a: i32, b: i32): i32 => Math.imul(a, b); /** `i32`'s `leading_ones`: the count of leading one bits. */ export const i32LeadingOnes = (a: i32): number => Math.clz32(~a); /** `i32`'s `leading_zeros`: the count of leading zero bits. */ @@ -507,6 +560,14 @@ export const usizeSaturatingSub: (a: usize, b: usize) => usize = u32SaturatingSu export const usizeWrappingAdd: (a: usize, b: usize) => usize = u32WrappingAdd as never; /** `usize`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const usizeWrappingSub: (a: usize, b: usize) => usize = u32WrappingSub as never; +/** `usize`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const usizeSaturatingMul: (a: usize, b: usize) => usize = u32SaturatingMul as never; +/** `usize`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const usizeWrappingMul: (a: usize, b: usize) => usize = u32WrappingMul as never; +/** `usize`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const usizeDivCeil: (a: usize, b: usize) => usize = u32DivCeil as never; +/** `usize`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const usizeIsMultipleOf: (a: usize, b: usize) => boolean = u32IsMultipleOf as never; /** `usize`'s `leading_ones`: the count of leading one bits. */ export const usizeLeadingOnes: (a: usize) => number = u32LeadingOnes as never; /** `usize`'s `leading_zeros`: the count of leading zero bits. */ @@ -553,6 +614,10 @@ export const isizeSaturatingSub: (a: isize, b: isize) => isize = i32SaturatingSu export const isizeWrappingAdd: (a: isize, b: isize) => isize = i32WrappingAdd as never; /** `isize`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const isizeWrappingSub: (a: isize, b: isize) => isize = i32WrappingSub as never; +/** `isize`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const isizeSaturatingMul: (a: isize, b: isize) => isize = i32SaturatingMul as never; +/** `isize`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const isizeWrappingMul: (a: isize, b: isize) => isize = i32WrappingMul as never; /** `isize`'s `leading_ones`: the count of leading one bits. */ export const isizeLeadingOnes: (a: isize) => number = i32LeadingOnes as never; /** `isize`'s `leading_zeros`: the count of leading zero bits. */ @@ -729,6 +794,37 @@ function saturated(v: Wide, bits: number, signed: boolean): Wide { return overflow === 0 ? v : extreme(overflow > 0, bits, signed); } +/** Whether a wide value is negative: only a signed type's can be. */ +function negative(v: Wide): boolean { + return typeof v === "number" ? v < 0 : v.hi < 0; +} + +/** `a * b`, clamped to the type's range: past it, toward the sign the product has. */ +function saturatingProduct(a: Wide, b: Wide, bits: number, signed: boolean): Wide { + return product(a, b, bits, signed) ?? extreme(negative(a) === negative(b), bits, signed); +} + +/** `a * b`, wrapped into the type's range. */ +function wrappingProduct(a: Wide, b: Wide, bits: number, signed: boolean): Wide { + return product(a, b, bits, signed) ?? one(box(exact(limbs(a, bits, signed)) * exact(limbs(b, bits, signed)), bits, signed)); +} + +/** Whether `a` is a multiple of `b`, unsigned: of 0, only 0 is. */ +function multiple(a: Wide, b: Wide, bits: number): boolean { + return b === 0 ? a === 0 : rem(a, b, bits, false) === 0; +} + +/** A wide value's decimal text, as its `Debug` writes it. */ +function decimal(v: Wide): string { + return typeof v === "number" ? String(v) : String(exact(v)); +} + +/** `Ord::clamp` of wide values: `a` within `[min, max]`, panicking unless `min <= max`. */ +function clampWide(a: Wide, min: Wide, max: Wide): Wide { + if (lt(max, min)) panic(`min > max. min = ${decimal(min)}, max = ${decimal(max)}`); + return lt(a, min) ? min : lt(max, a) ? max : a; +} + function mul(a: Wide, b: Wide, bits: number, signed: boolean): Wide { const v = product(a, b, bits, signed); if (v === undefined) panic("attempt to multiply with overflow"); @@ -804,6 +900,18 @@ function product128(a: number, b: number): Limbs { return { hi: n3 | 0, w2: n2, w1: n1, lo } as Limbs; } +/** An unsigned 64-bit `a / b`, rounded up, panicking on a zero divisor. */ +function ceil64(a: Wide, b: Wide): Wide { + const q = div(a, b, 64, false); + return rem(a, b, 64, false) === 0 ? q : sum64(q, 1, 1, false); +} + +/** An unsigned 128-bit `a / b`, rounded up, panicking on a zero divisor. */ +function ceil128(a: Wide, b: Wide): Wide { + const q = div(a, b, 128, false); + return rem(a, b, 128, false) === 0 ? q : sum128(q, 1, 1, false); +} + function div(a: Wide, b: Wide, bits: number, signed: boolean): Wide { if (b === 0) panic("attempt to divide by zero"); return quotient(a, b, bits, signed, false); @@ -1126,6 +1234,14 @@ export const u64SaturatingSub = (a: u64, b: u64): u64 => (typeof a === "number" export const u64WrappingAdd = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && fits(a + b, false) ? a + b : sum64(a, b, 1, false)) as u64; /** `u64`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u64WrappingSub = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && fits(a - b, false) ? a - b : sum64(a, b, -1, false)) as u64; +/** `u64`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u64SaturatingMul = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 64, false)) as u64; +/** `u64`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u64WrappingMul = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 64, false)) as u64; +/** `u64`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u64DivCeil = (a: u64, b: u64): u64 => (typeof a === "number" && typeof b === "number" ? ceilDivide(a, b) : ceil64(a, b)) as u64; +/** `u64`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u64IsMultipleOf = (a: u64, b: u64): boolean => (typeof a === "number" && typeof b === "number" ? multipleOf(a, b) : multiple(a, b, 64)); /** `u64`'s `leading_ones`: the count of leading one bits. */ export const u64LeadingOnes = (a: u64): number => leadingOnes64(a, false); /** `u64`'s `leading_zeros`: the count of leading zero bits. */ @@ -1166,6 +1282,8 @@ export const u64Ge = (a: u64, b: u64): boolean => typeof a === "number" && typeo export const u64Max = (a: u64, b: u64): u64 => (lt(b, a) ? a : b); /** `u64`'s `Ord::min`: the lesser, `a` if they are equal. */ export const u64Min = (a: u64, b: u64): u64 => (lt(b, a) ? b : a); +/** `u64`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const u64Clamp = (a: u64, min: u64, max: u64): u64 => clampWide(a, min, max) as u64; /** `u64`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const u64Step: Step = (n, by) => stepped(sum64(n, Math.abs(by), by < 0 ? -1 : 1, false)) as [u64, boolean]; @@ -1216,6 +1334,10 @@ export const i64SaturatingSub = (a: i64, b: i64): i64 => (typeof a === "number" export const i64WrappingAdd = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && fits(a + b, true) ? a + b : sum64(a, b, 1, true)) as i64; /** `i64`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i64WrappingSub = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && fits(a - b, true) ? a - b : sum64(a, b, -1, true)) as i64; +/** `i64`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i64SaturatingMul = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 64, true)) as i64; +/** `i64`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i64WrappingMul = (a: i64, b: i64): i64 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 64, true)) as i64; /** `i64`'s `leading_ones`: the count of leading one bits. */ export const i64LeadingOnes = (a: i64): number => leadingOnes64(a, true); /** `i64`'s `leading_zeros`: the count of leading zero bits. */ @@ -1254,6 +1376,8 @@ export const i64Ge = (a: i64, b: i64): boolean => typeof a === "number" && typeo export const i64Max = (a: i64, b: i64): i64 => (lt(b, a) ? a : b); /** `i64`'s `Ord::min`: the lesser, `a` if they are equal. */ export const i64Min = (a: i64, b: i64): i64 => (lt(b, a) ? b : a); +/** `i64`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const i64Clamp = (a: i64, min: i64, max: i64): i64 => clampWide(a, min, max) as i64; /** `i64`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const i64Step: Step = (n, by) => stepped(sum64(n, Math.abs(by), by < 0 ? -1 : 1, true)) as [i64, boolean]; @@ -1302,6 +1426,14 @@ export const u128SaturatingSub = (a: u128, b: u128): u128 => (typeof a === "numb export const u128WrappingAdd = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && fits(a + b, false) ? a + b : sum128(a, b, 1, false)) as u128; /** `u128`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const u128WrappingSub = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && fits(a - b, false) ? a - b : sum128(a, b, -1, false)) as u128; +/** `u128`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const u128SaturatingMul = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 128, false)) as u128; +/** `u128`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const u128WrappingMul = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 128, false)) as u128; +/** `u128`'s `div_ceil`: `a / b`, rounded up, panicking on a zero divisor. */ +export const u128DivCeil = (a: u128, b: u128): u128 => (typeof a === "number" && typeof b === "number" ? ceilDivide(a, b) : ceil128(a, b)) as u128; +/** `u128`'s `is_multiple_of`: whether `b` divides `a`; of 0, only 0 is a multiple. */ +export const u128IsMultipleOf = (a: u128, b: u128): boolean => (typeof a === "number" && typeof b === "number" ? multipleOf(a, b) : multiple(a, b, 128)); /** `u128`'s `leading_ones`: the count of leading one bits. */ export const u128LeadingOnes = (a: u128): number => leadingOnes128(a, false); /** `u128`'s `leading_zeros`: the count of leading zero bits. */ @@ -1340,6 +1472,8 @@ export const u128Ge = (a: u128, b: u128): boolean => typeof a === "number" && ty export const u128Max = (a: u128, b: u128): u128 => (lt(b, a) ? a : b); /** `u128`'s `Ord::min`: the lesser, `a` if they are equal. */ export const u128Min = (a: u128, b: u128): u128 => (lt(b, a) ? b : a); +/** `u128`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const u128Clamp = (a: u128, min: u128, max: u128): u128 => clampWide(a, min, max) as u128; /** `u128`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const u128Step: Step = (n, by) => stepped(sum128(n, Math.abs(by), by < 0 ? -1 : 1, false)) as [u128, boolean]; @@ -1390,6 +1524,10 @@ export const i128SaturatingSub = (a: i128, b: i128): i128 => (typeof a === "numb export const i128WrappingAdd = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && fits(a + b, true) ? a + b : sum128(a, b, 1, true)) as i128; /** `i128`'s `wrapping_sub`: `a - b`, wrapped into the type's range. */ export const i128WrappingSub = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && fits(a - b, true) ? a - b : sum128(a, b, -1, true)) as i128; +/** `i128`'s `saturating_mul`: `a * b`, clamped to the type's range. */ +export const i128SaturatingMul = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : saturatingProduct(a, b, 128, true)) as i128; +/** `i128`'s `wrapping_mul`: `a * b`, wrapped into the type's range. */ +export const i128WrappingMul = (a: i128, b: i128): i128 => (typeof a === "number" && typeof b === "number" && safe(a * b) ? a * b + 0 : wrappingProduct(a, b, 128, true)) as i128; /** `i128`'s `leading_ones`: the count of leading one bits. */ export const i128LeadingOnes = (a: i128): number => leadingOnes128(a, true); /** `i128`'s `leading_zeros`: the count of leading zero bits. */ @@ -1428,5 +1566,7 @@ export const i128Ge = (a: i128, b: i128): boolean => typeof a === "number" && ty export const i128Max = (a: i128, b: i128): i128 => (lt(b, a) ? a : b); /** `i128`'s `Ord::min`: the lesser, `a` if they are equal. */ export const i128Min = (a: i128, b: i128): i128 => (lt(b, a) ? b : a); +/** `i128`'s `Ord::clamp`: `a` within `[min, max]`, panicking unless `min <= max`. */ +export const i128Clamp = (a: i128, min: i128, max: i128): i128 => clampWide(a, min, max) as i128; /** `i128`'s `Step`, which ranges step by: `n` moved by `by`, and whether that overflowed. */ export const i128Step: Step = (n, by) => stepped(sum128(n, Math.abs(by), by < 0 ? -1 : 1, true)) as [i128, boolean]; diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 60f263eb1..2b7653a56 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -571,8 +571,12 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec "checked_mul" => "checkedMul", "saturating_add" => "saturatingAdd", "saturating_sub" => "saturatingSub", + "saturating_mul" => "saturatingMul", "wrapping_add" => "wrappingAdd", "wrapping_sub" => "wrappingSub", + "wrapping_mul" => "wrappingMul", + "div_ceil" => "divCeil", + "is_multiple_of" => "isMultipleOf", _ => return None, }; return Some(int.method(method, args)); @@ -683,6 +687,10 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec false => Expr::rt(if name == "max" { "max" } else { "min" }, values), } } + ("Ord", "clamp") if let Some(int) = Int::of(targ(gargs, 0)) => match int.big() { + true => int.method("clamp", args), + false => Expr::rt("clamp", args), + }, ("Clone", "clone") => { let ty = targ(gargs, 0); let values = args; diff --git a/ts/tests/differential.ts b/ts/tests/differential.ts index b7c12d6ab..00631a4d6 100644 --- a/ts/tests/differential.ts +++ b/ts/tests/differential.ts @@ -132,23 +132,27 @@ if (wideArg === "wide") { const u = i % 3 === 0 ? x : values[(i * 7) % values.length]; const v = values[(i * 13 + 5) % values.length]; const shift = shifts[i++ % shifts.length]; - for (let kind = 0; kind < 25; kind++) { + for (let kind = 0; kind < 30; kind++) { for (const op of [3, 9]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), shift)); for (const op of [4, 10]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), ...be(u), ...be(v), shift)); } + // `clamp` between two values of the sweep, whose third operand follows the shift's place. + for (const op of [3, 9]) cases.push(Uint8Array.of(op, 26, ...be(x), ...be(y), ...be(u))); + for (const op of [4, 10]) cases.push(Uint8Array.of(op, 26, ...be(x), ...be(y), ...be(u), ...be(v), ...be(y), ...be(x))); // Negating an `i64` and an `i128`. cases.push(Uint8Array.of(12, 3, ...be(x)), Uint8Array.of(12, 4, ...be(x), ...be(y))); - // `x * y` and `x.checked_mul(y)` at 128 bits, extended in each type's sign: a product - // of two numbers, past 2^53, multiplies their halves. + // `x * y`, `checked_mul`, `saturating_mul`, and `wrapping_mul` at 128 bits, extended in + // each type's sign: a product of two numbers, past 2^53, multiplies their halves. const signs = (v: bigint) => (v >> 63n === 1n ? 0xffffffffffffffffn : 0n); - for (const kind of [2, 13]) { + for (const kind of [2, 13, 24, 25]) { cases.push(Uint8Array.of(4, kind, ...be(0n), ...be(x), ...be(0n), ...be(y))); cases.push(Uint8Array.of(10, kind, ...be(signs(x)), ...be(x), ...be(signs(y)), ...be(y))); } - // `x:y / d` and `x:y % d` at 128 bits by a divisor below 2^32 in magnitude, which - // divides limbs by a number, extended in each type's sign: -1 overflows `i128::MIN`. + // `x:y / d`, `x:y % d`, `div_ceil`, and `is_multiple_of` at 128 bits by a divisor + // below 2^32 in magnitude, which divides limbs by a number, extended in each type's + // sign: -1 overflows `i128::MIN`. for (const d of [3n, 1_000_000n, 0xffffffffn, -1n, -0xffffffffn]) { - for (const kind of [3, 4]) { + for (const kind of [3, 4, 27, 28]) { for (const op of [4, 10]) cases.push(Uint8Array.of(op, kind, ...be(x), ...be(y), ...be(signs(d & 0xffffffffffffffffn)), ...be(d & 0xffffffffffffffffn))); } } diff --git a/ts/tests/fixtures.rs b/ts/tests/fixtures.rs index d30e57711..b018d1f4f 100644 --- a/ts/tests/fixtures.rs +++ b/ts/tests/fixtures.rs @@ -258,10 +258,10 @@ fn shake(out: &Path) { "byteSliceFrom", "byteSliceSplitAtChecked", "checked", - "clamp", "idx", "max", "panic", + "saturate", "u32SaturatingAdd", "u32Sub", "usizeSaturatingAdd", From af05f2c35cd12f375d9e3d60563274aa5526ab0d Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:06:23 -0700 Subject: [PATCH 04/11] wip(ts): std-more fixtures, unwind tests, RangeInclusive stepping, and docs Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/README.md | 19 +- ts/fixtures/lang/expected/collections.ts | 12 +- ts/fixtures/lang/expected/edits.Named.ts | 32 + ts/fixtures/lang/expected/edits.Stamp.ts | 18 + ts/fixtures/lang/expected/edits.Tally.ts | 15 + ts/fixtures/lang/expected/edits.ts | 299 ++++++++ ts/fixtures/lang/expected/harness.ts | 8 +- ts/fixtures/lang/expected/keys.ts | 33 +- ts/fixtures/lang/expected/wrappers.Scale.ts | 22 + ts/fixtures/lang/expected/wrappers.ts | 426 ++++++++++++ ts/fixtures/lang/src/edits.rs | 266 +++++++ ts/fixtures/lang/src/harness.rs | 6 +- ts/fixtures/lang/src/lib.rs | 2 + ts/fixtures/lang/src/wrappers.rs | 185 +++++ ts/fixtures/task/expected/drops.Key.ts | 13 + ts/fixtures/task/expected/drops.ts | 729 +++++++++++++++++--- ts/fixtures/task/expected/lib.ts | 16 + ts/fixtures/task/src/drops.rs | 84 ++- ts/runtime/rt.ts | 14 +- ts/runtime/rt/iter.ts | 25 +- ts/src/lower/collections.rs | 7 +- ts/src/lower/library.rs | 174 ++++- ts/src/lower/mir/call.rs | 11 +- ts/src/lower/mod.rs | 2 + ts/src/ts.rs | 10 +- ts/tests/retain.ts | 38 +- ts/tests/runtime.rs | 49 +- ts/tests/task.ts | 2 +- 28 files changed, 2355 insertions(+), 162 deletions(-) create mode 100644 ts/fixtures/lang/expected/edits.Named.ts create mode 100644 ts/fixtures/lang/expected/edits.Stamp.ts create mode 100644 ts/fixtures/lang/expected/edits.Tally.ts create mode 100644 ts/fixtures/lang/expected/edits.ts create mode 100644 ts/fixtures/lang/expected/wrappers.Scale.ts create mode 100644 ts/fixtures/lang/expected/wrappers.ts create mode 100644 ts/fixtures/lang/src/edits.rs create mode 100644 ts/fixtures/lang/src/wrappers.rs diff --git a/ts/README.md b/ts/README.md index df72cc199..7222f60b9 100644 --- a/ts/README.md +++ b/ts/README.md @@ -67,9 +67,10 @@ in `rt/str.ts`, collections in `rt/collections.ts`, and ownership and async in | `Result` | `rt.Result`: `{ ok: true, value }` or `{ ok: false, error }` | | `ControlFlow` | `rt.Result`, `Ok` to continue; what `?` branches on is the value it was applied to | | tuple, `[T; N]`, `&[T]`, `Vec` | an array; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec` | -| `&T`, `&mut T`, `Box` | the value: a `&mut` must point at an object JS can change in place, or at a map's value through an `rt.Place` | +| `&T`, `&mut T`, `Box`, `Reverse`, `NonZero` | the value: a `&mut` must point at an object JS can change in place, or at a map's value through an `rt.Place` | | an iterator | `rt.Iter`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` | | `a..b`, `a..=b` | `rt.Range`, `rt.RangeInclusive`, which are iterators too | +| `a..`, `..b`, `..=b`, `Bound` | `{ start }`, `{ end }`, `{ end, inclusive: true }`; `rt.Bound`, a union tagged by variant | | `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque` | `rt.HashMap` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` | | `Ordering`, `DefaultHasher` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher` | | closure | an arrow function | @@ -129,7 +130,7 @@ std's adaptors through `rt.iterFrom`. A caller calls `next()` for one item, or i an `rt.Iter` with `for ... of`. A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a search by a -`char`, a `&str`, or a predicate, as in `rt.strSplit(s, "/")`, takes the text or the +`char`, a `&str`, a predicate, or an array or slice of chars, as in `rt.strSplit(s, "/")`, takes the text or the closure, which it calls on each char it reads, in the order std reads them. An offset it returns, from `rfind` or `match_indices`, counts UTF-8 bytes, as Rust's does, and so does one `&s[a..b]` takes, which reads the string up to it and panics as std does inside a @@ -299,6 +300,11 @@ they need. are a JS `Map`'s, the engine's own hash table; its other keys go into a second `Map` by their translated hash, chained by `Eq`. `VecDeque` is a ring buffer over an array whose length is a power of two. +- A slice's `sort` and `sort_unstable` are one stable merge sort of the runtime's own, + calling only the comparator, as std permits of an unstable sort: JS's `sort` moves + `undefined`, a `None`, to the end without comparing it, and each engine orders its + comparisons differently. A comparator that panics leaves each element once, in an + order std's sort would not match. - Iterators are the runtime's lazy classes rather than generators or ES iterator helpers: std's adaptors would lower from std's own bodies, whose slice iterators are raw pointers, ES helpers lack most of them @@ -336,7 +342,7 @@ without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partiti own `impl Iterator` with `next_back`, `len`, or another provided method of its own, other format specs (a precision, `+`, `{:b}`, `{:x?}`, and widths from arguments), writing to a `String` with `write!` or pushing to one through a parameter, a `str` pattern other than a -`char`, a `&str`, or a predicate, a mutable `str` slice, a copy of a closure that changes +`char`, a `&str`, a predicate, or chars, a mutable `str` slice, a copy of a closure that changes what it captured, `mem::swap`, `replace`, or `take` of a reference's whole pointee, assigning an `Arc`, a waker, a `MutexGuard`, a pinned reference, or a future through a reference, a switch on or a field of another crate's type without a mapping, and std @@ -368,7 +374,9 @@ built natively for wasm32 and run beside its translation on the same inputs by on generic types, iterators, with closures that log what each adaptor reads, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` - disagree with JS's, and `vec![x; n]` of types whose `Clone` counts its clones. Its differential test runs through `caller.ts`, a + disagree with JS's, and `vec![x; n]` of types whose `Clone` counts its clones, a `Vec`'s + edits and sorts, with closures that log what each is called with, and std's `Bound`, + `Reverse`, and `NonZero`. Its differential test runs through `caller.ts`, a hand-written caller that also prints a `printable` error nothing translated prints, and adds every 64- and 128-bit case over each pair of values next to a power of two, where the runtime switches between numbers and limbs, and its limbs carry and borrow, @@ -391,7 +399,8 @@ built natively for wasm32 and run beside its translation on the same inputs by `tests/spawn.ts` checks that `rt.spawn` yields to a timer after its 128-poll budget, and rejects when a future panics as it drops. `tests/retain.ts` panics in a collection's -`retain` at each item, and `retain_unwinds` checks that it leaves what std's leaves. +`retain` and `Vec::dedup_by` at each item, and `retain_unwinds` checks that each leaves and +drops what std's does; a sort whose comparator panics must leave each item once. ## Bench diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 0ab82426d..df9f116c2 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -1094,12 +1094,12 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void { const hash: rt.HashMap = rt.hashNew() as rt.HashMap; rt.hashInsert(hash, 0, copy$u8_u8(pair)); rt.hashInsert(hash, 1, copy$u8_u8(pair)); - const _88: rt.Place<[rt.u8, rt.u8]> | undefined = rt.hashGetMut(hash, 0); + const _88: [rt.u8, rt.u8] | undefined = rt.hashGet(hash, 0); if (_88 !== undefined) { - _88.v[0] = _88.v[0] ^ 1; + _88[0] = _88[0] ^ 1; } - const place = rt.entryOrInsertMut(rt.entry(hash, 2), copy$u8_u8(pair)); - place.v[1] = place.v[1] ^ 2; + const _93: [rt.u8, rt.u8] = rt.entryOrInsert(rt.entry(hash, 2), copy$u8_u8(pair)); + _93[1] = _93[1] ^ 2; rt.iterExtendBytes(out, rt.iterFlatMap(new rt.Range(0, 3), (k: rt.u8): Uint8Array => { return rt.optionMapOr(rt.hashGet(hash, k), rt.bytes(2).fill(255), (p2: [rt.u8, rt.u8]): Uint8Array => { return Uint8Array.of(p2[0], p2[1]); @@ -1108,9 +1108,9 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void { const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; rt.btreeInsert(tree, 0, copy$u8_u8(pair)); rt.btreeInsert(tree, 1, copy$u8_u8(pair)); - const _106: rt.Place<[rt.u8, rt.u8]> | undefined = rt.btreeGetMut(tree, 1); + const _106: [rt.u8, rt.u8] | undefined = rt.btreeGet(tree, 1); if (_106 !== undefined) { - _106.v[1] = _106.v[1] ^ 1; + _106[1] = _106[1] ^ 1; } rt.iterExtendBytes(out, rt.iterFlatMap(rt.btreeValues(tree), (p3: [rt.u8, rt.u8]): Uint8Array => { return Uint8Array.of(p3[0], p3[1]); diff --git a/ts/fixtures/lang/expected/edits.Named.ts b/ts/fixtures/lang/expected/edits.Named.ts new file mode 100644 index 000000000..4b9e5c9fa --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Named.ts @@ -0,0 +1,32 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function clone$Clone(self: Named): Named { + return { id: self.id, name: self.name }; +} + +export function eq$PartialEq(self: Named, other: Named): boolean { + if (!(self.id === other.id)) { + return false; + } + return self.name === other.name; +} + +export function partialCmp$PartialOrd(self: Named, other: Named): rt.Ordering | undefined { + const cmp: rt.Ordering | undefined = rt.cmp(self.id, other.id); + if (cmp !== undefined) { + if (cmp === 0) { + return rt.cmpStr(self.name, other.name); + } + } + return cmp; +} + +/** An element that is not `Copy`, cloned and compared field by field. */ +export interface Named { + id: rt.u16; + name: string; +} + +//# sourceMappingURL=edits.Named.ts.map diff --git a/ts/fixtures/lang/expected/edits.Stamp.ts b/ts/fixtures/lang/expected/edits.Stamp.ts new file mode 100644 index 000000000..9c2dee638 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Stamp.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function partialCmp$PartialOrd(self: Stamp, other: Stamp): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + +export function cmp$Ord(self: Stamp, other: Stamp): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** The crate's own order, whose `min`, `max`, and `clamp` are `Ord`'s defaults. */ +export interface Stamp { + _0: rt.u8; +} + +//# sourceMappingURL=edits.Stamp.ts.map diff --git a/ts/fixtures/lang/expected/edits.Tally.ts b/ts/fixtures/lang/expected/edits.Tally.ts new file mode 100644 index 000000000..9a1bcb6cc --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Tally.ts @@ -0,0 +1,15 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** What `mem::take` leaves its own `Default` in place of. */ +export interface Tally { + n: rt.u8; + names: string[]; +} + +export function default$Default(): Tally { + return { n: 7, names: ["fresh"] }; +} + +//# sourceMappingURL=edits.Tally.ts.map diff --git a/ts/fixtures/lang/expected/edits.ts b/ts/fixtures/lang/expected/edits.ts new file mode 100644 index 000000000..60911c7e5 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.ts @@ -0,0 +1,299 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import * as Named from "./edits.Named.ts"; +import * as Stamp from "./edits.Stamp.ts"; +import * as Tally from "./edits.Tally.ts"; +import { put } from "./fmt.ts"; +import { text } from "./strs.ts"; + +export function putU16s(out: rt.ByteVec, v: rt.u16[]): void { + for (const _5 of v) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(_5))); + } + rt.byteVecPush(out, 254); +} + +export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _75: (a0: rt.u16) => Named.Named = (w: rt.u16): Named.Named => { + return { id: w, name: text(rt.byteSliceFrom(Uint8Array.of(rt.u8Div(w & 0xff, 16)))) }; + }; + const words: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_2: rt.u8): rt.u16 => { + return rt.u16Mul(_2 as rt.u16, 3); + })); + const at: (a0: rt.usize) => rt.u8 = (i3: rt.usize): rt.u8 => { + return rt.optionUnwrapOr(rt.byteSliceGet(data, i3), 0); + }; + const _8: rt.u8 = rt.u8Rem(kind, 7); + if (_8 === 0) { + const v: rt.u16[] = words.slice(); + const seen: rt.u16[] = []; + rt.vecRetain(v, (_225: rt.u16): boolean => { + const x3: rt.u16 = _225; + seen.push(x3); + return rt.u16Rem(x3, 4) !== 0; + }); + putU16s(out, seen); + putU16s(out, v); + const pairs: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_228: rt.u16): [rt.u16, rt.u16] => { + return [_228, 0] as [rt.u16, rt.u16]; + })); + rt.vecRetain(pairs, (p2: [rt.u16, rt.u16]): boolean => { + p2[1] = rt.u16Div(p2[0], 2); + return rt.u16Rem(p2[0], 3) === 0; + }); + for (const _33 of pairs) { + putU16s(out, [_33[0], _33[1]]); + } + const names: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_230: rt.u8): string => { + return text(rt.byteSliceFrom(Uint8Array.of(_230))); + })); + rt.vecRetain(names, (s2: string): boolean => { + return rt.stringLen(s2) > 1; + }); + rt.byteVecPush(out, names.length & 0xff); + const part2 = rt.usizeSaturatingSub(data.length, 1); + const stop: rt.u16 = rt.u16Mul(at(part2) as rt.u16, 3); + if ((kind & 128) !== 0) { + rt.vecRetain(v, (_232: rt.u16): boolean => { + const x4: rt.u16 = _232; + if (!(x4 === stop)) { + return true; + } + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u16Display(x4, f)]; + rt.panicFmt(["retain stopped at ", args2[0]]); + }); + } + } else if (_8 === 1) { + const v2: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_217: rt.u8): rt.u16 => { + return rt.u8Rem(_217, 4) as rt.u16; + })); + rt.vecDedupBy(v2, rt.same); + putU16s(out, v2); + const keyed: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_218: rt.u16): Named.Named => { + return _75(_218); + })); + rt.vecDedupByKey(keyed, (n: Named.Named): rt.u16 => { + return rt.u16Div(n.id, 24); + }, rt.same); + for (const _88 of keyed) { + putU16s(out, [_88.id]); + } + const tested: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_219: rt.u16): Named.Named => { + return _75(_219); + })); + const seen2: rt.u16[] = []; + rt.vecDedupBy(tested, (a3: Named.Named, b8: Named.Named): boolean => { + seen2.push(a3.id); + seen2.push(b8.id); + return a3.name === b8.name; + }); + putU16s(out, seen2); + for (const _115 of tested) { + put(out, _115.name); + } + const names2: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_221: rt.u8): string => { + return text(rt.byteSliceFrom(Uint8Array.of(rt.u8Rem(_221, 3)))); + })); + rt.vecDedupBy(names2, rt.same); + rt.byteVecPush(out, names2.length & 0xff); + } else if (_8 === 2) { + const v3: rt.u16[] = words.slice(); + rt.sliceSortBy(v3, rt.cmp); + putU16s(out, v3); + const v4: rt.u16[] = words.slice(); + rt.sliceSortBy(v4, (a: rt.u16, b4: rt.u16): rt.Ordering => { + return rt.cmp(b4, a); + }); + putU16s(out, v4); + const pairs2: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(words)), (_211: [rt.usize, rt.u16]): [rt.u16, rt.u16] => { + return [rt.u16Rem(_211[1], 5), _211[0] & 0xffff] as [rt.u16, rt.u16]; + })); + rt.sliceSortByKey(pairs2, (p: [rt.u16, rt.u16]): rt.u16 => { + return p[0]; + }, rt.cmp); + for (const _159 of pairs2) { + putU16s(out, [_159[0], _159[1]]); + } + rt.sliceSortByKey(pairs2, (_213: [rt.u16, rt.u16]): [rt.u16, rt.u16, rt.u16] => { + const a2: rt.u16 = _213[0]; + const b5: rt.u16 = _213[1]; + return [rt.u16Rem(b5, 3), a2, b5] as [rt.u16, rt.u16, rt.u16]; + }, rt.cmpTuple([rt.cmp, rt.cmp, rt.cmp])); + for (const _176 of pairs2) { + putU16s(out, [_176[0], _176[1]]); + } + rt.sliceSortBy(pairs2, (x2: [rt.u16, rt.u16], y: [rt.u16, rt.u16]): rt.Ordering => { + return rt.cmp(y[1], x2[1]); + }); + for (const _193 of pairs2) { + putU16s(out, [_193[0], _193[1]]); + } + const options: Array = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_214: rt.u16): rt.u16 | undefined => { + const w6: rt.u16 = _214; + if (!(rt.u16Rem(w6, 2) === 0)) { + return w6; + } + return undefined; + })); + rt.sliceSortBy(options, rt.cmpOption(rt.cmp)); + for (const _215 of options) { + putU16s(out, [rt.optionMapOr(_215, 65535, (o: rt.u16): rt.u16 => { + return o; + })]); + } + const names3: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_216: rt.u8): string => { + const b6: rt.u8 = _216; + return text(rt.byteSliceFrom(Uint8Array.of(b6, rt.u8Div(b6, 16)))); + })); + rt.sliceSortBy(names3, rt.cmpStr); + for (const _234 of names3) { + put(out, _234); + } + } else if (_8 === 3) { + const v5: rt.u16[] = words.slice(); + putU16s(out, [rt.optionUnwrapOr(rt.sliceLast(v5), 65535)]); + const runs: [rt.u16, rt.u16 | undefined][] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_28: rt.u16): [rt.u16, rt.u16 | undefined] => { + return [_28, undefined] as [rt.u16, rt.u16 | undefined]; + })); + const _256: [rt.u16, rt.u16 | undefined] | undefined = rt.sliceLast(runs); + if (_256 !== undefined) { + _256[1] = _256[0]; + } + const _263: [rt.u16, rt.u16 | undefined] | undefined = rt.sliceFirst(runs); + if (_263 !== undefined) { + _263[0] = rt.u16Add(_263[0], 1); + } + for (const _272 of runs) { + putU16s(out, [_272[0], rt.optionUnwrapOr(_272[1], 65535)]); + } + rt.sliceReverse(v5); + putU16s(out, v5); + const named: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_29: rt.u16): Named.Named => { + const w4: rt.u16 = _29; + return { id: w4, name: text(rt.byteSliceFrom(Uint8Array.of(w4 & 0xff))) }; + })); + const probe: Named.Named = { id: rt.u16Mul(at(1) as rt.u16, 3), name: text(rt.byteSliceFrom(Uint8Array.of(rt.u8WrappingMul(at(1), 3)))) }; + rt.byteVecPush(out, rt.sliceContains(named, probe, Named.eq$PartialEq) ? 1 : 0); + rt.byteVecPush(out, rt.sliceContains(words, rt.u16Mul(at(2) as rt.u16, 3), rt.same) ? 1 : 0); + const _332: rt.u8 = at(3); + rt.byteVecPush(out, rt.byteSliceView(data).includes(_332) ? 1 : 0); + const _337: [rt.usize, rt.usize] = [rt.usizeRem(at(0) as rt.usize, 8), rt.usizeRem(at(1) as rt.usize, 8)]; + const i: rt.usize = _337[0]; + const j: rt.usize = _337[1]; + const moved: rt.u16[] = words.slice(); + putU16s(out, [rt.vecSwapRemove(moved, i)]); + putU16s(out, moved); + rt.sliceSwap(moved, i, j); + putU16s(out, moved); + } else if (_8 === 4) { + const named2: Named.Named[] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_23: rt.u16): Named.Named => { + const w2: rt.u16 = _23; + return { id: w2, name: text(rt.byteSliceFrom(Uint8Array.of(w2 & 0xff))) }; + })); + const cloned: Named.Named[] = rt.vecClone(named2, Named.clone$Clone); + rt.byteVecPush(out, rt.eqSlice(Named.eq$PartialEq)(cloned, named2) ? 1 : 0); + const changed: Named.Named[] = rt.vecClone(named2, Named.clone$Clone); + const _382: Named.Named | undefined = rt.sliceFirst(changed); + if (_382 !== undefined) { + _382.name = _382.name + "!"; + } + rt.byteVecPush(out, rt.eqSlice(Named.eq$PartialEq)(changed, named2) ? 1 : 0); + rt.byteVecPush(out, !rt.eqSlice(Named.eq$PartialEq)(changed, named2) ? 1 : 0); + rt.byteVecPush(out, rt.cmpSlice(Named.partialCmp$PartialOrd)(changed, named2) === -1 ? 1 : 0); + const _406: Named.Named[] = rt.sliceRange(named2, 0, rt.usizeDiv(named2.length, 2)); + rt.vecExtendFromSlice(changed, _406, Named.clone$Clone); + rt.byteVecPush(out, changed.length & 0xff); + const nested: rt.u16[][] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_27: rt.u8): rt.u16[] => { + const b3: rt.u8 = _27; + return rt.iterToArray(rt.iterMap(new rt.Range(0, rt.u8Rem(b3, 3)), (i4: rt.u8): rt.u16 => { + return rt.u16Add(i4 as rt.u16, b3 as rt.u16); + })); + })); + const _424: rt.u16[][] = rt.vecClone(nested, (a011: rt.u16[]): rt.u16[] => { + return a011.slice(); + }); + rt.byteVecPush(out, rt.eqSlice(rt.eqSlice(rt.same))(_424, nested) ? 1 : 0); + const pair: [string, rt.u8] = [text(data), at(0)]; + const copy: [string, rt.u8] = rt.tupleClone(pair, [undefined, undefined], [undefined, undefined]); + put(out, copy[0]); + const _441: [rt.u8, string] = [copy[1], copy[0]]; + const _445: [rt.u8, string] = [at(1), pair[0]]; + rt.byteVecPush(out, rt.cmpTuple([rt.cmp, rt.cmpStr])(_441, _445) === 1 ? 1 : 0); + const _454: [rt.u8, rt.u8] = [at(0), at(1)]; + const _462: [rt.u8, rt.u8] = [at(1), at(0)]; + rt.byteVecPush(out, rt.cmpTuple([rt.cmp, rt.cmp])(_454, _462) === -1 ? 1 : 0); + const grown: rt.u16[] = words.slice(); + rt.vecExtendFromSlice(grown, words); + putU16s(out, grown); + } else if (_8 === 5) { + let tally: Tally.Tally = { n: at(0), names: [text(data)] }; + const default_ = Tally.default$Default(); + const taken3 = tally; + tally = default_; + rt.byteVecPush(out, taken3.n); + rt.byteVecPush(out, tally.n); + put(out, tally.names[rt.idx(tally.names, 0)]); + const _497: rt.Iter = rt.iterSlice(words); + let queue: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _497); + const default_2 = rt.dequeNew() as rt.VecDeque; + const taken4 = queue; + queue = default_2; + rt.byteVecPush(out, taken4.n & 0xff); + rt.byteVecPush(out, queue.n & 0xff); + const _512: rt.Iter = rt.iterSlice(words); + let set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _512, true); + const default_3 = rt.btreeNew(rt.cmp) as rt.BTreeSet; + const taken5 = set; + set = default_3; + rt.byteVecPush(out, rt.btreeLen(taken5) & 0xff); + rt.byteVecPush(out, rt.btreeLen(set) === 0 ? 1 : 0); + const _529: [Stamp.Stamp, Stamp.Stamp, Stamp.Stamp] = [{ _0: at(0) }, { _0: at(1) }, { _0: at(2) }]; + const x: Stamp.Stamp = _529[0]; + const lo: Stamp.Stamp = _529[1]; + const hi: Stamp.Stamp = _529[2]; + rt.byteVecPush(out, rt.ordMax(x, lo, Stamp.cmp$Ord)._0); + rt.byteVecPush(out, rt.ordMin(x, lo, Stamp.cmp$Ord)._0); + rt.byteVecPush(out, rt.ordClamp(x, lo, hi, Stamp.partialCmp$PartialOrd)._0); + } else { + const s: string = text(data); + const sep: rt.char[] = [47, 97]; + rt.byteVecPush(out, rt.strContains(s, rt.patternChars(sep)) ? 1 : 0); + rt.byteVecPush(out, rt.strContains(s, rt.patternChars(rt.sliceRange(sep, 0))) ? 1 : 0); + rt.byteVecPush(out, rt.strEndsWith(s, "/") ? 1 : 0); + rt.byteVecPush(out, rt.strEndsWith(s, "😀") ? 1 : 0); + rt.byteVecPush(out, rt.strEndsWith(s, (c: rt.char): boolean => { + return rt.charIsAsciiDigit(c); + }) ? 1 : 0); + const _581: [string, string] | undefined = rt.strSplitOnce(s, "/"); + if (_581 === undefined) { + rt.byteVecPush(out, 253); + } else { + put(out, _581[0]); + put(out, _581[1]); + } + const _590: [string, string] | undefined = rt.strSplitOnce(s, "a0"); + if (_590 === undefined) { + rt.byteVecPush(out, 253); + } else { + put(out, _590[0]); + put(out, _590[1]); + } + const iter10: rt.RangeInclusive = new rt.RangeInclusive(0, rt.usizeAdd(rt.stringLen(s), 1), rt.usizeStep); + while (true) { + const _605: rt.usize | rt.Done = iter10.next(); + if (_605 === rt.DONE) { + break; + } + rt.byteVecPush(out, rt.strIsCharBoundary(s, _605) ? 1 : 0); + } + rt.iterExtendBytes(out, rt.strBytes(s)); + rt.iterExtendBytes(out, rt.iterTake(rt.iterRev(rt.strBytes(s)), 3)); + rt.byteVecPush(out, rt.strBytes(s).len() & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterFilter(rt.strBytes(s), (_22: rt.u8): boolean => { + return _22 >= 128; + })) & 0xff); + } +} + +//# sourceMappingURL=edits.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 20cb1d2cb..904da5688 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -5,6 +5,7 @@ import { chars } from "./chars.ts"; import { chunks } from "./chunks.ts"; import { hashMaps, sets, btreeMaps, deques, vecs, stores } from "./collections.ts"; import { cows } from "./cows.ts"; +import { edits } from "./edits.ts"; import { ints, strings, derived, written, panics } from "./fmt.ts"; import { methods } from "./generics.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts"; @@ -12,6 +13,7 @@ import { adaptors, consumers, ranges, options, own, values } from "./iters.ts"; import { keys } from "./keys.ts"; import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { strs, slices } from "./strs.ts"; +import { wrappers } from "./wrappers.ts"; /** Run one case. */ export function run(input: rt.ByteSlice): rt.ByteVec { @@ -22,7 +24,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec { const _10: [rt.u8, rt.u8] = [input.data[input.start], input.data[input.start + 1]]; const op: rt.u8 = _10[0]; const kind: rt.u8 = _10[1]; - const _14: rt.u8 = rt.u8Rem(op, 47); + const _14: rt.u8 = rt.u8Rem(op, 49); if (_14 === 0) { u8Op(kind, rt.byteSliceRange(input, 2), out); } else if (_14 === 1) { @@ -133,6 +135,10 @@ export function run(input: rt.ByteSlice): rt.ByteVec { stores(rt.byteSliceRange(input, 2), out); } else if (_14 === 45) { chunks(kind, rt.byteSliceRange(input, 2), out); + } else if (_14 === 46) { + wrappers(kind, rt.byteSliceRange(input, 2), out); + } else if (_14 === 47) { + edits(kind, rt.byteSliceRange(input, 2), out); } else { cows(kind, rt.byteSliceRange(input, 2), out); } diff --git a/ts/fixtures/lang/expected/keys.ts b/ts/fixtures/lang/expected/keys.ts index 8d24c88c3..7eeb9cc32 100644 --- a/ts/fixtures/lang/expected/keys.ts +++ b/ts/fixtures/lang/expected/keys.ts @@ -849,10 +849,9 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { place11.v = (place11.v << 4) & 0xffff; } const _139: Hop.Hop = { _0: rt.u64Rem(b as rt.u64, 3) }; - const place14 = rt.entryOrInsertMut(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); - const _144: rt.u8 = rt.u8WrappingAdd(place14.v[0], b); - place14.v[0] = _144; - place14.v[1] = place14.v[1] ^ place14.v[0]; + const p: [rt.u8, rt.u8] = rt.entryOrInsert(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); + p[0] = rt.u8WrappingAdd(p[0], b); + p[1] = p[1] ^ p[0]; } const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; const _150: rt.usize = rt.usizeMul(data.length, 4); @@ -863,8 +862,8 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { const _159: rt.usize = rt.usizeRem(j, data.length); rt.idx(data, _159); const b2: rt.u8 = data.data[data.start + _159]; - const place15 = rt.entryOrInsertMut(rt.entry(tree, rt.u16Mul(j & 0xffff, 37) ^ b2 as rt.u16), j & 0xffff); - place15.v = rt.u16WrappingAdd(place15.v, b2 as rt.u16); + const place14 = rt.entryOrInsertMut(rt.entry(tree, rt.u16Mul(j & 0xffff, 37) ^ b2 as rt.u16), j & 0xffff); + place14.v = rt.u16WrappingAdd(place14.v, b2 as rt.u16); } const iter3: rt.Iter<[rt.u16, rt.u16]> = rt.btreeIter(tree); while (true) { @@ -876,31 +875,31 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(_179[1]))); } const touchy: rt.BTreeMap = rt.btreeNew(Touchy.cmp$Ord) as rt.BTreeMap; - const place16 = rt.entryOrInsertWithMut(rt.entry(touchy, { _0: data.length & 0xff }), (): rt.u8 => { + const place15 = rt.entryOrInsertWithMut(rt.entry(touchy, { _0: data.length & 0xff }), (): rt.u8 => { return 7; }); - place16.v = rt.u8Add(place16.v, 1); + place15.v = rt.u8Add(place15.v, 1); const hashy: rt.HashMap = rt.hashNew(rt.hashing(Touchy.hash$Hash_DefaultHasher, Touchy.eq$PartialEq)) as rt.HashMap; - const place17 = rt.entryOrInsertWithMut(rt.entry(hashy, { _0: data.length & 0xff }), (): rt.u8 => { + const place16 = rt.entryOrInsertWithMut(rt.entry(hashy, { _0: data.length & 0xff }), (): rt.u8 => { return 0; }); - place17.v = rt.u8Add(place17.v, 2); + place16.v = rt.u8Add(place16.v, 2); rt.iterExtendBytes(out, rt.iterChain(rt.btreeValues(touchy), rt.hashValues(hashy))); - const place18 = rt.entryOrInsertWithMut(rt.entry(counts, 0), (): rt.usize => { + const place17 = rt.entryOrInsertWithMut(rt.entry(counts, 0), (): rt.usize => { return 0; }); ((): void => { - place18.v = rt.usizeAdd(place18.v, 1); + place17.v = rt.usizeAdd(place17.v, 1); })(); const spare: rt.usize[] = [data.length, 8]; - const place19 = rt.entryOrInsertMut(rt.entry(counts, 1), 3); - const swapped = place19.v; - place19.v = spare[0]; + const place18 = rt.entryOrInsertMut(rt.entry(counts, 1), 3); + const swapped = place18.v; + place18.v = spare[0]; spare[0] = swapped; - const place20 = rt.entryOrInsertWithMut(rt.entry(counts, 2), (): rt.usize => { + const place19 = rt.entryOrInsertWithMut(rt.entry(counts, 2), (): rt.usize => { return 0; }); - place20.v = rt.usizeAdd(place20.v, spare[0]); + place19.v = rt.usizeAdd(place19.v, spare[0]); const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(counts); while (true) { const _241: [rt.u8, rt.usize] | rt.Done = iter4.next(); diff --git a/ts/fixtures/lang/expected/wrappers.Scale.ts b/ts/fixtures/lang/expected/wrappers.Scale.ts new file mode 100644 index 000000000..c9ff4733c --- /dev/null +++ b/ts/fixtures/lang/expected/wrappers.Scale.ts @@ -0,0 +1,22 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function eq$PartialEq(self: Scale, other: Scale): boolean { + return rt.u64Eq(self._0, other._0); +} + +export function partialCmp$PartialOrd(self: Scale, other: Scale): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + +export function cmp$Ord(self: Scale, other: Scale): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** A rate that is never 0, as a timescale is. */ +export interface Scale { + _0: rt.u64; +} + +//# sourceMappingURL=wrappers.Scale.ts.map diff --git a/ts/fixtures/lang/expected/wrappers.ts b/ts/fixtures/lang/expected/wrappers.ts new file mode 100644 index 000000000..4797f9123 --- /dev/null +++ b/ts/fixtures/lang/expected/wrappers.ts @@ -0,0 +1,426 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { put } from "./fmt.ts"; +import * as Scale from "./wrappers.Scale.ts"; + +export function putU64(out: rt.ByteVec, v: rt.u64): void { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(v))); +} + +export function putBound(out: rt.ByteVec, b: rt.Bound): void { + if (b.tag === "Included") { + rt.byteVecPush(out, 1); + putU64(out, (b as { tag: "Included"; _0: rt.u64 })._0); + } else if (b.tag === "Excluded") { + rt.byteVecPush(out, 2); + putU64(out, (b as { tag: "Excluded"; _0: rt.u64 })._0); + } else { + rt.byteVecPush(out, 3); + } +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$Bound_u64_Bound_u64(out: rt.ByteVec, r: [rt.Bound, rt.Bound]): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, r[0]); + putBound(out, r[1]); + const _10: rt.Bound = r[0]; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = r[1]; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeFrom_u64(out: rt.ByteVec, r: { start: rt.u64 }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Included", _0: r.start } as rt.Bound); + putBound(out, { tag: "Unbounded" } as rt.Bound); + const _10: rt.Bound = { tag: "Included", _0: r.start } as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = { tag: "Unbounded" } as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeFull(out: rt.ByteVec, _: undefined): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.Bound); + putBound(out, { tag: "Unbounded" } as rt.Bound); + const _10: rt.Bound = { tag: "Unbounded" } as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = { tag: "Unbounded" } as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeInclusive_u64(out: rt.ByteVec, r: rt.RangeInclusive): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, rt.rangeInclusiveStartBound(r) as rt.Bound); + putBound(out, rt.rangeInclusiveEndBound(r) as rt.Bound); + const _10: rt.Bound = rt.rangeInclusiveStartBound(r) as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = rt.rangeInclusiveEndBound(r) as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeToInclusive_u64(out: rt.ByteVec, r: { end: rt.u64; inclusive: true }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.Bound); + putBound(out, { tag: "Included", _0: r.end } as rt.Bound); + const _10: rt.Bound = { tag: "Unbounded" } as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = { tag: "Included", _0: r.end } as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$RangeTo_u64(out: rt.ByteVec, r: { end: rt.u64 }): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Unbounded" } as rt.Bound); + putBound(out, { tag: "Excluded", _0: r.end } as rt.Bound); + const _10: rt.Bound = { tag: "Unbounded" } as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = { tag: "Excluded", _0: r.end } as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** + * The bounds of `r`, written, then the first sequence and the end past the last it holds, + * as a range of groups reads them. + */ +export function bounds$Range_u64(out: rt.ByteVec, r: rt.Range): void { + let start!: rt.u64 | undefined; + let end!: rt.u64 | undefined; + putBound(out, { tag: "Included", _0: r.start } as rt.Bound); + putBound(out, { tag: "Excluded", _0: r.end } as rt.Bound); + const _10: rt.Bound = { tag: "Included", _0: r.start } as rt.Bound; + if (_10.tag === "Included") { + start = (_10 as { tag: "Included"; _0: rt.u64 })._0; + } else if (_10.tag === "Excluded") { + start = rt.u64CheckedAdd((_10 as { tag: "Excluded"; _0: rt.u64 })._0, 1); + } else { + start = 0; + } + const _17: rt.Bound = { tag: "Excluded", _0: r.end } as rt.Bound; + if (_17.tag === "Included") { + end = rt.u64CheckedAdd((_17 as { tag: "Included"; _0: rt.u64 })._0, 1); + } else if (_17.tag === "Excluded") { + end = (_17 as { tag: "Excluded"; _0: rt.u64 })._0; + } else { + end = undefined; + } + putU64(out, rt.optionUnwrapOr(start, 0)); + putU64(out, rt.optionUnwrapOr(end, 0)); + rt.byteVecPush(out, rt.u8Add(start !== undefined ? 1 : 0, rt.u8Mul(2, end !== undefined ? 1 : 0))); +} + +/** A bound of `a` picked by `kind`, held by value. */ +export function boundOf(kind: rt.u8, a: rt.u64): rt.Bound { + const _3: rt.u8 = rt.u8Rem(kind, 3); + if (_3 === 0) { + return { tag: "Included", _0: a } as rt.Bound; + } + if (_3 === 1) { + return { tag: "Excluded", _0: a } as rt.Bound; + } + return { tag: "Unbounded" } as rt.Bound; +} + +export function wrappers(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + let scale!: Scale.Scale; + let name!: string; + const _5: (a0: rt.u8) => rt.u64 = (b3: rt.u8): rt.u64 => { + const _3: rt.u8 = rt.u8Rem(b3, 4); + if (_3 === 0) { + return b3 as rt.u64; + } + if (_3 === 1) { + return rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, b3 as rt.u64); + } + if (_3 === 2) { + return rt.u64Add({ hi: 0x200000, lo: 0 } as rt.u64, b3 as rt.u64); + } + return rt.u64Mul(b3 as rt.u64, 7); + }; + const at: (a0: rt.usize) => rt.u8 = (i3: rt.usize): rt.u8 => { + return rt.optionUnwrapOr(rt.byteSliceGet(data, i3), 0); + }; + const part = at(0); + const _9: rt.u64 = _5(part); + const part2 = at(1); + const _8: [rt.u64, rt.u64] = [_9, _5(part2)]; + const a: rt.u64 = _9; + const b: rt.u64 = _8[1]; + const _21: rt.u8 = rt.u8Rem(kind, 5); + if (_21 === 0) { + bounds$Range_u64(out, new rt.Range(a, b, rt.u64Step)); + bounds$RangeInclusive_u64(out, new rt.RangeInclusive(a, b, rt.u64Step)); + const stepped: rt.RangeInclusive = new rt.RangeInclusive(rt.u64Rem(a, 4), rt.u64Rem(b, 4), rt.u64Step); + while (rt.iterToOption(stepped.next()) !== undefined) { + } + bounds$RangeInclusive_u64(out, stepped); + const top: rt.RangeInclusive = new rt.RangeInclusive(rt.u64Sub({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Rem(a, 2)), { hi: 0xffffffff, lo: 0xffffffff } as rt.u64, rt.u64Step); + while (rt.iterToOption(top.next()) !== undefined) { + } + bounds$RangeInclusive_u64(out, top); + const down: rt.RangeInclusive = new rt.RangeInclusive(0, rt.u64Rem(b, 3), rt.u64Step); + while (rt.iterToOption(down.nextBack()) !== undefined) { + } + bounds$RangeInclusive_u64(out, down); + bounds$RangeTo_u64(out, { end: b }); + bounds$RangeToInclusive_u64(out, { end: b, inclusive: true }); + bounds$RangeFrom_u64(out, { start: a }); + bounds$RangeFull(out, undefined); + bounds$Bound_u64_Bound_u64(out, [boundOf(at(2), a), boundOf(at(3), b)] as [rt.Bound, rt.Bound]); + const held: [rt.Bound, rt.Bound] = [boundOf(at(3), b), { tag: "Unbounded" } as rt.Bound]; + bounds$Bound_u64_Bound_u64(out, held); + putBound(out, held[0]); + } else if (_21 === 1) { + const map: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; + const iter: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))); + while (true) { + const _90: [rt.usize, rt.u8] | rt.Done = iter.next(); + if (_90 === rt.DONE) { + break; + } + rt.btreeInsert(map, _90[1] as rt.u64, _90[0] as rt.u64); + } + const _101: [rt.u64, rt.u64] = [at(0) as rt.u64, at(1) as rt.u64]; + const a2: rt.u64 = _101[0]; + const b2: rt.u64 = _101[1]; + const iter2: rt.Iter<[rt.u64, rt.u64]> = rt.btreeRange(map, { end: a2, inclusive: true }); + while (true) { + const _115: [rt.u64, rt.u64] | rt.Done = iter2.next(); + if (_115 === rt.DONE) { + break; + } + putU64(out, _115[0]); + putU64(out, _115[1]); + } + rt.byteVecPush(out, 254); + const _125: [rt.u64, rt.u64] | undefined = rt.iterToOption(rt.btreeRange(map, { end: b2, inclusive: true }).nextBack()); + if (_125 !== undefined) { + putU64(out, _125[0]); + } + rt.byteVecPush(out, rt.iterCount(rt.btreeRange(map, { end: a2 })) & 0xff); + const above: rt.BTreeMap = rt.btreeSplitOff(map, b2); + const iter3: rt.Iter<[rt.u64, rt.u64]> = rt.iterChain(rt.btreeIter(map), rt.btreeIter(above)); + while (true) { + const _150: [rt.u64, rt.u64] | rt.Done = iter3.next(); + if (_150 === rt.DONE) { + break; + } + putU64(out, _150[0]); + putU64(out, _150[1]); + } + rt.byteVecPush(out, rt.btreeLen(map) & 0xff); + rt.byteVecPush(out, rt.btreeLen(above) & 0xff); + const _168: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _168, true); + const _173: rt.u8 = at(2); + const high: rt.BTreeSet = rt.btreeSplitOff(set, _173); + rt.iterExtendBytes(out, rt.iterChain(rt.btreeKeys(set), rt.btreeKeys(high))); + rt.byteVecPush(out, rt.btreeLen(high) & 0xff); + } else if (_21 === 2) { + const _188: [rt.u8, rt.u8] = [at(0), at(1)]; + const x2: rt.u8 = _188[0]; + const y: rt.u8 = _188[1]; + rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) & 0xff); + rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) === -1 ? 1 : 0); + rt.byteVecPush(out, rt.cmpReverse(rt.cmpOption(rt.cmp))(x2, undefined) === 1 ? 1 : 0); + rt.byteVecPush(out, rt.ordMax(x2, y, rt.cmpReverse(rt.cmp))); + const order = rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])([x2, y] as [rt.u8, rt.u8], [y, x2] as [rt.u8, rt.u8]); + rt.byteVecPush(out, order !== undefined && order <= 0 ? 1 : 0); + const _232: rt.Iter<[rt.u8, rt.usize]> = rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_2: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { + return [_2[1], _2[0]] as [rt.u8, rt.usize]; + }); + const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmpReverse(rt.cmp)) as rt.BTreeMap, _232, true)); + while (true) { + const _238: [rt.u8, rt.usize] | rt.Done = iter4.next(); + if (_238 === rt.DONE) { + break; + } + rt.byteVecPush(out, _238[0]); + rt.byteVecPush(out, _238[1] & 0xff); + } + const ranked: [rt.u8, rt.usize][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_23: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { + return [_23[1], _23[0]] as [rt.u8, rt.usize]; + })); + rt.sliceSortByKey(ranked, (_25: [rt.u8, rt.usize]): [rt.u8, rt.usize] => { + return [rt.u8Rem(_25[0], 4), _25[1]] as [rt.u8, rt.usize]; + }, rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])); + for (const _258 of ranked) { + const d: rt.u8 = _258[0]; + const i2: rt.usize = _258[1]; + rt.byteVecPush(out, d); + rt.byteVecPush(out, i2 & 0xff); + } + put(out, "held"); + } else if (_21 === 3) { + const n: rt.u64 | undefined = rt.nonZero(a); + if (n === undefined) { + rt.byteVecPush(out, 0); + } else { + const n2: rt.u64 = n; + putU64(out, n2); + putU64(out, n2); + const _290: rt.u64 = rt.optionUnwrapOr(rt.nonZero(b), n2); + const _287: boolean = rt.u64Eq(n2, _290); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.fmtBool(_287, f)]; + put(out, rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2]])); + rt.byteVecPush(out, rt.u64Gt(n2, { _0: 1 }._0) ? 1 : 0); + rt.byteVecPush(out, rt.cmp(n2, { _0: 1000 }._0) & 0xff); + } + rt.byteVecPush(out, rt.nonZero(rt.u64And(a, 1)) !== undefined ? 1 : 0); + } else { + const _317: rt.u64 | undefined = rt.nonZero(a); + b1: { + if (_317 !== undefined) { + if (rt.u8Rem(at(2), 2) === 0) { + scale = { _0: _317 }; + break b1; + } + } + const _328: rt.usize = rt.usizeRem(at(3) as rt.usize, 3); + if (!(_328 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _328); + } + scale = [{ _0: 1 }, { _0: 1000 }, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }][_328]; + } + if (!rt.u64Eq(1, scale._0)) { + if (!rt.u64Eq(1000, scale._0)) { + if (!rt.u64Eq({ hi: 0xffffffff, lo: 0xffffffff } as rt.u64, scale._0)) { + name = "other"; + } else { + name = "wide"; + } + } else { + name = "milli"; + } + } else { + name = "one"; + } + put(out, name); + rt.byteVecPush(out, Scale.eq$PartialEq(scale, { _0: 1000 }) ? 1 : 0); + rt.byteVecPush(out, Scale.partialCmp$PartialOrd(scale, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }) === -1 ? 1 : 0); + putU64(out, scale._0); + } +} + +//# sourceMappingURL=wrappers.ts.map diff --git a/ts/fixtures/lang/src/edits.rs b/ts/fixtures/lang/src/edits.rs new file mode 100644 index 000000000..eddcaec53 --- /dev/null +++ b/ts/fixtures/lang/src/edits.rs @@ -0,0 +1,266 @@ +//! `Vec`'s and slices' editing and sorting methods, with closures that log what they are +//! called with, `Clone` and comparisons of vectors and tuples that are not `Copy`, +//! `mem::take`, `Ord`'s defaults on the crate's own types, and `str`'s byte searches. + +use std::collections::{BTreeSet, VecDeque}; + +use crate::fmt::put; +use crate::strs::text; + +/// The crate's own order, whose `min`, `max`, and `clamp` are `Ord`'s defaults. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] +struct Stamp(u8); + +/// What `mem::take` leaves its own `Default` in place of. +struct Tally { + n: u8, + names: Vec, +} + +impl Default for Tally { + fn default() -> Self { + Self { + n: 7, + names: vec![String::from("fresh")], + } + } +} + +/// An element that is not `Copy`, cloned and compared field by field. +#[derive(Clone, PartialEq, PartialOrd)] +struct Named { + id: u16, + name: String, +} + +fn put_u16s(out: &mut Vec, v: &[u16]) { + for x in v { + out.extend_from_slice(&x.to_be_bytes()); + } + out.push(0xfe); +} + +pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { + let words: Vec = data.iter().map(|&b| b as u16 * 3).collect(); + let at = |i: usize| data.get(i).copied().unwrap_or(0); + match kind % 7 { + 0 => { + // `retain` sees each element once, in order, and keeps what it returns true for. + let mut v = words.clone(); + let mut seen = Vec::new(); + v.retain(|&x| { + seen.push(x); + x % 4 != 0 + }); + put_u16s(out, &seen); + put_u16s(out, &v); + let mut pairs: Vec<(u16, u16)> = words.iter().map(|&w| (w, 0)).collect(); + pairs.retain_mut(|p| { + p.1 = p.0 / 2; + p.0 % 3 == 0 + }); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + let mut names: Vec = data.iter().map(|&b| text(&[b])).collect(); + names.retain(|s| s.len() > 1); + out.push(names.len() as u8); + // Panics on the element the last byte names, keeping what it decided. + let stop = at(data.len().saturating_sub(1)) as u16 * 3; + if kind & 0x80 != 0 { + v.retain(|&x| { + if x == stop { + panic!("retain stopped at {x}"); + } + true + }); + } + } + 1 => { + // Runs of equal neighbors, by value, by a key, and by a test that logs what it + // compares, current first. + let mut v: Vec = data.iter().map(|&b| (b % 4) as u16).collect(); + v.dedup(); + put_u16s(out, &v); + // By what each element's closure reads through its `&mut`. + let named = |w: u16| Named { + id: w, + name: text(&[w as u8 / 16]), + }; + let mut keyed: Vec = words.iter().map(|&w| named(w)).collect(); + keyed.dedup_by_key(|n| n.id / 24); + for n in &keyed { + put_u16s(out, &[n.id]); + } + let mut tested: Vec = words.iter().map(|&w| named(w)).collect(); + let mut seen = Vec::new(); + tested.dedup_by(|a, b| { + seen.push(a.id); + seen.push(b.id); + a.name == b.name + }); + put_u16s(out, &seen); + for n in &tested { + put(out, &n.name); + } + let mut names: Vec = data.iter().map(|&b| text(&[b % 3])).collect(); + names.dedup(); + out.push(names.len() as u8); + } + 2 => { + let mut v = words.clone(); + v.sort(); + put_u16s(out, &v); + let mut v = words.clone(); + v.sort_unstable_by(|a, b| b.cmp(a)); + put_u16s(out, &v); + // Stable: equal keys keep their order. + let mut pairs: Vec<(u16, u16)> = words.iter().enumerate().map(|(i, &w)| (w % 5, i as u16)).collect(); + pairs.sort_by_key(|p| p.0); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + pairs.sort_unstable_by_key(|&(a, b)| (b % 3, a, b)); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + pairs.sort_by(|x, y| y.1.cmp(&x.1)); + for (a, b) in &pairs { + put_u16s(out, &[*a, *b]); + } + // `None` first, as `Option`'s `Ord` puts it. + let mut options: Vec> = words.iter().map(|&w| if w % 2 == 0 { None } else { Some(w) }).collect(); + options.sort_unstable(); + for o in &options { + put_u16s(out, &[o.map_or(0xffff, |o| o)]); + } + let mut names: Vec = data.iter().map(|&b| text(&[b, b / 16])).collect(); + names.sort(); + for name in &names { + put(out, name); + } + } + 3 => { + let mut v = words.clone(); + put_u16s(out, &[v.last().copied().unwrap_or(0xffff)]); + let mut runs: Vec<(u16, Option)> = words.iter().map(|&w| (w, None)).collect(); + if let Some(last) = runs.last_mut() { + last.1 = Some(last.0); + } + if let Some(first) = runs.first_mut() { + first.0 += 1; + } + for (a, b) in &runs { + put_u16s(out, &[*a, b.unwrap_or(0xffff)]); + } + v.reverse(); + put_u16s(out, &v); + let named: Vec = words + .iter() + .map(|&w| Named { + id: w, + name: text(&[w as u8]), + }) + .collect(); + let probe = Named { + id: at(1) as u16 * 3, + name: text(&[at(1).wrapping_mul(3)]), + }; + out.push(named.contains(&probe) as u8); + out.push(words.contains(&(at(2) as u16 * 3)) as u8); + out.push(data.contains(&at(3)) as u8); + // Each panics with std's message past the end. + let (i, j) = (at(0) as usize % 8, at(1) as usize % 8); + let mut moved = words.clone(); + let taken = moved.swap_remove(i); + put_u16s(out, &[taken]); + put_u16s(out, &moved); + moved.swap(i, j); + put_u16s(out, &moved); + } + 4 => { + // Clones and comparisons of what is not `Copy`, element by element. + let named: Vec = words + .iter() + .map(|&w| Named { + id: w, + name: text(&[w as u8]), + }) + .collect(); + let cloned = named.clone(); + out.push((cloned == named) as u8); + let mut changed = named.to_vec(); + if let Some(first) = changed.first_mut() { + first.name.push('!'); + } + out.push((changed == named) as u8); + out.push((changed != named) as u8); + out.push((changed < named) as u8); + changed.extend_from_slice(&named[..named.len() / 2]); + out.push(changed.len() as u8); + let nested: Vec> = data.iter().map(|&b| (0..b % 3).map(|i| i as u16 + b as u16).collect()).collect(); + out.push((nested.clone() == nested) as u8); + let pair = (text(data), at(0)); + let copy = pair.clone(); + put(out, ©.0); + out.push(((copy.1, ©.0) > (at(1), &pair.0)) as u8); + out.push(((at(0), at(1)) < (at(1), at(0))) as u8); + let mut grown = words.clone(); + grown.extend_from_slice(&words); + put_u16s(out, &grown); + } + 5 => { + // Taken, leaving each type's own `Default`. + let mut tally = Tally { + n: at(0), + names: vec![text(data)], + }; + let taken = std::mem::take(&mut tally); + out.push(taken.n); + out.push(tally.n); + put(out, &tally.names[0]); + let mut queue: VecDeque = words.iter().copied().collect(); + let drained = std::mem::take(&mut queue); + out.push(drained.len() as u8); + out.push(queue.len() as u8); + let mut set: BTreeSet = words.iter().copied().collect(); + out.push(std::mem::take(&mut set).len() as u8); + out.push(set.is_empty() as u8); + // `Ord`'s defaults of the crate's own type; `clamp` panics on bounds out of order. + let (x, lo, hi) = (Stamp(at(0)), Stamp(at(1)), Stamp(at(2))); + out.push(x.max(lo).0); + out.push(x.min(lo).0); + out.push(x.clamp(lo, hi).0); + } + _ => { + let s = text(data); + let sep = ['/', 'a']; + out.push(s.contains(sep) as u8); + out.push(s.contains(&sep[..]) as u8); + out.push(s.ends_with("/") as u8); + out.push(s.ends_with('😀') as u8); + out.push(s.ends_with(|c: char| c.is_ascii_digit()) as u8); + match s.split_once('/') { + Some((head, tail)) => { + put(out, head); + put(out, tail); + } + None => out.push(0xfd), + } + match s.split_once("a0") { + Some((head, tail)) => { + put(out, head); + put(out, tail); + } + None => out.push(0xfd), + } + for i in 0..=s.len() + 1 { + out.push(s.is_char_boundary(i) as u8); + } + out.extend(s.bytes()); + out.extend(s.bytes().rev().take(3)); + out.push(s.bytes().len() as u8); + out.push(s.bytes().filter(|&b| b >= 0x80).count() as u8); + } + } +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 7ed64b1e9..a2619115f 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -1,7 +1,7 @@ //! The entry point both sides of the differential test run. The first byte picks a //! case and the rest is its input. -use crate::{chars, chunks, collections, cows, fmt, generics, ints, iters, keys, shapes, strs}; +use crate::{chars, chunks, collections, cows, edits, fmt, generics, ints, iters, keys, shapes, strs, wrappers}; /// The native side's entry: [`run`], except that a case starting with 0xff prints a /// [`fmt::Fault`], which the translated side prints from TypeScript in `caller.ts`. @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 47 { + match op % 49 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -76,6 +76,8 @@ pub fn run(input: &[u8]) -> Vec { 43 => strs::slices(kind, data, &mut out), 44 => collections::stores(data, &mut out), 45 => chunks::chunks(kind, data, &mut out), + 46 => wrappers::wrappers(kind, data, &mut out), + 47 => edits::edits(kind, data, &mut out), _ => cows::cows(kind, data, &mut out), } out diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index aaf82f5f3..e69badced 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -10,6 +10,7 @@ mod chars; mod chunks; mod collections; mod cows; +mod edits; mod fmt; mod generics; pub mod harness; @@ -18,6 +19,7 @@ mod iters; mod keys; mod shapes; mod strs; +mod wrappers; #[cfg(target_arch = "wasm32")] #[path = "../../wasm.rs"] mod wasm; diff --git a/ts/fixtures/lang/src/wrappers.rs b/ts/fixtures/lang/src/wrappers.rs new file mode 100644 index 000000000..a859db911 --- /dev/null +++ b/ts/fixtures/lang/src/wrappers.rs @@ -0,0 +1,185 @@ +//! std's bounds and wrappers: `Bound` and `RangeBounds` of each range, `..=` as a +//! B-tree's range, `split_off`, `Reverse` as an order and a key, and `NonZero`, made, read, +//! matched as a constant, compared, and printed. + +use std::cmp::Reverse; +use std::collections::{BTreeMap, BTreeSet}; +use std::num::NonZero; +use std::ops::{Bound, RangeBounds}; + +use crate::fmt::put; + +/// A rate that is never 0, as a timescale is. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +struct Scale(NonZero); + +impl Scale { + const ONE: Self = Self(NonZero::new(1).unwrap()); + const MILLI: Self = Self(NonZero::new(1000).unwrap()); + const WIDE: Self = Self(NonZero::new(u64::MAX).unwrap()); +} + +fn put_u64(out: &mut Vec, v: u64) { + out.extend_from_slice(&v.to_be_bytes()); +} + +fn put_bound(out: &mut Vec, b: Bound<&u64>) { + match b { + Bound::Included(v) => { + out.push(1); + put_u64(out, *v); + } + Bound::Excluded(v) => { + out.push(2); + put_u64(out, *v); + } + Bound::Unbounded => out.push(3), + } +} + +/// The bounds of `r`, written, then the first sequence and the end past the last it holds, +/// as a range of groups reads them. +fn bounds(out: &mut Vec, r: impl RangeBounds) { + put_bound(out, r.start_bound()); + put_bound(out, r.end_bound()); + let start = match r.start_bound().cloned() { + Bound::Included(s) => Some(s), + Bound::Excluded(s) => s.checked_add(1), + Bound::Unbounded => Some(0), + }; + let end = match r.end_bound().cloned() { + Bound::Included(e) => e.checked_add(1), + Bound::Excluded(e) => Some(e), + Bound::Unbounded => None, + }; + put_u64(out, start.unwrap_or(0)); + put_u64(out, end.unwrap_or(0)); + out.push(start.is_some() as u8 + 2 * end.is_some() as u8); +} + +/// A bound of `a` picked by `kind`, held by value. +fn bound_of(kind: u8, a: u64) -> Bound { + match kind % 3 { + 0 => Bound::Included(a), + 1 => Bound::Excluded(a), + _ => Bound::Unbounded, + } +} + +pub fn wrappers(kind: u8, data: &[u8], out: &mut Vec) { + let at = |i: usize| data.get(i).copied().unwrap_or(0); + // Wide values next to the ends, so `checked_add` and the limbs past 2^53 show. + let wide = |b: u8| match b % 4 { + 0 => b as u64, + 1 => u64::MAX - b as u64, + 2 => (1 << 53) + b as u64, + _ => b as u64 * 7, + }; + let (a, b) = (wide(at(0)), wide(at(1))); + match kind % 5 { + 0 => { + bounds(out, a..b); + bounds(out, a..=b); + // Drained, an inclusive range's start passes its end, and only wrapping exhausts it, + // which leaves it excluding its start. + let mut stepped = (a % 4)..=(b % 4); + while stepped.next().is_some() {} + bounds(out, stepped); + let mut top = (u64::MAX - a % 2)..=u64::MAX; + while top.next().is_some() {} + bounds(out, top); + let mut down = 0..=(b % 3); + while down.next_back().is_some() {} + bounds(out, down); + bounds(out, ..b); + bounds(out, ..=b); + bounds(out, a..); + bounds(out, ..); + bounds(out, (bound_of(at(2), a), bound_of(at(3), b))); + let held = (bound_of(at(3), b), Bound::Unbounded); + bounds(out, held); + put_bound(out, held.0.as_ref()); + } + 1 => { + let mut map = BTreeMap::new(); + for (i, &x) in data.iter().enumerate() { + map.insert(x as u64, i as u64); + } + let (a, b) = (at(0) as u64, at(1) as u64); + for (k, v) in map.range(..=a) { + put_u64(out, *k); + put_u64(out, *v); + } + out.push(0xfe); + if let Some((k, _)) = map.range(..=b).next_back() { + put_u64(out, *k); + } + out.push(map.range(..a).count() as u8); + let above = map.split_off(&b); + for (k, v) in map.iter().chain(above.iter()) { + put_u64(out, *k); + put_u64(out, *v); + } + out.push(map.len() as u8); + out.push(above.len() as u8); + let mut set: BTreeSet = data.iter().copied().collect(); + let high = set.split_off(&at(2)); + out.extend(set.iter().chain(high.iter())); + out.push(high.len() as u8); + } + 2 => { + // Ordered the other way, alone and in tuples, as keys and as sort keys. + let (x, y) = (at(0), at(1)); + out.push(Reverse(x).cmp(&Reverse(y)) as i8 as u8); + out.push((Reverse(x) < Reverse(y)) as u8); + out.push((Reverse(Some(x)) > Reverse(None)) as u8); + out.push(Reverse(x).max(Reverse(y)).0); + out.push(((Reverse(x), y) <= (Reverse(y), x)) as u8); + let keyed: BTreeMap, usize> = data.iter().enumerate().map(|(i, &d)| (Reverse(d), i)).collect(); + for (Reverse(k), i) in &keyed { + out.push(*k); + out.push(*i as u8); + } + let mut ranked: Vec<(u8, usize)> = data.iter().enumerate().map(|(i, &d)| (d, i)).collect(); + ranked.sort_by_key(|&(d, i)| (Reverse(d % 4), i)); + for (d, i) in ranked { + out.push(d); + out.push(i as u8); + } + let wrapped = Reverse(String::from("held")); + put(out, &wrapped.0); + } + 3 => { + let n = NonZero::new(a); + match n { + Some(n) => { + put_u64(out, n.get()); + put_u64(out, u64::from(n)); + put(out, &format!("{n} {n:?} {}", n == NonZero::new(b).unwrap_or(n))); + out.push((n > Scale::ONE.0) as u8); + out.push(n.cmp(&Scale::MILLI.0) as i8 as u8); + } + None => out.push(0), + } + let none: Option> = NonZero::new(a & 1); + out.push(none.is_some() as u8); + } + _ => { + // Matched against constants, as derived `PartialEq` and patterns read them. + let scale = match NonZero::new(a) { + Some(n) if at(2) % 2 == 0 => Scale(n), + _ => [Scale::ONE, Scale::MILLI, Scale::WIDE][at(3) as usize % 3], + }; + let name = match scale { + Scale::ONE => "one", + Scale::MILLI => "milli", + Scale::WIDE => "wide", + Scale(_) => "other", + }; + put(out, name); + out.push((scale == Scale::MILLI) as u8); + out.push((scale < Scale::WIDE) as u8); + put_u64(out, scale.0.get()); + } + } +} diff --git a/ts/fixtures/task/expected/drops.Key.ts b/ts/fixtures/task/expected/drops.Key.ts index 2b6777d3f..2f2e54c69 100644 --- a/ts/fixtures/task/expected/drops.Key.ts +++ b/ts/fixtures/task/expected/drops.Key.ts @@ -81,6 +81,10 @@ export function eq$PartialEq(self: Key, other: Key): boolean { return read(self) === read(other); } +export function partialCmp$PartialOrd(self: Key, other: Key): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + export function cmp$Ord(self: Key, other: Key): rt.Ordering { return rt.cmp(read(self), read(other)); } @@ -101,6 +105,15 @@ export function hash$Hash_DefaultHasher(self: Key, state: rt.Hasher): void { rt.hashInt(read(self), state); } +export function clone$Clone(self: Key): Key { + const id: rt.u32 = read(self); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(id, f)]; + const _5: string = rt.fmtFormat(["k", args2[0], " cloned"]); + Log.note(self.log, _5); + const _14: Log.Log = Log.clone$Clone(self.log); + return faulty(id, _14, self.fault); +} + export function fmt$Debug(self: Key, f: rt.Formatter): rt.Result { return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, "Key"), (f: rt.Formatter) => rt.u32Display(self.id, f))); } diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index ca0742106..d312482e8 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -1,7 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Guard_Bomb_Held, drop$Held, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Held, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; +import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Guard_Bomb_Held, drop$Held, drop$Key_Key, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Held, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; import * as Bomb from "./drops.Bomb.ts"; import type * as Fault from "./drops.Fault.ts"; import * as Held from "./drops.Held.ts"; @@ -15,7 +15,7 @@ import * as Log from "./log.Log.ts"; import * as Guard from "./model.Guard.ts"; /** - * Run scenario `arg % 13`, panicking at the point `arg / 13 % 8` names, if any: what + * Run scenario `arg % 14`, panicking at the point `arg / 14 % 8` names, if any: what * every value std holds drops, where Rust drops it, and in Rust's order. */ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { @@ -76,7 +76,7 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { _372 = false; _371 = false; _370 = false; - const at: rt.u8 = rt.u8Rem(rt.u8Div(arg, 13), 8); + const at: rt.u8 = rt.u8Rem(rt.u8Div(arg, 14), 8); const guard: (a0: rt.u32) => Guard.Guard = (n: rt.u32): Guard.Guard => { return Guard.new(rt.u32Add(id, n), Log.clone$Clone(log)); }; @@ -86,7 +86,7 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { rt.panicFmt(["d", args18[0], " at ", args18[1]]); } }; - const _13: rt.u8 = rt.u8Rem(arg, 13); + const _13: rt.u8 = rt.u8Rem(arg, 14); if (_13 === 4) { ordered(log, id, at); } else if (_13 === 5) { @@ -105,25 +105,27 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { grown(log, id, at, true); } else if (_13 === 12) { grown(log, id, at, false); + } else if (_13 === 13) { + edited(log, id, at); } else if (_13 === 0) { v = []; - unwind = 205; + unwind = 206; const _19 = { tag: "One", _0: guard(1) } as Held.Held; v.push(_19); v.push({ tag: "Empty" } as Held.Held); _29 = guard(2); - unwind = 204; - const _32: Guard.Guard = guard(3); unwind = 205; + const _32: Guard.Guard = guard(3); + unwind = 206; v.push({ tag: "Two", _0: _29, _1: _32 } as Held.Held); - unwind = 203; + unwind = 204; held_ = v; check(1); arc = new rt.Arc({ tag: "One", _0: guard(4) } as Held.Held); - unwind = 224; + unwind = 225; _378 = true; shared = rt.arcClone(arc); - unwind = 202; + unwind = 203; _378 = false; rt.arcDrop(arc, drop$Held); const part4 = shared.strong; @@ -131,7 +133,7 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { Log.note(log, rt.fmtFormat(["arc ", args2[0]])); const part5 = shared.strong; cloned = rt.arcClone(shared); - unwind = 222; + unwind = 223; _377 = true; const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.usizeDisplay(part5, f)]; Log.note(log, rt.fmtFormat(["counted ", args4[0]])); @@ -139,22 +141,22 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { rt.arcDrop(cloned, drop$Held); check(2); v2 = []; - unwind = 201; + unwind = 202; const _85 = { tag: "One", _0: guard(5) } as Held.Held; v2.push(_85); - unwind = 222; + unwind = 223; mutex = new rt.Mutex(v2); - unwind = 220; + unwind = 221; _376 = true; _91 = guard(6); - unwind = 200; + unwind = 201; const _94: Guard.Guard = guard(7); - unwind = 220; + unwind = 221; boxed = { tag: "Two", _0: _91, _1: _94 } as Held.Held; - unwind = 218; + unwind = 219; _375 = true; const _98: Held.Held = { tag: "One", _0: guard(8) }; - unwind = 199; + unwind = 200; maybe = _98; check(3); const _112: rt.usize = held_.length; @@ -167,9 +169,9 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { _376 = false; rt.dropAll(mutex.value, drop$Held); check(5); - unwind = 218; + unwind = 219; drop$Option_Box_Held(maybe); - unwind = 224; + unwind = 225; _375 = false; _376 = false; _377 = false; @@ -180,53 +182,53 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { } else if (_13 === 1) { const _133: rt.u32 = rt.u32Add(id, 10); _135 = Log.clone$Clone(log); - unwind = 198; + unwind = 199; const _137: Guard.Guard = guard(11); - unwind = 197; + unwind = 198; wrapped = new Wrap.Wrap({ id: _133, log: _135, inner: { tag: "One", _0: _137 } as Held.Held }); const _141: rt.u32 = rt.u32Add(id, 20); _143 = Log.clone$Clone(log); - unwind = 196; + unwind = 197; const _144: Guard.Guard = guard(21); - unwind = 195; + unwind = 196; guarded = new Wrap.Wrap({ id: _141, log: _143, inner: _144 }); check(1); _152 = guard(31); - unwind = 194; + unwind = 195; const _155: Guard.Guard = guard(32); - unwind = 193; + unwind = 194; _151 = { tag: "Two", _0: _152, _1: _155 } as Held.Held; const _158: Guard.Guard = guard(33); - unwind = 216; + unwind = 217; _374 = true; pair = new Pair.Pair({ first: _151, second: _158 }); v3 = []; - unwind = 192; + unwind = 193; _166 = guard(41); - unwind = 191; - const _169: Guard.Guard = guard(42); unwind = 192; + const _169: Guard.Guard = guard(42); + unwind = 193; v3.push(new Pair.Pair({ first: _166, second: _169 })); _175 = guard(43); - unwind = 190; + unwind = 191; const _178: Guard.Guard = guard(44); - unwind = 192; + unwind = 193; v3.push(new Pair.Pair({ first: _175, second: _178 })); - unwind = 189; + unwind = 190; pairs = v3; check(2); const _185: rt.u32 = rt.u32Add(id, 50); _187 = Log.clone$Clone(log); - unwind = 188; + unwind = 189; v4 = []; - unwind = 187; + unwind = 188; const _193: rt.u32 = rt.u32Add(id, 60); _195 = Log.clone$Clone(log); - unwind = 186; - const _197: Guard.Guard = guard(61); unwind = 187; + const _197: Guard.Guard = guard(61); + unwind = 188; v4.push(new Wrap.Wrap({ id: _193, log: _195, inner: { tag: "One", _0: _197 } as Held.Held })); - unwind = 185; + unwind = 186; nested = new Wrap.Wrap({ id: _185, log: _187, inner: v4 }); check(3); _374 = false; @@ -237,11 +239,11 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { const _220: rt.u32 = rt.u32Add(rt.u32Add(Guard.id(pairs[rt.idx(pairs, 1)].first), Guard.id(pairs[rt.idx(pairs, 0)].second)), nested.inner.length as rt.u32); const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(_214, f), (f: rt.Formatter) => rt.u32Display(_217, f), (f: rt.Formatter) => rt.u32Display(_220, f)]; Log.note(log, rt.fmtFormat(["wraps ", args8[0], " ", args8[1], " ", args8[2]])); - unwind = 189; + unwind = 190; drop$Wrap_Vec_Wrap_Held(nested); - unwind = 216; + unwind = 217; rt.dropAll(pairs); - unwind = 197; + unwind = 198; _374 = false; drop$Wrap_Guard(guarded); unwind = 0; @@ -249,22 +251,22 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { } else if (_13 === 2) { const _243: rt.u32 = rt.u32Add(id, 70); _245 = Log.clone$Clone(log); - unwind = 184; + unwind = 185; const _248: Guard.Guard = guard(71); - unwind = 183; + unwind = 184; _247 = { tag: "One", _0: _248 } as Held.Held; const _251: Guard.Guard = guard(72); unwind = 0; shared2 = new rt.Arc(new Wrap.Wrap({ id: _243, log: _245, inner: new Pair.Pair({ first: _247, second: _251 }) })); - unwind = 214; + unwind = 215; _373 = true; v5 = []; - unwind = 182; + unwind = 183; const _258: rt.Arc>> = rt.arcClone(shared2); v5.push(_258); const _262: rt.Arc>> = rt.arcClone(shared2); v5.push(_262); - unwind = 181; + unwind = 182; clones = v5; check(1); _373 = false; @@ -276,36 +278,36 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { const part3 = !bail(log, id, at).ok; const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(part3, f)]; Log.note(log, rt.fmtFormat(["bailed ", args12[0]])); - unwind = 214; + unwind = 215; rt.dropAll(clones, drop$Arc_Wrap_Pair_Held); _373 = false; } else { _300 = guard(81); - unwind = 180; + unwind = 181; const _303: Guard.Guard = guard(82); unwind = 0; arc2 = new rt.Arc(new rt.Mutex({ tag: "Two", _0: _300, _1: _303 } as Held.Held)); - unwind = 212; + unwind = 213; _372 = true; other = rt.arcClone(arc2); - unwind = 179; + unwind = 180; check(1); _372 = false; rt.arcDrop(arc2, drop$Mutex_Held); check(2); const _319: rt.Mutex = other.value; - unwind = 178; - const held2: boolean = Held.isSome(_319.value); unwind = 179; + const held2: boolean = Held.isSome(_319.value); + unwind = 180; const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(held2, f)]; Log.note(log, rt.fmtFormat(["locked ", args14[0]])); lent = guard(83); - unwind = 177; + unwind = 178; borrowed = new rt.Arc(lent); - unwind = 210; + unwind = 211; _371 = true; again = rt.arcClone(borrowed); - unwind = 208; + unwind = 209; _370 = true; _371 = false; rt.arcDrop(borrowed); @@ -315,11 +317,11 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { const part = Guard.id(lent); const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; Log.note(log, rt.fmtFormat(["lent ", args16[0]])); - unwind = 179; + unwind = 180; _370 = false; _371 = false; rt.drop(lent); - unwind = 212; + unwind = 213; rt.arcDrop(other, drop$Mutex_Held); _372 = false; } @@ -347,130 +349,130 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { if (unwind === 0) { throw e; } - if (unwind === 177) { - break b4; - } if (unwind === 178) { - break b3; + break b4; } if (unwind === 179) { break b3; } if (unwind === 180) { + break b3; + } + if (unwind === 181) { rt.drop(_300); break b1; } - if (unwind === 181) { + if (unwind === 182) { rt.dropAll(clones, drop$Arc_Wrap_Pair_Held); break b5; } - if (unwind === 182) { + if (unwind === 183) { rt.dropAll(v5, drop$Arc_Wrap_Pair_Held); break b5; } - if (unwind === 183) { + if (unwind === 184) { drop$Held(_247); break b6; } - if (unwind === 184) { + if (unwind === 185) { break b6; } - if (unwind === 185) { + if (unwind === 186) { drop$Wrap_Vec_Wrap_Held(nested); break b10; } - if (unwind === 186) { + if (unwind === 187) { rt.drop(_195); break b12; } - if (unwind === 187) { + if (unwind === 188) { break b12; } - if (unwind === 188) { + if (unwind === 189) { break b11; } - if (unwind === 189) { + if (unwind === 190) { break b10; } - if (unwind === 190) { + if (unwind === 191) { rt.drop(_175); break b13; } - if (unwind === 191) { + if (unwind === 192) { rt.drop(_166); break b13; } - if (unwind === 192) { + if (unwind === 193) { break b13; } - if (unwind === 193) { + if (unwind === 194) { drop$Held(_151); break b8; } - if (unwind === 194) { + if (unwind === 195) { rt.drop(_152); break b8; } - if (unwind === 195) { + if (unwind === 196) { break b8; } - if (unwind === 196) { + if (unwind === 197) { rt.drop(_143); break b7; } - if (unwind === 197) { + if (unwind === 198) { break b7; } - if (unwind === 198) { + if (unwind === 199) { rt.drop(_135); break b1; } - if (unwind === 199) { + if (unwind === 200) { drop$Option_Box_Held(maybe); break b19; } - if (unwind === 200) { + if (unwind === 201) { rt.drop(_91); break b18; } - if (unwind === 201) { + if (unwind === 202) { rt.dropAll(v2, drop$Held); break b17; } - if (unwind === 202) { + if (unwind === 203) { break b16; } - if (unwind === 203) { + if (unwind === 204) { break b14; } - if (unwind === 204) { + if (unwind === 205) { rt.drop(_29); break b20; } - if (unwind === 205) { + if (unwind === 206) { break b20; } - if (unwind === 208) { + if (unwind === 209) { if (_370) { rt.arcDrop(again); } - } else if (unwind !== 210) { - if (unwind === 212) { + } else if (unwind !== 211) { + if (unwind === 213) { break b2; } - if (unwind === 214) { + if (unwind === 215) { break b5; } - if (unwind === 216) { + if (unwind === 217) { break b9; } - if (unwind === 218) { + if (unwind === 219) { break b19; } - if (unwind === 220) { + if (unwind === 221) { break b18; } - if (unwind === 222) { + if (unwind === 223) { break b17; } break b15; @@ -3043,4 +3045,543 @@ export function grown(log: Log.Log, id: rt.u32, at: rt.u8, tree: boolean): void } } +/** + * What a `Vec`'s edits, its and a tuple's `clone`, and `Ord`'s defaults drop, scenario + * `at`'s alone, and what is left to drop when a closure, a clone, a drop, or an index + * panics partway. + */ +export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { + let v!: Key.Key[]; + let v2!: Key.Key[]; + let v3!: Key.Key[]; + let v4!: Key.Key[]; + let v5!: Key.Key[]; + let v6!: Key.Key[]; + let v7!: Key.Key[]; + let v8!: Key.Key[]; + let v9!: Key.Key[]; + let v10!: Key.Key[]; + let v11!: Key.Key[]; + let v12!: Key.Key[]; + let _260!: Key.Key[]; + let tripped_!: Key.Key[]; + let v13!: Key.Key[]; + let pair!: [Key.Key, Key.Key]; + let _288!: Key.Key; + let tripped2!: [Key.Key, Key.Key]; + let _298!: Key.Key; + let _316!: Key.Key; + let _317!: Key.Key; + let _336!: Key.Key; + let _337!: Key.Key; + let _356!: Key.Key; + let _357!: Key.Key; + let _360!: Key.Key; + let _379!: Key.Key; + let _380!: Key.Key; + let _383!: Key.Key; + let _396!: Key.Key; + let _399!: Key.Key; + let _420!: boolean; + let _421!: boolean; + let _422!: boolean; + let _423!: boolean; + let _424!: boolean; + let _425!: boolean; + let _426!: boolean; + let _427!: boolean; + let unwind: number = 0; + try { + b0: { + _427 = false; + _426 = false; + _425 = false; + _424 = false; + _423 = false; + _422 = false; + _421 = false; + _420 = false; + const key: (a0: rt.u32) => Key.Key = (n: rt.u32): Key.Key => { + return Key.new(rt.u32Add(id, n), Log.clone$Clone(log)); + }; + const fault: (a0: rt.u32, a1: Fault.Fault) => Key.Key = (n2: rt.u32, fault2: Fault.Fault): Key.Key => { + return Key.faulty(rt.u32Add(id, n2), Log.clone$Clone(log), fault2); + }; + const ids: (a0: Key.Key[]) => string = (v14: Key.Key[]): string => { + return rt.iterToArray(rt.iterMap(rt.iterSlice(v14), (k: Key.Key): string => { + const _46: rt.u32 = rt.u32Sub(k.id, id); + return rt.fmtToString((f: rt.Formatter) => rt.u32Display(_46, f)); + })).join(","); + }; + if (at === 0) { + v2 = []; + unwind = 228; + const _14: Key.Key = key(1); + v2.push(_14); + const _19: Key.Key = key(2); + v2.push(_19); + const _24: Key.Key = key(3); + v2.push(_24); + const _29: Key.Key = key(4); + v2.push(_29); + unwind = 227; + v = v2; + rt.vecRetain(v, (k4: Key.Key): boolean => { + return rt.u32Rem(rt.u32Sub(k4.id, id), 2) === 1; + }, rt.drop); + const _42: string = ids(v); + unwind = 226; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _42)]; + const _38: string = rt.fmtFormat(["retained ", args2[0]]); + unwind = 227; + Log.note(log, _38); + rt.vecRetain(v, (k5: Key.Key): boolean => { + return k5.id !== rt.u32Add(id, 3); + }, rt.drop); + const _61: string = ids(v); + unwind = 225; + const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _61)]; + const _57: string = rt.fmtFormat(["retained ", args4[0]]); + unwind = 227; + Log.note(log, _57); + unwind = 0; + rt.dropAll(v); + break b0; + } + if (at === 1) { + v4 = []; + unwind = 224; + const _74: Key.Key = key(1); + v4.push(_74); + const _79: Key.Key = key(2); + v4.push(_79); + const _84: Key.Key = key(3); + v4.push(_84); + const _89: Key.Key = key(4); + v4.push(_89); + unwind = 223; + v3 = v4; + rt.vecRetain(v3, (k3: Key.Key): boolean => { + if (!(k3.id === rt.u32Add(id, 3))) { + return k3.id !== rt.u32Add(id, 2); + } + const arg = k3.id; + const args24: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg, f)]; + rt.panicFmt(["k", args24[0], " retained"]); + }, rt.drop); + unwind = 0; + rt.dropAll(v3); + } else { + if (at === 2) { + v6 = []; + unwind = 222; + const _100: Key.Key = key(1); + v6.push(_100); + const _105: Key.Key = key(1); + v6.push(_105); + const _110: Key.Key = key(2); + v6.push(_110); + const _115: Key.Key = key(2); + v6.push(_115); + const _120: Key.Key = key(3); + v6.push(_120); + unwind = 221; + v5 = v6; + rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); + const _131: string = ids(v5); + unwind = 220; + const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _131)]; + const _127: string = rt.fmtFormat(["deduped ", args6[0]]); + unwind = 221; + Log.note(log, _127); + rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { + return rt.u32Div(k2.id, 2); + }, rt.same, rt.drop); + const _148: string = ids(v5); + unwind = 219; + const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _148)]; + const _144: string = rt.fmtFormat(["deduped ", args8[0]]); + unwind = 221; + Log.note(log, _144); + rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { + return a.id > b.id; + }, rt.drop); + const _165: string = ids(v5); + unwind = 218; + const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _165)]; + const _161: string = rt.fmtFormat(["deduped ", args10[0]]); + unwind = 221; + Log.note(log, _161); + unwind = 0; + rt.dropAll(v5); + break b0; + } + if (at === 3) { + v8 = []; + unwind = 217; + const _178: Key.Key = key(1); + v8.push(_178); + const _183: Key.Key = fault(1, "Blows" as Fault.Fault); + v8.push(_183); + const _189: Key.Key = key(1); + v8.push(_189); + const _194: Key.Key = key(2); + v8.push(_194); + unwind = 216; + v7 = v8; + rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); + unwind = 0; + rt.dropAll(v7); + } else if (at === 4) { + v10 = []; + unwind = 215; + const _203: Key.Key = key(1); + v10.push(_203); + const _208: Key.Key = key(2); + v10.push(_208); + const _213: Key.Key = key(3); + v10.push(_213); + unwind = 214; + v9 = v10; + rt.drop(rt.vecSwapRemove(v9, 0)); + const _225: string = ids(v9); + unwind = 213; + const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _225)]; + const _221: string = rt.fmtFormat(["swapped ", args12[0]]); + unwind = 214; + Log.note(log, _221); + rt.drop(rt.vecSwapRemove(v9, 3)); + unwind = 0; + rt.dropAll(v9); + } else if (at === 5) { + v12 = []; + unwind = 212; + const _241: Key.Key = key(1); + v12.push(_241); + const _246: Key.Key = key(2); + v12.push(_246); + unwind = 211; + v11 = v12; + _260 = rt.vecClone(v11, Key.clone$Clone, rt.drop); + unwind = 210; + const _255: string = ids(_260); + unwind = 209; + const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _255)]; + const _251: string = rt.fmtFormat(["cloned ", args14[0]]); + unwind = 211; + rt.dropAll(_260); + Log.note(log, _251); + v13 = []; + unwind = 208; + const _270: Key.Key = key(1); + v13.push(_270); + const _275: Key.Key = fault(2, "Trips" as Fault.Fault); + v13.push(_275); + const _281: Key.Key = key(3); + v13.push(_281); + unwind = 207; + tripped_ = v13; + rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); + unwind = 211; + rt.dropAll(tripped_); + unwind = 0; + rt.dropAll(v11); + } else if (at === 6) { + _288 = key(1); + unwind = 206; + const _291: Key.Key = key(2); + unwind = 205; + pair = [_288, _291] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + _298 = key(1); + unwind = 204; + const _301: Key.Key = fault(2, "Trips" as Fault.Fault); + unwind = 203; + tripped2 = [_298, _301] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + unwind = 205; + drop$Key_Key(tripped2); + unwind = 0; + drop$Key_Key(pair); + } else { + _427 = true; + _317 = key(1); + unwind = 245; + const _320: Key.Key = key(2); + _427 = false; + _316 = rt.ordMax(_317, _320, Key.cmp$Ord, rt.drop); + unwind = 202; + _427 = false; + const part = rt.u32Sub(_316.id, id); + const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; + const _310: string = rt.fmtFormat(["max ", args16[0]]); + unwind = 0; + rt.drop(_316); + Log.note(log, _310); + _426 = true; + _337 = key(5); + unwind = 243; + const _340: Key.Key = key(4); + _426 = false; + _336 = rt.ordMin(_337, _340, Key.cmp$Ord, rt.drop); + unwind = 201; + _426 = false; + const part2 = rt.u32Sub(_336.id, id); + const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; + const _330: string = rt.fmtFormat(["min ", args18[0]]); + unwind = 0; + rt.drop(_336); + Log.note(log, _330); + _425 = true; + _357 = key(2); + unwind = 241; + _360 = key(1); + unwind = 239; + _424 = true; + const _363: Key.Key = key(3); + _425 = false; + _424 = false; + _356 = rt.ordClamp(_357, _360, _363, Key.partialCmp$PartialOrd, rt.drop); + unwind = 200; + _424 = false; + _425 = false; + const part3 = rt.u32Sub(_356.id, id); + const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; + const _350: string = rt.fmtFormat(["clamped ", args20[0]]); + unwind = 0; + rt.drop(_356); + Log.note(log, _350); + _423 = true; + _380 = key(0); + unwind = 237; + _383 = key(1); + unwind = 235; + _422 = true; + const _386: Key.Key = key(3); + _423 = false; + _422 = false; + _379 = rt.ordClamp(_380, _383, _386, Key.partialCmp$PartialOrd, rt.drop); + unwind = 199; + _422 = false; + _423 = false; + const part4 = rt.u32Sub(_379.id, id); + const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; + const _373: string = rt.fmtFormat(["clamped ", args22[0]]); + unwind = 0; + rt.drop(_379); + Log.note(log, _373); + _421 = true; + _396 = key(2); + unwind = 233; + _399 = key(3); + unwind = 231; + _420 = true; + const _402: Key.Key = key(1); + _421 = false; + _420 = false; + const _395: Key.Key = rt.ordClamp(_396, _399, _402, Key.partialCmp$PartialOrd, rt.drop); + unwind = 0; + _420 = false; + _421 = false; + rt.drop(_395); + } + } + Log.note(log, rt.fmtFormat(["unreached"])); + } + } catch (e) { + b2: { + b3: { + b4: { + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + if (unwind === 0) { + throw e; + } + if (unwind === 199) { + rt.drop(_379); + break b2; + } + if (unwind === 200) { + rt.drop(_356); + break b2; + } + if (unwind === 201) { + rt.drop(_336); + break b2; + } + if (unwind === 202) { + rt.drop(_316); + break b2; + } + if (unwind === 203) { + drop$Key_Key(tripped2); + break b3; + } + if (unwind === 204) { + rt.drop(_298); + break b3; + } + if (unwind === 205) { + break b3; + } + if (unwind === 206) { + rt.drop(_288); + break b2; + } + if (unwind === 207) { + rt.dropAll(tripped_); + break b4; + } + if (unwind === 208) { + rt.dropAll(v13); + break b4; + } + if (unwind === 209) { + break b5; + } + if (unwind === 210) { + break b5; + } + if (unwind === 211) { + break b4; + } + if (unwind === 212) { + rt.dropAll(v12); + break b2; + } + if (unwind === 213) { + break b6; + } + if (unwind === 214) { + break b6; + } + if (unwind === 215) { + rt.dropAll(v10); + break b2; + } + if (unwind === 216) { + rt.dropAll(v7); + break b2; + } + if (unwind === 217) { + rt.dropAll(v8); + break b2; + } + if (unwind === 218) { + break b7; + } + if (unwind === 219) { + break b7; + } + if (unwind === 220) { + break b7; + } + if (unwind === 221) { + break b7; + } + if (unwind === 222) { + rt.dropAll(v6); + break b2; + } + if (unwind === 223) { + rt.dropAll(v3); + break b2; + } + if (unwind === 224) { + rt.dropAll(v4); + break b2; + } + if (unwind === 225) { + break b8; + } + if (unwind === 226) { + break b8; + } + if (unwind === 227) { + break b8; + } + if (unwind === 228) { + rt.dropAll(v2); + break b2; + } + if (unwind === 231) { + if (!_420) { + break b9; + } + rt.drop(_399); + break b9; + } + if (unwind === 233) { + break b9; + } + if (unwind === 235) { + if (!_422) { + break b10; + } + rt.drop(_383); + break b10; + } + if (unwind === 237) { + break b10; + } + if (unwind === 239) { + if (_424) { + rt.drop(_360); + } + } else if (unwind !== 241) { + if (unwind === 243) { + if (!_426) { + break b2; + } + rt.drop(_337); + break b2; + } + if (!_427) { + break b2; + } + rt.drop(_317); + break b2; + } + if (!_425) { + break b2; + } + rt.drop(_357); + break b2; + } + if (!_423) { + break b2; + } + rt.drop(_380); + break b2; + } + if (!_421) { + break b2; + } + rt.drop(_396); + break b2; + } + rt.dropAll(v); + break b2; + } + rt.dropAll(v5); + break b2; + } + rt.dropAll(v9); + break b2; + } + rt.dropAll(_260); + } + rt.dropAll(v11); + break b2; + } + drop$Key_Key(pair); + } + throw e; + } +} + //# sourceMappingURL=drops.ts.map diff --git a/ts/fixtures/task/expected/lib.ts b/ts/fixtures/task/expected/lib.ts index e1bbe24ba..15b682d7f 100644 --- a/ts/fixtures/task/expected/lib.ts +++ b/ts/fixtures/task/expected/lib.ts @@ -80,6 +80,22 @@ export function drop$Held(_1: Held.Held): void { } } +export function drop$Key_Key(_1: [Key.Key, Key.Key]): void { + let unwind: number = 0; + try { + unwind = 4; + rt.drop(_1[0]); + unwind = 0; + rt.drop(_1[1]); + } catch (e) { + if (unwind === 0) { + throw e; + } + rt.drop(_1[1]); + throw e; + } +} + export function drop$Mutex_Held(value: rt.Mutex): void { drop$Held(value.value); } diff --git a/ts/fixtures/task/src/drops.rs b/ts/fixtures/task/src/drops.rs index b8c3e0cf5..ee0f183bf 100644 --- a/ts/fixtures/task/src/drops.rs +++ b/ts/fixtures/task/src/drops.rs @@ -47,17 +47,17 @@ pub struct Pair { second: Guard, } -/// Run scenario `arg % 13`, panicking at the point `arg / 13 % 8` names, if any: what +/// Run scenario `arg % 14`, panicking at the point `arg / 14 % 8` names, if any: what /// every value std holds drops, where Rust drops it, and in Rust's order. pub fn run(log: &Log, id: u32, arg: u8) { - let at = arg / 13 % 8; + let at = arg / 14 % 8; let guard = |n: u32| Guard::new(id + n, log.clone()); let check = |point: u8| { if point == at { panic!("d{id} at {point}"); } }; - match arg % 13 { + match arg % 14 { 4 => ordered(log, id, at), 5 => hashed(log, id, at), 6 => options(log, id, at), @@ -67,6 +67,7 @@ pub fn run(log: &Log, id: u32, arg: u8) { 10 => tripped(log, id, at, false), 11 => grown(log, id, at, true), 12 => grown(log, id, at, false), + 13 => edited(log, id, at), 0 => { let held = list![Held::One(guard(1)), Held::Empty, Held::Two(guard(2), guard(3))]; check(1); @@ -298,6 +299,15 @@ impl Hash for Key { } } +/// The same key, logged, unless it trips. +impl Clone for Key { + fn clone(&self) -> Self { + let id = self.read(); + self.log.note(format!("k{id} cloned")); + Self::faulty(id, self.log.clone(), self.fault) + } +} + impl std::fmt::Debug for Key { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("Key").field(&self.id).finish() @@ -729,3 +739,71 @@ fn grown(log: &Log, id: u32, at: u8, tree: bool) { } log.note(format!("unreached")); } + +/// What a `Vec`'s edits, its and a tuple's `clone`, and `Ord`'s defaults drop, scenario +/// `at`'s alone, and what is left to drop when a closure, a clone, a drop, or an index +/// panics partway. +fn edited(log: &Log, id: u32, at: u8) { + let key = |n: u32| Key::new(id + n, log.clone()); + let fault = |n: u32, fault: Fault| Key::faulty(id + n, log.clone(), fault); + let ids = |v: &[Key]| v.iter().map(|k| (k.id - id).to_string()).collect::>().join(","); + match at { + 0 => { + let mut v = list![key(1), key(2), key(3), key(4)]; + v.retain(|k| (k.id - id) % 2 == 1); + log.note(format!("retained {}", ids(&v))); + v.retain_mut(|k| k.id != id + 3); + log.note(format!("retained {}", ids(&v))); + return; + } + 1 => { + let mut v = list![key(1), key(2), key(3), key(4)]; + v.retain(|k| { + if k.id == id + 3 { + panic!("k{} retained", k.id); + } + k.id != id + 2 + }); + } + 2 => { + let mut v = list![key(1), key(1), key(2), key(2), key(3)]; + v.dedup(); + log.note(format!("deduped {}", ids(&v))); + v.dedup_by_key(|k| k.id / 2); + log.note(format!("deduped {}", ids(&v))); + v.dedup_by(|a, b| a.id > b.id); + log.note(format!("deduped {}", ids(&v))); + return; + } + 3 => { + let mut v = list![key(1), fault(1, Fault::Blows), key(1), key(2)]; + v.dedup(); + } + 4 => { + let mut v = list![key(1), key(2), key(3)]; + drop(v.swap_remove(0)); + log.note(format!("swapped {}", ids(&v))); + drop(v.swap_remove(3)); + } + 5 => { + let v = list![key(1), key(2)]; + log.note(format!("cloned {}", ids(&v.clone()))); + let tripped = list![key(1), fault(2, Fault::Trips), key(3)]; + drop(tripped.clone()); + } + 6 => { + let pair = (key(1), key(2)); + drop(pair.clone()); + let tripped = (key(1), fault(2, Fault::Trips)); + drop(tripped.clone()); + } + _ => { + log.note(format!("max {}", key(1).max(key(2)).id - id)); + log.note(format!("min {}", key(5).min(key(4)).id - id)); + log.note(format!("clamped {}", key(2).clamp(key(1), key(3)).id - id)); + log.note(format!("clamped {}", key(0).clamp(key(1), key(3)).id - id)); + drop(key(2).clamp(key(3), key(1))); + } + } + log.note(format!("unreached")); +} diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index d5e0e6d37..89fe129cf 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -272,6 +272,16 @@ export function boundMap(b: Bound, clone: (value: T) => T): Bound { return b.tag === "Unbounded" ? b : { tag: b.tag, _0: clone(b._0) }; } +/** `NonZero::new`: `n`, unless it is 0. */ +export function nonZero(n: T): T | undefined { + return n === 0 ? undefined : n; +} + +/** `reverse`, in place. */ +export function sliceReverse(s: T[]): void { + s.reverse(); +} + /** `last` and `last_mut`: the last element, or `undefined` if empty. */ export function sliceLast(s: ArrayLike): T | undefined { return s.length === 0 ? undefined : s[s.length - 1]; @@ -438,8 +448,8 @@ export function vecClone(s: ArrayLike, clone: (item: T) => T, drop?: (item } /** `Vec::extend_from_slice`: a clone of each element of `s`, pushed in order, as far as they clone. */ -export function vecExtendFromSlice(v: T[], s: ArrayLike, clone: (item: T) => T): void { - for (let i = 0; i < s.length; i++) v.push(clone(s[i])); +export function vecExtendFromSlice(v: T[], s: ArrayLike, clone?: (item: T) => T): void { + for (let i = 0; i < s.length; i++) v.push(clone === undefined ? s[i] : clone(s[i])); } /** diff --git a/ts/runtime/rt/iter.ts b/ts/runtime/rt/iter.ts index eb739dea5..f04e90072 100644 --- a/ts/runtime/rt/iter.ts +++ b/ts/runtime/rt/iter.ts @@ -8,7 +8,7 @@ // functions, `iterMap(it, f)`, so a bundler drops the ones nothing calls; an iterator's // methods are only what each kind does its own way. -import { ByteVec, byteVecPush, Err, Ok, panic, type Result } from "../rt.ts"; +import { type Bound, ByteVec, byteVecPush, Err, Ok, panic, type Result } from "../rt.ts"; import { type Limbs, lt as wideLt, type Step } from "./int.ts"; /** What `next` returns once an iterator is exhausted, which no item is. */ @@ -1139,19 +1139,18 @@ export class RangeInclusive extends Iter { this.int = int; } + /** std's: `start` steps past the item, so it passes `end`, and only wrapping exhausts it. */ next(): T | Done { if (rangeInclusiveIsEmpty(this)) return DONE; const lo = this.lo; - if (lt(lo, this.hi)) this.lo = step(lo, 1, this.int)!; - else this.exhausted = true; + [this.lo, this.exhausted] = stepOverflowing(lo, 1, this.int); return lo; } override nextBack(): T | Done { if (rangeInclusiveIsEmpty(this)) return DONE; const hi = this.hi; - if (lt(this.lo, hi)) this.hi = step(hi, -1, this.int)!; - else this.exhausted = true; + [this.hi, this.exhausted] = stepOverflowing(hi, -1, this.int); return hi; } @@ -1208,7 +1207,23 @@ export function rangeInclusiveClone(r: RangeInclusive): RangeInclusive return range; } +/** `RangeInclusive::start_bound`: its start, included. */ +export function rangeInclusiveStartBound(r: RangeInclusive): Bound { + return { tag: "Included", _0: r.lo }; +} + +/** `RangeInclusive::end_bound`: its end, included, until wrapping exhausts it and it excludes its start, as std's. */ +export function rangeInclusiveEndBound(r: RangeInclusive): Bound { + return r.exhausted ? { tag: "Excluded", _0: r.lo } : { tag: "Included", _0: r.hi }; +} + /** `Step::forward_overflowing` and `backward_overflowing`: `n + by`, wrapped within `int`, and whether it wrapped. */ +/** `Step::forward_overflowing` by `by`, of an integer type's step or a safe number's. */ +function stepOverflowing(n: T, by: number, int: Step | undefined): [T, boolean] { + if (int !== undefined) return int(n, by); + return [step(n, by, int)!, false]; +} + function overflowing(n: T, by: number, int: Step | undefined): [T, boolean] { if (int === undefined) throw new Error("rust2-ts: stepping a range of no integer type"); return int(n, by); diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 9d2f463f4..cf20641a4 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -233,7 +233,7 @@ fn lookup_ty<'tcx>(b: &Body<'_, '_, 'tcx>, std: Std, call: &Call<'tcx>, owner: & ( _, "get" | "get_mut" | "get_key_value" | "contains_key" | "contains" | "remove" | "remove_entry" | "take" - | "range" | "range_mut", + | "range" | "range_mut" | "split_off", ) => { let tcx = b.t.tcx; let imp = tcx.inherent_impl_of_assoc(call.def_id)?; @@ -549,6 +549,7 @@ fn btree<'tcx>( (_, "range") if set => Expr::rt("btreeRangeKeys", values), (_, "range" | "range_mut") => Expr::rt("btreeRange", values), (_, "entry") => Expr::rt("entry", values), + (_, "split_off") => Expr::rt("btreeSplitOff", values), ("Index", "index") => Expr::rt("btreeIndex", values), ("Clone", "clone") => { let k = clone_fn(b, key, span); @@ -858,7 +859,7 @@ fn arc_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { /// `Ord::cmp` of `ty` as a function, or `PartialOrd::partial_cmp` if `partial`: the /// runtime's for a std type, which calls the same of what it holds, or the crate's. -fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: Span) -> Expr { +pub fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: Span) -> Expr { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { @@ -893,7 +894,7 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S } /// `PartialEq::eq` of `ty`, as a function: the runtime's for a std type, or the crate's. -fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { +pub fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { let tcx = b.t.tcx; let ty = peel(b, ty); match ty.kind() { diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 2b7653a56..d72b01406 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -477,6 +477,8 @@ fn discards(owner: &str, name: &str) -> Option<&'static [usize]> { // `inspect_err` its error if its closure panics. ("Result", "unwrap" | "expect" | "inspect_err") => &[1], ("Result", "unwrap_err") => &[0], + // `Vec` drops each element `retain` rejects and `dedup` removes. + ("Vec", "retain" | "retain_mut" | "dedup" | "dedup_by" | "dedup_by_key") => &[0], // `then_some::` drops its value when false, and `then::` its function. ("bool", "then_some") => &[0], ("bool", "then") => &[1], @@ -598,7 +600,8 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec let e = match (owner.as_str(), name.as_str()) { // Conversions. ("From", "from") => { - let (to, from) = (targ(gargs, 0), targ(gargs, 1)); + // A `NonZero` converts as its integer. + let (to, from) = (targ(gargs, 0), unwrapped(tcx, targ(gargs, 1))); let mut values = args; let value = values.pop()?; // One between strings, such as into a `Cow` or out of one, keeps the text. @@ -663,7 +666,7 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ) } ("PartialEq", "eq" | "ne") | ("PartialOrd", "lt" | "le" | "gt" | "ge") - if primitive(scalar(tcx, targ(gargs, 0))) => + if primitive(unwrapped(tcx, targ(gargs, 0))) => { let js = match name.as_str() { "eq" => "===", @@ -675,12 +678,12 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec }; let values = args; let [l, r] = <[Expr; 2]>::try_from(values).ok()?; - match Int::of(scalar(tcx, targ(gargs, 0))) { + match Int::of(unwrapped(tcx, targ(gargs, 0))) { Some(int) => int.compare(js, l, r), None => l.binary(js, r), } } - ("Ord", "max" | "min") if let Some(int) = Int::of(scalar(tcx, targ(gargs, 0))) => { + ("Ord", "max" | "min") if let Some(int) = Int::of(unwrapped(tcx, targ(gargs, 0))) => { let values = args; match int.big() { true => int.method(name.as_str(), values), @@ -700,6 +703,18 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec Expr::rt("byteVecFrom", vec![Expr::rt("byteVecView", vec![value])]) } ty::Adt(..) if string(tcx, ty) => value, + ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Vec) => { + return vec_clone(b, value, args.type_at(0), span); + } + ty::Tuple(tys) if !(b.t.is_copy(ty) && clone_copies(b.t, ty)) => { + let mut clones = Vec::new(); + let mut drops = Vec::new(); + for t in tys.iter() { + clones.push(super::collections::clone_fn(b, t, span)); + drops.push(b.t.drop_fn(t, span).unwrap_or_else(Expr::undefined)); + } + Expr::rt("tupleClone", vec![value, Expr::Array(clones), Expr::Array(drops)]) + } // Through the reference, a slice of the bytes. _ if super::byte_array(ty) => Expr::rt("byteSliceToArray", vec![value]), ty::Adt(adt, _) if int_range(ty) => { @@ -767,6 +782,44 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec Expr::rt_of(of, &super::camel(&name)).call(args) } + // A `NonZero` is its integer. + ("NonZero", "get") => args.pop()?, + ("NonZero", "new") => Expr::rt("nonZero", args), + // `Bound<&T>::cloned::` and `copied`: what it holds, cloned. + ("Bound", "cloned" | "copied") => { + let value = args.pop()?; + let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); + let bound = tcx.instantiate_bound_regions_with_erased(sig).output(); + match super::collections::clone_fn(b, targ(gargs, 0), span) { + Expr::Lit(l) if l == "undefined" => b.t.copied(value, bound, span), + clone => Expr::rt("boundMap", vec![value, clone]), + } + } + ("Bound", "as_ref") => args.pop()?, + ("RangeBounds", "start_bound" | "end_bound") => { + let start = name == "start_bound"; + let range = targ(gargs, 0).peel_refs(); + let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); + let ts = b.t.ty(tcx.instantiate_bound_regions_with_erased(sig).output(), span); + let r = args.pop()?; + let (variant, field) = match (range.kind(), b.t.std_of(range)) { + // `(Bound, Bound)`, whose bounds are its own. + (ty::Tuple(_), _) => return Some(r.index(Expr::lit(if start { "0" } else { "1" }))), + (_, Some(Std::Range)) if start => ("Included", Some("start")), + (_, Some(Std::Range)) => ("Excluded", Some("end")), + (_, Some(Std::RangeFrom)) if start => ("Included", Some("start")), + (_, Some(Std::RangeTo)) if !start => ("Excluded", Some("end")), + (_, Some(Std::RangeToInclusive)) if !start => ("Included", Some("end")), + (_, Some(Std::RangeFrom | Std::RangeTo | Std::RangeToInclusive | Std::RangeFull)) => ("Unbounded", None), + // Exhausted, it ends before its end. + (_, Some(Std::RangeInclusive)) => { + let f = if start { "rangeInclusiveStartBound" } else { "rangeInclusiveEndBound" }; + return Some(Expr::As(Box::new(Expr::rt(f, vec![r])), ts)); + } + _ => return None, + }; + bound(variant, field.map(|f| r.member(f)), ts) + } ("bool", "then_some") => { let values = args; Expr::rt("thenSome", values) @@ -800,17 +853,46 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec } ("slice", "to_vec") => { let elem = targ(gargs, 0); - let values = args; + let slice = args.pop()?; + match is_u8(elem) { + true => Expr::rt("byteSliceToByteVec", vec![slice]), + false => return vec_clone(b, slice, elem, span), + } + } + ("slice", "first_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceFirst", args), + ("slice", "last" | "last_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceLast", args), + ("slice", "reverse") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceReverse", args), + ("slice", "swap") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceSwap", args), + ("slice", "contains") => { + let elem = targ(gargs, 0); + let [s, x] = <[Expr; 2]>::try_from(args).ok()?; match is_u8(elem) { - true => Expr::rt("byteSliceToByteVec", values), - false if b.t.is_copy(elem) => { - let slice = values.into_iter().next()?; - match b.t.copy_fn(elem, span) { - Some(copy) => slice.member("map").call(vec![copy]), - None => slice.member("slice").call(Vec::new()), + true => Expr::rt("byteSliceView", vec![s]).method("includes", vec![x]), + false => { + let eq = super::collections::eq_fn(b, elem, span); + Expr::rt("sliceContains", vec![s, x, eq]) + } + } + } + // Sorted by `lt` of `Ord`, or by a comparator, or by `lt` of the keys a function makes. + ("slice", "sort" | "sort_unstable" | "sort_by" | "sort_unstable_by" | "sort_by_key" | "sort_unstable_by_key") + if !is_u8(targ(gargs, 0)) => + { + let mut values = args; + match name.as_str() { + "sort" | "sort_unstable" => { + values.push(super::collections::cmp_fn(b, targ(gargs, 0), true, span)); + Expr::rt("sliceSortBy", values) + } + "sort_by" | "sort_unstable_by" => Expr::rt("sliceSortBy", values), + _ => { + let key = targ(gargs, 1); + if b.t.drops(key) { + return Some(b.err(span, format!("`slice::{name}` by `{key}`, which drops, which is not supported yet"))); } + values.push(super::collections::cmp_fn(b, key, true, span)); + Expr::rt("sliceSortByKey", values) } - false => return None, } } // A boxed slice's elements, and `vec![a, b]`'s array once `mir::vec` took the box @@ -879,6 +961,42 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ("Vec", "truncate") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecTruncate", args), ("Vec", "clear") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecClear", args), ("Vec", "extend_from_slice") if is_u8(targ(gargs, 0)) => Expr::rt("byteVecExtendFromSlice", args), + ("Vec", "extend_from_slice") => { + let mut values = args; + let clone = super::collections::clone_fn(b, targ(gargs, 0), span); + if !matches!(&clone, Expr::Lit(l) if l == "undefined") { + values.push(clone); + } + Expr::rt("vecExtendFromSlice", values) + } + ("Vec", "swap_remove") if !is_u8(targ(gargs, 0)) => Expr::rt("vecSwapRemove", args), + // What each takes by value is a closure, which it drops once done. + ("Vec", "retain" | "retain_mut" | "dedup" | "dedup_by" | "dedup_by_key") if !is_u8(targ(gargs, 0)) => { + if let Some(ty) = dropping_operand(b, call) { + return Some(b.err( + span, + format!("passing `{ty}`, which drops, to `{owner}::{name}`, which is not supported yet"), + )); + } + let mut values = args; + match name.as_str() { + "retain" | "retain_mut" => Expr::rt("vecRetain", values), + "dedup" => { + values.push(super::collections::eq_fn(b, targ(gargs, 0), span)); + Expr::rt("vecDedupBy", values) + } + "dedup_by" => Expr::rt("vecDedupBy", values), + _ => { + // `Vec::dedup_by_key::`. + let key = targ(gargs, 3); + if b.t.drops(key) { + return Some(b.err(span, format!("`Vec::dedup_by_key` by `{key}`, which drops, which is not supported yet"))); + } + values.push(super::collections::eq_fn(b, key, span)); + Expr::rt("vecDedupByKey", values) + } + } + } ("Vec", "as_slice" | "as_mut_slice") => { let v = args.pop()?; vec_view(v, targ(gargs, 0)) @@ -905,8 +1023,10 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ("String", "new") => Expr::Str(String::new()), ("String" | "str", "is_empty") => args.pop()?.member("length").binary("===", Expr::lit("0")), ("str", "chars") => Expr::rt("strChars", args), + ("str", "bytes") => Expr::rt("strBytes", args), + ("str", "is_char_boundary") => Expr::rt("strIsCharBoundary", args), // Searches by a pattern. - ("str", "split" | "match_indices" | "contains" | "starts_with" | "rfind") + ("str", "split" | "match_indices" | "contains" | "starts_with" | "ends_with" | "rfind" | "split_once") | ("str", "trim_start_matches" | "trim_end_matches") => { let [s, p] = <[Expr; 2]>::try_from(args).ok()?; Expr::rt_of("str", &super::camel(&name)).call(vec![s, pattern(b.t, targ(gargs, 0), p)?]) @@ -1101,13 +1221,35 @@ fn owned<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, ty: Ty<'tcx>, span: Span } } -/// A `str` method's pattern as the runtime takes it, an `rt.Pattern`: a `char`'s text, -/// or a string or a predicate as it is. `None` for any other pattern. +/// A clone of `value`, a slice, array, or `Vec` of `elem` other than bytes, as a `Vec`: a +/// copy of the array if each element's clone is itself or a copy, or else each element +/// cloned, the clones dropping if one panics. +fn vec_clone<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, elem: Ty<'tcx>, span: Span) -> Option { + let clone = super::collections::clone_fn(b, elem, span); + if matches!(&clone, Expr::Lit(l) if l == "undefined") { + return Some(value.method("slice", Vec::new())); + } + if b.t.is_copy(elem) && clone_copies(b.t, elem) { + return Some(value.method("map", vec![clone])); + } + let mut values = vec![value, clone]; + values.extend(b.t.drop_fn(elem, span)); + Some(Expr::rt("vecClone", values)) +} + +/// A `str` method's pattern as the runtime takes it, an `rt.Pattern`: a `char`'s text, a +/// string or a predicate as it is, or a predicate for an array or slice of chars. `None` +/// for any other pattern. fn pattern<'tcx>(t: &Translator<'_, 'tcx>, ty: Ty<'tcx>, p: Expr) -> Option { match ty.kind() { ty::Char => Some(char_text(p)), ty::Closure(..) | ty::FnDef(..) => Some(p), ty::Ref(..) if is_text(t, ty) => Some(p), + // Any of the chars of an array or slice. + ty::Array(c, _) | ty::Slice(c) if c.is_char() => Some(Expr::rt("patternChars", vec![p])), + ty::Ref(_, inner, _) if matches!(inner.kind(), ty::Array(c, _) | ty::Slice(c) if c.is_char()) => { + Some(Expr::rt("patternChars", vec![p])) + } _ => None, } } @@ -1162,7 +1304,7 @@ fn int_named(name: &str) -> Option { } /// What a JS value of `ty` is through references and `NonZero`, which is its integer. -fn scalar<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { +fn unwrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = ty.peel_refs(); match ty.kind() { ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::NonZero) => args.type_at(0), diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index cde8f76db..dee85da27 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -340,9 +340,18 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let done = |e: Expr, effect: bool| Some(Some((e, effect))); match (owner.as_str(), name.as_str()) { // Replacing what a `&mut` borrows. + // What `Default::default` makes, a std type's or the crate's, before the swap. ("mem", "take") => { + let ty = targ(0)?; let place = self.borrowed_place(&args[0].node, span)?; - let default = library::default_value(self.b, targ(0)?)?; + let default = match library::default_value(self.b, ty) { + Some(default) => default, + None => { + let f = crate::lower::collections::trait_fn(tcx, "Default", "default"); + let default = self.b.call_def(f, tcx.mk_args(&[ty.into()]), Vec::new(), span, out); + self.path(default, "default", out) + } + }; done(self.swap_out(place, default, "taken", span, out), true) } ("mem", "replace") => { diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index d81163749..237268e10 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -837,6 +837,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Uint(ty::UintTy::U8) => Some(ObjectKind::Bytes), _ => Some(ObjectKind::Array), }, + // A JS array, whose elements change in place as an array's do. + ty::Tuple(tys) if !tys.is_empty() => Some(ObjectKind::Array), ty::Adt(adt, _) => match library::Std::of(self.tcx, adt.did()) { Some(library::Std::Vec) => Some(ObjectKind::Vec), Some( diff --git a/ts/src/ts.rs b/ts/src/ts.rs index 8198ba1bb..9c5e35df3 100644 --- a/ts/src/ts.rs +++ b/ts/src/ts.rs @@ -125,8 +125,14 @@ impl Expr { /// This without an outer `as`, where the context already gives the type. pub fn typed(self) -> Self { match self { - // Limbs keep theirs, which the brand of their type requires. - Self::As(e, ty) if matches!(*e, Self::Str(_) | Self::Array(_) | Self::Object(_)) && !wide(&ty) => *e, + // Limbs keep theirs, which the brand of their type requires, and an `rt.Bound` its + // own, without which a declaration narrows to the one variant it is made as. + Self::As(e, ty) + if matches!(*e, Self::Str(_) | Self::Array(_) | Self::Object(_)) + && !wide(&ty) && !matches!(ty, Type::Rt("Bound", _)) => + { + *e + } Self::Located(loc, e) => Self::Located(loc, Box::new(e.typed())), // `rt.Ok(v)` and `rt.Err(e)` infer their type from the context too. Self::Call(f, args) if matches!(&*f, Self::Rt(name) if name == "Ok" || name == "Err") => { diff --git a/ts/tests/retain.ts b/ts/tests/retain.ts index e8f8179ff..99c215f2a 100644 --- a/ts/tests/retain.ts +++ b/ts/tests/retain.ts @@ -35,9 +35,45 @@ for (let n = 0; n <= 6; n++) { for (let i = n >> 1; i < n; i++) rt.dequePushBack(deque, i); caught(() => rt.dequeRetain(deque, keep)); + const vec = [...Array(n).keys()]; + const dropped: number[] = []; + caught(() => rt.vecRetain(vec, keep, (i) => dropped.push(i))); + + // A run ends at each item the mask clears, and `same` panics comparing `p`. + const runs: [number, number][] = []; + for (let i = 0, run = 0; i < n; i++) runs.push([i, ((mask >> i) & 1) === 1 ? run : ++run]); + const deduped: number[] = []; + caught(() => + rt.vecDedupBy( + runs, + (a, b) => { + if (a[0] === p) throw new Thrown(); + return a[1] === b[1]; + }, + (r) => deduped.push(r[0]), + ), + ); + const entries = rt.iterToArray(rt.btreeIter(tree)); const items = rt.iterToArray(rt.dequeIter(deque)); - console.log(`${n} ${mask} ${p} btree ${entries.join(";")} deque ${items.join(",")}`); + const ran = runs.map((r) => r[0]); + console.log( + `${n} ${mask} ${p} btree ${entries.join(";")} deque ${items.join(",")} vec ${vec.join(",")} dropped ${dropped.join(",")} dedup ${ran.join(",")} dropped ${deduped.join(",")}`, + ); + + // A sort whose comparator panics at its `2p`th call leaves each item once. + const sorted = [...Array(n).keys()].map((i) => (i * 5 + mask) % 7); + let calls = 0; + caught(() => + rt.sliceSortBy(sorted, (a, b) => { + if (calls++ === p * 2) throw new Thrown(); + return rt.cmp(a, b); + }), + ); + const unsorted = [...Array(n).keys()].map((i) => (i * 5 + mask) % 7); + if (sorted.slice().sort().join() !== unsorted.sort().join()) { + throw new Error(`sort of ${n} by ${mask} panicking at ${p}: ${sorted}`); + } // Keys that collide by twos, so `retain` unlinks within chains. type Key = { k: number }; diff --git a/ts/tests/runtime.rs b/ts/tests/runtime.rs index c79761277..a34a72359 100644 --- a/ts/tests/runtime.rs +++ b/ts/tests/runtime.rs @@ -117,8 +117,18 @@ fn btree_script() { assert_eq!(got.lines().count(), want.len()); } -/// A `retain` whose predicate panics leaves a B-tree and a deque as std's do, which -/// `retain.ts` prints for every keep mask of up to 6 items and each item to panic on. +/// A value that logs itself when it drops. +struct Logged<'a, T: Copy>(T, &'a std::cell::RefCell>); + +impl Drop for Logged<'_, T> { + fn drop(&mut self) { + self.1.borrow_mut().push(self.0); + } +} + +/// A `retain` whose predicate panics leaves a B-tree, a deque, and a `Vec` as std's do, +/// and a `dedup_by` whose test panics leaves a `Vec`, each dropping what std's drops, +/// which `retain.ts` prints for every keep mask of up to 6 items and each item to panic on. #[test] fn retain_unwinds() { use std::collections::{BTreeMap, VecDeque}; @@ -152,9 +162,42 @@ fn retain_unwinds() { } deque.extend(n / 2..n); let _ = catch_unwind(AssertUnwindSafe(|| deque.retain(|&i| keep(i)))); + let dropped = std::cell::RefCell::new(Vec::new()); + let mut vec: Vec> = (0..n).map(|i| Logged(i, &dropped)).collect(); + let _ = catch_unwind(AssertUnwindSafe(|| vec.retain(|i| keep(i.0)))); + let vec: Vec = vec.iter().map(|i| i.0).collect(); + let dropped = std::mem::take(&mut *dropped.borrow_mut()); + // A run ends at each item the mask clears, and `same` panics comparing `p`. + let deduped = std::cell::RefCell::new(Vec::new()); + let mut run = 0; + let mut runs: Vec> = (0..n) + .map(|i| { + if (mask >> i) & 1 == 0 { + run += 1; + } + Logged((i, run), &deduped) + }) + .collect(); + let _ = catch_unwind(AssertUnwindSafe(|| { + runs.dedup_by(|a, b| { + assert!(a.0.0 != p); + a.0.1 == b.0.1 + }) + })); + let ran: Vec = runs.iter().map(|r| r.0.0).collect(); + let deduped: Vec = std::mem::take(&mut *deduped.borrow_mut()).into_iter().map(|r| r.0).collect(); let entries: Vec = tree.iter().map(|(k, v)| format!("{k},{v}")).collect(); let items: Vec = deque.iter().map(u32::to_string).collect(); - want += &format!("{n} {mask} {p} btree {} deque {}\n", entries.join(";"), items.join(",")); + let join = |v: &[u32]| v.iter().map(u32::to_string).collect::>().join(","); + want += &format!( + "{n} {mask} {p} btree {} deque {} vec {} dropped {} dedup {} dropped {}\n", + entries.join(";"), + items.join(","), + join(&vec), + join(&dropped), + join(&ran), + join(&deduped), + ); } } } diff --git a/ts/tests/task.ts b/ts/tests/task.ts index e00a5d77e..531a24839 100644 --- a/ts/tests/task.ts +++ b/ts/tests/task.ts @@ -281,5 +281,5 @@ export const cases: Uint8Array[] = [ [0, 0, 12, 0, 6, 0, 3, 5, 6, 0], [0, 0, 12, 0, 12, 1, 6, 0, 9, 1, 9, 0], // Each scenario of values std holds that drop, panicking at each point or none. - ...Array.from({ length: 104 }, (_, arg) => [11, arg]), + ...Array.from({ length: 112 }, (_, arg) => [11, arg]), ].map((script) => Uint8Array.from(script)); From f1f19efcd413fbbe6b091d4e27d02b18c843fef1 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:34:38 -0700 Subject: [PATCH 05/11] wip(ts): move now-translated reject cases into lang Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/expected/edits.ts | 24 ++-- ts/fixtures/lang/expected/lib.ts | 4 + ts/fixtures/lang/expected/wrappers.ts | 93 ++++++++-------- ts/fixtures/lang/src/edits.rs | 9 +- ts/fixtures/lang/src/lib.rs | 2 +- ts/fixtures/lang/src/wrappers.rs | 10 ++ ts/fixtures/reject/census.md | 153 ++++++++++++-------------- ts/fixtures/reject/expected.txt | 43 ++++---- ts/fixtures/reject/src/lib.rs | 11 -- ts/fixtures/reject/ts.toml | 2 - ts/src/lower/collections.rs | 14 ++- ts/src/lower/library.rs | 27 +++-- ts/src/lower/mir/place.rs | 5 +- ts/src/ts.rs | 3 +- ts/tests/runtime.rs | 5 +- 15 files changed, 214 insertions(+), 191 deletions(-) diff --git a/ts/fixtures/lang/expected/edits.ts b/ts/fixtures/lang/expected/edits.ts index 60911c7e5..9828637cb 100644 --- a/ts/fixtures/lang/expected/edits.ts +++ b/ts/fixtures/lang/expected/edits.ts @@ -1,6 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; +import { copy$chars } from "./lib.ts"; import * as Named from "./edits.Named.ts"; import * as Stamp from "./edits.Stamp.ts"; import * as Tally from "./edits.Tally.ts"; @@ -260,32 +261,33 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const sep: rt.char[] = [47, 97]; rt.byteVecPush(out, rt.strContains(s, rt.patternChars(sep)) ? 1 : 0); rt.byteVecPush(out, rt.strContains(s, rt.patternChars(rt.sliceRange(sep, 0))) ? 1 : 0); + rt.byteVecPush(out, rt.iterCount(rt.strSplit(s, rt.patternChars(copy$chars(sep)))) & 0xff); rt.byteVecPush(out, rt.strEndsWith(s, "/") ? 1 : 0); rt.byteVecPush(out, rt.strEndsWith(s, "😀") ? 1 : 0); rt.byteVecPush(out, rt.strEndsWith(s, (c: rt.char): boolean => { return rt.charIsAsciiDigit(c); }) ? 1 : 0); - const _581: [string, string] | undefined = rt.strSplitOnce(s, "/"); - if (_581 === undefined) { + const _587: [string, string] | undefined = rt.strSplitOnce(s, "/"); + if (_587 === undefined) { rt.byteVecPush(out, 253); } else { - put(out, _581[0]); - put(out, _581[1]); + put(out, _587[0]); + put(out, _587[1]); } - const _590: [string, string] | undefined = rt.strSplitOnce(s, "a0"); - if (_590 === undefined) { + const _596: [string, string] | undefined = rt.strSplitOnce(s, "a0"); + if (_596 === undefined) { rt.byteVecPush(out, 253); } else { - put(out, _590[0]); - put(out, _590[1]); + put(out, _596[0]); + put(out, _596[1]); } const iter10: rt.RangeInclusive = new rt.RangeInclusive(0, rt.usizeAdd(rt.stringLen(s), 1), rt.usizeStep); while (true) { - const _605: rt.usize | rt.Done = iter10.next(); - if (_605 === rt.DONE) { + const _611: rt.usize | rt.Done = iter10.next(); + if (_611 === rt.DONE) { break; } - rt.byteVecPush(out, rt.strIsCharBoundary(s, _605) ? 1 : 0); + rt.byteVecPush(out, rt.strIsCharBoundary(s, _611) ? 1 : 0); } rt.iterExtendBytes(out, rt.strBytes(s)); rt.iterExtendBytes(out, rt.iterTake(rt.iterRev(rt.strBytes(s)), 3)); diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index 47e98794d..fc3ee8eb7 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -135,6 +135,10 @@ export function copy$Wrap_u8(v: Wrap.Wrap): Wrap.Wrap { return new Wrap.Wrap({ value: v.value, count: v.count }); } +export function copy$chars(v: rt.char[]): rt.char[] { + return v.slice(); +} + export function copy$u8_Horizon(v: [rt.u8, Horizon.Horizon]): [rt.u8, Horizon.Horizon] { return [v[0], copy$Horizon(v[1])]; } diff --git a/ts/fixtures/lang/expected/wrappers.ts b/ts/fixtures/lang/expected/wrappers.ts index 4797f9123..9b36d71ee 100644 --- a/ts/fixtures/lang/expected/wrappers.ts +++ b/ts/fixtures/lang/expected/wrappers.ts @@ -291,73 +291,80 @@ export function wrappers(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void const held: [rt.Bound, rt.Bound] = [boundOf(at(3), b), { tag: "Unbounded" } as rt.Bound]; bounds$Bound_u64_Bound_u64(out, held); putBound(out, held[0]); + const _87: [{ end: rt.usize }, { start: rt.usize }] = [{ end: rt.usizeRem(at(2) as rt.usize, rt.usizeAdd(data.length, 1)) }, { start: rt.usizeRem(at(3) as rt.usize, rt.usizeAdd(data.length, 1)) }]; + const to: { end: rt.usize } = _87[0]; + const from: { start: rt.usize } = _87[1]; + putU64(out, rt.usizeAdd(to.end, from.start) as rt.u64); + putU64(out, b); + rt.byteVecPush(out, rt.byteSliceRange(data, 0, to.end).length & 0xff); + rt.byteVecPush(out, rt.byteSliceRange(data, from.start).length & 0xff); } else if (_21 === 1) { const map: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; const iter: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))); while (true) { - const _90: [rt.usize, rt.u8] | rt.Done = iter.next(); - if (_90 === rt.DONE) { + const _132: [rt.usize, rt.u8] | rt.Done = iter.next(); + if (_132 === rt.DONE) { break; } - rt.btreeInsert(map, _90[1] as rt.u64, _90[0] as rt.u64); + rt.btreeInsert(map, _132[1] as rt.u64, _132[0] as rt.u64); } - const _101: [rt.u64, rt.u64] = [at(0) as rt.u64, at(1) as rt.u64]; - const a2: rt.u64 = _101[0]; - const b2: rt.u64 = _101[1]; + const _143: [rt.u64, rt.u64] = [at(0) as rt.u64, at(1) as rt.u64]; + const a2: rt.u64 = _143[0]; + const b2: rt.u64 = _143[1]; const iter2: rt.Iter<[rt.u64, rt.u64]> = rt.btreeRange(map, { end: a2, inclusive: true }); while (true) { - const _115: [rt.u64, rt.u64] | rt.Done = iter2.next(); - if (_115 === rt.DONE) { + const _157: [rt.u64, rt.u64] | rt.Done = iter2.next(); + if (_157 === rt.DONE) { break; } - putU64(out, _115[0]); - putU64(out, _115[1]); + putU64(out, _157[0]); + putU64(out, _157[1]); } rt.byteVecPush(out, 254); - const _125: [rt.u64, rt.u64] | undefined = rt.iterToOption(rt.btreeRange(map, { end: b2, inclusive: true }).nextBack()); - if (_125 !== undefined) { - putU64(out, _125[0]); + const _167: [rt.u64, rt.u64] | undefined = rt.iterToOption(rt.btreeRange(map, { end: b2, inclusive: true }).nextBack()); + if (_167 !== undefined) { + putU64(out, _167[0]); } rt.byteVecPush(out, rt.iterCount(rt.btreeRange(map, { end: a2 })) & 0xff); const above: rt.BTreeMap = rt.btreeSplitOff(map, b2); const iter3: rt.Iter<[rt.u64, rt.u64]> = rt.iterChain(rt.btreeIter(map), rt.btreeIter(above)); while (true) { - const _150: [rt.u64, rt.u64] | rt.Done = iter3.next(); - if (_150 === rt.DONE) { + const _192: [rt.u64, rt.u64] | rt.Done = iter3.next(); + if (_192 === rt.DONE) { break; } - putU64(out, _150[0]); - putU64(out, _150[1]); + putU64(out, _192[0]); + putU64(out, _192[1]); } rt.byteVecPush(out, rt.btreeLen(map) & 0xff); rt.byteVecPush(out, rt.btreeLen(above) & 0xff); - const _168: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); - const set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _168, true); - const _173: rt.u8 = at(2); - const high: rt.BTreeSet = rt.btreeSplitOff(set, _173); + const _210: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const set: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _210, true); + const _215: rt.u8 = at(2); + const high: rt.BTreeSet = rt.btreeSplitOff(set, _215); rt.iterExtendBytes(out, rt.iterChain(rt.btreeKeys(set), rt.btreeKeys(high))); rt.byteVecPush(out, rt.btreeLen(high) & 0xff); } else if (_21 === 2) { - const _188: [rt.u8, rt.u8] = [at(0), at(1)]; - const x2: rt.u8 = _188[0]; - const y: rt.u8 = _188[1]; + const _230: [rt.u8, rt.u8] = [at(0), at(1)]; + const x2: rt.u8 = _230[0]; + const y: rt.u8 = _230[1]; rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) & 0xff); rt.byteVecPush(out, rt.cmpReverse(rt.cmp)(x2, y) === -1 ? 1 : 0); rt.byteVecPush(out, rt.cmpReverse(rt.cmpOption(rt.cmp))(x2, undefined) === 1 ? 1 : 0); rt.byteVecPush(out, rt.ordMax(x2, y, rt.cmpReverse(rt.cmp))); const order = rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])([x2, y] as [rt.u8, rt.u8], [y, x2] as [rt.u8, rt.u8]); rt.byteVecPush(out, order !== undefined && order <= 0 ? 1 : 0); - const _232: rt.Iter<[rt.u8, rt.usize]> = rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_2: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { + const _274: rt.Iter<[rt.u8, rt.usize]> = rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_2: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { return [_2[1], _2[0]] as [rt.u8, rt.usize]; }); - const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmpReverse(rt.cmp)) as rt.BTreeMap, _232, true)); + const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmpReverse(rt.cmp)) as rt.BTreeMap, _274, true)); while (true) { - const _238: [rt.u8, rt.usize] | rt.Done = iter4.next(); - if (_238 === rt.DONE) { + const _280: [rt.u8, rt.usize] | rt.Done = iter4.next(); + if (_280 === rt.DONE) { break; } - rt.byteVecPush(out, _238[0]); - rt.byteVecPush(out, _238[1] & 0xff); + rt.byteVecPush(out, _280[0]); + rt.byteVecPush(out, _280[1] & 0xff); } const ranked: [rt.u8, rt.usize][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_23: [rt.usize, rt.u8]): [rt.u8, rt.usize] => { return [_23[1], _23[0]] as [rt.u8, rt.usize]; @@ -365,9 +372,9 @@ export function wrappers(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void rt.sliceSortByKey(ranked, (_25: [rt.u8, rt.usize]): [rt.u8, rt.usize] => { return [rt.u8Rem(_25[0], 4), _25[1]] as [rt.u8, rt.usize]; }, rt.cmpTuple([rt.cmpReverse(rt.cmp), rt.cmp])); - for (const _258 of ranked) { - const d: rt.u8 = _258[0]; - const i2: rt.usize = _258[1]; + for (const _300 of ranked) { + const d: rt.u8 = _300[0]; + const i2: rt.usize = _300[1]; rt.byteVecPush(out, d); rt.byteVecPush(out, i2 & 0xff); } @@ -380,28 +387,28 @@ export function wrappers(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void const n2: rt.u64 = n; putU64(out, n2); putU64(out, n2); - const _290: rt.u64 = rt.optionUnwrapOr(rt.nonZero(b), n2); - const _287: boolean = rt.u64Eq(n2, _290); - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.fmtBool(_287, f)]; + const _332: rt.u64 = rt.optionUnwrapOr(rt.nonZero(b), n2); + const _329: boolean = rt.u64Eq(n2, _332); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.u64Display(n2, f), (f: rt.Formatter) => rt.fmtBool(_329, f)]; put(out, rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2]])); rt.byteVecPush(out, rt.u64Gt(n2, { _0: 1 }._0) ? 1 : 0); rt.byteVecPush(out, rt.cmp(n2, { _0: 1000 }._0) & 0xff); } rt.byteVecPush(out, rt.nonZero(rt.u64And(a, 1)) !== undefined ? 1 : 0); } else { - const _317: rt.u64 | undefined = rt.nonZero(a); + const _359: rt.u64 | undefined = rt.nonZero(a); b1: { - if (_317 !== undefined) { + if (_359 !== undefined) { if (rt.u8Rem(at(2), 2) === 0) { - scale = { _0: _317 }; + scale = { _0: _359 }; break b1; } } - const _328: rt.usize = rt.usizeRem(at(3) as rt.usize, 3); - if (!(_328 < 3)) { - rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _328); + const _370: rt.usize = rt.usizeRem(at(3) as rt.usize, 3); + if (!(_370 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _370); } - scale = [{ _0: 1 }, { _0: 1000 }, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }][_328]; + scale = [{ _0: 1 }, { _0: 1000 }, { _0: { hi: 0xffffffff, lo: 0xffffffff } as rt.u64 }][_370]; } if (!rt.u64Eq(1, scale._0)) { if (!rt.u64Eq(1000, scale._0)) { diff --git a/ts/fixtures/lang/src/edits.rs b/ts/fixtures/lang/src/edits.rs index eddcaec53..47c6bf964 100644 --- a/ts/fixtures/lang/src/edits.rs +++ b/ts/fixtures/lang/src/edits.rs @@ -129,7 +129,8 @@ pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { put_u16s(out, &[*a, *b]); } // `None` first, as `Option`'s `Ord` puts it. - let mut options: Vec> = words.iter().map(|&w| if w % 2 == 0 { None } else { Some(w) }).collect(); + let mut options: Vec> = + words.iter().map(|&w| if w % 2 == 0 { None } else { Some(w) }).collect(); options.sort_unstable(); for o in &options { put_u16s(out, &[o.map_or(0xffff, |o| o)]); @@ -198,7 +199,10 @@ pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { out.push((changed < named) as u8); changed.extend_from_slice(&named[..named.len() / 2]); out.push(changed.len() as u8); - let nested: Vec> = data.iter().map(|&b| (0..b % 3).map(|i| i as u16 + b as u16).collect()).collect(); + let nested: Vec> = data + .iter() + .map(|&b| (0..b % 3).map(|i| i as u16 + b as u16).collect()) + .collect(); out.push((nested.clone() == nested) as u8); let pair = (text(data), at(0)); let copy = pair.clone(); @@ -237,6 +241,7 @@ pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { let sep = ['/', 'a']; out.push(s.contains(sep) as u8); out.push(s.contains(&sep[..]) as u8); + out.push(s.split(sep).count() as u8); out.push(s.ends_with("/") as u8); out.push(s.ends_with('😀') as u8); out.push(s.ends_with(|c: char| c.is_ascii_digit()) as u8); diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index e69badced..c37779341 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -19,9 +19,9 @@ mod iters; mod keys; mod shapes; mod strs; -mod wrappers; #[cfg(target_arch = "wasm32")] #[path = "../../wasm.rs"] mod wasm; +mod wrappers; #[cfg(target_arch = "wasm32")] use harness::entry; diff --git a/ts/fixtures/lang/src/wrappers.rs b/ts/fixtures/lang/src/wrappers.rs index a859db911..0c7d74bd0 100644 --- a/ts/fixtures/lang/src/wrappers.rs +++ b/ts/fixtures/lang/src/wrappers.rs @@ -99,6 +99,16 @@ pub fn wrappers(kind: u8, data: &[u8], out: &mut Vec) { let held = (bound_of(at(3), b), Bound::Unbounded); bounds(out, held); put_bound(out, held.0.as_ref()); + // Each one-sided range's field, read and through struct update syntax. + let (to, from) = ( + ..(at(2) as usize % (data.len() + 1)), + (at(3) as usize % (data.len() + 1)).., + ); + let through = ..=b; + put_u64(out, (to.end + from.start) as u64); + put_u64(out, through.end); + out.push(data[std::ops::RangeTo { ..to }].len() as u8); + out.push(data[std::ops::RangeFrom { ..from }].len() as u8); } 1 => { let mut map = BTreeMap::new(); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 729903712..f1bb78c9d 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,24 +1,23 @@ # Census of `reject-fixture` -- Refusals: 86 -- Function instances: 67 +- Refusals: 83 +- Function instances: 65 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 8 | unsupported call to `_` | fixtures/reject/src/lib.rs:33:4 | | 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:17:2 | +| 7 | unsupported call to `_` | fixtures/reject/src/lib.rs:33:4 | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:28:15 | | 6 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:16:13 | | 5 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:56:2 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:405:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:394:2 | | 4 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:108:2 | | 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:128:20 | | 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:280:16 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:296:7 | | 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:187:1 | | 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:173:23 | | 2 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:51:1 | @@ -27,15 +26,15 @@ | 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:87:3 | | 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:86:3 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:90:3 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:301:6 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:416:18 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:324:6 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:356:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:366:6 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:332:9 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:296:6 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:405:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:319:6 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:351:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:361:6 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:327:9 | | 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:119:2 | | 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:200:51 | -| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:379:2 | +| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:374:2 | | 1 | a constant of type `_` | fixtures/reject/src/lib.rs:103:2 | | 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:290:14 | | 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:259:13 | @@ -45,9 +44,9 @@ | 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:89:3 | | 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:75:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:306:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:423:53 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:306:52 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:301:52 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:412:53 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:301:52 | | 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:88:3 | | 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:83:3 | | 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:84:3 | @@ -58,7 +57,7 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:405:2 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:394:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:28:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | | 6 | `u8` | fixtures/reject/src/lib.rs:65:10 | @@ -69,16 +68,16 @@ The type or module each refused type or path belongs to. | 2 | `Iterator` | fixtures/reject/src/lib.rs:167:2 | | 2 | `Meters` | fixtures/reject/src/lib.rs:108:2 | | 2 | `Poll` | fixtures/reject/src/lib.rs:128:20 | -| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:301:6 | +| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:296:6 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:280:16 | -| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:301:6 | +| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:296:6 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | | 2 | `std::slice` | fixtures/reject/src/lib.rs:33:4 | -| 2 | `{closure}` | fixtures/reject/src/lib.rs:398:15 | +| 2 | `{closure}` | fixtures/reject/src/lib.rs:387:15 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | | 1 | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | -| 1 | `HashMap` | fixtures/reject/src/lib.rs:324:6 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:332:9 | +| 1 | `HashMap` | fixtures/reject/src/lib.rs:319:6 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:327:9 | | 1 | `IntToFloat` | fixtures/reject/src/lib.rs:119:2 | | 1 | `Noisy` | fixtures/reject/src/lib.rs:254:20 | | 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:273:22 | @@ -87,11 +86,8 @@ The type or module each refused type or path belongs to. | 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | | 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | | 1 | `std::mem` | fixtures/reject/src/lib.rs:49:18 | -| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:296:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:296:7 | | 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:208:8 | | 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:154:11 | -| 1 | `std::str` | fixtures/reject/src/lib.rs:390:4 | | 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | | 1 | `u64` | fixtures/reject/src/lib.rs:119:2 | | 1 | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | @@ -101,7 +97,7 @@ The type or module each refused type or path belongs to. | Count | Construct | Type or path | First | | ---: | --- | --- | --- | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:28:15 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:405:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:394:2 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:128:20 | | 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:95:16 | @@ -110,22 +106,20 @@ The type or module each refused type or path belongs to. | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | | 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:66:3 | | 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | -| 2 | an iterator that owns `_`, which drops, which is not supported yet | `{closure}` | fixtures/reject/src/lib.rs:398:15 | +| 2 | an iterator that owns `_`, which drops, which is not supported yet | `{closure}` | fixtures/reject/src/lib.rs:387:15 | | 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:108:2 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:301:6 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:416:18 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:324:6 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:296:6 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:405:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:319:6 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:280:38 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:280:16 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:356:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:366:6 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:332:9 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:351:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:361:6 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:327:9 | | 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:119:2 | | 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:200:51 | -| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:379:2 | +| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:374:2 | | 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:103:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:296:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:296:7 | | 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:259:13 | | 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | @@ -136,40 +130,26 @@ The type or module each refused type or path belongs to. | 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | | 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:254:20 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:306:52 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:423:53 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:301:52 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:412:53 | | 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | | 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:306:52 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:301:52 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:167:2 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:221:2 | | 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:273:22 | -| 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:384:4 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:417:2 | +| 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:379:4 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:406:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:154:11 | | 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:97:10 | | 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:49:18 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:208:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:374:4 | +| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:369:4 | | 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:33:4 | -| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:390:4 | | 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | ## Spans -
unsupported call to `_` (8) - -- fixtures/reject/src/lib.rs:33:4: unsupported call to `std::slice::::sort` -- fixtures/reject/src/lib.rs:49:18: unsupported call to `std::mem::size_of_val::` -- fixtures/reject/src/lib.rs:97:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:154:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:208:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:374:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:390:4: unsupported call to `core::str::::split::<[char; 2]>` -- fixtures/reject/src/lib.rs:417:2: unsupported call to ` as std::ops::Deref>::deref` - -
-
an assignment through a reference to `_` (7) - fixtures/reject/src/lib.rs:17:2: an assignment through a reference to `u32` @@ -178,7 +158,19 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:144:2: an assignment through a reference to `std::pin::Pin>` - fixtures/reject/src/lib.rs:149:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` - fixtures/reject/src/lib.rs:267:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` -- fixtures/reject/src/lib.rs:367:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:362:3: an assignment through a reference to `u8` + +
+ +
unsupported call to `_` (7) + +- fixtures/reject/src/lib.rs:33:4: unsupported call to `std::slice::::sort` +- fixtures/reject/src/lib.rs:49:18: unsupported call to `std::mem::size_of_val::` +- fixtures/reject/src/lib.rs:97:10: unsupported call to `::write_fmt` +- fixtures/reject/src/lib.rs:154:11: unsupported call to ` as std::iter::Iterator>::cycle` +- fixtures/reject/src/lib.rs:208:8: unsupported call to `std::ops::Range::::contains::` +- fixtures/reject/src/lib.rs:369:4: unsupported call to `core::slice::::copy_within::>` +- fixtures/reject/src/lib.rs:406:2: unsupported call to ` as std::ops::Deref>::deref`
@@ -189,7 +181,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:37:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` - fixtures/reject/src/lib.rs:37:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` - fixtures/reject/src/lib.rs:133:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:301:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:296:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` @@ -199,8 +191,8 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:22:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it - fixtures/reject/src/lib.rs:65:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it - fixtures/reject/src/lib.rs:95:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:366:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:383:15: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:361:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:378:15: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it @@ -209,17 +201,17 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:56:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet - fixtures/reject/src/lib.rs:249:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet - fixtures/reject/src/lib.rs:254:20: an iterator that owns `Noisy`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:398:15: an iterator that owns `{closure@fixtures/reject/src/lib.rs:398:48: 398:56}`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:399:13: an iterator that owns `{closure@fixtures/reject/src/lib.rs:399:32: 399:39}`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:387:15: an iterator that owns `{closure@fixtures/reject/src/lib.rs:387:48: 387:56}`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:388:13: an iterator that owns `{closure@fixtures/reject/src/lib.rs:388:32: 388:39}`, which drops, which is not supported yet
a variant of `_`, which is not supported: either is the same JS string (4) -- fixtures/reject/src/lib.rs:405:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:406:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:407:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:412:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:394:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:395:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:396:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:401:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
@@ -228,7 +220,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:108:2: replacing the value behind a reference to `Meters` - fixtures/reject/src/lib.rs:112:2: replacing the value behind a reference to `Meters` - fixtures/reject/src/lib.rs:273:22: replacing the value behind a reference to `[u16; 1]` -- fixtures/reject/src/lib.rs:384:4: replacing the value behind a reference to `std::string::String` +- fixtures/reject/src/lib.rs:379:4: replacing the value behind a reference to `std::string::String` @@ -255,13 +247,6 @@ The type or module each refused type or path belongs to. -
a field of `_` (2) - -- fixtures/reject/src/lib.rs:296:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:296:48: a field of `std::ops::RangeFrom` - -
-
an iterator of the crate implementing `_`, which is not supported yet (2) - fixtures/reject/src/lib.rs:187:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet @@ -279,7 +264,7 @@ The type or module each refused type or path belongs to.
dropping a closure that owns a value that drops, which is not supported yet (2) - fixtures/reject/src/lib.rs:51:1: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:396:18: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:385:18: dropping a closure that owns a value that drops, which is not supported yet
@@ -316,37 +301,37 @@ The type or module each refused type or path belongs to.
`_` holds `_`, which is `undefined` as `None` is, which is not supported (1) -- fixtures/reject/src/lib.rs:301:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported +- fixtures/reject/src/lib.rs:296:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:416:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:405:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:324:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:319:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:356:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet +- fixtures/reject/src/lib.rs:351:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
`_`, a mutable reference to a value a map holds, kept other than to read and write it (1) -- fixtures/reject/src/lib.rs:366:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it +- fixtures/reject/src/lib.rs:361:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:332:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:327:9: `Hasher::write`, which is not supported yet
@@ -364,7 +349,7 @@ The type or module each refused type or path belongs to.
a coercion to `_` (1) -- fixtures/reject/src/lib.rs:379:2: a coercion to `std::sync::Arc<[u8]>` +- fixtures/reject/src/lib.rs:374:2: a coercion to `std::sync::Arc<[u8]>`
@@ -424,19 +409,19 @@ The type or module each refused type or path belongs to.
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:306:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:301:52: comparing `std::vec::Vec` as a key, which is not supported yet
constructing `_` (1) -- fixtures/reject/src/lib.rs:423:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:412:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:306:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:301:52: hashing `std::vec::Vec` as a key, which is not supported yet
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index c50db5aa5..ac4a962aa 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -54,30 +54,27 @@ replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib. `std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:280:16 `std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:280:38 a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:290:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:296:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:296:48 -`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:301:2 -`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:301:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:306:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:306:52 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:324:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:374:4 -a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:379:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:405:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:407:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:406:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:412:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:416:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:417:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:423:53 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:383:15 -replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:384:4 -unsupported call to `core::str::::split::<[char; 2]>` at fixtures/reject/src/lib.rs:390:4 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:396:18 -an iterator that owns `{closure@fixtures/reject/src/lib.rs:398:48: 398:56}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:398:15 -an iterator that owns `{closure@fixtures/reject/src/lib.rs:399:32: 399:39}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:399:13 +`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:296:2 +`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:296:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:301:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:301:52 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:319:6 +unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:369:4 +a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:374:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:394:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:396:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:395:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:401:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:405:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:406:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:412:53 +`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:378:15 +replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:379:4 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:385:18 +an iterator that owns `{closure@fixtures/reject/src/lib.rs:387:48: 387:56}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:387:15 +an iterator that owns `{closure@fixtures/reject/src/lib.rs:388:32: 388:39}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:388:13 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:167:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:187:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:221:2 an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:241:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:332:9 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:327:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 78204e0c7..306cff8c6 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -291,11 +291,6 @@ pub fn copied_closure(n: u8) -> u8 { g().wrapping_add(h()) } -/// Struct update syntax on a one-sided range reads its base's field, which is not supported. -pub fn one_sided(data: &[u8], to: std::ops::RangeTo, from: std::ops::RangeFrom) -> usize { - data[std::ops::RangeTo { ..to }].len() + data[std::ops::RangeFrom { ..from }].len() -} - /// `get`'s `None` and `Some(&None)` would both be `undefined`. pub fn optional(map: &std::collections::HashMap>) -> bool { map.get(&1).is_some() @@ -384,12 +379,6 @@ pub fn pushed(s: &mut String) { s.push('a'); } -/// A `str` pattern of several chars, where only a `char`, a `&str`, and a predicate are -/// supported. -pub fn split_chars(s: &str) -> usize { - s.split(['a', 'b']).count() -} - /// Each drops its closure, and the `Noisy` it owns, when it is done with it. pub fn owning_lazy(cond: bool) -> usize { let (a, b, c) = (Noisy(1), Noisy(2), Noisy(3)); diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 5ee7dadfa..469d8cb70 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -38,7 +38,6 @@ roots = [ "replace_captured", "filter_owned_bytes", "copied_closure", - "one_sided", "optional", "byte_keys", "borrowed", @@ -50,7 +49,6 @@ roots = [ "cow_bytes", "cow_made", "pushed", - "split_chars", "owning_lazy", "missing", ] diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index cf20641a4..a492873f8 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -918,10 +918,16 @@ pub fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => eq_fn(b, inner, span), // A slice compares its elements by `!=`, which `!eq` stands for only while that is // the default. - _ if let Some(elem) = elements_of(b, ty) && own_ne(b, elem) => b.err( - span, - format!("comparing `{ty}` by `<{elem} as PartialEq>::ne` through a held type's own, which is not supported yet"), - ), + _ if let Some(elem) = elements_of(b, ty) + && own_ne(b, elem) => + { + b.err( + span, + format!( + "comparing `{ty}` by `<{elem} as PartialEq>::ne` through a held type's own, which is not supported yet" + ), + ) + } _ if let Some(elem) = elements_of(b, ty) => Expr::rt("eqSlice", vec![eq_fn(b, elem, span)]), ty::Adt(..) if let Some(inner) = arc_of(b, ty) => { let mut values = vec![eq_fn(b, inner, span)]; diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index d72b01406..e2c0b3c1b 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -810,10 +810,16 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec (_, Some(Std::RangeFrom)) if start => ("Included", Some("start")), (_, Some(Std::RangeTo)) if !start => ("Excluded", Some("end")), (_, Some(Std::RangeToInclusive)) if !start => ("Included", Some("end")), - (_, Some(Std::RangeFrom | Std::RangeTo | Std::RangeToInclusive | Std::RangeFull)) => ("Unbounded", None), + (_, Some(Std::RangeFrom | Std::RangeTo | Std::RangeToInclusive | Std::RangeFull)) => { + ("Unbounded", None) + } // Exhausted, it ends before its end. (_, Some(Std::RangeInclusive)) => { - let f = if start { "rangeInclusiveStartBound" } else { "rangeInclusiveEndBound" }; + let f = if start { + "rangeInclusiveStartBound" + } else { + "rangeInclusiveEndBound" + }; return Some(Expr::As(Box::new(Expr::rt(f, vec![r])), ts)); } _ => return None, @@ -875,9 +881,10 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec } } // Sorted by `lt` of `Ord`, or by a comparator, or by `lt` of the keys a function makes. - ("slice", "sort" | "sort_unstable" | "sort_by" | "sort_unstable_by" | "sort_by_key" | "sort_unstable_by_key") - if !is_u8(targ(gargs, 0)) => - { + ( + "slice", + "sort" | "sort_unstable" | "sort_by" | "sort_unstable_by" | "sort_by_key" | "sort_unstable_by_key", + ) if !is_u8(targ(gargs, 0)) => { let mut values = args; match name.as_str() { "sort" | "sort_unstable" => { @@ -888,7 +895,10 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec _ => { let key = targ(gargs, 1); if b.t.drops(key) { - return Some(b.err(span, format!("`slice::{name}` by `{key}`, which drops, which is not supported yet"))); + return Some(b.err( + span, + format!("`slice::{name}` by `{key}`, which drops, which is not supported yet"), + )); } values.push(super::collections::cmp_fn(b, key, true, span)); Expr::rt("sliceSortByKey", values) @@ -990,7 +1000,10 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec // `Vec::dedup_by_key::`. let key = targ(gargs, 3); if b.t.drops(key) { - return Some(b.err(span, format!("`Vec::dedup_by_key` by `{key}`, which drops, which is not supported yet"))); + return Some(b.err( + span, + format!("`Vec::{name}` by `{key}`, which drops, which is not supported yet"), + )); } values.push(super::collections::eq_fn(b, key, span)); Expr::rt("vecDedupByKey", values) diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index eab452825..defe95f4a 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -298,7 +298,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let ty::Adt(_, args) = ty.kind() else { unreachable!() }; let variant = variant.unwrap_or(rustc_abi::FIRST_VARIANT); let fields = vec![ - ("tag".to_string(), crate::ts::Type::StrLit(adt.variant(variant).name.to_string())), + ( + "tag".to_string(), + crate::ts::Type::StrLit(adt.variant(variant).name.to_string()), + ), ("_0".to_string(), self.b.t.ty(args.type_at(0), span)), ]; Expr::As(Box::new(base), crate::ts::Type::Object(fields)).member("_0") diff --git a/ts/src/ts.rs b/ts/src/ts.rs index 9c5e35df3..bf9d96ade 100644 --- a/ts/src/ts.rs +++ b/ts/src/ts.rs @@ -129,7 +129,8 @@ impl Expr { // own, without which a declaration narrows to the one variant it is made as. Self::As(e, ty) if matches!(*e, Self::Str(_) | Self::Array(_) | Self::Object(_)) - && !wide(&ty) && !matches!(ty, Type::Rt("Bound", _)) => + && !wide(&ty) + && !matches!(ty, Type::Rt("Bound", _)) => { *e } diff --git a/ts/tests/runtime.rs b/ts/tests/runtime.rs index a34a72359..3f066eb32 100644 --- a/ts/tests/runtime.rs +++ b/ts/tests/runtime.rs @@ -185,7 +185,10 @@ fn retain_unwinds() { }) })); let ran: Vec = runs.iter().map(|r| r.0.0).collect(); - let deduped: Vec = std::mem::take(&mut *deduped.borrow_mut()).into_iter().map(|r| r.0).collect(); + let deduped: Vec = std::mem::take(&mut *deduped.borrow_mut()) + .into_iter() + .map(|r| r.0) + .collect(); let entries: Vec = tree.iter().map(|(k, v)| format!("{k},{v}")).collect(); let items: Vec = deque.iter().map(u32::to_string).collect(); let join = |v: &[u32]| v.iter().map(u32::to_string).collect::>().join(","); From 679de2e413647eaa7ed5f7fb859675c3e05a2209 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:36:20 -0700 Subject: [PATCH 06/11] chore(quest): finish quest/m2/ts-model/std-more.md Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- quest/m2/ts-model/README.md | 1 - quest/m2/ts-model/std-more.md | 19 ------------------- 2 files changed, 20 deletions(-) delete mode 100644 quest/m2/ts-model/std-more.md diff --git a/quest/m2/ts-model/README.md b/quest/m2/ts-model/README.md index c788f1b2c..4ed453819 100644 --- a/quest/m2/ts-model/README.md +++ b/quest/m2/ts-model/README.md @@ -50,7 +50,6 @@ Public API: the translator's output for moq-net's model. - [Translate safe dependencies with the package](/quest/m2/ts-model/crates.md) - kio, moq-clock, moq-pattern, and rangemap translate as one program with moq-net - [Std combinators from core's MIR](/quest/m2/ts-model/core-mir.md) - `Option`'s and `Result`'s combinators lower from core's own bodies - [Duration](/quest/m2/ts-model/time.md) - `Duration` translates as std's seconds and nanoseconds -- [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods - [Options of values that can be undefined](/quest/m2/ts-model/nested-option.md) - `Option>` and `Option<()>` keep `None` apart from `Some(None)` - [Mutable references to values JS copies](/quest/m2/ts-model/mut-place.md) - a `&mut` to a number or an `Option` passed on or kept - [Async in the TypeScript translator](/quest/m2/ts-async.md) - kio's producers and consumers are futures diff --git a/quest/m2/ts-model/std-more.md b/quest/m2/ts-model/std-more.md deleted file mode 100644 index 8a0a4b1b4..000000000 --- a/quest/m2/ts-model/std-more.md +++ /dev/null @@ -1,19 +0,0 @@ -# [M] Std gaps the model reaches - -## Goal - -rust2-ts translates the std ranges, wrappers, and methods moq-net's model and moq-pattern -call: `Bound` and `RangeBounds`, `Reverse`, `NonZero`, wrapping and saturating arithmetic, -`div_ceil`, tuples' comparisons and `Clone`, `Vec`'s and slices' editing and sorting -methods (`retain`, `swap_remove`, `dedup`, `sort_by_key`, `last_mut`), `Clone` and -`PartialEq` of a `Vec` that is not `Copy`, `BTreeMap::split_off`, `mem::take`, `Ord`'s -`min`, `max`, and `clamp`, and `str`'s byte searches, proven by differential tests against -native Rust. - -## Plan - -Found by the [model's](/quest/m2/ts-model/README.md) census on 2026-10-27: 246 refusals -over 121 items in the model, and 62 in moq-pattern. `capacity` (cache.rs, group.rs) stays -refused unless the maintainer decides otherwise. Report the census before and after. - -Public API: the translator's output. From 5172a237e4ec0a8e01111f4fdba26f5b7fda0fe5 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:48:57 -0700 Subject: [PATCH 07/11] fix(ts): keep each element when a merge's comparator panics, and empty B-tree ranges of wrapped inclusive ranges Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/src/wrappers.rs | 7 +++++++ ts/runtime/rt.ts | 6 +++++- ts/runtime/rt/collections.ts | 6 +++--- ts/tests/retain.ts | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ts/fixtures/lang/src/wrappers.rs b/ts/fixtures/lang/src/wrappers.rs index 0c7d74bd0..4f0d39211 100644 --- a/ts/fixtures/lang/src/wrappers.rs +++ b/ts/fixtures/lang/src/wrappers.rs @@ -125,6 +125,13 @@ pub fn wrappers(kind: u8, data: &[u8], out: &mut Vec) { put_u64(out, *k); } out.push(map.range(..a).count() as u8); + // Exhausted by wrapping either way, an inclusive range holds nothing. + let mut top = (u64::MAX - a % 2)..=u64::MAX; + while top.next().is_some() {} + let mut bottom = 0..=(b % 2); + while bottom.next_back().is_some() {} + out.push(map.range(top).count() as u8); + out.push(map.range(bottom).count() as u8); let above = map.split_off(&b); for (k, v) in map.iter().chain(above.iter()) { put_u64(out, *k); diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 0abf84858..644c082ff 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -356,7 +356,11 @@ function sort(s: T[], less: (a: T, b: T) => boolean): void { let j = mid; let k = lo; try { - while (i < left.length && j < hi) s[k++] = less(s[j], left[i]) ? s[j++] : left[i++]; + // `k` moves only once `less` returns, so a panic leaves no slot written twice. + while (i < left.length && j < hi) { + s[k] = less(s[j], left[i]) ? s[j++] : left[i++]; + k++; + } } finally { while (i < left.length) s[k++] = left[i++]; } diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index 7d17d65f8..2429fff07 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -1300,9 +1300,9 @@ export type Bounds = /** `RangeBounds`: the start, the end, and whether the end is in the range, as `..=end`'s is. */ function bounds(r: Bounds): [{ key: K } | undefined, { key: K } | undefined, boolean] { if (r === undefined) return [undefined, undefined, false]; - // Exhausted, an inclusive range ends before its end, as its `end_bound` says. A field - // test, not `instanceof`, so a bundle without `a..=b` leaves the class out. - if ("exhausted" in r) return [{ key: r.lo }, { key: r.hi }, !r.exhausted]; + // Exhausted by wrapping, an inclusive range excludes its start, as its `end_bound` says. + // A field test, not `instanceof`, so a bundle without `a..=b` leaves the class out. + if ("exhausted" in r) return [{ key: r.lo }, { key: r.exhausted ? r.lo : r.hi }, !r.exhausted]; return ["start" in r ? { key: r.start } : undefined, "end" in r ? { key: r.end } : undefined, "inclusive" in r]; } diff --git a/ts/tests/retain.ts b/ts/tests/retain.ts index 99c215f2a..7633903a6 100644 --- a/ts/tests/retain.ts +++ b/ts/tests/retain.ts @@ -103,3 +103,24 @@ for (let n = 0; n <= 6; n++) { } } } + +// Past one insertion-sorted run, so a comparator panics in merges too, at each of its calls. +for (const n of [17, 40, 70]) { + const unsorted = [...Array(n).keys()].map((i) => ((n - i) * 7) % 31); + const want = unsorted.slice().sort().join(); + for (let p = 0, thrown = true; thrown; p++) { + const sorted = unsorted.slice(); + let calls = 0; + thrown = false; + try { + rt.sliceSortBy(sorted, (a, b) => { + if (calls++ === p) throw new Thrown(); + return rt.cmp(a, b); + }); + } catch (err) { + if (!(err instanceof Thrown)) throw err; + thrown = true; + } + if (sorted.slice().sort().join() !== want) throw new Error(`sort of ${n} panicking at ${p}: ${sorted}`); + } +} From a3b072d59fcfd68a4850860f1d8b41d186778b52 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:04:45 -0700 Subject: [PATCH 08/11] fix(ts): refuse Bound::copied rather than call Clone Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/src/lower/library.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index d68512695..a94556559 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -795,8 +795,8 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec // A `NonZero` is its integer. ("NonZero", "get") => args.pop()?, ("NonZero", "new") => Expr::rt("nonZero", args), - // `Bound<&T>::cloned::` and `copied`: what it holds, cloned. - ("Bound", "cloned" | "copied") => { + // `Bound<&T>::cloned::`: what it holds, cloned. + ("Bound", "cloned") => { let value = args.pop()?; let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); let bound = tcx.instantiate_bound_regions_with_erased(sig).output(); From 29b6c285b6e53909b7f49da88394646113a3230a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:20:11 -0700 Subject: [PATCH 09/11] fix(ts): compare by PartialOrd's tests as std's sorts and Ord's defaults do Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/expected/edits.Lean.ts | 20 + ts/fixtures/lang/expected/edits.ts | 48 +- ts/fixtures/lang/expected/keys.ts | 4 +- ts/fixtures/lang/src/edits.rs | 27 + ts/fixtures/reject/census.md | 80 +-- ts/fixtures/reject/expected.txt | 35 +- ts/fixtures/reject/src/lib.rs | 21 + ts/fixtures/reject/ts.toml | 1 + ts/fixtures/task/expected/drops.ts | 652 ++++++++++++------------ ts/fixtures/task/src/drops.rs | 6 +- ts/runtime/rt/collections.ts | 23 +- ts/src/lower/collections.rs | 37 +- ts/src/lower/library.rs | 10 +- 13 files changed, 560 insertions(+), 404 deletions(-) create mode 100644 ts/fixtures/lang/expected/edits.Lean.ts diff --git a/ts/fixtures/lang/expected/edits.Lean.ts b/ts/fixtures/lang/expected/edits.Lean.ts new file mode 100644 index 000000000..b74e1ba26 --- /dev/null +++ b/ts/fixtures/lang/expected/edits.Lean.ts @@ -0,0 +1,20 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** + * An order whose `partial_cmp` leans on its first operand, an odd one less than any, and + * whose `cmp` is by value, so what `Ord`'s defaults call, with which operand first, shows. + */ +export interface Lean { + _0: rt.u8; +} + +export function partialCmp$PartialOrd(self: Lean, other: Lean): rt.Ordering | undefined { + if (rt.u8Rem(self._0, 2) === 1) { + return -1; + } + return rt.cmp(self._0, other._0); +} + +//# sourceMappingURL=edits.Lean.ts.map diff --git a/ts/fixtures/lang/expected/edits.ts b/ts/fixtures/lang/expected/edits.ts index 9828637cb..6f7e7bfba 100644 --- a/ts/fixtures/lang/expected/edits.ts +++ b/ts/fixtures/lang/expected/edits.ts @@ -2,6 +2,7 @@ import * as rt from "./rt.ts"; import { copy$chars } from "./lib.ts"; +import * as Lean from "./edits.Lean.ts"; import * as Named from "./edits.Named.ts"; import * as Stamp from "./edits.Stamp.ts"; import * as Tally from "./edits.Tally.ts"; @@ -39,9 +40,9 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const pairs: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterSlice(words), (_228: rt.u16): [rt.u16, rt.u16] => { return [_228, 0] as [rt.u16, rt.u16]; })); - rt.vecRetain(pairs, (p2: [rt.u16, rt.u16]): boolean => { - p2[1] = rt.u16Div(p2[0], 2); - return rt.u16Rem(p2[0], 3) === 0; + rt.vecRetain(pairs, (p3: [rt.u16, rt.u16]): boolean => { + p3[1] = rt.u16Div(p3[0], 2); + return rt.u16Rem(p3[0], 3) === 0; }); for (const _33 of pairs) { putU16s(out, [_33[0], _33[1]]); @@ -110,8 +111,8 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const pairs2: [rt.u16, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(words)), (_211: [rt.usize, rt.u16]): [rt.u16, rt.u16] => { return [rt.u16Rem(_211[1], 5), _211[0] & 0xffff] as [rt.u16, rt.u16]; })); - rt.sliceSortByKey(pairs2, (p: [rt.u16, rt.u16]): rt.u16 => { - return p[0]; + rt.sliceSortByKey(pairs2, (p2: [rt.u16, rt.u16]): rt.u16 => { + return p2[0]; }, rt.cmp); for (const _159 of pairs2) { putU16s(out, [_159[0], _159[1]]); @@ -211,8 +212,8 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { return rt.u16Add(i4 as rt.u16, b3 as rt.u16); })); })); - const _424: rt.u16[][] = rt.vecClone(nested, (a011: rt.u16[]): rt.u16[] => { - return a011.slice(); + const _424: rt.u16[][] = rt.vecClone(nested, (a014: rt.u16[]): rt.u16[] => { + return a014.slice(); }); rt.byteVecPush(out, rt.eqSlice(rt.eqSlice(rt.same))(_424, nested) ? 1 : 0); const pair: [string, rt.u8] = [text(data), at(0)]; @@ -253,9 +254,16 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { const x: Stamp.Stamp = _529[0]; const lo: Stamp.Stamp = _529[1]; const hi: Stamp.Stamp = _529[2]; - rt.byteVecPush(out, rt.ordMax(x, lo, Stamp.cmp$Ord)._0); - rt.byteVecPush(out, rt.ordMin(x, lo, Stamp.cmp$Ord)._0); + rt.byteVecPush(out, rt.ordMax(x, lo, Stamp.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordMin(x, lo, Stamp.partialCmp$PartialOrd)._0); rt.byteVecPush(out, rt.ordClamp(x, lo, hi, Stamp.partialCmp$PartialOrd)._0); + const _554: [Lean.Lean, Lean.Lean, Lean.Lean] = [{ _0: at(0) }, { _0: at(1) }, { _0: at(2) }]; + const p: Lean.Lean = _554[0]; + const q: Lean.Lean = _554[1]; + const r: Lean.Lean = _554[2]; + rt.byteVecPush(out, rt.ordMax(p, q, Lean.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordMin(p, q, Lean.partialCmp$PartialOrd)._0); + rt.byteVecPush(out, rt.ordClamp(p, q, r, Lean.partialCmp$PartialOrd)._0); } else { const s: string = text(data); const sep: rt.char[] = [47, 97]; @@ -267,27 +275,27 @@ export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, rt.strEndsWith(s, (c: rt.char): boolean => { return rt.charIsAsciiDigit(c); }) ? 1 : 0); - const _587: [string, string] | undefined = rt.strSplitOnce(s, "/"); - if (_587 === undefined) { + const _612: [string, string] | undefined = rt.strSplitOnce(s, "/"); + if (_612 === undefined) { rt.byteVecPush(out, 253); } else { - put(out, _587[0]); - put(out, _587[1]); + put(out, _612[0]); + put(out, _612[1]); } - const _596: [string, string] | undefined = rt.strSplitOnce(s, "a0"); - if (_596 === undefined) { + const _621: [string, string] | undefined = rt.strSplitOnce(s, "a0"); + if (_621 === undefined) { rt.byteVecPush(out, 253); } else { - put(out, _596[0]); - put(out, _596[1]); + put(out, _621[0]); + put(out, _621[1]); } const iter10: rt.RangeInclusive = new rt.RangeInclusive(0, rt.usizeAdd(rt.stringLen(s), 1), rt.usizeStep); while (true) { - const _611: rt.usize | rt.Done = iter10.next(); - if (_611 === rt.DONE) { + const _636: rt.usize | rt.Done = iter10.next(); + if (_636 === rt.DONE) { break; } - rt.byteVecPush(out, rt.strIsCharBoundary(s, _611) ? 1 : 0); + rt.byteVecPush(out, rt.strIsCharBoundary(s, _636) ? 1 : 0); } rt.iterExtendBytes(out, rt.strBytes(s)); rt.iterExtendBytes(out, rt.iterTake(rt.iterRev(rt.strBytes(s)), 3)); diff --git a/ts/fixtures/lang/expected/keys.ts b/ts/fixtures/lang/expected/keys.ts index 7eeb9cc32..723418b98 100644 --- a/ts/fixtures/lang/expected/keys.ts +++ b/ts/fixtures/lang/expected/keys.ts @@ -494,9 +494,9 @@ export function options(data: rt.ByteSlice, out: rt.ByteVec): void { const a: Hop.Hop | undefined = _27[0]; const b: Hop.Hop | undefined = _27[1]; rt.byteVecPush(out, (rt.eqOption(Hop.eq$PartialEq)(a, b) ? 1 : 0) | (((!rt.eqOption(Hop.eq$PartialEq)(a, b) ? 1 : 0) << 1) & 0xff) | ((order(rt.cmpOption(Hop.cmp$Ord)(a, b)) << 2) & 0xff)); - const _56: Hop.Hop | undefined = rt.ordMax(a, b, rt.cmpOption(Hop.cmp$Ord)); + const _56: Hop.Hop | undefined = rt.ordMax(a, b, rt.cmpOption(Hop.partialCmp$PartialOrd)); const _53: rt.u8 = rt.eqOption(Hop.eq$PartialEq)(_56, b) ? 1 : 0; - const _62: Hop.Hop | undefined = rt.ordMin(a, b, rt.cmpOption(Hop.cmp$Ord)); + const _62: Hop.Hop | undefined = rt.ordMin(a, b, rt.cmpOption(Hop.partialCmp$PartialOrd)); rt.byteVecPush(out, _53 | (((rt.eqOption(Hop.eq$PartialEq)(_62, a) ? 1 : 0) << 1) & 0xff)); rt.byteVecPush(out, rt.u64Eq(hashOf$Option_Hop(a), hashOf$Option_Hop(b)) ? 1 : 0); const _75: [rt.u8 | undefined, rt.u8 | undefined] = [small(c), small(d)]; diff --git a/ts/fixtures/lang/src/edits.rs b/ts/fixtures/lang/src/edits.rs index 47c6bf964..f85832c0c 100644 --- a/ts/fixtures/lang/src/edits.rs +++ b/ts/fixtures/lang/src/edits.rs @@ -2,6 +2,7 @@ //! called with, `Clone` and comparisons of vectors and tuples that are not `Copy`, //! `mem::take`, `Ord`'s defaults on the crate's own types, and `str`'s byte searches. +use std::cmp::Ordering; use std::collections::{BTreeSet, VecDeque}; use crate::fmt::put; @@ -11,6 +12,27 @@ use crate::strs::text; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] struct Stamp(u8); +/// An order whose `partial_cmp` leans on its first operand, an odd one less than any, and +/// whose `cmp` is by value, so what `Ord`'s defaults call, with which operand first, shows. +#[derive(Clone, Copy, PartialEq, Eq)] +struct Lean(u8); + +#[allow(clippy::non_canonical_partial_ord_impl)] +impl PartialOrd for Lean { + fn partial_cmp(&self, other: &Self) -> Option { + Some(match self.0 % 2 { + 1 => Ordering::Less, + _ => self.0.cmp(&other.0), + }) + } +} + +impl Ord for Lean { + fn cmp(&self, other: &Self) -> Ordering { + self.0.cmp(&other.0) + } +} + /// What `mem::take` leaves its own `Default` in place of. struct Tally { n: u8, @@ -235,6 +257,11 @@ pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { out.push(x.max(lo).0); out.push(x.min(lo).0); out.push(x.clamp(lo, hi).0); + // By `<`, `<=`, and `>`, which call `partial_cmp`, `other` first in `max` and `min`. + let (p, q, r) = (Lean(at(0)), Lean(at(1)), Lean(at(2))); + out.push(p.max(q).0); + out.push(p.min(q).0); + out.push(p.clamp(q, r).0); } _ => { let s = text(data); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 05a251a5e..f37f6125e 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,7 +1,7 @@ # Census of `reject-fixture` -- Refusals: 89 -- Function instances: 67 +- Refusals: 92 +- Function instances: 70 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct @@ -13,21 +13,22 @@ | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:28:15 | | 6 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:16:13 | | 6 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:51:1 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:411:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:432:2 | | 4 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:108:2 | | 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | +| 3 | comparing `_` through its own `_`, which is not supported yet | fixtures/reject/src/lib.rs:398:4 | | 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:128:20 | | 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:280:16 | | 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:187:1 | | 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:173:23 | -| 2 | dropping `_`, which is not supported yet | fixtures/reject/src/lib.rs:403:79 | +| 2 | dropping `_`, which is not supported yet | fixtures/reject/src/lib.rs:424:79 | | 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:167:2 | | 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:85:3 | | 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:87:3 | | 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:86:3 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:90:3 | | 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:296:6 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:422:18 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:443:18 | | 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:319:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | fixtures/reject/src/lib.rs:56:13 | | 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:351:2 | @@ -46,10 +47,10 @@ | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:89:3 | | 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:75:2 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:405:13 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:426:13 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:301:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:429:53 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:450:53 | | 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:301:52 | | 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:88:3 | | 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:83:3 | @@ -61,26 +62,29 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:411:2 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:432:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:28:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | | 6 | `u8` | fixtures/reject/src/lib.rs:65:10 | | 4 | `std::string::String` | fixtures/reject/src/lib.rs:95:16 | | 4 | `u32` | fixtures/reject/src/lib.rs:16:13 | +| 3 | `PartialOrd` | fixtures/reject/src/lib.rs:398:4 | | 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:56:13 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:124:2 | | 2 | `Iterator` | fixtures/reject/src/lib.rs:167:2 | +| 2 | `Lopsided` | fixtures/reject/src/lib.rs:398:4 | | 2 | `Meters` | fixtures/reject/src/lib.rs:108:2 | | 2 | `Noisy` | fixtures/reject/src/lib.rs:56:13 | | 2 | `Poll` | fixtures/reject/src/lib.rs:128:20 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:280:16 | | 2 | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | -| 2 | `std::iter::Take` | fixtures/reject/src/lib.rs:403:79 | +| 2 | `std::iter::Take` | fixtures/reject/src/lib.rs:424:79 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:208:8 | | 2 | `std::option::Option` | fixtures/reject/src/lib.rs:296:6 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | | 2 | `std::slice` | fixtures/reject/src/lib.rs:33:4 | | 2 | `std::vec::Vec` | fixtures/reject/src/lib.rs:301:52 | +| 1 | `(i32, &Lopsided)` | fixtures/reject/src/lib.rs:399:13 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | | 1 | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | | 1 | `HashMap` | fixtures/reject/src/lib.rs:319:6 | @@ -95,7 +99,7 @@ The type or module each refused type or path belongs to. | 1 | `std::mem` | fixtures/reject/src/lib.rs:49:18 | | 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:154:11 | | 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | -| 1 | `std::time::Duration` | fixtures/reject/src/lib.rs:437:2 | +| 1 | `std::time::Duration` | fixtures/reject/src/lib.rs:458:2 | | 1 | `u64` | fixtures/reject/src/lib.rs:119:2 | | 1 | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | @@ -104,7 +108,7 @@ The type or module each refused type or path belongs to. | Count | Construct | Type or path | First | | ---: | --- | --- | --- | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:28:15 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:411:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:432:2 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:128:20 | | 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:95:16 | @@ -112,10 +116,11 @@ The type or module each refused type or path belongs to. | 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:65:10 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | | 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:66:3 | -| 2 | dropping `_`, which is not supported yet | `std::iter::Take` | fixtures/reject/src/lib.rs:403:79 | +| 2 | comparing `_` through its own `_`, which is not supported yet | `Lopsided`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:398:4 | +| 2 | dropping `_`, which is not supported yet | `std::iter::Take` | fixtures/reject/src/lib.rs:424:79 | | 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:108:2 | | 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:296:6 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:422:18 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:443:18 | | 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:319:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | `into_keys`, `std::collections::HashMap`, `Noisy` | fixtures/reject/src/lib.rs:56:13 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:280:38 | @@ -137,10 +142,11 @@ The type or module each refused type or path belongs to. | 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:17:2 | | 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | | 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:405:13 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:426:13 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:301:52 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:429:53 | +| 1 | comparing `_` through its own `_`, which is not supported yet | `(i32, &Lopsided)`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:399:13 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:450:53 | | 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | | 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | | 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:301:52 | @@ -148,10 +154,10 @@ The type or module each refused type or path belongs to. | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:221:2 | | 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:273:22 | | 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:379:4 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:423:2 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:444:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:154:11 | | 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:97:10 | -| 1 | unsupported call to `_` | `::add_assign` | fixtures/reject/src/lib.rs:437:2 | +| 1 | unsupported call to `_` | `::add_assign` | fixtures/reject/src/lib.rs:458:2 | | 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:49:18 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:208:8 | | 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:369:4 | @@ -168,8 +174,8 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:154:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:208:8: unsupported call to `std::ops::Range::::contains::` - fixtures/reject/src/lib.rs:369:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:423:2: unsupported call to ` as std::ops::Deref>::deref` -- fixtures/reject/src/lib.rs:437:2: unsupported call to `::add_assign` +- fixtures/reject/src/lib.rs:444:2: unsupported call to ` as std::ops::Deref>::deref` +- fixtures/reject/src/lib.rs:458:2: unsupported call to `::add_assign`
@@ -210,20 +216,20 @@ The type or module each refused type or path belongs to.
dropping a closure that owns a value that drops, which is not supported yet (6) - fixtures/reject/src/lib.rs:51:1: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:386:12: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:390:12: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:401:18: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:403:15: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:404:13: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:407:12: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:411:12: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:422:18: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:424:15: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:425:13: dropping a closure that owns a value that drops, which is not supported yet
a variant of `_`, which is not supported: either is the same JS string (4) -- fixtures/reject/src/lib.rs:411:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:412:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:413:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:418:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:432:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:433:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:434:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:439:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
@@ -245,6 +251,14 @@ The type or module each refused type or path belongs to. +
comparing `_` through its own `_`, which is not supported yet (3) + +- fixtures/reject/src/lib.rs:398:4: comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet +- fixtures/reject/src/lib.rs:399:13: comparing `(i32, &Lopsided)` through its own `PartialOrd::lt`, which is not supported yet +- fixtures/reject/src/lib.rs:400:12: comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet + +
+
`_` is not supported: it would be pending two ways with one value (2) - fixtures/reject/src/lib.rs:128:20: `Poll>>` is not supported: it would be pending two ways with one value @@ -275,8 +289,8 @@ The type or module each refused type or path belongs to.
dropping `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:403:79: dropping `std::iter::Take>`, which is not supported yet -- fixtures/reject/src/lib.rs:404:62: dropping `std::iter::Take>`, which is not supported yet +- fixtures/reject/src/lib.rs:424:79: dropping `std::iter::Take>`, which is not supported yet +- fixtures/reject/src/lib.rs:425:62: dropping `std::iter::Take>`, which is not supported yet
@@ -319,7 +333,7 @@ The type or module each refused type or path belongs to.
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:422:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:443:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
@@ -433,7 +447,7 @@ The type or module each refused type or path belongs to.
an iterator that owns `_`, which drops, which is not supported yet (1) -- fixtures/reject/src/lib.rs:405:13: an iterator that owns `Noisy`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:426:13: an iterator that owns `Noisy`, which drops, which is not supported yet
@@ -451,7 +465,7 @@ The type or module each refused type or path belongs to.
constructing `_` (1) -- fixtures/reject/src/lib.rs:429:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:450:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 4313ddab7..694c0a173 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -61,24 +61,27 @@ comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/r `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:319:6 unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:369:4 a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:374:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:411:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:413:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:412:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:418:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:422:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:423:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:429:53 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:432:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:434:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:433:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:439:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:443:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:444:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:450:53 `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:378:15 replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:379:4 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:386:12 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:390:12 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:401:18 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:403:15 -dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:403:79 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:404:13 -dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:404:62 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:405:13 -unsupported call to `::add_assign` at fixtures/reject/src/lib.rs:437:2 +comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:398:4 +comparing `(i32, &Lopsided)` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:399:13 +comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:400:12 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:407:12 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:411:12 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:422:18 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:424:15 +dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:424:79 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:425:13 +dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:425:62 +an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:426:13 +unsupported call to `::add_assign` at fixtures/reject/src/lib.rs:458:2 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:167:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:187:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:221:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index c8d21067d..4689b33d7 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -379,6 +379,27 @@ pub fn pushed(s: &mut String) { s.push('a'); } +/// A `<` of its own, which `sort`, `max`, and a tuple's `<` would call where the +/// translation calls `partial_cmp`. +#[derive(PartialEq, Eq, Ord)] +pub struct Lopsided(u8); + +impl PartialOrd for Lopsided { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.0.cmp(&other.0)) + } + + fn lt(&self, other: &Self) -> bool { + self.0 > other.0 + } +} + +pub fn lopsided(v: &mut Vec, a: Lopsided, b: Lopsided) -> bool { + v.sort(); + let wins = (1, &a) < (2, &b); + wins && a.max(b).0 > 0 +} + /// `Option::map` drops its closure on `None`, as `Result::map_err` does on `Ok`, and with /// it what it captured, which lives in an arrow function. pub fn discarded_closure(a: Option, b: Result) -> u8 { diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index b7eae3616..fa22a12d8 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -49,6 +49,7 @@ roots = [ "cow_bytes", "cow_made", "pushed", + "lopsided", "discarded_closure", "owning_lazy", "duration_assign", diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index fa04dec55..9ca37b857 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -2558,7 +2558,7 @@ export function tripped(log: Log.Log, id: rt.u32, at: rt.u8, tree: boolean): voi _155 = true; const _114: rt.Arc = new rt.Arc(trip(4)); _155 = false; - const _109: rt.Arc = rt.ordMax(_110, _114, rt.cmpArc(Key.cmp$Ord), rt.drop); + const _109: rt.Arc = rt.ordMax(_110, _114, rt.cmpArc(Key.partialCmp$PartialOrd), rt.drop); unwind = 100; _155 = false; rt.drop(_109); @@ -3124,50 +3124,53 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { let v4!: Key.Key[]; let v5!: Key.Key[]; let v6!: Key.Key[]; + let _176!: Key.Key; + let _179!: Key.Key; let v7!: Key.Key[]; let v8!: Key.Key[]; let v9!: Key.Key[]; let v10!: Key.Key[]; let v11!: Key.Key[]; let v12!: Key.Key[]; - let _260!: Key.Key[]; + let _271!: Key.Key[]; let tripped_!: Key.Key[]; let v13!: Key.Key[]; let pair!: [Key.Key, Key.Key]; - let _288!: Key.Key; + let _299!: Key.Key; let tripped2!: [Key.Key, Key.Key]; - let _298!: Key.Key; - let _316!: Key.Key; - let _317!: Key.Key; - let _336!: Key.Key; - let _337!: Key.Key; - let _356!: Key.Key; - let _357!: Key.Key; - let _360!: Key.Key; - let _379!: Key.Key; - let _380!: Key.Key; - let _383!: Key.Key; - let _396!: Key.Key; - let _399!: Key.Key; - let _420!: boolean; - let _421!: boolean; - let _422!: boolean; - let _423!: boolean; - let _424!: boolean; - let _425!: boolean; - let _426!: boolean; - let _427!: boolean; + let _309!: Key.Key; + let _327!: Key.Key; + let _328!: Key.Key; + let _347!: Key.Key; + let _348!: Key.Key; + let _367!: Key.Key; + let _368!: Key.Key; + let _371!: Key.Key; + let _390!: Key.Key; + let _391!: Key.Key; + let _394!: Key.Key; + let _407!: Key.Key; + let _429!: boolean; + let _430!: boolean; + let _431!: boolean; + let _432!: boolean; + let _433!: boolean; + let _434!: boolean; + let _435!: boolean; + let _436!: boolean; + let _437!: boolean; let unwind: number = 0; try { b0: { - _427 = false; - _426 = false; - _425 = false; - _424 = false; - _423 = false; - _422 = false; - _421 = false; - _420 = false; + _437 = false; + _436 = false; + _435 = false; + _434 = false; + _433 = false; + _432 = false; + _431 = false; + _430 = false; + _429 = false; const key: (a0: rt.u32) => Key.Key = (n: rt.u32): Key.Key => { return Key.new(rt.u32Add(id, n), Log.clone$Clone(log)); }; @@ -3182,7 +3185,7 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { }; if (at === 0) { v2 = []; - unwind = 228; + unwind = 232; const _14: Key.Key = key(1); v2.push(_14); const _19: Key.Key = key(2); @@ -3191,25 +3194,25 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { v2.push(_24); const _29: Key.Key = key(4); v2.push(_29); - unwind = 227; + unwind = 231; v = v2; rt.vecRetain(v, (k4: Key.Key): boolean => { return rt.u32Rem(rt.u32Sub(k4.id, id), 2) === 1; }, rt.drop); const _42: string = ids(v); - unwind = 226; + unwind = 230; const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _42)]; const _38: string = rt.fmtFormat(["retained ", args2[0]]); - unwind = 227; + unwind = 231; Log.note(log, _38); rt.vecRetain(v, (k5: Key.Key): boolean => { return k5.id !== rt.u32Add(id, 3); }, rt.drop); const _61: string = ids(v); - unwind = 225; + unwind = 229; const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _61)]; const _57: string = rt.fmtFormat(["retained ", args4[0]]); - unwind = 227; + unwind = 231; Log.note(log, _57); unwind = 0; rt.dropAll(v); @@ -3217,7 +3220,7 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { } if (at === 1) { v4 = []; - unwind = 224; + unwind = 228; const _74: Key.Key = key(1); v4.push(_74); const _79: Key.Key = key(2); @@ -3226,7 +3229,7 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { v4.push(_84); const _89: Key.Key = key(4); v4.push(_89); - unwind = 223; + unwind = 227; v3 = v4; rt.vecRetain(v3, (k3: Key.Key): boolean => { if (!(k3.id === rt.u32Add(id, 3))) { @@ -3238,220 +3241,225 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { }, rt.drop); unwind = 0; rt.dropAll(v3); + } else if (at === 2) { + v6 = []; + unwind = 226; + const _100: Key.Key = key(1); + v6.push(_100); + const _105: Key.Key = key(1); + v6.push(_105); + const _110: Key.Key = key(2); + v6.push(_110); + const _115: Key.Key = key(2); + v6.push(_115); + const _120: Key.Key = key(3); + v6.push(_120); + unwind = 225; + v5 = v6; + rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); + const _131: string = ids(v5); + unwind = 224; + const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _131)]; + const _127: string = rt.fmtFormat(["deduped ", args6[0]]); + unwind = 225; + Log.note(log, _127); + rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { + return rt.u32Div(k2.id, 2); + }, rt.same, rt.drop); + const _148: string = ids(v5); + unwind = 223; + const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _148)]; + const _144: string = rt.fmtFormat(["deduped ", args8[0]]); + unwind = 225; + Log.note(log, _144); + rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { + return a.id > b.id; + }, rt.drop); + const _165: string = ids(v5); + unwind = 222; + const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _165)]; + const _161: string = rt.fmtFormat(["deduped ", args10[0]]); + unwind = 225; + Log.note(log, _161); + _176 = key(2); + unwind = 251; + _437 = true; + _179 = key(3); + unwind = 249; + _436 = true; + const _182: Key.Key = key(1); + _437 = false; + _436 = false; + const _175: Key.Key = rt.ordClamp(_176, _179, _182, Key.partialCmp$PartialOrd, rt.drop); + unwind = 225; + _436 = false; + _437 = false; + rt.drop(_175); + unwind = 0; + rt.dropAll(v5); + } else if (at === 3) { + v8 = []; + unwind = 221; + const _189: Key.Key = key(1); + v8.push(_189); + const _194: Key.Key = fault(1, "Blows" as Fault.Fault); + v8.push(_194); + const _200: Key.Key = key(1); + v8.push(_200); + const _205: Key.Key = key(2); + v8.push(_205); + unwind = 220; + v7 = v8; + rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); + unwind = 0; + rt.dropAll(v7); + } else if (at === 4) { + v10 = []; + unwind = 219; + const _214: Key.Key = key(1); + v10.push(_214); + const _219: Key.Key = key(2); + v10.push(_219); + const _224: Key.Key = key(3); + v10.push(_224); + unwind = 218; + v9 = v10; + rt.drop(rt.vecSwapRemove(v9, 0)); + const _236: string = ids(v9); + unwind = 217; + const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _236)]; + const _232: string = rt.fmtFormat(["swapped ", args12[0]]); + unwind = 218; + Log.note(log, _232); + rt.drop(rt.vecSwapRemove(v9, 3)); + unwind = 0; + rt.dropAll(v9); + } else if (at === 5) { + v12 = []; + unwind = 216; + const _252: Key.Key = key(1); + v12.push(_252); + const _257: Key.Key = key(2); + v12.push(_257); + unwind = 215; + v11 = v12; + _271 = rt.vecClone(v11, Key.clone$Clone, rt.drop); + unwind = 214; + const _266: string = ids(_271); + unwind = 213; + const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _266)]; + const _262: string = rt.fmtFormat(["cloned ", args14[0]]); + unwind = 215; + rt.dropAll(_271); + Log.note(log, _262); + v13 = []; + unwind = 212; + const _281: Key.Key = key(1); + v13.push(_281); + const _286: Key.Key = fault(2, "Trips" as Fault.Fault); + v13.push(_286); + const _292: Key.Key = key(3); + v13.push(_292); + unwind = 211; + tripped_ = v13; + rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); + unwind = 215; + rt.dropAll(tripped_); + unwind = 0; + rt.dropAll(v11); + } else if (at === 6) { + _299 = key(1); + unwind = 210; + const _302: Key.Key = key(2); + unwind = 209; + pair = [_299, _302] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + _309 = key(1); + unwind = 208; + const _312: Key.Key = fault(2, "Trips" as Fault.Fault); + unwind = 207; + tripped2 = [_309, _312] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + unwind = 209; + drop$Key_Key(tripped2); + unwind = 0; + drop$Key_Key(pair); } else { - if (at === 2) { - v6 = []; - unwind = 222; - const _100: Key.Key = key(1); - v6.push(_100); - const _105: Key.Key = key(1); - v6.push(_105); - const _110: Key.Key = key(2); - v6.push(_110); - const _115: Key.Key = key(2); - v6.push(_115); - const _120: Key.Key = key(3); - v6.push(_120); - unwind = 221; - v5 = v6; - rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); - const _131: string = ids(v5); - unwind = 220; - const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _131)]; - const _127: string = rt.fmtFormat(["deduped ", args6[0]]); - unwind = 221; - Log.note(log, _127); - rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { - return rt.u32Div(k2.id, 2); - }, rt.same, rt.drop); - const _148: string = ids(v5); - unwind = 219; - const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _148)]; - const _144: string = rt.fmtFormat(["deduped ", args8[0]]); - unwind = 221; - Log.note(log, _144); - rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { - return a.id > b.id; - }, rt.drop); - const _165: string = ids(v5); - unwind = 218; - const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _165)]; - const _161: string = rt.fmtFormat(["deduped ", args10[0]]); - unwind = 221; - Log.note(log, _161); - unwind = 0; - rt.dropAll(v5); - break b0; - } - if (at === 3) { - v8 = []; - unwind = 217; - const _178: Key.Key = key(1); - v8.push(_178); - const _183: Key.Key = fault(1, "Blows" as Fault.Fault); - v8.push(_183); - const _189: Key.Key = key(1); - v8.push(_189); - const _194: Key.Key = key(2); - v8.push(_194); - unwind = 216; - v7 = v8; - rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); - unwind = 0; - rt.dropAll(v7); - } else if (at === 4) { - v10 = []; - unwind = 215; - const _203: Key.Key = key(1); - v10.push(_203); - const _208: Key.Key = key(2); - v10.push(_208); - const _213: Key.Key = key(3); - v10.push(_213); - unwind = 214; - v9 = v10; - rt.drop(rt.vecSwapRemove(v9, 0)); - const _225: string = ids(v9); - unwind = 213; - const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _225)]; - const _221: string = rt.fmtFormat(["swapped ", args12[0]]); - unwind = 214; - Log.note(log, _221); - rt.drop(rt.vecSwapRemove(v9, 3)); - unwind = 0; - rt.dropAll(v9); - } else if (at === 5) { - v12 = []; - unwind = 212; - const _241: Key.Key = key(1); - v12.push(_241); - const _246: Key.Key = key(2); - v12.push(_246); - unwind = 211; - v11 = v12; - _260 = rt.vecClone(v11, Key.clone$Clone, rt.drop); - unwind = 210; - const _255: string = ids(_260); - unwind = 209; - const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _255)]; - const _251: string = rt.fmtFormat(["cloned ", args14[0]]); - unwind = 211; - rt.dropAll(_260); - Log.note(log, _251); - v13 = []; - unwind = 208; - const _270: Key.Key = key(1); - v13.push(_270); - const _275: Key.Key = fault(2, "Trips" as Fault.Fault); - v13.push(_275); - const _281: Key.Key = key(3); - v13.push(_281); - unwind = 207; - tripped_ = v13; - rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); - unwind = 211; - rt.dropAll(tripped_); - unwind = 0; - rt.dropAll(v11); - } else if (at === 6) { - _288 = key(1); - unwind = 206; - const _291: Key.Key = key(2); - unwind = 205; - pair = [_288, _291] as [Key.Key, Key.Key]; - drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); - _298 = key(1); - unwind = 204; - const _301: Key.Key = fault(2, "Trips" as Fault.Fault); - unwind = 203; - tripped2 = [_298, _301] as [Key.Key, Key.Key]; - drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); - unwind = 205; - drop$Key_Key(tripped2); - unwind = 0; - drop$Key_Key(pair); - } else { - _427 = true; - _317 = key(1); - unwind = 245; - const _320: Key.Key = key(2); - _427 = false; - _316 = rt.ordMax(_317, _320, Key.cmp$Ord, rt.drop); - unwind = 202; - _427 = false; - const part = rt.u32Sub(_316.id, id); - const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; - const _310: string = rt.fmtFormat(["max ", args16[0]]); - unwind = 0; - rt.drop(_316); - Log.note(log, _310); - _426 = true; - _337 = key(5); - unwind = 243; - const _340: Key.Key = key(4); - _426 = false; - _336 = rt.ordMin(_337, _340, Key.cmp$Ord, rt.drop); - unwind = 201; - _426 = false; - const part2 = rt.u32Sub(_336.id, id); - const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; - const _330: string = rt.fmtFormat(["min ", args18[0]]); - unwind = 0; - rt.drop(_336); - Log.note(log, _330); - _425 = true; - _357 = key(2); - unwind = 241; - _360 = key(1); - unwind = 239; - _424 = true; - const _363: Key.Key = key(3); - _425 = false; - _424 = false; - _356 = rt.ordClamp(_357, _360, _363, Key.partialCmp$PartialOrd, rt.drop); - unwind = 200; - _424 = false; - _425 = false; - const part3 = rt.u32Sub(_356.id, id); - const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; - const _350: string = rt.fmtFormat(["clamped ", args20[0]]); - unwind = 0; - rt.drop(_356); - Log.note(log, _350); - _423 = true; - _380 = key(0); - unwind = 237; - _383 = key(1); - unwind = 235; - _422 = true; - const _386: Key.Key = key(3); - _423 = false; - _422 = false; - _379 = rt.ordClamp(_380, _383, _386, Key.partialCmp$PartialOrd, rt.drop); - unwind = 199; - _422 = false; - _423 = false; - const part4 = rt.u32Sub(_379.id, id); - const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; - const _373: string = rt.fmtFormat(["clamped ", args22[0]]); - unwind = 0; - rt.drop(_379); - Log.note(log, _373); - _421 = true; - _396 = key(2); - unwind = 233; - _399 = key(3); - unwind = 231; - _420 = true; - const _402: Key.Key = key(1); - _421 = false; - _420 = false; - const _395: Key.Key = rt.ordClamp(_396, _399, _402, Key.partialCmp$PartialOrd, rt.drop); - unwind = 0; - _420 = false; - _421 = false; - rt.drop(_395); - } + _435 = true; + _328 = key(1); + unwind = 247; + const _331: Key.Key = key(2); + _435 = false; + _327 = rt.ordMax(_328, _331, Key.partialCmp$PartialOrd, rt.drop); + unwind = 206; + _435 = false; + const part = rt.u32Sub(_327.id, id); + const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; + const _321: string = rt.fmtFormat(["max ", args16[0]]); + unwind = 0; + rt.drop(_327); + Log.note(log, _321); + _434 = true; + _348 = key(5); + unwind = 245; + const _351: Key.Key = key(4); + _434 = false; + _347 = rt.ordMin(_348, _351, Key.partialCmp$PartialOrd, rt.drop); + unwind = 205; + _434 = false; + const part2 = rt.u32Sub(_347.id, id); + const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; + const _341: string = rt.fmtFormat(["min ", args18[0]]); + unwind = 0; + rt.drop(_347); + Log.note(log, _341); + _433 = true; + _368 = key(2); + unwind = 243; + _371 = key(1); + unwind = 241; + _432 = true; + const _374: Key.Key = key(3); + _433 = false; + _432 = false; + _367 = rt.ordClamp(_368, _371, _374, Key.partialCmp$PartialOrd, rt.drop); + unwind = 204; + _432 = false; + _433 = false; + const part3 = rt.u32Sub(_367.id, id); + const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; + const _361: string = rt.fmtFormat(["clamped ", args20[0]]); + unwind = 0; + rt.drop(_367); + Log.note(log, _361); + _431 = true; + _391 = key(0); + unwind = 239; + _394 = key(1); + unwind = 237; + _430 = true; + const _397: Key.Key = key(3); + _431 = false; + _430 = false; + _390 = rt.ordClamp(_391, _394, _397, Key.partialCmp$PartialOrd, rt.drop); + unwind = 203; + _430 = false; + _431 = false; + const part4 = rt.u32Sub(_390.id, id); + const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; + const _384: string = rt.fmtFormat(["clamped ", args22[0]]); + unwind = 0; + rt.drop(_390); + Log.note(log, _384); + _429 = true; + _407 = key(1); + unwind = 235; + const _410: Key.Key = fault(2, "Trips" as Fault.Fault); + _429 = false; + const _406: Key.Key = rt.ordMax(_407, _410, Key.partialCmp$PartialOrd, rt.drop); + unwind = 0; + _429 = false; + rt.drop(_406); } Log.note(log, rt.fmtFormat(["unreached"])); } @@ -3468,167 +3476,175 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { if (unwind === 0) { throw e; } - if (unwind === 199) { - rt.drop(_379); + if (unwind === 203) { + rt.drop(_390); break b2; } - if (unwind === 200) { - rt.drop(_356); + if (unwind === 204) { + rt.drop(_367); break b2; } - if (unwind === 201) { - rt.drop(_336); + if (unwind === 205) { + rt.drop(_347); break b2; } - if (unwind === 202) { - rt.drop(_316); + if (unwind === 206) { + rt.drop(_327); break b2; } - if (unwind === 203) { + if (unwind === 207) { drop$Key_Key(tripped2); break b3; } - if (unwind === 204) { - rt.drop(_298); + if (unwind === 208) { + rt.drop(_309); break b3; } - if (unwind === 205) { + if (unwind === 209) { break b3; } - if (unwind === 206) { - rt.drop(_288); + if (unwind === 210) { + rt.drop(_299); break b2; } - if (unwind === 207) { + if (unwind === 211) { rt.dropAll(tripped_); break b4; } - if (unwind === 208) { + if (unwind === 212) { rt.dropAll(v13); break b4; } - if (unwind === 209) { + if (unwind === 213) { break b5; } - if (unwind === 210) { + if (unwind === 214) { break b5; } - if (unwind === 211) { + if (unwind === 215) { break b4; } - if (unwind === 212) { + if (unwind === 216) { rt.dropAll(v12); break b2; } - if (unwind === 213) { + if (unwind === 217) { break b6; } - if (unwind === 214) { + if (unwind === 218) { break b6; } - if (unwind === 215) { + if (unwind === 219) { rt.dropAll(v10); break b2; } - if (unwind === 216) { + if (unwind === 220) { rt.dropAll(v7); break b2; } - if (unwind === 217) { + if (unwind === 221) { rt.dropAll(v8); break b2; } - if (unwind === 218) { + if (unwind === 222) { break b7; } - if (unwind === 219) { + if (unwind === 223) { break b7; } - if (unwind === 220) { + if (unwind === 224) { break b7; } - if (unwind === 221) { + if (unwind === 225) { break b7; } - if (unwind === 222) { + if (unwind === 226) { rt.dropAll(v6); break b2; } - if (unwind === 223) { + if (unwind === 227) { rt.dropAll(v3); break b2; } - if (unwind === 224) { + if (unwind === 228) { rt.dropAll(v4); break b2; } - if (unwind === 225) { + if (unwind === 229) { break b8; } - if (unwind === 226) { + if (unwind === 230) { break b8; } - if (unwind === 227) { + if (unwind === 231) { break b8; } - if (unwind === 228) { + if (unwind === 232) { rt.dropAll(v2); break b2; } - if (unwind === 231) { - if (!_420) { + if (unwind === 235) { + if (!_429) { + break b2; + } + rt.drop(_407); + break b2; + } + if (unwind === 237) { + if (!_430) { break b9; } - rt.drop(_399); + rt.drop(_394); break b9; } - if (unwind === 233) { + if (unwind === 239) { break b9; } - if (unwind === 235) { - if (!_422) { + if (unwind === 241) { + if (!_432) { break b10; } - rt.drop(_383); + rt.drop(_371); break b10; } - if (unwind === 237) { + if (unwind === 243) { break b10; } - if (unwind === 239) { - if (_424) { - rt.drop(_360); - } - } else if (unwind !== 241) { - if (unwind === 243) { - if (!_426) { - break b2; - } - rt.drop(_337); + if (unwind === 245) { + if (!_434) { break b2; } - if (!_427) { + rt.drop(_348); + break b2; + } + if (unwind === 247) { + if (!_435) { break b2; } - rt.drop(_317); + rt.drop(_328); break b2; } - if (!_425) { - break b2; + if (unwind === 249) { + if (_436) { + rt.drop(_179); + } } - rt.drop(_357); - break b2; + if (!_437) { + break b7; + } + rt.drop(_176); + break b7; } - if (!_423) { + if (!_433) { break b2; } - rt.drop(_380); + rt.drop(_368); break b2; } - if (!_421) { + if (!_431) { break b2; } - rt.drop(_396); + rt.drop(_391); break b2; } rt.dropAll(v); @@ -3640,7 +3656,7 @@ export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { rt.dropAll(v9); break b2; } - rt.dropAll(_260); + rt.dropAll(_271); } rt.dropAll(v11); break b2; diff --git a/ts/fixtures/task/src/drops.rs b/ts/fixtures/task/src/drops.rs index 6a954e371..bc8d1c486 100644 --- a/ts/fixtures/task/src/drops.rs +++ b/ts/fixtures/task/src/drops.rs @@ -801,7 +801,8 @@ fn edited(log: &Log, id: u32, at: u8) { log.note(format!("deduped {}", ids(&v))); v.dedup_by(|a, b| a.id > b.id); log.note(format!("deduped {}", ids(&v))); - return; + // Bounds out of order, so `clamp`'s assertion panics holding all three. + drop(key(2).clamp(key(3), key(1))); } 3 => { let mut v = list![key(1), fault(1, Fault::Blows), key(1), key(2)]; @@ -830,7 +831,8 @@ fn edited(log: &Log, id: u32, at: u8) { log.note(format!("min {}", key(5).min(key(4)).id - id)); log.note(format!("clamped {}", key(2).clamp(key(1), key(3)).id - id)); log.note(format!("clamped {}", key(0).clamp(key(1), key(3)).id - id)); - drop(key(2).clamp(key(3), key(1))); + // A comparison that panics in `max`, holding both. + drop(key(1).max(fault(2, Fault::Trips))); } } log.note(format!("unreached")); diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index 9c604ea7a..3008975fb 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -95,12 +95,15 @@ export function cmpArc(cmp: (a: T, b: T) => O return (a, b) => cmp(a.value, b.value); } -/** `cmp(a, b)`, which drops `b` and then `a` if it panics, as `max_by`'s unwinding does. */ -function compare(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): Ordering { +/** + * `other < self` of `Ord::max` and `min`, by `cmp`, a `partial_cmp`, which drops `other` and + * then `self` if it panics, as their unwinding does. + */ +function less(self: T, other: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): boolean { try { - return cmp(a, b); + return cmp(other, self) === -1; } catch (e) { - dropPair(b, a, drop, drop); + dropPair(other, self, drop, drop); throw e; } } @@ -126,9 +129,9 @@ export function ordClamp(a: T, min: T, max: T, cmp: (a: T, b: T) => Ordering return out === 1 ? min : out === 2 ? max : a; } -/** `Ord::max`, by `cmp`: `b` unless `a` is greater, and the other drops. */ -export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): T { - if (compare(a, b, cmp, drop) > 0) { +/** `Ord::max`, by `cmp`, a `partial_cmp`: `a` if `b < a`, or else `b`, and the other drops. */ +export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + if (less(a, b, cmp, drop)) { drop?.(b); return a; } @@ -136,9 +139,9 @@ export function ordMax(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (val return b; } -/** `Ord::min`, by `cmp`: `a` unless it is greater, and the other drops. */ -export function ordMin(a: T, b: T, cmp: (a: T, b: T) => Ordering, drop?: (value: T) => void): T { - if (compare(a, b, cmp, drop) > 0) { +/** `Ord::min`, by `cmp`, a `partial_cmp`: `b` if `b < a`, or else `a`, and the other drops. */ +export function ordMin(a: T, b: T, cmp: (a: T, b: T) => Ordering | undefined, drop?: (value: T) => void): T { + if (less(a, b, cmp, drop)) { drop?.(a); return b; } diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index c1a81eca7..6388bd3c1 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -57,15 +57,20 @@ pub fn call<'tcx>( let f = hash_fn(b, t, hasher, span); return Ok(Some(f.call(args))); } - // `Ord`'s defaults, of a std type or the crate's: `clamp` compares by `PartialOrd`. + // `Ord`'s defaults, of a std type or the crate's, which compare by `PartialOrd`'s `<`, + // `<=`, and `>`, and so by `partial_cmp` while those are the defaults. ("Ord", "max" | "min" | "clamp", ..) if let Some(t) = self_ty => { let t = peel(b, t); let local = matches!(t.kind(), ty::Adt(adt, _) if adt.did().is_local()); if !(std_key(b, t) || local) || Int::of(t).is_some() { return Err(args); } + let tests: &[&str] = if name == "clamp" { &["le", "lt", "gt"] } else { &["lt"] }; + if let Some(test) = tests.iter().find(|test| own_test(b, t, test)) { + return Ok(Some(b.err(span, own_test_err(t, test)))); + } let mut values = args; - values.push(cmp_fn(b, t, name == "clamp", span)); + values.push(cmp_fn(b, t, true, span)); // What drops the operands it does not return. let Some(droppers) = b.t.droppers(self_ty, span) else { return Ok(Some(Expr::undefined())); @@ -85,6 +90,9 @@ pub fn call<'tcx>( if matches!(t.kind(), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_)) || !std_key(b, t) { return Err(args); } + if own_test(b, t, name) { + return Ok(Some(b.err(span, own_test_err(t, name)))); + } let order = cmp_fn(b, t, true, span).call(args); let test = match name { "lt" => library::Inherited::Lt, @@ -519,6 +527,31 @@ fn own_ne<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { } } +/// Whether `ty`'s `PartialOrd::{test}`, `lt` or another of its tests, reaches the crate's +/// own `test` of a type it holds, which `partial_cmp` stands for only while that is the +/// default: through a tuple's last element, `Arc`s, and `Reverse`s. +pub fn own_test<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>, test: &str) -> bool { + let tcx = b.t.tcx; + let ty = peel(b, ty); + match ty.kind() { + ty::Tuple(tys) => tys.last().is_some_and(|&t| own_test(b, t, test)), + ty::Adt(..) if let Some(inner) = arc_of(b, ty).or_else(|| reverse_of(b, ty)) => own_test(b, inner, test), + ty::Adt(adt, _) if adt.did().is_local() => { + let f = trait_fn(tcx, "PartialOrd", test); + Instance::try_resolve(tcx, b.t.typing_env_pub(), f, tcx.mk_args(&[ty.into(), ty.into()])) + .ok() + .flatten() + .is_some_and(|instance| instance.def_id() != f) + } + _ => false, + } +} + +/// The refusal of a comparison that reaches the crate's own `test` of `ty`. +pub fn own_test_err(ty: Ty<'_>, test: &str) -> String { + format!("comparing `{ty}` through its own `PartialOrd::{test}`, which is not supported yet") +} + /// Whether `ty`'s `PartialEq` is derived, so it compares as JS compares its tags. fn derived_eq<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { let tcx = b.t.tcx; diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index a94556559..96b82c287 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -897,8 +897,13 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ) if !is_u8(targ(gargs, 0)) => { let mut values = args; match name.as_str() { + // By `<`, which is `partial_cmp`'s while it is the default. "sort" | "sort_unstable" => { - values.push(super::collections::cmp_fn(b, targ(gargs, 0), true, span)); + let elem = targ(gargs, 0); + if super::collections::own_test(b, elem, "lt") { + return Some(b.err(span, super::collections::own_test_err(elem, "lt"))); + } + values.push(super::collections::cmp_fn(b, elem, true, span)); Expr::rt("sliceSortBy", values) } "sort_by" | "sort_unstable_by" => Expr::rt("sliceSortBy", values), @@ -910,6 +915,9 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec format!("`slice::{name}` by `{key}`, which drops, which is not supported yet"), )); } + if super::collections::own_test(b, key, "lt") { + return Some(b.err(span, super::collections::own_test_err(key, "lt"))); + } values.push(super::collections::cmp_fn(b, key, true, span)); Expr::rt("sliceSortByKey", values) } From b49b28f703f43a3e749350d3e17c98ef23c2daf7 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:56:10 -0700 Subject: [PATCH 10/11] fix(ts): reach the edited drops scenario, and unwind clamp and split_off as std does - drops.rs dispatched `arg % 22` after the merge, so `edited` at 22 never ran. - `ordClamp` drops the operands it does not return under unwinding, so a panicking drop still drops the rest. - `btreeSplitOff` compares before it moves an entry, so a panicking `Ord` leaves the map whole. Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/task/expected/drops.ts | 1031 ++++++++++++++-------------- ts/fixtures/task/src/drops.rs | 5 +- ts/runtime/rt/collections.ts | 26 +- ts/tests/retain.ts | 32 + 4 files changed, 582 insertions(+), 512 deletions(-) diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index a5b18a7e7..5c5333df2 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -95,7 +95,7 @@ export function run(log: Log.Log, id: rt.u32, arg: rt.u8): void { rt.panicFmt(["d", args18[0], " at ", args18[1]]); } }; - const _13: rt.u8 = rt.u8Rem(arg, 22); + const _13: rt.u8 = rt.u8Rem(arg, 23); if (_13 === 19) { scoped(log, id, at); } else if (_13 === 20) { @@ -3302,546 +3302,579 @@ export function grown(log: Log.Log, id: rt.u32, at: rt.u8, tree: boolean): void export function edited(log: Log.Log, id: rt.u32, at: rt.u8): void { let v!: Key.Key[]; let v2!: Key.Key[]; + let _72!: Key.Key; + let _75!: Key.Key; let v3!: Key.Key[]; let v4!: Key.Key[]; let v5!: Key.Key[]; let v6!: Key.Key[]; - let _176!: Key.Key; - let _179!: Key.Key; + let _188!: Key.Key; + let _191!: Key.Key; let v7!: Key.Key[]; let v8!: Key.Key[]; let v9!: Key.Key[]; let v10!: Key.Key[]; let v11!: Key.Key[]; let v12!: Key.Key[]; - let _271!: Key.Key[]; + let _283!: Key.Key[]; let tripped_!: Key.Key[]; let v13!: Key.Key[]; let pair!: [Key.Key, Key.Key]; - let _299!: Key.Key; + let _311!: Key.Key; let tripped2!: [Key.Key, Key.Key]; - let _309!: Key.Key; - let _327!: Key.Key; - let _328!: Key.Key; - let _347!: Key.Key; - let _348!: Key.Key; - let _367!: Key.Key; - let _368!: Key.Key; - let _371!: Key.Key; - let _390!: Key.Key; - let _391!: Key.Key; - let _394!: Key.Key; - let _407!: Key.Key; - let _429!: boolean; - let _430!: boolean; - let _431!: boolean; - let _432!: boolean; - let _433!: boolean; - let _434!: boolean; - let _435!: boolean; - let _436!: boolean; - let _437!: boolean; + let _321!: Key.Key; + let _339!: Key.Key; + let _340!: Key.Key; + let _359!: Key.Key; + let _360!: Key.Key; + let _379!: Key.Key; + let _380!: Key.Key; + let _383!: Key.Key; + let _402!: Key.Key; + let _403!: Key.Key; + let _406!: Key.Key; + let _419!: Key.Key; + let _441!: boolean; + let _442!: boolean; + let _443!: boolean; + let _444!: boolean; + let _445!: boolean; + let _446!: boolean; + let _447!: boolean; + let _448!: boolean; + let _449!: boolean; + let _450!: boolean; + let _451!: boolean; let unwind: number = 0; try { - b0: { - _437 = false; - _436 = false; - _435 = false; - _434 = false; - _433 = false; - _432 = false; - _431 = false; - _430 = false; - _429 = false; - const key: (a0: rt.u32) => Key.Key = (n: rt.u32): Key.Key => { - return Key.new(rt.u32Add(id, n), Log.clone$Clone(log)); - }; - const fault: (a0: rt.u32, a1: Fault.Fault) => Key.Key = (n2: rt.u32, fault2: Fault.Fault): Key.Key => { - return Key.faulty(rt.u32Add(id, n2), Log.clone$Clone(log), fault2); - }; - const ids: (a0: Key.Key[]) => string = (v14: Key.Key[]): string => { - return rt.iterToArray(rt.iterMap(rt.iterSlice(v14), (k: Key.Key): string => { - const _46: rt.u32 = rt.u32Sub(k.id, id); - return rt.fmtToString((f: rt.Formatter) => rt.u32Display(_46, f)); - })).join(","); - }; - if (at === 0) { - v2 = []; - unwind = 232; - const _14: Key.Key = key(1); - v2.push(_14); - const _19: Key.Key = key(2); - v2.push(_19); - const _24: Key.Key = key(3); - v2.push(_24); - const _29: Key.Key = key(4); - v2.push(_29); - unwind = 231; - v = v2; - rt.vecRetain(v, (k4: Key.Key): boolean => { - return rt.u32Rem(rt.u32Sub(k4.id, id), 2) === 1; - }, rt.drop); - const _42: string = ids(v); - unwind = 230; - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _42)]; - const _38: string = rt.fmtFormat(["retained ", args2[0]]); - unwind = 231; - Log.note(log, _38); - rt.vecRetain(v, (k5: Key.Key): boolean => { - return k5.id !== rt.u32Add(id, 3); - }, rt.drop); - const _61: string = ids(v); - unwind = 229; - const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _61)]; - const _57: string = rt.fmtFormat(["retained ", args4[0]]); - unwind = 231; - Log.note(log, _57); - unwind = 0; - rt.dropAll(v); - break b0; - } - if (at === 1) { - v4 = []; - unwind = 228; - const _74: Key.Key = key(1); - v4.push(_74); - const _79: Key.Key = key(2); - v4.push(_79); - const _84: Key.Key = key(3); - v4.push(_84); - const _89: Key.Key = key(4); - v4.push(_89); - unwind = 227; - v3 = v4; - rt.vecRetain(v3, (k3: Key.Key): boolean => { - if (!(k3.id === rt.u32Add(id, 3))) { - return k3.id !== rt.u32Add(id, 2); - } - const arg = k3.id; - const args24: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg, f)]; - rt.panicFmt(["k", args24[0], " retained"]); - }, rt.drop); - unwind = 0; - rt.dropAll(v3); - } else if (at === 2) { - v6 = []; - unwind = 226; - const _100: Key.Key = key(1); - v6.push(_100); - const _105: Key.Key = key(1); - v6.push(_105); - const _110: Key.Key = key(2); - v6.push(_110); - const _115: Key.Key = key(2); - v6.push(_115); - const _120: Key.Key = key(3); - v6.push(_120); - unwind = 225; - v5 = v6; - rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); - const _131: string = ids(v5); - unwind = 224; - const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _131)]; - const _127: string = rt.fmtFormat(["deduped ", args6[0]]); - unwind = 225; - Log.note(log, _127); - rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { - return rt.u32Div(k2.id, 2); - }, rt.same, rt.drop); - const _148: string = ids(v5); - unwind = 223; - const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _148)]; - const _144: string = rt.fmtFormat(["deduped ", args8[0]]); - unwind = 225; - Log.note(log, _144); - rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { - return a.id > b.id; - }, rt.drop); - const _165: string = ids(v5); - unwind = 222; - const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _165)]; - const _161: string = rt.fmtFormat(["deduped ", args10[0]]); - unwind = 225; - Log.note(log, _161); - _176 = key(2); - unwind = 251; - _437 = true; - _179 = key(3); - unwind = 249; - _436 = true; - const _182: Key.Key = key(1); - _437 = false; - _436 = false; - const _175: Key.Key = rt.ordClamp(_176, _179, _182, Key.partialCmp$PartialOrd, rt.drop); - unwind = 225; - _436 = false; - _437 = false; - rt.drop(_175); - unwind = 0; - rt.dropAll(v5); - } else if (at === 3) { - v8 = []; - unwind = 221; - const _189: Key.Key = key(1); - v8.push(_189); - const _194: Key.Key = fault(1, "Blows" as Fault.Fault); - v8.push(_194); - const _200: Key.Key = key(1); - v8.push(_200); - const _205: Key.Key = key(2); - v8.push(_205); - unwind = 220; - v7 = v8; - rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); - unwind = 0; - rt.dropAll(v7); - } else if (at === 4) { - v10 = []; - unwind = 219; - const _214: Key.Key = key(1); - v10.push(_214); - const _219: Key.Key = key(2); - v10.push(_219); - const _224: Key.Key = key(3); - v10.push(_224); - unwind = 218; - v9 = v10; - rt.drop(rt.vecSwapRemove(v9, 0)); - const _236: string = ids(v9); - unwind = 217; - const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _236)]; - const _232: string = rt.fmtFormat(["swapped ", args12[0]]); - unwind = 218; - Log.note(log, _232); - rt.drop(rt.vecSwapRemove(v9, 3)); - unwind = 0; - rt.dropAll(v9); - } else if (at === 5) { - v12 = []; - unwind = 216; - const _252: Key.Key = key(1); - v12.push(_252); - const _257: Key.Key = key(2); - v12.push(_257); - unwind = 215; - v11 = v12; - _271 = rt.vecClone(v11, Key.clone$Clone, rt.drop); - unwind = 214; - const _266: string = ids(_271); - unwind = 213; - const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _266)]; - const _262: string = rt.fmtFormat(["cloned ", args14[0]]); - unwind = 215; - rt.dropAll(_271); - Log.note(log, _262); - v13 = []; - unwind = 212; - const _281: Key.Key = key(1); - v13.push(_281); - const _286: Key.Key = fault(2, "Trips" as Fault.Fault); - v13.push(_286); - const _292: Key.Key = key(3); - v13.push(_292); - unwind = 211; - tripped_ = v13; - rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); - unwind = 215; - rt.dropAll(tripped_); - unwind = 0; - rt.dropAll(v11); - } else if (at === 6) { - _299 = key(1); - unwind = 210; - const _302: Key.Key = key(2); - unwind = 209; - pair = [_299, _302] as [Key.Key, Key.Key]; - drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); - _309 = key(1); - unwind = 208; - const _312: Key.Key = fault(2, "Trips" as Fault.Fault); - unwind = 207; - tripped2 = [_309, _312] as [Key.Key, Key.Key]; - drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); - unwind = 209; - drop$Key_Key(tripped2); - unwind = 0; - drop$Key_Key(pair); - } else { - _435 = true; - _328 = key(1); - unwind = 247; - const _331: Key.Key = key(2); - _435 = false; - _327 = rt.ordMax(_328, _331, Key.partialCmp$PartialOrd, rt.drop); - unwind = 206; - _435 = false; - const part = rt.u32Sub(_327.id, id); - const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; - const _321: string = rt.fmtFormat(["max ", args16[0]]); - unwind = 0; - rt.drop(_327); - Log.note(log, _321); - _434 = true; - _348 = key(5); - unwind = 245; - const _351: Key.Key = key(4); - _434 = false; - _347 = rt.ordMin(_348, _351, Key.partialCmp$PartialOrd, rt.drop); - unwind = 205; - _434 = false; - const part2 = rt.u32Sub(_347.id, id); - const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; - const _341: string = rt.fmtFormat(["min ", args18[0]]); - unwind = 0; - rt.drop(_347); - Log.note(log, _341); - _433 = true; - _368 = key(2); - unwind = 243; - _371 = key(1); - unwind = 241; - _432 = true; - const _374: Key.Key = key(3); - _433 = false; - _432 = false; - _367 = rt.ordClamp(_368, _371, _374, Key.partialCmp$PartialOrd, rt.drop); - unwind = 204; - _432 = false; - _433 = false; - const part3 = rt.u32Sub(_367.id, id); - const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; - const _361: string = rt.fmtFormat(["clamped ", args20[0]]); - unwind = 0; - rt.drop(_367); - Log.note(log, _361); - _431 = true; - _391 = key(0); - unwind = 239; - _394 = key(1); - unwind = 237; - _430 = true; - const _397: Key.Key = key(3); - _431 = false; - _430 = false; - _390 = rt.ordClamp(_391, _394, _397, Key.partialCmp$PartialOrd, rt.drop); - unwind = 203; - _430 = false; - _431 = false; - const part4 = rt.u32Sub(_390.id, id); - const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; - const _384: string = rt.fmtFormat(["clamped ", args22[0]]); - unwind = 0; - rt.drop(_390); - Log.note(log, _384); - _429 = true; - _407 = key(1); - unwind = 235; - const _410: Key.Key = fault(2, "Trips" as Fault.Fault); - _429 = false; - const _406: Key.Key = rt.ordMax(_407, _410, Key.partialCmp$PartialOrd, rt.drop); - unwind = 0; - _429 = false; - rt.drop(_406); - } - Log.note(log, rt.fmtFormat(["unreached"])); + _451 = false; + _450 = false; + _449 = false; + _448 = false; + _447 = false; + _446 = false; + _445 = false; + _444 = false; + _443 = false; + _442 = false; + _441 = false; + const key: (a0: rt.u32) => Key.Key = (n: rt.u32): Key.Key => { + return Key.new(rt.u32Add(id, n), Log.clone$Clone(log)); + }; + const fault: (a0: rt.u32, a1: Fault.Fault) => Key.Key = (n2: rt.u32, fault2: Fault.Fault): Key.Key => { + return Key.faulty(rt.u32Add(id, n2), Log.clone$Clone(log), fault2); + }; + const ids: (a0: Key.Key[]) => string = (v14: Key.Key[]): string => { + return rt.iterToArray(rt.iterMap(rt.iterSlice(v14), (k: Key.Key): string => { + const _46: rt.u32 = rt.u32Sub(k.id, id); + return rt.fmtToString((f: rt.Formatter) => rt.u32Display(_46, f)); + })).join(","); + }; + if (at === 0) { + v2 = []; + unwind = 237; + const _14: Key.Key = key(1); + v2.push(_14); + const _19: Key.Key = key(2); + v2.push(_19); + const _24: Key.Key = key(3); + v2.push(_24); + const _29: Key.Key = key(4); + v2.push(_29); + unwind = 236; + v = v2; + rt.vecRetain(v, (k4: Key.Key): boolean => { + return rt.u32Rem(rt.u32Sub(k4.id, id), 2) === 1; + }, rt.drop); + const _42: string = ids(v); + unwind = 235; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _42)]; + const _38: string = rt.fmtFormat(["retained ", args2[0]]); + unwind = 236; + Log.note(log, _38); + rt.vecRetain(v, (k5: Key.Key): boolean => { + return k5.id !== rt.u32Add(id, 3); + }, rt.drop); + const _61: string = ids(v); + unwind = 234; + const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _61)]; + const _57: string = rt.fmtFormat(["retained ", args4[0]]); + unwind = 236; + Log.note(log, _57); + _72 = key(2); + unwind = 260; + _451 = true; + _75 = key(1); + unwind = 258; + _450 = true; + const _78: Key.Key = fault(3, "Blows" as Fault.Fault); + _451 = false; + _450 = false; + const _71: Key.Key = rt.ordClamp(_72, _75, _78, Key.partialCmp$PartialOrd, rt.drop); + unwind = 236; + _450 = false; + _451 = false; + rt.drop(_71); + unwind = 0; + rt.dropAll(v); + } else if (at === 1) { + v4 = []; + unwind = 233; + const _86: Key.Key = key(1); + v4.push(_86); + const _91: Key.Key = key(2); + v4.push(_91); + const _96: Key.Key = key(3); + v4.push(_96); + const _101: Key.Key = key(4); + v4.push(_101); + unwind = 232; + v3 = v4; + rt.vecRetain(v3, (k3: Key.Key): boolean => { + if (!(k3.id === rt.u32Add(id, 3))) { + return k3.id !== rt.u32Add(id, 2); + } + const arg = k3.id; + const args24: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg, f)]; + rt.panicFmt(["k", args24[0], " retained"]); + }, rt.drop); + unwind = 0; + rt.dropAll(v3); + } else if (at === 2) { + v6 = []; + unwind = 231; + const _112: Key.Key = key(1); + v6.push(_112); + const _117: Key.Key = key(1); + v6.push(_117); + const _122: Key.Key = key(2); + v6.push(_122); + const _127: Key.Key = key(2); + v6.push(_127); + const _132: Key.Key = key(3); + v6.push(_132); + unwind = 230; + v5 = v6; + rt.vecDedupBy(v5, Key.eq$PartialEq, rt.drop); + const _143: string = ids(v5); + unwind = 229; + const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _143)]; + const _139: string = rt.fmtFormat(["deduped ", args6[0]]); + unwind = 230; + Log.note(log, _139); + rt.vecDedupByKey(v5, (k2: Key.Key): rt.u32 => { + return rt.u32Div(k2.id, 2); + }, rt.same, rt.drop); + const _160: string = ids(v5); + unwind = 228; + const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _160)]; + const _156: string = rt.fmtFormat(["deduped ", args8[0]]); + unwind = 230; + Log.note(log, _156); + rt.vecDedupBy(v5, (a: Key.Key, b: Key.Key): boolean => { + return a.id > b.id; + }, rt.drop); + const _177: string = ids(v5); + unwind = 227; + const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _177)]; + const _173: string = rt.fmtFormat(["deduped ", args10[0]]); + unwind = 230; + Log.note(log, _173); + _188 = key(2); + unwind = 256; + _449 = true; + _191 = key(3); + unwind = 254; + _448 = true; + const _194: Key.Key = key(1); + _449 = false; + _448 = false; + const _187: Key.Key = rt.ordClamp(_188, _191, _194, Key.partialCmp$PartialOrd, rt.drop); + unwind = 230; + _448 = false; + _449 = false; + rt.drop(_187); + unwind = 0; + rt.dropAll(v5); + } else if (at === 3) { + v8 = []; + unwind = 226; + const _201: Key.Key = key(1); + v8.push(_201); + const _206: Key.Key = fault(1, "Blows" as Fault.Fault); + v8.push(_206); + const _212: Key.Key = key(1); + v8.push(_212); + const _217: Key.Key = key(2); + v8.push(_217); + unwind = 225; + v7 = v8; + rt.vecDedupBy(v7, Key.eq$PartialEq, rt.drop); + unwind = 0; + rt.dropAll(v7); + } else if (at === 4) { + v10 = []; + unwind = 224; + const _226: Key.Key = key(1); + v10.push(_226); + const _231: Key.Key = key(2); + v10.push(_231); + const _236: Key.Key = key(3); + v10.push(_236); + unwind = 223; + v9 = v10; + rt.drop(rt.vecSwapRemove(v9, 0)); + const _248: string = ids(v9); + unwind = 222; + const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _248)]; + const _244: string = rt.fmtFormat(["swapped ", args12[0]]); + unwind = 223; + Log.note(log, _244); + rt.drop(rt.vecSwapRemove(v9, 3)); + unwind = 0; + rt.dropAll(v9); + } else if (at === 5) { + v12 = []; + unwind = 221; + const _264: Key.Key = key(1); + v12.push(_264); + const _269: Key.Key = key(2); + v12.push(_269); + unwind = 220; + v11 = v12; + _283 = rt.vecClone(v11, Key.clone$Clone, rt.drop); + unwind = 219; + const _278: string = ids(_283); + unwind = 218; + const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, _278)]; + const _274: string = rt.fmtFormat(["cloned ", args14[0]]); + unwind = 220; + rt.dropAll(_283); + Log.note(log, _274); + v13 = []; + unwind = 217; + const _293: Key.Key = key(1); + v13.push(_293); + const _298: Key.Key = fault(2, "Trips" as Fault.Fault); + v13.push(_298); + const _304: Key.Key = key(3); + v13.push(_304); + unwind = 216; + tripped_ = v13; + rt.dropAll(rt.vecClone(tripped_, Key.clone$Clone, rt.drop)); + unwind = 220; + rt.dropAll(tripped_); + unwind = 0; + rt.dropAll(v11); + } else if (at === 6) { + _311 = key(1); + unwind = 215; + const _314: Key.Key = key(2); + unwind = 214; + pair = [_311, _314] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(pair, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + _321 = key(1); + unwind = 213; + const _324: Key.Key = fault(2, "Trips" as Fault.Fault); + unwind = 212; + tripped2 = [_321, _324] as [Key.Key, Key.Key]; + drop$Key_Key(rt.tupleClone(tripped2, [Key.clone$Clone, Key.clone$Clone], [rt.drop, rt.drop])); + unwind = 214; + drop$Key_Key(tripped2); + unwind = 0; + drop$Key_Key(pair); + } else { + _447 = true; + _340 = key(1); + unwind = 252; + const _343: Key.Key = key(2); + _447 = false; + _339 = rt.ordMax(_340, _343, Key.partialCmp$PartialOrd, rt.drop); + unwind = 211; + _447 = false; + const part = rt.u32Sub(_339.id, id); + const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part, f)]; + const _333: string = rt.fmtFormat(["max ", args16[0]]); + unwind = 0; + rt.drop(_339); + Log.note(log, _333); + _446 = true; + _360 = key(5); + unwind = 250; + const _363: Key.Key = key(4); + _446 = false; + _359 = rt.ordMin(_360, _363, Key.partialCmp$PartialOrd, rt.drop); + unwind = 210; + _446 = false; + const part2 = rt.u32Sub(_359.id, id); + const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part2, f)]; + const _353: string = rt.fmtFormat(["min ", args18[0]]); + unwind = 0; + rt.drop(_359); + Log.note(log, _353); + _445 = true; + _380 = key(2); + unwind = 248; + _383 = key(1); + unwind = 246; + _444 = true; + const _386: Key.Key = key(3); + _445 = false; + _444 = false; + _379 = rt.ordClamp(_380, _383, _386, Key.partialCmp$PartialOrd, rt.drop); + unwind = 209; + _444 = false; + _445 = false; + const part3 = rt.u32Sub(_379.id, id); + const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part3, f)]; + const _373: string = rt.fmtFormat(["clamped ", args20[0]]); + unwind = 0; + rt.drop(_379); + Log.note(log, _373); + _443 = true; + _403 = key(0); + unwind = 244; + _406 = key(1); + unwind = 242; + _442 = true; + const _409: Key.Key = key(3); + _443 = false; + _442 = false; + _402 = rt.ordClamp(_403, _406, _409, Key.partialCmp$PartialOrd, rt.drop); + unwind = 208; + _442 = false; + _443 = false; + const part4 = rt.u32Sub(_402.id, id); + const args22: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; + const _396: string = rt.fmtFormat(["clamped ", args22[0]]); + unwind = 0; + rt.drop(_402); + Log.note(log, _396); + _441 = true; + _419 = key(1); + unwind = 240; + const _422: Key.Key = fault(2, "Trips" as Fault.Fault); + _441 = false; + const _418: Key.Key = rt.ordMax(_419, _422, Key.partialCmp$PartialOrd, rt.drop); + unwind = 0; + _441 = false; + rt.drop(_418); } + Log.note(log, rt.fmtFormat(["unreached"])); } catch (e) { - b2: { - b3: { - b4: { - b5: { - b6: { - b7: { - b8: { - b9: { - b10: { - if (unwind === 0) { - throw e; - } - if (unwind === 203) { - rt.drop(_390); - break b2; - } - if (unwind === 204) { - rt.drop(_367); - break b2; - } - if (unwind === 205) { - rt.drop(_347); - break b2; - } - if (unwind === 206) { - rt.drop(_327); - break b2; - } - if (unwind === 207) { - drop$Key_Key(tripped2); - break b3; - } - if (unwind === 208) { - rt.drop(_309); - break b3; - } - if (unwind === 209) { - break b3; - } - if (unwind === 210) { - rt.drop(_299); - break b2; - } - if (unwind === 211) { - rt.dropAll(tripped_); - break b4; - } - if (unwind === 212) { - rt.dropAll(v13); - break b4; - } - if (unwind === 213) { - break b5; - } - if (unwind === 214) { - break b5; - } - if (unwind === 215) { - break b4; - } - if (unwind === 216) { - rt.dropAll(v12); - break b2; - } - if (unwind === 217) { - break b6; - } - if (unwind === 218) { - break b6; - } - if (unwind === 219) { - rt.dropAll(v10); - break b2; - } - if (unwind === 220) { - rt.dropAll(v7); - break b2; - } - if (unwind === 221) { - rt.dropAll(v8); - break b2; - } - if (unwind === 222) { - break b7; - } - if (unwind === 223) { - break b7; - } - if (unwind === 224) { - break b7; - } - if (unwind === 225) { - break b7; - } - if (unwind === 226) { - rt.dropAll(v6); - break b2; - } - if (unwind === 227) { - rt.dropAll(v3); - break b2; - } - if (unwind === 228) { - rt.dropAll(v4); - break b2; - } - if (unwind === 229) { - break b8; - } - if (unwind === 230) { - break b8; - } - if (unwind === 231) { - break b8; - } - if (unwind === 232) { - rt.dropAll(v2); - break b2; - } - if (unwind === 235) { - if (!_429) { + b1: { + b2: { + b3: { + b4: { + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + if (unwind === 0) { + throw e; + } + if (unwind === 208) { + rt.drop(_402); + break b1; + } + if (unwind === 209) { + rt.drop(_379); + break b1; + } + if (unwind === 210) { + rt.drop(_359); + break b1; + } + if (unwind === 211) { + rt.drop(_339); + break b1; + } + if (unwind === 212) { + drop$Key_Key(tripped2); break b2; } - rt.drop(_407); - break b2; - } - if (unwind === 237) { - if (!_430) { + if (unwind === 213) { + rt.drop(_321); + break b2; + } + if (unwind === 214) { + break b2; + } + if (unwind === 215) { + rt.drop(_311); + break b1; + } + if (unwind === 216) { + rt.dropAll(tripped_); + break b3; + } + if (unwind === 217) { + rt.dropAll(v13); + break b3; + } + if (unwind === 218) { + break b4; + } + if (unwind === 219) { + break b4; + } + if (unwind === 220) { + break b3; + } + if (unwind === 221) { + rt.dropAll(v12); + break b1; + } + if (unwind === 222) { + break b5; + } + if (unwind === 223) { + break b5; + } + if (unwind === 224) { + rt.dropAll(v10); + break b1; + } + if (unwind === 225) { + rt.dropAll(v7); + break b1; + } + if (unwind === 226) { + rt.dropAll(v8); + break b1; + } + if (unwind === 227) { + break b6; + } + if (unwind === 228) { + break b6; + } + if (unwind === 229) { + break b6; + } + if (unwind === 230) { + break b6; + } + if (unwind === 231) { + rt.dropAll(v6); + break b1; + } + if (unwind === 232) { + rt.dropAll(v3); + break b1; + } + if (unwind === 233) { + rt.dropAll(v4); + break b1; + } + if (unwind === 234) { + break b7; + } + if (unwind === 235) { + break b7; + } + if (unwind === 236) { + break b7; + } + if (unwind === 237) { + rt.dropAll(v2); + break b1; + } + if (unwind === 240) { + if (!_441) { + break b1; + } + rt.drop(_419); + break b1; + } + if (unwind === 242) { + if (!_442) { + break b8; + } + rt.drop(_406); + break b8; + } + if (unwind === 244) { + break b8; + } + if (unwind === 246) { + if (!_444) { + break b9; + } + rt.drop(_383); break b9; } - rt.drop(_394); - break b9; - } - if (unwind === 239) { - break b9; - } - if (unwind === 241) { - if (!_432) { + if (unwind === 248) { + break b9; + } + if (unwind === 250) { + if (!_446) { + break b1; + } + rt.drop(_360); + break b1; + } + if (unwind === 252) { + if (!_447) { + break b1; + } + rt.drop(_340); + break b1; + } + if (unwind === 254) { + if (!_448) { + break b10; + } + rt.drop(_191); break b10; } - rt.drop(_371); - break b10; - } - if (unwind === 243) { - break b10; - } - if (unwind === 245) { - if (!_434) { - break b2; + if (unwind === 256) { + break b10; } - rt.drop(_348); - break b2; - } - if (unwind === 247) { - if (!_435) { - break b2; + if (unwind === 258) { + if (_450) { + rt.drop(_75); + } } - rt.drop(_328); - break b2; - } - if (unwind === 249) { - if (_436) { - rt.drop(_179); + if (!_451) { + break b7; } - } - if (!_437) { + rt.drop(_72); break b7; } - rt.drop(_176); - break b7; + if (!_449) { + break b6; + } + rt.drop(_188); + break b6; } - if (!_433) { - break b2; + if (!_445) { + break b1; } - rt.drop(_368); - break b2; + rt.drop(_380); + break b1; } - if (!_431) { - break b2; + if (!_443) { + break b1; } - rt.drop(_391); - break b2; + rt.drop(_403); + break b1; } rt.dropAll(v); - break b2; + break b1; } rt.dropAll(v5); - break b2; + break b1; } rt.dropAll(v9); - break b2; + break b1; } - rt.dropAll(_271); + rt.dropAll(_283); } rt.dropAll(v11); - break b2; + break b1; } drop$Key_Key(pair); } diff --git a/ts/fixtures/task/src/drops.rs b/ts/fixtures/task/src/drops.rs index a1c054062..16cbcc57c 100644 --- a/ts/fixtures/task/src/drops.rs +++ b/ts/fixtures/task/src/drops.rs @@ -74,7 +74,7 @@ pub fn run(log: &Log, id: u32, arg: u8) { panic!("d{id} at {point}"); } }; - match arg % 22 { + match arg % 23 { 19 => closures::scoped(log, id, at), 20 => closures::discarded(log, id, at), 21 => closures::blasted(log, id, at), @@ -813,7 +813,8 @@ fn edited(log: &Log, id: u32, at: u8) { log.note(format!("retained {}", ids(&v))); v.retain_mut(|k| k.id != id + 3); log.note(format!("retained {}", ids(&v))); - return; + // `max` blows as `clamp` drops it, and `min` still drops. + drop(key(2).clamp(key(1), fault(3, Fault::Blows))); } 1 => { let mut v = list![key(1), key(2), key(3), key(4)]; diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index 8152ef0cb..1ea6af37e 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -16,7 +16,7 @@ import { type Place, panic } from "../rt.ts"; import { type Limbs, lt } from "./int.ts"; -import { DONE, type Done, Iter, iterSlice, iterToArray, type RangeInclusive } from "./iter.ts"; +import { DONE, type Done, Iter, iterSlice, type RangeInclusive } from "./iter.ts"; import { type Arc, dropAll } from "./task.ts"; // Ordering @@ -120,11 +120,8 @@ export function ordClamp(a: T, min: T, max: T, cmp: (a: T, b: T) => Ordering if (order === undefined || order > 0) panic("assertion failed: min <= max"); out = cmp(a, min) === -1 ? 1 : cmp(a, max) === 1 ? 2 : 0; } finally { - if (drop !== undefined) { - if (out !== 2) drop(max); - if (out !== 1) drop(min); - if (out !== 0) drop(a); - } + // A panic in one drop still drops the rest, as unwinding does. + if (drop !== undefined) dropAll([max, min, a].filter((_, i) => 2 - i !== out), drop); } return out === 1 ? min : out === 2 ? max : a; } @@ -1215,13 +1212,20 @@ export function btreeClear(m: BTreeMap, k?: (key: K) => void, v?: (v m.r = false; } -/** `split_off` of a map or set: the entries from `key` on, moved in order into a tree of their own. */ +/** + * `split_off` of a map or set: the entries from `key` on, moved in order into a tree of + * their own. It compares before it moves any, so a panic in `cmp` leaves `m` whole, as + * std's does. Like std's, the new tree has a root unless `m` was empty. + */ export function btreeSplitOff(m: BTreeMap, key: K): BTreeMap { const out = btreeNew(m.c); - for (const [k, v] of iterToArray(btreeRange(m, { start: key }))) { - btreeRemove(m, k); - btreeInsert(out, k, v); - } + if (m.n === 0) return out; + const [keys, values] = flatten(m); + const i = search(keys, key, m.c); + const at = i < 0 ? ~i : i; + build(out, keys.slice(at), values.slice(at)); + build(m, keys.slice(0, at), values.slice(0, at)); + out.r = true; return out; } diff --git a/ts/tests/retain.ts b/ts/tests/retain.ts index 7633903a6..6724439c6 100644 --- a/ts/tests/retain.ts +++ b/ts/tests/retain.ts @@ -124,3 +124,35 @@ for (const n of [17, 40, 70]) { if (sorted.slice().sort().join() !== want) throw new Error(`sort of ${n} panicking at ${p}: ${sorted}`); } } + +// `split_off` whose key order panics at each of its calls leaves the map whole, as std's +// compares before it moves an entry. Past one leaf, so it splits branches too. +for (const n of [6, 70, 200]) { + for (const at of [0, n >> 1, n]) { + for (let p = 0, thrown = true; thrown; p++) { + let calls = -1; + const tree = rt.btreeNew((a, b) => { + if (calls >= 0 && calls++ === p) throw new Thrown(); + return rt.cmp(a, b); + }); + for (let i = 0; i < n; i++) rt.btreeInsert(tree, i, i); + calls = 0; + thrown = false; + let above: rt.BTreeMap | undefined; + try { + above = rt.btreeSplitOff(tree, at); + } catch (err) { + if (!(err instanceof Thrown)) throw err; + thrown = true; + } + calls = -1; + const kept = rt.iterToArray(rt.btreeKeys(tree)).join(); + const moved = above === undefined ? "" : rt.iterToArray(rt.btreeKeys(above)).join(); + const all = [...Array(n).keys()]; + const want = thrown ? [all.join(), ""] : [all.slice(0, at).join(), all.slice(at).join()]; + if (kept !== want[0] || moved !== want[1] || rt.btreeLen(tree) !== (thrown ? n : at)) { + throw new Error(`split_off of ${n} at ${at} panicking at ${p}: ${kept} | ${moved}`); + } + } + } +} From 241faac08a65b3e73a31a3a408183ad6009e0c5a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 19:51:59 -0700 Subject: [PATCH 11/11] fix(ts): refuse hashing a slice of a type with its own hash_slice A slice's `Hash` calls its element's `hash_slice`, which the runtime's `hashSlice` replaces with each element's `hash`. Refuse that while an element type of the crate overrides it, and check the crate's own types through `own` as main's bindings do. Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/reject/census.md | 115 +++++++++++++++++--------------- ts/fixtures/reject/expected.txt | 39 +++++------ ts/fixtures/reject/src/lib.rs | 21 ++++++ ts/fixtures/reject/ts.toml | 1 + ts/src/census.rs | 1 + ts/src/lower/collections.rs | 29 +++++++- 6 files changed, 132 insertions(+), 74 deletions(-) diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 7ef6562e6..361daee89 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,17 +1,17 @@ # Census of `reject-fixture` -- Refusals: 86 -- Function instances: 74 -- Generic functions no instance reached, lowered over their type parameters: 2 +- Refusals: 88 +- Function instances: 78 +- Generic functions no instance reached, lowered over their type parameters: 4 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 9 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | +| 10 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:23:15 | | 5 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:45:11 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:407:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:428:2 | | 4 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:109:2 | | 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | | 3 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:17:2 | @@ -28,7 +28,7 @@ | 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:71:3 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:75:3 | | 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:281:6 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:418:18 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:439:18 | | 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:304:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | fixtures/reject/src/lib.rs:51:13 | | 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:336:2 | @@ -41,17 +41,18 @@ | 1 | a constant of type `_` | fixtures/reject/src/lib.rs:88:2 | | 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:275:14 | | 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:244:13 | -| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:456:12 | +| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:477:12 | | 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:67:3 | | 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:100:1 | | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:74:3 | | 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:60:2 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:401:13 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:422:13 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:286:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:425:53 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:446:53 | | 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:286:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | fixtures/reject/src/lib.rs:399:16 | | 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:73:3 | | 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:68:3 | | 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:69:3 | @@ -62,7 +63,7 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:407:2 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:428:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:23:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | | 5 | `{closure}` | fixtures/reject/src/lib.rs:45:11 | @@ -72,29 +73,30 @@ The type or module each refused type or path belongs to. | 3 | `std::iter::Map` | fixtures/reject/src/lib.rs:45:18 | | 3 | `std::slice` | fixtures/reject/src/lib.rs:28:4 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:109:2 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:286:52 | +| 3 | `u8` | fixtures/reject/src/lib.rs:88:2 | | 2 | `Lopsided` | fixtures/reject/src/lib.rs:378:4 | | 2 | `Meters` | fixtures/reject/src/lib.rs:93:2 | | 2 | `Noisy` | fixtures/reject/src/lib.rs:51:13 | | 2 | `Poll` | fixtures/reject/src/lib.rs:113:20 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:265:16 | -| 2 | `std::iter::Take` | fixtures/reject/src/lib.rs:399:79 | +| 2 | `std::iter::Take` | fixtures/reject/src/lib.rs:420:79 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:193:8 | | 2 | `std::option::Option` | fixtures/reject/src/lib.rs:281:6 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:129:2 | -| 2 | `std::vec::Vec` | fixtures/reject/src/lib.rs:286:52 | -| 2 | `u8` | fixtures/reject/src/lib.rs:88:2 | | 1 | `(i32, &Lopsided)` | fixtures/reject/src/lib.rs:379:13 | +| 1 | `Batched` | fixtures/reject/src/lib.rs:399:16 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:172:1 | -| 1 | `Entry` | fixtures/reject/src/lib.rs:390:13 | +| 1 | `Entry` | fixtures/reject/src/lib.rs:411:13 | | 1 | `FusedIterator` | fixtures/reject/src/lib.rs:226:1 | | 1 | `HashMap` | fixtures/reject/src/lib.rs:304:6 | | 1 | `Hasher` | fixtures/reject/src/lib.rs:312:9 | | 1 | `IntToFloat` | fixtures/reject/src/lib.rs:104:2 | | 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:258:22 | | 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | -| 1 | `from_fn` | fixtures/reject/src/lib.rs:400:13 | +| 1 | `from_fn` | fixtures/reject/src/lib.rs:421:13 | | 1 | `into_keys` | fixtures/reject/src/lib.rs:51:13 | -| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:446:15 | +| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:467:15 | | 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:185:51 | | 1 | `std::iter::Flatten` | fixtures/reject/src/lib.rs:234:26 | | 1 | `std::iter::IntoIterator` | fixtures/reject/src/lib.rs:17:2 | @@ -103,8 +105,8 @@ The type or module each refused type or path belongs to. | 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:139:11 | | 1 | `std::string::String` | fixtures/reject/src/lib.rs:82:10 | | 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:134:2 | -| 1 | `std::time::Duration` | fixtures/reject/src/lib.rs:433:2 | -| 1 | `successors` | fixtures/reject/src/lib.rs:399:15 | +| 1 | `std::time::Duration` | fixtures/reject/src/lib.rs:454:2 | +| 1 | `successors` | fixtures/reject/src/lib.rs:420:15 | | 1 | `u32` | fixtures/reject/src/lib.rs:244:13 | | 1 | `u64` | fixtures/reject/src/lib.rs:104:2 | | 1 | `{async closure}` | fixtures/reject/src/lib.rs:60:2 | @@ -114,23 +116,23 @@ The type or module each refused type or path belongs to. | Count | Construct | Type or path | First | | ---: | --- | --- | --- | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:23:15 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:407:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:428:2 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:113:20 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:129:2 | | 2 | comparing `_` through its own `_`, which is not supported yet | `Lopsided`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:378:4 | -| 2 | dropping `_`, which is not supported yet | `std::iter::Take` | fixtures/reject/src/lib.rs:399:79 | +| 2 | dropping `_`, which is not supported yet | `std::iter::Take` | fixtures/reject/src/lib.rs:420:79 | | 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:93:2 | | 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:281:6 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:418:18 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:439:18 | | 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:304:6 | | 1 | `_` of `_`, which drops `_`, which is not supported yet | `into_keys`, `std::collections::HashMap`, `Noisy` | fixtures/reject/src/lib.rs:51:13 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:265:38 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:265:16 | | 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:336:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:446:15 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:467:15 | | 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::iter::IntoIterator::into_iter` | fixtures/reject/src/lib.rs:17:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:439:21 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:460:21 | | 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:312:9 | | 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | `std::iter::Flatten` | fixtures/reject/src/lib.rs:234:26 | | 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:104:2 | @@ -145,28 +147,30 @@ The type or module each refused type or path belongs to. | 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:134:2 | | 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:172:1 | | 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:226:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:401:13 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:422:13 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:286:52 | | 1 | comparing `_` through its own `_`, which is not supported yet | `(i32, &Lopsided)`, `PartialOrd::lt` | fixtures/reject/src/lib.rs:379:13 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:425:53 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:446:53 | | 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:158:23 | | 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:179:14 | | 1 | dropping `_`, which is not supported yet | `std::iter::Map` | fixtures/reject/src/lib.rs:45:18 | | 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:286:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | `std::vec::Vec`, `Batched` | fixtures/reject/src/lib.rs:399:16 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:152:2 | | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:206:2 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:390:13 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::any` | fixtures/reject/src/lib.rs:391:11 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:411:13 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::any` | fixtures/reject/src/lib.rs:412:11 | | 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::map` | fixtures/reject/src/lib.rs:45:11 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `from_fn::from_fn` | fixtures/reject/src/lib.rs:400:13 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `successors::successors` | fixtures/reject/src/lib.rs:399:15 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `from_fn::from_fn` | fixtures/reject/src/lib.rs:421:13 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `successors::successors` | fixtures/reject/src/lib.rs:420:15 | | 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:258:22 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:419:2 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:463:2 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:440:2 | +| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:484:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:139:11 | | 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:82:10 | -| 1 | unsupported call to `_` | `::add_assign` | fixtures/reject/src/lib.rs:433:2 | +| 1 | unsupported call to `_` | `::add_assign` | fixtures/reject/src/lib.rs:454:2 | +| 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:390:10 | | 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:44:29 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:193:8 | | 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:354:4 | @@ -175,7 +179,7 @@ The type or module each refused type or path belongs to. ## Spans -
unsupported call to `_` (9) +
unsupported call to `_` (10) - fixtures/reject/src/lib.rs:28:4: unsupported call to `std::slice::::sort` - fixtures/reject/src/lib.rs:44:29: unsupported call to `std::mem::size_of_val::` @@ -183,9 +187,10 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:139:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:193:8: unsupported call to `std::ops::Range::::contains::` - fixtures/reject/src/lib.rs:354:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:419:2: unsupported call to ` as std::ops::Deref>::deref` -- fixtures/reject/src/lib.rs:433:2: unsupported call to `::add_assign` -- fixtures/reject/src/lib.rs:463:2: unsupported call to ` as std::cmp::PartialEq>::eq` +- fixtures/reject/src/lib.rs:390:10: unsupported call to `::hash::` +- fixtures/reject/src/lib.rs:440:2: unsupported call to ` as std::ops::Deref>::deref` +- fixtures/reject/src/lib.rs:454:2: unsupported call to `::add_assign` +- fixtures/reject/src/lib.rs:484:2: unsupported call to ` as std::cmp::PartialEq>::eq`
@@ -203,19 +208,19 @@ The type or module each refused type or path belongs to.
passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet (5) - fixtures/reject/src/lib.rs:45:11: passing `{closure@fixtures/reject/src/lib.rs:44:10: 44:23}`, a closure that owns a value that drops, to `Iterator::map`, which is not supported yet -- fixtures/reject/src/lib.rs:390:13: passing `{closure@fixtures/reject/src/lib.rs:390:28: 390:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet -- fixtures/reject/src/lib.rs:391:11: passing `{closure@fixtures/reject/src/lib.rs:391:15: 391:24}`, a closure that owns a value that drops, to `Iterator::any`, which is not supported yet -- fixtures/reject/src/lib.rs:399:15: passing `{closure@fixtures/reject/src/lib.rs:399:48: 399:56}`, a closure that owns a value that drops, to `successors::successors`, which is not supported yet -- fixtures/reject/src/lib.rs:400:13: passing `{closure@fixtures/reject/src/lib.rs:400:32: 400:39}`, a closure that owns a value that drops, to `from_fn::from_fn`, which is not supported yet +- fixtures/reject/src/lib.rs:411:13: passing `{closure@fixtures/reject/src/lib.rs:411:28: 411:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet +- fixtures/reject/src/lib.rs:412:11: passing `{closure@fixtures/reject/src/lib.rs:412:15: 412:24}`, a closure that owns a value that drops, to `Iterator::any`, which is not supported yet +- fixtures/reject/src/lib.rs:420:15: passing `{closure@fixtures/reject/src/lib.rs:420:48: 420:56}`, a closure that owns a value that drops, to `successors::successors`, which is not supported yet +- fixtures/reject/src/lib.rs:421:13: passing `{closure@fixtures/reject/src/lib.rs:421:32: 421:39}`, a closure that owns a value that drops, to `from_fn::from_fn`, which is not supported yet
a variant of `_`, which is not supported: either is the same JS string (4) -- fixtures/reject/src/lib.rs:407:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:408:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:409:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:414:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:428:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:429:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:430:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:435:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
@@ -240,8 +245,8 @@ The type or module each refused type or path belongs to.
`_` with a mutable reference to a value JS copies, which its mapping would copy (3) - fixtures/reject/src/lib.rs:17:2: `std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:439:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:446:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:460:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:467:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy
@@ -256,8 +261,8 @@ The type or module each refused type or path belongs to.
dropping `_`, which is not supported yet (3) - fixtures/reject/src/lib.rs:45:18: dropping `std::iter::Map, {closure@fixtures/reject/src/lib.rs:44:10: 44:23}>`, which is not supported yet -- fixtures/reject/src/lib.rs:399:79: dropping `std::iter::Take>`, which is not supported yet -- fixtures/reject/src/lib.rs:400:62: dropping `std::iter::Take>`, which is not supported yet +- fixtures/reject/src/lib.rs:420:79: dropping `std::iter::Take>`, which is not supported yet +- fixtures/reject/src/lib.rs:421:62: dropping `std::iter::Take>`, which is not supported yet
@@ -336,7 +341,7 @@ The type or module each refused type or path belongs to.
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:418:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:439:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
@@ -414,7 +419,7 @@ The type or module each refused type or path belongs to.
a mutable reference into a `Result`'s payload, passed on or kept (1) -- fixtures/reject/src/lib.rs:456:12: a mutable reference into a `Result`'s payload, passed on or kept +- fixtures/reject/src/lib.rs:477:12: a mutable reference into a `Result`'s payload, passed on or kept
@@ -450,7 +455,7 @@ The type or module each refused type or path belongs to.
an iterator that owns `_`, which drops, which is not supported yet (1) -- fixtures/reject/src/lib.rs:401:13: an iterator that owns `Noisy`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:422:13: an iterator that owns `Noisy`, which drops, which is not supported yet
@@ -468,7 +473,7 @@ The type or module each refused type or path belongs to.
constructing `_` (1) -- fixtures/reject/src/lib.rs:425:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:446:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
@@ -478,6 +483,12 @@ The type or module each refused type or path belongs to.
+
hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet (1) + +- fixtures/reject/src/lib.rs:399:16: hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet + +
+
hex `Debug`, as in `{:x?}`, is not supported (1) - fixtures/reject/src/lib.rs:73:3: hex `Debug`, as in `{:x?}`, is not supported diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 0d94bbc60..06f8c98b7 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -57,28 +57,29 @@ comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/r `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:304:6 unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:354:4 a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:359:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:407:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:409:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:408:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:414:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:418:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:419:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:425:53 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:428:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:430:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:429:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:435:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:439:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:440:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:446:53 comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:378:4 comparing `(i32, &Lopsided)` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:379:13 comparing `Lopsided` through its own `PartialOrd::lt`, which is not supported yet at fixtures/reject/src/lib.rs:380:12 -passing `{closure@fixtures/reject/src/lib.rs:390:28: 390: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:390:13 -passing `{closure@fixtures/reject/src/lib.rs:391:15: 391:24}`, a closure that owns a value that drops, to `Iterator::any`, which is not supported yet at fixtures/reject/src/lib.rs:391:11 -passing `{closure@fixtures/reject/src/lib.rs:399:48: 399:56}`, a closure that owns a value that drops, to `successors::successors`, which is not supported yet at fixtures/reject/src/lib.rs:399:15 -dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:399:79 -passing `{closure@fixtures/reject/src/lib.rs:400:32: 400:39}`, a closure that owns a value that drops, to `from_fn::from_fn`, which is not supported yet at fixtures/reject/src/lib.rs:400:13 -dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:400:62 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:401:13 -unsupported call to `::add_assign` at fixtures/reject/src/lib.rs:433:2 -`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:439:21 -`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:446:15 -a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:456:12 -unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:463:2 +hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet at fixtures/reject/src/lib.rs:399:16 +passing `{closure@fixtures/reject/src/lib.rs:411:28: 411:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet at fixtures/reject/src/lib.rs:411:13 +passing `{closure@fixtures/reject/src/lib.rs:412:15: 412:24}`, a closure that owns a value that drops, to `Iterator::any`, which is not supported yet at fixtures/reject/src/lib.rs:412:11 +passing `{closure@fixtures/reject/src/lib.rs:420:48: 420:56}`, a closure that owns a value that drops, to `successors::successors`, which is not supported yet at fixtures/reject/src/lib.rs:420:15 +dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:420:79 +passing `{closure@fixtures/reject/src/lib.rs:421:32: 421:39}`, a closure that owns a value that drops, to `from_fn::from_fn`, which is not supported yet at fixtures/reject/src/lib.rs:421:13 +dropping `std::iter::Take>`, which is not supported yet at fixtures/reject/src/lib.rs:421:62 +an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:422:13 +unsupported call to `::add_assign` at fixtures/reject/src/lib.rs:454:2 +`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:460:21 +`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:467:15 +a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:477:12 +unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:484:2 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:152:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:172:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:206:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 3b4222fe6..6c45d3d8e 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -380,6 +380,27 @@ pub fn lopsided(v: &mut Vec, a: Lopsided, b: Lopsided) -> bool { wins && a.max(b).0 > 0 } +/// A `hash_slice` of its own, which a `Vec`'s `Hash` calls where the translation hashes each +/// element. +#[derive(PartialEq, Eq)] +pub struct Batched(u8); + +impl std::hash::Hash for Batched { + fn hash(&self, state: &mut H) { + self.0.hash(state); + } + + fn hash_slice(data: &[Self], state: &mut H) { + state.write_usize(data.len()); + } +} + +pub fn batched(v: Vec) -> usize { + let mut set = std::collections::HashSet::new(); + set.insert(v); + set.len() +} + /// Closures that own a value that drops, which `any` and `or_insert_with` would call but /// never drop. pub fn called_closure(v: &[u8], m: &mut std::collections::HashMap) -> bool { diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 4a54e08be..68c741d7d 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -47,6 +47,7 @@ roots = [ "cow_bytes", "cow_made", "lopsided", + "batched", "called_closure", "owning_lazy", "duration_assign", diff --git a/ts/src/census.rs b/ts/src/census.rs index 579ed8af0..7f41013a5 100644 --- a/ts/src/census.rs +++ b/ts/src/census.rs @@ -148,6 +148,7 @@ const VERBATIM: &[&str] = &[ "Drop", "From", "From::from", + "Hash::hash_slice", "LowerExp", "None", "Octal", diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 934319dc0..751f52a7f 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -61,7 +61,7 @@ pub fn call<'tcx>( // `<=`, and `>`, and so by `partial_cmp` while those are the defaults. ("Ord", "max" | "min" | "clamp", ..) if let Some(t) = self_ty => { let t = peel(b, t); - let local = matches!(t.kind(), ty::Adt(adt, _) if adt.did().is_local()); + let local = matches!(t.kind(), ty::Adt(adt, _) if b.t.own(adt.did())); if !(std_key(b, t) || local) || Int::of(t).is_some() { return Err(args); } @@ -530,7 +530,7 @@ pub fn own_test<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>, test: &str) -> bool match ty.kind() { ty::Tuple(tys) => tys.last().is_some_and(|&t| own_test(b, t, test)), ty::Adt(..) if let Some(inner) = arc_of(b, ty).or_else(|| reverse_of(b, ty)) => own_test(b, inner, test), - ty::Adt(adt, _) if adt.did().is_local() => { + ty::Adt(adt, _) if b.t.own(adt.did()) => { let f = trait_fn(tcx, "PartialOrd", test); Instance::try_resolve(tcx, b.t.typing_env_pub(), f, tcx.mk_args(&[ty.into(), ty.into()])) .ok() @@ -1135,7 +1135,14 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("hashArc", vec![hash_fn(b, inner, hasher, span)]), ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => hash_fn(b, inner, hasher, span), - _ if let Some(elem) = elements_of(b, ty) => Expr::rt("hashSlice", vec![hash_fn(b, elem, hasher, span)]), + _ if let Some(elem) = elements_of(b, ty) => { + if own_hash_slice(b, elem, hasher) { + let msg = + format!("hashing `{ty}` through `{elem}`'s own `Hash::hash_slice`, which is not supported yet"); + return b.err(span, msg); + } + Expr::rt("hashSlice", vec![hash_fn(b, elem, hasher, span)]) + } ty::Adt(adt, _) if b.t.own(adt.did()) => { let hash = trait_fn(tcx, "Hash", "hash"); b.fn_value(hash, tcx.mk_args(&[ty.into(), hasher.into()]), span) @@ -1145,6 +1152,22 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa } } +/// Whether the crate's own `Hash` of `elem` overrides `hash_slice`, which a slice of it +/// hashes through in place of each element's `hash`. +fn own_hash_slice<'tcx>(b: &Body<'_, '_, 'tcx>, elem: Ty<'tcx>, hasher: Ty<'tcx>) -> bool { + let tcx = b.t.tcx; + let elem = peel(b, elem); + let ty::Adt(adt, _) = elem.kind() else { + return false; + }; + let f = trait_fn(tcx, "Hash", "hash_slice"); + b.t.own(adt.did()) + && Instance::try_resolve(tcx, b.t.typing_env_pub(), f, tcx.mk_args(&[elem.into(), hasher.into()])) + .ok() + .flatten() + .is_some_and(|instance| instance.def_id() != f) +} + /// `Clone::clone` of `ty`, as a function, or `undefined` where it is the value itself. pub fn clone_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { let tcx = b.t.tcx;