From a97ee029f3c18bf124fc33b9ff87ab583cfadac5 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:53:00 -0700 Subject: [PATCH 1/6] chore(quest): claim quest/m3/ts-eq-unlike.md Quest-Claim: 8377302edac9656b From 48389a8a8ae1472bad6dbd6fb2ac32060c7a818c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:08:01 -0700 Subject: [PATCH 2/6] feat(ts): compare std sequences of unlike items, and VecDeque against any Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 1 - quest/m3/ts-eq-unlike.md | 18 -- ts/README.md | 7 +- ts/fixtures/lang/caller.ts | 12 +- ts/fixtures/lang/expected/collections.Left.ts | 25 ++ .../lang/expected/collections.Right.ts | 15 ++ ts/fixtures/lang/expected/collections.ts | 243 ++++++++++++++++++ ts/fixtures/lang/expected/harness.ts | 4 +- ts/fixtures/lang/expected/iters.ts | 4 +- ts/fixtures/lang/src/collections.rs | 147 +++++++++++ ts/fixtures/lang/src/harness.rs | 1 + ts/fixtures/reject/census.md | 61 ++--- ts/fixtures/reject/expected.txt | 20 +- ts/fixtures/reject/src/lib.rs | 20 -- ts/fixtures/reject/ts.toml | 2 - ts/runtime/rt/collections.ts | 27 +- ts/src/lower/collections.rs | 102 ++++++++ ts/src/lower/iter.rs | 23 +- 18 files changed, 620 insertions(+), 112 deletions(-) delete mode 100644 quest/m3/ts-eq-unlike.md create mode 100644 ts/fixtures/lang/expected/collections.Left.ts create mode 100644 ts/fixtures/lang/expected/collections.Right.ts diff --git a/quest/m3/README.md b/quest/m3/README.md index 628c33f97..2a3c8135f 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -27,7 +27,6 @@ generic std gap is planned here even when moq never calls it. - [A B-tree's drop order](/quest/m3/ts-btree-drop.md) - dropping a whole `BTreeMap` or `BTreeSet` drops its entries node by node, as std's does - [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do - [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate -- [Equality of std containers of unlike elements](/quest/m3/ts-eq-unlike.md) - `==` and `next_if_eq` of a `Vec` against a `&[Right]`, and of `VecDeque` against `Vec`, translate - [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does - [A VecDeque's Debug](/quest/m3/ts-deque-debug.md) - `{:?}` of a `VecDeque` translates, writing std's list diff --git a/quest/m3/ts-eq-unlike.md b/quest/m3/ts-eq-unlike.md deleted file mode 100644 index 6d7a0d7ac..000000000 --- a/quest/m3/ts-eq-unlike.md +++ /dev/null @@ -1,18 +0,0 @@ -# [S] Equality of std containers of unlike elements - -## Goal - -`==` and `next_if_eq` of std containers whose elements are of other types that compare -by their own `PartialEq`, as a `Vec` against a `&[Right]` does, and of -`VecDeque` against `Vec`, slices, and arrays, translate, proven by a differential test -against native Rust. - -## Plan - -Refused at their spans today, as the reject fixture's `unlike_elements` and -`peeked_deque` are: the collections mapping compares only containers whose elements -compare alike. Each element pair could lower through `>::eq` as -`next_if_eq` of other types does, lending a `[u8; N]` element as its `rt.ByteSlice`, with -`ne` by the elements' own `ne` where a crate overrides it. - -Public API: the translator's output. diff --git a/ts/README.md b/ts/README.md index 968be877c..766909ed3 100644 --- a/ts/README.md +++ b/ts/README.md @@ -298,7 +298,9 @@ finds any other key, a 64-bit one past 2^53 included, through its translated `Ha `Option` orders `None` first, an `Arc` compares, orders, and hashes as what it holds, so a map of `Arc` finds a `&str`, and byte arrays, slices, and vectors order by their bytes and then their length, and compare and hash alike whatever their form, so a map of -`Vec` finds a `&[u8]`. A collection's reference to a byte array it holds, as `keys`, +`Vec` finds a `&[u8]`. Slices, arrays, `Vec`s, and `VecDeque`s compare against each +other as std's do, by their lengths and then each pair of items in order, through the +items' own `PartialEq`, and its `ne` where the crate overrides it. A collection's reference to a byte array it holds, as `keys`, `HashSet::get`, and `retain`'s closure get one, is an `rt.ByteSlice` of its bytes, as a `&[u8; N]` is elsewhere; a `&mut` writes where the collection holds them. A `&mut` to a value a map holds that JS copies, such as a number, from `get_mut` or the entry API, is an `rt.Place` whose `v` reads and @@ -695,7 +697,8 @@ built natively for wasm32 and run beside its translation on the same inputs by closures that log what each adaptor reads, `Option`'s and `Result`'s combinators, with closures that log each call, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` - disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, `&mut` + disagree with JS's, sequences compared across forms and item types by an `eq` and `ne` + that disagree, `vec![x; n]` of types whose `Clone` counts its clones, `&mut` to values JS copies, of locals, fields, elements, and a map's values, passed on, returned, kept in a struct, and captured, a `Vec`'s edits and sorts, with closures that log what each is called with, std's `Bound`, `Reverse`, and `NonZero`, and raw diff --git a/ts/fixtures/lang/caller.ts b/ts/fixtures/lang/caller.ts index e48668adc..a564143b8 100644 --- a/ts/fixtures/lang/caller.ts +++ b/ts/fixtures/lang/caller.ts @@ -544,4 +544,14 @@ const setOps = [ const zerosOp = op("zeros::zeros"); const zeros = Array.from({ length: 7 * 4 }, (_, i) => Uint8Array.of(zerosOp, i % 7, ...Array.from({ length: Math.floor(i / 7) }, (_, b) => b))); -export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds]; +/** + * `collections::unlike_eqs` of every pair of positions where `eq` and `ne` disagree and each + * length the right side may lose, over no items, one, two, a wrapped deque's four, and nine, + * whose positions are all within it. + */ +const unlikeEqsOp = op("collections::unlike_eqs"); +const unlikeEqs = [[], [5], [1, 2], [0, 7, 2, 9], [3, 3, 3, 3, 3, 3, 3, 3, 3]].flatMap((bytes) => + Array.from({ length: 128 }, (_, kind) => Uint8Array.of(unlikeEqsOp, kind, ...bytes)), +); + +export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs]; diff --git a/ts/fixtures/lang/expected/collections.Left.ts b/ts/fixtures/lang/expected/collections.Left.ts new file mode 100644 index 000000000..3688ef7d4 --- /dev/null +++ b/ts/fixtures/lang/expected/collections.Left.ts @@ -0,0 +1,25 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import type * as Right from "./collections.Right.ts"; + +/** + * An item that equals a `Right` of the same remainder by 4, but whose `ne` sees the + * remainder by 3, so what `!=` finds tells which std calls. Each call adds to the log, + * in order. + */ +export interface Left { + _0: rt.u16; + _1: rt.Cell; +} + +export function log(self: Left, by: rt.u16): void { + rt.cellSet(self._1, rt.u16WrappingAdd(rt.u16WrappingMul(self._1.v, 31), self._0 ^ by)); +} + +export function ne$PartialEq_Right(self: Left, other: Right.Right): boolean { + log(self, 512); + return rt.u16Rem(self._0, 3) !== rt.u16Rem(other._0, 3); +} + +//# sourceMappingURL=collections.Left.ts.map diff --git a/ts/fixtures/lang/expected/collections.Right.ts b/ts/fixtures/lang/expected/collections.Right.ts new file mode 100644 index 000000000..215951243 --- /dev/null +++ b/ts/fixtures/lang/expected/collections.Right.ts @@ -0,0 +1,15 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import * as Left from "./collections.Left.ts"; + +export interface Right { + _0: rt.u16; +} + +export function eq$PartialEq_Left(self: Right, other: Left.Left): boolean { + Left.log(other, 1024); + return rt.u16Rem(self._0, 4) === rt.u16Rem(other._0, 4); +} + +//# sourceMappingURL=collections.Right.ts.map diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 4cc8e88ab..c6bce3944 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -7,9 +7,11 @@ import * as Cloned from "./collections.Cloned.ts"; import * as Dir from "./collections.Dir.ts"; import * as Fussy from "./collections.Fussy.ts"; import type * as Holder from "./collections.Holder.ts"; +import * as Left from "./collections.Left.ts"; import * as Nibble from "./collections.Nibble.ts"; import * as Pair from "./collections.Pair.ts"; import * as Rank from "./collections.Rank.ts"; +import * as Right from "./collections.Right.ts"; import * as Tally from "./collections.Tally.ts"; import { thenSome$0d5am30 } from "./core/bool.ts"; import { unwrapOr$1j4op5y, unwrapOr$0r2bmpr, map$09ua5et, map$0oc32h1, mapOr$0q0ymkh, mapOr$1xztl8h, mapOr$1to2ul4, mapOr$1ht002r, mapOr$099335t, mapOr$0z4mj8g, mapOr$1surhce, mapOr$0mmpeqx, mapOr$1nlkf9b, mapOr$1t0muvr, mapOr$1w1gbwl, mapOr$02k4ito, clone$14nprly, flatten$1nwzx42 } from "./core/option.ts"; @@ -3525,4 +3527,245 @@ export function putSorted$u8s(items: rt.ByteSlice[], put: (a0: rt.ByteSlice) => putAll$u8s_IntoIter_u8s(rt.iterSlice(items), put, out); } +export function eq$PartialEq_Right_u8(self: rt.u8, other: Right.Right): boolean { + return rt.u16Rem(self as rt.u16, 4) === rt.u16Rem(other._0, 4); +} + +export function eq$PartialEq_Right_u8s(self: rt.ByteSlice, other: Right.Right): boolean { + return rt.u16Rem(rt.u16Add(self.data[self.start] as rt.u16, self.data[self.start + 1] as rt.u16), 4) === rt.u16Rem(other._0, 4); +} + +/** Whether a comparison found its sides equal, then the log of the calls it made. */ +export function putEq(eq: boolean, log: rt.Cell, out: rt.ByteVec): void { + rt.byteVecPush(out, eq ? 1 : 0); + rt.iterExtendBytes(out, rt.iterSlice(rt.u16ToBeBytes(rt.cellReplace(log, 0)).reverse()), undefined, true); +} + +/** + * `==` and `!=` of sequences whose items compare by their own `PartialEq`, and of a + * `VecDeque` against each other sequence: of unequal lengths, empty, with items `eq` and + * `ne` disagree on at the positions `kind` picks, and a deque wrapped around its buffer. + * Then `next_if_eq` of such sequences, matching and missing. + */ +export function unlikeEqs(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const log: rt.Cell = new rt.Cell(0); + const lefts: () => Left.Left[] = (): Left.Left[] => { + return rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_25: rt.u8): Left.Left => { + return { _0: _25 as rt.u16, _1: log }; + }), undefined, 8, true); + }; + const _9: [rt.usize, rt.usize] = [(kind & 7) as rt.usize, ((kind >> 3) & 7) as rt.usize]; + const byNe: rt.usize = _9[0]; + const byEq: rt.usize = _9[1]; + const step: (a0: rt.usize) => rt.u16 = (i: rt.usize): rt.u16 => { + if (!(i === byEq)) { + if (!(i === byNe)) { + return 12; + } + return 4; + } + return 3; + }; + const rights: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_29: [rt.usize, rt.u8]): Right.Right => { + return { _0: rt.u16Add(_29[1] as rt.u16, step(_29[0])) }; + }), undefined, 2, true); + if ((kind & 64) !== 0) { + rights.pop(); + } + const at: (a0: rt.usize) => rt.u16 = (i3: rt.usize): rt.u16 => { + return unwrapOr$0r2bmpr(rt.byteSliceGet(data, i3), 0) as rt.u16; + }; + const pair: () => Right.Right[] = (): Right.Right[] => { + return [{ _0: rt.u16Add(at(0), 12) }, { _0: rt.u16Add(at(1), 12) }]; + }; + const mine: Left.Left[] = lefts(); + const _39: Right.Right[] = rights; + putEq(rt.eqSeq((a: Left.Left, b7: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a, b7); + })(mine, _39), log, out); + putEq(!rt.eqSeq((a2: Left.Left, b8: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a2, b8); + })(mine, rights), log, out); + const _49: Left.Left[] = rt.sliceRange(mine, 0); + const _51: Right.Right[] = rt.sliceRange(rights, 0); + putEq(rt.eqSeq((a3: Left.Left, b9: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a3, b9); + })(_49, _51), log, out); + putEq(rt.eqSeq(Right.eq$PartialEq_Left)(rights, mine), log, out); + const _63: Left.Left[] = mine; + putEq(rt.eqSeq((a4: Left.Left, b10: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a4, b10); + })(_63, rights), log, out); + const _71: Right.Right[] = pair(); + putEq(rt.eqSeq((a5: Left.Left, b11: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a5, b11); + })(mine, _71), log, out); + const _79: Right.Right[] = pair(); + putEq(rt.eqSeq((a6: Left.Left, b12: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a6, b12); + })(mine, _79), log, out); + const _85: Left.Left[] = mine; + const _88: Right.Right[] = pair(); + putEq(rt.eqSeq((a7: Left.Left, b13: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a7, b13); + })(_85, _88), log, out); + const two: Left.Left[] = [{ _0: at(0), _1: log }, { _0: at(1), _1: log }]; + const _106: Right.Right[] = pair(); + putEq(rt.eqSeq((a8: Left.Left, b14: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a8, b14); + })(two, _106), log, out); + const _113: Right.Right[] = pair(); + putEq(!rt.eqSeq((a9: Left.Left, b15: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a9, b15); + })(two, _113), log, out); + const _119: Right.Right[] = rt.sliceRange(rights, 0); + putEq(rt.eqSeq((a10: Left.Left, b16: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a10, b16); + })(two, _119), log, out); + const _126: Right.Right[] = rights; + putEq(rt.eqSeq((a11: Left.Left, b17: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a11, b17); + })(two, _126), log, out); + const _132: Left.Left[] = []; + const _134: Right.Right[] = []; + putEq(rt.eqSeq((a20: Left.Left, b18: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a20, b18); + })(_132, _134), log, out); + const _139: Left.Left[] = []; + putEq(rt.eqSeq((a21: Left.Left, b19: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a21, b19); + })(_139, rights), log, out); + const _145: Right.Right[] = []; + putEq(rt.eqSeq((a22: Left.Left, b20: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a22, b20); + })(mine, _145), log, out); + const _150: rt.ByteVec = rt.byteSliceToByteVec(data); + putEq(rt.eqSeq(eq$PartialEq_Right_u8)(_150, rights), log, out); + const _157: Right.Right[] = rights; + putEq(rt.eqSeq(eq$PartialEq_Right_u8)(data, _157), log, out); + const pairs: Uint8Array[] = rt.iterToArray(rt.iterMap(rt.byteSliceChunksExact(data, 2), (c: rt.ByteSlice): Uint8Array => { + rt.idx(c, 0); + const _35: rt.u8 = c.data[c.start]; + rt.idx(c, 1); + return Uint8Array.of(_35, c.data[c.start + 1]); + }), undefined, 2, true); + const _165: Uint8Array[] = rt.sliceRange(pairs, 0); + const _167: Right.Right[] = rt.sliceRange(rights, 0, rt.min(pairs.length, rights.length)); + putEq(rt.eqSeq((a23: Uint8Array, b21: Right.Right): boolean => { + return eq$PartialEq_Right_u8s(rt.byteSliceFrom(a23), b21); + })(_165, _167), log, out); + const _179: Left.Left[][] = [lefts(), lefts()]; + const _186: Right.Right[][] = [rights, rt.sliceRange(rights, 0)]; + putEq(rt.eqSeq(rt.eqSeq((a24: Left.Left, b22: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a24, b22); + }))(_179, _186), log, out); + const half: rt.usize = rt.usizeDiv(data.length, 2); + const q: rt.VecDeque = rt.dequeNew() as rt.VecDeque; + const iter: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); + while (true) { + const _202: rt.u8 | rt.Done = iter.next(); + if (_202 === rt.DONE) { + break; + } + const _208: Left.Left = { _0: _202 as rt.u16, _1: log }; + rt.dequePushFront(q, _208); + } + for (const _215 of rt.byteSliceView(rt.byteSliceRange(data, half))) { + const _221: Left.Left = { _0: _215 as rt.u16, _1: log }; + rt.dequePushBack(q, _221); + } + const _228: Right.Right[] = rights; + putEq(rt.eqSeq((a25: Left.Left, b23: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a25, b23); + })(q, _228), log, out); + putEq(rt.eqSeq((a26: Left.Left, b24: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a26, b24); + })(q, rights), log, out); + const _240: Right.Right[] = rights; + putEq(!rt.eqSeq((a27: Left.Left, b25: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a27, b25); + })(q, _240), log, out); + const _248: Right.Right[] = rights; + putEq(rt.eqSeq((a28: Left.Left, b26: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a28, b26); + })(q, _248), log, out); + const _255: Right.Right[] = pair(); + putEq(rt.eqSeq((a29: Left.Left, b27: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a29, b27); + })(q, _255), log, out); + const _263: Right.Right[] = pair(); + putEq(rt.eqSeq((a30: Left.Left, b28: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a30, b28); + })(q, _263), log, out); + const _271: Right.Right[] = pair(); + putEq(rt.eqSeq((a31: Left.Left, b29: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a31, b29); + })(q, _271), log, out); + const bytes: rt.VecDeque = rt.dequeNew() as rt.VecDeque; + const iter3: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); + while (true) { + const _281: rt.u8 | rt.Done = iter3.next(); + if (_281 === rt.DONE) { + break; + } + rt.dequePushFront(bytes, _281); + } + const _289: rt.ByteSlice = rt.byteSliceRange(data, half); + rt.dequeExtend(bytes, rt.iterSlice(rt.byteSliceView(_289)), undefined, 1, true); + const stepped: rt.ByteVec = rt.iterToByteVec(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_214: [rt.usize, rt.u8]): rt.u8 => { + return _214[1] ^ (_214[0] === byEq ? 1 : 0); + }), undefined, true); + putEq(rt.eqSeq(rt.same)(bytes, stepped), log, out); + putEq(rt.eqSeq(rt.same)(bytes, data), log, out); + const _310: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of(unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 0), 0)); + putEq(rt.eqSeq(rt.same)(bytes, _310), log, out); + const _317: rt.Iter = rt.iterMap(rt.dequeIter(bytes), (_216: rt.u8): rt.u16 => { + return _216 as rt.u16; + }); + const wide_: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _317, undefined, 2, true); + const wrapped: rt.VecDeque = rt.dequeNew() as rt.VecDeque; + const iter4: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteVecSlice(stepped)))); + while (true) { + const _327: rt.u8 | rt.Done = iter4.next(); + if (_327 === rt.DONE) { + break; + } + rt.dequePushFront(wrapped, _327 as rt.u16); + } + putEq(rt.eqSeq(rt.same)(wide_, wrapped), log, out); + const _342: rt.VecDeque[] = [rt.dequeClone(wide_, undefined)]; + const _347: rt.VecDeque[] = [wrapped]; + putEq(rt.eqSeq(rt.eqSeq(rt.same))(_342, _347), log, out); + const it: rt.Peekable = rt.iterPeekable(rt.iterSlice([lefts(), lefts(), lefts()])); + const exact: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_217: rt.u8): Right.Right => { + return { _0: _217 as rt.u16 }; + }), undefined, 2, true); + putEq(rt.peekableNextIfEq(it, exact, (a027: Left.Left[], a127: Right.Right[]): boolean => { + return rt.eqSeq((a32: Left.Left, b33: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a32, b33); + })(a027, a127); + }) !== undefined, log, out); + putEq(rt.peekableNextIfEq(it, rights, (a029: Left.Left[], a129: Right.Right[]): boolean => { + return rt.eqSeq((a33: Left.Left, b34: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a33, b34); + })(a029, a129); + }) !== undefined, log, out); + const _385: Right.Right[] = rt.sliceRange(exact, 0, half); + putEq(rt.peekableNextIfEq(it, _385, (a031: Left.Left[], a131: Right.Right[]): boolean => { + return rt.eqSeq((a34: Left.Left, b35: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a34, b35); + })(a031, a131); + }) !== undefined, log, out); + rt.byteVecPush(out, rt.iterCount(it) & 0xff); + const it2: rt.Peekable> = rt.iterPeekable(rt.iterSlice([rt.dequeClone(bytes, undefined), bytes])); + const _406: rt.ByteVec = rt.byteSliceToByteVec(data); + putEq(rt.peekableNextIfEq(it2, _406, (a033: rt.VecDeque, a133: rt.ByteVec): boolean => { + return rt.eqSeq(rt.same)(a033, a133); + }) !== undefined, log, out); + putEq(rt.peekableNextIfEq(it2, stepped, (a034: rt.VecDeque, a134: rt.ByteVec): boolean => { + return rt.eqSeq(rt.same)(a034, a134); + }) !== undefined, log, out); + rt.byteVecPush(out, rt.iterCount(it2) & 0xff); +} + //# sourceMappingURL=collections.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 96a3147b1..ae05626f6 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -9,7 +9,7 @@ import { captures } from "./captures.ts"; import { cells } from "./cells.ts"; import { chars } from "./chars.ts"; import { chunks } from "./chunks.ts"; -import { hashMaps, sets, btreeMaps, deques, vecs, stores, optionals, setOps } from "./collections.ts"; +import { hashMaps, sets, btreeMaps, deques, vecs, stores, optionals, setOps, unlikeEqs } from "./collections.ts"; import { combinators } from "./combinators.ts"; import { arcs, clonedArcs, cyclicArcs, uniqueArcs, clonedRcs, cyclicRcs, rcs, uniqueRcs, copies } from "./counts.ts"; import { cows } from "./cows.ts"; @@ -192,7 +192,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) maps(data69, out70); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["arrays::lent", (_2170: rt.u8, data70: rt.ByteSlice, out71: rt.ByteVec): undefined => { lent(data70, out71); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["floats::mul_adds", mulAdds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::mul_adds", singles_mulAdds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["floats::mul_adds", mulAdds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::mul_adds", singles_mulAdds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::unlike_eqs", unlikeEqs as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index 50ec71d36..df73ed19c 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -533,7 +533,7 @@ export function peekedOthers(data: rt.ByteSlice, out: rt.ByteVec): void { return Uint8Array.of(_317, rt.u8Rem(c.data[c.start + 1], 2)); })); const _217: rt.ByteSlice = rt.byteSliceRange(rt.byteSliceFrom(Uint8Array.of(0, 1)), 0); - rt.byteVecPush(out, mapOr$0sl5app(rt.peekableNextIfEq(it9, _217, (a, b7): boolean => { + rt.byteVecPush(out, mapOr$0sl5app(rt.peekableNextIfEq(it9, _217, (a: Uint8Array, b7: rt.ByteSlice): boolean => { return ((a017: rt.ByteSlice, a113: rt.ByteSlice): boolean => { return rt.eqBytes(a017, a113); })(rt.byteSliceFrom(a), b7); @@ -543,7 +543,7 @@ export function peekedOthers(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, mapOr$0sl5app(rt.iterToOption(it9.next()), 170, (p2: Uint8Array): rt.u8 => { return p2[0]; })); - rt.byteVecPush(out, mapOr$0sl5app(rt.peekableNextIfEq(it9, { _0: 1, _1: calls }, (a2, b8): boolean => { + rt.byteVecPush(out, mapOr$0sl5app(rt.peekableNextIfEq(it9, { _0: 1, _1: calls }, (a2: Uint8Array, b8: Quarter.Quarter): boolean => { return eq$PartialEq_Quarter_u8s(rt.byteSliceFrom(a2), b8); }), 170, (p3: Uint8Array): rt.u8 => { return p3[0]; diff --git a/ts/fixtures/lang/src/collections.rs b/ts/fixtures/lang/src/collections.rs index 5ae291115..ad4e3c800 100644 --- a/ts/fixtures/lang/src/collections.rs +++ b/ts/fixtures/lang/src/collections.rs @@ -1172,3 +1172,150 @@ fn put_sorted(mut items: Vec<&T>, put: fn(&T) -> u8, out: &mut Vec) items.sort(); put_all(items.into_iter(), put, out); } + +/// An item that equals a `Right` of the same remainder by 4, but whose `ne` sees the +/// remainder by 3, so what `!=` finds tells which std calls. Each call adds to the log, +/// in order. +struct Left<'a>(u16, &'a std::cell::Cell); + +struct Right(u16); + +impl Left<'_> { + fn log(&self, by: u16) { + self.1.set(self.1.get().wrapping_mul(31).wrapping_add(self.0 ^ by)); + } +} + +impl PartialEq for Left<'_> { + fn eq(&self, other: &Right) -> bool { + self.log(0x100); + self.0 % 4 == other.0 % 4 + } + + fn ne(&self, other: &Right) -> bool { + self.log(0x200); + self.0 % 3 != other.0 % 3 + } +} + +/// The other way, by the remainder by 4, with `ne`'s default. +impl<'a> PartialEq> for Right { + fn eq(&self, other: &Left<'a>) -> bool { + other.log(0x400); + self.0 % 4 == other.0 % 4 + } +} + +/// A byte against a `Right`, read from a typed array. +impl PartialEq for u8 { + fn eq(&self, other: &Right) -> bool { + u16::from(*self) % 4 == other.0 % 4 + } +} + +/// A pair against a `Right` by its sum, which reads the array through the reference `eq` +/// takes. +impl PartialEq for [u8; 2] { + fn eq(&self, other: &Right) -> bool { + (u16::from(self[0]) + u16::from(self[1])) % 4 == other.0 % 4 + } +} + +/// Whether a comparison found its sides equal, then the log of the calls it made. +fn put_eq(eq: bool, log: &std::cell::Cell, out: &mut Vec) { + out.push(eq as u8); + out.extend(log.replace(0).to_le_bytes()); +} + +/// `==` and `!=` of sequences whose items compare by their own `PartialEq`, and of a +/// `VecDeque` against each other sequence: of unequal lengths, empty, with items `eq` and +/// `ne` disagree on at the positions `kind` picks, and a deque wrapped around its buffer. +/// Then `next_if_eq` of such sequences, matching and missing. +pub fn unlike_eqs(kind: u8, data: &[u8], out: &mut Vec) { + let log = std::cell::Cell::new(0); + let lefts = || data.iter().map(|&b| Left(b.into(), &log)).collect::>(); + // Of the same remainders by 3 and 4 but where only `ne`'s or only `eq`'s is. + let (by_ne, by_eq) = (usize::from(kind & 7), usize::from(kind >> 3 & 7)); + let step = |i: usize| match i { + _ if i == by_eq => 3, + _ if i == by_ne => 4, + _ => 12, + }; + let mut rights: Vec = data + .iter() + .enumerate() + .map(|(i, &b)| Right(u16::from(b) + step(i))) + .collect(); + if kind & 0x40 != 0 { + rights.pop(); + } + let at = |i: usize| u16::from(data.get(i).copied().unwrap_or(0)); + let pair = || [Right(at(0) + 12), Right(at(1) + 12)]; + + let mut mine = lefts(); + put_eq(mine == rights.as_slice(), &log, out); + put_eq(mine != rights, &log, out); + put_eq(mine[..] == rights[..], &log, out); + put_eq(rights == mine, &log, out); + put_eq(&mut mine[..] == rights, &log, out); + put_eq(mine == pair(), &log, out); + put_eq(mine == &pair(), &log, out); + put_eq(mine.as_slice() == pair(), &log, out); + let two = [Left(at(0), &log), Left(at(1), &log)]; + put_eq(two == pair(), &log, out); + put_eq(two != pair(), &log, out); + put_eq(two == rights[..], &log, out); + put_eq(two == rights.as_slice(), &log, out); + put_eq(Vec::::new() == Vec::::new(), &log, out); + put_eq(Vec::::new() == rights, &log, out); + put_eq(mine == [] as [Right; 0], &log, out); + put_eq(data.to_vec() == rights, &log, out); + put_eq(data == rights.as_slice(), &log, out); + let pairs: Vec<[u8; 2]> = data.chunks_exact(2).map(|c| [c[0], c[1]]).collect(); + put_eq(pairs[..] == rights[..pairs.len().min(rights.len())], &log, out); + put_eq(vec![lefts(), lefts()] == [rights.as_slice(), &rights[..]], &log, out); + + // Wrapped around: the first half pushed to the front backwards, the rest to the back. + let half = data.len() / 2; + let mut q = std::collections::VecDeque::new(); + for &b in data[..half].iter().rev() { + q.push_front(Left(b.into(), &log)); + } + for &b in &data[half..] { + q.push_back(Left(b.into(), &log)); + } + put_eq(q == rights.as_slice(), &log, out); + put_eq(q == rights, &log, out); + put_eq(q != rights.as_slice(), &log, out); + put_eq(q == &mut rights[..], &log, out); + put_eq(q == pair(), &log, out); + put_eq(q == &pair(), &log, out); + put_eq(q == &mut pair(), &log, out); + let mut bytes = std::collections::VecDeque::new(); + for &b in data[..half].iter().rev() { + bytes.push_front(b); + } + bytes.extend(&data[half..]); + let stepped: Vec = data.iter().enumerate().map(|(i, &b)| b ^ (i == by_eq) as u8).collect(); + put_eq(bytes == stepped, &log, out); + put_eq(bytes == data, &log, out); + put_eq(bytes == [data.first().copied().unwrap_or(0), 0], &log, out); + let wide: std::collections::VecDeque = bytes.iter().map(|&b| u16::from(b)).collect(); + let mut wrapped = std::collections::VecDeque::new(); + for &b in stepped.iter().rev() { + wrapped.push_front(u16::from(b)); + } + put_eq(wide == wrapped, &log, out); + put_eq(vec![wide.clone()] == [wrapped], &log, out); + + let mut it = vec![lefts(), lefts(), lefts()].into_iter().peekable(); + let exact: Vec = data.iter().map(|&b| Right(b.into())).collect(); + put_eq(it.next_if_eq(exact.as_slice()).is_some(), &log, out); + put_eq(it.next_if_eq(&rights.as_slice()).is_some(), &log, out); + put_eq(it.next_if_eq(&exact[..half]).is_some(), &log, out); + out.push(it.count() as u8); + let mut it = vec![bytes.clone(), bytes].into_iter().peekable(); + put_eq(it.next_if_eq(&data.to_vec()).is_some(), &log, out); + put_eq(it.next_if_eq(&stepped).is_some(), &log, out); + out.push(it.count() as u8); +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 92a1764db..e79f947f0 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -171,6 +171,7 @@ fn cases() -> Vec<(&'static str, Case)> { ("arrays::lent", |_, data, out| arrays::lent(data, out)), ("floats::mul_adds", floats::mul_adds), ("singles::mul_adds", singles::mul_adds), + ("collections::unlike_eqs", collections::unlike_eqs), ] } diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 4bb6a9f3f..091b7aa94 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,14 +1,14 @@ # Census of `reject-fixture` -- Refusals: 126 -- Function instances: 152 +- Refusals: 124 +- Function instances: 149 - Generic functions no instance reached, lowered over their type parameters: 10 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 17 | unsupported call to `_` | fixtures/reject/src/lib.rs:138:11 | +| 15 | unsupported call to `_` | fixtures/reject/src/lib.rs:138:11 | | 12 | a raw pointer to `_` in `_`, which the crate may put another object in place of | fixtures/reject/src/lib.rs:658:10 | | 8 | a raw pointer to `_` in a variable assigned again while it may point there | fixtures/reject/src/lib.rs:666:10 | | 5 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:374:4 | @@ -83,16 +83,16 @@ The type or module each refused type or path belongs to. | 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:379:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:16:15 | | 6 | `f16` | fixtures/reject/src/lib.rs:7:14 | -| 5 | `Gap` | fixtures/reject/src/lib.rs:1008:10 | +| 5 | `Gap` | fixtures/reject/src/lib.rs:988:10 | | 5 | `Iterator` | fixtures/reject/src/lib.rs:42:4 | | 5 | `u32` | fixtures/reject/src/lib.rs:605:27 | | 4 | `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:737:15 | | 4 | `std::pin::Pin` | fixtures/reject/src/lib.rs:112:2 | -| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:357:16 | | 4 | `{closure}` | fixtures/reject/src/lib.rs:366:13 | | 3 | `Spent` | fixtures/reject/src/lib.rs:853:4 | | 3 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:55:13 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:315:2 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:357:16 | | 3 | `u8` | fixtures/reject/src/lib.rs:283:6 | | 2 | `Poll` | fixtures/reject/src/lib.rs:93:20 | | 2 | `Reused` | fixtures/reject/src/lib.rs:21:4 | @@ -104,7 +104,7 @@ The type or module each refused type or path belongs to. | 2 | `std::any::TypeId` | fixtures/reject/src/lib.rs:588:2 | | 2 | `std::collections::BTreeSet` | fixtures/reject/src/lib.rs:265:75 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:244:16 | -| 2 | `std::mem::MaybeUninit` | fixtures/reject/src/lib.rs:1022:19 | +| 2 | `std::mem::MaybeUninit` | fixtures/reject/src/lib.rs:1002:19 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:192:8 | | 2 | `std::std` | fixtures/reject/src/lib.rs:617:11 | | 2 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:104:2 | @@ -121,17 +121,17 @@ The type or module each refused type or path belongs to. | 1 | `HashMap` | fixtures/reject/src/lib.rs:283:6 | | 1 | `Hasher` | fixtures/reject/src/lib.rs:291:9 | | 1 | `Hits` | fixtures/reject/src/lib.rs:770:21 | -| 1 | `Lane` | fixtures/reject/src/lib.rs:972:19 | +| 1 | `Lane` | fixtures/reject/src/lib.rs:952:19 | | 1 | `Maybe` | fixtures/reject/src/lib.rs:31:2 | | 1 | `Noisy` | fixtures/reject/src/lib.rs:55:13 | | 1 | `Only` | fixtures/reject/src/lib.rs:787:11 | -| 1 | `Plain` | fixtures/reject/src/lib.rs:926:10 | +| 1 | `Plain` | fixtures/reject/src/lib.rs:906:10 | | 1 | `Sink` | fixtures/reject/src/lib.rs:76:10 | | 1 | `Span2` | fixtures/reject/src/lib.rs:658:10 | | 1 | `String` | fixtures/reject/src/lib.rs:859:4 | | 1 | `T \| undefined` | fixtures/reject/src/lib.rs:31:2 | | 1 | `Tail` | fixtures/reject/src/lib.rs:534:30 | -| 1 | `Track` | fixtures/reject/src/lib.rs:952:19 | +| 1 | `Track` | fixtures/reject/src/lib.rs:932:19 | | 1 | `VecDeque` | fixtures/reject/src/lib.rs:853:29 | | 1 | `Vec` | fixtures/reject/src/lib.rs:853:4 | | 1 | `Waiting` | fixtures/reject/src/lib.rs:545:2 | @@ -142,9 +142,8 @@ The type or module each refused type or path belongs to. | 1 | `poll` | fixtures/reject/src/lib.rs:545:2 | | 1 | `rt.Poll` | fixtures/reject/src/lib.rs:545:2 | | 1 | `std::any::Any` | fixtures/reject/src/lib.rs:588:4 | -| 1 | `std::collections::VecDeque` | fixtures/reject/src/lib.rs:896:27 | | 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:184:51 | -| 1 | `std::iter::Extend` | fixtures/reject/src/lib.rs:1030:6 | +| 1 | `std::iter::Extend` | fixtures/reject/src/lib.rs:1010:6 | | 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:233:30 | | 1 | `std::net::AddrParseError` | fixtures/reject/src/lib.rs:481:32 | | 1 | `std::net::Ipv4Addr` | fixtures/reject/src/lib.rs:481:32 | @@ -167,13 +166,13 @@ The type or module each refused type or path belongs to. | ---: | --- | --- | --- | | 6 | a raw pointer to `_` in a variable assigned again while it may point there | `(u32, u32)` | fixtures/reject/src/lib.rs:666:10 | | 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:379:2 | -| 3 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Gap` | fixtures/reject/src/lib.rs:1008:10 | +| 3 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Gap` | fixtures/reject/src/lib.rs:988:10 | | 3 | unsupported type `_` | `f16` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:16:15 | | 2 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::scan`, `Option` | fixtures/reject/src/lib.rs:42:4 | | 2 | `_`, a trait object of another crate's trait, which is not supported yet | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | `dyn Scaled`, `Scaled` | fixtures/reject/src/lib.rs:507:23 | -| 2 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::mem::MaybeUninit`, `Gap` | fixtures/reject/src/lib.rs:1022:19 | +| 2 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::mem::MaybeUninit`, `Gap` | fixtures/reject/src/lib.rs:1002:19 | | 2 | a raw pointer to `_` in a variable assigned again while it may point there | `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:746:15 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:128:2 | | 2 | replacing the value behind a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:112:2 | @@ -191,7 +190,7 @@ The type or module each refused type or path belongs to. | 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::clone_from_slice`, `Reused` | fixtures/reject/src/lib.rs:333:4 | | 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::fill`, `Reused` | fixtures/reject/src/lib.rs:21:4 | | 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::collections::HashMap::into_keys` | fixtures/reject/src/lib.rs:891: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::Extend::extend` | fixtures/reject/src/lib.rs:1030: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::Extend::extend` | fixtures/reject/src/lib.rs:1010: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:244: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:244:16 | | 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:315:2 | @@ -210,10 +209,10 @@ The type or module each refused type or path belongs to. | 1 | a dangling pointer to `_`, a value of no bytes made of more than structs and tuples | `Only` | fixtures/reject/src/lib.rs:787:11 | | 1 | a future of `_`, which can be `rt.Pending`, as the future's own `Pending` is | `std::task::Poll` | fixtures/reject/src/lib.rs:98:34 | | 1 | a raw pointer to `_` behind a reference, which is the object and not where it is kept | `std::vec::Vec` | fixtures/reject/src/lib.rs:627:10 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Lane` | fixtures/reject/src/lib.rs:972:19 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Plain` | fixtures/reject/src/lib.rs:926:10 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Lane` | fixtures/reject/src/lib.rs:952:19 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Plain` | fixtures/reject/src/lib.rs:906:10 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Span2` | fixtures/reject/src/lib.rs:658:10 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Track` | fixtures/reject/src/lib.rs:952:19 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Track` | fixtures/reject/src/lib.rs:932:19 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Window` | fixtures/reject/src/lib.rs:719:2 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:737:15 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::cell::UnsafeCell`, `Hits` | fixtures/reject/src/lib.rs:770:21 | @@ -246,12 +245,10 @@ The type or module each refused type or path belongs to. | 1 | union `_`, whose fields overlap in `_` and `f64`, which JS keeps apart | `Bits`, `u32` | fixtures/reject/src/lib.rs:632:1 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:588:2 | | 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:391:2 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:896:27 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:417:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:138:11 | | 1 | unsupported call to `_` | `::is_sorted` | fixtures/reject/src/lib.rs:816:15 | -| 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:986:10 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:911:27 | +| 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:966:10 | | 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:348:10 | | 1 | unsupported call to `_` | `std::any::TypeId::of` | fixtures/reject/src/lib.rs:588:17 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:192:8 | @@ -264,7 +261,7 @@ The type or module each refused type or path belongs to. ## Spans -
unsupported call to `_` (17) +
unsupported call to `_` (15) - fixtures/reject/src/lib.rs:138:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:192:8: unsupported call to `std::ops::Range::::contains::` @@ -280,9 +277,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:617:11: unsupported call to `std::alloc::alloc` - fixtures/reject/src/lib.rs:620:3: unsupported call to `std::alloc::dealloc` - fixtures/reject/src/lib.rs:816:15: unsupported call to ` as std::iter::Iterator>::is_sorted` -- fixtures/reject/src/lib.rs:896:27: unsupported call to ` as std::cmp::PartialEq>>::eq` -- fixtures/reject/src/lib.rs:911:27: unsupported call to ` as std::cmp::PartialEq<&[Right]>>::eq` -- fixtures/reject/src/lib.rs:986:10: unsupported call to ` as std::clone::Clone>::clone_from` +- fixtures/reject/src/lib.rs:966:10: unsupported call to ` as std::clone::Clone>::clone_from`
@@ -292,14 +287,14 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:719:2: a raw pointer to `(u32, u32)` in `Window`, which the crate may put another object in place of - fixtures/reject/src/lib.rs:737:15: a raw pointer to `(u32, u32)` in `std::cell::UnsafeCell<(u32, u32)>`, which the crate may put another object in place of - fixtures/reject/src/lib.rs:770:21: a raw pointer to `std::cell::UnsafeCell` in `Hits`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:926:10: a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:952:19: a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:972:19: a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:1008:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:1009:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:1010:58: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:1022:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:1023:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:906:10: a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:932:19: a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:952:19: a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:988:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:989:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:990:58: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:1002:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:1003:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of
@@ -331,7 +326,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:244:16: `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 - fixtures/reject/src/lib.rs:244:38: `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 - fixtures/reject/src/lib.rs:891:6: `std::collections::HashMap::::into_keys` 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:1030:6: `std::iter::Extend::extend` 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:1010:6: `std::iter::Extend::extend` 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 diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 275657c8c..ced7069ed 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -107,17 +107,15 @@ passing `Spent`, which drops, to `VecDeque::drain`, which is not supported yet a passing `Spent`, which drops, to `BTreeMap::range`, which is not supported yet at fixtures/reject/src/lib.rs:853:56 passing `{closure@fixtures/reject/src/lib.rs:859:11: 859:19}`, which drops, to `String::retain`, which is not supported yet at fixtures/reject/src/lib.rs:859:4 `std::collections::HashMap::::into_keys` 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:891:6 -unsupported call to ` as std::cmp::PartialEq>>::eq` at fixtures/reject/src/lib.rs:896:27 -unsupported call to ` as std::cmp::PartialEq<&[Right]>>::eq` at fixtures/reject/src/lib.rs:911:27 -a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:926:10 -a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:952:19 -a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:972:19 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1008:10 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1009:10 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1010:58 -a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1022:19 -a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1023:19 -`std::iter::Extend::extend` 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:1030:6 +a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:906:10 +a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:932:19 +a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:952:19 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:988:10 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:989:10 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:990:58 +a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1002:19 +a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1003:19 +`std::iter::Extend::extend` 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:1010:6 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:151:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:171:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:205:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index e8faf1f12..ffc54c437 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -891,26 +891,6 @@ pub fn byte_key(map: std::collections::HashMap<&[u8; 2], [u8; 2]>) -> u8 { map.into_keys().next().map_or(0, |k| k[0]) } -/// `next_if_eq` compares by the item's `PartialEq>`, which is refused as `==` is. -pub fn peeked_deque(v: Vec>) -> bool { - v.into_iter().peekable().next_if_eq(&vec![1]).is_some() -} - -pub struct Left(pub u16); - -pub struct Right(pub u16); - -impl PartialEq for Left { - fn eq(&self, other: &Right) -> bool { - self.0 % 4 == other.0 % 4 - } -} - -/// `Vec`s compare by their elements' `PartialEq`, not by `Left`'s own. -pub fn unlike_elements(v: Vec>, w: &[Right]) -> bool { - v.into_iter().peekable().next_if_eq(&w).is_some() -} - pub struct Plain { pub at: (u32, u32), } diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index b142d0f83..e47e0e381 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -92,8 +92,6 @@ roots = [ "bound_ranges", "string_retained", "byte_key", - "peeked_deque", - "unlike_elements", "put_replaced", "object_replaced", "closure_replaced", diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index 924a3a820..3d85d90e2 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -14,7 +14,7 @@ // A function that may drop a key, value, or item std's would, rather than return or keep // it, takes what drops each that does, as `k`, `v`, or `f`, and drops it where std's does. -import { ByteSlice, type ByteVec, type None, type Place, panic, type RangeBound, rangeCheck } from "../rt.ts"; +import { ByteSlice, ByteVec, type None, type Place, panic, type RangeBound, rangeCheck } from "../rt.ts"; import type { Hashing } from "./hash.ts"; import { type Limbs, lt } from "./int.ts"; import { @@ -275,6 +275,31 @@ export function eqSlice(eq: (a: T, b: T) => boolean): (a: ArrayLike, b: Ar }; } +/** A slice, an array, or a `Vec`, of bytes in any form, or a `VecDeque`. */ +type Seq = ArrayLike | ByteSlice | ByteVec | VecDeque; + +/** The length of `s` and what reads its element at an index. */ +function seqItems(s: Seq): [number, (i: number) => T] { + if (s instanceof ByteSlice) return [s.length, (i) => s.data[s.start + i] as T]; + if (s instanceof ByteVec) return [s.length, (i) => s.data[i] as T]; + if (!("length" in s)) return [s.n, (i) => s.b[at(s, i)] as T]; + return [s.length, (i) => s[i] as T]; +} + +/** + * `PartialEq::eq` of sequences of any form against each other, as std's of slices, arrays, + * `Vec`s, and `VecDeque`s are: their lengths, then each pair in order by `eq`. + */ +export function eqSeq(eq: (a: T, b: U) => boolean): (a: Seq, b: Seq) => boolean { + return (a, b) => { + const [n, x] = seqItems(a); + const [m, y] = seqItems(b); + if (n !== m) return false; + for (let i = 0; i < n; i++) if (!eq(x(i), y(i))) return false; + return true; + }; +} + /** `PartialEq::eq` of `Option`s, from their values'. */ export function eqOption(eq: (a: T, b: T) => boolean): (a: T | undefined, b: T | undefined) => boolean; export function eqOption(eq: (a: T, b: T) => boolean, none: None): (a: T | None, b: T | None) => boolean; diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index ef8db4804..7843ab346 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -115,6 +115,11 @@ pub fn call<'tcx>( let eq = Expr::rt("eqBytes", args); return Ok(Some(if name == "eq" { eq } else { eq.not() })); } + // Sequences of other forms or items, whose `ne` is `!eq`. + if let Some(eq) = seq_eq(b, t, rhs, span) { + let eq = eq.call(args); + return Ok(Some(if name == "eq" { eq } else { eq.not() })); + } let kind = b.t.std_of(t) == Some(Std::ErrorKind); if matches!(t.kind(), ty::Bool | ty::Int(_) | ty::Uint(_)) || bytes(b, t) @@ -1788,6 +1793,103 @@ pub fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr } } +/// `PartialEq::eq` of sequences of types `t` and `u`, as a function, where the runtime's of +/// keys does not compare them: a `VecDeque` against another sequence, or items that are no +/// key or compare by their own `PartialEq`. Else `None`. +fn seq_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, t: Ty<'tcx>, u: Ty<'tcx>, span: Span) -> Option { + let (t, u) = (peel(b, t), peel(b, u)); + let (Some(ti), Some(ui)) = (seq_item(b, t), seq_item(b, u)) else { + return None; + }; + let deque = [t, u].into_iter().any(|t| b.t.std_of(t) == Some(Std::VecDeque)); + if !deque && alike(b, t, u) && std_key(b, t) { + return None; + } + Some(Expr::rt("eqSeq", vec![item_eq(b, t, ti, ui, span)])) +} + +/// What a slice, an array, a `Vec`, or a `VecDeque` of type `ty` holds, bytes included. +fn seq_item<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Slice(item) | ty::Array(item, _) => Some(*item), + ty::Adt(..) if matches!(b.t.std_of(ty), Some(Std::Vec | Std::VecDeque)) => Some(arg(ty, 0)), + _ => None, + } +} + +/// What std's `!=` of a `t` and a `u` that sequence `seq` holds finds equal, as a function: +/// `>::ne`, which `!eq` stands for unless the crate overrides it. +fn item_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, seq: Ty<'tcx>, t: Ty<'tcx>, u: Ty<'tcx>, span: Span) -> Expr { + let tcx = b.t.tcx; + if let Some(eq) = seq_eq(b, t, u, span) { + return eq; + } + let (pt, pu) = (peel(b, t), peel(b, u)); + if b.t.deferred(pt) || b.t.deferred(pu) { + return Expr::undefined(); + } + if alike(b, pt, pu) { + if own_ne(b, pt) { + return b.err( + span, + format!( + "comparing `{seq}` by `<{pt} as PartialEq>::ne` through a held type's own, which is not supported yet" + ), + ); + } + return eq_fn(b, pt, span); + } + // By the impl itself, which a reference's forwards to. + let (pt, pu) = (peel_refs(b, t), peel_refs(b, u)); + let ne = trait_fn(tcx, "PartialEq", "ne"); + let own = Instance::try_resolve(tcx, b.t.typing_env_pub(), ne, tcx.mk_args(&[pt.into(), pu.into()])) + .ok() + .flatten() + .is_some_and(|instance| instance.def_id() != ne); + impl_eq(b, if own { "ne" } else { "eq" }, pt, pu, [t, u], span) +} + +/// `ty` through references that are no `rt.Place`, which JS holds as what they point at. +fn peel_refs<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.kind() { + ty::Ref(_, inner, _) if b.t.place_pointee(ty).is_none() => peel_refs(b, *inner), + _ => ty, + } +} + +/// `>::{name}`, `eq` or `ne`, as a function of what JS holds of types +/// `held`, references to `t` and `u` or they themselves: a `[u8; N]` held is a typed array, +/// lent as the `rt.ByteSlice` the impl's `&[u8; N]` is. A `ne` returns what `eq` would. +pub fn impl_eq<'tcx>( + b: &mut Body<'_, '_, 'tcx>, + name: &str, + t: Ty<'tcx>, + u: Ty<'tcx>, + held: [Ty<'tcx>; 2], + span: Span, +) -> Expr { + let tcx = b.t.tcx; + let f = trait_fn(tcx, "PartialEq", name); + let f = b.fn_value(f, tcx.mk_args(&[t.into(), u.into()]), span); + let ne = name == "ne"; + if !ne && !held.iter().any(|&ty| super::byte_array(ty)) { + return f; + } + let names = [b.fresh("a"), b.fresh("b")]; + let args = std::iter::zip(&names, held) + .map(|(name, ty)| match super::byte_array(ty) { + true => Expr::rt("byteSliceFrom", vec![Expr::ident(name)]), + false => Expr::ident(name), + }) + .collect(); + let call = f.call(args); + let params = std::iter::zip(names, held) + .map(|(name, ty)| Param { name, ty: Some(b.t.ty(ty, span)) }) + .collect(); + let ret = StmtKind::Return(Some(if ne { call.not() } else { call })).at(None); + Expr::Arrow(params, crate::ts::Type::Builtin("boolean"), vec![ret]) +} + /// `Hash::hash` of `ty` into a `hasher`, as a function: the runtime's for a std type, or /// the crate's. fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, span: Span) -> Expr { diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index 198c20c19..a90e36a66 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -12,7 +12,7 @@ use super::Translator; use super::body::Body; use super::library::{self, Call, Std}; use super::num::Int; -use crate::ts::{Expr, Param, StmtKind, Type}; +use crate::ts::{Expr, Param, Type}; /// `Iterator::next`, and the trait's `Item`. fn trait_items(tcx: ty::TyCtxt<'_>) -> Option<(DefId, DefId)> { @@ -492,29 +492,14 @@ pub fn call<'tcx>( // An item JS copies is lent as its place, and an object as itself. "peek_mut" => method(&camel, vec![Expr::lit(b.t.needs_place(item).to_string())]), // By the item's `PartialEq`: `eq_fn` of its own type, else the impl's `eq`, as a - // call to it lowers. + // call to it lowers, given a `&T`. "next_if_eq" => { let expected = targ(1)?; let eq = match expected == item { true => super::collections::eq_fn(b, item, span), false => { - let eq = super::collections::trait_fn(tcx, "PartialEq", "eq"); - let eq = b.fn_value(eq, tcx.mk_args(&[item.into(), expected.into()]), span); - match super::byte_array(item) { - // The `eq` takes a `&[u8; N]`, an `rt.ByteSlice` of the item's bytes. - true => { - let (a, c) = (b.fresh("a"), b.fresh("b")); - let lent = Expr::rt("byteSliceFrom", vec![Expr::ident(&a)]); - let call = eq.call(vec![lent, Expr::ident(&c)]); - let params = [a, c].map(|name| Param { name, ty: None }).into(); - Expr::Arrow( - params, - Type::Builtin("boolean"), - vec![StmtKind::Return(Some(call)).at(None)], - ) - } - false => eq, - } + let by = Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, expected); + super::collections::impl_eq(b, "eq", item, expected, [item, by], span) } }; method(&camel, [rest, vec![eq], none.into_iter().collect()].concat()) From 2132d1d4d3c01d4d6cb982213c26434d8bdf2551 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:15:36 -0700 Subject: [PATCH 3/6] chore(quest): plan equality through a held type's own ne Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 1 + quest/m3/ts-eq-own-ne.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 quest/m3/ts-eq-own-ne.md diff --git a/quest/m3/README.md b/quest/m3/README.md index 2a3c8135f..54ccff8e2 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -29,6 +29,7 @@ generic std gap is planned here even when moq never calls it. - [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate - [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does +- [Equality through a held type's own ne](/quest/m3/ts-eq-own-ne.md) - `==` of slices of a type whose `ne` the crate overrides, and `!=` of a tuple or `Arc` of one, translate - [A VecDeque's Debug](/quest/m3/ts-deque-debug.md) - `{:?}` of a `VecDeque` translates, writing std's list - [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it - [std's impls of its zero-sized types](/quest/m3/ts-zero-sized-impls.md) - `PhantomData`'s derived impls translate, and `()` is a hash or B-tree key diff --git a/quest/m3/ts-eq-own-ne.md b/quest/m3/ts-eq-own-ne.md new file mode 100644 index 000000000..356b06cb9 --- /dev/null +++ b/quest/m3/ts-eq-own-ne.md @@ -0,0 +1,16 @@ +# [S] Equality through a held type's own ne + +## Goal + +`==` of slices, `Vec`s, and `VecDeque`s of a crate's type whose `PartialEq` overrides `ne`, +and `!=` of a tuple or an `Arc` holding one, translate, proven by a differential test +against native Rust. + +## Plan + +Refused today with "through a held type's own" at the comparison's span: the runtime's +`eqSlice`, `eqTuple`, and `eqArc` compare by `eq`, where std's slices call each item's +`ne`, and a tuple's and an `Arc`'s `ne` call what they hold's. Items of unlike types +already compare by `!ne` through the crate's impl (`item_eq` in the collections +lowering); items of one type could do the same, and a tuple's or `Arc`'s `ne` could +lower by its fields' `ne`. From 5b81862b673bdd98bf7cd247009d43116726dfea Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:20:30 -0700 Subject: [PATCH 4/6] style(ts): format Co-Authored-By: Claude Opus 5.5 --- ts/src/lower/collections.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 7843ab346..9707b9dc5 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -1884,7 +1884,10 @@ pub fn impl_eq<'tcx>( .collect(); let call = f.call(args); let params = std::iter::zip(names, held) - .map(|(name, ty)| Param { name, ty: Some(b.t.ty(ty, span)) }) + .map(|(name, ty)| Param { + name, + ty: Some(b.t.ty(ty, span)), + }) .collect(); let ret = StmtKind::Return(Some(if ne { call.not() } else { call })).at(None); Expr::Arrow(params, crate::ts::Type::Builtin("boolean"), vec![ret]) From 92152140de96982c42f9315cf057cc8e32f5837c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:30:50 -0700 Subject: [PATCH 5/6] fix(ts): compare an item against a reference by its own impl, not as two of one type Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/collections.Left.ts | 10 ++ ts/fixtures/lang/expected/collections.ts | 126 ++++++++++-------- ts/fixtures/lang/src/collections.rs | 22 +++ ts/fixtures/reject/census.md | 61 ++++----- ts/fixtures/reject/expected.txt | 20 ++- ts/src/lower/collections.rs | 26 ++-- 6 files changed, 154 insertions(+), 111 deletions(-) diff --git a/ts/fixtures/lang/expected/collections.Left.ts b/ts/fixtures/lang/expected/collections.Left.ts index 3688ef7d4..3663aa2e0 100644 --- a/ts/fixtures/lang/expected/collections.Left.ts +++ b/ts/fixtures/lang/expected/collections.Left.ts @@ -22,4 +22,14 @@ export function ne$PartialEq_Right(self: Left, other: Right.Right): boolean { return rt.u16Rem(self._0, 3) !== rt.u16Rem(other._0, 3); } +export function eq$PartialEq_Right(self: Left, other: Right.Right): boolean { + log(self, 2048); + return rt.u16Rem(self._0, 5) === rt.u16Rem(other._0, 5); +} + +export function eq$PartialEq_Left(self: Left, other: Left): boolean { + log(self, 4096); + return rt.u16Rem(self._0, 2) === rt.u16Rem(other._0, 2); +} + //# sourceMappingURL=collections.Left.ts.map diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index c6bce3944..04c3fb53d 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -3659,111 +3659,119 @@ export function unlikeEqs(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): voi putEq(rt.eqSeq(rt.eqSeq((a24: Left.Left, b22: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a24, b22); }))(_179, _186), log, out); + const refs: Right.Right[] = rt.iterToArray(rt.iterSlice(rights), undefined, 4, true); + putEq(rt.eqSeq(Left.eq$PartialEq_Right)(mine, refs), log, out); + const _204: Left.Left[] = rt.iterToArray(rt.iterSlice(mine), undefined, 4, true); + putEq(rt.eqSeq((a25: Left.Left, b23: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a25, b23); + })(_204, refs), log, out); + const _216: Left.Left[] = rt.iterToArray(rt.iterSlice(lefts()), undefined, 4, true); + putEq(rt.eqSeq(Left.eq$PartialEq_Left)(mine, _216), log, out); const half: rt.usize = rt.usizeDiv(data.length, 2); const q: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); while (true) { - const _202: rt.u8 | rt.Done = iter.next(); - if (_202 === rt.DONE) { + const _231: rt.u8 | rt.Done = iter.next(); + if (_231 === rt.DONE) { break; } - const _208: Left.Left = { _0: _202 as rt.u16, _1: log }; - rt.dequePushFront(q, _208); + const _237: Left.Left = { _0: _231 as rt.u16, _1: log }; + rt.dequePushFront(q, _237); } - for (const _215 of rt.byteSliceView(rt.byteSliceRange(data, half))) { - const _221: Left.Left = { _0: _215 as rt.u16, _1: log }; - rt.dequePushBack(q, _221); + for (const _244 of rt.byteSliceView(rt.byteSliceRange(data, half))) { + const _250: Left.Left = { _0: _244 as rt.u16, _1: log }; + rt.dequePushBack(q, _250); } - const _228: Right.Right[] = rights; - putEq(rt.eqSeq((a25: Left.Left, b23: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a25, b23); - })(q, _228), log, out); + const _257: Right.Right[] = rights; putEq(rt.eqSeq((a26: Left.Left, b24: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a26, b24); - })(q, rights), log, out); - const _240: Right.Right[] = rights; - putEq(!rt.eqSeq((a27: Left.Left, b25: Right.Right): boolean => { + })(q, _257), log, out); + putEq(rt.eqSeq((a27: Left.Left, b25: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a27, b25); - })(q, _240), log, out); - const _248: Right.Right[] = rights; - putEq(rt.eqSeq((a28: Left.Left, b26: Right.Right): boolean => { + })(q, rights), log, out); + const _269: Right.Right[] = rights; + putEq(!rt.eqSeq((a28: Left.Left, b26: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a28, b26); - })(q, _248), log, out); - const _255: Right.Right[] = pair(); + })(q, _269), log, out); + const _277: Right.Right[] = rights; putEq(rt.eqSeq((a29: Left.Left, b27: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a29, b27); - })(q, _255), log, out); - const _263: Right.Right[] = pair(); + })(q, _277), log, out); + const _284: Right.Right[] = pair(); putEq(rt.eqSeq((a30: Left.Left, b28: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a30, b28); - })(q, _263), log, out); - const _271: Right.Right[] = pair(); + })(q, _284), log, out); + const _292: Right.Right[] = pair(); putEq(rt.eqSeq((a31: Left.Left, b29: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a31, b29); - })(q, _271), log, out); + })(q, _292), log, out); + const _300: Right.Right[] = pair(); + putEq(rt.eqSeq((a32: Left.Left, b30: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a32, b30); + })(q, _300), log, out); const bytes: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter3: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); while (true) { - const _281: rt.u8 | rt.Done = iter3.next(); - if (_281 === rt.DONE) { + const _310: rt.u8 | rt.Done = iter3.next(); + if (_310 === rt.DONE) { break; } - rt.dequePushFront(bytes, _281); + rt.dequePushFront(bytes, _310); } - const _289: rt.ByteSlice = rt.byteSliceRange(data, half); - rt.dequeExtend(bytes, rt.iterSlice(rt.byteSliceView(_289)), undefined, 1, true); - const stepped: rt.ByteVec = rt.iterToByteVec(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_214: [rt.usize, rt.u8]): rt.u8 => { - return _214[1] ^ (_214[0] === byEq ? 1 : 0); + const _318: rt.ByteSlice = rt.byteSliceRange(data, half); + rt.dequeExtend(bytes, rt.iterSlice(rt.byteSliceView(_318)), undefined, 1, true); + const stepped: rt.ByteVec = rt.iterToByteVec(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_211: [rt.usize, rt.u8]): rt.u8 => { + return _211[1] ^ (_211[0] === byEq ? 1 : 0); }), undefined, true); putEq(rt.eqSeq(rt.same)(bytes, stepped), log, out); putEq(rt.eqSeq(rt.same)(bytes, data), log, out); - const _310: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of(unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 0), 0)); - putEq(rt.eqSeq(rt.same)(bytes, _310), log, out); - const _317: rt.Iter = rt.iterMap(rt.dequeIter(bytes), (_216: rt.u8): rt.u16 => { - return _216 as rt.u16; + const _339: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of(unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 0), 0)); + putEq(rt.eqSeq(rt.same)(bytes, _339), log, out); + const _346: rt.Iter = rt.iterMap(rt.dequeIter(bytes), (_212: rt.u8): rt.u16 => { + return _212 as rt.u16; }); - const wide_: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _317, undefined, 2, true); + const wide_: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _346, undefined, 2, true); const wrapped: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter4: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteVecSlice(stepped)))); while (true) { - const _327: rt.u8 | rt.Done = iter4.next(); - if (_327 === rt.DONE) { + const _356: rt.u8 | rt.Done = iter4.next(); + if (_356 === rt.DONE) { break; } - rt.dequePushFront(wrapped, _327 as rt.u16); + rt.dequePushFront(wrapped, _356 as rt.u16); } putEq(rt.eqSeq(rt.same)(wide_, wrapped), log, out); - const _342: rt.VecDeque[] = [rt.dequeClone(wide_, undefined)]; - const _347: rt.VecDeque[] = [wrapped]; - putEq(rt.eqSeq(rt.eqSeq(rt.same))(_342, _347), log, out); + const _371: rt.VecDeque[] = [rt.dequeClone(wide_, undefined)]; + const _376: rt.VecDeque[] = [wrapped]; + putEq(rt.eqSeq(rt.eqSeq(rt.same))(_371, _376), log, out); const it: rt.Peekable = rt.iterPeekable(rt.iterSlice([lefts(), lefts(), lefts()])); - const exact: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_217: rt.u8): Right.Right => { - return { _0: _217 as rt.u16 }; + const exact: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_214: rt.u8): Right.Right => { + return { _0: _214 as rt.u16 }; }), undefined, 2, true); - putEq(rt.peekableNextIfEq(it, exact, (a027: Left.Left[], a127: Right.Right[]): boolean => { - return rt.eqSeq((a32: Left.Left, b33: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a32, b33); - })(a027, a127); - }) !== undefined, log, out); - putEq(rt.peekableNextIfEq(it, rights, (a029: Left.Left[], a129: Right.Right[]): boolean => { + putEq(rt.peekableNextIfEq(it, exact, (a030: Left.Left[], a130: Right.Right[]): boolean => { return rt.eqSeq((a33: Left.Left, b34: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a33, b34); - })(a029, a129); + })(a030, a130); }) !== undefined, log, out); - const _385: Right.Right[] = rt.sliceRange(exact, 0, half); - putEq(rt.peekableNextIfEq(it, _385, (a031: Left.Left[], a131: Right.Right[]): boolean => { + putEq(rt.peekableNextIfEq(it, rights, (a032: Left.Left[], a132: Right.Right[]): boolean => { return rt.eqSeq((a34: Left.Left, b35: Right.Right): boolean => { return !Left.ne$PartialEq_Right(a34, b35); - })(a031, a131); + })(a032, a132); + }) !== undefined, log, out); + const _414: Right.Right[] = rt.sliceRange(exact, 0, half); + putEq(rt.peekableNextIfEq(it, _414, (a034: Left.Left[], a134: Right.Right[]): boolean => { + return rt.eqSeq((a35: Left.Left, b36: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a35, b36); + })(a034, a134); }) !== undefined, log, out); rt.byteVecPush(out, rt.iterCount(it) & 0xff); const it2: rt.Peekable> = rt.iterPeekable(rt.iterSlice([rt.dequeClone(bytes, undefined), bytes])); - const _406: rt.ByteVec = rt.byteSliceToByteVec(data); - putEq(rt.peekableNextIfEq(it2, _406, (a033: rt.VecDeque, a133: rt.ByteVec): boolean => { - return rt.eqSeq(rt.same)(a033, a133); + const _435: rt.ByteVec = rt.byteSliceToByteVec(data); + putEq(rt.peekableNextIfEq(it2, _435, (a036: rt.VecDeque, a136: rt.ByteVec): boolean => { + return rt.eqSeq(rt.same)(a036, a136); }) !== undefined, log, out); - putEq(rt.peekableNextIfEq(it2, stepped, (a034: rt.VecDeque, a134: rt.ByteVec): boolean => { - return rt.eqSeq(rt.same)(a034, a134); + putEq(rt.peekableNextIfEq(it2, stepped, (a037: rt.VecDeque, a137: rt.ByteVec): boolean => { + return rt.eqSeq(rt.same)(a037, a137); }) !== undefined, log, out); rt.byteVecPush(out, rt.iterCount(it2) & 0xff); } diff --git a/ts/fixtures/lang/src/collections.rs b/ts/fixtures/lang/src/collections.rs index ad4e3c800..f67628bc7 100644 --- a/ts/fixtures/lang/src/collections.rs +++ b/ts/fixtures/lang/src/collections.rs @@ -1198,6 +1198,22 @@ impl PartialEq for Left<'_> { } } +/// Against a reference, by the remainder by 5, which no reference's impl forwards to. +impl PartialEq<&Right> for Left<'_> { + fn eq(&self, other: &&Right) -> bool { + self.log(0x800); + self.0 % 5 == other.0 % 5 + } +} + +/// Against a reference to another, by the remainder by 2. +impl<'a> PartialEq<&Left<'a>> for Left<'_> { + fn eq(&self, other: &&Left<'a>) -> bool { + self.log(0x1000); + self.0 % 2 == other.0 % 2 + } +} + /// The other way, by the remainder by 4, with `ne`'s default. impl<'a> PartialEq> for Right { fn eq(&self, other: &Left<'a>) -> bool { @@ -1274,6 +1290,12 @@ pub fn unlike_eqs(kind: u8, data: &[u8], out: &mut Vec) { let pairs: Vec<[u8; 2]> = data.chunks_exact(2).map(|c| [c[0], c[1]]).collect(); put_eq(pairs[..] == rights[..pairs.len().min(rights.len())], &log, out); put_eq(vec![lefts(), lefts()] == [rights.as_slice(), &rights[..]], &log, out); + // By the impls against references, and through references of both, by `Right`'s. + let refs: Vec<&Right> = rights.iter().collect(); + put_eq(mine == refs, &log, out); + put_eq(mine.iter().collect::>() == refs, &log, out); + let others = lefts(); + put_eq(mine == others.iter().collect::>(), &log, out); // Wrapped around: the first half pushed to the front backwards, the rest to the back. let half = data.len() / 2; diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index d36414e8e..c003c0c65 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,14 +1,14 @@ # Census of `reject-fixture` -- Refusals: 121 -- Function instances: 147 +- Refusals: 119 +- Function instances: 144 - Generic functions no instance reached, lowered over their type parameters: 10 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 17 | unsupported call to `_` | fixtures/reject/src/lib.rs:129:11 | +| 15 | unsupported call to `_` | fixtures/reject/src/lib.rs:129:11 | | 12 | a raw pointer to `_` in `_`, which the crate may put another object in place of | fixtures/reject/src/lib.rs:648:10 | | 8 | a raw pointer to `_` in a variable assigned again while it may point there | fixtures/reject/src/lib.rs:656:10 | | 4 | `_` 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:235:16 | @@ -82,13 +82,13 @@ The type or module each refused type or path belongs to. | 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:369:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:16:15 | | 6 | `f16` | fixtures/reject/src/lib.rs:7:14 | -| 5 | `Gap` | fixtures/reject/src/lib.rs:973:10 | +| 5 | `Gap` | fixtures/reject/src/lib.rs:953:10 | | 5 | `u32` | fixtures/reject/src/lib.rs:595:27 | | 4 | `Iterator` | fixtures/reject/src/lib.rs:42:4 | | 4 | `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:727:15 | | 4 | `std::pin::Pin` | fixtures/reject/src/lib.rs:103:2 | -| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:348:16 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:306:2 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:348:16 | | 3 | `u8` | fixtures/reject/src/lib.rs:274:6 | | 3 | `{closure}` | fixtures/reject/src/lib.rs:357:13 | | 2 | `Poll` | fixtures/reject/src/lib.rs:84:20 | @@ -102,7 +102,7 @@ The type or module each refused type or path belongs to. | 2 | `std::collections::BTreeSet` | fixtures/reject/src/lib.rs:256:75 | | 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:274:6 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:235:16 | -| 2 | `std::mem::MaybeUninit` | fixtures/reject/src/lib.rs:987:19 | +| 2 | `std::mem::MaybeUninit` | fixtures/reject/src/lib.rs:967:19 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:183:8 | | 2 | `std::std` | fixtures/reject/src/lib.rs:607:11 | | 2 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:95:2 | @@ -118,16 +118,16 @@ The type or module each refused type or path belongs to. | 1 | `HashMap` | fixtures/reject/src/lib.rs:274:6 | | 1 | `Hasher` | fixtures/reject/src/lib.rs:282:9 | | 1 | `Hits` | fixtures/reject/src/lib.rs:760:21 | -| 1 | `Lane` | fixtures/reject/src/lib.rs:937:19 | +| 1 | `Lane` | fixtures/reject/src/lib.rs:917:19 | | 1 | `Maybe` | fixtures/reject/src/lib.rs:31:2 | | 1 | `Only` | fixtures/reject/src/lib.rs:777:11 | -| 1 | `Plain` | fixtures/reject/src/lib.rs:891:10 | +| 1 | `Plain` | fixtures/reject/src/lib.rs:871:10 | | 1 | `Sink` | fixtures/reject/src/lib.rs:67:10 | | 1 | `Span2` | fixtures/reject/src/lib.rs:648:10 | | 1 | `String` | fixtures/reject/src/lib.rs:824:4 | | 1 | `T \| undefined` | fixtures/reject/src/lib.rs:31:2 | | 1 | `Tail` | fixtures/reject/src/lib.rs:524:30 | -| 1 | `Track` | fixtures/reject/src/lib.rs:917:19 | +| 1 | `Track` | fixtures/reject/src/lib.rs:897:19 | | 1 | `Waiting` | fixtures/reject/src/lib.rs:535:2 | | 1 | `Window` | fixtures/reject/src/lib.rs:709:2 | | 1 | `[u8; 4]` | fixtures/reject/src/lib.rs:514:26 | @@ -135,9 +135,8 @@ The type or module each refused type or path belongs to. | 1 | `poll` | fixtures/reject/src/lib.rs:535:2 | | 1 | `rt.Poll` | fixtures/reject/src/lib.rs:535:2 | | 1 | `std::any::Any` | fixtures/reject/src/lib.rs:578:4 | -| 1 | `std::collections::VecDeque` | fixtures/reject/src/lib.rs:861:27 | | 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:175:51 | -| 1 | `std::iter::Extend` | fixtures/reject/src/lib.rs:995:6 | +| 1 | `std::iter::Extend` | fixtures/reject/src/lib.rs:975:6 | | 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:224:30 | | 1 | `std::net::AddrParseError` | fixtures/reject/src/lib.rs:471:32 | | 1 | `std::net::Ipv4Addr` | fixtures/reject/src/lib.rs:471:32 | @@ -160,13 +159,13 @@ The type or module each refused type or path belongs to. | ---: | --- | --- | --- | | 6 | a raw pointer to `_` in a variable assigned again while it may point there | `(u32, u32)` | fixtures/reject/src/lib.rs:656:10 | | 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:369:2 | -| 3 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Gap` | fixtures/reject/src/lib.rs:973:10 | +| 3 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Gap` | fixtures/reject/src/lib.rs:953:10 | | 3 | unsupported type `_` | `f16` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:16:15 | | 2 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::scan`, `Option` | fixtures/reject/src/lib.rs:42:4 | | 2 | `_`, a trait object of another crate's trait, which is not supported yet | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | | 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | `dyn Scaled`, `Scaled` | fixtures/reject/src/lib.rs:497:23 | -| 2 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::mem::MaybeUninit`, `Gap` | fixtures/reject/src/lib.rs:987:19 | +| 2 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::mem::MaybeUninit`, `Gap` | fixtures/reject/src/lib.rs:967:19 | | 2 | a raw pointer to `_` in a variable assigned again while it may point there | `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:736:15 | | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:119:2 | | 2 | replacing the value behind a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:103:2 | @@ -183,7 +182,7 @@ The type or module each refused type or path belongs to. | 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::clone_from_slice`, `Reused` | fixtures/reject/src/lib.rs:324:4 | | 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::fill`, `Reused` | fixtures/reject/src/lib.rs:21:4 | | 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::collections::HashMap::into_keys` | fixtures/reject/src/lib.rs:856: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::Extend::extend` | fixtures/reject/src/lib.rs:995: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::Extend::extend` | fixtures/reject/src/lib.rs:975: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:235: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:235:16 | | 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:306:2 | @@ -202,10 +201,10 @@ The type or module each refused type or path belongs to. | 1 | a dangling pointer to `_`, a value of no bytes made of more than structs and tuples | `Only` | fixtures/reject/src/lib.rs:777:11 | | 1 | a future of `_`, which can be `rt.Pending`, as the future's own `Pending` is | `std::task::Poll` | fixtures/reject/src/lib.rs:89:34 | | 1 | a raw pointer to `_` behind a reference, which is the object and not where it is kept | `std::vec::Vec` | fixtures/reject/src/lib.rs:617:10 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Lane` | fixtures/reject/src/lib.rs:937:19 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Plain` | fixtures/reject/src/lib.rs:891:10 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Lane` | fixtures/reject/src/lib.rs:917:19 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Plain` | fixtures/reject/src/lib.rs:871:10 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Span2` | fixtures/reject/src/lib.rs:648:10 | -| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Track` | fixtures/reject/src/lib.rs:917:19 | +| 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Track` | fixtures/reject/src/lib.rs:897:19 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `Window` | fixtures/reject/src/lib.rs:709:2 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `(u32, u32)`, `std::cell::UnsafeCell` | fixtures/reject/src/lib.rs:727:15 | | 1 | a raw pointer to `_` in `_`, which the crate may put another object in place of | `std::cell::UnsafeCell`, `Hits` | fixtures/reject/src/lib.rs:760:21 | @@ -234,12 +233,10 @@ The type or module each refused type or path belongs to. | 1 | union `_`, whose fields overlap in `_` and `f64`, which JS keeps apart | `Bits`, `u32` | fixtures/reject/src/lib.rs:622:1 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:578:2 | | 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:381:2 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:861:27 | | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:407:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:129:11 | | 1 | unsupported call to `_` | `::is_sorted` | fixtures/reject/src/lib.rs:806:15 | -| 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:951:10 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:876:27 | +| 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:931:10 | | 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:339:10 | | 1 | unsupported call to `_` | `std::any::TypeId::of` | fixtures/reject/src/lib.rs:578:17 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:183:8 | @@ -252,7 +249,7 @@ The type or module each refused type or path belongs to. ## Spans -
unsupported call to `_` (17) +
unsupported call to `_` (15) - fixtures/reject/src/lib.rs:129:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:183:8: unsupported call to `std::ops::Range::::contains::` @@ -268,9 +265,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:607:11: unsupported call to `std::alloc::alloc` - fixtures/reject/src/lib.rs:610:3: unsupported call to `std::alloc::dealloc` - fixtures/reject/src/lib.rs:806:15: unsupported call to ` as std::iter::Iterator>::is_sorted` -- fixtures/reject/src/lib.rs:861:27: unsupported call to ` as std::cmp::PartialEq>>::eq` -- fixtures/reject/src/lib.rs:876:27: unsupported call to ` as std::cmp::PartialEq<&[Right]>>::eq` -- fixtures/reject/src/lib.rs:951:10: unsupported call to ` as std::clone::Clone>::clone_from` +- fixtures/reject/src/lib.rs:931:10: unsupported call to ` as std::clone::Clone>::clone_from`
@@ -280,14 +275,14 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:709:2: a raw pointer to `(u32, u32)` in `Window`, which the crate may put another object in place of - fixtures/reject/src/lib.rs:727:15: a raw pointer to `(u32, u32)` in `std::cell::UnsafeCell<(u32, u32)>`, which the crate may put another object in place of - fixtures/reject/src/lib.rs:760:21: a raw pointer to `std::cell::UnsafeCell` in `Hits`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:891:10: a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:917:19: a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:937:19: a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:973:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:974:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:975:58: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:987:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of -- fixtures/reject/src/lib.rs:988:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:871:10: a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:897:19: a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:917:19: a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:953:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:954:10: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:955:58: a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:967:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of +- fixtures/reject/src/lib.rs:968:19: a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of
@@ -309,7 +304,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:235:16: `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 - fixtures/reject/src/lib.rs:235:38: `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 - fixtures/reject/src/lib.rs:856:6: `std::collections::HashMap::::into_keys` 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:995:6: `std::iter::Extend::extend` 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:975:6: `std::iter::Extend::extend` 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 diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index a497a6173..a0b936a3b 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -102,17 +102,15 @@ comparing pointers to `u32` in an atomic, which JS has no address of at fixtures a constant of type `&u32`, a pointer into memory translation can't name at fixtures/reject/src/lib.rs:818:3 passing `{closure@fixtures/reject/src/lib.rs:824:11: 824:19}`, which drops, to `String::retain`, which is not supported yet at fixtures/reject/src/lib.rs:824:4 `std::collections::HashMap::::into_keys` 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:856:6 -unsupported call to ` as std::cmp::PartialEq>>::eq` at fixtures/reject/src/lib.rs:861:27 -unsupported call to ` as std::cmp::PartialEq<&[Right]>>::eq` at fixtures/reject/src/lib.rs:876:27 -a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:891:10 -a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:917:19 -a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:937:19 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:973:10 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:974:10 -a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:975:58 -a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:987:19 -a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:988:19 -`std::iter::Extend::extend` 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:995:6 +a raw pointer to `(u32, u32)` in `Plain`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:871:10 +a raw pointer to `(u32, u32)` in `Track`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:897:19 +a raw pointer to `(u32, u32)` in `Lane`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:917:19 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:953:10 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:954:10 +a raw pointer to `(u32, u32)` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:955:58 +a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:967:19 +a raw pointer to `std::mem::MaybeUninit<(u32, u32)>` in `Gap`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:968:19 +`std::iter::Extend::extend` 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:975:6 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:142:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:162:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:196:2 diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 050f92e61..02dd1fc1d 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -498,6 +498,12 @@ fn same_key<'tcx>(b: &Body<'_, '_, 'tcx>, key: Ty<'tcx>, by: Ty<'tcx>) -> bool { /// Whether a `ty` compares to an `other` as to another `ty`: as keys do, as bytes do, or /// by elements that do. Else the impl of `PartialEq` is its own. fn alike<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool { + // A crate's type against a reference compares by an impl of the crate's own, which no + // reference's forwards to. + let (ty, other) = peel_pair(b, ty, other); + if (ty.is_ref() || other.is_ref()) && (local(b, peel(b, ty)) || local(b, peel(b, other))) { + return false; + } let (ty, other) = (peel(b, ty), peel(b, other)); same_key(b, ty, other) || (bytes(b, ty) && bytes(b, other)) @@ -1862,7 +1868,7 @@ fn item_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, seq: Ty<'tcx>, t: Ty<'tcx>, u: Ty<' if b.t.deferred(pt) || b.t.deferred(pu) { return Expr::undefined(); } - if alike(b, pt, pu) { + if alike(b, t, u) { if own_ne(b, pt) { return b.err( span, @@ -1873,8 +1879,7 @@ fn item_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, seq: Ty<'tcx>, t: Ty<'tcx>, u: Ty<' } return eq_fn(b, pt, span); } - // By the impl itself, which a reference's forwards to. - let (pt, pu) = (peel_refs(b, t), peel_refs(b, u)); + let (pt, pu) = peel_pair(b, t, u); let ne = trait_fn(tcx, "PartialEq", "ne"); let own = Instance::try_resolve(tcx, b.t.typing_env_pub(), ne, tcx.mk_args(&[pt.into(), pu.into()])) .ok() @@ -1883,11 +1888,16 @@ fn item_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, seq: Ty<'tcx>, t: Ty<'tcx>, u: Ty<' impl_eq(b, if own { "ne" } else { "eq" }, pt, pu, [t, u], span) } -/// `ty` through references that are no `rt.Place`, which JS holds as what they point at. -fn peel_refs<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - match ty.kind() { - ty::Ref(_, inner, _) if b.t.place_pointee(ty).is_none() => peel_refs(b, *inner), - _ => ty, +/// `t` and `u` through the references std's `PartialEq` of two references forwards +/// through, one of each at a time, while JS holds both as what they point at. +fn peel_pair<'tcx>(b: &Body<'_, '_, 'tcx>, t: Ty<'tcx>, u: Ty<'tcx>) -> (Ty<'tcx>, Ty<'tcx>) { + match (t.kind(), u.kind()) { + (ty::Ref(_, t_in, _), ty::Ref(_, u_in, _)) + if b.t.place_pointee(t).is_none() && b.t.place_pointee(u).is_none() => + { + peel_pair(b, *t_in, *u_in) + } + _ => (t, u), } } From 22ae2011cf9b423f7514bea323d7047dc26f1242 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:36:41 -0700 Subject: [PATCH 6/6] fix(ts): stop at a crate's own PartialEq of two references Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/collections.Odd.ts | 18 +++ ts/fixtures/lang/expected/collections.ts | 145 ++++++++++--------- ts/fixtures/lang/src/collections.rs | 12 ++ ts/src/lower/collections.rs | 13 +- 4 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 ts/fixtures/lang/expected/collections.Odd.ts diff --git a/ts/fixtures/lang/expected/collections.Odd.ts b/ts/fixtures/lang/expected/collections.Odd.ts new file mode 100644 index 000000000..a40eadcbc --- /dev/null +++ b/ts/fixtures/lang/expected/collections.Odd.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import type * as Right from "./collections.Right.ts"; + +/** + * An item only a reference to compares, by the crate's impl of two references, which + * std's of references would otherwise forward from. + */ +export interface Odd { + _0: rt.u16; +} + +export function eq$PartialEq_Right(self: Odd, other: Right.Right): boolean { + return rt.u16Rem(self._0, 2) === rt.u16Rem(other._0, 2); +} + +//# sourceMappingURL=collections.Odd.ts.map diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 04c3fb53d..68d76c85a 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -9,6 +9,7 @@ import * as Fussy from "./collections.Fussy.ts"; import type * as Holder from "./collections.Holder.ts"; import * as Left from "./collections.Left.ts"; import * as Nibble from "./collections.Nibble.ts"; +import * as Odd from "./collections.Odd.ts"; import * as Pair from "./collections.Pair.ts"; import * as Rank from "./collections.Rank.ts"; import * as Right from "./collections.Right.ts"; @@ -3667,112 +3668,116 @@ export function unlikeEqs(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): voi })(_204, refs), log, out); const _216: Left.Left[] = rt.iterToArray(rt.iterSlice(lefts()), undefined, 4, true); putEq(rt.eqSeq(Left.eq$PartialEq_Left)(mine, _216), log, out); + const _227: Odd.Odd[] = rt.iterToArray(rt.iterSlice(rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_211: rt.u8): Odd.Odd => { + return { _0: _211 as rt.u16 }; + }), undefined, 2, true)), undefined, 4, true); + putEq(rt.eqSeq(Odd.eq$PartialEq_Right)(_227, refs), log, out); const half: rt.usize = rt.usizeDiv(data.length, 2); const q: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); while (true) { - const _231: rt.u8 | rt.Done = iter.next(); - if (_231 === rt.DONE) { + const _243: rt.u8 | rt.Done = iter.next(); + if (_243 === rt.DONE) { break; } - const _237: Left.Left = { _0: _231 as rt.u16, _1: log }; - rt.dequePushFront(q, _237); + const _249: Left.Left = { _0: _243 as rt.u16, _1: log }; + rt.dequePushFront(q, _249); } - for (const _244 of rt.byteSliceView(rt.byteSliceRange(data, half))) { - const _250: Left.Left = { _0: _244 as rt.u16, _1: log }; - rt.dequePushBack(q, _250); + for (const _256 of rt.byteSliceView(rt.byteSliceRange(data, half))) { + const _262: Left.Left = { _0: _256 as rt.u16, _1: log }; + rt.dequePushBack(q, _262); } - const _257: Right.Right[] = rights; - putEq(rt.eqSeq((a26: Left.Left, b24: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a26, b24); - })(q, _257), log, out); - putEq(rt.eqSeq((a27: Left.Left, b25: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a27, b25); - })(q, rights), log, out); const _269: Right.Right[] = rights; - putEq(!rt.eqSeq((a28: Left.Left, b26: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a28, b26); + putEq(rt.eqSeq((a26: Left.Left, b25: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a26, b25); })(q, _269), log, out); - const _277: Right.Right[] = rights; - putEq(rt.eqSeq((a29: Left.Left, b27: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a29, b27); - })(q, _277), log, out); - const _284: Right.Right[] = pair(); - putEq(rt.eqSeq((a30: Left.Left, b28: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a30, b28); - })(q, _284), log, out); - const _292: Right.Right[] = pair(); - putEq(rt.eqSeq((a31: Left.Left, b29: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a31, b29); - })(q, _292), log, out); - const _300: Right.Right[] = pair(); - putEq(rt.eqSeq((a32: Left.Left, b30: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a32, b30); - })(q, _300), log, out); + putEq(rt.eqSeq((a27: Left.Left, b26: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a27, b26); + })(q, rights), log, out); + const _281: Right.Right[] = rights; + putEq(!rt.eqSeq((a28: Left.Left, b27: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a28, b27); + })(q, _281), log, out); + const _289: Right.Right[] = rights; + putEq(rt.eqSeq((a29: Left.Left, b28: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a29, b28); + })(q, _289), log, out); + const _296: Right.Right[] = pair(); + putEq(rt.eqSeq((a30: Left.Left, b29: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a30, b29); + })(q, _296), log, out); + const _304: Right.Right[] = pair(); + putEq(rt.eqSeq((a31: Left.Left, b30: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a31, b30); + })(q, _304), log, out); + const _312: Right.Right[] = pair(); + putEq(rt.eqSeq((a32: Left.Left, b31: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a32, b31); + })(q, _312), log, out); const bytes: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter3: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 0, half)))); while (true) { - const _310: rt.u8 | rt.Done = iter3.next(); - if (_310 === rt.DONE) { + const _322: rt.u8 | rt.Done = iter3.next(); + if (_322 === rt.DONE) { break; } - rt.dequePushFront(bytes, _310); + rt.dequePushFront(bytes, _322); } - const _318: rt.ByteSlice = rt.byteSliceRange(data, half); - rt.dequeExtend(bytes, rt.iterSlice(rt.byteSliceView(_318)), undefined, 1, true); - const stepped: rt.ByteVec = rt.iterToByteVec(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_211: [rt.usize, rt.u8]): rt.u8 => { - return _211[1] ^ (_211[0] === byEq ? 1 : 0); + const _330: rt.ByteSlice = rt.byteSliceRange(data, half); + rt.dequeExtend(bytes, rt.iterSlice(rt.byteSliceView(_330)), undefined, 1, true); + const stepped: rt.ByteVec = rt.iterToByteVec(rt.iterMap(rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))), (_212: [rt.usize, rt.u8]): rt.u8 => { + return _212[1] ^ (_212[0] === byEq ? 1 : 0); }), undefined, true); putEq(rt.eqSeq(rt.same)(bytes, stepped), log, out); putEq(rt.eqSeq(rt.same)(bytes, data), log, out); - const _339: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of(unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 0), 0)); - putEq(rt.eqSeq(rt.same)(bytes, _339), log, out); - const _346: rt.Iter = rt.iterMap(rt.dequeIter(bytes), (_212: rt.u8): rt.u16 => { - return _212 as rt.u16; + const _351: rt.ByteSlice = rt.byteSliceFrom(Uint8Array.of(unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 0), 0)); + putEq(rt.eqSeq(rt.same)(bytes, _351), log, out); + const _358: rt.Iter = rt.iterMap(rt.dequeIter(bytes), (_214: rt.u8): rt.u16 => { + return _214 as rt.u16; }); - const wide_: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _346, undefined, 2, true); + const wide_: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, _358, undefined, 2, true); const wrapped: rt.VecDeque = rt.dequeNew() as rt.VecDeque; const iter4: rt.Iter = rt.iterRev(rt.iterSlice(rt.byteSliceView(rt.byteVecSlice(stepped)))); while (true) { - const _356: rt.u8 | rt.Done = iter4.next(); - if (_356 === rt.DONE) { + const _368: rt.u8 | rt.Done = iter4.next(); + if (_368 === rt.DONE) { break; } - rt.dequePushFront(wrapped, _356 as rt.u16); + rt.dequePushFront(wrapped, _368 as rt.u16); } putEq(rt.eqSeq(rt.same)(wide_, wrapped), log, out); - const _371: rt.VecDeque[] = [rt.dequeClone(wide_, undefined)]; - const _376: rt.VecDeque[] = [wrapped]; - putEq(rt.eqSeq(rt.eqSeq(rt.same))(_371, _376), log, out); + const _383: rt.VecDeque[] = [rt.dequeClone(wide_, undefined)]; + const _388: rt.VecDeque[] = [wrapped]; + putEq(rt.eqSeq(rt.eqSeq(rt.same))(_383, _388), log, out); const it: rt.Peekable = rt.iterPeekable(rt.iterSlice([lefts(), lefts(), lefts()])); - const exact: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_214: rt.u8): Right.Right => { - return { _0: _214 as rt.u16 }; + const exact: Right.Right[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_215: rt.u8): Right.Right => { + return { _0: _215 as rt.u16 }; }), undefined, 2, true); - putEq(rt.peekableNextIfEq(it, exact, (a030: Left.Left[], a130: Right.Right[]): boolean => { - return rt.eqSeq((a33: Left.Left, b34: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a33, b34); - })(a030, a130); + putEq(rt.peekableNextIfEq(it, exact, (a031: Left.Left[], a131: Right.Right[]): boolean => { + return rt.eqSeq((a33: Left.Left, b35: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a33, b35); + })(a031, a131); }) !== undefined, log, out); - putEq(rt.peekableNextIfEq(it, rights, (a032: Left.Left[], a132: Right.Right[]): boolean => { - return rt.eqSeq((a34: Left.Left, b35: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a34, b35); - })(a032, a132); + putEq(rt.peekableNextIfEq(it, rights, (a033: Left.Left[], a133: Right.Right[]): boolean => { + return rt.eqSeq((a34: Left.Left, b36: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a34, b36); + })(a033, a133); }) !== undefined, log, out); - const _414: Right.Right[] = rt.sliceRange(exact, 0, half); - putEq(rt.peekableNextIfEq(it, _414, (a034: Left.Left[], a134: Right.Right[]): boolean => { - return rt.eqSeq((a35: Left.Left, b36: Right.Right): boolean => { - return !Left.ne$PartialEq_Right(a35, b36); - })(a034, a134); + const _426: Right.Right[] = rt.sliceRange(exact, 0, half); + putEq(rt.peekableNextIfEq(it, _426, (a035: Left.Left[], a135: Right.Right[]): boolean => { + return rt.eqSeq((a35: Left.Left, b37: Right.Right): boolean => { + return !Left.ne$PartialEq_Right(a35, b37); + })(a035, a135); }) !== undefined, log, out); rt.byteVecPush(out, rt.iterCount(it) & 0xff); const it2: rt.Peekable> = rt.iterPeekable(rt.iterSlice([rt.dequeClone(bytes, undefined), bytes])); - const _435: rt.ByteVec = rt.byteSliceToByteVec(data); - putEq(rt.peekableNextIfEq(it2, _435, (a036: rt.VecDeque, a136: rt.ByteVec): boolean => { - return rt.eqSeq(rt.same)(a036, a136); - }) !== undefined, log, out); - putEq(rt.peekableNextIfEq(it2, stepped, (a037: rt.VecDeque, a137: rt.ByteVec): boolean => { + const _447: rt.ByteVec = rt.byteSliceToByteVec(data); + putEq(rt.peekableNextIfEq(it2, _447, (a037: rt.VecDeque, a137: rt.ByteVec): boolean => { return rt.eqSeq(rt.same)(a037, a137); }) !== undefined, log, out); + putEq(rt.peekableNextIfEq(it2, stepped, (a038: rt.VecDeque, a138: rt.ByteVec): boolean => { + return rt.eqSeq(rt.same)(a038, a138); + }) !== undefined, log, out); rt.byteVecPush(out, rt.iterCount(it2) & 0xff); } diff --git a/ts/fixtures/lang/src/collections.rs b/ts/fixtures/lang/src/collections.rs index f67628bc7..5dfa50662 100644 --- a/ts/fixtures/lang/src/collections.rs +++ b/ts/fixtures/lang/src/collections.rs @@ -1214,6 +1214,16 @@ impl<'a> PartialEq<&Left<'a>> for Left<'_> { } } +/// An item only a reference to compares, by the crate's impl of two references, which +/// std's of references would otherwise forward from. +struct Odd(u16); + +impl PartialEq<&Right> for &Odd { + fn eq(&self, other: &&Right) -> bool { + self.0 % 2 == other.0 % 2 + } +} + /// The other way, by the remainder by 4, with `ne`'s default. impl<'a> PartialEq> for Right { fn eq(&self, other: &Left<'a>) -> bool { @@ -1296,6 +1306,8 @@ pub fn unlike_eqs(kind: u8, data: &[u8], out: &mut Vec) { put_eq(mine.iter().collect::>() == refs, &log, out); let others = lefts(); put_eq(mine == others.iter().collect::>(), &log, out); + let odds: Vec = data.iter().map(|&b| Odd(b.into())).collect(); + put_eq(odds.iter().collect::>() == refs, &log, out); // Wrapped around: the first half pushed to the front backwards, the rest to the back. let half = data.len() / 2; diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 02dd1fc1d..84984bf9b 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -1889,11 +1889,20 @@ fn item_eq<'tcx>(b: &mut Body<'_, '_, 'tcx>, seq: Ty<'tcx>, t: Ty<'tcx>, u: Ty<' } /// `t` and `u` through the references std's `PartialEq` of two references forwards -/// through, one of each at a time, while JS holds both as what they point at. +/// through, one of each at a time, while JS holds both as what they point at. A crate's +/// own impl of two references is where they stop. fn peel_pair<'tcx>(b: &Body<'_, '_, 'tcx>, t: Ty<'tcx>, u: Ty<'tcx>) -> (Ty<'tcx>, Ty<'tcx>) { + let tcx = b.t.tcx; + let forwards = || { + let eq = trait_fn(tcx, "PartialEq", "eq"); + Instance::try_resolve(tcx, b.t.typing_env_pub(), eq, tcx.mk_args(&[t.into(), u.into()])) + .ok() + .flatten() + .is_some_and(|instance| library::is_std(tcx, instance.def_id())) + }; match (t.kind(), u.kind()) { (ty::Ref(_, t_in, _), ty::Ref(_, u_in, _)) - if b.t.place_pointee(t).is_none() && b.t.place_pointee(u).is_none() => + if b.t.place_pointee(t).is_none() && b.t.place_pointee(u).is_none() && forwards() => { peel_pair(b, *t_in, *u_in) }