From 049bd4acca12df5c232f3281e2a02ffd26c58130 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:30:03 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m2/ts-model/mut-place.md Quest-Claim: 82ad6b0c23befcab From f04e01b39502da71004cd23068145387d625576d Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:09:42 -0700 Subject: [PATCH 2/5] feat(ts): translate a &mut to a value JS copies as an rt.Place Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/expected/collections.ts | 4 +- ts/fixtures/lang/expected/cows.ts | 4 +- ts/fixtures/lang/expected/harness.ts | 7 +- ts/fixtures/lang/expected/keys.ts | 88 +-- ts/fixtures/lang/expected/refs.Counts.ts | 18 + ts/fixtures/lang/expected/refs.Cursor.ts | 20 + ts/fixtures/lang/expected/refs.Fetch.ts | 7 + ts/fixtures/lang/expected/refs.Pair.ts | 9 + ts/fixtures/lang/expected/refs.ts | 271 ++++++++ ts/fixtures/lang/src/harness.rs | 7 +- ts/fixtures/lang/src/lib.rs | 3 +- ts/fixtures/lang/src/refs.rs | 237 +++++++ ts/fixtures/reject/census.md | 435 +++++++------ ts/fixtures/reject/expected.txt | 150 +++-- ts/fixtures/reject/src/lib.rs | 48 +- ts/fixtures/reject/ts.toml | 6 +- ts/fixtures/task/expected/drops.ts | 10 +- ts/fixtures/task/expected/model.ts | 765 +++++++++++++---------- ts/fixtures/task/src/model.rs | 19 +- ts/runtime/rt.ts | 34 + ts/runtime/rt/collections.ts | 10 +- ts/src/lower/collections.rs | 14 +- ts/src/lower/mir/call.rs | 209 ++++--- ts/src/lower/mir/mod.rs | 191 +++--- ts/src/lower/mir/place.rs | 176 +++++- ts/src/lower/mir/rvalue.rs | 26 +- ts/src/lower/mod.rs | 25 + 27 files changed, 1850 insertions(+), 943 deletions(-) create mode 100644 ts/fixtures/lang/expected/refs.Counts.ts create mode 100644 ts/fixtures/lang/expected/refs.Cursor.ts create mode 100644 ts/fixtures/lang/expected/refs.Fetch.ts create mode 100644 ts/fixtures/lang/expected/refs.Pair.ts create mode 100644 ts/fixtures/lang/expected/refs.ts create mode 100644 ts/fixtures/lang/src/refs.rs diff --git a/ts/fixtures/lang/expected/collections.ts b/ts/fixtures/lang/expected/collections.ts index 0ab82426d..84aa756bf 100644 --- a/ts/fixtures/lang/expected/collections.ts +++ b/ts/fixtures/lang/expected/collections.ts @@ -1098,8 +1098,8 @@ export function stores(data: rt.ByteSlice, out: rt.ByteVec): void { if (_88 !== undefined) { _88.v[0] = _88.v[0] ^ 1; } - const place = rt.entryOrInsertMut(rt.entry(hash, 2), copy$u8_u8(pair)); - place.v[1] = place.v[1] ^ 2; + const _93: rt.Place<[rt.u8, rt.u8]> = rt.entryOrInsertMut(rt.entry(hash, 2), copy$u8_u8(pair)); + _93.v[1] = _93.v[1] ^ 2; rt.iterExtendBytes(out, rt.iterFlatMap(new rt.Range(0, 3), (k: rt.u8): Uint8Array => { return rt.optionMapOr(rt.hashGet(hash, k), rt.bytes(2).fill(255), (p2: [rt.u8, rt.u8]): Uint8Array => { return Uint8Array.of(p2[0], p2[1]); diff --git a/ts/fixtures/lang/expected/cows.ts b/ts/fixtures/lang/expected/cows.ts index e2b791c0c..d6ee3ba05 100644 --- a/ts/fixtures/lang/expected/cows.ts +++ b/ts/fixtures/lang/expected/cows.ts @@ -118,8 +118,8 @@ export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { break; } const _279: string = cow(_271[1], rt.usizeRem(_271[0], 2) === 1 === owned); - const place = rt.entryOrInsertMut(rt.entry(counts, _279), 0); - place.v = rt.u8Add(place.v, 1); + const _276: rt.Place = rt.entryOrInsertMut(rt.entry(counts, _279), 0); + _276.v = rt.u8Add(_276.v, 1); } const iter4: rt.Iter<[string, rt.u8]> = rt.btreeIter(counts); while (true) { diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 20cb1d2cb..6b30f0eed 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -10,6 +10,7 @@ import { methods } from "./generics.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts"; import { adaptors, consumers, ranges, options, own, values } from "./iters.ts"; import { keys } from "./keys.ts"; +import { refs } from "./refs.ts"; import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { strs, slices } from "./strs.ts"; @@ -22,7 +23,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec { const _10: [rt.u8, rt.u8] = [input.data[input.start], input.data[input.start + 1]]; const op: rt.u8 = _10[0]; const kind: rt.u8 = _10[1]; - const _14: rt.u8 = rt.u8Rem(op, 47); + const _14: rt.u8 = rt.u8Rem(op, 48); if (_14 === 0) { u8Op(kind, rt.byteSliceRange(input, 2), out); } else if (_14 === 1) { @@ -133,8 +134,10 @@ export function run(input: rt.ByteSlice): rt.ByteVec { stores(rt.byteSliceRange(input, 2), out); } else if (_14 === 45) { chunks(kind, rt.byteSliceRange(input, 2), out); - } else { + } else if (_14 === 46) { cows(kind, rt.byteSliceRange(input, 2), out); + } else { + refs(rt.byteSliceRange(input, 2), out); } return out; } diff --git a/ts/fixtures/lang/expected/keys.ts b/ts/fixtures/lang/expected/keys.ts index 8d24c88c3..b84be823e 100644 --- a/ts/fixtures/lang/expected/keys.ts +++ b/ts/fixtures/lang/expected/keys.ts @@ -780,10 +780,10 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { const k: rt.u8 = rt.u8Rem(b, 97); const _18: rt.u8 = rt.u8Rem(b, 6); if (_18 === 0) { - const place8 = rt.entryOrInsertWithMut(rt.entry(counts, k), (): rt.usize => { + const _20: rt.Place = rt.entryOrInsertWithMut(rt.entry(counts, k), (): rt.usize => { return 0; }); - place8.v = rt.usizeAdd(place8.v, 1); + _20.v = rt.usizeAdd(_20.v, 1); } else if (_18 === 1) { const _24: rt.Place | undefined = rt.btreeGetMut(counts, k); if (_24 !== undefined) { @@ -795,40 +795,40 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { } else if (_18 === 2) { const _35: rt.Entry = rt.entry(counts, k); if (!rt.entryOccupied(_35)) { - const place7 = rt.entryOrInsertMut(_35, i); - place7.v = rt.usizeAdd(place7.v, 2); + const _50: rt.Place = rt.entryOrInsertMut(_35, i); + _50.v = rt.usizeAdd(_50.v, 2); } else if (!(rt.entryGet(_35) > 1)) { - const place6 = rt.entryGetMut(_35); - place6.v = rt.usizeAdd(place6.v, 7); + const _47: rt.Place = rt.entryGetMut(_35); + _47.v = rt.usizeAdd(_47.v, 7); } else { - const place5 = rt.entryGetMut(_35); - place5.v = rt.usizeMul(place5.v, 3); + const _43: rt.Place = rt.entryGetMut(_35); + _43.v = rt.usizeMul(_43.v, 3); } } else if (_18 === 3) { - const place4 = rt.entryOrInsertWithMut(rt.entry(counts, k), (): rt.usize => { + const c: rt.Place = rt.entryOrInsertWithMut(rt.entry(counts, k), (): rt.usize => { return rt.usizeMul(i, 2); }); - place4.v = (place4.v ^ 5) >>> 0; - rt.byteVecPush(out, place4.v & 0xff); + c.v = (c.v ^ 5) >>> 0; + rt.byteVecPush(out, c.v & 0xff); } else if (_18 === 4) { if (!rt.btreeContains(counts, k)) { - const place3 = rt.entryOrInsertMut(rt.entry(counts, k), 9); - place3.v = (place3.v << 1) >>> 0; + const _69: rt.Place = rt.entryOrInsertMut(rt.entry(counts, k), 9); + _69.v = (_69.v << 1) >>> 0; } else { - const place2 = rt.optionExpect(rt.btreeGetMut(counts, k), "a counted key"); - place2.v = rt.usizeAdd(place2.v, 4); + const _63: rt.Place = rt.optionExpect(rt.btreeGetMut(counts, k), "a counted key"); + _63.v = rt.usizeAdd(_63.v, 4); } } else { - const place = rt.optionUnwrap(rt.btreeGetMut(counts, k)); - place.v = rt.usizeAdd(place.v, 1); + const _74: rt.Place = rt.optionUnwrap(rt.btreeGetMut(counts, k)); + _74.v = rt.usizeAdd(_74.v, 1); } - const place9 = rt.entryOrInsertMut(rt.entry(wide, rt.u8Rem(b, 7)), 4503599627370496); - place9.v = rt.u64WrappingAdd(rt.u64WrappingAdd(place9.v, rt.u64Shr(place9.v, 1)), b as rt.u64); + const w: rt.Place = rt.entryOrInsertMut(rt.entry(wide, rt.u8Rem(b, 7)), 4503599627370496); + w.v = rt.u64WrappingAdd(rt.u64WrappingAdd(w.v, rt.u64Shr(w.v, 1)), b as rt.u64); const _98: Hop.Hop = { _0: rt.u64Rem(b as rt.u64, 6) }; - const place10 = rt.entryOrInsertWithMut(rt.entry(hops, _98), (): rt.u16 => { + const h: rt.Place = rt.entryOrInsertWithMut(rt.entry(hops, _98), (): rt.u16 => { return 0; }); - place10.v = rt.u16WrappingAdd(place10.v, b as rt.u16); + h.v = rt.u16WrappingAdd(h.v, b as rt.u16); const _108: Hop.Hop = { _0: rt.u64Rem(b as rt.u64, 4) }; const _105: rt.Place | undefined = rt.hashGetMut(hops, _108); if (_105 !== undefined) { @@ -838,21 +838,21 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { const _114: rt.Entry = rt.entry(hops, _116); if (rt.entryOccupied(_114)) { if (!(rt.entryGet(_114) > 4096)) { - const place13 = rt.entryGetMut(_114); - place13.v = place13.v | 1; + const _130: rt.Place = rt.entryGetMut(_114); + _130.v = _130.v | 1; } else { - const place12 = rt.entryGetMut(_114); - place12.v = rt.u16Sub(place12.v, 4096); + const _126: rt.Place = rt.entryGetMut(_114); + _126.v = rt.u16Sub(_126.v, 4096); } } else { - const place11 = rt.entryOrInsertMut(_114, b as rt.u16); - place11.v = (place11.v << 4) & 0xffff; + const _132: rt.Place = rt.entryOrInsertMut(_114, b as rt.u16); + _132.v = (_132.v << 4) & 0xffff; } const _139: Hop.Hop = { _0: rt.u64Rem(b as rt.u64, 3) }; - const place14 = rt.entryOrInsertMut(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); - const _144: rt.u8 = rt.u8WrappingAdd(place14.v[0], b); - place14.v[0] = _144; - place14.v[1] = place14.v[1] ^ place14.v[0]; + const p: rt.Place<[rt.u8, rt.u8]> = rt.entryOrInsertMut(rt.entry(pairs, _139), [0, 0] as [rt.u8, rt.u8]); + const _144: rt.u8 = rt.u8WrappingAdd(p.v[0], b); + p.v[0] = _144; + p.v[1] = p.v[1] ^ p.v[0]; } const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; const _150: rt.usize = rt.usizeMul(data.length, 4); @@ -863,8 +863,8 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { const _159: rt.usize = rt.usizeRem(j, data.length); rt.idx(data, _159); const b2: rt.u8 = data.data[data.start + _159]; - const place15 = rt.entryOrInsertMut(rt.entry(tree, rt.u16Mul(j & 0xffff, 37) ^ b2 as rt.u16), j & 0xffff); - place15.v = rt.u16WrappingAdd(place15.v, b2 as rt.u16); + const v: rt.Place = rt.entryOrInsertMut(rt.entry(tree, rt.u16Mul(j & 0xffff, 37) ^ b2 as rt.u16), j & 0xffff); + v.v = rt.u16WrappingAdd(v.v, b2 as rt.u16); } const iter3: rt.Iter<[rt.u16, rt.u16]> = rt.btreeIter(tree); while (true) { @@ -876,31 +876,31 @@ export function places(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(_179[1]))); } const touchy: rt.BTreeMap = rt.btreeNew(Touchy.cmp$Ord) as rt.BTreeMap; - const place16 = rt.entryOrInsertWithMut(rt.entry(touchy, { _0: data.length & 0xff }), (): rt.u8 => { + const _195: rt.Place = rt.entryOrInsertWithMut(rt.entry(touchy, { _0: data.length & 0xff }), (): rt.u8 => { return 7; }); - place16.v = rt.u8Add(place16.v, 1); + _195.v = rt.u8Add(_195.v, 1); const hashy: rt.HashMap = rt.hashNew(rt.hashing(Touchy.hash$Hash_DefaultHasher, Touchy.eq$PartialEq)) as rt.HashMap; - const place17 = rt.entryOrInsertWithMut(rt.entry(hashy, { _0: data.length & 0xff }), (): rt.u8 => { + const _203: rt.Place = rt.entryOrInsertWithMut(rt.entry(hashy, { _0: data.length & 0xff }), (): rt.u8 => { return 0; }); - place17.v = rt.u8Add(place17.v, 2); + _203.v = rt.u8Add(_203.v, 2); rt.iterExtendBytes(out, rt.iterChain(rt.btreeValues(touchy), rt.hashValues(hashy))); - const place18 = rt.entryOrInsertWithMut(rt.entry(counts, 0), (): rt.usize => { + const c2: rt.Place = rt.entryOrInsertWithMut(rt.entry(counts, 0), (): rt.usize => { return 0; }); ((): void => { - place18.v = rt.usizeAdd(place18.v, 1); + c2.v = rt.usizeAdd(c2.v, 1); })(); const spare: rt.usize[] = [data.length, 8]; - const place19 = rt.entryOrInsertMut(rt.entry(counts, 1), 3); - const swapped = place19.v; - place19.v = spare[0]; + const c3: rt.Place = rt.entryOrInsertMut(rt.entry(counts, 1), 3); + const swapped = c3.v; + c3.v = spare[0]; spare[0] = swapped; - const place20 = rt.entryOrInsertWithMut(rt.entry(counts, 2), (): rt.usize => { + const d: rt.Place = rt.entryOrInsertWithMut(rt.entry(counts, 2), (): rt.usize => { return 0; }); - place20.v = rt.usizeAdd(place20.v, spare[0]); + d.v = rt.usizeAdd(d.v, spare[0]); const iter4: rt.Iter<[rt.u8, rt.usize]> = rt.btreeIter(counts); while (true) { const _241: [rt.u8, rt.usize] | rt.Done = iter4.next(); diff --git a/ts/fixtures/lang/expected/refs.Counts.ts b/ts/fixtures/lang/expected/refs.Counts.ts new file mode 100644 index 000000000..ac3e8ae5a --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Counts.ts @@ -0,0 +1,18 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export interface Counts { + hits: rt.usize; + misses: rt.usize; +} + +/** A `&mut` returned to one of two fields, as moq-net's `count` returns one. */ +export function count(self: Counts, hit: boolean): rt.Place { + if (!hit) { + return rt.place(() => self.misses, (value2) => self.misses = value2); + } + return rt.place(() => self.hits, (value) => self.hits = value); +} + +//# sourceMappingURL=refs.Counts.ts.map diff --git a/ts/fixtures/lang/expected/refs.Cursor.ts b/ts/fixtures/lang/expected/refs.Cursor.ts new file mode 100644 index 000000000..557a528a7 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Cursor.ts @@ -0,0 +1,20 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** A struct that keeps a `&mut` to its position. */ +export interface Cursor { + at: rt.Place; + data: rt.ByteSlice; +} + +export function next(self: Cursor): rt.u8 | undefined { + const _3: rt.u8 | undefined = rt.byteSliceGet(self.data, self.at.v); + if (_3 !== undefined) { + self.at.v = rt.usizeAdd(self.at.v, 1); + return _3; + } + return undefined; +} + +//# sourceMappingURL=refs.Cursor.ts.map diff --git a/ts/fixtures/lang/expected/refs.Fetch.ts b/ts/fixtures/lang/expected/refs.Fetch.ts new file mode 100644 index 000000000..7f6ff2c99 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Fetch.ts @@ -0,0 +1,7 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export type Fetch = { tag: "Idle" } | { tag: "Pending"; _0: rt.u8 } | { tag: "Refused" }; + +//# sourceMappingURL=refs.Fetch.ts.map diff --git a/ts/fixtures/lang/expected/refs.Pair.ts b/ts/fixtures/lang/expected/refs.Pair.ts new file mode 100644 index 000000000..4a283ac52 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Pair.ts @@ -0,0 +1,9 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export interface Pair { + n: rt.u8; +} + +//# sourceMappingURL=refs.Pair.ts.map diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts new file mode 100644 index 000000000..e58f64bc0 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.ts @@ -0,0 +1,271 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import * as Counts from "./refs.Counts.ts"; +import * as Cursor from "./refs.Cursor.ts"; +import type * as Fetch from "./refs.Fetch.ts"; +import type * as Pair from "./refs.Pair.ts"; + +export function bump(x: rt.Place, by: rt.u8): void { + x.v = rt.u32Add(x.v, by as rt.u32); +} + +/** A parameter passed on twice, and once from a closure that captures it. */ +export function bumpThrice(x: rt.Place, by: rt.u8): void { + bump(x, by); + bump(x, 1); + ((n: rt.u8): void => { + bump(x, n); + })(by); +} + +/** Over 2^53, where the runtime switches a `u64` to limbs. */ +export function shiftWide(x: rt.Place, by: rt.u8): void { + x.v = rt.u64WrappingAdd(rt.u64WrappingAdd(x.v, { hi: 0x200000, lo: 0 } as rt.u64), by as rt.u64); +} + +/** moq-net's cache shape: the largest seen so far, read, replaced, and taken. */ +export function takeLargest(seen: rt.Place, next: rt.u8): rt.u8 | undefined { + if (!rt.optionMapOr(seen.v, true, (s: rt.u8): boolean => { + return next > s; + })) { + if (seen.v !== undefined) { + seen.v = rt.u8WrappingAdd(seen.v, 1); + } + if (!(next === 0)) { + return undefined; + } + const taken = seen.v; + seen.v = undefined; + return taken; + } + const old = seen.v; + seen.v = next; + return old; +} + +/** A `&mut Option` passed on from inside a closure std calls. */ +export function largestOf(seen: rt.Place, items: rt.ByteSlice): rt.u8 { + let taken: rt.u8 = 0; + rt.iterForEach(rt.iterSlice(rt.byteSliceView(items)), (_2: rt.u8): void => { + if (takeLargest(seen, _2) !== undefined) { + taken = rt.u8WrappingAdd(taken, 1); + } + }); + return taken; +} + +/** moq-net's `&mut Box`: changed through, and replaced whole. */ +export function rebox(b: rt.Place, by: rt.u8): void { + const _3: rt.u8 = rt.u8WrappingAdd(b.v.n, by); + b.v.n = _3; + if (rt.u8Rem(by, 2) === 0) { + const _8: Pair.Pair = { n: rt.u8WrappingAdd(b.v.n, b.v.n) }; + b.v = _8; + } +} + +export function swapPair(p: rt.Place<[rt.u8, rt.u8]>): void { + const swapped = p.v[0]; + p.v[0] = p.v[1]; + p.v[1] = swapped; + const _5: rt.u8 = rt.u8WrappingAdd(p.v[1], 1); + p.v[1] = _5; +} + +export function refuse(f: rt.Place): void { + let _2!: Fetch.Fetch; + if (f.v.tag === "Idle") { + _2 = { tag: "Pending", _0: 1 } as Fetch.Fetch; + } else if (f.v.tag === "Pending") { + if (!(f.v._0 > 2)) { + _2 = { tag: "Pending", _0: rt.u8Add(f.v._0, 1) } as Fetch.Fetch; + } else { + _2 = { tag: "Refused" } as Fetch.Fetch; + } + } else { + _2 = { tag: "Idle" } as Fetch.Fetch; + } + f.v = _2; +} + +export function pushTo(s: rt.Place, c: rt.char): void { + s.v = s.v + String.fromCodePoint(c); + if (c === 122) { + const taken = s.v; + s.v = ""; + const iter: rt.Iter = rt.iterTake(rt.strChars(taken), 2); + while (true) { + const _12: rt.char | rt.Done = iter.next(); + if (_12 === rt.DONE) { + break; + } + s.v = s.v + String.fromCodePoint(_12); + } + } +} + +export function skip(remaining: rt.Place, data: rt.ByteSlice): rt.usize { + let skipped: rt.usize = 0; + const iterS: Uint8Array = rt.byteSliceView(data); + let iterI: number = 0; + while (true) { + const _6: rt.u8 | rt.Done = iterI < iterS.length ? iterS[iterI++] : rt.DONE; + if (_6 === rt.DONE) { + return skipped; + } + const b: rt.u8 = _6; + if (!(remaining.v === 0)) { + remaining.v = rt.usizeSub(remaining.v, 1); + skipped = rt.usizeAdd(skipped, rt.u8Rem(b, 2) as rt.usize); + } else { + return skipped; + } + } +} + +export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { + let _133!: rt.u8; + const _228: (a0: rt.Place, a1: rt.u8) => void = (x2: rt.Place, b7: rt.u8): void => { + bump(x2, b7); + }; + const by: rt.u8 = rt.optionUnwrapOr(rt.byteSliceFirst(data), 3); + let local: rt.u32 = 7; + bumpThrice(rt.place(() => local, (value) => local = value), by); + const counts: Counts.Counts = { hits: 0, misses: 0 }; + const held: rt.u32[] = [1, 2, 3]; + const v: rt.u32[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_2: rt.u8): rt.u32 => { + return _2 as rt.u32; + })); + const iter: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))); + while (true) { + const _18: [rt.usize, rt.u8] | rt.Done = iter.next(); + if (_18 === rt.DONE) { + break; + } + const i: rt.usize = _18[0]; + const b: rt.u8 = _18[1]; + const _23: rt.Place = Counts.count(counts, rt.u8Rem(b, 3) === 0); + _23.v = rt.usizeAdd(_23.v, 1); + bumpSlot(Counts.count(counts, rt.u8Rem(b, 2) === 0), b); + const _37: rt.usize = rt.usizeRem(i, 3); + if (!(_37 < 3)) { + rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _37); + } + bump(rt.place(() => held[_37], (value2) => held[_37] = value2), b); + const at2 = rt.idx(v, i); + bump(rt.place(() => v[at2], (value3) => v[at2] = value3), 1); + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(local))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(counts.hits as rt.u32))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(counts.misses as rt.u32))); + const iter2: rt.Iter = rt.iterChain(rt.iterSlice(held), rt.iterSlice(v)); + while (true) { + const _67: rt.u32 | rt.Done = iter2.next(); + if (_67 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(_67))); + } + let wide: rt.u64 = { hi: 0xffffffff, lo: 0xfffffffc } as rt.u64; + shiftWide(rt.place(() => wide, (value4) => wide = value4), by); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(wide))); + let seen: rt.u8 | undefined = undefined; + rt.byteVecPush(out, largestOf(rt.place(() => seen, (value5) => seen = value5), data)); + rt.byteVecPush(out, rt.optionUnwrapOr(seen, 238)); + let slot: rt.u8 | undefined = by; + if (slot !== undefined) { + bumpByte(rt.place(() => slot as rt.u8, (value6) => slot = value6)); + } + rt.byteVecPush(out, rt.optionUnwrapOr(slot, 238)); + let boxed: Pair.Pair = { n: by }; + let pair: [rt.u8, rt.u8] = [by, rt.u8WrappingAdd(by, 1)]; + let fetch = { tag: "Idle" } as Fetch.Fetch; + let text: string = ""; + for (const b2 of rt.byteSliceView(data)) { + rebox(rt.place(() => boxed, (value7) => boxed = value7), b2); + swapPair(rt.place(() => pair, (value8) => pair = value8)); + refuse(rt.place(() => fetch, (value9) => fetch = value9)); + const _120: rt.char = rt.u8Add(97, rt.u8Rem(b2, 26)) as rt.char; + pushTo(rt.place(() => text, (value10) => text = value10), _120); + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(boxed.n, pair[0], pair[1]))); + if (fetch.tag === "Idle") { + _133 = 0; + } else if (fetch.tag === "Pending") { + _133 = fetch._0; + } else { + _133 = 255; + } + rt.byteVecPush(out, _133); + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(text)); + let at: rt.usize = 0; + const cursor: Cursor.Cursor = { at: rt.place(() => at, (value11) => at = value11), data }; + let sum: rt.u8 = 0; + while (true) { + const _143: rt.u8 | undefined = Cursor.next(cursor); + if (_143 !== undefined) { + const b3: rt.u8 = _143; + sum = rt.u8WrappingAdd(sum, b3); + if (b3 > 200) { + break; + } + } else { + break; + } + } + rt.byteVecPush(out, sum); + rt.byteVecPush(out, at & 0xff); + let remaining: rt.usize = rt.u8Rem(by, 5) as rt.usize; + rt.byteVecPush(out, skip(rt.place(() => remaining, (value12) => remaining = value12), data) & 0xff); + rt.byteVecPush(out, remaining & 0xff); + const _167: [Pair.Pair, Pair.Pair] = [{ n: 1 }, { n: 2 }]; + const a: Pair.Pair = _167[0]; + const b4: Pair.Pair = _167[1]; + let p: Pair.Pair = a; + const borrowed = p; + const r: rt.Place = rt.place(() => borrowed.n, (value13) => borrowed.n = value13); + p = b4; + bumpByte(r); + p.n = rt.u8Add(p.n, 10); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.n, b4.n))); + const hash: rt.HashMap = rt.hashNew() as rt.HashMap; + const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; + for (const b5 of rt.byteSliceView(data)) { + bump(rt.entryOrInsertMut(rt.entry(hash, rt.u8Rem(b5, 4)), 0), b5); + bump(rt.entryOrInsertWithMut(rt.entry(tree, rt.u8Rem(b5, 3)), (): rt.u32 => { + return 0; + }), 1); + const _201: rt.Place | undefined = rt.hashGetMut(hash, rt.u8Rem(b5, 2)); + if (_201 !== undefined) { + bump(_201, 2); + } + } + const _210: rt.Iter<[rt.u8, rt.u32]> = rt.hashIter(hash); + const iter5: rt.Iter<[rt.u8, rt.u32]> = rt.iterChain(rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmp) as rt.BTreeMap, _210, true)), rt.btreeIter(tree)); + while (true) { + const _217: [rt.u8, rt.u32] | rt.Done = iter5.next(); + if (_217 === rt.DONE) { + break; + } + const k: rt.u8 = _217[0]; + const x: rt.u32 = _217[1]; + rt.byteVecPush(out, k); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x))); + } + let total: rt.u32 = 0; + for (const b6 of rt.byteSliceView(data)) { + _228(rt.place(() => total, (value14) => total = value14), b6); + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(total))); +} + +export function bumpSlot(c: rt.Place, b: rt.u8): void { + c.v = rt.usizeAdd(c.v, rt.u8Rem(b, 4) as rt.usize); +} + +export function bumpByte(x: rt.Place): void { + x.v = rt.u8WrappingAdd(x.v, 1); +} + +//# sourceMappingURL=refs.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 7ed64b1e9..d40296f60 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -1,7 +1,7 @@ //! The entry point both sides of the differential test run. The first byte picks a //! case and the rest is its input. -use crate::{chars, chunks, collections, cows, fmt, generics, ints, iters, keys, shapes, strs}; +use crate::{chars, chunks, collections, cows, fmt, generics, ints, iters, keys, refs, shapes, strs}; /// The native side's entry: [`run`], except that a case starting with 0xff prints a /// [`fmt::Fault`], which the translated side prints from TypeScript in `caller.ts`. @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 47 { + match op % 48 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -76,7 +76,8 @@ pub fn run(input: &[u8]) -> Vec { 43 => strs::slices(kind, data, &mut out), 44 => collections::stores(data, &mut out), 45 => chunks::chunks(kind, data, &mut out), - _ => cows::cows(kind, data, &mut out), + 46 => cows::cows(kind, data, &mut out), + _ => refs::refs(data, &mut out), } out } diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index aaf82f5f3..86f0840d6 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -1,7 +1,7 @@ //! The language the driver translates, exercised against native Rust: every integer //! width's arithmetic and casts, `char`s and the `str` methods over them, `Cow`, //! control flow, patterns, `Copy` aggregates, closures, traits, generic types, formatting, -//! collections, and the standard library calls it maps. +//! collections, `&mut` to values JS copies, and the standard library calls it maps. //! //! `harness::run` is the entry point both sides of the differential test run, and //! `fmt::Fault` an error only `caller.ts` prints. @@ -16,6 +16,7 @@ pub mod harness; mod ints; mod iters; mod keys; +mod refs; mod shapes; mod strs; #[cfg(target_arch = "wasm32")] diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs new file mode 100644 index 000000000..2c57ce668 --- /dev/null +++ b/ts/fixtures/lang/src/refs.rs @@ -0,0 +1,237 @@ +//! `&mut` to values JS copies, a number, an `Option`, a `Box`, a tuple, an enum, or a +//! `String`, passed on, returned, kept in a struct, and captured: each borrows a local, a +//! field, an element, or a map's value, and what is written through it must land there. + +use std::collections::{BTreeMap, HashMap}; + +fn bump(x: &mut u32, by: u8) { + *x += u32::from(by); +} + +/// A parameter passed on twice, and once from a closure that captures it. +fn bump_thrice(x: &mut u32, by: u8) { + bump(x, by); + bump(&mut *x, 1); + let mut again = |n: u8| bump(x, n); + again(by); +} + +/// Over 2^53, where the runtime switches a `u64` to limbs. +fn shift_wide(x: &mut u64, by: u8) { + *x = x.wrapping_add(1 << 53).wrapping_add(u64::from(by)); +} + +/// moq-net's cache shape: the largest seen so far, read, replaced, and taken. +fn take_largest(seen: &mut Option, next: u8) -> Option { + if seen.map_or(true, |s| next > s) { + return std::mem::replace(seen, Some(next)); + } + if let Some(s) = seen { + *s = s.wrapping_add(1); + } + if next == 0 { seen.take() } else { None } +} + +/// A `&mut Option` passed on from inside a closure std calls. +fn largest_of(seen: &mut Option, items: &[u8]) -> u8 { + let mut taken = 0u8; + items.iter().for_each(|&b| { + if take_largest(seen, b).is_some() { + taken = taken.wrapping_add(1); + } + }); + taken +} + +/// moq-net's `&mut Box`: changed through, and replaced whole. +fn rebox(b: &mut Box, by: u8) { + b.n = b.n.wrapping_add(by); + if by % 2 == 0 { + *b = Box::new(Pair { + n: b.n.wrapping_add(b.n), + }); + } +} + +fn swap_pair(p: &mut (u8, u8)) { + std::mem::swap(&mut p.0, &mut p.1); + p.1 = p.1.wrapping_add(1); +} + +#[derive(Clone, Copy, Debug, PartialEq)] +enum Fetch { + Idle, + Pending(u8), + Refused, +} + +fn refuse(f: &mut Fetch) { + *f = match *f { + Fetch::Idle => Fetch::Pending(1), + Fetch::Pending(n) if n > 2 => Fetch::Refused, + Fetch::Pending(n) => Fetch::Pending(n + 1), + Fetch::Refused => Fetch::Idle, + }; +} + +fn push_to(s: &mut String, c: char) { + s.push(c); + if c == 'z' { + let old = std::mem::take(s); + for c in old.chars().take(2) { + s.push(c); + } + } +} + +struct Counts { + hits: usize, + misses: usize, +} + +impl Counts { + /// A `&mut` returned to one of two fields, as moq-net's `count` returns one. + fn count(&mut self, hit: bool) -> &mut usize { + match hit { + true => &mut self.hits, + false => &mut self.misses, + } + } +} + +/// A struct that keeps a `&mut` to its position. +struct Cursor<'a> { + at: &'a mut usize, + data: &'a [u8], +} + +impl Cursor<'_> { + fn next(&mut self) -> Option { + let b = *self.data.get(*self.at)?; + *self.at += 1; + Some(b) + } +} + +fn skip(remaining: &mut usize, data: &[u8]) -> usize { + let mut skipped = 0; + for &b in data { + if *remaining == 0 { + break; + } + *remaining -= 1; + skipped += usize::from(b % 2); + } + skipped +} + +struct Pair { + n: u8, +} + +pub fn refs(data: &[u8], out: &mut Vec) { + let by = data.first().copied().unwrap_or(3); + // A local, a field, and elements of an array and a `Vec`. + let mut local = 7u32; + bump_thrice(&mut local, by); + let mut counts = Counts { hits: 0, misses: 0 }; + let mut held = [1u32, 2, 3]; + let mut v: Vec = data.iter().map(|&b| u32::from(b)).collect(); + for (i, &b) in data.iter().enumerate() { + *counts.count(b % 3 == 0) += 1; + let c = counts.count(b % 2 == 0); + bump_slot(c, b); + bump(&mut held[i % 3], b); + bump(&mut v[i], 1); + } + out.extend_from_slice(&local.to_be_bytes()); + out.extend_from_slice(&(counts.hits as u32).to_be_bytes()); + out.extend_from_slice(&(counts.misses as u32).to_be_bytes()); + for x in held.iter().chain(&v) { + out.extend_from_slice(&x.to_be_bytes()); + } + // Wide integers, in a local and a field. + let mut wide = u64::MAX - 3; + shift_wide(&mut wide, by); + out.extend_from_slice(&wide.to_be_bytes()); + // `Option`s, in a local and through a field's payload. + let mut seen = None; + out.push(largest_of(&mut seen, data)); + out.push(seen.unwrap_or(0xee)); + let mut slot = Some(by); + if let Some(s) = &mut slot { + bump_byte(s); + } + out.push(slot.unwrap_or(0xee)); + // A box, a tuple, an enum, and a string. + let mut boxed = Box::new(Pair { n: by }); + let mut pair = (by, by.wrapping_add(1)); + let mut fetch = Fetch::Idle; + let mut text = String::new(); + for &b in data { + rebox(&mut boxed, b); + swap_pair(&mut pair); + refuse(&mut fetch); + push_to(&mut text, char::from(b'a' + b % 26)); + } + out.extend_from_slice(&[boxed.n, pair.0, pair.1]); + out.push(match fetch { + Fetch::Idle => 0, + Fetch::Pending(n) => n, + Fetch::Refused => 0xff, + }); + out.extend_from_slice(text.as_bytes()); + // A struct keeping a `&mut`, and one passed on in a loop. + let mut at = 0; + let mut cursor = Cursor { at: &mut at, data }; + let mut sum = 0u8; + while let Some(b) = cursor.next() { + sum = sum.wrapping_add(b); + if b > 200 { + break; + } + } + out.push(sum); + out.push(at as u8); + let mut remaining = usize::from(by % 5); + out.push(skip(&mut remaining, data) as u8); + out.push(remaining as u8); + // A borrow through a reference reassigned while the borrow lives. + let (mut a, mut b) = (Pair { n: 1 }, Pair { n: 2 }); + let mut p = &mut a; + let r = &mut p.n; + p = &mut b; + bump_byte(r); + p.n += 10; + out.extend_from_slice(&[a.n, b.n]); + // A map's values, passed on. + let mut hash: HashMap = HashMap::new(); + let mut tree: BTreeMap = BTreeMap::new(); + for &b in data { + bump(hash.entry(b % 4).or_insert(0), b); + bump(tree.entry(b % 3).or_default(), 1); + if let Some(x) = hash.get_mut(&(b % 2)) { + bump(x, 2); + } + } + let sorted: BTreeMap = hash.into_iter().collect(); + for (k, x) in sorted.into_iter().chain(tree) { + out.push(k); + out.extend_from_slice(&x.to_be_bytes()); + } + // A closure that takes a `&mut`. + let mut total = 0u32; + let add = |x: &mut u32, b: u8| bump(x, b); + for &b in data { + add(&mut total, b); + } + out.extend_from_slice(&total.to_be_bytes()); +} + +fn bump_slot(c: &mut usize, b: u8) { + *c += usize::from(b % 4); +} + +fn bump_byte(x: &mut u8) { + *x = x.wrapping_add(1); +} diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 729903712..1c8f73c73 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,56 +1,56 @@ # Census of `reject-fixture` -- Refusals: 86 -- Function instances: 67 +- Refusals: 80 +- Function instances: 68 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 8 | unsupported call to `_` | fixtures/reject/src/lib.rs:33:4 | -| 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:17:2 | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:28:15 | -| 6 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:16:13 | -| 5 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:56:2 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:405:2 | -| 4 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:108:2 | +| 8 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:23:15 | +| 5 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:51:2 | +| 4 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:17:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:385:2 | +| 4 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:109:2 | | 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:128:20 | -| 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:280:16 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:296:7 | -| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:187:1 | -| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:173:23 | -| 2 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:51:1 | -| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:167:2 | -| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:85:3 | -| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:87:3 | -| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:86:3 | -| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:90:3 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:301:6 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:416:18 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:324:6 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:356:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:366:6 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:332:9 | -| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:119:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:200:51 | -| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:379:2 | -| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:103:2 | -| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:290:14 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:259:13 | -| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:82:3 | -| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:115:1 | +| 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:93:2 | +| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:113:20 | +| 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:265:16 | +| 2 | a field of `_` | fixtures/reject/src/lib.rs:281:7 | +| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:172:1 | +| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:158:23 | +| 2 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:46:1 | +| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:152:2 | +| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:70:3 | +| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:72:3 | +| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:71:3 | +| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:75:3 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:286:6 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:396:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:309:6 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:341:2 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:317:9 | +| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:104:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:185:51 | +| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:364:2 | +| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:88:2 | +| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:275:14 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:244:13 | +| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:428:12 | +| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:67:3 | +| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:100:1 | | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | -| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:89:3 | -| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:75:2 | +| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:74:3 | +| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:60:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:306:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:423:53 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:306:52 | -| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:88:3 | -| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:83:3 | -| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:84:3 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:291:52 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:403:53 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:291:52 | +| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:73:3 | +| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:68:3 | +| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:69:3 | ## By API @@ -58,177 +58,162 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:405:2 | -| 6 | `Option` | fixtures/reject/src/lib.rs:28:15 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:385:2 | +| 6 | `Option` | fixtures/reject/src/lib.rs:23:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | -| 6 | `u8` | fixtures/reject/src/lib.rs:65:10 | -| 4 | `std::string::String` | fixtures/reject/src/lib.rs:95:16 | -| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | -| 4 | `u32` | fixtures/reject/src/lib.rs:16:13 | -| 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:124:2 | -| 2 | `Iterator` | fixtures/reject/src/lib.rs:167:2 | -| 2 | `Meters` | fixtures/reject/src/lib.rs:108:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:128:20 | -| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:301:6 | -| 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:280:16 | -| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:301:6 | -| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | -| 2 | `std::slice` | fixtures/reject/src/lib.rs:33:4 | -| 2 | `{closure}` | fixtures/reject/src/lib.rs:398:15 | -| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | -| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | -| 1 | `HashMap` | fixtures/reject/src/lib.rs:324:6 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:332:9 | -| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:119:2 | -| 1 | `Noisy` | fixtures/reject/src/lib.rs:254:20 | -| 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:273:22 | +| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:51:2 | +| 3 | `std::slice` | fixtures/reject/src/lib.rs:28:4 | +| 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:109:2 | +| 2 | `Iterator` | fixtures/reject/src/lib.rs:152:2 | +| 2 | `Meters` | fixtures/reject/src/lib.rs:93:2 | +| 2 | `Poll` | fixtures/reject/src/lib.rs:113:20 | +| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:286:6 | +| 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:265:16 | +| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:286:6 | +| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:129:2 | +| 2 | `u8` | fixtures/reject/src/lib.rs:88:2 | +| 2 | `{closure}` | fixtures/reject/src/lib.rs:378:15 | +| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:172:1 | +| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:226:1 | +| 1 | `HashMap` | fixtures/reject/src/lib.rs:309:6 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:317:9 | +| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:104:2 | +| 1 | `Noisy` | fixtures/reject/src/lib.rs:239:20 | +| 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:258:22 | | 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | -| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:200:51 | -| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | -| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | -| 1 | `std::mem` | fixtures/reject/src/lib.rs:49:18 | -| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:296:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:296:7 | -| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:208:8 | -| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:154:11 | -| 1 | `std::str` | fixtures/reject/src/lib.rs:390:4 | -| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | -| 1 | `u64` | fixtures/reject/src/lib.rs:119:2 | -| 1 | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | +| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:418:15 | +| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:185:51 | +| 1 | `std::iter::IntoIterator` | fixtures/reject/src/lib.rs:17:2 | +| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:158:23 | +| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:179:14 | +| 1 | `std::mem` | fixtures/reject/src/lib.rs:44:18 | +| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:281:48 | +| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:281:7 | +| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:193:8 | +| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:139:11 | +| 1 | `std::str` | fixtures/reject/src/lib.rs:370:4 | +| 1 | `std::string::String` | fixtures/reject/src/lib.rs:82:10 | +| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:134:2 | +| 1 | `u32` | fixtures/reject/src/lib.rs:244:13 | +| 1 | `u64` | fixtures/reject/src/lib.rs:104:2 | +| 1 | `{async closure}` | fixtures/reject/src/lib.rs:60:2 | ## By type or path | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:28:15 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:405:2 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:23:15 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:385:2 | | 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:128:20 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:95:16 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:16:13 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:65:10 | -| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | -| 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:66:3 | -| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | -| 2 | an iterator that owns `_`, which drops, which is not supported yet | `{closure}` | fixtures/reject/src/lib.rs:398:15 | -| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:108:2 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:301:6 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:416:18 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:324:6 | -| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:280:38 | -| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:280:16 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:356:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:366:6 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:332:9 | -| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:119:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:200:51 | -| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:379:2 | -| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:103:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:296:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:296:7 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:259:13 | +| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:113:20 | +| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:129:2 | +| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:51:2 | +| 2 | an iterator that owns `_`, which drops, which is not supported yet | `{closure}` | fixtures/reject/src/lib.rs:378:15 | +| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:93:2 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:286:6 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:396:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:309: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:265:38 | +| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:265:16 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:341:2 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:418:15 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::iter::IntoIterator::into_iter` | fixtures/reject/src/lib.rs:17:2 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::option::Option::map_or` | fixtures/reject/src/lib.rs:351:18 | +| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:411:21 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:317:9 | +| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:104:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:185:51 | +| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:364:2 | +| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:88:2 | +| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:281:48 | +| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:281:7 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:244:13 | | 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | -| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | -| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:124:2 | -| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | -| 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:17:2 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:254:20 | +| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:60:2 | +| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:109:2 | +| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:134:2 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:172:1 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:226:1 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:239:20 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:306:52 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:423:53 | -| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | -| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:306:52 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:167:2 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:221:2 | -| 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:273:22 | -| 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:384:4 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:417:2 | -| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:154:11 | -| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:97:10 | -| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:49:18 | -| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:208:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:374:4 | -| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:33:4 | -| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:390:4 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:291:52 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:403:53 | +| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:158:23 | +| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:179:14 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:291:52 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:152:2 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:206:2 | +| 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:258:22 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:397:2 | +| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:139:11 | +| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:82:10 | +| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:44:18 | +| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:193:8 | +| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:359:4 | +| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:28:4 | +| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:370:4 | | 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | ## Spans
unsupported call to `_` (8) -- fixtures/reject/src/lib.rs:33:4: unsupported call to `std::slice::::sort` -- fixtures/reject/src/lib.rs:49:18: unsupported call to `std::mem::size_of_val::` -- fixtures/reject/src/lib.rs:97:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:154:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:208:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:374:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:390:4: unsupported call to `core::str::::split::<[char; 2]>` -- fixtures/reject/src/lib.rs:417:2: unsupported call to ` as std::ops::Deref>::deref` - -
- -
an assignment through a reference to `_` (7) - -- fixtures/reject/src/lib.rs:17:2: an assignment through a reference to `u32` -- fixtures/reject/src/lib.rs:66:3: an assignment through a reference to `u8` -- fixtures/reject/src/lib.rs:124:2: an assignment through a reference to `std::sync::Arc` -- fixtures/reject/src/lib.rs:144:2: an assignment through a reference to `std::pin::Pin>` -- fixtures/reject/src/lib.rs:149:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` -- fixtures/reject/src/lib.rs:267:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` -- fixtures/reject/src/lib.rs:367:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:28:4: unsupported call to `std::slice::::sort` +- fixtures/reject/src/lib.rs:44:18: unsupported call to `std::mem::size_of_val::` +- fixtures/reject/src/lib.rs:82:10: unsupported call to `::write_fmt` +- fixtures/reject/src/lib.rs:139:11: unsupported call to ` as std::iter::Iterator>::cycle` +- fixtures/reject/src/lib.rs:193:8: unsupported call to `std::ops::Range::::contains::` +- fixtures/reject/src/lib.rs:359:4: unsupported call to `core::slice::::copy_within::>` +- fixtures/reject/src/lib.rs:370:4: unsupported call to `core::str::::split::<[char; 2]>` +- fixtures/reject/src/lib.rs:397:2: unsupported call to ` as std::ops::Deref>::deref`
`_` is not supported: its `None` and `Some` would both be `undefined` (6) -- fixtures/reject/src/lib.rs:28:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:29:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:37:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:37:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:133:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:301:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:23:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:24:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:32:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:32:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:118:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:286:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined`
-
`_`: a JS value of `_` is a copy, so a reference can't change it (6) +
an iterator that owns `_`, which drops, which is not supported yet (5) -- fixtures/reject/src/lib.rs:16:13: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:22:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:65:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:95:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:366:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:383:15: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:51:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:234:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:239:20: an iterator that owns `Noisy`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:378:15: an iterator that owns `{closure@fixtures/reject/src/lib.rs:378:48: 378:56}`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:379:13: an iterator that owns `{closure@fixtures/reject/src/lib.rs:379:32: 379:39}`, which drops, which is not supported yet
-
an iterator that owns `_`, which drops, which is not supported yet (5) +
`_` with a mutable reference to a value JS copies, which its mapping would copy (4) -- fixtures/reject/src/lib.rs:56:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:249:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:254:20: an iterator that owns `Noisy`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:398:15: an iterator that owns `{closure@fixtures/reject/src/lib.rs:398:48: 398:56}`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:399:13: an iterator that owns `{closure@fixtures/reject/src/lib.rs:399:32: 399:39}`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:17:2: `std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:351:18: `std::option::Option::::map_or` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:411:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:418:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy
a variant of `_`, which is not supported: either is the same JS string (4) -- fixtures/reject/src/lib.rs:405:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:406:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:407:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:412:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:385:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:386:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:387:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:392:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
-
replacing the value behind a reference to `_` (4) +
an assignment through a reference to `_` (4) -- fixtures/reject/src/lib.rs:108:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:112:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:273:22: replacing the value behind a reference to `[u16; 1]` -- fixtures/reject/src/lib.rs:384:4: replacing the value behind a reference to `std::string::String` +- fixtures/reject/src/lib.rs:109:2: an assignment through a reference to `std::sync::Arc` +- fixtures/reject/src/lib.rs:129:2: an assignment through a reference to `std::pin::Pin>` +- fixtures/reject/src/lib.rs:134:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` +- fixtures/reject/src/lib.rs:252:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>`
@@ -237,164 +222,172 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:7:14: unsupported type `f64` - fixtures/reject/src/lib.rs:7:25: unsupported type `f64` - fixtures/reject/src/lib.rs:11:16: unsupported type `dyn std::ops::Fn(u8) -> u8` -- fixtures/reject/src/lib.rs:117:51: unsupported type `f64` +- fixtures/reject/src/lib.rs:102:51: unsupported type `f64` + +
+ +
replacing the value behind a reference to `_` (3) + +- fixtures/reject/src/lib.rs:93:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:97:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:258:22: replacing the value behind a reference to `[u16; 1]`
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:128:20: `Poll>>` is not supported: it would be pending two ways with one value -- fixtures/reject/src/lib.rs:138:54: `Poll>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:113:20: `Poll>>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:123:54: `Poll>` is not supported: it would be pending two ways with one value
`_` 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 (2) -- fixtures/reject/src/lib.rs:280: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:280: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:265: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:265: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
a field of `_` (2) -- fixtures/reject/src/lib.rs:296:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:296:48: a field of `std::ops::RangeFrom` +- fixtures/reject/src/lib.rs:281:7: a field of `std::ops::RangeTo` +- fixtures/reject/src/lib.rs:281:48: a field of `std::ops::RangeFrom`
an iterator of the crate implementing `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:187:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet -- fixtures/reject/src/lib.rs:241:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:172:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:226:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet
constructing `_` from another crate (2) -- fixtures/reject/src/lib.rs:173:23: constructing `std::iter::Map` from another crate -- fixtures/reject/src/lib.rs:194:14: constructing `std::iter::Rev` from another crate +- fixtures/reject/src/lib.rs:158:23: constructing `std::iter::Map` from another crate +- fixtures/reject/src/lib.rs:179:14: constructing `std::iter::Rev` from another crate
dropping a closure that owns a value that drops, which is not supported yet (2) -- fixtures/reject/src/lib.rs:51:1: dropping a closure that owns a value that drops, which is not supported yet -- fixtures/reject/src/lib.rs:396:18: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:46:1: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:376:18: dropping a closure that owns a value that drops, which is not supported yet
overriding `_`, which std's adaptors call in place of `next` or beside it (2) -- fixtures/reject/src/lib.rs:167:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it -- fixtures/reject/src/lib.rs:221:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:152:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:206:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it
`Binary` formatting, as in `{:b}`, is not supported (1) -- fixtures/reject/src/lib.rs:85:3: `Binary` formatting, as in `{:b}`, is not supported +- fixtures/reject/src/lib.rs:70:3: `Binary` formatting, as in `{:b}`, is not supported
`LowerExp` formatting, as in `{:e}`, is not supported (1) -- fixtures/reject/src/lib.rs:87:3: `LowerExp` formatting, as in `{:e}`, is not supported +- fixtures/reject/src/lib.rs:72:3: `LowerExp` formatting, as in `{:e}`, is not supported
`Octal` formatting, as in `{:o}`, is not supported (1) -- fixtures/reject/src/lib.rs:86:3: `Octal` formatting, as in `{:o}`, is not supported +- fixtures/reject/src/lib.rs:71:3: `Octal` formatting, as in `{:o}`, is not supported
`Pointer` formatting, as in `{:p}`, is not supported (1) -- fixtures/reject/src/lib.rs:90:3: `Pointer` formatting, as in `{:p}`, is not supported +- fixtures/reject/src/lib.rs:75:3: `Pointer` formatting, as in `{:p}`, is not supported
`_` holds `_`, which is `undefined` as `None` is, which is not supported (1) -- fixtures/reject/src/lib.rs:301:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported +- fixtures/reject/src/lib.rs:286:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:416:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:396:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:324:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:309:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:356:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet - -
- -
`_`, a mutable reference to a value a map holds, kept other than to read and write it (1) - -- fixtures/reject/src/lib.rs:366:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it +- fixtures/reject/src/lib.rs:341:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:332:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:317:9: `Hasher::write`, which is not supported yet
a `_` cast from `_` to `_` (1) -- fixtures/reject/src/lib.rs:119:2: a `IntToFloat` cast from `u64` to `f64` +- fixtures/reject/src/lib.rs:104:2: a `IntToFloat` cast from `u64` to `f64`
a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` (1) -- fixtures/reject/src/lib.rs:200:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:200:15: 200:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` +- fixtures/reject/src/lib.rs:185:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:185:15: 185:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold`
a coercion to `_` (1) -- fixtures/reject/src/lib.rs:379:2: a coercion to `std::sync::Arc<[u8]>` +- fixtures/reject/src/lib.rs:364:2: a coercion to `std::sync::Arc<[u8]>`
a constant of type `_` (1) -- fixtures/reject/src/lib.rs:103:2: a constant of type `&u8` +- fixtures/reject/src/lib.rs:88:2: a constant of type `&u8`
a copy of a closure that changes what it captured (1) -- fixtures/reject/src/lib.rs:290:14: a copy of a closure that changes what it captured +- fixtures/reject/src/lib.rs:275:14: a copy of a closure that changes what it captured
a mutable borrow of a subslice of `_`, which JS would copy, having no views (1) -- fixtures/reject/src/lib.rs:259:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views +- fixtures/reject/src/lib.rs:244:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views + +
+ +
a mutable reference into a `Result`'s payload, passed on or kept (1) + +- fixtures/reject/src/lib.rs:428:12: a mutable reference into a `Result`'s payload, passed on or kept
a precision, as in `{:.2}`, is not supported (1) -- fixtures/reject/src/lib.rs:82:3: a precision, as in `{:.2}`, is not supported +- fixtures/reject/src/lib.rs:67:3: a precision, as in `{:.2}`, is not supported
a printable type must implement `Display` or `Debug` (1) -- fixtures/reject/src/lib.rs:115:1: a printable type must implement `Display` or `Debug` +- fixtures/reject/src/lib.rs:100:1: a printable type must implement `Display` or `Debug`
@@ -406,13 +399,13 @@ The type or module each refused type or path belongs to.
a width or precision from an argument, as in `{:1$}`, is not supported (1) -- fixtures/reject/src/lib.rs:89:3: a width or precision from an argument, as in `{:1$}`, is not supported +- fixtures/reject/src/lib.rs:74:3: a width or precision from an argument, as in `{:1$}`, is not supported
a zero-sized constant of type `_` (1) -- fixtures/reject/src/lib.rs:75:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:74:10: 74:18}` +- fixtures/reject/src/lib.rs:60:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:59:10: 59:18}`
@@ -424,36 +417,36 @@ The type or module each refused type or path belongs to.
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:306:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:291:52: comparing `std::vec::Vec` as a key, which is not supported yet
constructing `_` (1) -- fixtures/reject/src/lib.rs:423:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:403:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:306:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:291:52: hashing `std::vec::Vec` as a key, which is not supported yet
hex `Debug`, as in `{:x?}`, is not supported (1) -- fixtures/reject/src/lib.rs:88:3: hex `Debug`, as in `{:x?}`, is not supported +- fixtures/reject/src/lib.rs:73:3: hex `Debug`, as in `{:x?}`, is not supported
the `+` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:83:3: the `+` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:68:3: the `+` flag of a format spec is not supported
the `-` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:84:3: the `-` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:69:3: the `-` flag of a format spec is not supported
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index c50db5aa5..0adb65df0 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,83 +1,79 @@ -a root must not be generic at fixtures/reject/src/lib.rs:117:1 +a root must not be generic at fixtures/reject/src/lib.rs:102:1 no item `missing` in the crate -a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:115:1 +a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:100:1 unsupported type `f64` at fixtures/reject/src/lib.rs:7:14 a scalar constant of type `f64` at fixtures/reject/src/lib.rs:8:2 arithmetic on `f64` at fixtures/reject/src/lib.rs:8:2 unsupported type `f64` at fixtures/reject/src/lib.rs:7:25 unsupported type `dyn std::ops::Fn(u8) -> u8` at fixtures/reject/src/lib.rs:11:16 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:16:13 -an assignment through a reference to `u32` at fixtures/reject/src/lib.rs:17:2 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:22:11 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:29:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:28:15 -unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:33:4 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:37:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:37:42 -unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:49:18 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:51:1 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:56:11 -`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:65:10 -an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:66:3 -a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:74:10: 74:18}` at fixtures/reject/src/lib.rs:75:2 -a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:82:3 -the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:83:3 -the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:84:3 -`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:85:12 -`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:86:12 -`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:87:12 -hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:88:3 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:89:15 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:89:3 -`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:90:12 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:95:16 -unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:97:10 -a constant of type `&u8` at fixtures/reject/src/lib.rs:103:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:108:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:112:2 -an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:124:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:128:20 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:133:19 -`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:138:54 -an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:144:2 -an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:149:2 -unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:154:11 -constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:173:23 -constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:194:14 -a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:200:15: 200:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:200:51 -unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:208:8 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:249:4 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:254:20 -a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:259:13 -an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:267:2 -replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib.rs:273:22 -`std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:280:16 -`std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:280:38 -a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:290:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:296:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:296:48 -`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:301:2 -`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:301:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:306:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:306:52 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:324:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:374:4 -a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:379:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:405:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:407:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:406:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:412:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:416:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:417:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:423:53 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:383:15 -replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:384:4 -unsupported call to `core::str::::split::<[char; 2]>` at fixtures/reject/src/lib.rs:390:4 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:396:18 -an iterator that owns `{closure@fixtures/reject/src/lib.rs:398:48: 398:56}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:398:15 -an iterator that owns `{closure@fixtures/reject/src/lib.rs:399:32: 399:39}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:399:13 -overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:167:2 -an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:187:1 -overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:221:2 -an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:241:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:332:9 +`std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:17:11 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:24:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:23:15 +unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:28:4 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:32:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:32:42 +unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:44:18 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:46:1 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:51:11 +a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:59:10: 59:18}` at fixtures/reject/src/lib.rs:60:2 +a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:67:3 +the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:68:3 +the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:69:3 +`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:70:12 +`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:71:12 +`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:72:12 +hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:73:3 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:74:15 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:74:3 +`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:75:12 +unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:82:10 +a constant of type `&u8` at fixtures/reject/src/lib.rs:88:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:93:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:97:2 +an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:109:2 +`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:113:20 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:118:19 +`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:123:54 +an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:129:2 +an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:134:2 +unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:139:11 +constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:158:23 +constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:179:14 +a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:185:15: 185:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:185:51 +unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:193:8 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:234:4 +an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:239:20 +a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:244:13 +an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:252:2 +replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib.rs:258:22 +`std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:265:16 +`std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:265:38 +a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:275:14 +a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:281:7 +a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:281:48 +`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:286:2 +`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:286:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:291:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:291:52 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:309:6 +unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:359:4 +a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:364:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:385:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:387:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:386:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:392:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:396:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:397:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:403:53 +unsupported call to `core::str::::split::<[char; 2]>` at fixtures/reject/src/lib.rs:370:4 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:376:18 +an iterator that owns `{closure@fixtures/reject/src/lib.rs:378:48: 378:56}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:378:15 +an iterator that owns `{closure@fixtures/reject/src/lib.rs:379:32: 379:39}`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:379:13 +`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:411:21 +`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:418:15 +a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:428:12 +overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:152:2 +an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:172:1 +overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:206:2 +an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:226:1 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:317:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 78204e0c7..33a3bbbd4 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -12,11 +12,6 @@ pub fn dynamic(f: &dyn Fn(u8) -> u8) -> u8 { f(1) } -/// JS has no reference to a number: the caller's `u32` would not change. -pub fn bump(x: &mut u32) { - *x += 1; -} - /// Each element would be a copy, so the increments would be lost. pub fn increment(v: &mut [u32]) { for x in v { @@ -59,16 +54,6 @@ pub fn each(v: Vec) -> u8 { sum } -/// The async block's generator would change its own copy of `n`. -pub fn async_borrow() -> u8 { - let mut n = 1u8; - let f = async { - n += 1; - }; - drop(f); - n -} - /// An async closure is a coroutine closure, not an async body. pub fn async_closure() -> u8 { let f = async || 1u8; @@ -91,7 +76,7 @@ pub fn specs(n: u8, w: usize) -> [String; 9] { ] } -/// `fmt::Write` for a `String`, which a JS string can't be changed through. +/// `fmt::Write` for a `String`, which has no mapping. pub fn written(s: &mut String, n: u8) { use std::fmt::Write; let _ = write!(s, "{n}"); @@ -361,7 +346,7 @@ pub fn widest(a: std::sync::Arc, b: std::sync::Arc) -> std::sync::Arc< a.max(b) } -/// A reference to a value a map holds that JS copies, passed on, where no `rt.Place` follows it. +/// std hands its closure a `&mut` to a value JS copies, which its mapping has as the value. pub fn passed(map: &mut std::collections::HashMap) -> u8 { map.get_mut(&1).map_or(0, |v| { *v += 1; @@ -379,11 +364,6 @@ pub fn shared(b: std::sync::Arc<[u8; 2]>) -> std::sync::Arc<[u8]> { b } -/// A `String` pushed to through a parameter, whose JS value is the caller's copy. -pub fn pushed(s: &mut String) { - s.push('a'); -} - /// A `str` pattern of several chars, where only a `char`, a `&str`, and a predicate are /// supported. pub fn split_chars(s: &str) -> usize { @@ -425,3 +405,27 @@ pub fn cow_made(a: &std::sync::Arc) -> usize { } std::sync::Arc::strong_count(a) } + +/// std makes a `&mut` to a value JS copies, which its mapping has as the value. +pub fn last_bumped(v: &mut Vec) { + if let Some(x) = v.last_mut() { + *x += 1; + } +} + +/// std hands the closure a `&mut` to a value JS copies, as `passed`'s is. +pub fn modified(map: &mut std::collections::HashMap) { + map.entry(1).and_modify(|v| *v += 1); +} + +fn bumped(x: &mut u8) { + *x += 1; +} + +/// A `Result`'s value passed on: a store through it makes the `Result` again, which no +/// `rt.Place` of a path does. +pub fn ok_passed(r: &mut Result) { + if let Ok(v) = r { + bumped(v); + } +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 5ee7dadfa..2a691382d 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -2,7 +2,6 @@ package = "reject-fixture" roots = [ "float", "dynamic", - "bump", "increment", "nested", "sorted", @@ -10,7 +9,6 @@ roots = [ "Noisy", "owning_closure", "each", - "async_borrow", "async_closure", "specs", "written", @@ -49,9 +47,11 @@ roots = [ "cow_borrowed", "cow_bytes", "cow_made", - "pushed", "split_chars", "owning_lazy", + "last_bumped", + "modified", + "ok_passed", "missing", ] printable = ["Meters"] diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index ca0742106..03b30f7fa 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -1905,8 +1905,8 @@ export function arcs(log: Log.Log, id: rt.u32, at: rt.u8): void { count("tree", other); check(1); const _48: rt.Arc = rt.arcClone(name); - const place = rt.entryOrInsertMut(rt.entry(map, _48, rt.drop), 0); - place.v = rt.u8Add(place.v, 1); + const _45: rt.Place = rt.entryOrInsertMut(rt.entry(map, _48, rt.drop), 0); + _45.v = rt.u8Add(_45.v, 1); count("entry", name); rt.hashRemove(map, name, rt.drop); count("remove", name); @@ -1944,9 +1944,9 @@ export function arcs(log: Log.Log, id: rt.u32, at: rt.u8): void { unwind = 88; const _123 = { tag: "One", _0: Guard.new(rt.u32Add(id, 1), Log.clone$Clone(log)) } as Held.Held; drop$Option_Held(rt.btreeInsert(tags, 1, _123, undefined, drop$Held)); - const place2 = rt.entryOrInsertMut(rt.entry(tags, 1), { tag: "One", _0: Guard.new(rt.u32Add(id, 2), Log.clone$Clone(log)) } as Held.Held, drop$Held); - if (place2.v.tag === "One") { - const part8 = Guard.id(place2.v._0); + const _128: rt.Place = rt.entryOrInsertMut(rt.entry(tags, 1), { tag: "One", _0: Guard.new(rt.u32Add(id, 2), Log.clone$Clone(log)) } as Held.Held, drop$Held); + if (_128.v.tag === "One") { + const part8 = Guard.id(_128.v._0); const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part8, f)]; Log.note(log, rt.fmtFormat(["tag ", args4[0]])); } diff --git a/ts/fixtures/task/expected/model.ts b/ts/fixtures/task/expected/model.ts index bad498315..61c260813 100644 --- a/ts/fixtures/task/expected/model.ts +++ b/ts/fixtures/task/expected/model.ts @@ -173,10 +173,11 @@ export class sumFuture { /** * One value read through the captures only an async block makes: a borrow, which * dropping the block must not drop; a copy, which a later change to the original must - * not reach; a mutable borrow the block replaces whole, which the caller must see; a - * move on one path only; and a move the block only borrows, which drops when the block - * returns or is cancelled. Between them, a value of two types that hold each other, and - * guards held across awaits that read values first. + * not reach; a mutable borrow the block replaces whole, and one of a number it writes + * across an await, which the caller must see; a move on one path only; and a move the + * block only borrows, which drops when the block returns or is cancelled. Between them, + * a value of two types that hold each other, and guards held across awaits that read + * values first. */ export function blocks(rx: Consumer.Consumer, guard: Guard.Guard, moves: boolean): rt.Future { return new blocksFuture(rx, guard, moves); @@ -198,6 +199,8 @@ export class blocksFuture { #saved$2!: rt.u32; #awaitee$3!: rt.Future; #mark!: Mark.Mark; + #count!: rt.u32; + #counted!: rt.u32; #nested!: Inner.Inner; #looped!: rt.u32; #awaitee$4!: rt.Future; @@ -222,71 +225,78 @@ export class blocksFuture { b1: { b2: { b3: { - if (this.#state === 0) { - unwind = 89; - rt.drop(this.#rx); - unwind = 0; - rt.drop(this.#guard); - return; - } - if (this.#state === 3) { - unwind = 63; - rt.drop(this.#awaitee); - unwind = 64; - rt.drop(this.#saved); - this.#saved$9 = false; - break b0; - } - if (this.#state === 4) { - unwind = 58; - rt.drop(this.#awaitee$2); - unwind = 59; - rt.drop(this.#saved); - this.#saved$8 = false; - break b1; - } - if (this.#state === 5) { - unwind = 54; - rt.drop(this.#awaitee$3); - break b2; - } - if (this.#state === 6) { + b4: { + if (this.#state === 0) { + unwind = 96; + rt.drop(this.#rx); + unwind = 0; + rt.drop(this.#guard); + return; + } + if (this.#state === 3) { + unwind = 70; + rt.drop(this.#awaitee); + unwind = 71; + rt.drop(this.#saved); + this.#saved$9 = false; + break b0; + } + if (this.#state === 4) { + unwind = 65; + rt.drop(this.#awaitee$2); + unwind = 66; + rt.drop(this.#saved); + this.#saved$8 = false; + break b1; + } + if (this.#state === 5) { + unwind = 61; + rt.drop(this.#awaitee$3); + break b2; + } + if (this.#state === 6) { + unwind = 58; + rt.drop(this.#awaitee$3); + break b3; + } + if (this.#state === 7) { + unwind = 55; + rt.drop(this.#awaitee$3); + break b4; + } + if (this.#state === 8) { + unwind = 48; + rt.drop(this.#awaitee$3); + } else if (this.#state === 9) { + unwind = 45; + rt.drop(this.#awaitee$4); + } else { + return; + } unwind = 51; - rt.drop(this.#awaitee$3); - break b3; - } - if (this.#state === 7) { - unwind = 44; - rt.drop(this.#awaitee$3); - } else if (this.#state === 8) { - unwind = 41; - rt.drop(this.#awaitee$4); - } else { - return; + rt.drop(this.#saved); + unwind = 53; + rt.drop(this.#nested); } - unwind = 47; - rt.drop(this.#saved); - unwind = 49; - rt.drop(this.#nested); } } this.#saved$7 = false; } - unwind = 62; + unwind = 69; rt.dropAll(this.#slots); } if (this.#saved$4) { - unwind = 67; + unwind = 74; rt.drop(this.#second); } this.#saved$4 = false; if (this.#saved$5) { - unwind = 68; + unwind = 75; rt.drop(this.#first); } this.#saved$5 = false; if (this.#saved$3) { - unwind = 69; + unwind = 76; rt.drop(this.#guard); } this.#saved$3 = false; @@ -296,74 +306,79 @@ export class blocksFuture { } this.#saved$6 = false; } catch (e) { - b9: { - b10: { - b11: { - b12: { - b13: { - b14: { - b15: { - b16: { - b17: { - b18: { - b19: { - b20: { - b21: { - if (unwind === 0) { - throw e; - } - if (unwind === 41) { - break b20; - } - if (unwind === 44) { - break b20; - } - if (unwind === 47) { - break b19; - } - if (unwind === 49) { - break b18; - } - if (unwind === 51) { - break b17; - } - if (unwind === 54) { - break b16; - } - if (unwind === 58) { - rt.drop(this.#saved); - break b21; - } - if (unwind === 59) { - break b21; - } - if (unwind === 62) { - break b14; - } - if (unwind === 63) { - rt.drop(this.#saved); - } else if (unwind !== 64) { - if (unwind === 67) { - break b12; + b10: { + b11: { + b12: { + b13: { + b14: { + b15: { + b16: { + b17: { + b18: { + b19: { + b20: { + b21: { + b22: { + b23: { + if (unwind === 0) { + throw e; + } + if (unwind === 45) { + break b22; + } + if (unwind === 48) { + break b22; } - if (unwind === 68) { - break b11; + if (unwind === 51) { + break b21; + } + if (unwind === 53) { + break b20; + } + if (unwind === 55) { + break b19; + } + if (unwind === 58) { + break b18; + } + if (unwind === 61) { + break b17; + } + if (unwind === 65) { + rt.drop(this.#saved); + break b23; + } + if (unwind === 66) { + break b23; } if (unwind === 69) { + break b15; + } + if (unwind === 70) { + rt.drop(this.#saved); + } else if (unwind !== 71) { + if (unwind === 74) { + break b13; + } + if (unwind === 75) { + break b12; + } + if (unwind === 76) { + break b11; + } + rt.drop(this.#guard); break b10; } - rt.drop(this.#guard); - break b9; + this.#saved$9 = false; + break b14; } - this.#saved$9 = false; - break b13; + this.#saved$8 = false; + break b16; } - this.#saved$8 = false; - break b15; + rt.drop(this.#saved); } - rt.drop(this.#saved); + rt.drop(this.#nested); } - rt.drop(this.#nested); } } } @@ -400,7 +415,7 @@ export class blocksFuture { let _40!: Guard.Guard; let result2!: rt.usize; let seen!: rt.Future; - let _141!: Inner.Inner | undefined; + let _167!: Inner.Inner | undefined; let unwind: number = 0; try { b0: { @@ -408,323 +423,355 @@ export class blocksFuture { b2: { b3: { b4: { - if (this.#state === 0) { - unwind = 148; - this.#saved$6 = false; - this.#saved$3 = false; - this.#saved$5 = false; - this.#saved$4 = false; - this.#saved$9 = false; - this.#saved$8 = false; - this.#saved$7 = false; - this.#saved$6 = true; - this.#saved$3 = true; - this.#first = Guard.new(rt.u32Add(this.#guard.id, 200), Log.clone$Clone(this.#guard.log)); - unwind = 147; - this.#saved$5 = true; - this.#second = Guard.new(rt.u32Add(this.#guard.id, 300), Log.clone$Clone(this.#guard.log)); - unwind = 158; - this.#saved$4 = true; - rt.drop(new blocksFuture$2(this.#first)); - turns(this.#guard.log, rt.u32Rem(this.#guard.id, 5)); - temporaries(this.#guard.log, this.#guard.id); - unwind = 146; - this.#saved = Guard.new(rt.u32Add(this.#guard.id, 900), Log.clone$Clone(this.#guard.log)); - unwind = 144; - this.#saved$9 = true; - this.#awaitee = new recvFuture(this.#rx); - } else if (this.#state === 1) { - rt.asyncFnResumed(); - } else if (this.#state === 2) { - rt.asyncFnResumedPanic(); - } else if (this.#state !== 3) { - if (this.#state === 4) { - break b4; - } - if (this.#state === 5) { - break b3; - } - if (this.#state === 6) { - break b2; + b5: { + if (this.#state === 0) { + unwind = 165; + this.#saved$6 = false; + this.#saved$3 = false; + this.#saved$5 = false; + this.#saved$4 = false; + this.#saved$9 = false; + this.#saved$8 = false; + this.#saved$7 = false; + this.#saved$6 = true; + this.#saved$3 = true; + this.#first = Guard.new(rt.u32Add(this.#guard.id, 200), Log.clone$Clone(this.#guard.log)); + unwind = 164; + this.#saved$5 = true; + this.#second = Guard.new(rt.u32Add(this.#guard.id, 300), Log.clone$Clone(this.#guard.log)); + unwind = 175; + this.#saved$4 = true; + rt.drop(new blocksFuture$2(this.#first)); + turns(this.#guard.log, rt.u32Rem(this.#guard.id, 5)); + temporaries(this.#guard.log, this.#guard.id); + unwind = 163; + this.#saved = Guard.new(rt.u32Add(this.#guard.id, 900), Log.clone$Clone(this.#guard.log)); + unwind = 161; + this.#saved$9 = true; + this.#awaitee = new recvFuture(this.#rx); + } else if (this.#state === 1) { + rt.asyncFnResumed(); + } else if (this.#state === 2) { + rt.asyncFnResumedPanic(); + } else if (this.#state !== 3) { + if (this.#state === 4) { + break b5; + } + if (this.#state === 5) { + break b4; + } + if (this.#state === 6) { + break b3; + } + if (this.#state === 7) { + break b2; + } + if (this.#state === 8) { + break b1; + } + break b0; } - if (this.#state === 7) { - break b1; + unwind = 158; + const _32: rt.Poll = this.#awaitee.poll(_2); + if (_32 !== rt.Pending) { + unwind = 159; + const result: rt.u64 | undefined = _32; + rt.drop(this.#awaitee); + this.#saved$9 = false; + this.#waited = consume(this.#saved, result); + unwind = 175; + this.#saved$9 = false; + _40 = Guard.new(rt.u32Add(this.#guard.id, 910), Log.clone$Clone(this.#guard.log)); + unwind = 157; + const _46: Guard.Guard = Guard.new(rt.u32Add(this.#guard.id, 920), Log.clone$Clone(this.#guard.log)); + unwind = 155; + this.#slots = [_40, _46]; + this.#saved = Guard.new(rt.u32Add(this.#guard.id, 930), Log.clone$Clone(this.#guard.log)); + unwind = 153; + this.#saved$8 = true; + this.#awaitee$2 = new slotFuture(this.#rx, this.#slots.length); + } else { + this.#state = 3; + return rt.Pending; } - break b0; } - unwind = 141; - const _32: rt.Poll = this.#awaitee.poll(_2); - if (_32 !== rt.Pending) { - unwind = 142; - const result: rt.u64 | undefined = _32; - rt.drop(this.#awaitee); - this.#saved$9 = false; - this.#waited = consume(this.#saved, result); - unwind = 158; - this.#saved$9 = false; - _40 = Guard.new(rt.u32Add(this.#guard.id, 910), Log.clone$Clone(this.#guard.log)); - unwind = 140; - const _46: Guard.Guard = Guard.new(rt.u32Add(this.#guard.id, 920), Log.clone$Clone(this.#guard.log)); - unwind = 138; - this.#slots = [_40, _46]; - this.#saved = Guard.new(rt.u32Add(this.#guard.id, 930), Log.clone$Clone(this.#guard.log)); - unwind = 136; - this.#saved$8 = true; - this.#awaitee$2 = new slotFuture(this.#rx, this.#slots.length); + unwind = 151; + const _63: rt.Poll = this.#awaitee$2.poll(_2); + if (_63 !== rt.Pending) { + unwind = 172; + result2 = _63; + rt.drop(this.#awaitee$2); + if (!(result2 < 2)) { + rt.panic("index out of bounds: the len is " + 2 + " but the index is " + result2); + } + unwind = 44; + rt.drop(this.#slots[result2]); + unwind = 156; + this.#saved$8 = false; + this.#slots[result2] = this.#saved; + this.#saved$8 = false; + const arg = this.#waited; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; + const _78: string = rt.fmtFormat(["slot after ", args2[0]]); + unwind = 150; + Guard.note(this.#slots[0], _78); + unwind = 170; + this.#tally = { n: this.#guard.id }; + this.#saved$7 = true; + seen = new blocksFuture$3(copy$Tally(this.#tally)); + this.#tally.n = rt.u32Add(this.#tally.n, 1000); + this.#saved = this.#guard; + this.#saved$2 = this.#tally.n; + this.#saved$7 = false; + this.#awaitee$3 = seen; } else { - this.#state = 3; + this.#state = 4; return rt.Pending; } } - unwind = 134; - const _63: rt.Poll = this.#awaitee$2.poll(_2); - if (_63 !== rt.Pending) { - unwind = 155; - result2 = _63; - rt.drop(this.#awaitee$2); - if (!(result2 < 2)) { - rt.panic("index out of bounds: the len is " + 2 + " but the index is " + result2); - } - unwind = 44; - rt.drop(this.#slots[result2]); - unwind = 139; - this.#saved$8 = false; - this.#slots[result2] = this.#saved; - this.#saved$8 = false; - const arg = this.#waited; - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; - const _78: string = rt.fmtFormat(["slot after ", args2[0]]); - unwind = 133; - Guard.note(this.#slots[0], _78); - unwind = 153; - this.#tally = { n: this.#guard.id }; - this.#saved$7 = true; - seen = new blocksFuture$3(copy$Tally(this.#tally)); - this.#tally.n = rt.u32Add(this.#tally.n, 1000); - this.#saved = this.#guard; - this.#saved$2 = this.#tally.n; - this.#saved$7 = false; - this.#awaitee$3 = seen; + unwind = 148; + const _101: rt.Poll = this.#awaitee$3.poll(_2); + if (_101 !== rt.Pending) { + unwind = 170; + const _98: rt.u32 = _101; + rt.drop(this.#awaitee$3); + const arg2 = this.#saved$2; + const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg2, f), (f: rt.Formatter) => rt.u32Display(_98, f)]; + const _93: string = rt.fmtFormat(["tally ", args4[0], " then ", args4[1]]); + unwind = 147; + Guard.note(this.#saved, _93); + unwind = 170; + this.#mark = { n: 1 }; + this.#awaitee$3 = new blocksFuture$4(this.#mark); } else { - this.#state = 4; + this.#state = 5; return rt.Pending; } } - unwind = 131; - const _101: rt.Poll = this.#awaitee$3.poll(_2); - if (_101 !== rt.Pending) { - unwind = 153; - const _98: rt.u32 = _101; + unwind = 146; + const _117: rt.Poll = this.#awaitee$3.poll(_2); + if (_117 !== rt.Pending) { + unwind = 170; + this.#saved$2 = _117; rt.drop(this.#awaitee$3); - const arg2 = this.#saved$2; - const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg2, f), (f: rt.Formatter) => rt.u32Display(_98, f)]; - const _93: string = rt.fmtFormat(["tally ", args4[0], " then ", args4[1]]); - unwind = 130; - Guard.note(this.#saved, _93); - unwind = 153; - this.#mark = { n: 1 }; - this.#awaitee$3 = new blocksFuture$4(this.#mark); + const arg3 = this.#saved$2; + const _136: rt.Fmt = (f: rt.Formatter) => rt.u32Display(arg3, f); + const arg4 = this.#mark.n; + const args6: rt.Fmt[] = [_136, (f: rt.Formatter) => rt.u32Display(arg4, f)]; + const _129: string = rt.fmtFormat(["mark ", args6[0], " ", args6[1]]); + unwind = 145; + Guard.note(this.#guard, _129); + unwind = 170; + this.#count = this.#guard.id; + this.#awaitee$3 = new blocksFuture$5(rt.place(() => this.#count, (value) => this.#count = value)); } else { - this.#state = 5; + this.#state = 6; return rt.Pending; } } - unwind = 129; - const _117: rt.Poll = this.#awaitee$3.poll(_2); - if (_117 !== rt.Pending) { - unwind = 153; - this.#saved$2 = _117; + unwind = 144; + const _143: rt.Poll = this.#awaitee$3.poll(_2); + if (_143 !== rt.Pending) { + unwind = 170; + this.#counted = _143; rt.drop(this.#awaitee$3); - const arg3 = this.#saved$2; - const _136: rt.Fmt = (f: rt.Formatter) => rt.u32Display(arg3, f); - const arg4 = this.#mark.n; - const args6: rt.Fmt[] = [_136, (f: rt.Formatter) => rt.u32Display(arg4, f)]; - const _129: string = rt.fmtFormat(["mark ", args6[0], " ", args6[1]]); - unwind = 128; - Guard.note(this.#guard, _129); - unwind = 127; - _141 = undefined; - const _142: Guard.Guard = Guard.new(rt.u32Add(this.#guard.id, 800), Log.clone$Clone(this.#guard.log)); - unwind = 153; - const _149: Outer.Outer = new Outer.Outer({ inner: _141, guard: _142 }); - unwind = 126; - this.#nested = new Inner.Inner({ outer: _149 }); + const arg5 = this.#counted; + const _162: rt.Fmt = (f: rt.Formatter) => rt.u32Display(arg5, f); + const arg6 = this.#count; + const args8: rt.Fmt[] = [_162, (f: rt.Formatter) => rt.u32Display(arg6, f)]; + const _155: string = rt.fmtFormat(["count ", args8[0], " ", args8[1]]); + unwind = 143; + Guard.note(this.#guard, _155); + unwind = 142; + _167 = undefined; + const _168: Guard.Guard = Guard.new(rt.u32Add(this.#guard.id, 800), Log.clone$Clone(this.#guard.log)); + unwind = 170; + const _175: Outer.Outer = new Outer.Outer({ inner: _167, guard: _168 }); + unwind = 141; + this.#nested = new Inner.Inner({ outer: _175 }); const third: Guard.Guard = Guard.new(rt.u32Add(this.#guard.id, 400), Log.clone$Clone(this.#guard.log)); if (!this.#moves) { this.#saved = third; } else { this.#saved = third; } - unwind = 125; + unwind = 140; Guard.note(this.#saved, "chosen"); - this.#awaitee$3 = new blocksFuture$5(this.#guard.id); + this.#awaitee$3 = new blocksFuture$7(this.#guard.id); } else { - this.#state = 6; + this.#state = 7; return rt.Pending; } } - unwind = 124; - const _162: rt.Poll = this.#awaitee$3.poll(_2); - if (_162 !== rt.Pending) { - unwind = 125; - this.#looped = _162; + unwind = 139; + const _188: rt.Poll = this.#awaitee$3.poll(_2); + if (_188 !== rt.Pending) { + unwind = 140; + this.#looped = _188; rt.drop(this.#awaitee$3); - const arg5 = this.#looped; - const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg5, f)]; - const _174: string = rt.fmtFormat(["looped ", args8[0]]); - unwind = 123; - Guard.note(this.#saved, _174); + const arg7 = this.#looped; + const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(arg7, f)]; + const _200: string = rt.fmtFormat(["looped ", args10[0]]); + unwind = 138; + Guard.note(this.#saved, _200); if (this.#moves) { - unwind = 125; + unwind = 140; this.#saved$3 = false; - rt.drop(new blocksFuture$7(this.#guard)); + rt.drop(new blocksFuture$9(this.#guard)); } - unwind = 125; + unwind = 140; this.#saved$5 = false; this.#saved$4 = false; this.#saved$6 = false; - this.#awaitee$4 = new blocksFuture$8(this.#first, this.#second, this.#rx); + this.#awaitee$4 = new blocksFuture$10(this.#first, this.#second, this.#rx); } else { - this.#state = 7; + this.#state = 8; return rt.Pending; } } - unwind = 122; - const _188: rt.Poll = this.#awaitee$4.poll(_2); - if (_188 !== rt.Pending) { - unwind = 125; - const result6: rt.u64 = _188; + unwind = 137; + const _214: rt.Poll = this.#awaitee$4.poll(_2); + if (_214 !== rt.Pending) { + unwind = 140; + const result7: rt.u64 = _214; rt.drop(this.#awaitee$4); - unwind = 126; + unwind = 141; rt.drop(this.#saved); - unwind = 153; + unwind = 170; rt.drop(this.#nested); - unwind = 158; + unwind = 175; this.#saved$7 = false; rt.dropAll(this.#slots); this.#saved$4 = false; this.#saved$5 = false; if (this.#saved$3) { - unwind = 149; + unwind = 166; rt.drop(this.#guard); } this.#saved$3 = false; this.#saved$6 = false; this.#state = 1; - return result6; + return result7; } - this.#state = 8; + this.#state = 9; return rt.Pending; } catch (e) { - b9: { - b10: { - b11: { - b12: { - b13: { - b14: { - b15: { - b16: { - b17: { + b10: { + b11: { + b12: { + b13: { + b14: { + b15: { + b16: { + b17: { + b18: { if (unwind === 0) { throw e; } if (unwind === 44) { this.#saved$8 = false; this.#slots[result2] = this.#saved; - break b14; + break b15; } - if (unwind === 122) { + if (unwind === 137) { rt.drop(this.#awaitee$4); - break b17; + break b18; } - if (unwind === 123) { - break b17; + if (unwind === 138) { + break b18; } - if (unwind === 124) { + if (unwind === 139) { rt.drop(this.#awaitee$3); - break b17; + break b18; + } + if (unwind === 140) { + break b18; } - if (unwind === 125) { + if (unwind === 141) { break b17; } - if (unwind === 126) { + if (unwind === 142) { + rt.drop(_167); break b16; } - if (unwind === 127) { - rt.drop(_141); - break b15; + if (unwind === 143) { + break b16; } - if (unwind === 128) { - break b15; + if (unwind === 144) { + rt.drop(this.#awaitee$3); + break b16; + } + if (unwind === 145) { + break b16; } - if (unwind === 129) { + if (unwind === 146) { rt.drop(this.#awaitee$3); - break b15; + break b16; } - if (unwind === 130) { - break b15; + if (unwind === 147) { + break b16; } - if (unwind === 131) { + if (unwind === 148) { rt.drop(this.#awaitee$3); - break b15; + break b16; } - if (unwind === 133) { - break b13; + if (unwind === 150) { + break b14; } - if (unwind === 134) { + if (unwind === 151) { rt.drop(this.#awaitee$2); - break b14; + break b15; } - if (unwind === 136) { + if (unwind === 153) { rt.drop(this.#saved); this.#saved$8 = false; - break b13; + break b14; } - if (unwind === 138) { + if (unwind === 155) { this.#saved$8 = false; - break b13; + break b14; } - if (unwind === 139) { - break b13; + if (unwind === 156) { + break b14; } - if (unwind === 140) { + if (unwind === 157) { rt.drop(_40); - break b12; + break b13; } - if (unwind === 141) { + if (unwind === 158) { rt.drop(this.#awaitee); - } else if (unwind !== 142) { - if (unwind === 144) { + } else if (unwind !== 159) { + if (unwind === 161) { rt.drop(this.#saved); this.#saved$9 = false; - break b12; + break b13; } - if (unwind === 146) { + if (unwind === 163) { this.#saved$9 = false; + break b13; + } + if (unwind === 164) { break b12; } - if (unwind === 147) { + if (unwind === 165) { break b11; } - if (unwind === 148) { + if (unwind === 166) { break b10; } - if (unwind === 149) { - break b9; + if (unwind === 170) { + break b16; } - if (unwind === 153) { + if (unwind === 172) { break b15; } - if (unwind === 155) { - break b14; - } - break b12; + break b13; } if (this.#saved$9) { rt.drop(this.#saved); } this.#saved$9 = false; - break b12; + break b13; } rt.drop(this.#saved); } @@ -734,7 +781,7 @@ export class blocksFuture { rt.drop(seen); } this.#saved$7 = false; - break b13; + break b14; } if (this.#saved$8) { rt.drop(this.#saved); @@ -862,6 +909,72 @@ export class blocksFuture$4 { } export class blocksFuture$5 { + #state: number = 0; + #count: rt.Place; + #awaitee!: rt.Future; + + constructor(count: rt.Place) { + this.#count = count; + } + + [Symbol.dispose](): void { + if (this.#state === 3) { + rt.drop(this.#awaitee); + } + } + + poll(_2: rt.Context): rt.Poll { + let unwind: number = 0; + try { + if (this.#state === 0) { + unwind = 13; + this.#count.v = rt.u32Add(this.#count.v, 1); + this.#awaitee = new blocksFuture$6(); + } else if (this.#state === 1) { + rt.asyncFnResumed(); + } else if (this.#state === 2) { + rt.asyncFnResumedPanic(); + } + unwind = 12; + if (this.#awaitee.poll(_2) !== rt.Pending) { + unwind = 13; + rt.drop(this.#awaitee); + this.#count.v = rt.u32Add(this.#count.v, 1); + const _0: rt.Poll = this.#count.v; + this.#state = 1; + return _0; + } + this.#state = 3; + return rt.Pending; + } catch (e) { + if (unwind === 0) { + throw e; + } + if (unwind === 12) { + rt.drop(this.#awaitee); + } + this.#state = 2; + throw e; + } + } +} + +export class blocksFuture$6 { + #state: number = 0; + + [Symbol.dispose](): void { + } + + poll(_2: rt.Context): rt.Poll { + if (this.#state === 0) { + this.#state = 1; + return undefined; + } + rt.asyncFnResumed(); + } +} + +export class blocksFuture$7 { #state: number = 0; #base: rt.u32; #total!: rt.u32; @@ -909,7 +1022,7 @@ export class blocksFuture$5 { unwind = 17; this.#x = this.#base; this.#x = rt.u32Add(this.#x, 1); - this.#awaitee = new blocksFuture$6(); + this.#awaitee = new blocksFuture$8(); bb0 = 5; continue; case 5: @@ -939,7 +1052,7 @@ export class blocksFuture$5 { } } -export class blocksFuture$6 { +export class blocksFuture$8 { #state: number = 0; [Symbol.dispose](): void { @@ -954,7 +1067,7 @@ export class blocksFuture$6 { } } -export class blocksFuture$7 { +export class blocksFuture$9 { #state: number = 0; #guard: Guard.Guard; @@ -997,7 +1110,7 @@ export class blocksFuture$7 { } } -export class blocksFuture$8 { +export class blocksFuture$10 { #state: number = 0; #first: Guard.Guard; #second: Guard.Guard; diff --git a/ts/fixtures/task/src/model.rs b/ts/fixtures/task/src/model.rs index 33aaba0ad..42a244cb7 100644 --- a/ts/fixtures/task/src/model.rs +++ b/ts/fixtures/task/src/model.rs @@ -117,10 +117,11 @@ pub async fn sum(mut rx: Consumer, guard: Guard) -> u64 { /// One value read through the captures only an async block makes: a borrow, which /// dropping the block must not drop; a copy, which a later change to the original must -/// not reach; a mutable borrow the block replaces whole, which the caller must see; a -/// move on one path only; and a move the block only borrows, which drops when the block -/// returns or is cancelled. Between them, a value of two types that hold each other, and -/// guards held across awaits that read values first. +/// not reach; a mutable borrow the block replaces whole, and one of a number it writes +/// across an await, which the caller must see; a move on one path only; and a move the +/// block only borrows, which drops when the block returns or is cancelled. Between them, +/// a value of two types that hold each other, and guards held across awaits that read +/// values first. pub async fn blocks(mut rx: Consumer, guard: Guard, moves: bool) -> u64 { let first = Guard::new(guard.id + 200, guard.log.clone()); let second = Guard::new(guard.id + 300, guard.log.clone()); @@ -147,6 +148,16 @@ pub async fn blocks(mut rx: Consumer, guard: Guard, moves: bool) -> u64 { } .await; guard.note(&format!("mark {replaced} {}", mark.n)); + // A number a block borrows mutably across an await, whose writes the caller sees. + let mut count = guard.id; + let counted = async { + count += 1; + async {}.await; + count += 1; + count + } + .await; + guard.note(&format!("count {counted} {count}")); let cycle = Outer { inner: None, guard: Guard::new(guard.id + 800, guard.log.clone()), diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 158fa9ad2..4e92606fb 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -44,6 +44,40 @@ export function assertFailed(op: string, left: Fmt, right: Fmt, args?: Arguments panicFmt(["assertion `left ", op, " right`", ...failed, "\n left: ", left, "\n right: ", right]); } +// Places + +/** + * A `&mut` to a value JS copies, such as a number, which no JS value can point at: where + * the value is, read and written through `v`. + */ +export interface Place { + v: T; +} + +/** A place read and written by `get` and `set`: a local's, a field's, or an element's. */ +class Accessed implements Place { + private readonly read: () => T; + private readonly write: (value: T) => void; + + constructor(read: () => T, write: (value: T) => void) { + this.read = read; + this.write = write; + } + + get v(): T { + return this.read(); + } + + set v(value: T) { + this.write(value); + } +} + +/** The place `get` reads and `set` writes. */ +export function place(get: () => T, set: (value: T) => void): Place { + return new Accessed(get, set); +} + // Results /** `Result`. */ diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index e1b53884c..9b8a6d901 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 { panic } from "../rt.ts"; +import { type Place, panic } from "../rt.ts"; import { type Limbs, lt } from "./int.ts"; import { DONE, type Done, Iter, iterToArray, type RangeInclusive } from "./iter.ts"; import { type Arc, dropAll } from "./task.ts"; @@ -237,14 +237,6 @@ function itself(value: T): T { return value; } -/** - * A `&mut` to a value a collection holds that JS copies, such as a number, which no JS - * value can point at: where the value is, read and written through `v`. - */ -export interface Place { - v: T; -} - /** The place of index `i` of `a`. */ class AtIndex implements Place { private readonly a: T[]; diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 0c311c7f8..f48cad9f7 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -242,12 +242,6 @@ fn undefined_arg<'tcx>(b: &Body<'_, '_, 'tcx>, std: Std, coll: Ty<'tcx>) -> Opti (0..n).map(|i| arg(coll, i)).find(|&t| b.t.erases_to(t).undefined) } -/// Whether a value of type `ty` a collection holds is one JS copies, such as a number, so -/// a `&mut` to it is an `rt.Place` rather than the value. -fn copied<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { - b.t.object_kind(ty).is_none() && !matches!(ty.kind(), ty::Ref(..)) -} - /// Whether `call` returns a `&mut`, or an `Option` of one, to a value a map holds that JS /// copies, which its mapping returns as an `rt.Place`: `get_mut`, and an entry's. pub fn place_call<'tcx>(b: &Body<'_, '_, 'tcx>, call: &Call<'tcx>) -> bool { @@ -270,7 +264,7 @@ pub fn place_call<'tcx>(b: &Body<'_, '_, 'tcx>, call: &Call<'tcx>) -> bool { ], _ => return false, }; - methods.contains(&name.as_str()) && copied(b, arg(coll, 1)) + methods.contains(&name.as_str()) && b.t.needs_place(arg(coll, 1)) } /// The type an inherent method's impl is of, such as `HashMap`. @@ -335,7 +329,7 @@ fn hash<'tcx>( (_, "is_empty") => Expr::rt("hashLen", values).binary("===", Expr::lit("0")), (_, "clear") => Expr::rt("hashClear", values), (_, "contains_key" | "contains") => Expr::rt("hashContains", values), - (_, "get_mut") if !set && copied(b, arg(coll, 1)) => Expr::rt("hashGetMut", values), + (_, "get_mut") if !set && b.t.needs_place(arg(coll, 1)) => Expr::rt("hashGetMut", values), (_, "get" | "get_mut") if !set => Expr::rt("hashGet", values), (_, "get") => Expr::rt("hashKey", values), (_, "take") => { @@ -496,7 +490,7 @@ fn btree<'tcx>( (_, "is_empty") => Expr::rt("btreeLen", values).binary("===", Expr::lit("0")), (_, "clear") => Expr::rt("btreeClear", values), (_, "contains_key" | "contains") => Expr::rt("btreeContains", values), - (_, "get_mut") if !set && copied(b, arg(coll, 1)) => Expr::rt("btreeGetMut", values), + (_, "get_mut") if !set && b.t.needs_place(arg(coll, 1)) => Expr::rt("btreeGetMut", values), (_, "get" | "get_mut") if !set => Expr::rt("btreeGet", values), (_, "get_key_value") => Expr::rt("btreeGetKeyValue", values), (_, "insert") if set => Expr::rt("btreeAdd", values), @@ -661,7 +655,7 @@ fn entry<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, name: &str, args: Vec let value = arg(coll, 1); let mut values = args; // What these return a `&mut` to is a place where JS would copy it. - let place = copied(b, value); + let place = b.t.needs_place(value); let mutable = |f: &str| match place { true => format!("{f}Mut"), false => f.to_string(), diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index cde8f76db..829597fed 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -89,7 +89,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }, ty::FnPtr(..) => { let f = self.operand(func, span, &mut pre); - let values = self.operands(false, args, result, span, &mut pre); + let values = self.operands(false, &[], args, result, span, &mut pre); (f.call(values), true) } _ => (self.err(span, format!("a call through `{fn_ty}`")), true), @@ -105,15 +105,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if !pre.is_empty() { self.emit(pre, None, false, out); } - let value = match *fn_ty.kind() { - ty::FnDef(def_id, gargs) if self.place_result(def_id, gargs.skip_binder(), args, span) => { - match self.hold_place(dest, value, span, out) { - Some(value) => value, - None => return, - } - } - _ => value, - }; // What an `Iterator::next` returns, by the protocol, unless a `next` made it already. let value = match dest.as_local() { Some(rustc_middle::mir::RETURN_PLACE) @@ -197,10 +188,12 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { /// Arguments, uncopied, since a callee that changes a parameter in place copies it /// first, but for a `Copy` aggregate std `keeps`, copied unless moved out of a local's - /// own value, which the analysis then made the local's own. + /// own value, which the analysis then made the local's own. Each argument `pointees` + /// marks is what an `rt.Place` it is reads, as std's mappings take a `&mut` parameter. fn operands( &mut self, translated: bool, + pointees: &[bool], args: &[Spanned>], result: Ty<'tcx>, span: Span, @@ -208,7 +201,19 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { ) -> Vec { let saved = std::mem::replace(&mut self.into_frozen, true); let mut values = Vec::with_capacity(args.len()); - for arg in args { + for (i, arg) in args.iter().enumerate() { + if pointees.get(i) == Some(&true) + && let Some(p) = arg.node.place() + && self + .b + .t + .place_pointee(p.ty(&self.mir.local_decls, self.tcx).ty) + .is_some() + { + let deref = self.tcx.mk_place_deref(p); + values.push(self.place_expr(deref, span, out)); + continue; + } let value = self.operand_frozen(&arg.node, span, out); values.push(match &arg.node { // Its type, rather than its variant's, for std's runtime function to infer @@ -274,36 +279,79 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let f = self.operand(&callee.node, span, out); return f.call(values); } - // A function of the crate gets what JS passes, so a `&mut` to a number can't reach it. let local = self.b.t.translated(def_id, gargs); - if local { - for arg in args { - self.check_escape(&arg.node, span); + let pointees = match local { + true => Vec::new(), + false => { + if let Some(err) = self.std_places(def_id, gargs, result, span) { + return err; + } + let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(); + let inputs = tcx.instantiate_bound_regions_with_erased(sig).inputs().to_vec(); + inputs + .iter() + .map(|t| matches!(t.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut))) + .collect() } - } - let values = self.operands(local, args, result, span, out); + }; + let values = self.operands(local, &pointees, args, result, span, out); self.b.call_def(def_id, gargs, values, span, out) } - /// Refuse a `&mut` to a value JS copies, passed on whole to code that could write - /// through it: it would change a copy. - fn check_escape(&mut self, op: &Operand<'tcx>, span: Span) { - let (Operand::Copy(place) | Operand::Move(place)) = op else { - return; + /// A refusal of std's `def_id` if it would make a `&mut` to a value JS copies, which + /// its mapping has as the value, not an `rt.Place`: one it returns or its iterator + /// yields, other than a map's mapping, or one it hands a closure. A `&mut` it returns + /// as a type parameter, as `Option::unwrap` does, is what it was given. + fn std_places( + &mut self, + def_id: rustc_hir::def_id::DefId, + gargs: GenericArgsRef<'tcx>, + result: Ty<'tcx>, + span: Span, + ) -> Option { + let tcx = self.tcx; + let gargs = self.b.subst(gargs); + let call = library::Call { + def_id, + args: gargs, + span, }; - if !place.projection.is_empty() { - return; + if crate::lower::collections::place_call(self.b, &call) { + return None; } - let ty = self.mir.local_decls[place.local].ty; - if let ty::Ref(_, inner, rustc_ast::Mutability::Mut) = ty.kind() - && matches!(self.slots[place.local], Slot::Alias(_)) - && self.b.t.object_kind(*inner).is_none() - { - self.err( - span, - format!("a mutable reference to `{inner}` passed on, which is no object it can change in place"), - ); + let t = &*self.b.t; + let handed = gargs.types().any(|ty| { + let sig = match ty.kind() { + ty::Closure(_, args) => args.as_closure().sig(), + ty::FnDef(..) | ty::FnPtr(..) => ty.fn_sig(tcx), + _ => return false, + }; + tcx.instantiate_bound_regions_with_erased(sig) + .inputs() + .iter() + .any(|&i| t.has_place(i)) + }); + let yielded = t.iter_item(result).is_some_and(|item| t.has_place(item)); + let made = t.has_place(result) && { + let resolved = Instance::try_resolve(tcx, t.typing_env_pub(), def_id, gargs) + .ok() + .flatten() + .map_or(def_id, |instance| instance.def_id()); + let sig = tcx.fn_sig(resolved).instantiate_identity().skip_norm_wip(); + let output = tcx.instantiate_bound_regions_with_erased(sig).output(); + output + .walk() + .filter_map(|a| a.as_type()) + .any(|ty| matches!(ty.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut))) + }; + if !(handed || yielded || made) { + return None; } + let path = tcx.def_path_str(def_id); + Some(self.err( + span, + format!("`{path}` with a mutable reference to a value JS copies, which its mapping would copy"), + )) } /// A std call MIR needs lowered here: `Some(Some((value, effect)))`, or `Some(None)` @@ -341,21 +389,21 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { match (owner.as_str(), name.as_str()) { // Replacing what a `&mut` borrows. ("mem", "take") => { - let place = self.borrowed_place(&args[0].node, span)?; + let place = self.borrowed_place(&args[0].node, span, out)?; let default = library::default_value(self.b, targ(0)?)?; done(self.swap_out(place, default, "taken", span, out), true) } ("mem", "replace") => { - let place = self.borrowed_place(&args[0].node, span)?; + let place = self.borrowed_place(&args[0].node, span, out)?; let value = self.operand(&args[1].node, span, out); done(self.swap_out(place, value, "old", span, out), true) } ("mem", "swap") => { - let a = self.borrowed_place(&args[0].node, span)?; - let c = self.borrowed_place(&args[1].node, span)?; + let a = self.borrowed_place(&args[0].node, span, out)?; + let c = self.borrowed_place(&args[1].node, span, out)?; let old = self.swap_out(a, c.0.clone(), "swapped", span, out); self.set_borrowed(&c, old, span, out); - done(Expr::undefined(), true) + done(Expr::undefined(), false) } // A range of numbers steps in place, with nothing between it and the loop. ("Iterator", "next") if super::small_range(tcx, targ(0)?) => { @@ -370,7 +418,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // A JS string can't change in place, so what the `&mut` borrows gets a longer one. ("String", "push") => { - let place = self.borrowed_place(&args[0].node, span)?; + let place = self.borrowed_place(&args[0].node, span, out)?; let c = self.operand(&args[1].node, span, out); let pushed = place.0.clone().binary("+", library::char_text(c)); self.set_borrowed(&place, pushed, span, out); @@ -378,7 +426,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // A `Cow` is the `String` it would hold, so the `&mut` borrows the same place. ("Cow", "to_mut") if targ(0).is_some_and(|t| t.is_str()) => { - let (place, borrowed) = self.borrowed_place(&args[0].node, span)?; + let (place, borrowed) = self.borrowed_place(&args[0].node, span, out)?; if let Some(local) = dest.as_local() && self.defs[local] == 1 && matches!(self.slots[local], Slot::Var(_)) @@ -387,10 +435,16 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { self.reborrows.extend(borrowed.map(|b| (local, b))); return Some(None); } - done(place, true) + match borrowed { + Some(borrowed) => { + let target = self.stable_target(borrowed, place, span, out); + done(self.place_of(target, None), true) + } + None => done(place, true), + } } ("Option", "take") => { - let place = self.borrowed_place(&args[0].node, span)?; + let place = self.borrowed_place(&args[0].node, span, out)?; done(self.swap_out(place, Expr::undefined(), "taken", span, out), true) } // Indexing, whose result a `&mut` reads in place. @@ -405,9 +459,11 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { && matches!(self.slots[local], Slot::Var(_)) => { let result = dest.ty(&self.mir.local_decls, tcx).ty; - let place = self.call_def(def_id, gargs, args, result, span, out); + let values = self.operands(false, &[], args, result, span, out); + let place = self.b.call_def(def_id, gargs, values, span, out); if !place.is_path() { - return done(place, true); + let msg = format!("`{}` of a value JS copies, which is no path", tcx.def_path_str(def_id)); + return done(self.err(span, msg), true); } self.materialize(&place, out); self.slots[local] = Slot::Alias(Some(place)); @@ -598,70 +654,25 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } - /// Whether a call returns the `rt.Place` of a value a map holds that JS copies, or an - /// `Option` of one: a map's mapping, or `expect` or `unwrap` of such an `Option`. - fn place_result( - &self, - def_id: rustc_hir::def_id::DefId, - gargs: GenericArgsRef<'tcx>, - args: &[Spanned>], - span: Span, - ) -> bool { - let call = library::Call { - def_id, - args: self.b.subst(gargs), - span, - }; - if crate::lower::collections::place_call(self.b, &call) { - return true; - } - let unwrap = library::key(self.tcx, def_id) - .is_some_and(|(o, n)| o == "Option" && matches!(n.as_str(), "expect" | "unwrap")); - unwrap - && matches!(args.first().map(|a| &a.node), Some(Operand::Move(p) | Operand::Copy(p)) - if p.as_local().is_some_and(|l| self.place_opts.contains(&l))) - } - - /// The value of a call that returns a place, for its destination: a reference, which - /// reads and writes through the place held in a constant, and `None` once it is one; an - /// `Option` only tested and taken apart; or else a refusal, since no other code takes a - /// place for a reference. - fn hold_place(&mut self, dest: Place<'tcx>, value: Expr, span: Span, out: &mut Vec) -> Option { - let ty = dest.ty(&self.mir.local_decls, self.tcx).ty; - match dest.as_local() { - Some(local) if self.uses[local] == 0 => Some(value), - Some(local) - if matches!(ty.kind(), ty::Ref(..)) - && self.defs[local] == 1 - && matches!(self.slots[local], Slot::Var(_)) => - { - let place = self.path(value, "place", out); - self.slots[local] = Slot::Alias(Some(place.member("v"))); - None - } - Some(local) if self.place_opts.contains(&local) => Some(value), - _ => Some(self.err( - span, - format!("`{ty}`, a mutable reference to a value a map holds, kept other than to read and write it"), - )), - } - } - /// The place a `&mut` operand borrows, as an assignable path, and through the /// reference, which a store resolves: an alias of a borrowed place, not a copy of a - /// reference, which holds the object it points at. - fn borrowed_place(&mut self, op: &Operand<'tcx>, span: Span) -> Option> { + /// reference, which holds the object it points at, or an `rt.Place`, whose `v` it is. + fn borrowed_place(&mut self, op: &Operand<'tcx>, span: Span, out: &mut Vec) -> Option> { let (Operand::Copy(place) | Operand::Move(place)) = op else { return None; }; if !place.projection.is_empty() { return None; } + let deref = self.tcx.mk_place_deref(*place); match &self.slots[place.local] { Slot::Alias(Some(target)) if (target.is_path() || matches!(target, Expr::Index(..))) && self.alias_of_place(place.local) => { - Some((target.clone(), Some(self.tcx.mk_place_deref(*place)))) + Some((target.clone(), Some(deref))) + } + _ if self.b.t.place_pointee(self.mir.local_decls[place.local].ty).is_some() => { + Some((self.place_expr(deref, span, out), Some(deref))) } _ => { let pointee = self.mir.local_decls[place.local].ty.peel_refs(); @@ -796,6 +807,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { self.slots[local] = Slot::Alias(Some(place)); return Some(None); } + if name == "index_mut" && self.b.t.needs_place(elem_ty) { + let target = self.stable_path(place, false, span, out); + return Some(Some((self.place_of(target, None), true))); + } Some(Some((place, true))) } None => { diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 542533661..494a179d0 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -85,14 +85,23 @@ fn instance_mir<'tcx>(t: &mut Translator<'_, 'tcx>, instance: Instance<'tcx>, sp pub enum Env { /// A parameter like any other. Plain, - /// A closure's environment, whose fields are the expressions it captured. - Closure(Vec), + /// A closure's environment, whose fields are what it captured. + Closure(Vec), /// A coroutine's state, behind `Pin<&mut Self>` or `&mut Self`: `this` of its class. Coroutine, /// Drop glue, whose `_1` is a pointer to the value: the value in JS. Shim, } +/// What a closure captured. +#[derive(Clone)] +pub struct Capture { + pub value: Expr, + /// Whether `value` is the place a `&mut` captured by reference borrows, which the + /// closure reads and writes as JS's do, rather than an `rt.Place` of it. + pub pointee: bool, +} + /// How a MIR local lowers. #[derive(Clone, Debug)] enum Slot<'tcx> { @@ -225,10 +234,6 @@ pub struct Fx<'m, 'b, 'a, 'tcx> { halves: FxHashMap, &'m Operand<'tcx>)>, /// Temporaries of those joins, whose assignments go unlowered. joined: FxHashSet, - /// `Option`s of a `&mut` to a value a map holds that JS copies, as `get_mut` returns - /// it: its `rt.Place` or `undefined`, which is only tested, unwrapped, or taken apart - /// into a reference that reads and writes through it. - place_opts: FxHashSet, /// The paths a switch lowered so far tests the variant of, which `tsc` narrows in /// its arms. switched: FxHashSet, @@ -291,7 +296,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { unwind_out: FxHashMap::default(), halves: FxHashMap::default(), joined: FxHashSet::default(), - place_opts: FxHashSet::default(), switched: FxHashSet::default(), tested: IndexVec::from_elem_n(false, n), widened: FxHashSet::default(), @@ -456,7 +460,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { self.find_stepped(); self.unborrow_passed(); self.find_halves(); - self.find_place_opts(); for local in mir.local_decls.indices() { let ty = mir.local_decls[local].ty; let slot = if self.zero_sized(ty) { @@ -835,6 +838,66 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } + /// Whether a reference in `local` is read whole, rather than only through, or a reborrow + /// of what it points at is: passed on, kept, or captured. A `&mut` parameter of std's + /// reads through it, as its mapping takes what it points at. + fn read_whole(&self, local: Local) -> bool { + use rustc_middle::mir::visit::{PlaceContext, Visitor}; + struct Reads<'a, 'tcx> { + local: Local, + whole: bool, + reborrows: Vec, + pointees: &'a dyn Fn(&Operand<'tcx>, usize) -> bool, + } + impl<'tcx> Visitor<'tcx> for Reads<'_, 'tcx> { + fn visit_terminator(&mut self, term: &mir::Terminator<'tcx>, at: mir::Location) { + if let TerminatorKind::Call { func, args, .. } = &term.kind + && args.iter().enumerate().any(|(i, a)| { + a.node.place().is_some_and(|p| p.as_local() == Some(self.local)) && !(self.pointees)(func, i) + }) { + self.whole = true; + } + if !matches!(term.kind, TerminatorKind::Call { .. }) { + self.super_terminator(term, at); + } + } + fn visit_assign(&mut self, to: &Place<'tcx>, rvalue: &Rvalue<'tcx>, at: mir::Location) { + if let Rvalue::Ref(_, _, p) = rvalue + && p.local == self.local + && let [mir::ProjectionElem::Deref] = p.projection.as_slice() + && let Some(to) = to.as_local() + { + self.reborrows.push(to); + } + self.super_assign(to, rvalue, at); + } + fn visit_place(&mut self, place: &Place<'tcx>, cx: PlaceContext, _: mir::Location) { + let used = matches!(cx, PlaceContext::NonMutatingUse(_)) + || matches!(cx, PlaceContext::MutatingUse(mir::visit::MutatingUseContext::Borrow)); + if place.local == self.local && place.projection.is_empty() && used { + self.whole = true; + } + } + } + let tcx = self.tcx; + let pointees = |func: &Operand<'tcx>, i: usize| match *func.ty(&self.mir.local_decls, tcx).kind() { + ty::FnDef(def_id, gargs) if !self.b.t.translated(def_id, self.b.subst(gargs.skip_binder())) => { + let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(); + let input = tcx.instantiate_bound_regions_with_erased(sig).inputs().get(i).copied(); + input.is_some_and(|t| matches!(t.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut))) + } + _ => false, + }; + let mut reads = Reads { + local, + whole: false, + reborrows: Vec::new(), + pointees: &pointees, + }; + reads.visit_body(self.mir); + reads.whole || reads.reborrows.into_iter().any(|r| r != local && self.read_whole(r)) + } + /// Whether `local` is the task's context an async body is resumed with, as it passes it /// on: a parameter nothing assigns, or a local assigned it once, in another type that /// is the context in JS too. @@ -983,91 +1046,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } - /// The `Option`s of places `get_mut` returns that are only tested, unwrapped, or taken - /// apart into a reference that reads its place in place: no other code sees a place. - fn find_place_opts(&mut self) { - use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; - struct Uses<'tcx> { - local: Local, - at: Vec<(Place<'tcx>, PlaceContext, mir::Location)>, - } - impl<'tcx> Visitor<'tcx> for Uses<'tcx> { - fn visit_place(&mut self, place: &Place<'tcx>, cx: PlaceContext, at: mir::Location) { - if place.local == self.local { - self.at.push((*place, cx, at)); - } - } - } - let mir: &'m mir::Body<'tcx> = self.mir; - let tcx = self.tcx; - let callee = |func: &Operand<'tcx>| match *func.ty(&mir.local_decls, tcx).kind() { - ty::FnDef(def_id, gargs) => Some((def_id, gargs.skip_binder())), - _ => None, - }; - for data in mir.basic_blocks.iter() { - let TerminatorKind::Call { - func, - destination, - fn_span, - .. - } = &data.terminator().kind - else { - continue; - }; - let Some(local) = destination.as_local() else { - continue; - }; - let option = self.b.t.std_of(mir.local_decls[local].ty) == Some(crate::lower::library::Std::Option); - let Some((def_id, gargs)) = callee(func) else { - continue; - }; - let call = crate::lower::library::Call { - def_id, - args: self.b.subst(gargs), - span: *fn_span, - }; - if !option || self.defs[local] != 1 || !crate::lower::collections::place_call(self.b, &call) { - continue; - } - let mut uses = Uses { local, at: Vec::new() }; - uses.visit_body(mir); - let ok = uses - .at - .iter() - .all(|&(place, cx, at)| match (place.projection.as_slice(), cx) { - ( - _, - PlaceContext::NonUse(_) | PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention), - ) => true, - ([], PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect)) => true, - // Its one definition, by the call. - ([], PlaceContext::MutatingUse(MutatingUseContext::Call)) => true, - // Unwrapped by value, into a reference to the same place. - ([], PlaceContext::NonMutatingUse(NonMutatingUseContext::Move | NonMutatingUseContext::Copy)) => { - let term = mir.basic_blocks[at.block].terminator(); - matches!(&term.kind, TerminatorKind::Call { func, args, .. } - if matches!(args.first().map(|a| &a.node), Some(Operand::Move(p) | Operand::Copy(p)) if *p == place) - && callee(func).and_then(|(d, _)| crate::lower::library::key(tcx, d)) - .is_some_and(|(o, n)| o == "Option" && matches!(n.as_str(), "expect" | "unwrap"))) - } - // `Some`'s reference, into a local that reads it in place. - ( - [mir::ProjectionElem::Downcast(_, v), mir::ProjectionElem::Field(f, _)], - PlaceContext::NonMutatingUse(NonMutatingUseContext::Move | NonMutatingUseContext::Copy), - ) if v.as_u32() == 1 && f.as_u32() == 0 => { - let stmt = mir.basic_blocks[at.block].statements.get(at.statement_index); - matches!(stmt.map(|s| &s.kind), Some(StatementKind::Assign(assign)) - if matches!(&assign.1, Rvalue::Use(Operand::Move(p) | Operand::Copy(p), _) if *p == place) - && assign.0.as_local().is_some_and(|to| self.alias(to))) - } - _ => false, - }); - if ok { - self.place_opts.insert(local); - } - } - } - /// Each `(hi as u64) << 32 | lo as u64` of halves of at most 32 bits, as moq's /// `from_halves` writes it, which lowers to `rt.u64FromHalves(hi, lo)`: no shift that /// boxes limbs past 2^53, and no `|` that unboxes them. Its shift and casts go @@ -1487,13 +1465,6 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } return Type::Union(vec![item, Type::Rt("Done", Vec::new())]); } - if self.place_opts.contains(&local) - && let ty::Adt(_, args) = ty.kind() - && let ty::Ref(_, value, _) = args.type_at(0).kind() - { - let value = self.b.t.ty(*value, self.span); - return Type::Union(vec![Type::Rt("Place", vec![value]), Type::Builtin("undefined")]); - } let ty = match (self.checked.contains(&local), ty.kind()) { (true, ty::Tuple(tys)) => tys[0], // A box's pointer is the box's contents in JS. @@ -2085,13 +2056,23 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let target = match rvalue { Rvalue::Ref(_, kind, p) => match self.mut_subslice(*kind, *p, span) { Some(e) => e, - None => self.place_expr(*p, span, out), + None => match self.reborrowed(*p, span, out) { + Some(e) => e, + // Read whole, the place is held as it is now for its `rt.Place`. + None if self.points_at_place(local) && self.read_whole(local) => { + let target = self.place_expr(*p, span, out); + self.stable_target(*p, target, span, out) + } + None => self.place_expr(*p, span, out), + }, }, - Rvalue::CopyForDeref(p) => self.place_expr(*p, span, out), - // `Some`'s place, which the reference reads and writes through. - Rvalue::Use(Operand::Copy(p) | Operand::Move(p), _) if self.place_opts.contains(&p.local) => { - self.place_expr(*p, span, out).member("v") + // A copy of a `&mut` captured by reference borrows the same place. + Rvalue::CopyForDeref(p) | Rvalue::Use(Operand::Copy(p) | Operand::Move(p), _) + if let Some(target) = self.pointee_capture(*p) => + { + target } + Rvalue::CopyForDeref(p) => self.place_expr(*p, span, out), Rvalue::Use(Operand::Copy(p) | Operand::Move(p), _) => self.place_expr(*p, span, out), Rvalue::Cast(_, Operand::Copy(p) | Operand::Move(p), _) => self.place_expr(*p, span, out), Rvalue::Use(op @ Operand::Constant(_), _) => self.operand(op, span, out), diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 437add783..e38cf0331 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -35,6 +35,15 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { // gets here, and `tsc` sees that through `rt.unreachable`. Slot::Unit if self.mir.local_decls[local].ty.is_never() => Expr::rt("unreachable", vec![Expr::undefined()]), Slot::Unit => Expr::undefined(), + // Passed on or kept, a `&mut` to a borrowed place JS copies is its `rt.Place`. + Slot::Alias(Some(target)) if self.points_at_place(local) => { + let target = target.clone(); + let payload = match self.def_rvalue(local) { + Some(mir::Rvalue::Ref(_, _, p)) => self.payload_ty(*p, span), + _ => None, + }; + self.place_of(target, payload) + } Slot::Alias(Some(target)) => target.clone(), Slot::Alias(None) => self.err(span, "a reference read before its borrow"), Slot::Discr(_) => self.err(span, "a discriminant read other than by a switch"), @@ -64,9 +73,19 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { match projection.next() { Some(elem @ ProjectionElem::Field(field, _)) => { pty = pty.projection_ty(tcx, elem); - match captures.get(field.as_usize()) { - Some(capture) => capture.clone(), - None => return self.err(span, "a capture the closure doesn't have"), + let Some(capture) = captures.get(field.as_usize()) else { + return self.err(span, "a capture the closure doesn't have"); + }; + let (value, pointee) = (capture.value.clone(), capture.pointee); + match projection.peek() { + Some(ProjectionElem::Deref) if pointee => { + pty = pty.projection_ty(tcx, ProjectionElem::>::Deref); + projection.next(); + value + } + // Passed on or kept whole, it is the place's `rt.Place`. + None if pointee => self.place_of(value, None), + _ => value, } } _ => return self.err(span, "a closure's environment read whole"), @@ -94,6 +113,16 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { projection.next(); part } + // An alias of a borrowed place is that place, which the dereference reads. + _ if matches!(projection.peek(), Some(ProjectionElem::Deref)) && self.points_at_place(place.local) => { + let Slot::Alias(Some(target)) = &self.slots[place.local] else { + return self.err(span, "a reference read before its borrow"); + }; + let target = target.clone(); + pty = pty.projection_ty(tcx, ProjectionElem::>::Deref); + projection.next(); + target + } _ => self.local_expr(place.local, span), }; // Checked arithmetic's pair is its value, and `.1` is whether it overflowed, which @@ -119,6 +148,12 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { in_bytes = in_bytes || byte_slice(ty); match elem { ProjectionElem::Deref => { + // Drop glue's pointer is the value it drops. + let glue = + matches!(self.env, Env::Shim) && place.local.as_u32() == 1 && pty.ty == decls[place.local].ty; + if self.b.t.place_pointee(ty).is_some() && !glue { + e = e.member("v"); + } // A box's pointer is the box in JS: one to an object shares it. if let ty::RawPtr(pointee, _) = ty.kind() && !matches!(self.slots[place.local], Slot::Alias(_)) @@ -426,9 +461,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // `*r = v` replaces the object `r` points at in place, which other references and // captures share. An alias of a borrowed place, or of a reference to no object, - // assigns the place. + // assigns the place, and an `rt.Place` its `v`. if let [ProjectionElem::Deref] = place.projection.as_slice() && !self.alias_of_place(place.local) + && self.b.t.place_pointee(self.mir.local_decls[place.local].ty).is_none() && !(place.local.as_u32() == 1 && matches!(self.env, Env::Closure(_))) { let pointee = place.ty(&self.mir.local_decls, self.tcx).ty; @@ -512,13 +548,143 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { pub(super) fn alias_of_place(&self, local: Local) -> bool { matches!(self.slots[local], Slot::Alias(_)) && match self.def_rvalue(local) { - Some(mir::Rvalue::Ref(_, _, p)) => !matches!(p.projection.last(), Some(ProjectionElem::Deref)), + // A reborrow of what an alias of a borrowed place points at borrows that place. + Some(mir::Rvalue::Ref(_, _, p)) => match p.projection.as_slice() { + [ProjectionElem::Deref] => self.points_at_place(p.local), + [.., ProjectionElem::Deref] => false, + _ => true, + }, + // A copy of a `&mut` the closure captured by reference. + Some(mir::Rvalue::CopyForDeref(p) | mir::Rvalue::Use(Operand::Copy(p) | Operand::Move(p), _)) => { + self.pointee_capture(*p).is_some() + } Some(_) => false, // An element `index_mut` borrows. None => true, } } + /// The place `place` borrows, if it is a `&mut` the closure captured by reference. + pub(super) fn pointee_capture(&self, place: Place<'tcx>) -> Option { + let Env::Closure(captures) = &self.env else { + return None; + }; + let ([ProjectionElem::Field(field, _)] | [ProjectionElem::Deref, ProjectionElem::Field(field, _)]) = + place.projection.as_slice() + else { + return None; + }; + let capture = captures + .get(field.as_usize()) + .filter(|c| c.pointee && place.local.as_u32() == 1)?; + Some(capture.value.clone()) + } + + /// Whether `local` is an `rt.Place` reference that aliases the place it borrows, so its + /// target is that place rather than the `rt.Place`. + pub(super) fn points_at_place(&self, local: Local) -> bool { + self.b.t.place_pointee(self.mir.local_decls[local].ty).is_some() && self.alias_of_place(local) + } + + /// The `rt.Place` of `target`, the JS path of the borrowed `place`, fixed where it is now. + pub(super) fn make_place(&mut self, place: Place<'tcx>, target: Expr, span: Span, out: &mut Vec) -> Expr { + let target = self.stable_target(place, target, span, out); + let payload = self.payload_ty(place, span); + self.place_of(target, payload) + } + + /// The type of `place` if it is a variant's payload, whose JS path is its whole enum, + /// as `Some`'s is the `Option`. + pub(super) fn payload_ty(&mut self, place: Place<'tcx>, span: Span) -> Option { + let downcast = place.iter_projections().any(|(base, e)| { + matches!(e, ProjectionElem::Downcast(..)) && base.ty(&self.mir.local_decls, self.tcx).ty.is_enum() + }); + downcast.then(|| self.b.t.ty(place.ty(&self.mir.local_decls, self.tcx).ty, span)) + } + + /// `target`, the JS path of the borrowed `place`, with the objects and index it goes + /// through held where they are now, as the borrow fixes them, for an `rt.Place` that + /// reads and writes it later. + pub(super) fn stable_target(&mut self, place: Place<'tcx>, target: Expr, span: Span, out: &mut Vec) -> Expr { + // A store into a `Result`'s value makes the `Result` again, which a path can't. + for (base, elem) in place.iter_projections() { + if let ProjectionElem::Downcast(..) = elem + && let Some(std @ (Std::Result | Std::ControlFlow)) = + self.b.t.std_of(base.ty(&self.mir.local_decls, self.tcx).ty) + { + return self.err( + span, + format!("a mutable reference into a `{std:?}`'s payload, passed on or kept"), + ); + } + } + self.stable_path(target, super::own(place), span, out) + } + + /// `target`, a path, with the index it goes through held where it is now, and the + /// object too unless it is a local's `own` value, which can't change while borrowed. + pub(super) fn stable_path(&mut self, target: Expr, own: bool, span: Span, out: &mut Vec) -> Expr { + self.materialize(&target, out); + let mut base = |fx: &mut Self, e: Expr| match own { + true => e, + false => fx.held_now(e, out), + }; + match target { + Expr::Located(_, e) => self.stable_path(*e, own, span, out), + Expr::Ident(_) | Expr::This => target, + Expr::Member(object, key) => Expr::Member(Box::new(base(self, *object)), key), + Expr::Index(object, i) => { + let object = base(self, *object); + Expr::Index(Box::new(object), Box::new(self.held_now(*i, out))) + } + _ => self.err(span, "a mutable reference passed on or kept, to a value with no place"), + } + } + + /// `e`, evaluated now into a constant unless reading it later reads the same. + fn held_now(&mut self, e: Expr, out: &mut Vec) -> Expr { + if e.is_constant() || matches!(e, Expr::This) || self.stable_name(&e) { + return e; + } + let name = self.b.fresh("borrowed"); + let stmt = StmtKind::decl(false, name.clone(), None, Some(e)).at(None); + self.emit(vec![stmt], None, false, out); + Expr::ident(name) + } + + /// The `rt.Place` that reads and writes `target`, a path that stays put, read as + /// `payload` if it is a variant's. + pub(super) fn place_of(&mut self, target: Expr, payload: Option) -> Expr { + let value = self.b.fresh("value"); + let param = crate::ts::Param { + name: value.clone(), + ty: None, + }; + let read = match payload { + Some(ty) => Expr::As(Box::new(target.clone()), ty), + None => target.clone(), + }; + let get = Expr::Lambda(Vec::new(), Box::new(read)); + let set = Expr::Lambda(vec![param], Box::new(target.assign(Expr::ident(value)))); + Expr::rt("place", vec![get, set]) + } + + /// The `rt.Place` of `place`, a reborrow `&mut *r` of a reference `r` that is one, which is `r`'s. + pub(super) fn reborrowed(&mut self, place: Place<'tcx>, span: Span, out: &mut Vec) -> Option { + let [rest @ .., ProjectionElem::Deref] = place.projection.as_slice() else { + return None; + }; + let base = Place { + local: place.local, + projection: self.tcx.mk_place_elems(rest), + }; + let base_ty = base.ty(&self.mir.local_decls, self.tcx).ty; + if self.b.t.place_pointee(base_ty).is_none() || base.as_local().is_some_and(|l| self.alias_of_place(l)) { + return None; + } + Some(self.place_expr(base, span, out)) + } + /// `SetDiscriminant`: a coroutine's state. pub(super) fn set_discriminant(&mut self, place: Place<'tcx>, variant: VariantIdx, span: Span) -> Option { let ty = place.ty(&self.mir.local_decls, self.tcx).ty; diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index 1b9e441ae..f43b77b80 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{self, Instance, Ty}; use rustc_span::Span; -use super::{Env, Fx, Slot}; +use super::{Capture, Env, Fx, Slot}; use crate::lower::library::Std; use crate::lower::num::{self, Int}; use crate::lower::{AdtRepr, byte_array, field_name}; @@ -34,9 +34,14 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } if let mir::BorrowKind::Mut { .. } = kind { let pointee = place.ty(&self.mir.local_decls, tcx).ty; - if self.b.t.object_kind(pointee).is_none() - && !matches!(pointee.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut)) - { + if self.b.t.needs_place(pointee) { + if let Some(reborrowed) = self.reborrowed(*place, span, out) { + return Some(reborrowed); + } + let target = self.place_expr(*place, span, out); + return Some(self.make_place(*place, target, span, out)); + } + if matches!(pointee.kind(), ty::Ref(_, _, rustc_ast::Mutability::Not)) { return Some(self.err( span, format!("a mutable reference to `{pointee}`, which is no object it can change in place"), @@ -447,6 +452,17 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let mut captures = Vec::with_capacity(ops.len()); for op in ops.iter() { let ty = op.ty(&self.mir.local_decls, tcx); + // A `&mut` to a borrowed place the closure reads and writes as a JS closure does. + if let Some(local) = op.place().and_then(|p| p.as_local()) + && self.points_at_place(local) + && let Slot::Alias(Some(target)) = &self.slots[local] + { + captures.push(Capture { + value: target.clone(), + pointee: true, + }); + continue; + } let value = self.operand(op, span, out); let in_var = op .place() @@ -465,7 +481,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Expr::ident(name) } }; - captures.push(value); + captures.push(Capture { value, pointee: false }); } let instance = Instance::new_raw(def_id, args); let Some(mir) = super::instance_mir(self.b.t, instance, span) else { diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index dcdc450f9..6c80710b6 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -874,6 +874,28 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } } + /// Whether a JS value of `ty` is a copy that no JS value can point at, such as a number, + /// so a `&mut` to it is an `rt.Place`: where the value is, read and written through `v`. + /// A reference's referent is the object it points at, or a copy itself. + pub fn needs_place(&self, ty: Ty<'tcx>) -> bool { + self.object_kind(ty).is_none() && !ty.is_ref() + } + + /// What `ty` points at, if it is a `&mut` that is an `rt.Place`. + pub fn place_pointee(&self, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Ref(_, inner, rustc_ast::Mutability::Mut) if self.needs_place(*inner) => Some(*inner), + _ => None, + } + } + + /// Whether `ty` holds a `&mut` that is an `rt.Place`, a closure's captures included. + pub fn has_place(&self, ty: Ty<'tcx>) -> bool { + ty.walk() + .filter_map(|arg| arg.as_type()) + .any(|t| self.place_pointee(t).is_some()) + } + /// The TypeScript type of a Rust type. pub fn ty(&mut self, ty: Ty<'tcx>, span: Span) -> Type { let tcx = self.tcx; @@ -885,6 +907,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Never => Type::Builtin("never"), ty::Tuple(tys) if tys.is_empty() => Type::Builtin("undefined"), ty::Tuple(tys) => Type::Tuple(tys.iter().map(|t| self.ty(t, span)).collect()), + ty::Ref(_, inner, rustc_ast::Mutability::Mut) if self.needs_place(*inner) => { + Type::Rt("Place", vec![self.ty(*inner, span)]) + } ty::Ref(_, inner, rustc_ast::Mutability::Mut) if self.object_kind(*inner).is_none() => { self.err( span, From a10c31d79bedd7b7f1c0596241243d9816eee827 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:31:22 -0700 Subject: [PATCH 3/5] docs(ts): document rt.Place and finish the mut-place quest has_place skips what a closure or coroutine captured: a std call that takes a closure holding an rt.Place never sees the Place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- quest/m2/ts-model/README.md | 1 - quest/m2/ts-model/mut-place.md | 18 ------------------ ts/README.md | 26 +++++++++++++++++++------- ts/src/lower/mod.rs | 16 ++++++++++++---- 4 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 quest/m2/ts-model/mut-place.md diff --git a/quest/m2/ts-model/README.md b/quest/m2/ts-model/README.md index c788f1b2c..eef1be819 100644 --- a/quest/m2/ts-model/README.md +++ b/quest/m2/ts-model/README.md @@ -52,5 +52,4 @@ Public API: the translator's output for moq-net's model. - [Duration](/quest/m2/ts-model/time.md) - `Duration` translates as std's seconds and nanoseconds - [Std gaps the model reaches](/quest/m2/ts-model/std-more.md) - ranges, wrappers, and `Vec`'s editing methods - [Options of values that can be undefined](/quest/m2/ts-model/nested-option.md) - `Option>` and `Option<()>` keep `None` apart from `Some(None)` -- [Mutable references to values JS copies](/quest/m2/ts-model/mut-place.md) - a `&mut` to a number or an `Option` passed on or kept - [Async in the TypeScript translator](/quest/m2/ts-async.md) - kio's producers and consumers are futures diff --git a/quest/m2/ts-model/mut-place.md b/quest/m2/ts-model/mut-place.md deleted file mode 100644 index 0d019425e..000000000 --- a/quest/m2/ts-model/mut-place.md +++ /dev/null @@ -1,18 +0,0 @@ -# [M] Mutable references to values JS copies - -## Goal - -rust2-ts translates a `&mut` to a local, field, or element whose JS value is a copy (a -number, an `Option` of one, a `Box`) when it is passed on or kept, proven by differential -tests against native Rust. - -## Plan - -Found by the [model's](/quest/m2/ts-model/README.md) census on 2026-10-27: 74 refusals -over 36 items in the model (`&mut Option` in track.rs, `&mut u64` in origin.rs, -`&mut Box` in resume.rs), 9 in moq-pattern's cursors, and 3 in kio. -`rt.Place` already does this for a map's slot. - -Measure on the [TS benchmark](/ts/README.md#bench): code that needs no place gets none. - -Public API: the translator's output. diff --git a/ts/README.md b/ts/README.md index df72cc199..a11be87e3 100644 --- a/ts/README.md +++ b/ts/README.md @@ -67,7 +67,7 @@ in `rt/str.ts`, collections in `rt/collections.ts`, and ownership and async in | `Result` | `rt.Result`: `{ ok: true, value }` or `{ ok: false, error }` | | `ControlFlow` | `rt.Result`, `Ok` to continue; what `?` branches on is the value it was applied to | | tuple, `[T; N]`, `&[T]`, `Vec` | an array; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec` | -| `&T`, `&mut T`, `Box` | the value: a `&mut` must point at an object JS can change in place, or at a map's value through an `rt.Place` | +| `&T`, `&mut T`, `Box` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, is an `rt.Place` | | an iterator | `rt.Iter`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` | | `a..b`, `a..=b` | `rt.Range`, `rt.RangeInclusive`, which are iterators too | | `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque` | `rt.HashMap` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` | @@ -160,6 +160,16 @@ a std function's parameters take, where the crate calls it or takes it as a valu one kept other than in a local, counts as a write into what it points at. A write over a type parameter counts for every type its bounds allow. A caller must not change in place what it passes to or gets from the translation either. +A `&mut` to a value JS copies, which no JS value can point at, such as a number, an +`Option`, an enum, a tuple, a `Box`, or a `String`, is an `rt.Place` whose `v` reads and +writes where it points. Where it is only read and written through, in the function that +borrows it, it is the place it borrows, so a body that passes none on makes none. Passed +on, returned, kept in a field, or captured by a value, it is +`rt.place(() => x, (value) => x = value)` over that place, the objects and index it goes +through held as they were when it was borrowed; a reborrow of one is the same +`rt.Place`. A caller passes one as `{ v }`, or as any object whose `v` it reads and writes. +std's mappings take a `&mut` parameter as what it points at. + A collection keeps Rust's key semantics. A hash map or set keeps a key that is a JS number, string, or boolean in a JS `Map`, which compares those as Rust's `Eq` does, and finds any other key, a 64-bit one past 2^53 included, through its translated `Hash` and @@ -326,16 +336,16 @@ bind to hand-written TS through config ([model](/quest/m2/ts-model/README.md)). ## Not yet -These fail translation: floats, statics, async blocks that borrow a number -mutably and async closures, values that drop in a closure dropped without a call that +These fail translation: floats, statics, async closures, values that drop in a closure dropped without a call that takes it or in an iterator ([Drop](/quest/m2/ts-drop.md)), a `Cow` of other than `str`, a collection holding a type that can be `undefined`, as `()` and `Option` can, a collection's `capacity`, looking up a key by -another type it borrows as through the crate's own `Borrow`, a `&mut` to a value a map -holds that JS copies kept other than to read and write it, `Hasher::write` of bytes, the adaptors +another type it borrows as through the crate's own `Borrow`, a `&mut` to a value JS +copies that std makes, other than a map's, or hands a closure, as `iter_mut` and +`and_modify` do, one into a `Result`'s payload passed on or kept, `Hasher::write` of bytes, the adaptors without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partition`), an own `impl Iterator` with `next_back`, `len`, or another provided method of its own, other format specs (a precision, `+`, `{:b}`, `{:x?}`, and widths from arguments), writing to a -`String` with `write!` or pushing to one through a parameter, a `str` pattern other than a +`String` with `write!`, a `str` pattern other than a `char`, a `&str`, or a predicate, a mutable `str` slice, a copy of a closure that changes what it captured, `mem::swap`, `replace`, or `take` of a reference's whole pointee, assigning an `Arc`, a waker, a `MutexGuard`, a pinned reference, or a future through a @@ -368,7 +378,9 @@ built natively for wasm32 and run beside its translation on the same inputs by on generic types, iterators, with closures that log what each adaptor reads, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` - disagree with JS's, and `vec![x; n]` of types whose `Clone` counts its clones. Its differential test runs through `caller.ts`, a + disagree with JS's, `vec![x; n]` of types whose `Clone` counts its clones, and `&mut` + to values JS copies, of locals, fields, elements, and a map's values, passed on, + returned, kept in a struct, and captured. Its differential test runs through `caller.ts`, a hand-written caller that also prints a `printable` error nothing translated prints, and adds every 64- and 128-bit case over each pair of values next to a power of two, where the runtime switches between numbers and limbs, and its limbs carry and borrow, diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 6c80710b6..57f02e1d0 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -889,11 +889,19 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } } - /// Whether `ty` holds a `&mut` that is an `rt.Place`, a closure's captures included. + /// Whether `ty` holds a `&mut` that is an `rt.Place`, other than in what a closure or + /// coroutine captured. pub fn has_place(&self, ty: Ty<'tcx>) -> bool { - ty.walk() - .filter_map(|arg| arg.as_type()) - .any(|t| self.place_pointee(t).is_some()) + let mut walker = ty.walk(); + while let Some(arg) = walker.next() { + let Some(t) = arg.as_type() else { continue }; + if matches!(t.kind(), ty::Closure(..) | ty::Coroutine(..) | ty::CoroutineClosure(..)) { + walker.skip_current_subtree(); + } else if self.place_pointee(t).is_some() { + return true; + } + } + false } /// The TypeScript type of a Rust type. From 2c3138c2877efe7571b55e610469f589ab61d637 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:55:27 -0700 Subject: [PATCH 4/5] fix(ts): read an rt.Place's value where std looks through a reference std's impls for references compare, order, hash, and format what they point at, which a reference to a Place is not: the forwarded operand, fmt's reference arm, and the collections' key functions now take the Place's `v`, or refuse where a runtime function would compare the Place. DerefMut's receiver passes as its pointee, as std's `&mut self` does, so a `&mut Box` of a copied value writes through the Place instead of rebinding it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/lang/expected/refs.ts | 30 ++++++++++++++++++++++++++++-- ts/fixtures/lang/src/refs.rs | 22 ++++++++++++++++++++++ ts/fixtures/reject/census.md | 12 +++++++----- ts/fixtures/reject/expected.txt | 1 + ts/fixtures/reject/src/lib.rs | 5 +++++ ts/fixtures/reject/ts.toml | 1 + ts/src/lower/body.rs | 12 ++++++++++++ ts/src/lower/collections.rs | 5 +++-- ts/src/lower/fmt.rs | 5 ++++- ts/src/lower/mir/call.rs | 3 ++- ts/src/lower/mod.rs | 9 +++++++++ 11 files changed, 94 insertions(+), 11 deletions(-) diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index e58f64bc0..85f715809 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -124,10 +124,27 @@ export function skip(remaining: rt.Place, data: rt.ByteSlice): rt.usiz } } +/** + * Places std reads through: its impls for references compare, order, and format what + * they point at. + */ +export function readThrough(a: rt.Place, b: rt.Place, out: rt.ByteVec): void { + rt.byteVecPush(out, a.v === b.v ? 1 : 0); + rt.byteVecPush(out, a.v < b.v ? 1 : 0); + rt.byteVecPush(out, rt.cmp(a.v, b.v) & 0xff); + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(a.v, f), (f: rt.Formatter) => rt.u32Display(b.v, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], "|", args2[1]]))); +} + +/** A `&mut Box` dereferenced through `DerefMut`, as generic code over it would. */ +export function derefBox(b: rt.Place, to: rt.u8): void { + b.v = to; +} + export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { let _133!: rt.u8; - const _228: (a0: rt.Place, a1: rt.u8) => void = (x2: rt.Place, b7: rt.u8): void => { - bump(x2, b7); + const _228: (a0: rt.Place, a1: rt.u8) => void = (x3: rt.Place, b7: rt.u8): void => { + bump(x3, b7); }; const by: rt.u8 = rt.optionUnwrapOr(rt.byteSliceFirst(data), 3); let local: rt.u32 = 7; @@ -258,6 +275,15 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { _228(rt.place(() => total, (value14) => total = value14), b6); } rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(total))); + const _246: [rt.u32, rt.u32] = [by as rt.u32, rt.optionUnwrapOr(rt.byteSliceGet(data, 1), 5) as rt.u32]; + let x2: rt.u32 = _246[0]; + let y: rt.u32 = _246[1]; + readThrough(rt.place(() => x2, (value15) => x2 = value15), rt.place(() => y, (value16) => y = value16), out); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(x2 & 0xff, y & 0xff))); + let boxed2: rt.u8 | undefined = undefined as rt.u8 | undefined; + const _267: rt.u8 = total & 0xff; + derefBox(rt.place(() => boxed2, (value17) => boxed2 = value17), _267); + rt.byteVecPush(out, rt.optionUnwrapOr(boxed2, 238)); } export function bumpSlot(c: rt.Place, b: rt.u8): void { diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index 2c57ce668..af8adb1e2 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -129,6 +129,21 @@ struct Pair { n: u8, } +/// Places std reads through: its impls for references compare, order, and format what +/// they point at. +fn read_through(a: &mut u32, b: &mut u32, out: &mut Vec) { + out.push(u8::from(a == b)); + out.push(u8::from(a < b)); + out.push(a.cmp(&b) as u8); + out.extend_from_slice(format!("{a}|{b:?}").as_bytes()); +} + +/// A `&mut Box` dereferenced through `DerefMut`, as generic code over it would. +fn deref_box(b: &mut Box>, to: u8) { + let r = > as std::ops::DerefMut>::deref_mut(b); + *r = Some(to); +} + pub fn refs(data: &[u8], out: &mut Vec) { let by = data.first().copied().unwrap_or(3); // A local, a field, and elements of an array and a `Vec`. @@ -226,6 +241,13 @@ pub fn refs(data: &[u8], out: &mut Vec) { add(&mut total, b); } out.extend_from_slice(&total.to_be_bytes()); + // Read through by std, and dereferenced through `DerefMut`. + let (mut x, mut y) = (u32::from(by), u32::from(data.get(1).copied().unwrap_or(5))); + read_through(&mut x, &mut y, out); + out.extend_from_slice(&[x as u8, y as u8]); + let mut boxed = Box::new(None); + deref_box(&mut boxed, total as u8); + out.push(std::ops::Deref::deref(&boxed).unwrap_or(0xee)); } fn bump_slot(c: &mut usize, b: u8) { diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index ceeec1cd6..c7017e36e 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,14 +1,14 @@ # Census of `reject-fixture` -- Refusals: 81 -- Function instances: 69 +- Refusals: 82 +- Function instances: 70 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 9 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | +| 10 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | | 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:23:15 | | 5 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:51:2 | | 4 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:17:2 | @@ -62,6 +62,7 @@ The type or module each refused type or path belongs to. | 6 | `Option` | fixtures/reject/src/lib.rs:23:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | | 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:51:2 | +| 3 | `std::option::Option` | fixtures/reject/src/lib.rs:286:6 | | 3 | `std::slice` | fixtures/reject/src/lib.rs:28:4 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:109:2 | | 2 | `Iterator` | fixtures/reject/src/lib.rs:152:2 | @@ -69,7 +70,6 @@ The type or module each refused type or path belongs to. | 2 | `Poll` | fixtures/reject/src/lib.rs:113:20 | | 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:286:6 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:265:16 | -| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:286:6 | | 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:129:2 | | 2 | `u8` | fixtures/reject/src/lib.rs:88:2 | | 2 | `{closure}` | fixtures/reject/src/lib.rs:378:15 | @@ -146,6 +146,7 @@ The type or module each refused type or path belongs to. | 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:206:2 | | 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:258:22 | | 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:397:2 | +| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:441:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:139:11 | | 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:82:10 | | 1 | unsupported call to `_` | `::add_assign` | fixtures/reject/src/lib.rs:411:2 | @@ -158,7 +159,7 @@ The type or module each refused type or path belongs to. ## Spans -
unsupported call to `_` (9) +
unsupported call to `_` (10) - fixtures/reject/src/lib.rs:28:4: unsupported call to `std::slice::::sort` - fixtures/reject/src/lib.rs:44:18: unsupported call to `std::mem::size_of_val::` @@ -169,6 +170,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:370:4: unsupported call to `core::str::::split::<[char; 2]>` - fixtures/reject/src/lib.rs:397:2: unsupported call to ` as std::ops::Deref>::deref` - fixtures/reject/src/lib.rs:411:2: unsupported call to `::add_assign` +- fixtures/reject/src/lib.rs:441:2: unsupported call to ` as std::cmp::PartialEq>::eq`
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 0de61e911..9e03c83e0 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -73,6 +73,7 @@ unsupported call to `::add_assign` a `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:417:21 `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:424:15 a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:434:12 +unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:441:2 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:152:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:172:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:206:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index c781dab52..1b08e64e1 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -435,3 +435,8 @@ pub fn ok_passed(r: &mut Result) { bumped(v); } } + +/// `Option`s holding `rt.Place`s, which std's runtime would compare as the Places. +pub fn places_equal(a: &mut u32, b: &mut u32) -> bool { + Some(a) == Some(b) +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index c86ac0847..91e82b22a 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -53,6 +53,7 @@ roots = [ "last_bumped", "modified", "ok_passed", + "places_equal", "missing", ] printable = ["Meters"] diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 51b121031..a7c663f4a 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -123,6 +123,18 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { return call; } if let Some(referent) = library::referent(tcx, def_id, gargs, instance) { + // An operand that was a reference to an `rt.Place`, as `&&mut u32` is, passes + // what the Place points at. + let inputs = |gargs| { + let sig = tcx.fn_sig(def_id).instantiate(tcx, gargs).skip_norm_wip(); + tcx.instantiate_bound_regions_with_erased(sig).inputs().to_vec() + }; + let args = std::iter::zip(args, std::iter::zip(inputs(gargs), inputs(referent))) + .map(|(arg, (was, now))| match was.kind() { + ty::Ref(_, inner, _) if was != now => self.t.pointee_value(*inner, arg), + _ => arg, + }) + .collect(); return self.call_def(def_id, referent, args, span, out); } if let Some(inherited) = library::Inherited::of(tcx, instance) { diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 2baa0dff9..13a431ebe 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -287,10 +287,11 @@ fn arg<'tcx>(coll: Ty<'tcx>, n: usize) -> Ty<'tcx> { args.types().nth(n).expect("a collection's type argument") } -/// What a JS value of `ty` is: through references and boxes, which are their pointee. +/// What a JS value of `ty` is: through references and boxes, which are their pointee, +/// up to a `&mut` that is an `rt.Place`. fn peel<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - let ty = ty.peel_refs(); match ty.kind() { + ty::Ref(_, inner, _) if b.t.place_pointee(ty).is_none() => peel(b, *inner), ty::Adt(adt, args) if Std::of(b.t.tcx, adt.did()) == Some(Std::Box) => peel(b, args.type_at(0)), _ => ty, } diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 3de60f0aa..cd6b3a1f1 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -216,7 +216,10 @@ pub fn std_impl<'tcx>( ty::Ref(_, inner, _) if super::byte_array(*inner) => { b.fmt_call(tr, Ty::new_slice(tcx, tcx.types.u8), value, f, span) } - ty::Ref(_, inner, _) => b.fmt_call(tr, *inner, value, f, span), + ty::Ref(_, inner, _) => { + let value = b.t.pointee_value(ty, value); + b.fmt_call(tr, *inner, value, f, span) + } ty::Int(_) | ty::Uint(_) => { let method = match tr { Trait::Display | Trait::Debug => "display", diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 829597fed..9bd94136f 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -459,7 +459,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { && matches!(self.slots[local], Slot::Var(_)) => { let result = dest.ty(&self.mir.local_decls, tcx).ty; - let values = self.operands(false, &[], args, result, span, out); + // The receiver passes as what it points at, as std's `&mut self` does. + let values = self.operands(false, &[true], args, result, span, out); let place = self.b.call_def(def_id, gargs, values, span, out); if !place.is_path() { let msg = format!("`{}` of a value JS copies, which is no path", tcx.def_path_str(def_id)); diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 2574b3b98..b996e2149 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -890,6 +890,15 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } } + /// What `value`, a `ty` that is a reference, points at: an `rt.Place`'s `v`, and + /// otherwise the reference's own JS value. + pub fn pointee_value(&self, ty: Ty<'tcx>, value: ts::Expr) -> ts::Expr { + match self.place_pointee(ty) { + Some(_) => value.member("v"), + None => value, + } + } + /// Whether `ty` holds a `&mut` that is an `rt.Place`, other than in what a closure or /// coroutine captured. pub fn has_place(&self, ty: Ty<'tcx>) -> bool { From 762e4ee60c2d1b6b6526e90ed8d416973587b24f Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:24:29 -0700 Subject: [PATCH 5/5] fix(ts): pass a binding its Place, and read a shared reborrow's value A bound function's export is checked against the translated signature, which takes a `&mut` to a copied value as an `rt.Place`, but its call went through std's adaptation, which passes the pointee. `mapped` now tells std's mappings from the crate's functions and bindings. A shared reborrow `&*r` of an `rt.Place` aliased the Place itself, so a `&self` method called through a `&mut` parameter read the Place rather than its value. Only a mutable reborrow is the same Place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3 --- ts/fixtures/bind/bind/skip.ts | 7 +++ ts/fixtures/bind/expected/bind/skip.ts | 8 +++ ts/fixtures/bind/expected/harness.ts | 74 ++++++++++++++------------ ts/fixtures/bind/refused.toml | 1 + ts/fixtures/bind/refused.txt | 18 +++---- ts/fixtures/bind/src/harness.rs | 9 ++-- ts/fixtures/bind/src/raw.rs | 9 ++++ ts/fixtures/bind/ts.toml | 1 + ts/fixtures/bind/wrong.toml | 1 + ts/fixtures/bind/wrong.txt | 4 +- ts/fixtures/lang/expected/refs.ts | 64 +++++++++++++--------- ts/fixtures/lang/src/refs.rs | 11 ++++ ts/src/lower/mir/call.rs | 6 +-- ts/src/lower/mir/mod.rs | 12 ++--- ts/src/lower/mir/place.rs | 12 ++++- ts/src/lower/mir/rvalue.rs | 2 +- ts/src/lower/mod.rs | 12 +++++ 17 files changed, 165 insertions(+), 86 deletions(-) create mode 100644 ts/fixtures/bind/bind/skip.ts create mode 100644 ts/fixtures/bind/expected/bind/skip.ts diff --git a/ts/fixtures/bind/bind/skip.ts b/ts/fixtures/bind/bind/skip.ts new file mode 100644 index 000000000..a9170fa0f --- /dev/null +++ b/ts/fixtures/bind/bind/skip.ts @@ -0,0 +1,7 @@ +// `raw::skip`, which reads through a raw pointer. + +import type * as rt from "../rt.ts"; + +export function skip(bytes: rt.ByteSlice, at: rt.Place): void { + while (at.v < bytes.length && bytes.data[bytes.start + at.v] === 0) at.v++; +} diff --git a/ts/fixtures/bind/expected/bind/skip.ts b/ts/fixtures/bind/expected/bind/skip.ts new file mode 100644 index 000000000..182c90215 --- /dev/null +++ b/ts/fixtures/bind/expected/bind/skip.ts @@ -0,0 +1,8 @@ +// Generated by rust2-ts. Do not edit. +// `raw::skip`, which reads through a raw pointer. + +import type * as rt from "../rt.ts"; + +export function skip(bytes: rt.ByteSlice, at: rt.Place): void { + while (at.v < bytes.length && bytes.data[bytes.start + at.v] === 0) at.v++; +} diff --git a/ts/fixtures/bind/expected/harness.ts b/ts/fixtures/bind/expected/harness.ts index 6a8c82b93..ae33dd5bc 100644 --- a/ts/fixtures/bind/expected/harness.ts +++ b/ts/fixtures/bind/expected/harness.ts @@ -3,25 +3,26 @@ import * as rt from "./rt.ts"; import * as Bytes from "./bind/bytes.ts"; import * as checksum from "./bind/checksum.ts"; +import * as skip from "./bind/skip.ts"; import * as Tally from "./bind/tally.ts"; /** - * Split the input as `Bytes`, compare and hash the parts, and count tallies down as they - * drop. A first byte of 1 slices out of order, which panics. + * Split the input as `Bytes`, compare and hash the parts, skip its leading zeros, and + * count tallies down as they drop. A first byte of 1 slices out of order, which panics. */ export function run(input: rt.ByteSlice): rt.ByteVec { let count!: rt.Arc; let a!: Tally.Tally; let b!: Tally.Tally; let held!: Tally.Tally | undefined; - let _120!: boolean; - let _121!: boolean; - let _122!: boolean; + let _127!: boolean; + let _128!: boolean; + let _129!: boolean; let unwind: number = 0; try { - _122 = false; - _121 = false; - _120 = false; + _129 = false; + _128 = false; + _127 = false; const out: rt.ByteVec = new rt.ByteVec(); const bytes: Bytes.Bytes = Bytes.copyFromSlice(input); const mid: rt.usize = rt.usizeDiv(Bytes.len(bytes), 2); @@ -52,43 +53,46 @@ export function run(input: rt.ByteSlice): rt.ByteVec { } rt.byteVecPush(out, rt.u32Shr(sum, _65) & 0xff); } + let at: rt.usize = 0; + skip.skip(input, rt.place(() => at, (value) => at = value)); + rt.byteVecPush(out, at & 0xff); if (rt.byteSliceFirst(input) === 1) { - const _81: rt.Range = new rt.Range(mid, rt.usizeSaturatingSub(mid, 1)); - Bytes.slice(bytes, _81); + const _88: rt.Range = new rt.Range(mid, rt.usizeSaturatingSub(mid, 1)); + Bytes.slice(bytes, _88); } count = new rt.Arc(input.length as rt.u32); - unwind = 67; + unwind = 69; a = Tally.new(count); - unwind = 82; - _122 = true; + unwind = 84; + _129 = true; b = Tally.new(count); - unwind = 80; - _121 = true; + unwind = 82; + _128 = true; rt.byteVecPush(out, count.strong & 0xff); - _122 = false; + _129 = false; rt.drop(a); rt.byteVecPush(out, count.strong & 0xff); - const _104: rt.u8 = Tally.get(b) & 0xff; - rt.byteVecPush(out, _104); - unwind = 78; - _121 = false; - const _108: Tally.Tally = b; - _120 = true; - held = _108; + const _111: rt.u8 = Tally.get(b) & 0xff; + rt.byteVecPush(out, _111); + unwind = 80; + _128 = false; + const _115: Tally.Tally = b; + _127 = true; + held = _115; if (rt.byteSliceFirst(input) === 2) { - _120 = false; + _127 = false; rt.drop(held); } rt.byteVecPush(out, count.strong & 0xff); const _0: rt.ByteVec = out; - if (_120) { - unwind = 80; + if (_127) { + unwind = 82; rt.drop(held); } unwind = 0; - _120 = false; - _121 = false; - _122 = false; + _127 = false; + _128 = false; + _129 = false; rt.drop(count); return _0; } catch (e) { @@ -97,21 +101,21 @@ export function run(input: rt.ByteSlice): rt.ByteVec { if (unwind === 0) { throw e; } - if (unwind === 67) { + if (unwind === 69) { break b5; } - if (unwind === 78) { - if (_120) { + if (unwind === 80) { + if (_127) { rt.drop(held); } - } else if (unwind !== 80) { + } else if (unwind !== 82) { break b6; } - if (_121) { + if (_128) { rt.drop(b); } } - if (_122) { + if (_129) { rt.drop(a); } } diff --git a/ts/fixtures/bind/refused.toml b/ts/fixtures/bind/refused.toml index 2d7142859..d51509e97 100644 --- a/ts/fixtures/bind/refused.toml +++ b/ts/fixtures/bind/refused.toml @@ -16,6 +16,7 @@ roots = ["harness::run", "harness::refused"] "raw::Tally" = "bind/bytes.ts" "checksum" = "bind/missing.ts" "raw::checksum" = "bind/checksum.ts" +"raw::skip" = "bind/skip.ts" "raw::Held" = "bind/tally.ts" "raw::zero" = "bind/checksum.ts" "raw::value" = "bind/checksum.ts" diff --git a/ts/fixtures/bind/refused.txt b/ts/fixtures/bind/refused.txt index 282435c04..835c8c9dd 100644 --- a/ts/fixtures/bind/refused.txt +++ b/ts/fixtures/bind/refused.txt @@ -9,12 +9,12 @@ binding `raw::Tally::new`: rt/tally.ts would replace the runtime, rt.ts and rt/ binding `raw::checksum`: `checksum` binds the same item binding `std::vec::Vec`: std's type has a representation of its own reading bind/missing.ts: No such file or directory (os error 2) at fixtures/bind/src/harness.rs:25:12 -unsupported type `*const u32` at fixtures/bind/src/raw.rs:27:2 -`raw::Held` binds without drop, so it would never drop its `raw::Tally` at fixtures/bind/src/harness.rs:58:13 -a binding of `raw::value`, whose `N` one export for every instance can't recover from its arguments at fixtures/bind/src/raw.rs:56:1 -a binding of `raw::zero`, whose `T` one export for every instance can't recover from its arguments at fixtures/bind/src/raw.rs:51:1 -`raw::Held` binds without drop, so it would never drop its `raw::Tally` at fixtures/bind/src/harness.rs:58:6 -unsupported call to `std::sync::Arc::::from_raw` at fixtures/bind/src/raw.rs:46:17 -unsupported call to `std::sync::Arc::::into_raw` at fixtures/bind/src/raw.rs:33:11 -a raw pointer dereferenced at fixtures/bind/src/raw.rs:39:12 -an assignment through a reference to `bytes::Bytes` at fixtures/bind/src/harness.rs:65:2 +unsupported type `*const u32` at fixtures/bind/src/raw.rs:36:2 +`raw::Held` binds without drop, so it would never drop its `raw::Tally` at fixtures/bind/src/harness.rs:61:13 +a binding of `raw::value`, whose `N` one export for every instance can't recover from its arguments at fixtures/bind/src/raw.rs:65:1 +a binding of `raw::zero`, whose `T` one export for every instance can't recover from its arguments at fixtures/bind/src/raw.rs:60:1 +`raw::Held` binds without drop, so it would never drop its `raw::Tally` at fixtures/bind/src/harness.rs:61:6 +unsupported call to `std::sync::Arc::::from_raw` at fixtures/bind/src/raw.rs:55:17 +unsupported call to `std::sync::Arc::::into_raw` at fixtures/bind/src/raw.rs:42:11 +a raw pointer dereferenced at fixtures/bind/src/raw.rs:48:12 +an assignment through a reference to `bytes::Bytes` at fixtures/bind/src/harness.rs:68:2 diff --git a/ts/fixtures/bind/src/harness.rs b/ts/fixtures/bind/src/harness.rs index 5a6e6050a..f8bc3bbe8 100644 --- a/ts/fixtures/bind/src/harness.rs +++ b/ts/fixtures/bind/src/harness.rs @@ -4,10 +4,10 @@ use std::sync::Arc; use bytes::Bytes; -use crate::raw::{Tally, checksum}; +use crate::raw::{Tally, checksum, skip}; -/// Split the input as `Bytes`, compare and hash the parts, and count tallies down as they -/// drop. A first byte of 1 slices out of order, which panics. +/// Split the input as `Bytes`, compare and hash the parts, skip its leading zeros, and +/// count tallies down as they drop. A first byte of 1 slices out of order, which panics. pub fn run(input: &[u8]) -> Vec { let mut out = Vec::new(); let bytes = Bytes::copy_from_slice(input); @@ -26,6 +26,9 @@ pub fn run(input: &[u8]) -> Vec { for shift in [0, 8, 16, 24] { out.push((sum >> shift) as u8); } + let mut at = 0; + skip(input, &mut at); + out.push(at as u8); if input.first() == Some(&1) { let _ = bytes.slice(mid..mid.saturating_sub(1)); } diff --git a/ts/fixtures/bind/src/raw.rs b/ts/fixtures/bind/src/raw.rs index e3810bd4e..ccd408d57 100644 --- a/ts/fixtures/bind/src/raw.rs +++ b/ts/fixtures/bind/src/raw.rs @@ -22,6 +22,15 @@ pub fn checksum(bytes: &[u8]) -> u32 { sum } +/// Moves `at` past the zeros it points at, read through a raw pointer. +pub fn skip(bytes: &[u8], at: &mut usize) { + let ptr = bytes.as_ptr(); + // SAFETY: `*at` is in bounds while it is less than the length. + while *at < bytes.len() && unsafe { *ptr.add(*at) } == 0 { + *at += 1; + } +} + /// A count held by a raw pointer to its `Arc`, which drops it where Rust drops the tally. pub struct Tally { count: *const u32, diff --git a/ts/fixtures/bind/ts.toml b/ts/fixtures/bind/ts.toml index 6a2d07c53..7280781b9 100644 --- a/ts/fixtures/bind/ts.toml +++ b/ts/fixtures/bind/ts.toml @@ -4,4 +4,5 @@ roots = ["harness::run"] [bind] "bytes::Bytes" = "bind/bytes.ts" "raw::checksum" = "bind/checksum.ts" +"raw::skip" = "bind/skip.ts" "raw::Tally" = { file = "bind/tally.ts", drop = true } diff --git a/ts/fixtures/bind/wrong.toml b/ts/fixtures/bind/wrong.toml index a11a36e21..181413f09 100644 --- a/ts/fixtures/bind/wrong.toml +++ b/ts/fixtures/bind/wrong.toml @@ -6,5 +6,6 @@ roots = ["harness::run", "harness::held"] [bind] "bytes::Bytes" = "wrong/bytes.ts" "raw::checksum" = "bind/checksum.ts" +"raw::skip" = "bind/skip.ts" "raw::Tally" = { file = "wrong/tally.ts", drop = true } "raw::Held" = "wrong/held.ts" diff --git a/ts/fixtures/bind/wrong.txt b/ts/fixtures/bind/wrong.txt index 7b03b86f0..d4a0892c9 100644 --- a/ts/fixtures/bind/wrong.txt +++ b/ts/fixtures/bind/wrong.txt @@ -5,6 +5,6 @@ the binding of `bytes::Bytes::slice::>` in wrong/bytes. the binding of `::eq` in wrong/bytes.ts doesn't type-check: error TS2322: Type '(self: ByteSlice, other: string) => boolean' is not assignable to type '(a0: ByteSlice, a1: ByteSlice) => boolean'. Types of parameters 'other' and 'a1' are incompatible. Type 'ByteSlice' is not assignable to type 'string'. at bytes-1.12.1/src/bytes.rs:769:5 -the binding of `raw::Tally` in wrong/tally.ts doesn't type-check: error TS2322: Type 'Tally' is not assignable to type '"a bound value that drops must have a [Symbol.dispose]"'. at fixtures/bind/src/raw.rs:26:1 +the binding of `raw::Tally` in wrong/tally.ts doesn't type-check: error TS2322: Type 'Tally' is not assignable to type '"a bound value that drops must have a [Symbol.dispose]"'. at fixtures/bind/src/raw.rs:35:1 the binding of `raw::Held>` in wrong/held.ts doesn't type-check: error TS2322: Type 'u8 | undefined' is not assignable to type '"a bound value can't be undefined, which None is"'. - Type 'undefined' is not assignable to type '"a bound value can't be undefined, which None is"'. at fixtures/bind/src/raw.rs:61:1 + Type 'undefined' is not assignable to type '"a bound value can't be undefined, which None is"'. at fixtures/bind/src/raw.rs:70:1 diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 85f715809..fe55b46b0 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -141,9 +141,17 @@ export function derefBox(b: rt.Place, to: rt.u8): void { b.v = to; } +/** Methods that take `&self`, called through a `&mut`. */ +export function fill(seen: rt.Place, s: rt.Place, next: rt.u8): rt.u8 { + if (seen.v === undefined) { + seen.v = next; + } + return rt.u8WrappingAdd(rt.optionUnwrapOr(seen.v, 238), rt.stringLen(s.v) & 0xff); +} + export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { let _133!: rt.u8; - const _228: (a0: rt.Place, a1: rt.u8) => void = (x3: rt.Place, b7: rt.u8): void => { + const _238: (a0: rt.Place, a1: rt.u8) => void = (x3: rt.Place, b7: rt.u8): void => { bump(x3, b7); }; const by: rt.u8 = rt.optionUnwrapOr(rt.byteSliceFirst(data), 3); @@ -216,13 +224,17 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { } rt.byteVecPush(out, _133); rt.byteVecExtendFromSlice(out, rt.stringAsBytes(text)); + let empty: rt.u8 | undefined = undefined; + rt.byteVecPush(out, fill(rt.place(() => empty, (value11) => empty = value11), rt.place(() => text, (value12) => text = value12), by)); + const _148: rt.u8 = rt.u8WrappingAdd(by, 1); + rt.byteVecPush(out, fill(rt.place(() => empty, (value13) => empty = value13), rt.place(() => text, (value14) => text = value14), _148)); let at: rt.usize = 0; - const cursor: Cursor.Cursor = { at: rt.place(() => at, (value11) => at = value11), data }; + const cursor: Cursor.Cursor = { at: rt.place(() => at, (value15) => at = value15), data }; let sum: rt.u8 = 0; while (true) { - const _143: rt.u8 | undefined = Cursor.next(cursor); - if (_143 !== undefined) { - const b3: rt.u8 = _143; + const _153: rt.u8 | undefined = Cursor.next(cursor); + if (_153 !== undefined) { + const b3: rt.u8 = _153; sum = rt.u8WrappingAdd(sum, b3); if (b3 > 200) { break; @@ -234,14 +246,14 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, sum); rt.byteVecPush(out, at & 0xff); let remaining: rt.usize = rt.u8Rem(by, 5) as rt.usize; - rt.byteVecPush(out, skip(rt.place(() => remaining, (value12) => remaining = value12), data) & 0xff); + rt.byteVecPush(out, skip(rt.place(() => remaining, (value16) => remaining = value16), data) & 0xff); rt.byteVecPush(out, remaining & 0xff); - const _167: [Pair.Pair, Pair.Pair] = [{ n: 1 }, { n: 2 }]; - const a: Pair.Pair = _167[0]; - const b4: Pair.Pair = _167[1]; + const _177: [Pair.Pair, Pair.Pair] = [{ n: 1 }, { n: 2 }]; + const a: Pair.Pair = _177[0]; + const b4: Pair.Pair = _177[1]; let p: Pair.Pair = a; const borrowed = p; - const r: rt.Place = rt.place(() => borrowed.n, (value13) => borrowed.n = value13); + const r: rt.Place = rt.place(() => borrowed.n, (value17) => borrowed.n = value17); p = b4; bumpByte(r); p.n = rt.u8Add(p.n, 10); @@ -253,36 +265,36 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { bump(rt.entryOrInsertWithMut(rt.entry(tree, rt.u8Rem(b5, 3)), (): rt.u32 => { return 0; }), 1); - const _201: rt.Place | undefined = rt.hashGetMut(hash, rt.u8Rem(b5, 2)); - if (_201 !== undefined) { - bump(_201, 2); + const _211: rt.Place | undefined = rt.hashGetMut(hash, rt.u8Rem(b5, 2)); + if (_211 !== undefined) { + bump(_211, 2); } } - const _210: rt.Iter<[rt.u8, rt.u32]> = rt.hashIter(hash); - const iter5: rt.Iter<[rt.u8, rt.u32]> = rt.iterChain(rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmp) as rt.BTreeMap, _210, true)), rt.btreeIter(tree)); + const _220: rt.Iter<[rt.u8, rt.u32]> = rt.hashIter(hash); + const iter5: rt.Iter<[rt.u8, rt.u32]> = rt.iterChain(rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmp) as rt.BTreeMap, _220, true)), rt.btreeIter(tree)); while (true) { - const _217: [rt.u8, rt.u32] | rt.Done = iter5.next(); - if (_217 === rt.DONE) { + const _227: [rt.u8, rt.u32] | rt.Done = iter5.next(); + if (_227 === rt.DONE) { break; } - const k: rt.u8 = _217[0]; - const x: rt.u32 = _217[1]; + const k: rt.u8 = _227[0]; + const x: rt.u32 = _227[1]; rt.byteVecPush(out, k); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x))); } let total: rt.u32 = 0; for (const b6 of rt.byteSliceView(data)) { - _228(rt.place(() => total, (value14) => total = value14), b6); + _238(rt.place(() => total, (value18) => total = value18), b6); } rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(total))); - const _246: [rt.u32, rt.u32] = [by as rt.u32, rt.optionUnwrapOr(rt.byteSliceGet(data, 1), 5) as rt.u32]; - let x2: rt.u32 = _246[0]; - let y: rt.u32 = _246[1]; - readThrough(rt.place(() => x2, (value15) => x2 = value15), rt.place(() => y, (value16) => y = value16), out); + const _256: [rt.u32, rt.u32] = [by as rt.u32, rt.optionUnwrapOr(rt.byteSliceGet(data, 1), 5) as rt.u32]; + let x2: rt.u32 = _256[0]; + let y: rt.u32 = _256[1]; + readThrough(rt.place(() => x2, (value19) => x2 = value19), rt.place(() => y, (value20) => y = value20), out); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(x2 & 0xff, y & 0xff))); let boxed2: rt.u8 | undefined = undefined as rt.u8 | undefined; - const _267: rt.u8 = total & 0xff; - derefBox(rt.place(() => boxed2, (value17) => boxed2 = value17), _267); + const _277: rt.u8 = total & 0xff; + derefBox(rt.place(() => boxed2, (value21) => boxed2 = value21), _277); rt.byteVecPush(out, rt.optionUnwrapOr(boxed2, 238)); } diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index af8adb1e2..18632a31a 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -144,6 +144,14 @@ fn deref_box(b: &mut Box>, to: u8) { *r = Some(to); } +/// Methods that take `&self`, called through a `&mut`. +fn fill(seen: &mut Option, s: &mut String, next: u8) -> u8 { + if seen.is_none() { + *seen = Some(next); + } + seen.unwrap_or(0xee).wrapping_add(s.len() as u8) +} + pub fn refs(data: &[u8], out: &mut Vec) { let by = data.first().copied().unwrap_or(3); // A local, a field, and elements of an array and a `Vec`. @@ -196,6 +204,9 @@ pub fn refs(data: &[u8], out: &mut Vec) { Fetch::Refused => 0xff, }); out.extend_from_slice(text.as_bytes()); + let mut empty = None; + out.push(fill(&mut empty, &mut text, by)); + out.push(fill(&mut empty, &mut text, by.wrapping_add(1))); // A struct keeping a `&mut`, and one passed on in a loop. let mut at = 0; let mut cursor = Cursor { at: &mut at, data }; diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 0fa0d1539..4d5d3ebc2 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -285,9 +285,9 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { return f.call(values); } let local = self.b.t.translated(def_id, gargs); - let pointees = match local { - true => Vec::new(), - false => { + let pointees = match self.b.t.mapped(def_id, gargs) { + false => Vec::new(), + true => { if let Some(err) = self.std_places(def_id, gargs, result, span) { return err; } diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 2e70102cc..7852913a3 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -846,9 +846,9 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } - /// Whether a reference in `local` is read whole, rather than only through, or a reborrow - /// of what it points at is: passed on, kept, or captured. A `&mut` parameter of std's - /// reads through it, as its mapping takes what it points at. + /// Whether a reference in `local` is read whole, rather than only through, or a mutable + /// reborrow of what it points at is: passed on, kept, or captured. A `&mut` parameter of + /// std's reads through it, as its mapping takes what it points at. fn read_whole(&self, local: Local) -> bool { use rustc_middle::mir::visit::{PlaceContext, Visitor}; struct Reads<'a, 'tcx> { @@ -870,7 +870,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } fn visit_assign(&mut self, to: &Place<'tcx>, rvalue: &Rvalue<'tcx>, at: mir::Location) { - if let Rvalue::Ref(_, _, p) = rvalue + if let Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, p) = rvalue && p.local == self.local && let [mir::ProjectionElem::Deref] = p.projection.as_slice() && let Some(to) = to.as_local() @@ -889,7 +889,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } let tcx = self.tcx; let pointees = |func: &Operand<'tcx>, i: usize| match *func.ty(&self.mir.local_decls, tcx).kind() { - ty::FnDef(def_id, gargs) if !self.b.t.translated(def_id, self.b.subst(gargs.skip_binder())) => { + ty::FnDef(def_id, gargs) if self.b.t.mapped(def_id, self.b.subst(gargs.skip_binder())) => { let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(); let input = tcx.instantiate_bound_regions_with_erased(sig).inputs().get(i).copied(); input.is_some_and(|t| matches!(t.kind(), ty::Ref(_, _, rustc_ast::Mutability::Mut))) @@ -2083,7 +2083,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let target = match rvalue { Rvalue::Ref(_, kind, p) => match self.mut_subslice(*kind, *p, span) { Some(e) => e, - None => match self.reborrowed(*p, span, out) { + None => match self.reborrowed(*kind, *p, span, out) { Some(e) => e, // Read whole, the place is held as it is now for its `rt.Place`. None if self.points_at_place(local) && self.read_whole(local) => { diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 1253bae4a..20f7010bc 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -750,7 +750,17 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } /// The `rt.Place` of `place`, a reborrow `&mut *r` of a reference `r` that is one, which is `r`'s. - pub(super) fn reborrowed(&mut self, place: Place<'tcx>, span: Span, out: &mut Vec) -> Option { + /// A shared reborrow `&*r` is what `r` points at instead. + pub(super) fn reborrowed( + &mut self, + kind: mir::BorrowKind, + place: Place<'tcx>, + span: Span, + out: &mut Vec, + ) -> Option { + if !matches!(kind, mir::BorrowKind::Mut { .. }) { + return None; + } let [rest @ .., ProjectionElem::Deref] = place.projection.as_slice() else { return None; }; diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index a7787b3ab..d86126a9b 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -35,7 +35,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if let mir::BorrowKind::Mut { .. } = kind { let pointee = place.ty(&self.mir.local_decls, tcx).ty; if self.b.t.needs_place(pointee) { - if let Some(reborrowed) = self.reborrowed(*place, span, out) { + if let Some(reborrowed) = self.reborrowed(*kind, *place, span, out) { return Some(reborrowed); } let target = self.place_expr(*place, span, out); diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index ac8c21bfc..8e5c955f3 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -687,6 +687,18 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { } } + /// Whether a call of `def_id` with `args` runs std's mapping, which takes a `&mut` + /// parameter as what it points at, rather than the crate's function or a binding's export. + pub fn mapped(&self, def_id: DefId, args: GenericArgsRef<'tcx>) -> bool { + match Instance::try_resolve(self.tcx, self.typing_env(), def_id, args) { + Ok(Some(instance)) => { + !matches!(instance.def, InstanceKind::Item(did) if did.is_local()) + && self.bound_module(instance).is_none() + } + _ => true, + } + } + /// Whether a call of `def_id` with `args` calls a binding's export. pub fn binds(&self, def_id: DefId, args: GenericArgsRef<'tcx>) -> bool { match Instance::try_resolve(self.tcx, self.typing_env(), def_id, args) {