diff --git a/quest/m3/README.md b/quest/m3/README.md index 71c6aaa8c..ea66a11f5 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -34,7 +34,6 @@ generic std gap is planned here even when moq never calls it. - [An array as a slice](/quest/m3/ts-array-as-slice.md) - `<[T; N]>::as_slice` and `as_mut_slice` translate - [Closures that return an Option whose None is rt.None](/quest/m3/ts-option-closures.md) - `find_map`, `filter_map`, and `map_while` to `Option>` keep `None` apart from `Some(None)` - [Peekable::next_if_eq against another type](/quest/m3/ts-next-if-eq-other.md) - `next_if_eq` with an expected value of another type than the item, such as a `&str` of `String` items, translates -- [A slice's edits in place](/quest/m3/ts-slice-edits.md) - `fill`, `rotate_left`, and `copy_from_slice` of other values translate - [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does - [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it diff --git a/quest/m3/ts-slice-edits.md b/quest/m3/ts-slice-edits.md deleted file mode 100644 index 3876da13f..000000000 --- a/quest/m3/ts-slice-edits.md +++ /dev/null @@ -1,15 +0,0 @@ -# [S] A slice's edits in place - -## Goal - -rust2-ts translates a slice's `fill`, `fill_with`, `rotate_left`, and `rotate_right`, and -`copy_within`, `copy_from_slice`, and `clone_from_slice` of other than bytes, matching -std's results and panics. Proven by differential tests against native Rust. - -## Plan - -Each refuses with a span today as an unsupported call; only bytes' `copy_from_slice` and -`copy_within` map. -A mutable chunk's view takes them as an array does. - -Public API: the translator's output. diff --git a/ts/fixtures/lang/caller.ts b/ts/fixtures/lang/caller.ts index b1df5cf09..2b9853f9b 100644 --- a/ts/fixtures/lang/caller.ts +++ b/ts/fixtures/lang/caller.ts @@ -366,4 +366,16 @@ const ranges = [0, 1, 2, 3, 4].flatMap((n) => { */ const reducers = [[], [9], [9, 9], [8, 4, 12, 0x40, 0x80]].map((bytes) => Uint8Array.of(op("iters::reducers"), 0, ...bytes)); -export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...ranges, ...reducers]; +/** + * `edits` of each kind over zero to four items, at every three bounds up to one past the + * end, so parts are empty, at the end, backwards, and out of bounds. + */ +const editsSlicesOp = op("slices::edits"); +const sliceEdits = [0, 1, 2, 3, 4].flatMap((n) => + Array.from({ length: 8 * (n + 2) ** 3 }, (_, i) => { + const [kind, a, b, c] = [i % 8, Math.floor(i / 8) % (n + 2), Math.floor(i / 8 / (n + 2)) % (n + 2), Math.floor(i / 8 / (n + 2) ** 2)]; + return Uint8Array.of(editsSlicesOp, kind, a, b, c, ...[0x31, 0xc2, 0x07, 0xfe].slice(0, n)); + }), +); + +export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...ranges, ...reducers, ...sliceEdits]; diff --git a/ts/fixtures/lang/expected/core/option.ts b/ts/fixtures/lang/expected/core/option.ts index 797887210..4db5e2072 100644 --- a/ts/fixtures/lang/expected/core/option.ts +++ b/ts/fixtures/lang/expected/core/option.ts @@ -32,6 +32,7 @@ import type * as Point from "../shapes.Point.ts"; import type * as shapes_Shape from "../shapes.Shape.ts"; import { digest, digestWords } from "../slices.ts"; import type * as slices_Item from "../slices.Item.ts"; +import * as slices_Noisy from "../slices.Noisy.ts"; import type * as slices_Pair from "../slices.Pair.ts"; import type * as Short from "../splits.Short.ts"; @@ -511,6 +512,13 @@ export function mapOr$0qqbaqw(self: Noisy.Noisy | undefined, default_: rt.u8, f: return f(self); } +export function mapOr$189goit(self: slices_Noisy.Noisy | undefined, default_: rt.u8, f: (a0: slices_Noisy.Noisy) => rt.u8): rt.u8 { + if (self === undefined) { + return default_; + } + return f(self); +} + export function mapOr$0cqaybi(self: locals_Noisy.Noisy | undefined, default_: rt.u8, f: (a0: locals_Noisy.Noisy) => rt.u8): rt.u8 { if (self === undefined) { return default_; @@ -1090,6 +1098,13 @@ export function clone$0vcwlo5(self: Named.Named | undefined): Named.Named | unde return Named.clone$Clone(self); } +export function clone$1omlcob(self: slices_Noisy.Noisy | undefined): slices_Noisy.Noisy | undefined { + if (self === undefined) { + return undefined; + } + return slices_Noisy.clone$Clone(self); +} + export function clone$14nprly(self: string | undefined): string | undefined { if (self === undefined) { return undefined; diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index ec5131533..abf735a5d 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -34,7 +34,7 @@ import { orders, bytes as orders_bytes } from "./orders.ts"; import { lists, shared as pointers_shared, places, unchecked, nested as pointers_nested, copies as pointers_copies, sentinels, cells as pointers_cells, rebound, writers } from "./pointers.ts"; import { refs, toRefs } from "./refs.ts"; import { copies as shapes_copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; -import { parts, chunked, subslices, drains, ranges as slices_ranges } from "./slices.ts"; +import { parts, chunked, subslices, drains, ranges as slices_ranges, edits as slices_edits } from "./slices.ts"; import { splits } from "./splits.ts"; import { statics, cells as statics_cells, onces } from "./statics.ts"; import { strs, slices, edits as strs_edits, parses as strs_parses } from "./strs.ts"; @@ -90,7 +90,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) refs(data21, out21); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2121: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { counts(data22, out22); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _375: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _378: rt.ByteSlice, out23: rt.ByteVec): void => { rounding(out23); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2123: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); @@ -176,7 +176,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) reducers(data63, out64); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::writers", (_2164: rt.u8, data64: rt.ByteSlice, out65: rt.ByteVec): void => { writers(data64, out65); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["errors::eqs", eqs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]; + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["errors::eqs", eqs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["slices::edits", slices_edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]; } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/slices.Counted.ts b/ts/fixtures/lang/expected/slices.Counted.ts new file mode 100644 index 000000000..4dfc24ca2 --- /dev/null +++ b/ts/fixtures/lang/expected/slices.Counted.ts @@ -0,0 +1,21 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { LOG } from "./slices.ts"; + +/** + * A `Copy` element whose own `Clone` logs, which `fill` and `clone_from_slice` call and + * `copy_within` and `copy_from_slice` do not. + */ +export interface Counted { + n: rt.u8; +} + +export function clone$Clone(self: Counted): Counted { + rt.localKeyWithBorrowMut(LOG, (log: rt.ByteVec): void => { + rt.byteVecPush(log, self.n ^ 64); + }); + return self; +} + +//# sourceMappingURL=slices.Counted.ts.map diff --git a/ts/fixtures/lang/expected/slices.Noisy.ts b/ts/fixtures/lang/expected/slices.Noisy.ts new file mode 100644 index 000000000..4f69cffb8 --- /dev/null +++ b/ts/fixtures/lang/expected/slices.Noisy.ts @@ -0,0 +1,35 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { LOG } from "./slices.ts"; + +/** + * Logs its tag with the high bit set as it is cloned, into a clone one higher, and logs + * its tag as it drops. + */ +export class Noisy { + tag: rt.u8; + + constructor(tag: rt.u8) { + this.tag = tag; + } + + [Symbol.dispose](): void { + drop$Drop(this); + } +} + +export function clone$Clone(self: Noisy): Noisy { + rt.localKeyWithBorrowMut(LOG, (log: rt.ByteVec): void => { + rt.byteVecPush(log, self.tag | 128); + }); + return new Noisy(rt.u8WrappingAdd(self.tag, 1)); +} + +export function drop$Drop(self: Noisy): void { + rt.localKeyWithBorrowMut(LOG, (log: rt.ByteVec): void => { + rt.byteVecPush(log, self.tag); + }); +} + +//# sourceMappingURL=slices.Noisy.ts.map diff --git a/ts/fixtures/lang/expected/slices.ts b/ts/fixtures/lang/expected/slices.ts index 802a823bb..2891c8bc3 100644 --- a/ts/fixtures/lang/expected/slices.ts +++ b/ts/fixtures/lang/expected/slices.ts @@ -2,8 +2,10 @@ import * as rt from "./rt.ts"; import { copy$Pair$2 } from "./lib.ts"; -import { map$003seos, map$11y9s7r, map$0qyyft9, map$1wqzuhy, map$0a57co2, map$0c2keyb, map$1xk4yz1 } from "./core/option.ts"; +import { map$003seos, map$11y9s7r, map$0qyyft9, map$1wqzuhy, map$0a57co2, map$0c2keyb, map$1xk4yz1, mapOr$189goit, clone$1omlcob } from "./core/option.ts"; +import * as Counted from "./slices.Counted.ts"; import * as Item from "./slices.Item.ts"; +import * as Noisy from "./slices.Noisy.ts"; import * as Pair from "./slices.Pair.ts"; export const LOG: rt.LocalKey> = /* @__PURE__ */ new rt.LocalKey(LOG$init, false); @@ -155,29 +157,20 @@ export function scribbleWords(i: rt.usize, chunk: rt.u16[]): void { if (_22 !== undefined) { _22.v = _22.v ^ 4660; } - b1: { - if (rt.usizeRem(i, 3) === 2) { - const iter: rt.Iter> = rt.iterSliceMut(chunk); - while (true) { - const _31: rt.Place | rt.Done = iter.next(); - if (_31 === rt.DONE) { - break b1; - } - _31.v = i & 0xffff; - } - } + if (rt.usizeRem(i, 3) === 2) { + chunk.fill(i & 0xffff); } - const iter2: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.sliceChunksMut(chunk, 2)); + const iter: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.sliceChunksMut(chunk, 2)); while (true) { - const _39: [rt.usize, rt.u16[]] | rt.Done = iter2.next(); - if (_39 === rt.DONE) { + const _34: [rt.usize, rt.u16[]] | rt.Done = iter.next(); + if (_34 === rt.DONE) { break; } - const j: rt.usize = _39[0]; - rt.idx(_39[1], 0); - const _44: rt.u16 = rt.u16WrappingAdd(_39[1][0], j & 0xffff); - rt.idx(_39[1], 0); - _39[1][0] = _44; + const j: rt.usize = _34[0]; + rt.idx(_34[1], 0); + const _39: rt.u16 = rt.u16WrappingAdd(_34[1][0], j & 0xffff); + rt.idx(_34[1], 0); + _34[1][0] = _39; } } @@ -848,32 +841,25 @@ export function chunked(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void } const it23: rt.Iter = rt.sliceRchunksExactMut(words, size); it23.next(); - const iter26: rt.Iter> = rt.iterSliceMut(rt.partsRemainder(it23)); - while (true) { - const _1404: rt.Place | rt.Done = iter26.next(); - if (_1404 === rt.DONE) { - break; - } - _1404.v = 7; - } + rt.partsRemainder(it23).fill(7); rt.partsRemainder(rt.sliceRchunksExactMut(pairs, size)).reverse(); } else { const part = rt.usizeDiv(data.length, 3); - const iter27: rt.Iter<[rt.usize, rt.ByteSlice]> = rt.iterEnumerate(rt.byteSliceRchunks(rt.byteSliceRange(rt.byteVecSlice(bytes), part), size)); + const iter26: rt.Iter<[rt.usize, rt.ByteSlice]> = rt.iterEnumerate(rt.byteSliceRchunks(rt.byteSliceRange(rt.byteVecSlice(bytes), part), size)); while (true) { - const _1423: [rt.usize, rt.ByteSlice] | rt.Done = iter27.next(); - if (_1423 === rt.DONE) { + const _1418: [rt.usize, rt.ByteSlice] | rt.Done = iter26.next(); + if (_1418 === rt.DONE) { break; } - scribble(_1423[0], _1423[1]); + scribble(_1418[0], _1418[1]); } - const iter28: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.iterRev(rt.sliceChunksExactMut(words, size))); + const iter27: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.iterRev(rt.sliceChunksExactMut(words, size))); while (true) { - const _1436: [rt.usize, rt.u16[]] | rt.Done = iter28.next(); - if (_1436 === rt.DONE) { + const _1431: [rt.usize, rt.u16[]] | rt.Done = iter27.next(); + if (_1431 === rt.DONE) { break b0; } - scribbleWords(_1436[0], _1436[1]); + scribbleWords(_1431[0], _1431[1]); } } } @@ -897,24 +883,25 @@ export function pokeWords(i: rt.usize, s: rt.u16[]): void { _13.v = _13.v ^ 3855; } s.reverse(); + rt.sliceRotateLeft(s, rt.usizeDiv(n, 3)); const iter: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(s)); while (true) { - const _21: [rt.usize, rt.Place] | rt.Done = iter.next(); - if (_21 === rt.DONE) { + const _24: [rt.usize, rt.Place] | rt.Done = iter.next(); + if (_24 === rt.DONE) { break; } - const j: rt.usize = _21[0]; - const _27: rt.u16 = rt.u16WrappingMul(_21[1].v, 3); - _21[1].v = rt.u16WrappingAdd(_27, j & 0xffff); + const j: rt.usize = _24[0]; + const _30: rt.u16 = rt.u16WrappingMul(_24[1].v, 3); + _24[1].v = rt.u16WrappingAdd(_30, j & 0xffff); } if (n > 1) { rt.sliceSwap(s, 0, rt.usizeSub(n, 1)); - const _36: rt.usize = rt.usizeDiv(n, 2); - rt.idx(s, _36); - const _34: rt.u16 = rt.u16WrappingAdd(s[_36], 257); - const _41: rt.usize = rt.usizeDiv(n, 2); - rt.idx(s, _41); - s[_41] = _34; + const _39: rt.usize = rt.usizeDiv(n, 2); + rt.idx(s, _39); + const _37: rt.u16 = rt.u16WrappingAdd(s[_39], 257); + const _44: rt.usize = rt.usizeDiv(n, 2); + rt.idx(s, _44); + s[_44] = _37; } } @@ -1316,17 +1303,17 @@ export function ranges(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { let _189!: rt.u8; let _197!: rt.u8; let _207!: rt.u8; - let _293!: rt.u8; - let _302!: rt.u8; - let _311!: rt.u8; - let _350!: rt.u8; - let _358!: rt.u8; + let _287!: rt.u8; + let _296!: rt.u8; + let _305!: rt.u8; + let _344!: rt.u8; + let _352!: rt.u8; const _46: (a0: rt.u32[]) => rt.u8 = (s2: rt.u32[]): rt.u8 => { return rt.iterFold(rt.iterSlice(s2), s2.length & 0xff, (acc: rt.u8, _32: rt.u32): rt.u8 => { return rt.u8WrappingMul(acc, 31) ^ ((_32 >>> 5) & 0xff); }); }; - const _335: (a0: rt.usize, a1: rt.u8) => rt.RangeBound = (x2: rt.usize, k: rt.u8): rt.RangeBound => { + const _329: (a0: rt.usize, a1: rt.u8) => rt.RangeBound = (x2: rt.usize, k: rt.u8): rt.RangeBound => { const _42: rt.u8 = rt.u8Rem(k, 3); if (_42 === 0) { return { tag: "Included", _0: x2 } as rt.RangeBound; @@ -1518,124 +1505,115 @@ export function ranges(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteSliceView(_216).reverse(); } const _222: rt.ByteSlice | undefined = rt.byteSliceGetRange(rt.byteVecSlice(bytes), 0, b); - b26: { - if (_222 !== undefined) { - const iter2: rt.Iter> = rt.iterSliceMut(rt.byteSliceView(_222)); - while (true) { - const _231: rt.Place | rt.Done = iter2.next(); - if (_231 === rt.DONE) { - break b26; - } - _231.v = 119; - } - } + if (_222 !== undefined) { + rt.byteSliceFill(_222, 119); } - const _236: rt.u16[] | undefined = rt.sliceGetRangeMut(words, a, b); - if (_236 === undefined) { + const _230: rt.u16[] | undefined = rt.sliceGetRangeMut(words, a, b); + if (_230 === undefined) { rt.byteVecPush(out, 238); } else { - pokeWords(3, _236); - } - const _243: rt.u16[] = words; - const bounds13 = rt.sliceGetBounds({ end: b, inclusive: true }, _243.length); - const _242: rt.u16[] | undefined = rt.sliceGetRangeMut(_243, bounds13[0], bounds13[1]); - if (_242 !== undefined) { - pokeWords(4, _242); - } - const _251: Pair.Pair[] = pairs; - const bounds14 = rt.sliceGetBounds(new rt.RangeInclusive(a, b, rt.usizeStep), _251.length); - const _250: Pair.Pair[] | undefined = rt.sliceGetRangeMut(_251, bounds14[0], bounds14[1]); - if (_250 === undefined) { + pokeWords(3, _230); + } + const _237: rt.u16[] = words; + const bounds13 = rt.sliceGetBounds({ end: b, inclusive: true }, _237.length); + const _236: rt.u16[] | undefined = rt.sliceGetRangeMut(_237, bounds13[0], bounds13[1]); + if (_236 !== undefined) { + pokeWords(4, _236); + } + const _245: Pair.Pair[] = pairs; + const bounds14 = rt.sliceGetBounds(new rt.RangeInclusive(a, b, rt.usizeStep), _245.length); + const _244: Pair.Pair[] | undefined = rt.sliceGetRangeMut(_245, bounds14[0], bounds14[1]); + if (_244 === undefined) { rt.byteVecPush(out, 238); } else { - pokePairs(5, _250); + pokePairs(5, _244); } - const _256: Pair.Pair[] | undefined = rt.sliceGetRangeMut(pairs, a); - if (_256 !== undefined) { - pokePairs(6, _256); + const _250: Pair.Pair[] | undefined = rt.sliceGetRangeMut(pairs, a); + if (_250 !== undefined) { + pokePairs(6, _250); } - const _264: rt.u32[] = array; - const bounds15 = rt.sliceGetBounds(new rt.RangeInclusive(a, b, rt.usizeStep), _264.length); - const _263: rt.u32[] | undefined = rt.sliceGetRangeMut(_264, bounds15[0], bounds15[1]); - if (_263 !== undefined) { - pokeArray(_263); + const _258: rt.u32[] = array; + const bounds15 = rt.sliceGetBounds(new rt.RangeInclusive(a, b, rt.usizeStep), _258.length); + const _257: rt.u32[] | undefined = rt.sliceGetRangeMut(_258, bounds15[0], bounds15[1]); + if (_257 !== undefined) { + pokeArray(_257); } } else if (_47 === 4) { const stepped: rt.RangeInclusive = new rt.RangeInclusive(a, b, rt.usizeStep); - const iter3: rt.Iter = rt.iterTake(rt.iterBorrow(stepped), 8); - while (iter3.next() !== rt.DONE) { + const iter2: rt.Iter = rt.iterTake(rt.iterBorrow(stepped), 8); + while (iter2.next() !== rt.DONE) { } const folded: rt.RangeInclusive = new rt.RangeInclusive(a, rt.min(b, reach), rt.usizeStep); rt.iterSum(rt.iterBorrow(folded), rt.usizeAdd, 0); rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(rt.rangeInclusiveIsEmpty(stepped) ? 1 : 0, rt.rangeInclusiveIsEmpty(folded) ? 1 : 0))); - const _295: rt.u16[] = words; - const bounds6 = rt.sliceGetBounds(rt.rangeInclusiveClone(stepped), _295.length); - const _294: rt.u16[] | undefined = rt.sliceGetRange(_295, bounds6[0], bounds6[1]); - if (_294 === undefined) { - _293 = 238; + const _289: rt.u16[] = words; + const bounds6 = rt.sliceGetBounds(rt.rangeInclusiveClone(stepped), _289.length); + const _288: rt.u16[] | undefined = rt.sliceGetRange(_289, bounds6[0], bounds6[1]); + if (_288 === undefined) { + _287 = 238; } else { - _293 = digestWords(_294); - } - rt.byteVecPush(out, _293); - const _304: rt.ByteSlice = rt.byteVecSlice(bytes); - const bounds7 = rt.sliceGetBounds(rt.rangeInclusiveClone(folded), _304.length); - const _303: rt.ByteSlice | undefined = rt.byteSliceGetRange(_304, bounds7[0], bounds7[1]); - if (_303 === undefined) { - _302 = 238; + _287 = digestWords(_288); + } + rt.byteVecPush(out, _287); + const _298: rt.ByteSlice = rt.byteVecSlice(bytes); + const bounds7 = rt.sliceGetBounds(rt.rangeInclusiveClone(folded), _298.length); + const _297: rt.ByteSlice | undefined = rt.byteSliceGetRange(_298, bounds7[0], bounds7[1]); + if (_297 === undefined) { + _296 = 238; } else { - _302 = digest(_303); - } - rt.byteVecPush(out, _302); - const _313: Pair.Pair[] = pairs; - const bounds8 = rt.sliceGetBounds(rt.rangeInclusiveClone(folded), _313.length); - const _312: Pair.Pair[] | undefined = rt.sliceGetRangeMut(_313, bounds8[0], bounds8[1]); - if (_312 === undefined) { - _311 = 238; + _296 = digest(_297); + } + rt.byteVecPush(out, _296); + const _307: Pair.Pair[] = pairs; + const bounds8 = rt.sliceGetBounds(rt.rangeInclusiveClone(folded), _307.length); + const _306: Pair.Pair[] | undefined = rt.sliceGetRangeMut(_307, bounds8[0], bounds8[1]); + if (_306 === undefined) { + _305 = 238; } else { - _311 = ((p: Pair.Pair[]): rt.u8 => { + _305 = ((p: Pair.Pair[]): rt.u8 => { return digestPairs(p); - })(_312); + })(_306); } - rt.byteVecPush(out, _311); + rt.byteVecPush(out, _305); const bounds9 = rt.sliceIndexBounds(rt.rangeInclusiveClone(folded), words.length); pokeWords(7, rt.sliceRangeMut(words, bounds9[0], bounds9[1])); - const _330: rt.RangeInclusive = stepped; + const _324: rt.RangeInclusive = stepped; const slice3 = rt.byteVecSlice(bytes); - const bounds10 = rt.sliceIndexBounds(_330, slice3.length); + const bounds10 = rt.sliceIndexBounds(_324, slice3.length); rt.byteVecPush(out, digest(rt.byteSliceRange(slice3, bounds10[0], bounds10[1]))); - const _334: rt.RangeInclusive = folded; + const _328: rt.RangeInclusive = folded; const slice4 = rt.byteSliceRange(data, 2); - const bounds11 = rt.sliceIndexBounds(_334, slice4.length); + const bounds11 = rt.sliceIndexBounds(_328, slice4.length); rt.byteVecPush(out, digest(rt.byteSliceRange(slice4, bounds11[0], bounds11[1]))); } else if (_47 === 5) { const part4 = rt.byteSliceRange(data, 2).length & 0xff; - const _339: rt.RangeBound = _335(a, part4); - const _338: [rt.RangeBound, rt.RangeBound] = [_339, _335(b, rt.u8Div(kind, 8))]; - const lo: rt.RangeBound = _339; - const hi: rt.RangeBound = _338[1]; - const _352: rt.ByteSlice = rt.byteVecSlice(bytes); - const bounds = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _352.length); - const _351: rt.ByteSlice | undefined = rt.byteSliceGetRange(_352, bounds[0], bounds[1]); - if (_351 === undefined) { - _350 = 238; + const _333: rt.RangeBound = _329(a, part4); + const _332: [rt.RangeBound, rt.RangeBound] = [_333, _329(b, rt.u8Div(kind, 8))]; + const lo: rt.RangeBound = _333; + const hi: rt.RangeBound = _332[1]; + const _346: rt.ByteSlice = rt.byteVecSlice(bytes); + const bounds = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _346.length); + const _345: rt.ByteSlice | undefined = rt.byteSliceGetRange(_346, bounds[0], bounds[1]); + if (_345 === undefined) { + _344 = 238; } else { - _350 = digest(_351); - } - rt.byteVecPush(out, _350); - const _360: Pair.Pair[] = pairs; - const bounds2 = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _360.length); - const _359: Pair.Pair[] | undefined = rt.sliceGetRange(_360, bounds2[0], bounds2[1]); - if (_359 === undefined) { - _358 = 238; + _344 = digest(_345); + } + rt.byteVecPush(out, _344); + const _354: Pair.Pair[] = pairs; + const bounds2 = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _354.length); + const _353: Pair.Pair[] | undefined = rt.sliceGetRange(_354, bounds2[0], bounds2[1]); + if (_353 === undefined) { + _352 = 238; } else { - _358 = digestPairs(_359); + _352 = digestPairs(_353); } - rt.byteVecPush(out, _358); - const _366: rt.u16[] = words; - const bounds3 = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _366.length); - const _365: rt.u16[] | undefined = rt.sliceGetRangeMut(_366, bounds3[0], bounds3[1]); - if (_365 !== undefined) { - pokeWords(8, _365); + rt.byteVecPush(out, _352); + const _360: rt.u16[] = words; + const bounds3 = rt.sliceGetBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], _360.length); + const _359: rt.u16[] | undefined = rt.sliceGetRangeMut(_360, bounds3[0], bounds3[1]); + if (_359 !== undefined) { + pokeWords(8, _359); } const bounds4 = rt.sliceIndexBounds([lo, hi] as [rt.RangeBound, rt.RangeBound], pairs.length); pokePairs(9, rt.sliceRangeMut(pairs, bounds4[0], bounds4[1])); @@ -1668,74 +1646,74 @@ export function ranges(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { if (slice.length >= 1) { rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digest(new rt.ByteSlice(slice.data, slice.start, 1)), digest(new rt.ByteSlice(slice.data, slice.start + 1, slice.length - 1))))); } - const _423: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitLastChunk(rt.byteVecSlice(bytes), 4); - if (_423 !== undefined) { - rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digest(_423[0]), digest(_423[1])))); + const _417: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitLastChunk(rt.byteVecSlice(bytes), 4); + if (_417 !== undefined) { + rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digest(_417[0]), digest(_417[1])))); } - const _434: [rt.u16[], rt.u16[]] | undefined = rt.sliceSplitAtChecked(words, 0); - if (_434 !== undefined) { - rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digestWords(_434[0]), digestWords(_434[1])))); + const _428: [rt.u16[], rt.u16[]] | undefined = rt.sliceSplitAtChecked(words, 0); + if (_428 !== undefined) { + rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digestWords(_428[0]), digestWords(_428[1])))); } - const _445: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitLastChunk(pairs, 3); - if (_445 !== undefined) { - rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digestPairs(_445[0]), digestPairs(_445[1])))); + const _439: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitLastChunk(pairs, 3); + if (_439 !== undefined) { + rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(digestPairs(_439[0]), digestPairs(_439[1])))); } - const _456: [rt.u32[], rt.u32[]] | undefined = rt.sliceSplitLastChunk(array, 5); - if (_456 !== undefined) { - rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(_46(_456[0]), _46(_456[1])))); + const _450: [rt.u32[], rt.u32[]] | undefined = rt.sliceSplitLastChunk(array, 5); + if (_450 !== undefined) { + rt.iterExtendBytes(out, rt.iterSlice(Uint8Array.of(_46(_450[0]), _46(_450[1])))); } } else { - const _471: rt.ByteSlice | undefined = rt.byteSliceGetRange(rt.byteVecSlice(bytes), 0, 3); - if (_471 !== undefined) { - const _476: rt.u8 = rt.u8WrappingAdd(_471.data[_471.start + 2], 1); - _471.data[_471.start] = _476; - rt.byteSliceView(_471).reverse(); - } - const _484: rt.ByteSlice | undefined = rt.byteSliceLastChunk(rt.byteVecSlice(bytes), 1); - if (_484 !== undefined) { - _484.data[_484.start] = _484.data[_484.start] ^ 255; - } - const _491: rt.u16[] | undefined = rt.sliceGetRangeMut(words, 0, 4); - if (_491 !== undefined) { - pokeWords(10, _491); - } - const _498: rt.u16[] | undefined = rt.sliceLastChunkMut(words, 0); - if (_498 !== undefined) { - pokeWords(11, _498); - } - const _505: Pair.Pair[] | undefined = rt.sliceLastChunkMut(pairs, 3); - if (_505 !== undefined) { - pokePairs(12, _505); - _505[0].b = 9; - } - const _514: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitAtChecked(rt.byteVecSlice(bytes), 1); - if (_514 !== undefined) { - _514[0].data[_514[0].start] = _514[1].length & 0xff; - rt.byteSliceView(_514[1]).reverse(); - } - const _525: [rt.u16[], rt.u16[]] | undefined = rt.sliceSplitLastChunkMut(words, 4); - if (_525 !== undefined) { - pokeWords(13, _525[0]); - rt.sliceSwap(_525[1], 0, 3); - _525[1][1] = 43981; - } - const _536: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitAtMutChecked(pairs, 0); - if (_536 !== undefined) { - pokePairs(14, _536[0]); - pokePairs(15, _536[1]); - } - const _545: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitAtMutChecked(pairs, 2); - if (_545 !== undefined) { - rt.idx(_545[1], 0); - const swapped = _545[0][0]; - _545[0][0] = _545[1][0]; - _545[1][0] = swapped; - _545[0][1].a = 3; - } - const _562: [rt.u32[], rt.u32[]] | undefined = rt.sliceSplitLastChunkMut(array, 2); - if (_562 !== undefined) { - _562[1][1] = _562[0].length as rt.u32; - pokeArray(_562[0]); + const _465: rt.ByteSlice | undefined = rt.byteSliceGetRange(rt.byteVecSlice(bytes), 0, 3); + if (_465 !== undefined) { + const _470: rt.u8 = rt.u8WrappingAdd(_465.data[_465.start + 2], 1); + _465.data[_465.start] = _470; + rt.byteSliceView(_465).reverse(); + } + const _478: rt.ByteSlice | undefined = rt.byteSliceLastChunk(rt.byteVecSlice(bytes), 1); + if (_478 !== undefined) { + _478.data[_478.start] = _478.data[_478.start] ^ 255; + } + const _485: rt.u16[] | undefined = rt.sliceGetRangeMut(words, 0, 4); + if (_485 !== undefined) { + pokeWords(10, _485); + } + const _492: rt.u16[] | undefined = rt.sliceLastChunkMut(words, 0); + if (_492 !== undefined) { + pokeWords(11, _492); + } + const _499: Pair.Pair[] | undefined = rt.sliceLastChunkMut(pairs, 3); + if (_499 !== undefined) { + pokePairs(12, _499); + _499[0].b = 9; + } + const _508: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitAtChecked(rt.byteVecSlice(bytes), 1); + if (_508 !== undefined) { + _508[0].data[_508[0].start] = _508[1].length & 0xff; + rt.byteSliceView(_508[1]).reverse(); + } + const _519: [rt.u16[], rt.u16[]] | undefined = rt.sliceSplitLastChunkMut(words, 4); + if (_519 !== undefined) { + pokeWords(13, _519[0]); + rt.sliceSwap(_519[1], 0, 3); + _519[1][1] = 43981; + } + const _530: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitAtMutChecked(pairs, 0); + if (_530 !== undefined) { + pokePairs(14, _530[0]); + pokePairs(15, _530[1]); + } + const _539: [Pair.Pair[], Pair.Pair[]] | undefined = rt.sliceSplitAtMutChecked(pairs, 2); + if (_539 !== undefined) { + rt.idx(_539[1], 0); + const swapped = _539[0][0]; + _539[0][0] = _539[1][0]; + _539[1][0] = swapped; + _539[0][1].a = 3; + } + const _556: [rt.u32[], rt.u32[]] | undefined = rt.sliceSplitLastChunkMut(array, 2); + if (_556 !== undefined) { + _556[1][1] = _556[0].length as rt.u32; + pokeArray(_556[0]); } } rt.iterExtendBytes(out, rt.iterSlice(rt.byteVecView(bytes))); @@ -1751,4 +1729,303 @@ export function ranges(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } } +/** + * A slice's `fill`, `fill_with`, `rotate_left`, `rotate_right`, `copy_within`, + * `copy_from_slice`, and `clone_from_slice`, of bytes, other integers, objects that are + * `Copy`, a `Copy` whose `Clone` logs, values that log as they are cloned and drop, and + * options of them, on the whole slice and on mutable parts and chunks of it, at bounds + * from the first three bytes, which may be out of bounds or backwards, which panics. + */ +export function edits(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + if (data.length >= 3) { + const reach: rt.usize = rt.usizeAdd(rt.byteSliceRange(data, 3).length, 2); + const _16: [rt.usize, rt.usize, rt.usize] = [rt.usizeRem(data.data[data.start] as rt.usize, reach), rt.usizeRem(data.data[data.start + 1] as rt.usize, reach), rt.usizeRem(data.data[data.start + 2] as rt.usize, reach)]; + const a: rt.usize = _16[0]; + const b: rt.usize = _16[1]; + const c: rt.usize = _16[2]; + const size: rt.usize = rt.usizeAdd(rt.usizeRem(c, 3), 1); + const bytes: rt.ByteVec = rt.byteSliceToByteVec(rt.byteSliceRange(data, 3)); + const words: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), (_2: rt.u8): rt.u16 => { + return rt.u16Mul(_2 as rt.u16, 257); + })); + const pairs: Pair.Pair[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), (_29: rt.u8): Pair.Pair => { + const b4: rt.u8 = _29; + return { a: b4, b: rt.u16Mul(b4 as rt.u16, 3) }; + })); + const counted: Counted.Counted[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), (_211: rt.u8): Counted.Counted => { + return { n: _211 }; + })); + const items: Noisy.Noisy[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), (_212: rt.u8): Noisy.Noisy => { + return new Noisy.Noisy(_212); + })); + const array: rt.u32[] = Array.from({ length: 5 }, (): rt.u32 => { + return 0; + }); + const iter: rt.Iter<[rt.Place, rt.u8]> = rt.iterZip(rt.iterSliceMut(array), rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), true); + while (true) { + const _53: [rt.Place, rt.u8] | rt.Done = iter.next(); + if (_53 === rt.DONE) { + break; + } + _53[0].v = rt.u32Mul(_53[1] as rt.u32, 65599); + } + const _60: rt.u8 = rt.u8Rem(kind, 8); + if (_60 === 0) { + rt.byteSliceFill(rt.byteVecSlice(bytes), c & 0xff); + const part18 = a; + rt.byteSliceFill(rt.byteSliceRange(rt.byteVecSlice(bytes), part18), 90); + rt.sliceRangeMut(words, 0, b).fill(rt.u16Mul(c & 0xffff, 257)); + rt.sliceFill(pairs, { a: 1, b: 2 }, copy$Pair$2); + const _81: Pair.Pair | undefined = rt.sliceFirst(pairs); + if (_81 !== undefined) { + _81.a = 9; + } + const pair: Pair.Pair = { a: 3, b: c & 0xffff }; + rt.sliceFill(rt.sliceRangeMut(pairs, a, b), copy$Pair$2(pair), copy$Pair$2); + const _92: Pair.Pair | undefined = rt.sliceGet(pairs, rt.usizeWrappingSub(b, 1)); + if (_92 !== undefined) { + _92.b = _92.b ^ 1; + } + rt.byteVecPush(out, pair.b & 0xff); + rt.sliceFill(rt.sliceRangeMut(counted, 0, b), { n: 17 }, Counted.clone$Clone); + flush(out); + rt.sliceFill(rt.sliceRangeMut(items, a), new Noisy.Noisy(32), Noisy.clone$Clone, rt.drop); + flush(out); + rt.sliceFill(rt.sliceRangeMut(items, 0, 0), new Noisy.Noisy(48), Noisy.clone$Clone, rt.drop); + flush(out); + rt.sliceFill(items, new Noisy.Noisy(c & 0xff), Noisy.clone$Clone, rt.drop); + flush(out); + rt.sliceRangeMut(array, rt.min(a, 5)).fill(c as rt.u32); + const opts: Array = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 3))), (_224: rt.u8): Noisy.Noisy | undefined => { + return new Noisy.Noisy(_224); + })); + rt.sliceFill(rt.sliceRangeMut(opts, a), undefined as Noisy.Noisy | undefined, clone$1omlcob, rt.drop); + flush(out); + rt.sliceFill(opts, new Noisy.Noisy(64), clone$1omlcob, rt.drop); + flush(out); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(opts), (o: Noisy.Noisy | undefined): rt.u8 => { + return mapOr$189goit(o, 238, (x: Noisy.Noisy): rt.u8 => { + return x.tag; + }); + })); + rt.dropAll(opts); + } else if (_60 === 1) { + let n: rt.u8 = c & 0xff; + rt.byteSliceFillWith(rt.byteSliceRange(rt.byteVecSlice(bytes), 0, b), (): rt.u8 => { + n = rt.u8WrappingAdd(n, 3); + return n; + }); + rt.sliceFillWith(rt.sliceRangeMut(words, a), (): rt.u16 => { + n = rt.u8WrappingMul(n, 5); + return n as rt.u16; + }); + rt.sliceFillWith(pairs, (): Pair.Pair => { + n = n ^ 33; + return { a: n, b: n as rt.u16 }; + }); + rt.sliceFillWith(rt.sliceRangeMut(counted, a, b), (): Counted.Counted => { + return { n: 7 }; + }); + flush(out); + let tag: rt.u8 = 96; + rt.sliceFillWith(rt.sliceRangeMut(items, a), (): Noisy.Noisy => { + rt.localKeyWithBorrowMut(LOG, (log: rt.ByteVec): void => { + rt.byteVecPush(log, 254); + }); + tag = rt.u8Add(tag, 1); + return new Noisy.Noisy(tag); + }, rt.drop); + flush(out); + const held: Noisy.Noisy = new Noisy.Noisy(112); + const _184: Noisy.Noisy[] = items; + const captured = held; + const _186: () => Noisy.Noisy = rt.closure((): Noisy.Noisy => { + return new Noisy.Noisy(captured.tag ^ 1); + }, (): void => { + captured[Symbol.dispose](); + }); + rt.dropAfter(_186, () => rt.sliceFillWith(_184, _186, rt.drop)); + flush(out); + rt.byteVecPush(out, 153); + rt.sliceFillWith(array, (): rt.u32 => { + return 0; + }); + } else if (_60 === 2) { + rt.byteSliceRotateLeft(rt.byteVecSlice(bytes), c); + rt.sliceRotateRight(words, a); + rt.sliceRotateLeft(rt.sliceRangeMut(pairs, a), b); + rt.sliceRotateRight(counted, c); + rt.sliceRotateLeft(items, c); + flush(out); + rt.sliceRotateRight(array, c); + rt.byteSliceRotateRight(rt.byteSliceRange(rt.byteVecSlice(bytes), 0, b), a); + } else if (_60 === 3) { + const iter2: rt.Iter<[rt.usize, rt.u16[]]> = rt.iterEnumerate(rt.sliceChunksMut(words, size)); + while (true) { + const _222: [rt.usize, rt.u16[]] | rt.Done = iter2.next(); + if (_222 === rt.DONE) { + break; + } + rt.sliceRotateLeft(_222[1], rt.usizeRem(_222[0], rt.usizeAdd(_222[1].length, 1))); + } + const iter3: rt.Iter = rt.sliceChunksExactMut(pairs, size); + while (true) { + const _239: Pair.Pair[] | rt.Done = iter3.next(); + if (_239 === rt.DONE) { + break; + } + rt.sliceRotateRight(_239, 1); + } + const _246: [Noisy.Noisy[], Noisy.Noisy[]] = rt.sliceSplitAtMut(items, a); + rt.sliceRotateRight(_246[0], 0); + const n2: rt.usize = _246[1].length; + rt.sliceRotateLeft(_246[1], n2); + rt.sliceRotateRight(_246[1], rt.min(b, n2)); + flush(out); + const _258: [rt.ByteSlice, rt.ByteSlice] = rt.byteSliceSplitAt(rt.byteVecSlice(bytes), rt.min(b, rt.byteSliceRange(data, 3).length)); + rt.byteSliceRotateLeft(_258[0], _258[0].length); + rt.byteSliceRotateRight(_258[1], rt.usizeDiv(_258[1].length, 2)); + rt.sliceRotateLeft(rt.sliceRangeMut(array, 1), c); + } else if (_60 === 4) { + const part9 = a; + rt.byteSliceCopyWithin(rt.byteVecSlice(bytes), part9, b, c); + const part10 = a; + const _280: rt.u16[] = words; + rt.sliceCopyWithin(_280, part10, _280.length, c); + rt.sliceCopyWithin(pairs, 0, b, c, copy$Pair$2); + const _287: Pair.Pair | undefined = rt.sliceGet(pairs, c); + if (_287 !== undefined) { + _287.a = _287.a ^ 255; + } + const _293: Counted.Counted[] = counted; + const bounds = rt.boundsRange(new rt.RangeInclusive(a, b, rt.usizeStep), _293.length); + rt.sliceCopyWithin(_293, bounds[0], bounds[1], c); + flush(out); + const part11 = rt.min(a, 5); + const _302: rt.usize = rt.min(c, 5); + const _298: rt.u32[] = array; + rt.sliceCopyWithin(_298, part11, _298.length, _302); + const part12 = rt.usizeDiv(a, 2); + const part13 = rt.usizeDiv(b, 2); + const part: rt.u16[] = rt.sliceRangeMut(words, part12); + rt.sliceCopyWithin(part, part13, part.length, 0); + const _313: rt.ByteSlice = rt.byteVecSlice(bytes); + const bounds2 = rt.boundsRange([{ tag: "Excluded", _0: a } as rt.RangeBound, { tag: "Unbounded" } as rt.RangeBound] as [rt.RangeBound, rt.RangeBound], _313.length); + rt.byteSliceCopyWithin(_313, bounds2[0], bounds2[1], c); + } else if (_60 === 5) { + const _320: [rt.u16[], rt.u16[]] = rt.sliceSplitAtMut(words, a); + const n3: rt.usize = rt.min(_320[0].length, _320[1].length); + rt.sliceCopyFromSlice(rt.sliceRangeMut(_320[0], 0, n3), rt.sliceRange(_320[1], 0, n3)); + const _336: [Pair.Pair[], Pair.Pair[]] = rt.sliceSplitAtMut(pairs, b); + const n4: rt.usize = rt.min(_336[0].length, _336[1].length); + rt.sliceCopyFromSlice(rt.sliceRangeMut(_336[1], 0, n4), rt.sliceRange(_336[0], 0, n4), copy$Pair$2); + const _350: Pair.Pair | undefined = rt.sliceFirst(_336[0]); + if (_350 !== undefined) { + _350.b = 48879; + } + const _357: Counted.Counted[] = rt.sliceRangeMut(counted, a); + const part8 = rt.usizeSub(rt.byteSliceRange(data, 3).length, a); + rt.sliceCopyFromSlice(_357, rt.sliceRange(rt.iterToArray(rt.iterMap(new rt.Range(0, c), (n9: rt.usize): Counted.Counted => { + return { n: n9 & 0xff }; + })), 0, part8)); + flush(out); + const more: rt.u32[] = Array.from({ length: 3 }, (): rt.u32 => { + return 0; + }); + rt.sliceCopyFromSlice(more, rt.sliceRange(array, 0, 3)); + rt.sliceCopyFromSlice(rt.sliceRangeMut(array, 2), more); + const source: Pair.Pair[] = rt.vecFromElem({ a: 4, b: 5 }, c, copy$Pair$2); + rt.sliceCopyFromSlice(rt.sliceRangeMut(pairs, 0, b), source, copy$Pair$2); + } else if (_60 === 6) { + const source2: Noisy.Noisy[] = rt.iterToArray(rt.iterMap(new rt.Range(0, c), (tag3: rt.usize): Noisy.Noisy => { + return new Noisy.Noisy((tag3 & 0xff) | 80); + })); + const n5: rt.usize = rt.min(rt.byteSliceRange(data, 3).length, c); + rt.sliceCloneFromSlice(rt.sliceRangeMut(items, 0, n5), rt.sliceRange(source2, 0, n5), Noisy.clone$Clone, rt.drop); + flush(out); + const _403: [Counted.Counted[], Counted.Counted[]] = rt.sliceSplitAtMut(counted, a); + const n6: rt.usize = rt.min(_403[0].length, _403[1].length); + rt.sliceCloneFromSlice(rt.sliceRangeMut(_403[0], 0, n6), rt.sliceRange(_403[1], 0, n6), Counted.clone$Clone); + flush(out); + const _420: [Pair.Pair[], Pair.Pair[]] = rt.sliceSplitAtMut(pairs, a); + const n7: rt.usize = rt.min(_420[0].length, _420[1].length); + rt.sliceCopyFromSlice(rt.sliceRangeMut(_420[1], 0, n7), rt.sliceRange(_420[0], 0, n7), copy$Pair$2); + const _434: Pair.Pair | undefined = rt.sliceFirst(_420[0]); + if (_434 !== undefined) { + _434.b = 48879; + } + const part4 = rt.min(b, 3); + const _438: rt.u16[] = rt.sliceRangeMut(words, a); + const _442: rt.u16[] = [7, 8, 9]; + rt.sliceCopyFromSlice(_438, rt.sliceRange(_442, 0, part4)); + rt.sliceCloneFromSlice(rt.sliceRangeMut(items, a), rt.sliceRange(source2, 0, rt.min(b, c)), Noisy.clone$Clone, rt.drop); + flush(out); + rt.sliceCopyFromSlice(rt.sliceRangeMut(pairs, 0, c), [{ a: 1, b: 1 }, { a: 1, b: 1 }], copy$Pair$2); + rt.dropAll(source2); + } else { + const iter4: rt.Iter<[rt.usize, Pair.Pair[]]> = rt.iterEnumerate(rt.sliceChunksMut(pairs, size)); + while (true) { + const _467: [rt.usize, Pair.Pair[]] | rt.Done = iter4.next(); + if (_467 === rt.DONE) { + break; + } + const i2: rt.usize = _467[0]; + const _472: rt.usize = rt.usizeRem(i2, 3); + if (_472 === 0) { + rt.sliceFill(_467[1], { a: i2 & 0xff, b: 0 }, copy$Pair$2); + } else if (_472 === 1) { + const slice = _467[1]; + rt.sliceCopyWithin(slice, 1, slice.length, 0, copy$Pair$2); + } else { + rt.sliceRotateLeft(_467[1], 1); + } + } + const it: rt.Iter = rt.sliceRchunksExactMut(items, size); + const _480: [Noisy.Noisy[] | undefined, Noisy.Noisy[] | undefined] = [rt.iterToOption(it.next()), rt.iterToOption(it.next())]; + if (_480[0] !== undefined) { + if (_480[1] !== undefined) { + rt.sliceCloneFromSlice(_480[0], _480[1], Noisy.clone$Clone, rt.drop); + rt.sliceRotateRight(_480[1], 1); + rt.sliceFill(_480[1], new Noisy.Noisy(15), Noisy.clone$Clone, rt.drop); + } + } + flush(out); + const iter5: rt.Iter = rt.sliceChunksExactMut(words, size); + while (true) { + const _500: rt.u16[] | rt.Done = iter5.next(); + if (_500 === rt.DONE) { + break; + } + rt.sliceFillWith(_500, (): rt.u16 => { + return a & 0xffff; + }); + } + const _507: [Counted.Counted[], Counted.Counted[]] | undefined = rt.sliceSplitAtMutChecked(counted, 1); + if (_507 !== undefined) { + rt.sliceCopyFromSlice(_507[0], rt.sliceRange(_507[1], 0, rt.min(1, _507[1].length))); + } + flush(out); + } + flush(out); + rt.iterExtendBytes(out, rt.iterSlice(rt.byteVecView(bytes))); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(words), (_225: rt.u16): rt.u8 => { + const w: rt.u16 = _225; + return (w ^ (w >> 8)) & 0xff; + })); + rt.byteVecPush(out, digestPairs(pairs)); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(counted), (x2: Counted.Counted): rt.u8 => { + return x2.n; + })); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(items), (x3: Noisy.Noisy): rt.u8 => { + return x3.tag; + })); + rt.iterExtendBytes(out, rt.iterMap(rt.iterSlice(array), (_226: rt.u32): rt.u8 => { + const x4: rt.u32 = _226; + return ((x4 ^ (x4 >>> 13)) >>> 0) & 0xff; + })); + rt.dropAll(items); + flush(out); + } +} + //# sourceMappingURL=slices.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 3a0a53f8c..dd11a6943 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -147,6 +147,7 @@ fn cases() -> Vec<(&'static str, Case)> { ("iters::reducers", |_, data, out| iters::reducers(data, out)), ("pointers::writers", |_, data, out| pointers::writers(data, out)), ("errors::eqs", errors::eqs), + ("slices::edits", slices::edits), ] } diff --git a/ts/fixtures/lang/src/slices.rs b/ts/fixtures/lang/src/slices.rs index e414df926..d8fb7d36c 100644 --- a/ts/fixtures/lang/src/slices.rs +++ b/ts/fixtures/lang/src/slices.rs @@ -3,7 +3,8 @@ //! is written through a mutable chunk landing in the slice; and `Vec::drain` of //! each kind of range, read from both ends, dropped part way, and forgotten, of values //! that log when they drop; and a slice's parts by each kind of range and by fixed size, -//! with what is written through a mutable one landing in the slice. +//! with what is written through a mutable one landing in the slice; and a slice's edits in +//! place, of values that log as they are cloned and drop. use std::cell::RefCell; @@ -115,9 +116,7 @@ fn scribble_words(i: usize, chunk: &mut [u16]) { *w ^= 0x1234; } if i % 3 == 2 { - for w in chunk.iter_mut() { - *w = i as u16; - } + chunk.fill(i as u16); } // A chunk of a chunk writes through to the slice too. for (j, inner) in chunk.chunks_mut(2).enumerate() { @@ -249,9 +248,7 @@ pub fn chunked(kind: u8, data: &[u8], out: &mut Vec) { } let mut it = words.rchunks_exact_mut(size); it.next(); - for w in it.into_remainder() { - *w = 7; - } + it.into_remainder().fill(7); pairs.rchunks_exact_mut(size).into_remainder().reverse(); } // Chunks of a mutable slice that is itself part of the vector. @@ -280,6 +277,7 @@ fn poke_words(i: usize, s: &mut [u16]) { *w ^= 0x0f0f; } s.reverse(); + s.rotate_left(n / 3); for (j, w) in s.iter_mut().enumerate() { *w = w.wrapping_mul(3).wrapping_add(j as u16); } @@ -648,9 +646,7 @@ pub fn ranges(kind: u8, data: &[u8], out: &mut Vec) { None => out.push(0xee), } if let Some(part) = bytes.get_mut(..b) { - for x in part.iter_mut() { - *x = 0x77; - } + part.fill(0x77); } match words.get_mut(a..b) { Some(part) => poke_words(3, part), @@ -774,3 +770,249 @@ pub fn ranges(kind: u8, data: &[u8], out: &mut Vec) { out.push(digest_pairs(&pairs)); out.extend(array.iter().map(|&x| (x ^ x >> 13) as u8)); } + +/// Logs its tag with the high bit set as it is cloned, into a clone one higher, and logs +/// its tag as it drops. +struct Noisy { + tag: u8, +} + +impl Clone for Noisy { + fn clone(&self) -> Self { + LOG.with_borrow_mut(|log| log.push(self.tag | 0x80)); + Noisy { + tag: self.tag.wrapping_add(1), + } + } +} + +impl Drop for Noisy { + fn drop(&mut self) { + LOG.with_borrow_mut(|log| log.push(self.tag)); + } +} + +/// A `Copy` element whose own `Clone` logs, which `fill` and `clone_from_slice` call and +/// `copy_within` and `copy_from_slice` do not. +#[derive(Copy)] +struct Counted { + n: u8, +} + +impl Clone for Counted { + fn clone(&self) -> Self { + LOG.with_borrow_mut(|log| log.push(self.n ^ 0x40)); + *self + } +} + +/// A slice's `fill`, `fill_with`, `rotate_left`, `rotate_right`, `copy_within`, +/// `copy_from_slice`, and `clone_from_slice`, of bytes, other integers, objects that are +/// `Copy`, a `Copy` whose `Clone` logs, values that log as they are cloned and drop, and +/// options of them, on the whole slice and on mutable parts and chunks of it, at bounds +/// from the first three bytes, which may be out of bounds or backwards, which panics. +pub fn edits(kind: u8, data: &[u8], out: &mut Vec) { + let [a, b, c, data @ ..] = data else { + return; + }; + let reach = data.len() + 2; + let (a, b, c) = (*a as usize % reach, *b as usize % reach, *c as usize % reach); + let size = c % 3 + 1; + let mut bytes = data.to_vec(); + let mut words: Vec = data.iter().map(|&b| b as u16 * 257).collect(); + let mut pairs: Vec = data.iter().map(|&b| Pair { a: b, b: b as u16 * 3 }).collect(); + let mut counted: Vec = data.iter().map(|&n| Counted { n }).collect(); + let mut items: Vec = data.iter().map(|&tag| Noisy { tag }).collect(); + let mut array = [0u32; 5]; + for (x, &b) in array.iter_mut().zip(data) { + *x = b as u32 * 65599; + } + match kind % 8 { + // Each slot but the last a clone, the last the value, and each old one dropped + // after its slot's clone; an empty slice drops the value. + 0 => { + bytes.fill(c as u8); + bytes[a..].fill(0x5a); + words[..b].fill(c as u16 * 0x0101); + pairs.fill(Pair { a: 1, b: 2 }); + if let Some(p) = pairs.first_mut() { + p.a = 9; + } + // The value is the caller's, which the last slot is a copy of. + let pair = Pair { a: 3, b: c as u16 }; + pairs[a..b].fill(pair); + if let Some(p) = pairs.get_mut(b.wrapping_sub(1)) { + p.b ^= 1; + } + out.push(pair.b as u8); + counted[..b].fill(Counted { n: 0x11 }); + flush(out); + items[a..].fill(Noisy { tag: 0x20 }); + flush(out); + items[..0].fill(Noisy { tag: 0x30 }); + flush(out); + items.fill(Noisy { tag: c as u8 }); + flush(out); + array[a.min(5)..].fill(c as u32); + let mut opts: Vec> = data.iter().map(|&tag| Some(Noisy { tag })).collect(); + opts[a..].fill(None); + flush(out); + opts.fill(Some(Noisy { tag: 0x40 })); + flush(out); + out.extend(opts.iter().map(|o| o.as_ref().map_or(0xee, |x| x.tag))); + } + // In slot order, each value made before its slot's old one drops. + 1 => { + let mut n = c as u8; + bytes[..b].fill_with(|| { + n = n.wrapping_add(3); + n + }); + words[a..].fill_with(|| { + n = n.wrapping_mul(5); + n as u16 + }); + pairs.fill_with(|| { + n ^= 0x21; + Pair { a: n, b: n as u16 } + }); + counted[a..b].fill_with(|| Counted { n: 7 }); + flush(out); + let mut tag = 0x60; + items[a..].fill_with(|| { + LOG.with_borrow_mut(|log| log.push(0xfe)); + tag += 1; + Noisy { tag } + }); + flush(out); + // The function, holding a value that drops, drops once the slots are full. + let held = Noisy { tag: 0x70 }; + items.fill_with(move || { + let held = &held; + Noisy { tag: held.tag ^ 1 } + }); + flush(out); + out.push(0x99); + array.fill_with(Default::default); + } + 2 => { + bytes.rotate_left(c); + words.rotate_right(a); + pairs[a..].rotate_left(b); + counted.rotate_right(c); + items.rotate_left(c); + flush(out); + array.rotate_right(c); + bytes[..b].rotate_right(a); + } + // Rotations of chunks, halves, and nothing, by 0 and by the length. + 3 => { + for (i, chunk) in words.chunks_mut(size).enumerate() { + chunk.rotate_left(i % (chunk.len() + 1)); + } + for chunk in pairs.chunks_exact_mut(size) { + chunk.rotate_right(1); + } + let (l, r) = items.split_at_mut(a); + l.rotate_right(0); + let n = r.len(); + r.rotate_left(n); + r.rotate_right(b.min(n)); + flush(out); + let (l, r) = bytes.split_at_mut(b.min(data.len())); + l.rotate_left(l.len()); + r.rotate_right(r.len() / 2); + array[1..].rotate_left(c); + } + // Overlapping either way, and of a `Copy` object, which each copy is its own of. + 4 => { + bytes.copy_within(a..b, c); + words.copy_within(a.., c); + pairs.copy_within(..b, c); + if let Some(p) = pairs.get_mut(c) { + p.a ^= 0xff; + } + counted.copy_within(a..=b, c); + flush(out); + array.copy_within(a.min(5).., c.min(5)); + let part = &mut words[a / 2..]; + part.copy_within(b / 2.., 0); + bytes.copy_within((std::ops::Bound::Excluded(a), std::ops::Bound::Unbounded), c); + } + // Of a part of the same slice, and of another, of a length that may not match. + 5 => { + let (l, r) = words.split_at_mut(a); + let n = l.len().min(r.len()); + l[..n].copy_from_slice(&r[..n]); + let (l, r) = pairs.split_at_mut(b); + let n = l.len().min(r.len()); + r[..n].copy_from_slice(&l[..n]); + if let Some(p) = l.first_mut() { + p.b = 0xbeef; + } + let other: Vec = (0..c).map(|n| Counted { n: n as u8 }).collect(); + counted[a..].copy_from_slice(&other[..data.len() - a]); + flush(out); + let mut more = [0u32; 3]; + more.copy_from_slice(&array[..3]); + array[2..].copy_from_slice(&more); + let source = vec![Pair { a: 4, b: 5 }; c]; + pairs[..b].copy_from_slice(&source); + } + // Each slot's clone in order, each old one dropped after its clone; of a length + // that may not match, which panics before any clone. + 6 => { + let source: Vec = (0..c).map(|tag| Noisy { tag: tag as u8 | 0x50 }).collect(); + let n = data.len().min(c); + items[..n].clone_from_slice(&source[..n]); + flush(out); + let (l, r) = counted.split_at_mut(a); + let n = l.len().min(r.len()); + l[..n].clone_from_slice(&r[..n]); + flush(out); + let (l, r) = pairs.split_at_mut(a); + let n = l.len().min(r.len()); + r[..n].clone_from_slice(&l[..n]); + if let Some(p) = l.first_mut() { + p.b = 0xbeef; + } + words[a..].clone_from_slice(&[7, 8, 9][..b.min(3)]); + items[a..].clone_from_slice(&source[..b.min(c)]); + flush(out); + pairs[..c].clone_from_slice(&[Pair { a: 1, b: 1 }; 2]); + } + // Each edit on each mutable chunk, which lands in the slice. + _ => { + for (i, chunk) in pairs.chunks_mut(size).enumerate() { + match i % 3 { + 0 => chunk.fill(Pair { a: i as u8, b: 0 }), + 1 => chunk.copy_within(1.., 0), + _ => chunk.rotate_left(1), + } + } + let mut it = items.rchunks_exact_mut(size); + if let (Some(x), Some(y)) = (it.next(), it.next()) { + x.clone_from_slice(y); + y.rotate_right(1); + y.fill(Noisy { tag: 0x0f }); + } + flush(out); + for chunk in words.chunks_exact_mut(size) { + chunk.fill_with(|| a as u16); + } + if let Some((first, rest)) = counted.split_first_chunk_mut::<1>() { + first.copy_from_slice(&rest[..1.min(rest.len())]); + } + flush(out); + } + } + flush(out); + out.extend(&bytes); + out.extend(words.iter().map(|&w| (w ^ w >> 8) as u8)); + out.push(digest_pairs(&pairs)); + out.extend(counted.iter().map(|x| x.n)); + out.extend(items.iter().map(|x| x.tag)); + out.extend(array.iter().map(|&x| (x ^ x >> 13) as u8)); + drop(items); + flush(out); +} diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 5f9d143fc..2b9271e7d 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,14 +1,14 @@ # Census of `reject-fixture` -- Refusals: 122 -- Function instances: 145 +- Refusals: 123 +- Function instances: 147 - Generic functions no instance reached, lowered over their type parameters: 10 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 16 | unsupported call to `_` | fixtures/reject/src/lib.rs:21:4 | +| 15 | unsupported call to `_` | fixtures/reject/src/lib.rs:136:11 | | 8 | a raw pointer to `_` in a variable assigned again while it may point there | fixtures/reject/src/lib.rs:669:10 | | 7 | a raw pointer to `_` in `_`, which the crate may put another object in place of | fixtures/reject/src/lib.rs:661:10 | | 5 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:372:4 | @@ -20,6 +20,7 @@ | 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:110:2 | | 3 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | | 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | fixtures/reject/src/lib.rs:16:15 | +| 2 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | fixtures/reject/src/lib.rs:21:4 | | 2 | `_`, a trait object of another crate's trait, which is not supported yet | fixtures/reject/src/lib.rs:11:16 | | 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | fixtures/reject/src/lib.rs:510:23 | | 2 | a coercion to `_`, which is not supported yet | fixtures/reject/src/lib.rs:501:40 | @@ -92,23 +93,24 @@ The type or module each refused type or path belongs to. | 4 | `{closure}` | fixtures/reject/src/lib.rs:364:13 | | 3 | `Spent` | fixtures/reject/src/lib.rs:861:4 | | 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:313:2 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:355:16 | | 3 | `u8` | fixtures/reject/src/lib.rs:281:6 | | 2 | `Poll` | fixtures/reject/src/lib.rs:91:20 | +| 2 | `Reused` | fixtures/reject/src/lib.rs:21:4 | | 2 | `Scaled` | fixtures/reject/src/lib.rs:510:23 | | 2 | `dyn Scaled` | fixtures/reject/src/lib.rs:510:23 | | 2 | `dyn std::any::Any` | fixtures/reject/src/lib.rs:585:32 | | 2 | `dyn std::iter::Iterator` | fixtures/reject/src/lib.rs:11:16 | +| 2 | `slice` | fixtures/reject/src/lib.rs:21:4 | | 2 | `std::any::TypeId` | fixtures/reject/src/lib.rs:591:2 | | 2 | `std::collections::BTreeSet` | fixtures/reject/src/lib.rs:263:75 | | 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:53:13 | | 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:242:16 | | 2 | `std::iter::Map` | fixtures/reject/src/lib.rs:155:23 | | 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:190:8 | -| 2 | `std::slice` | fixtures/reject/src/lib.rs:21:4 | | 2 | `std::std` | fixtures/reject/src/lib.rs:620:11 | | 2 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:102:2 | | 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:475:17 | -| 2 | `std::vec::Vec` | fixtures/reject/src/lib.rs:355:16 | | 2 | `str` | fixtures/reject/src/lib.rs:372:4 | | 1 | `BTreeMap` | fixtures/reject/src/lib.rs:861:56 | | 1 | `Batched` | fixtures/reject/src/lib.rs:355:16 | @@ -190,6 +192,8 @@ The type or module each refused type or path belongs to. | 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `BinaryHeap::pop`, `Option` | fixtures/reject/src/lib.rs:819:7 | | 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `HashSet::get`, `Option` | fixtures/reject/src/lib.rs:258:6 | | 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::find_map`, `Option` | fixtures/reject/src/lib.rs:41:11 | +| 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::clone_from_slice`, `Reused` | fixtures/reject/src/lib.rs:331:4 | +| 1 | `_` of `_`, whose `clone_from` is its own, which is not supported yet | `slice::fill`, `Reused` | fixtures/reject/src/lib.rs:21:4 | | 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::collections::HashSet::get` | fixtures/reject/src/lib.rs:899: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:242: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:242:16 | @@ -251,11 +255,10 @@ The type or module each refused type or path belongs to. | 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:415:2 | | 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:136:11 | | 1 | unsupported call to `_` | `::is_sorted` | fixtures/reject/src/lib.rs:824:15 | +| 1 | unsupported call to `_` | `::clone_from` | fixtures/reject/src/lib.rs:979:10 | | 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:346:10 | | 1 | unsupported call to `_` | `std::any::TypeId::of` | fixtures/reject/src/lib.rs:591:17 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:190:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:331:4 | -| 1 | unsupported call to `_` | `std::slice::rotate_left` | fixtures/reject/src/lib.rs:21:4 | | 1 | unsupported call to `_` | `std::std::Layout::new` | fixtures/reject/src/lib.rs:618:15 | | 1 | unsupported call to `_` | `std::std::alloc` | fixtures/reject/src/lib.rs:620:11 | | 1 | unsupported call to `_` | `std::std::dealloc` | fixtures/reject/src/lib.rs:623:3 | @@ -265,12 +268,10 @@ The type or module each refused type or path belongs to. ## Spans -
unsupported call to `_` (16) +
unsupported call to `_` (15) -- fixtures/reject/src/lib.rs:21:4: unsupported call to `core::slice::::rotate_left` - fixtures/reject/src/lib.rs:136:11: unsupported call to ` as std::iter::Iterator>::cycle` - fixtures/reject/src/lib.rs:190:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:331:4: unsupported call to `core::slice::::copy_within::>` - fixtures/reject/src/lib.rs:346:10: unsupported call to `::hash::` - fixtures/reject/src/lib.rs:389:2: unsupported call to ` as std::ops::Deref>::deref` - fixtures/reject/src/lib.rs:415:2: unsupported call to ` as std::cmp::PartialEq>::eq` @@ -283,6 +284,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:620:11: unsupported call to `std::alloc::alloc` - fixtures/reject/src/lib.rs:623:3: unsupported call to `std::alloc::dealloc` - fixtures/reject/src/lib.rs:824:15: unsupported call to ` as std::iter::Iterator>::is_sorted` +- fixtures/reject/src/lib.rs:979:10: unsupported call to ` as std::clone::Clone>::clone_from`
@@ -385,6 +387,13 @@ The type or module each refused type or path belongs to.
+
`_` of `_`, whose `clone_from` is its own, which is not supported yet (2) + +- fixtures/reject/src/lib.rs:21:4: `slice::fill` of `Reused`, whose `clone_from` is its own, which is not supported yet +- fixtures/reject/src/lib.rs:331:4: `slice::clone_from_slice` of `Reused`, whose `clone_from` is its own, which is not supported yet + +
+
`_`, a trait object of another crate's trait, which is not supported yet (2) - fixtures/reject/src/lib.rs:11:16: `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index ee8045a3a..79f61d767 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -11,7 +11,7 @@ unsupported type `f32` at fixtures/reject/src/lib.rs:7:25 `dyn std::iter::Iterator`, a trait object of another crate's trait, which is not supported yet at fixtures/reject/src/lib.rs:12:4 `Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:17:2 `Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:16:15 -unsupported call to `core::slice::::rotate_left` at fixtures/reject/src/lib.rs:21:4 +`slice::fill` of `Reused`, whose `clone_from` is its own, which is not supported yet at fixtures/reject/src/lib.rs:21:4 `Iterator::find_map` of `Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:41:11 `Maybe<()>` is not supported: its field `value` is `Option`, typed `T | undefined`, whose `None` would be `rt.None` as `Option<()>` at fixtures/reject/src/lib.rs:31:2 collecting `Option<()>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:36:43 @@ -41,7 +41,7 @@ a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs: hashing `std::collections::BTreeSet` as a key, which is not supported yet at fixtures/reject/src/lib.rs:263:75 comparing `std::collections::BTreeSet` as a key, which is not supported yet at fixtures/reject/src/lib.rs:263:75 `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:281:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:331:4 +`slice::clone_from_slice` of `Reused`, whose `clone_from` is its own, which is not supported yet at fixtures/reject/src/lib.rs:331:4 a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:336:2 a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:377:2 a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:379:27 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 8ba247148..689702dd2 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -17,8 +17,8 @@ pub fn nested(x: Option>>) -> bool { x.is_some() } -pub fn rotated(v: &mut [u8]) { - v.rotate_left(1); +pub fn refilled(v: &mut [Reused], r: Reused) { + v.fill(r); } /// A generic type's `Option` is `T | undefined`, which can't hold `rt.None`, the `None` @@ -326,9 +326,9 @@ pub fn passed(map: &mut std::collections::HashMap) -> u8 { }) } -/// JS's `copyWithin` would share each tuple, which Rust copies. -pub fn shifted(v: &mut [(u8, u8)]) { - v.copy_within(0..1, 1); +/// `clone_from_slice` calls `Reused`'s own `clone_from` for each element. +pub fn recloned(v: &mut [Reused], w: &[Reused]) { + v.clone_from_slice(w); } /// An `Arc`'s bytes would need a `ByteSlice` made inside it. @@ -966,3 +966,16 @@ pub fn closure_replaced(n: u32) -> u32 { resetter(whole)(); unsafe { (*p).0 } } + +/// A `clone_from` of its own, which `fill` calls for each slot but the last. +pub struct Reused(Vec); + +impl Clone for Reused { + fn clone(&self) -> Self { + Reused(self.0.clone()) + } + + fn clone_from(&mut self, source: &Self) { + self.0.clone_from(&source.0); + } +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 238b6068f..4b580f3a1 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -3,7 +3,7 @@ roots = [ "float", "dynamic", "nested", - "rotated", + "refilled", "iterators", "generic_unit", "collected", @@ -36,7 +36,7 @@ roots = [ "set_keys", "borrowed", "raw_keys", - "shifted", + "recloned", "shared", "cow_matched", "cow_borrowed", diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index 186d66278..bb8f8f15c 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -465,6 +465,91 @@ export function sliceSwap(s: T[], a: number, b: number): void { s[b] = x; } +/** + * `fill`: a clone of `value` into each slot but the last, each old element dropped once + * its slot's clone is made, then `value` itself into the last, or `value` dropped if there + * is none. `clone` is `undefined` where a clone is the value. + */ +export function sliceFill(s: T[], value: T, clone: ((value: T) => T) | undefined, drop?: (item: T) => void): void { + const last = s.length - 1; + if (last < 0) return drop?.(value); + for (let i = 0; i < last; i++) { + const item = clone === undefined ? value : clone(value); + drop?.(s[i]); + s[i] = item; + } + drop?.(s[last]); + s[last] = value; +} + +/** `fill_with`: `f()` into each slot in order, each old element dropped once its slot's value is made. */ +export function sliceFillWith(s: T[], f: () => T, drop?: (item: T) => void): void { + for (let i = 0; i < s.length; i++) { + const item = f(); + drop?.(s[i]); + s[i] = item; + } +} + +/** `rotate_left`, panicking past the length. */ +export function sliceRotateLeft(s: T[], mid: number): void { + if (mid > s.length) panic("assertion failed: mid <= self.len()"); + rotate(s, mid); +} + +/** `rotate_right`, panicking past the length. */ +export function sliceRotateRight(s: T[], k: number): void { + if (k > s.length) panic("assertion failed: k <= self.len()"); + rotate(s, s.length - k); +} + +/** The elements from `mid` on, then those before it, in place. */ +function rotate(s: T[], mid: number): void { + if (mid === 0 || mid === s.length) return; + const head = s.slice(0, mid); + s.copyWithin(0, mid); + for (let i = 0; i < mid; i++) s[s.length - mid + i] = head[i]; +} + +/** `copy_within`: `s[start..end]` copied to index `dest`, panicking out of bounds; `copy` is `undefined` where a copy is the value. */ +export function sliceCopyWithin(s: T[], start: number, end: number, dest: number, copy?: (value: T) => T): void { + copyWithinCheck(s.length, start, end, dest); + if (copy === undefined) { + s.copyWithin(dest, start, end); + return; + } + const items = s.slice(start, end); + for (let i = 0; i < items.length; i++) s[dest + i] = copy(items[i]); +} + +/** `copy_within`'s checks of `start..end` and `dest` in `length` elements. */ +function copyWithinCheck(length: number, start: number, end: number, dest: number): void { + // `slice::range` checks the end first, then `range` reports the rest. + if (end > length) panic(`range end index ${end} out of range for slice of length ${length}`); + rangeCheck(length, start, end); + if (dest > length - (end - start)) panic("dest is out of bounds"); +} + +/** `copy_from_slice`, and `clone_from_slice` of a `TrivialClone`, panicking if the lengths differ; `copy` as `sliceCopyWithin`'s. */ +export function sliceCopyFromSlice(dst: T[], src: ArrayLike, copy?: (value: T) => T): void { + if (dst.length !== src.length) copyLengthFail(dst.length, src.length); + for (let i = 0; i < src.length; i++) dst[i] = copy === undefined ? src[i] : copy(src[i]); +} + +/** `clone_from_slice`: each slot's clone in order, each old element dropped once its slot's clone is made, panicking first if the lengths differ. */ +export function sliceCloneFromSlice(dst: T[], src: ArrayLike, clone: ((value: T) => T) | undefined, drop?: (item: T) => void): void { + if (dst.length !== src.length) panic("destination and source slices have different lengths"); + for (let i = 0; i < src.length; i++) { + const item = clone === undefined ? src[i] : clone(src[i]); + drop?.(dst[i]); + dst[i] = item; + } +} + +function copyLengthFail(dst: number, src: number): never { + panic(`copy_from_slice: source slice length (${src}) does not match destination slice length (${dst})`); +} + /** `sort_by` and `sort_unstable_by`: by `cmp`, whether it orders `Less`, as `sliceSort` sorts. */ export function sliceSortBy(s: { [i: number]: T; length: number }, cmp: (a: T, b: T) => Ordering): void { sliceSort(s, (a, b) => cmp(a, b) === -1); @@ -764,21 +849,45 @@ export function copyBytes(dst: Uint8Array, at: number, src: Uint8Array, start: n /** `copy_from_slice`, panicking if the lengths differ. */ export function byteSliceCopyFromSlice(dst: ByteSlice, src: ByteSlice): void { - if (dst.length !== src.length) { - panic(`copy_from_slice: source slice length (${src.length}) does not match destination slice length (${dst.length})`); - } + if (dst.length !== src.length) copyLengthFail(dst.length, src.length); copyBytes(dst.data, dst.start, src.data, src.start, src.length); } /** `copy_within`: `s[start..end]` copied to index `dest`, panicking out of bounds. */ export function byteSliceCopyWithin(s: ByteSlice, start: number, end: number, dest: number): void { - // `slice::range` checks the end first, then `range` reports the rest. - if (end > s.length) panic(`range end index ${end} out of range for slice of length ${s.length}`); - rangeCheck(s.length, start, end); - if (dest > s.length - (end - start)) panic("dest is out of bounds"); + copyWithinCheck(s.length, start, end, dest); s.data.copyWithin(s.start + dest, s.start + start, s.start + end); } +/** `fill` of bytes. */ +export function byteSliceFill(s: ByteSlice, value: number): void { + s.data.fill(value, s.start, s.start + s.length); +} + +/** `fill_with` of bytes: `f()` into each in order. */ +export function byteSliceFillWith(s: ByteSlice, f: () => number): void { + for (let i = 0; i < s.length; i++) s.data[s.start + i] = f(); +} + +/** `rotate_left` of bytes, panicking past the length. */ +export function byteSliceRotateLeft(s: ByteSlice, mid: number): void { + if (mid > s.length) panic("assertion failed: mid <= self.len()"); + byteRotate(s, mid); +} + +/** `rotate_right` of bytes, panicking past the length. */ +export function byteSliceRotateRight(s: ByteSlice, k: number): void { + if (k > s.length) panic("assertion failed: k <= self.len()"); + byteRotate(s, s.length - k); +} + +/** The bytes from `mid` on, then those before it, in place. */ +function byteRotate(s: ByteSlice, mid: number): void { + const head = s.data.slice(s.start, s.start + mid); + s.data.copyWithin(s.start, s.start + mid, s.start + s.length); + s.data.set(head, s.start + s.length - mid); +} + /** `to_vec` of bytes. */ export function byteSliceToByteVec(s: ByteSlice): ByteVec { const v = new ByteVec(s.length); diff --git a/ts/src/census.rs b/ts/src/census.rs index 9b58070d6..d261fc5e2 100644 --- a/ts/src/census.rs +++ b/ts/src/census.rs @@ -169,6 +169,7 @@ const VERBATIM: &[&str] = &[ "become", "bool", "break", + "clone_from", "collect", "copy_nonoverlapping", "dyn Future", diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 2ecd5a8cc..1a7df8874 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -723,6 +723,9 @@ fn discards(owner: &str, name: &str) -> Option<&'static [usize]> { // `Vec` drops each element `retain` rejects, `dedup` removes, and `truncate` and // `clear` cut. ("Vec", "retain" | "retain_mut" | "dedup" | "dedup_by" | "dedup_by_key" | "truncate" | "clear") => &[0], + // A slice's `fill`, `fill_with`, and `clone_from_slice` drop each element they write + // over, and `fill` its value if there is no slot for it. + ("slice", "fill" | "fill_with" | "clone_from_slice") => &[0], // `get_or_init::` drops its function uncalled if the cell is set. ("OnceCell" | "OnceLock", "get_or_init") => &[1], ("Once", "call_once" | "call_once_force") => &[0], @@ -1485,7 +1488,44 @@ fn mapping<'tcx>( false => Expr::Array(vec![value]), } } - ("slice", "copy_from_slice") if is_u8(targ(gargs, 0)) => rt2(args, "byteSlice", "copyFromSlice"), + // Each slot but the last a clone, as `clone_from` makes it, and the last the value; + // a `TrivialClone`'s copies, as std specializes `fill` to. + ("slice", "fill") => { + let elem = targ(gargs, 0); + if is_u8(elem) { + return Some(rt2(args, "byteSlice", "fill")); + } + let clone = clone_into(b, elem, &name, span); + let mut values = args; + // A value its own clone, which nothing drops, is JS's `fill`. + if matches!(&clone, Expr::Lit(l) if l == "undefined") && !b.t.drops(elem) { + let slice = values.remove(0); + return Some(slice.method("fill", values)); + } + values.push(clone); + Expr::rt("sliceFill", values) + } + ("slice", "fill_with" | "rotate_left" | "rotate_right") => match is_u8(targ(gargs, 0)) { + true => rt2(args, "byteSlice", &super::camel(&name)), + false => rt2(args, "slice", &super::camel(&name)), + }, + // A `TrivialClone`'s `clone_from_slice` is std's `copy_from_slice`, panics included. + ("slice", "copy_from_slice" | "clone_from_slice") + if name == "copy_from_slice" || super::iter::implements(b.t, targ(gargs, 0), "TrivialClone") => + { + let elem = targ(gargs, 0); + if is_u8(elem) { + return Some(rt2(args, "byteSlice", "copyFromSlice")); + } + let mut values = args; + values.extend(b.t.copy_fn(elem, span)); + Expr::rt("sliceCopyFromSlice", values) + } + ("slice", "clone_from_slice") => { + let mut values = args; + values.push(clone_into(b, targ(gargs, 0), &name, span)); + Expr::rt("sliceCloneFromSlice", values) + } ("PartialEq", "eq") if byte_slice(targ(gargs, 0)) && byte_slice(targ(gargs, 1)) => { Expr::rt("byteSliceEq", args) } @@ -1978,6 +2018,43 @@ fn owned<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, ty: Ty<'tcx>, span: Span } } +/// What clones an `elem` into a slot of a slice, as `fill` and `clone_from_slice` do by +/// `clone_from`: a copy for a `TrivialClone`, or else `clone_fn`, where `clone_from` does +/// as `*self = source.clone()` does. Refused for any other `clone_from`. +fn clone_into<'tcx>(b: &mut Body<'_, '_, 'tcx>, elem: Ty<'tcx>, name: &str, span: Span) -> Expr { + if super::iter::implements(b.t, elem, "TrivialClone") { + return b.t.copy_fn(elem, span).unwrap_or_else(Expr::undefined); + } + if !clone_from_clones(b.t, elem) { + return b.err( + span, + format!("`slice::{name}` of `{elem}`, whose `clone_from` is its own, which is not supported yet"), + ); + } + super::collections::clone_fn(b, elem, span) +} + +/// Whether `clone_from` of `ty` clones, and drops what it writes over, as +/// `*self = source.clone()` would: `Clone`'s own, and std's own over such types, where it +/// only reuses memory, if nothing drops or it is an `Option`'s. +fn clone_from_clones<'tcx>(t: &mut Translator<'_, 'tcx>, ty: Ty<'tcx>) -> bool { + let tcx = t.tcx; + let clone_from = super::collections::trait_fn(tcx, "Clone", "clone_from"); + let resolved = Instance::try_resolve(tcx, t.typing_env_pub(), clone_from, tcx.mk_args(&[ty.into()])); + let Some(instance) = resolved.ok().flatten() else { + return false; + }; + if instance.def_id() == clone_from { + return true; + } + let inner: Vec> = match ty.kind() { + ty::Adt(adt, args) if is_std(tcx, adt.did()) => args.types().collect(), + ty::Array(elem, _) => vec![*elem], + _ => return false, + }; + (t.std_of(ty) == Some(Std::Option) || !t.drops(ty)) && inner.into_iter().all(|arg| clone_from_clones(t, arg)) +} + /// A clone of `value`, a slice, array, or `Vec` of `elem` other than bytes, as a `Vec`: a /// copy of the array if each element's clone is itself, or else each element cloned. fn vec_clone<'tcx>(b: &mut Body<'_, '_, 'tcx>, value: Expr, elem: Ty<'tcx>, span: Span) -> Option { diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index e22b37599..41da6506d 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -771,14 +771,38 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let b = self.operand(&args[0].node, span, out); done(Expr::rt("bytesSliceToInclusive", vec![b, end]), true) } - // Of bytes only: JS's `copyWithin` would share a `Copy` aggregate Rust copies. - ("slice", "copy_within") if targ(0).is_some_and(|t| matches!(t.kind(), ty::Uint(ty::UintTy::U8))) => { + // A range's bounds taken apart where it is made, or any other's checked as + // `slice::range` checks them. A `Copy` aggregate is copied, which JS's + // `copyWithin` would share. + ("slice", "copy_within") => { + let elem = targ(0)?; let s = self.operand(&args[0].node, span, out); let s = self.path(s, "slice", out); - let (start, end) = self.range_bounds(&args[1].node, targ(1)?, span, out)?; - let end = end.unwrap_or_else(|| s.clone().member("length")); + let (start, end) = match self.range_bounds(&args[1].node, targ(1)?, span, out) { + Some((start, end)) => (start, end.unwrap_or_else(|| s.clone().member("length"))), + None => { + let range = self.operand(&args[1].node, span, out); + let call = library::Call { + def_id, + args: gargs, + span, + }; + let range = crate::lower::collections::bounds(self.b, &call, range); + let checked = Expr::rt("boundsRange", vec![range, s.clone().member("length")]); + let pair = self.path(checked, "bounds", out); + (pair.clone().index(Expr::lit("0")), pair.index(Expr::lit("1"))) + } + }; let dest = self.operand(&args[2].node, span, out); - done(Expr::rt("byteSliceCopyWithin", vec![s, start, end, dest]), true) + let mut values = vec![s, start, end, dest]; + let f = match elem.kind() { + ty::Uint(ty::UintTy::U8) => "byteSliceCopyWithin", + _ => { + values.extend(self.b.t.copy_fn(elem, span)); + "sliceCopyWithin" + } + }; + done(Expr::rt(f, values), true) } // An integer from an array of bytes made in place: its bytes shifted, no array made. (int, "from_be_bytes") if let Some(int) = int_named(int) => {