From 4f089ef48304bf754dcc289600aeaaa45f527152 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:22:36 -0700 Subject: [PATCH 1/9] chore(quest): claim quest/m3/ts-mut-ref.md Quest-Claim: 819f8d49541ee7e7 From e629e3174d5b00211537f8d9454337e775c9fd5e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:19:07 -0700 Subject: [PATCH 2/9] feat(ts): translate a &mut to a reference as an rt.Place Co-Authored-By: Claude Opus 5.5 --- ts/README.md | 10 +- ts/fixtures/lang/expected/harness.ts | 100 +- ts/fixtures/lang/expected/pointers.ts | 6 +- ts/fixtures/lang/expected/refs.Pair.ts | 20 + ts/fixtures/lang/expected/refs.Reader.ts | 14 + ts/fixtures/lang/expected/refs.ts | 212 +++- ts/fixtures/lang/src/harness.rs | 1 + ts/fixtures/lang/src/refs.rs | 175 ++++ ts/fixtures/reject/census.md | 13 +- ts/fixtures/reject/expected.txt | 1 + ts/fixtures/reject/src/lib.rs | 24 + ts/fixtures/reject/ts.toml | 1 + ts/fixtures/stock/expected/buf.Pieces.ts | 174 +++- ts/fixtures/stock/expected/buf.Provided.ts | 333 +++++++ ts/fixtures/stock/expected/buf.ts | 391 +++++++- .../stock/expected/bytes/buf/buf_impl.ts | 920 +++++++++++++++++- .../stock/expected/bytes/buf/buf_mut.ts | 597 ++++++++++++ ts/fixtures/stock/src/buf.rs | 63 +- ts/fixtures/task/expected/drops/objects.ts | 6 +- ts/fixtures/task/expected/futures.ts | 8 +- ts/runtime/rt/bytes.ts | 44 + ts/src/census.rs | 1 + ts/src/lower/iter.rs | 20 +- ts/src/lower/mir/call.rs | 26 +- ts/src/lower/mir/mod.rs | 21 +- ts/src/lower/mod.rs | 18 +- ts/src/lower/stock.rs | 96 +- ts/src/lower/task.rs | 12 +- ts/src/ts.rs | 9 + 29 files changed, 3160 insertions(+), 156 deletions(-) create mode 100644 ts/fixtures/lang/expected/refs.Reader.ts create mode 100644 ts/fixtures/stock/expected/buf.Provided.ts create mode 100644 ts/fixtures/stock/expected/bytes/buf/buf_mut.ts diff --git a/ts/README.md b/ts/README.md index 2bd2e4054..afdb1d50d 100644 --- a/ts/README.md +++ b/ts/README.md @@ -86,7 +86,7 @@ crate translation reaches is refused, and so are two versions of one crate it re | `Result` | `rt.Result`: `{ ok: true, value }` or `{ ok: false, error }`; `rt.OK` or `rt.ERR` where the payload is `undefined`, as in `Ok(())` | | `ControlFlow` | `rt.Result`, `Ok` to continue; what `?` branches on is the value it was applied to, but for a `Poll`'s `Pending` and `Ready(None)`, which continue as `Ok` of themselves | | tuple, `[T; N]`, `&[T]`, `Vec` | an array; for bytes, `Uint8Array` for `[u8; N]`, `rt.ByteSlice` for `&[u8]` and `&[u8; N]`, and `rt.ByteVec` for `Vec` | -| `&T`, `&mut T`, `Box`, `Reverse`, `NonZero` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a `String`, or to an `Arc` or a `Waker`, is an `rt.Place` | +| `&T`, `&mut T`, `Box`, `Reverse`, `NonZero` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, a `String`, or a reference, or to an `Arc` or a `Waker`, is an `rt.Place` | | `*const T`, `*mut T`, `NonNull` | what a `&mut T` is: the object, or an `rt.Place` to a value JS copies and to a library type such as a `Vec` or an `Arc`; `rt.NULL` for null and `rt.DANGLING` for dangling. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there; a read copies what the crate writes into in place | | `MaybeUninit` | `T`: `undefined` until written, or an object whose parts kept as objects are there, holding `undefined` | | `union` | an object of slots named by offset, `at0` and `at8`, each holding the field part kept there; fields must overlap in the same type, or in a non-null pointer and an `Option` of it | @@ -340,9 +340,11 @@ of them: `put_` of an integer or `f64`, `put_slice`, `put_bytes`, and `put`, whose panics are `bytes`'. `put` of the crate's own `Buf` into a `Vec` reads it through its methods as `bytes` does, and into a `BytesMut` is refused, as `bytes` picks those methods by its - capacity. - The rest of `bytes`, such as the provided methods of the crate's own `Buf` and the impls - forwarding through a `&mut` or a `Box`, translates from its MIR, refused where that is. + capacity. The provided `copy_to_bytes` of the crate's own `Buf`, whose `BytesMut` has + the capacity it asks for, reads it chunk by chunk through its methods. + The rest of `bytes`, such as the other provided methods of the crate's own `Buf` and the + impls forwarding through a `&mut` or a `Box`, translates from its MIR, refused where + that is. - `rand::rng()` is an `rt.ThreadRng`, whose `random` of an integer or `bool` and `random_range` of an integer range map to `rt/rand.ts`. Each value comes from `crypto.getRandomValues`, uniform as `rand`'s are, though no seed reproduces them, as diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index e05388b78..c042e9eff 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -29,7 +29,7 @@ import { locks, relock, rwlocks } from "./locks.ts"; import { nested } from "./nested.ts"; import { objects } from "./objects.ts"; import { lists, shared as pointers_shared, places, unchecked, nested as pointers_nested, copies, sentinels } from "./pointers.ts"; -import { refs } from "./refs.ts"; +import { refs, toRefs } from "./refs.ts"; import { copies as shapes_copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { splits } from "./splits.ts"; import { statics } from "./statics.ts"; @@ -42,101 +42,103 @@ import { wrappers } from "./wrappers.ts"; * case added at the end moves no other. */ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void][] { - return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_276: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { + return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_279: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { convert(data, out); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_277: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_280: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { shapes_copies(data2, out2); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_278: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_281: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { loops(data3, out3); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_279: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_282: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { patterns(data4, out4); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_280: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_283: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { closures(data5, out5); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_281: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_284: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { discriminants(data6, out6); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_282: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_285: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { library(data7, out7); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_283: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_286: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { strings(data8, out8); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_284: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_287: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { derived(data9, out9); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_285: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_288: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { written(data10, out10); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_286: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_289: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { methods(data11, out11); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_287: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_290: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { ranges(data12, out12); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_288: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_291: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { options(data13, out13); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_289: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_292: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { own(data14, out14); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_290: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_293: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { values(data15, out15); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_291: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_294: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { order(data16, out16); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_292: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_295: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { deques(data17, out17); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_293: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_296: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { flows(data18, out18); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_294: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_297: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { vecs(data19, out19); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_295: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_298: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { stores(data20, out20); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_296: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_299: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { refs(data21, out21); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_297: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2100: 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", (_298: rt.u8, _310: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2101: rt.u8, _310: 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", (_299: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { + }] 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", (_2102: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2100: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2103: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { shared(data24, out25); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2101: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2104: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { locks(data25, out26); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2102: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2105: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { relock(data26, out27); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2103: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2106: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { locals(data27, out28); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2104: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2107: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { statics(data28, out29); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2105: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2108: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { rwlocks(data29, out30); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2106: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2109: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { borrows(data30, out31); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2107: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2110: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { defaults(data31, out32); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2108: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2111: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { arcs(data32, out33); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2109: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2112: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { rcs(data33, out34); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2110: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2113: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { cyclicArcs(data34, out35); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2111: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2114: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { cyclicRcs(data35, out36); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2112: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2115: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { anys(data36, out37); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2113: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2116: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { fns(data37, out38); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2114: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2117: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { copies(data38, out39); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2115: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2118: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { lists(data39, out40); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2116: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2119: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { pointers_nested(data40, out41); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2117: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2120: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { places(data41, out42); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2118: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2121: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { sentinels(data42, out43); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2119: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2122: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { pointers_shared(data43, out44); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2120: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2123: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { unchecked(data44, out45); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2121: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2124: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { fromFns(data45, out46); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2122: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2125: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { objects(data46, out47); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::to_refs", (_2126: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { + toRefs(data47, out48); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/pointers.ts b/ts/fixtures/lang/expected/pointers.ts index df581e9e7..9d20d0574 100644 --- a/ts/fixtures/lang/expected/pointers.ts +++ b/ts/fixtures/lang/expected/pointers.ts @@ -211,7 +211,7 @@ export function unchecked(data: rt.ByteSlice, out: rt.ByteVec): void { uninit.v = 7; uninit; const held: rt.Arc = new rt.Arc(0); - let dropped: rt.Arc = rt.arcClone(held); + const dropped: rt.Arc = rt.arcClone(held); for (const byte of rt.byteSliceView(data)) { const at: rt.usize = rt.u8Rem(byte, 4) as rt.usize; const _23: rt.u32[] = counts; @@ -227,7 +227,7 @@ export function unchecked(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, boxed.v & 0xff); rt.byteVecPush(out, slot & 0xff); rt.byteVecPush(out, held.strong & 0xff); - rt.place(() => dropped, (value3) => dropped = value3).v[Symbol.dispose](); + dropped[Symbol.dispose](); rt.byteVecPush(out, held.strong & 0xff); held[Symbol.dispose](); } @@ -244,7 +244,7 @@ export function nested(data: rt.ByteSlice, out: rt.ByteVec): void { const pair: [rt.u32, rt.u32] = _8[1]; rt.ptrWrite(inner, { a: 1, b: 2 }); rt.ptrWrite(pair, [3, 4] as [rt.u32, rt.u32]); - rt.place(() => p.n, (value) => p.n = value).v = 5; + p.n = 5; for (const byte of rt.byteSliceView(data)) { const v: rt.u32 = byte as rt.u32; const _25: rt.u8 = rt.u8Rem(byte, 6); diff --git a/ts/fixtures/lang/expected/refs.Pair.ts b/ts/fixtures/lang/expected/refs.Pair.ts index 4a283ac52..abd6a82a0 100644 --- a/ts/fixtures/lang/expected/refs.Pair.ts +++ b/ts/fixtures/lang/expected/refs.Pair.ts @@ -6,4 +6,24 @@ export interface Pair { n: rt.u8; } +export function tally$Tally(self: Pair, n: rt.u8): void { + self.n = rt.u8WrappingAdd(self.n, n); +} + +export function total$Tally(self: Pair): rt.u32 { + return self.n as rt.u32; +} + +export function tally$Tally$2(self: rt.Place, n: rt.u8): void { + tally$Tally(self.v, n); +} + +export function total$Tally$2(self: rt.Place): rt.u32 { + return total$Tally$3(self.v); +} + +export function total$Tally$3(self: Pair): rt.u32 { + return total$Tally(self); +} + //# sourceMappingURL=refs.Pair.ts.map diff --git a/ts/fixtures/lang/expected/refs.Reader.ts b/ts/fixtures/lang/expected/refs.Reader.ts new file mode 100644 index 000000000..bc458ed43 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Reader.ts @@ -0,0 +1,14 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +/** A reader keeping a `&mut` to the slice it reads, which it lends on. */ +export interface Reader { + rest: rt.Place; +} + +export function rest(self: Reader): rt.Place { + return self.rest; +} + +//# sourceMappingURL=refs.Reader.ts.map diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index eddf7610b..3a82e720e 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -8,8 +8,9 @@ import * as Counts from "./refs.Counts.ts"; import * as Cursor from "./refs.Cursor.ts"; import type * as Fetch from "./refs.Fetch.ts"; import * as Listing from "./refs.Listing.ts"; -import type * as Pair from "./refs.Pair.ts"; +import * as Pair from "./refs.Pair.ts"; import type * as Pair2 from "./refs.Pair2.ts"; +import * as Reader from "./refs.Reader.ts"; export function bump(x: rt.Place, by: rt.u8): void { x.v = rt.u32Add(x.v, by as rt.u32); @@ -892,7 +893,7 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { break; } let o6: rt.Place | undefined = _391; - rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o6, (value9) => o6 = value9).v)) & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.optionAsMut(rt.place(() => o6, (value9) => o6 = value9)))) & 0xff); } rt.byteVecPush(out, n); let _406: rt.u8 | undefined = seenOf(data); @@ -1057,4 +1058,211 @@ export function bumpByte(x: rt.Place): void { x.v = rt.u8WrappingAdd(x.v, 1); } +/** + * The front of a slice taken through a `&mut` to it, which it moves past: out of bounds + * past the end, it panics. + */ +export function takeFront(s: rt.Place, n: rt.usize): rt.ByteSlice { + const slice: rt.ByteSlice = s.v; + if (n > slice.length) { + rt.panic("mid > len"); + } + const front: rt.ByteSlice = new rt.ByteSlice(slice.data, slice.start, n); + s.v = new rt.ByteSlice(slice.data, slice.start + n, slice.length - n); + return front; +} + +export function tally$Tally_u32(self: rt.Place, n: rt.u8): void { + self.v = rt.u32Add(self.v, n as rt.u32); +} + +export function total$Tally_u32(self: rt.u32): rt.u32 { + return self; +} + +export function tally$Tally_u32$2(self: rt.Place>>, n: rt.u8): void { + tally$Tally_u32$3(self.v, n); +} + +export function tally$Tally_u32$3(self: rt.Place>, n: rt.u8): void { + tally$Tally_u32(self.v, n); +} + +export function total$Tally_u32$2(self: rt.Place>>): rt.u32 { + return total$Tally_u32$3(self.v); +} + +export function total$Tally_u32$3(self: rt.Place>): rt.u32 { + return total$Tally_u32$4(self.v); +} + +export function total$Tally_u32$4(self: rt.Place): rt.u32 { + return total$Tally_u32(self.v); +} + +export function tallyAll$Pair(t: rt.Place, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + Pair.tally$Tally$2(t, _5); + } + return Pair.total$Tally$2(t); +} + +export function tallyAll$u32(t: rt.Place>>, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + tally$Tally_u32$2(t, _5); + } + return total$Tally_u32$2(t); +} + +export function tallyAll$u32$2(t: rt.Place>, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + tally$Tally_u32$3(t, _5); + } + return total$Tally_u32$3(t); +} + +/** The larger of two references, replacing the one a `&mut` points at. */ +export function keepLarger(r: rt.Place, other: Pair.Pair): void { + if (other.n > r.v.n) { + r.v = other; + } +} + +/** A `&mut` to a `&mut`, written through twice over, then pointed elsewhere. */ +export function retarget(r: rt.Place>, other: rt.Place, by: rt.u8): void { + r.v.v = rt.u32Add(r.v.v, by as rt.u32); + if (rt.u8Rem(by, 2) === 0) { + r.v = other; + } + r.v.v = rt.u32Add(r.v.v, 1); +} + +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Copied_Iter_u8(it: rt.Place>): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 221)); +} + +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Copied_Iter_u8$2(it: rt.Iter): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.next()), 221)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$to_refs_closure2(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return rt.u8WrappingAdd(f.v(1), f.v(2)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$to_refs_closure2$2(f: (a0: rt.u8) => rt.u8): rt.u8 { + return rt.u8WrappingAdd(f(1), f(2)); +} + +/** + * A `&mut` to a reference: replaced, read, and written through, held, passed on, swapped, + * and through an impl that forwards a trait through `&mut T`. + */ +export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { + if (data.length >= 1) { + const n: rt.usize = data.data[data.start] as rt.usize; + let bytes: rt.ByteSlice = rt.byteSliceRange(data, 1); + const _12: rt.usize = rt.usizeRem(n, rt.usizeAdd(rt.byteSliceRange(data, 1).length, 2)); + rt.byteVecExtendFromSlice(out, takeFront(rt.place(() => bytes, (value) => bytes = value), _12)); + rt.byteVecPush(out, bytes.length & 0xff); + const reader: Reader.Reader = { rest: rt.place(() => bytes, (value2) => bytes = value2) }; + while (true) { + const slice: rt.ByteSlice = Reader.rest(reader).v; + if (slice.length !== 0) { + const b: rt.u8 = slice.data[slice.start]; + Reader.rest(reader).v = new rt.ByteSlice(slice.data, slice.start + 1, slice.length - 1); + if (!(rt.u8Rem(b, 5) === 0)) { + rt.byteVecPush(out, b); + } else { + break; + } + } else { + break; + } + } + rt.byteVecPush(out, bytes.length & 0xff); + let tail2: rt.u32[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))), (_2: rt.u8): rt.u32 => { + return (((_2 as rt.u32)) << 8) >>> 0; + })); + while (tail2.length >= 1) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tail2[0]))); + tail2 = tail2.slice(1, tail2.length - 0); + } + let text: string = ""; + for (const _59 of rt.byteSliceView(rt.byteSliceRange(data, 1))) { + text = text + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(_59, 26)) as rt.char); + } + let s: string = text; + const part = rt.min(rt.usizeRem(n, 3), rt.stringLen(s)); + s = rt.strSlice(s, part); + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s)); + const part2 = rt.usizeDiv(rt.byteSliceRange(data, 1).length, 2); + const _85: rt.ByteSlice = rt.byteSliceRange(rt.byteSliceRange(data, 1), part2); + let a: rt.ByteSlice = rt.byteSliceRange(data, 1); + let b3: rt.ByteSlice = _85; + const swapped = a; + a = b3; + b3 = swapped; + const old2 = b3; + b3 = rt.byteSliceFrom(Uint8Array.of()); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.length & 0xff, b3.length & 0xff, old2.length & 0xff))); + const pairs: Pair.Pair[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))), (_22: rt.u8): Pair.Pair => { + return { n: _22 }; + })); + const first: Pair.Pair = { n: 0 }; + let largest: Pair.Pair = first; + for (const _117 of pairs) { + keepLarger(rt.place(() => largest, (value3) => largest = value3), _117); + } + rt.byteVecPush(out, largest.n); + let x: rt.u32 = 0; + let y: rt.u32 = 100; + let r: rt.Place = rt.place(() => x, (value4) => x = value4); + retarget(rt.place(() => r, (value5) => r = value5), rt.place(() => y, (value6) => y = value6), n & 0xff); + r.v = rt.u32Add(r.v, 1000); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(y))); + let count: rt.u32 = 0; + const pair: Pair.Pair = { n: 1 }; + let _152: rt.Place = rt.place(() => count, (value7) => count = value7); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32$2(rt.place(() => _152, (value8) => _152 = value8), rt.byteSliceRange(data, 1))))); + let _159: Pair.Pair = pair; + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$Pair(rt.place(() => _159, (value9) => _159 = value9), rt.byteSliceRange(data, 1))))); + let _167: rt.Place = rt.place(() => count, (value10) => count = value10); + let _166: rt.Place> = rt.place(() => _167, (value11) => _167 = value11); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32(rt.place(() => _166, (value12) => _166 = value12), rt.byteSliceRange(data, 1))))); + rt.byteVecPush(out, pair.n); + const it: rt.Iter = rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))); + rt.byteVecPush(out, nextTwo$Copied_Iter_u8$2(it)); + let _178: rt.Iter = it; + rt.byteVecPush(out, nextTwo$Copied_Iter_u8(rt.place(() => _178, (value13) => _178 = value13))); + let r2: rt.Iter = it; + const iter3: rt.Place> = rt.place(() => r2, (value14) => r2 = value14); + while (true) { + const _183: rt.u8 | rt.Done = iter3.v.next(); + if (_183 === rt.DONE) { + break; + } + const b4: rt.u8 = _183; + if (!(rt.u8Rem(b4, 3) === 0)) { + rt.byteVecPush(out, b4); + } else { + break; + } + } + rt.byteVecPush(out, rt.iterCount(it) & 0xff); + let calls: rt.u8 = 0; + const counted: (a0: rt.u8) => rt.u8 = (b6: rt.u8): rt.u8 => { + calls = rt.u8WrappingAdd(calls, b6); + return calls; + }; + rt.byteVecPush(out, callTwice$to_refs_closure2$2(counted)); + let _204: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$to_refs_closure2(rt.place(() => _204, (value15) => _204 = value15))); + } +} + //# sourceMappingURL=refs.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 354738fa1..6528e1dc4 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -114,6 +114,7 @@ fn cases() -> Vec<(&'static str, Case)> { ("collections::optionals", collections::optionals), ("objects::objects", |_, data, out| objects::objects(data, out)), ("holds::holds", holds::holds), + ("refs::to_refs", |_, data, out| refs::to_refs(data, out)), ] } diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index cc2c96508..2bc029632 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -679,3 +679,178 @@ fn bump_slot(c: &mut usize, b: u8) { fn bump_byte(x: &mut u8) { *x = x.wrapping_add(1); } + +/// The front of a slice taken through a `&mut` to it, which it moves past: out of bounds +/// past the end, it panics. +fn take_front<'a>(s: &mut &'a [u8], n: usize) -> &'a [u8] { + let (front, rest) = s.split_at(n); + *s = rest; + front +} + +/// A count through `&mut self`, and the impl that forwards it through a `&mut`, as `bytes`' +/// `Buf` and `BufMut` forward theirs. +trait Tally { + fn tally(&mut self, n: u8); + fn total(&self) -> u32; +} + +impl Tally for u32 { + fn tally(&mut self, n: u8) { + *self += u32::from(n); + } + + fn total(&self) -> u32 { + *self + } +} + +impl Tally for Pair { + fn tally(&mut self, n: u8) { + self.n = self.n.wrapping_add(n); + } + + fn total(&self) -> u32 { + self.n.into() + } +} + +impl Tally for &mut T { + fn tally(&mut self, n: u8) { + (**self).tally(n); + } + + fn total(&self) -> u32 { + (**self).total() + } +} + +fn tally_all(t: &mut T, data: &[u8]) -> u32 { + for &b in data { + t.tally(b); + } + t.total() +} + +/// A reader keeping a `&mut` to the slice it reads, which it lends on. +struct Reader<'a, 'b> { + rest: &'b mut &'a [u8], +} + +impl<'a> Reader<'a, '_> { + fn rest(&mut self) -> &mut &'a [u8] { + self.rest + } +} + +/// The larger of two references, replacing the one a `&mut` points at. +fn keep_larger<'a>(r: &mut &'a Pair, other: &'a Pair) { + if other.n > r.n { + *r = other; + } +} + +/// A `&mut` to a `&mut`, written through twice over, then pointed elsewhere. +fn retarget<'a>(r: &mut &'a mut u32, other: &'a mut u32, by: u8) { + **r += u32::from(by); + if by % 2 == 0 { + *r = other; + } + **r += 1; +} + +/// The next two items, through std's `Iterator` for `&mut I` when `it` is one. +fn next_two>(mut it: I) -> u8 { + let first = it.next().unwrap_or(0xee); + first.wrapping_add(it.next().unwrap_or(0xdd)) +} + +/// Called twice, through std's `FnMut` for `&mut F` when `f` is one. +fn call_twice u8>(mut f: F) -> u8 { + f(1).wrapping_add(f(2)) +} + +/// A `&mut` to a reference: replaced, read, and written through, held, passed on, swapped, +/// and through an impl that forwards a trait through `&mut T`. +pub fn to_refs(data: &[u8], out: &mut Vec) { + let [n, rest @ ..] = data else { + return; + }; + let n = usize::from(*n); + // Out of bounds past the end, which panics. + let mut bytes = rest; + let front = take_front(&mut bytes, n % (rest.len() + 2)); + out.extend_from_slice(front); + out.push(bytes.len() as u8); + // Through a struct's field, lent on. + let mut reader = Reader { rest: &mut bytes }; + while let Some((&b, tail)) = reader.rest().split_first() { + *reader.rest() = tail; + if b % 5 == 0 { + break; + } + out.push(b); + } + out.push(bytes.len() as u8); + // Of a slice that isn't bytes, and of a `str`. + let words: Vec = rest.iter().map(|&b| u32::from(b) << 8).collect(); + let mut tail: &[u32] = &words; + while let [first, more @ ..] = tail { + out.extend_from_slice(&first.to_be_bytes()); + let tail_ref = &mut tail; + *tail_ref = more; + } + let mut text = String::new(); + for &b in rest { + text.push(char::from(b'a' + b % 26)); + } + let mut s = text.as_str(); + let s_ref = &mut s; + *s_ref = &s_ref[(n % 3).min(s_ref.len())..]; + out.extend_from_slice(s.as_bytes()); + // Swapped and replaced by std. + let (mut a, mut b) = (rest, &rest[rest.len() / 2..]); + std::mem::swap(&mut a, &mut b); + let old = std::mem::replace(&mut b, &[]); + out.extend_from_slice(&[a.len() as u8, b.len() as u8, old.len() as u8]); + // A reference to an object, replaced. + let pairs: Vec = rest.iter().map(|&n| Pair { n }).collect(); + let first = Pair { n: 0 }; + let mut largest = &first; + for p in &pairs { + keep_larger(&mut largest, p); + } + out.push(largest.n); + // A `&mut` to a `&mut`: a number's place, and an object. + let (mut x, mut y) = (0u32, 100u32); + let mut r = &mut x; + retarget(&mut r, &mut y, n as u8); + *r += 1000; + out.extend_from_slice(&x.to_be_bytes()); + out.extend_from_slice(&y.to_be_bytes()); + let mut count = 0u32; + let mut pair = Pair { n: 1 }; + out.extend_from_slice(&tally_all(&mut &mut count, rest).to_be_bytes()); + out.extend_from_slice(&tally_all(&mut &mut pair, rest).to_be_bytes()); + out.extend_from_slice(&tally_all(&mut &mut &mut count, rest).to_be_bytes()); + out.push(pair.n); + // std's impls forwarding through a `&mut`. + let mut it = rest.iter().copied(); + out.push(next_two(&mut it)); + out.push(next_two(&mut &mut it)); + let mut r = &mut it; + for b in &mut r { + if b % 3 == 0 { + break; + } + out.push(b); + } + out.push(it.count() as u8); + let mut calls = 0u8; + let mut counted = |b: u8| { + calls = calls.wrapping_add(b); + calls + }; + out.push(call_twice(&mut counted)); + out.push(call_twice(&mut &mut counted)); +} diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index fc1213895..eab761f45 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,7 +1,7 @@ # Census of `reject-fixture` -- Refusals: 96 -- Function instances: 109 +- Refusals: 97 +- Function instances: 113 - Generic functions no instance reached, lowered over their type parameters: 7 ## By construct @@ -23,6 +23,7 @@ | 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:155:23 | | 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:149:2 | | 2 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:372:13 | +| 1 | `Buf::copy_to_bytes` of `_`, a value JS copies, which is not supported | fixtures/reject/src/lib.rs:725:2 | | 1 | `BufMut::put` of `_` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported | fixtures/reject/src/lib.rs:443:2 | | 1 | `Bytes::from_owner` of `_`, which would drop with the last clone of what it makes, which is not supported | fixtures/reject/src/lib.rs:428:2 | | 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:68:2 | @@ -102,6 +103,7 @@ The type or module each refused type or path belongs to. | 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:483:17 | | 1 | `Batched` | fixtures/reject/src/lib.rs:363:16 | | 1 | `Bits` | fixtures/reject/src/lib.rs:643:1 | +| 1 | `Blank` | fixtures/reject/src/lib.rs:725:2 | | 1 | `BytesMut` | fixtures/reject/src/lib.rs:437:6 | | 1 | `Counted` | fixtures/reject/src/lib.rs:443:2 | | 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:169:1 | @@ -150,6 +152,7 @@ The type or module each refused type or path belongs to. | 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:126:2 | | 2 | replacing the value behind a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:110:2 | | 2 | unsupported call to `_` | `::sum` | fixtures/reject/src/lib.rs:483:17 | +| 1 | `Buf::copy_to_bytes` of `_`, a value JS copies, which is not supported | `Blank` | fixtures/reject/src/lib.rs:725:2 | | 1 | `BufMut::put` of `_` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported | `Counted` | fixtures/reject/src/lib.rs:443:2 | | 1 | `Bytes::from_owner` of `_`, which would drop with the last clone of what it makes, which is not supported | `std::sync::Arc` | fixtures/reject/src/lib.rs:428:2 | | 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:396:18 | @@ -348,6 +351,12 @@ The type or module each refused type or path belongs to. +
`Buf::copy_to_bytes` of `_`, a value JS copies, which is not supported (1) + +- fixtures/reject/src/lib.rs:725:2: `Buf::copy_to_bytes` of `Blank`, a value JS copies, which is not supported + +
+
`BufMut::put` of `_` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported (1) - fixtures/reject/src/lib.rs:443:2: `BufMut::put` of `Counted` into a `BytesMut`, which picks the methods it calls by a capacity that depends on whether the other handles of its storage dropped, which is not supported diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index e4c73c741..51c39b9a3 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -88,6 +88,7 @@ a raw pointer to `(u32, u32)` in a variable assigned again while it may point th a raw pointer to `(u32, u32)` in an element, a payload, or a union field, which is not supported yet at fixtures/reject/src/lib.rs:685:10 comparing pointers to `()`, which has no bytes and so no address of its own at fixtures/reject/src/lib.rs:692:2 a dangling pointer to `Only`, a value of no bytes made of more than structs and tuples at fixtures/reject/src/lib.rs:701:11 +`Buf::copy_to_bytes` of `Blank`, a value JS copies, which is not supported at fixtures/reject/src/lib.rs:725:2 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:149:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:169:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:203:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 290eac556..00b8b7524 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -700,3 +700,27 @@ pub enum Only { pub fn dangling_enum() -> bool { unsafe { std::ptr::NonNull::::dangling().as_ptr().as_ref().is_some() } } + +/// A buffer of the crate's own that JS copies, so `&mut` to it is an `rt.Place`, which the +/// provided `copy_to_bytes` doesn't read through. +pub enum Blank { + Empty, +} + +impl bytes::Buf for Blank { + fn remaining(&self) -> usize { + 0 + } + + fn chunk(&self) -> &[u8] { + &[] + } + + fn advance(&mut self, cnt: usize) { + assert_eq!(cnt, 0); + } +} + +pub fn blank_bytes(len: usize) -> usize { + bytes::Buf::copy_to_bytes(&mut Blank::Empty, len).len() +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index c53534ecf..1207a70d1 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -76,5 +76,6 @@ roots = [ "element_pointer", "units_compared", "dangling_enum", + "blank_bytes", ] printable = ["Meters"] diff --git a/ts/fixtures/stock/expected/buf.Pieces.ts b/ts/fixtures/stock/expected/buf.Pieces.ts index 1fd25467f..bc6e7c70e 100644 --- a/ts/fixtures/stock/expected/buf.Pieces.ts +++ b/ts/fixtures/stock/expected/buf.Pieces.ts @@ -246,7 +246,7 @@ export function copyToSlice$Buf(self: Pieces, dst: rt.ByteSlice): void { * This function panics if there is no more remaining data in `self`. */ export function getU8$Buf(self: Pieces): rt.u8 { - if (!(remaining$Buf$2(self) < 1)) { + if (!(remaining$Buf$3(self) < 1)) { const _7: rt.ByteSlice = chunk$Buf$2(self); rt.idx(_7, 0); const ret: rt.u8 = _7.data[_7.start]; @@ -289,7 +289,7 @@ export function getU8$Buf(self: Pieces): rt.u8 { * ``` */ export function tryCopyToSlice$Buf(self: Pieces, dst: rt.ByteSlice): rt.Result { - if (!(remaining$Buf$2(self) < dst.length)) { + if (!(remaining$Buf$3(self) < dst.length)) { while (!(dst.length === 0)) { const src: rt.ByteSlice = chunk$Buf$2(self); const cnt: rt.usize = rt.min(src.length, dst.length); @@ -299,7 +299,43 @@ export function tryCopyToSlice$Buf(self: Pieces, dst: rt.ByteSlice): rt.Result self.remaining()`. + * + * # Implementer notes + * + * It is recommended for implementations of `advance` to panic if `cnt > + * self.remaining()`. If the implementation does not panic, the call must + * behave as if `cnt == self.remaining()`. + * + * A call with `cnt == 0` should never panic and be a no-op. + */ +export function advance$Buf$2(self: rt.Place, cnt: rt.usize): void { + advance$Buf(self.v, cnt); } /** @@ -336,6 +372,103 @@ export function chunk$Buf$2(self: Pieces): rt.ByteSlice { return chunk$Buf(self); } +/** + * Consumes `len` bytes inside self and returns new instance of `Bytes` + * with this data. + * + * This function may be optimized by the underlying type to avoid actual + * copies. For example, `Bytes` implementation will do a shallow copy + * (ref-count increment). + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let bytes = (&b"hello world"[..]).copy_to_bytes(5); + * assert_eq!(&bytes[..], &b"hello"[..]); + * ``` + * + * # Panics + * + * This function panics if `len > self.remaining()`. + */ +export function copyToBytes$Buf$2(self: rt.Place, len: rt.usize): rt.ByteSlice { + return copyToBytes$Buf(self.v, len); +} + +/** + * Copies bytes from `self` into `dst`. + * + * The cursor is advanced by the number of bytes copied. `self` must have + * enough remaining bytes to fill `dst`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 5]; + * + * buf.copy_to_slice(&mut dst); + * assert_eq!(&b"hello"[..], &dst); + * assert_eq!(6, buf.remaining()); + * ``` + * + * # Panics + * + * This function panics if `self.remaining() < dst.len()`. + */ +export function copyToSlice$Buf$2(self: rt.Place, dst: rt.ByteSlice): void { + copyToSlice$Buf(self.v, dst); +} + +/** + * Gets an unsigned 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_u8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getU8$Buf$2(self: rt.Place): rt.u8 { + return getU8$Buf(self.v); +} + +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf$2(self: rt.Place): boolean { + return hasRemaining$Buf$3(self.v); +} + /** * Returns true if there are any more bytes to consume * @@ -355,7 +488,7 @@ export function chunk$Buf$2(self: Pieces): rt.ByteSlice { * assert!(!buf.has_remaining()); * ``` */ -export function hasRemaining$Buf$2(self: Pieces): boolean { +export function hasRemaining$Buf$3(self: Pieces): boolean { return hasRemaining$Buf(self); } @@ -386,7 +519,38 @@ export function hasRemaining$Buf$2(self: Pieces): boolean { * not change unless a call is made to `advance` or any other function that * is documented to change the `Buf`'s current position. */ -export function remaining$Buf$2(self: Pieces): rt.usize { +export function remaining$Buf$2(self: rt.Place): rt.usize { + return remaining$Buf$3(self.v); +} + +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf$3(self: Pieces): rt.usize { return remaining$Buf(self); } diff --git a/ts/fixtures/stock/expected/buf.Provided.ts b/ts/fixtures/stock/expected/buf.Provided.ts new file mode 100644 index 000000000..60569d2db --- /dev/null +++ b/ts/fixtures/stock/expected/buf.Provided.ts @@ -0,0 +1,333 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import * as Pieces from "./buf.Pieces.ts"; +import { panicAdvance } from "./bytes.ts"; +import type * as TryGetError from "./bytes.TryGetError.ts"; +import { unwrapOrElse$Result_unit_TryGetError_copy_to_slice_closure0 } from "./core/result.ts"; + +/** + * A buffer in pieces with only `Buf`'s required methods, so `copy_to_bytes` is the + * provided one, which reads it through a `Take<&mut Self>`. + */ +export interface Provided { + _0: Pieces.Pieces; +} + +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf(self: Provided): rt.usize { + return Pieces.remaining$Buf(self._0); +} + +/** + * Returns a slice starting at the current position and of length between 0 + * and `Buf::remaining()`. Note that this *can* return a shorter slice (this + * allows non-continuous internal representation). + * + * This is a lower level function. Most operations are done with other + * functions. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.chunk(), &b"hello world"[..]); + * + * buf.advance(6); + * + * assert_eq!(buf.chunk(), &b"world"[..]); + * ``` + * + * # Implementer notes + * + * This function should never panic. `chunk()` should return an empty + * slice **if and only if** `remaining()` returns 0. In other words, + * `chunk()` returning an empty slice implies that `remaining()` will + * return 0 and `remaining()` returning 0 implies that `chunk()` will + * return an empty slice. + */ +export function chunk$Buf(self: Provided): rt.ByteSlice { + return Pieces.chunk$Buf(self._0); +} + +/** + * Advance the internal cursor of the Buf + * + * The next call to `chunk()` will return a slice starting `cnt` bytes + * further into the underlying buffer. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.chunk(), &b"hello world"[..]); + * + * buf.advance(6); + * + * assert_eq!(buf.chunk(), &b"world"[..]); + * ``` + * + * # Panics + * + * This function **may** panic if `cnt > self.remaining()`. + * + * # Implementer notes + * + * It is recommended for implementations of `advance` to panic if `cnt > + * self.remaining()`. If the implementation does not panic, the call must + * behave as if `cnt == self.remaining()`. + * + * A call with `cnt == 0` should never panic and be a no-op. + */ +export function advance$Buf(self: Provided, cnt: rt.usize): void { + Pieces.advance$Buf(self._0, cnt); +} + +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf(self: Provided): boolean { + return remaining$Buf(self) > 0; +} + +/** + * Copies bytes from `self` into `dst`. + * + * The cursor is advanced by the number of bytes copied. `self` must have + * enough remaining bytes to fill `dst`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 5]; + * + * buf.copy_to_slice(&mut dst); + * assert_eq!(&b"hello"[..], &dst); + * assert_eq!(6, buf.remaining()); + * ``` + * + * # Panics + * + * This function panics if `self.remaining() < dst.len()`. + */ +export function copyToSlice$Buf(self: Provided, dst: rt.ByteSlice): void { + unwrapOrElse$Result_unit_TryGetError_copy_to_slice_closure0(tryCopyToSlice$Buf(self, dst), (error: TryGetError.TryGetError): void => { + panicAdvance(error); + }); +} + +/** + * Gets an unsigned 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_u8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getU8$Buf(self: Provided): rt.u8 { + if (!(remaining$Buf$2(self) < 1)) { + const _7: rt.ByteSlice = chunk$Buf$2(self); + rt.idx(_7, 0); + const ret: rt.u8 = _7.data[_7.start]; + advance$Buf(self, 1); + return ret; + } + panicAdvance({ requested: 1, available: 0 }); +} + +/** + * Copies bytes from `self` into `dst`. + * + * The cursor is advanced by the number of bytes copied. `self` must have + * enough remaining bytes to fill `dst`. + * + * Returns `Err(TryGetError)` when there are not enough + * remaining bytes to read the value. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 5]; + * + * assert_eq!(Ok(()), buf.try_copy_to_slice(&mut dst)); + * assert_eq!(&b"hello"[..], &dst); + * assert_eq!(6, buf.remaining()); + * ``` + * + * ``` + * use bytes::{Buf, TryGetError}; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 12]; + * + * assert_eq!(Err(TryGetError{requested: 12, available: 11}), buf.try_copy_to_slice(&mut dst)); + * assert_eq!(11, buf.remaining()); + * ``` + */ +export function tryCopyToSlice$Buf(self: Provided, dst: rt.ByteSlice): rt.Result { + if (!(remaining$Buf$2(self) < dst.length)) { + while (!(dst.length === 0)) { + const src: rt.ByteSlice = chunk$Buf$2(self); + const cnt: rt.usize = rt.min(src.length, dst.length); + rt.byteSliceCopyFromSlice(rt.byteSliceRange(dst, 0, cnt), rt.byteSliceRange(src, 0, cnt)); + dst = rt.byteSliceRange(dst, cnt); + advance$Buf(self, cnt); + } + return rt.OK; + } + return rt.Err({ requested: dst.length, available: remaining$Buf$2(self) }); +} + +/** + * Returns a slice starting at the current position and of length between 0 + * and `Buf::remaining()`. Note that this *can* return a shorter slice (this + * allows non-continuous internal representation). + * + * This is a lower level function. Most operations are done with other + * functions. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.chunk(), &b"hello world"[..]); + * + * buf.advance(6); + * + * assert_eq!(buf.chunk(), &b"world"[..]); + * ``` + * + * # Implementer notes + * + * This function should never panic. `chunk()` should return an empty + * slice **if and only if** `remaining()` returns 0. In other words, + * `chunk()` returning an empty slice implies that `remaining()` will + * return 0 and `remaining()` returning 0 implies that `chunk()` will + * return an empty slice. + */ +export function chunk$Buf$2(self: Provided): rt.ByteSlice { + return chunk$Buf(self); +} + +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf$2(self: Provided): boolean { + return hasRemaining$Buf(self); +} + +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf$2(self: Provided): rt.usize { + return remaining$Buf(self); +} + +//# sourceMappingURL=buf.Provided.ts.map diff --git a/ts/fixtures/stock/expected/buf.ts b/ts/fixtures/stock/expected/buf.ts index 0a25eb402..eb3a661a6 100644 --- a/ts/fixtures/stock/expected/buf.ts +++ b/ts/fixtures/stock/expected/buf.ts @@ -3,7 +3,9 @@ import * as rt from "./rt.ts"; import * as Ops from "./buf.Ops.ts"; import * as Pieces from "./buf.Pieces.ts"; -import { hasRemaining$Buf_Bytes, hasRemaining$Buf_BytesMut, remaining$Buf_Bytes, remaining$Buf_BytesMut } from "./bytes/buf/buf_impl.ts"; +import * as Provided from "./buf.Provided.ts"; +import { advance$Buf_Bytes, advance$Buf_u8s, copyToBytes$Buf_Bytes, copyToBytes$Buf_u8s, copyToSlice$Buf_Bytes, copyToSlice$Buf_u8s, getF64$Buf_Bytes, getF64$Buf_u8s, getI128$Buf_Bytes, getI128$Buf_u8s, getI16Le$Buf_Bytes, getI16Le$Buf_u8s, getI32$Buf_Bytes, getI32$Buf_u8s, getI64Le$Buf_Bytes, getI64Le$Buf_u8s, getI8$Buf_Bytes, getI8$Buf_u8s, getIntLe$Buf_Bytes, getIntLe$Buf_u8s, getU128Le$Buf_Bytes, getU128Le$Buf_u8s, getU16$Buf_Bytes, getU16$Buf_u8s, getU32Le$Buf_Bytes, getU32Le$Buf_u8s, getU64$Buf_Bytes, getU64$Buf_u8s, getU8$Buf_Bytes, getU8$Buf_u8s, getUint$Buf_Bytes, getUint$Buf_u8s, hasRemaining$Buf_Bytes, hasRemaining$Buf_Bytes$2, hasRemaining$Buf_BytesMut, hasRemaining$Buf_u8s, hasRemaining$Buf_u8s$2, remaining$Buf_Bytes, remaining$Buf_Bytes$2, remaining$Buf_BytesMut, remaining$Buf_u8s, remaining$Buf_u8s$2 } from "./bytes/buf/buf_impl.ts"; +import { hasRemainingMut$BufMut_BytesMut, hasRemainingMut$BufMut_Vec_u8, putI128Le$BufMut_BytesMut, putI128Le$BufMut_Vec_u8, putF64$BufMut_BytesMut, putF64$BufMut_Vec_u8, putI32$BufMut_BytesMut, putI32$BufMut_Vec_u8, putI8$BufMut_BytesMut, putI8$BufMut_Vec_u8, putSlice$BufMut_BytesMut, putSlice$BufMut_Vec_u8, putU16Le$BufMut_BytesMut, putU16Le$BufMut_Vec_u8, putU64$BufMut_BytesMut, putU64$BufMut_Vec_u8, putU8$BufMut_BytesMut, putU8$BufMut_Vec_u8, remainingMut$BufMut_BytesMut, remainingMut$BufMut_Vec_u8 } from "./bytes/buf/buf_mut.ts"; import { then$bool_BytesMut_reserves_closure0 } from "./core/bool.ts"; /** @@ -132,7 +134,55 @@ export function getU8Checked$Checked_BytesMut(self: rt.BytesMut): rt.u8 { } /** A scalar read off the front of a buffer by `n`'s pick, as a `u128`'s bytes. */ -export function read$Bytes(buf: rt.Place, n: rt.usize): rt.u128 { +export function read$Bytes(buf: rt.Place>, n: rt.usize): rt.u128 { + const _3: rt.usize = rt.usizeRem(n, 14); + if (_3 === 0) { + return getU8$Buf_Bytes(buf) as rt.u128; + } + if (_3 === 1) { + return rt.u128Cast(getI8$Buf_Bytes(buf)); + } + if (_3 === 2) { + return getU16$Buf_Bytes(buf) as rt.u128; + } + if (_3 === 3) { + return rt.u128Cast(getI16Le$Buf_Bytes(buf)); + } + if (_3 === 4) { + return getU32Le$Buf_Bytes(buf) as rt.u128; + } + if (_3 === 5) { + return rt.u128Cast(getI32$Buf_Bytes(buf)); + } + if (_3 === 6) { + return rt.u128Cast(getU64$Buf_Bytes(buf)); + } + if (_3 === 7) { + return rt.u128Cast(getI64Le$Buf_Bytes(buf)); + } + if (_3 === 8) { + return getU128Le$Buf_Bytes(buf); + } + if (_3 === 9) { + return rt.u128Cast(getI128$Buf_Bytes(buf)); + } + if (_3 === 10) { + return rt.u128Cast(getUint$Buf_Bytes(buf, rt.usizeRem(n, 10))); + } + if (_3 === 11) { + return rt.u128Cast(getIntLe$Buf_Bytes(buf, rt.usizeRem(n, 10))); + } + if (_3 === 12) { + return rt.u128Cast(rt.f64ToBits(getF64$Buf_Bytes(buf))); + } + const dst: Uint8Array = rt.bytes(3); + const part = rt.usizeRem(n, 4); + copyToSlice$Buf_Bytes(buf, rt.byteSliceRange(rt.byteSliceFrom(dst), 0, part)); + return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; +} + +/** A scalar read off the front of a buffer by `n`'s pick, as a `u128`'s bytes. */ +export function read$Bytes$2(buf: rt.Place, n: rt.usize): rt.u128 { const _3: rt.usize = rt.usizeRem(n, 14); if (_3 === 0) { return ((rt.bytesReadWord(buf, 1, false) as rt.u8)) as rt.u128; @@ -227,6 +277,102 @@ export function read$BytesMut(buf: rt.BytesMut, n: rt.usize): rt.u128 { return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; } +/** A scalar read off the front of a buffer by `n`'s pick, as a `u128`'s bytes. */ +export function read$u8s(buf: rt.Place, n: rt.usize): rt.u128 { + const _3: rt.usize = rt.usizeRem(n, 14); + if (_3 === 0) { + return ((rt.bytesReadWord(buf, 1, false) as rt.u8)) as rt.u128; + } + if (_3 === 1) { + return rt.u128Cast((rt.bytesReadWord(buf, 1, false) << 24) >> 24 as rt.i8); + } + if (_3 === 2) { + return ((rt.bytesReadWord(buf, 2, false) as rt.u16)) as rt.u128; + } + if (_3 === 3) { + return rt.u128Cast((rt.bytesReadWord(buf, 2, true) << 16) >> 16 as rt.i16); + } + if (_3 === 4) { + return ((rt.bytesReadWord(buf, 4, true) as rt.u32)) as rt.u128; + } + if (_3 === 5) { + return rt.u128Cast((rt.bytesReadWord(buf, 4, false) | 0) as rt.i32); + } + if (_3 === 6) { + return rt.u128Cast(rt.u64FromBeBytes(rt.bytesRead(buf, 8, false))); + } + if (_3 === 7) { + return rt.u128Cast(rt.i64FromBeBytes(rt.bytesRead(buf, 8, true))); + } + if (_3 === 8) { + return rt.u128FromBeBytes(rt.bytesRead(buf, 16, true)); + } + if (_3 === 9) { + return rt.u128Cast(rt.i128FromBeBytes(rt.bytesRead(buf, 16, false))); + } + if (_3 === 10) { + return rt.u128Cast(rt.u64FromBeBytes(rt.bytesReadInt(buf, 8, rt.usizeRem(n, 10), false, false))); + } + if (_3 === 11) { + return rt.u128Cast(rt.i64FromBeBytes(rt.bytesReadInt(buf, 8, rt.usizeRem(n, 10), true, true))); + } + if (_3 === 12) { + return rt.u128Cast(rt.f64ToBits(rt.f64FromBeBytes(rt.bytesRead(buf, 8, false)))); + } + const dst: Uint8Array = rt.bytes(3); + const part = rt.usizeRem(n, 4); + rt.bytesCopyToSlice(buf, rt.byteSliceRange(rt.byteSliceFrom(dst), 0, part)); + return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; +} + +/** A scalar read off the front of a buffer by `n`'s pick, as a `u128`'s bytes. */ +export function read$u8s$2(buf: rt.Place>, n: rt.usize): rt.u128 { + const _3: rt.usize = rt.usizeRem(n, 14); + if (_3 === 0) { + return getU8$Buf_u8s(buf) as rt.u128; + } + if (_3 === 1) { + return rt.u128Cast(getI8$Buf_u8s(buf)); + } + if (_3 === 2) { + return getU16$Buf_u8s(buf) as rt.u128; + } + if (_3 === 3) { + return rt.u128Cast(getI16Le$Buf_u8s(buf)); + } + if (_3 === 4) { + return getU32Le$Buf_u8s(buf) as rt.u128; + } + if (_3 === 5) { + return rt.u128Cast(getI32$Buf_u8s(buf)); + } + if (_3 === 6) { + return rt.u128Cast(getU64$Buf_u8s(buf)); + } + if (_3 === 7) { + return rt.u128Cast(getI64Le$Buf_u8s(buf)); + } + if (_3 === 8) { + return getU128Le$Buf_u8s(buf); + } + if (_3 === 9) { + return rt.u128Cast(getI128$Buf_u8s(buf)); + } + if (_3 === 10) { + return rt.u128Cast(getUint$Buf_u8s(buf, rt.usizeRem(n, 10))); + } + if (_3 === 11) { + return rt.u128Cast(getIntLe$Buf_u8s(buf, rt.usizeRem(n, 10))); + } + if (_3 === 12) { + return rt.u128Cast(rt.f64ToBits(getF64$Buf_u8s(buf))); + } + const dst: Uint8Array = rt.bytes(3); + const part = rt.usizeRem(n, 4); + copyToSlice$Buf_u8s(buf, rt.byteSliceRange(rt.byteSliceFrom(dst), 0, part)); + return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; +} + /** * `reserve` at the edges of `rt.BytesMut`'s limit for storage that was shared, 512 MiB * counting what it read past: a vector of its own grows as `Vec` does on either side of @@ -259,8 +405,8 @@ export function reserves(data: rt.ByteSlice, out: rt.ByteVec): void { } /** - * The same reads off a `Bytes`, a `BytesMut`, and a buffer in pieces: each scalar, and - * what remains. + * The same reads off a `Bytes`, a `BytesMut`, a `&[u8]`, buffers in pieces, and each + * through the impl forwarding through a `&mut`: each scalar, and what remains. */ export function reads(data: rt.ByteSlice, out: rt.ByteVec): void { let rest!: rt.ByteVec; @@ -271,19 +417,36 @@ export function reads(data: rt.ByteSlice, out: rt.ByteVec): void { } const input: rt.ByteSlice = new rt.ByteSlice(data.data, data.start + 2 + mid, data.length - 2 - mid); const cut: rt.usize = rt.usizeRem(data.data[data.start + 1] as rt.usize, rt.usizeAdd(input.length, 1)); - const _22: rt.u8 = rt.u8Rem(data.data[data.start], 3); + const _22: rt.u8 = rt.u8Rem(data.data[data.start], 8); if (_22 === 0) { let _24: rt.ByteSlice = rt.bytesCopyFromSlice(input); - rest = readAll$Bytes(rt.place(() => _24, (value) => _24 = value), new rt.ByteSlice(data.data, data.start + 2, mid), read$Bytes, out); + rest = readAll$Bytes$2(rt.place(() => _24, (value7) => _24 = value7), new rt.ByteSlice(data.data, data.start + 2, mid), read$Bytes$2, out); } else if (_22 === 1) { rest = readAll$BytesMut(rt.bytesMutFrom(input), new rt.ByteSlice(data.data, data.start + 2, mid), read$BytesMut, out); + } else if (_22 === 2) { + rest = readAll$Pieces$2(Pieces.new(input, cut), new rt.ByteSlice(data.data, data.start + 2, mid), readPieces$Pieces$2, out); + } else if (_22 === 3) { + let _33: rt.ByteSlice = rt.byteSliceRange(input, 0); + rest = readAll$u8s(rt.place(() => _33, (value6) => _33 = value6), new rt.ByteSlice(data.data, data.start + 2, mid), read$u8s, out); + } else if (_22 === 4) { + const _37: Provided.Provided = { _0: Pieces.new(input, cut) }; + rest = readAll$Provided(_37, new rt.ByteSlice(data.data, data.start + 2, mid), readPieces$Provided, out); + } else if (_22 === 5) { + let _42: rt.ByteSlice = rt.bytesCopyFromSlice(input); + let _41: rt.Place = rt.place(() => _42, (value4) => _42 = value4); + rest = readAll$Bytes(rt.place(() => _41, (value5) => _41 = value5), new rt.ByteSlice(data.data, data.start + 2, mid), read$Bytes, out); + } else if (_22 === 6) { + let _46: rt.ByteSlice = rt.byteSliceRange(input, 0); + let _45: rt.Place = rt.place(() => _46, (value2) => _46 = value2); + rest = readAll$u8s$2(rt.place(() => _45, (value3) => _45 = value3), new rt.ByteSlice(data.data, data.start + 2, mid), read$u8s$2, out); } else { - rest = readAll$Pieces(Pieces.new(input, cut), new rt.ByteSlice(data.data, data.start + 2, mid), readPieces, out); + let _50: Pieces.Pieces = Pieces.new(input, cut); + rest = readAll$Pieces(rt.place(() => _50, (value) => _50 = value), new rt.ByteSlice(data.data, data.start + 2, mid), readPieces$Pieces, out); } rt.byteVecExtendFromSlice(out, rt.byteVecSlice(rest)); const vec: rt.ByteVec = new rt.ByteVec(); - const _38: Pieces.Pieces = Pieces.new(input, cut); - rt.byteVecPutBuf(vec, _38, Pieces.hasRemaining$Buf, Pieces.remaining$Buf, Pieces.chunk$Buf, Pieces.advance$Buf); + const _59: Pieces.Pieces = Pieces.new(input, cut); + rt.byteVecPutBuf(vec, _59, Pieces.hasRemaining$Buf, Pieces.remaining$Buf, Pieces.chunk$Buf, Pieces.advance$Buf); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(vec)); const slice: rt.ByteSlice = input; rt.byteVecPush(out, slice.length === input.length ? 1 : 0); @@ -296,7 +459,21 @@ export function reads(data: rt.ByteSlice, out: rt.ByteVec): void { * The reads of `Buf`'s provided methods that translate for a buffer of the crate's own: * those whose MIR reads no bytes as another type. */ -export function readPieces(buf: Pieces.Pieces, n: rt.usize): rt.u128 { +export function readPieces$Pieces(buf: rt.Place, n: rt.usize): rt.u128 { + if (rt.usizeRem(n, 2) === 0) { + return Pieces.getU8$Buf$2(buf) as rt.u128; + } + const dst: Uint8Array = rt.bytes(3); + const part = rt.usizeRem(n, 4); + Pieces.copyToSlice$Buf$2(buf, rt.byteSliceRange(rt.byteSliceFrom(dst), 0, part)); + return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; +} + +/** + * The reads of `Buf`'s provided methods that translate for a buffer of the crate's own: + * those whose MIR reads no bytes as another type. + */ +export function readPieces$Pieces$2(buf: Pieces.Pieces, n: rt.usize): rt.u128 { if (rt.usizeRem(n, 2) === 0) { return Pieces.getU8$Buf(buf) as rt.u128; } @@ -306,17 +483,45 @@ export function readPieces(buf: Pieces.Pieces, n: rt.usize): rt.u128 { return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; } +/** + * The reads of `Buf`'s provided methods that translate for a buffer of the crate's own: + * those whose MIR reads no bytes as another type. + */ +export function readPieces$Provided(buf: Provided.Provided, n: rt.usize): rt.u128 { + if (rt.usizeRem(n, 2) === 0) { + return Provided.getU8$Buf(buf) as rt.u128; + } + const dst: Uint8Array = rt.bytes(3); + const part = rt.usizeRem(n, 4); + Provided.copyToSlice$Buf(buf, rt.byteSliceRange(rt.byteSliceFrom(dst), 0, part)); + return ((dst[0] << 16) | (dst[1] << 8) | dst[2]) as rt.u128; +} + /** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ -export function readAll$Bytes(buf: rt.Place, ops: rt.ByteSlice, read: (a0: rt.Place, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { +export function readAll$Bytes(buf: rt.Place>, ops: rt.ByteSlice, read: (a0: rt.Place>, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { for (const op of rt.byteSliceView(ops)) { if (!(op === 255)) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); rt.byteVecPush(out, hasRemaining$Buf_Bytes(buf) ? 1 : 0); } else { - rt.bytesAdvance(buf, 1); + advance$Buf_Bytes(buf, 1); } } const n: rt.usize = remaining$Buf_Bytes(buf); + return rt.byteSliceToByteVec(copyToBytes$Buf_Bytes(buf, n)); +} + +/** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ +export function readAll$Bytes$2(buf: rt.Place, ops: rt.ByteSlice, read: (a0: rt.Place, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { + for (const op of rt.byteSliceView(ops)) { + if (!(op === 255)) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); + rt.byteVecPush(out, hasRemaining$Buf_Bytes$2(buf) ? 1 : 0); + } else { + rt.bytesAdvance(buf, 1); + } + } + const n: rt.usize = remaining$Buf_Bytes$2(buf); return rt.byteSliceToByteVec(rt.bytesSplitTo(buf, n)); } @@ -335,25 +540,93 @@ export function readAll$BytesMut(buf: rt.BytesMut, ops: rt.ByteSlice, read: (a0: } /** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ -export function readAll$Pieces(buf: Pieces.Pieces, ops: rt.ByteSlice, read: (a0: Pieces.Pieces, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { +export function readAll$Pieces(buf: rt.Place, ops: rt.ByteSlice, read: (a0: rt.Place, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { for (const op of rt.byteSliceView(ops)) { if (!(op === 255)) { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); rt.byteVecPush(out, Pieces.hasRemaining$Buf$2(buf) ? 1 : 0); } else { - Pieces.advance$Buf(buf, 1); + Pieces.advance$Buf$2(buf, 1); } } const n: rt.usize = Pieces.remaining$Buf$2(buf); + return rt.byteSliceToByteVec(Pieces.copyToBytes$Buf$2(buf, n)); +} + +/** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ +export function readAll$Pieces$2(buf: Pieces.Pieces, ops: rt.ByteSlice, read: (a0: Pieces.Pieces, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { + for (const op of rt.byteSliceView(ops)) { + if (!(op === 255)) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); + rt.byteVecPush(out, Pieces.hasRemaining$Buf$3(buf) ? 1 : 0); + } else { + Pieces.advance$Buf(buf, 1); + } + } + const n: rt.usize = Pieces.remaining$Buf$3(buf); return rt.byteSliceToByteVec(Pieces.copyToBytes$Buf(buf, n)); } -/** The same writes into a `Vec` and a `BytesMut`, which must match. */ +/** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ +export function readAll$Provided(buf: Provided.Provided, ops: rt.ByteSlice, read: (a0: Provided.Provided, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { + for (const op of rt.byteSliceView(ops)) { + if (!(op === 255)) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); + rt.byteVecPush(out, Provided.hasRemaining$Buf$2(buf) ? 1 : 0); + } else { + Provided.advance$Buf(buf, 1); + } + } + const n: rt.usize = Provided.remaining$Buf$2(buf); + return rt.byteSliceToByteVec(rt.bufCopyToBytes(buf, n, Provided.remaining$Buf, Provided.chunk$Buf, Provided.advance$Buf)); +} + +/** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ +export function readAll$u8s(buf: rt.Place, ops: rt.ByteSlice, read: (a0: rt.Place, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { + for (const op of rt.byteSliceView(ops)) { + if (!(op === 255)) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); + rt.byteVecPush(out, hasRemaining$Buf_u8s(buf) ? 1 : 0); + } else { + rt.byteSliceAdvance(buf, 1); + } + } + const n: rt.usize = remaining$Buf_u8s(buf); + return rt.byteSliceToByteVec(rt.byteSliceCopyToBytes(buf, n)); +} + +/** `read`s by each of `ops`, then the rest, as `copy_to_bytes` takes it. */ +export function readAll$u8s$2(buf: rt.Place>, ops: rt.ByteSlice, read: (a0: rt.Place>, a1: rt.usize) => rt.u128, out: rt.ByteVec): rt.ByteVec { + for (const op of rt.byteSliceView(ops)) { + if (!(op === 255)) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(read(buf, op as rt.usize)))); + rt.byteVecPush(out, hasRemaining$Buf_u8s$2(buf) ? 1 : 0); + } else { + advance$Buf_u8s(buf, 1); + } + } + const n: rt.usize = remaining$Buf_u8s$2(buf); + return rt.byteSliceToByteVec(copyToBytes$Buf_u8s(buf, n)); +} + +/** + * The same writes into a `Vec` and a `BytesMut`, which must match, and through the + * impl forwarding through a `&mut`. + */ export function writes(data: rt.ByteSlice, out: rt.ByteVec): void { const vec: rt.ByteVec = new rt.ByteVec(); const buf: rt.BytesMut = rt.bytesMutWithCapacity(0); writeAll$Vec_u8(vec, data); writeAll$BytesMut(buf, data); + const _11: [rt.ByteVec, rt.BytesMut] = [new rt.ByteVec(), rt.bytesMutWithCapacity(0)]; + const throughVec: rt.ByteVec = _11[0]; + const throughBuf: rt.BytesMut = _11[1]; + let _16: rt.ByteVec = throughVec; + writeThrough$Vec_u8(rt.place(() => _16, (value) => _16 = value), data); + let _19: rt.BytesMut = throughBuf; + writeThrough$BytesMut(rt.place(() => _19, (value2) => _19 = value2), data); + rt.byteVecExtendFromSlice(out, rt.byteVecSlice(throughVec)); + rt.byteVecExtendFromSlice(out, rt.bytesMutView(throughBuf)); rt.byteVecPush(out, rt.byteSliceEq(rt.byteVecSlice(vec), rt.bytesMutView(buf)) ? 1 : 0); rt.byteVecPush(out, ((0x7fffffff - vec.length as rt.usize)) === 0x7fffffff - buf.length as rt.usize ? 1 : 0); rt.byteVecPush(out, buf.length < 0x7fffffff ? 1 : 0); @@ -470,6 +743,94 @@ export function writeAll$Vec_u8(buf: rt.ByteVec, data: rt.ByteSlice): void { } } +/** + * A write by each pair of `data`'s bytes, of those that `&mut T` forwards, and of those + * whose provided body calls only those. + */ +export function writeThrough$BytesMut(buf: rt.Place, data: rt.ByteSlice): void { + let dataData: Uint8Array = data.data; + let dataStart: number = data.start; + let dataLen: number = data.length; + while (dataLen >= 2) { + const op: rt.u8 = dataData[dataStart]; + const n: rt.u8 = dataData[dataStart + 1]; + const restData: Uint8Array = dataData; + const restStart: number = dataStart + 2; + const restLen: number = dataLen - 2; + dataData = restData; + dataStart = restStart; + dataLen = restLen; + const op2: rt.u8 = op; + const n2: rt.u8 = n; + const v: rt.u64 = rt.u64Mul(n2 as rt.u64, { hi: 0x1010101, lo: 0x1010101 } as rt.u64); + const _18: rt.u8 = rt.u8Rem(op2, 9); + if (_18 === 0) { + putU8$BufMut_BytesMut(buf, n2); + } else if (_18 === 1) { + putI8$BufMut_BytesMut(buf, (n2 << 24) >> 24); + } else if (_18 === 2) { + putU16Le$BufMut_BytesMut(buf, rt.u64Low(v) & 0xffff); + } else if (_18 === 3) { + putI32$BufMut_BytesMut(buf, rt.u64Low(v) | 0); + } else if (_18 === 4) { + putU64$BufMut_BytesMut(buf, v); + } else if (_18 === 5) { + putSlice$BufMut_BytesMut(buf, rt.byteSliceFrom(Uint8Array.of(op2, n2))); + } else if (_18 === 6) { + putI128Le$BufMut_BytesMut(buf, rt.i128Shl(rt.i128Cast(v), 40)); + } else if (_18 === 7) { + putF64$BufMut_BytesMut(buf, ((n2 as rt.f64)) / 3.0); + } else { + const _32: rt.u8 = rt.u8Add(hasRemainingMut$BufMut_BytesMut(buf) ? 1 : 0, rt.usizeRem(remainingMut$BufMut_BytesMut(buf), 7) & 0xff); + putU8$BufMut_BytesMut(buf, _32); + } + } +} + +/** + * A write by each pair of `data`'s bytes, of those that `&mut T` forwards, and of those + * whose provided body calls only those. + */ +export function writeThrough$Vec_u8(buf: rt.Place, data: rt.ByteSlice): void { + let dataData: Uint8Array = data.data; + let dataStart: number = data.start; + let dataLen: number = data.length; + while (dataLen >= 2) { + const op: rt.u8 = dataData[dataStart]; + const n: rt.u8 = dataData[dataStart + 1]; + const restData: Uint8Array = dataData; + const restStart: number = dataStart + 2; + const restLen: number = dataLen - 2; + dataData = restData; + dataStart = restStart; + dataLen = restLen; + const op2: rt.u8 = op; + const n2: rt.u8 = n; + const v: rt.u64 = rt.u64Mul(n2 as rt.u64, { hi: 0x1010101, lo: 0x1010101 } as rt.u64); + const _18: rt.u8 = rt.u8Rem(op2, 9); + if (_18 === 0) { + putU8$BufMut_Vec_u8(buf, n2); + } else if (_18 === 1) { + putI8$BufMut_Vec_u8(buf, (n2 << 24) >> 24); + } else if (_18 === 2) { + putU16Le$BufMut_Vec_u8(buf, rt.u64Low(v) & 0xffff); + } else if (_18 === 3) { + putI32$BufMut_Vec_u8(buf, rt.u64Low(v) | 0); + } else if (_18 === 4) { + putU64$BufMut_Vec_u8(buf, v); + } else if (_18 === 5) { + putSlice$BufMut_Vec_u8(buf, rt.byteSliceFrom(Uint8Array.of(op2, n2))); + } else if (_18 === 6) { + putI128Le$BufMut_Vec_u8(buf, rt.i128Shl(rt.i128Cast(v), 40)); + } else if (_18 === 7) { + putF64$BufMut_Vec_u8(buf, ((n2 as rt.f64)) / 3.0); + } else { + const _32: rt.u8 = rt.u8Add(hasRemainingMut$BufMut_Vec_u8(buf) ? 1 : 0, rt.usizeRem(remainingMut$BufMut_Vec_u8(buf), 7) & 0xff); + putU8$BufMut_Vec_u8(buf, _32); + } + } +} + /** `Bytes`' own edits, through a `&mut`, and `slice_ref` of a part of it. */ export function edits(data: rt.ByteSlice, out: rt.ByteVec): void { let part!: rt.ByteSlice; diff --git a/ts/fixtures/stock/expected/bytes/buf/buf_impl.ts b/ts/fixtures/stock/expected/bytes/buf/buf_impl.ts index 89d7c1c69..474f0c252 100644 --- a/ts/fixtures/stock/expected/bytes/buf/buf_impl.ts +++ b/ts/fixtures/stock/expected/bytes/buf/buf_impl.ts @@ -2,6 +2,783 @@ import * as rt from "../../rt.ts"; +/** + * Advance the internal cursor of the Buf + * + * The next call to `chunk()` will return a slice starting `cnt` bytes + * further into the underlying buffer. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.chunk(), &b"hello world"[..]); + * + * buf.advance(6); + * + * assert_eq!(buf.chunk(), &b"world"[..]); + * ``` + * + * # Panics + * + * This function **may** panic if `cnt > self.remaining()`. + * + * # Implementer notes + * + * It is recommended for implementations of `advance` to panic if `cnt > + * self.remaining()`. If the implementation does not panic, the call must + * behave as if `cnt == self.remaining()`. + * + * A call with `cnt == 0` should never panic and be a no-op. + */ +export function advance$Buf_Bytes(self: rt.Place>, cnt: rt.usize): void { + rt.bytesAdvance(self.v, cnt); +} + +/** + * Advance the internal cursor of the Buf + * + * The next call to `chunk()` will return a slice starting `cnt` bytes + * further into the underlying buffer. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.chunk(), &b"hello world"[..]); + * + * buf.advance(6); + * + * assert_eq!(buf.chunk(), &b"world"[..]); + * ``` + * + * # Panics + * + * This function **may** panic if `cnt > self.remaining()`. + * + * # Implementer notes + * + * It is recommended for implementations of `advance` to panic if `cnt > + * self.remaining()`. If the implementation does not panic, the call must + * behave as if `cnt == self.remaining()`. + * + * A call with `cnt == 0` should never panic and be a no-op. + */ +export function advance$Buf_u8s(self: rt.Place>, cnt: rt.usize): void { + rt.byteSliceAdvance(self.v, cnt); +} + +/** + * Consumes `len` bytes inside self and returns new instance of `Bytes` + * with this data. + * + * This function may be optimized by the underlying type to avoid actual + * copies. For example, `Bytes` implementation will do a shallow copy + * (ref-count increment). + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let bytes = (&b"hello world"[..]).copy_to_bytes(5); + * assert_eq!(&bytes[..], &b"hello"[..]); + * ``` + * + * # Panics + * + * This function panics if `len > self.remaining()`. + */ +export function copyToBytes$Buf_Bytes(self: rt.Place>, len: rt.usize): rt.ByteSlice { + return rt.bytesSplitTo(self.v, len); +} + +/** + * Consumes `len` bytes inside self and returns new instance of `Bytes` + * with this data. + * + * This function may be optimized by the underlying type to avoid actual + * copies. For example, `Bytes` implementation will do a shallow copy + * (ref-count increment). + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let bytes = (&b"hello world"[..]).copy_to_bytes(5); + * assert_eq!(&bytes[..], &b"hello"[..]); + * ``` + * + * # Panics + * + * This function panics if `len > self.remaining()`. + */ +export function copyToBytes$Buf_u8s(self: rt.Place>, len: rt.usize): rt.ByteSlice { + return rt.byteSliceCopyToBytes(self.v, len); +} + +/** + * Copies bytes from `self` into `dst`. + * + * The cursor is advanced by the number of bytes copied. `self` must have + * enough remaining bytes to fill `dst`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 5]; + * + * buf.copy_to_slice(&mut dst); + * assert_eq!(&b"hello"[..], &dst); + * assert_eq!(6, buf.remaining()); + * ``` + * + * # Panics + * + * This function panics if `self.remaining() < dst.len()`. + */ +export function copyToSlice$Buf_Bytes(self: rt.Place>, dst: rt.ByteSlice): void { + rt.bytesCopyToSlice(self.v, dst); +} + +/** + * Copies bytes from `self` into `dst`. + * + * The cursor is advanced by the number of bytes copied. `self` must have + * enough remaining bytes to fill `dst`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * let mut dst = [0; 5]; + * + * buf.copy_to_slice(&mut dst); + * assert_eq!(&b"hello"[..], &dst); + * assert_eq!(6, buf.remaining()); + * ``` + * + * # Panics + * + * This function panics if `self.remaining() < dst.len()`. + */ +export function copyToSlice$Buf_u8s(self: rt.Place>, dst: rt.ByteSlice): void { + rt.bytesCopyToSlice(self.v, dst); +} + +/** + * Gets an IEEE754 double-precision (8 bytes) floating point number from + * `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello"[..]; + * assert_eq!(1.2f64, buf.get_f64()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getF64$Buf_Bytes(self: rt.Place>): rt.f64 { + return rt.f64FromBeBytes(rt.bytesRead(self.v, 8, false)); +} + +/** + * Gets an IEEE754 double-precision (8 bytes) floating point number from + * `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello"[..]; + * assert_eq!(1.2f64, buf.get_f64()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getF64$Buf_u8s(self: rt.Place>): rt.f64 { + return rt.f64FromBeBytes(rt.bytesRead(self.v, 8, false)); +} + +/** + * Gets a signed 128 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello"[..]; + * assert_eq!(0x01020304050607080910111213141516, buf.get_i128()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI128$Buf_Bytes(self: rt.Place>): rt.i128 { + return rt.i128FromBeBytes(rt.bytesRead(self.v, 16, false)); +} + +/** + * Gets a signed 128 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello"[..]; + * assert_eq!(0x01020304050607080910111213141516, buf.get_i128()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI128$Buf_u8s(self: rt.Place>): rt.i128 { + return rt.i128FromBeBytes(rt.bytesRead(self.v, 16, false)); +} + +/** + * Gets a signed 16 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x09\x08 hello"[..]; + * assert_eq!(0x0809, buf.get_i16_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI16Le$Buf_Bytes(self: rt.Place>): rt.i16 { + return (rt.bytesReadWord(self.v, 2, true) << 16) >> 16 as rt.i16; +} + +/** + * Gets a signed 16 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x09\x08 hello"[..]; + * assert_eq!(0x0809, buf.get_i16_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI16Le$Buf_u8s(self: rt.Place>): rt.i16 { + return (rt.bytesReadWord(self.v, 2, true) << 16) >> 16 as rt.i16; +} + +/** + * Gets a signed 32 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x09\xA0\xA1 hello"[..]; + * assert_eq!(0x0809A0A1, buf.get_i32()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI32$Buf_Bytes(self: rt.Place>): rt.i32 { + return (rt.bytesReadWord(self.v, 4, false) | 0) as rt.i32; +} + +/** + * Gets a signed 32 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x09\xA0\xA1 hello"[..]; + * assert_eq!(0x0809A0A1, buf.get_i32()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI32$Buf_u8s(self: rt.Place>): rt.i32 { + return (rt.bytesReadWord(self.v, 4, false) | 0) as rt.i32; +} + +/** + * Gets a signed 64 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..]; + * assert_eq!(0x0102030405060708, buf.get_i64_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI64Le$Buf_Bytes(self: rt.Place>): rt.i64 { + return rt.i64FromBeBytes(rt.bytesRead(self.v, 8, true)); +} + +/** + * Gets a signed 64 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..]; + * assert_eq!(0x0102030405060708, buf.get_i64_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getI64Le$Buf_u8s(self: rt.Place>): rt.i64 { + return rt.i64FromBeBytes(rt.bytesRead(self.v, 8, true)); +} + +/** + * Gets a signed 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_i8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getI8$Buf_Bytes(self: rt.Place>): rt.i8 { + return (rt.bytesReadWord(self.v, 1, false) << 24) >> 24 as rt.i8; +} + +/** + * Gets a signed 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_i8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getI8$Buf_u8s(self: rt.Place>): rt.i8 { + return (rt.bytesReadWord(self.v, 1, false) << 24) >> 24 as rt.i8; +} + +/** + * Gets a signed n-byte integer from `self` in little-endian byte order. + * + * The current position is advanced by `nbytes`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x03\x02\x01 hello"[..]; + * assert_eq!(0x010203, buf.get_int_le(3)); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`, or + * if `nbytes` is greater than 8. + */ +export function getIntLe$Buf_Bytes(self: rt.Place>, nbytes: rt.usize): rt.i64 { + return rt.i64FromBeBytes(rt.bytesReadInt(self.v, 8, nbytes, true, true)); +} + +/** + * Gets a signed n-byte integer from `self` in little-endian byte order. + * + * The current position is advanced by `nbytes`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x03\x02\x01 hello"[..]; + * assert_eq!(0x010203, buf.get_int_le(3)); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`, or + * if `nbytes` is greater than 8. + */ +export function getIntLe$Buf_u8s(self: rt.Place>, nbytes: rt.usize): rt.i64 { + return rt.i64FromBeBytes(rt.bytesReadInt(self.v, 8, nbytes, true, true)); +} + +/** + * Gets an unsigned 128 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..]; + * assert_eq!(0x01020304050607080910111213141516, buf.get_u128_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU128Le$Buf_Bytes(self: rt.Place>): rt.u128 { + return rt.u128FromBeBytes(rt.bytesRead(self.v, 16, true)); +} + +/** + * Gets an unsigned 128 bit integer from `self` in little-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..]; + * assert_eq!(0x01020304050607080910111213141516, buf.get_u128_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU128Le$Buf_u8s(self: rt.Place>): rt.u128 { + return rt.u128FromBeBytes(rt.bytesRead(self.v, 16, true)); +} + +/** + * Gets an unsigned 16 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x09 hello"[..]; + * assert_eq!(0x0809, buf.get_u16()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU16$Buf_Bytes(self: rt.Place>): rt.u16 { + return rt.bytesReadWord(self.v, 2, false) as rt.u16; +} + +/** + * Gets an unsigned 16 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08\x09 hello"[..]; + * assert_eq!(0x0809, buf.get_u16()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU16$Buf_u8s(self: rt.Place>): rt.u16 { + return rt.bytesReadWord(self.v, 2, false) as rt.u16; +} + +/** + * Gets an unsigned 32 bit integer from `self` in the little-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\xA1\xA0\x09\x08 hello"[..]; + * assert_eq!(0x0809A0A1, buf.get_u32_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU32Le$Buf_Bytes(self: rt.Place>): rt.u32 { + return rt.bytesReadWord(self.v, 4, true) as rt.u32; +} + +/** + * Gets an unsigned 32 bit integer from `self` in the little-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\xA1\xA0\x09\x08 hello"[..]; + * assert_eq!(0x0809A0A1, buf.get_u32_le()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU32Le$Buf_u8s(self: rt.Place>): rt.u32 { + return rt.bytesReadWord(self.v, 4, true) as rt.u32; +} + +/** + * Gets an unsigned 64 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08 hello"[..]; + * assert_eq!(0x0102030405060708, buf.get_u64()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU64$Buf_Bytes(self: rt.Place>): rt.u64 { + return rt.u64FromBeBytes(rt.bytesRead(self.v, 8, false)); +} + +/** + * Gets an unsigned 64 bit integer from `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08 hello"[..]; + * assert_eq!(0x0102030405060708, buf.get_u64()); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`. + */ +export function getU64$Buf_u8s(self: rt.Place>): rt.u64 { + return rt.u64FromBeBytes(rt.bytesRead(self.v, 8, false)); +} + +/** + * Gets an unsigned 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_u8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getU8$Buf_Bytes(self: rt.Place>): rt.u8 { + return rt.bytesReadWord(self.v, 1, false) as rt.u8; +} + +/** + * Gets an unsigned 8 bit integer from `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x08 hello"[..]; + * assert_eq!(8, buf.get_u8()); + * ``` + * + * # Panics + * + * This function panics if there is no more remaining data in `self`. + */ +export function getU8$Buf_u8s(self: rt.Place>): rt.u8 { + return rt.bytesReadWord(self.v, 1, false) as rt.u8; +} + +/** + * Gets an unsigned n-byte integer from `self` in big-endian byte order. + * + * The current position is advanced by `nbytes`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03 hello"[..]; + * assert_eq!(0x010203, buf.get_uint(3)); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`, or + * if `nbytes` is greater than 8. + */ +export function getUint$Buf_Bytes(self: rt.Place>, nbytes: rt.usize): rt.u64 { + return rt.u64FromBeBytes(rt.bytesReadInt(self.v, 8, nbytes, false, false)); +} + +/** + * Gets an unsigned n-byte integer from `self` in big-endian byte order. + * + * The current position is advanced by `nbytes`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"\x01\x02\x03 hello"[..]; + * assert_eq!(0x010203, buf.get_uint(3)); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining data in `self`, or + * if `nbytes` is greater than 8. + */ +export function getUint$Buf_u8s(self: rt.Place>, nbytes: rt.usize): rt.u64 { + return rt.u64FromBeBytes(rt.bytesReadInt(self.v, 8, nbytes, false, false)); +} + +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf_Bytes(self: rt.Place>): boolean { + return hasRemaining$Buf_Bytes$2(self.v); +} + /** * Returns true if there are any more bytes to consume * @@ -21,7 +798,7 @@ import * as rt from "../../rt.ts"; * assert!(!buf.has_remaining()); * ``` */ -export function hasRemaining$Buf_Bytes(self: rt.Place): boolean { +export function hasRemaining$Buf_Bytes$2(self: rt.Place): boolean { return self.v.length !== 0; } @@ -48,6 +825,83 @@ export function hasRemaining$Buf_BytesMut(self: rt.BytesMut): boolean { return self.length !== 0; } +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf_u8s(self: rt.Place): boolean { + return self.v.length !== 0; +} + +/** + * Returns true if there are any more bytes to consume + * + * This is equivalent to `self.remaining() != 0`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"a"[..]; + * + * assert!(buf.has_remaining()); + * + * buf.get_u8(); + * + * assert!(!buf.has_remaining()); + * ``` + */ +export function hasRemaining$Buf_u8s$2(self: rt.Place>): boolean { + return hasRemaining$Buf_u8s(self.v); +} + +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf_Bytes(self: rt.Place>): rt.usize { + return remaining$Buf_Bytes$2(self.v); +} + /** * Returns the number of bytes between the current position and the end of * the buffer. @@ -75,7 +929,7 @@ export function hasRemaining$Buf_BytesMut(self: rt.BytesMut): boolean { * not change unless a call is made to `advance` or any other function that * is documented to change the `Buf`'s current position. */ -export function remaining$Buf_Bytes(self: rt.Place): rt.usize { +export function remaining$Buf_Bytes$2(self: rt.Place): rt.usize { return self.v.length; } @@ -110,4 +964,66 @@ export function remaining$Buf_BytesMut(self: rt.BytesMut): rt.usize { return self.length; } +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf_u8s(self: rt.Place): rt.usize { + return self.v.length; +} + +/** + * Returns the number of bytes between the current position and the end of + * the buffer. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk()`. + * + * # Examples + * + * ``` + * use bytes::Buf; + * + * let mut buf = &b"hello world"[..]; + * + * assert_eq!(buf.remaining(), 11); + * + * buf.get_u8(); + * + * assert_eq!(buf.remaining(), 10); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining` should ensure that the return value does + * not change unless a call is made to `advance` or any other function that + * is documented to change the `Buf`'s current position. + */ +export function remaining$Buf_u8s$2(self: rt.Place>): rt.usize { + return remaining$Buf_u8s(self.v); +} + //# sourceMappingURL=buf_impl.ts.map diff --git a/ts/fixtures/stock/expected/bytes/buf/buf_mut.ts b/ts/fixtures/stock/expected/bytes/buf/buf_mut.ts new file mode 100644 index 000000000..68d97a188 --- /dev/null +++ b/ts/fixtures/stock/expected/bytes/buf/buf_mut.ts @@ -0,0 +1,597 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "../../rt.ts"; + +/** + * Returns true if there is space in `self` for more bytes. + * + * This is equivalent to `self.remaining_mut() != 0`. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 5]; + * let mut buf = &mut dst[..]; + * + * assert!(buf.has_remaining_mut()); + * + * buf.put(&b"hello"[..]); + * + * assert!(!buf.has_remaining_mut()); + * ``` + */ +export function hasRemainingMut$BufMut_BytesMut(self: rt.Place): boolean { + return remainingMut$BufMut_BytesMut(self) > 0; +} + +/** + * Returns true if there is space in `self` for more bytes. + * + * This is equivalent to `self.remaining_mut() != 0`. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 5]; + * let mut buf = &mut dst[..]; + * + * assert!(buf.has_remaining_mut()); + * + * buf.put(&b"hello"[..]); + * + * assert!(!buf.has_remaining_mut()); + * ``` + */ +export function hasRemainingMut$BufMut_Vec_u8(self: rt.Place): boolean { + return remainingMut$BufMut_Vec_u8(self) > 0; +} + +/** + * Writes a signed 128 bit integer to `self` in little-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i128_le(0x01020304050607080910111213141516); + * assert_eq!(buf, b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI128Le$BufMut_BytesMut(self: rt.Place, n: rt.i128): void { + putSlice$BufMut_BytesMut(self, rt.byteSliceFrom(rt.i128ToBeBytes(n).reverse())); +} + +/** + * Writes a signed 128 bit integer to `self` in little-endian byte order. + * + * The current position is advanced by 16. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i128_le(0x01020304050607080910111213141516); + * assert_eq!(buf, b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI128Le$BufMut_Vec_u8(self: rt.Place, n: rt.i128): void { + putSlice$BufMut_Vec_u8(self, rt.byteSliceFrom(rt.i128ToBeBytes(n).reverse())); +} + +/** + * Writes an IEEE754 double-precision (8 bytes) floating point number to + * `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_f64(1.2f64); + * assert_eq!(buf, b"\x3F\xF3\x33\x33\x33\x33\x33\x33"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putF64$BufMut_BytesMut(self: rt.Place, n: rt.f64): void { + putU64$BufMut_BytesMut(self, rt.f64ToBits(n)); +} + +/** + * Writes an IEEE754 double-precision (8 bytes) floating point number to + * `self` in big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_f64(1.2f64); + * assert_eq!(buf, b"\x3F\xF3\x33\x33\x33\x33\x33\x33"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putF64$BufMut_Vec_u8(self: rt.Place, n: rt.f64): void { + putU64$BufMut_Vec_u8(self, rt.f64ToBits(n)); +} + +/** + * Writes a signed 32 bit integer to `self` in big-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i32(0x0809A0A1); + * assert_eq!(buf, b"\x08\x09\xA0\xA1"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI32$BufMut_BytesMut(self: rt.Place, n: rt.i32): void { + rt.bytesMutPutWord(self.v, n, 4, false); +} + +/** + * Writes a signed 32 bit integer to `self` in big-endian byte order. + * + * The current position is advanced by 4. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i32(0x0809A0A1); + * assert_eq!(buf, b"\x08\x09\xA0\xA1"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI32$BufMut_Vec_u8(self: rt.Place, n: rt.i32): void { + rt.byteVecPutWord(self.v, n, 4, false); +} + +/** + * Writes a signed 8 bit integer to `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i8(0x01); + * assert_eq!(buf, b"\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI8$BufMut_BytesMut(self: rt.Place, n: rt.i8): void { + rt.bytesMutPutWord(self.v, n, 1, false); +} + +/** + * Writes a signed 8 bit integer to `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_i8(0x01); + * assert_eq!(buf, b"\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putI8$BufMut_Vec_u8(self: rt.Place, n: rt.i8): void { + rt.byteVecPutWord(self.v, n, 1, false); +} + +/** + * Transfer bytes into `self` from `src` and advance the cursor by the + * number of bytes written. + * + * `self` must have enough remaining capacity to contain all of `src`. + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 6]; + * + * { + * let mut buf = &mut dst[..]; + * buf.put_slice(b"hello"); + * + * assert_eq!(1, buf.remaining_mut()); + * } + * + * assert_eq!(b"hello\0", &dst); + * ``` + */ +export function putSlice$BufMut_BytesMut(self: rt.Place, src: rt.ByteSlice): void { + rt.bytesMutExtend(self.v, src); +} + +/** + * Transfer bytes into `self` from `src` and advance the cursor by the + * number of bytes written. + * + * `self` must have enough remaining capacity to contain all of `src`. + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 6]; + * + * { + * let mut buf = &mut dst[..]; + * buf.put_slice(b"hello"); + * + * assert_eq!(1, buf.remaining_mut()); + * } + * + * assert_eq!(b"hello\0", &dst); + * ``` + */ +export function putSlice$BufMut_Vec_u8(self: rt.Place, src: rt.ByteSlice): void { + rt.byteVecExtendFromSlice(self.v, src); +} + +/** + * Writes an unsigned 16 bit integer to `self` in little-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u16_le(0x0809); + * assert_eq!(buf, b"\x09\x08"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU16Le$BufMut_BytesMut(self: rt.Place, n: rt.u16): void { + rt.bytesMutPutWord(self.v, n, 2, true); +} + +/** + * Writes an unsigned 16 bit integer to `self` in little-endian byte order. + * + * The current position is advanced by 2. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u16_le(0x0809); + * assert_eq!(buf, b"\x09\x08"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU16Le$BufMut_Vec_u8(self: rt.Place, n: rt.u16): void { + rt.byteVecPutWord(self.v, n, 2, true); +} + +/** + * Writes an unsigned 64 bit integer to `self` in the big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u64(0x0102030405060708); + * assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU64$BufMut_BytesMut(self: rt.Place, n: rt.u64): void { + rt.bytesMutPutBytes(self.v, rt.u64ToBeBytes(n), false); +} + +/** + * Writes an unsigned 64 bit integer to `self` in the big-endian byte order. + * + * The current position is advanced by 8. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u64(0x0102030405060708); + * assert_eq!(buf, b"\x01\x02\x03\x04\x05\x06\x07\x08"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU64$BufMut_Vec_u8(self: rt.Place, n: rt.u64): void { + rt.byteVecPutBytes(self.v, rt.u64ToBeBytes(n), false); +} + +/** + * Writes an unsigned 8 bit integer to `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u8(0x01); + * assert_eq!(buf, b"\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU8$BufMut_BytesMut(self: rt.Place, n: rt.u8): void { + rt.bytesMutPutWord(self.v, n, 1, false); +} + +/** + * Writes an unsigned 8 bit integer to `self`. + * + * The current position is advanced by 1. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut buf = vec![]; + * buf.put_u8(0x01); + * assert_eq!(buf, b"\x01"); + * ``` + * + * # Panics + * + * This function panics if there is not enough remaining capacity in + * `self`. + */ +export function putU8$BufMut_Vec_u8(self: rt.Place, n: rt.u8): void { + rt.byteVecPutWord(self.v, n, 1, false); +} + +/** + * Returns the number of bytes that can be written from the current + * position until the end of the buffer is reached. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk_mut()`. + * + * Writing to a `BufMut` may involve allocating more memory on the fly. + * Implementations may fail before reaching the number of bytes indicated + * by this method if they encounter an allocation failure. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 10]; + * let mut buf = &mut dst[..]; + * + * let original_remaining = buf.remaining_mut(); + * buf.put(&b"hello"[..]); + * + * assert_eq!(original_remaining - 5, buf.remaining_mut()); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining_mut` should ensure that the return value + * does not change unless a call is made to `advance_mut` or any other + * function that is documented to change the `BufMut`'s current position. + * + * # Note + * + * `remaining_mut` may return value smaller than actual available space. + */ +export function remainingMut$BufMut_BytesMut(self: rt.Place): rt.usize { + return remainingMut$BufMut_BytesMut$2(self.v); +} + +/** + * Returns the number of bytes that can be written from the current + * position until the end of the buffer is reached. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk_mut()`. + * + * Writing to a `BufMut` may involve allocating more memory on the fly. + * Implementations may fail before reaching the number of bytes indicated + * by this method if they encounter an allocation failure. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 10]; + * let mut buf = &mut dst[..]; + * + * let original_remaining = buf.remaining_mut(); + * buf.put(&b"hello"[..]); + * + * assert_eq!(original_remaining - 5, buf.remaining_mut()); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining_mut` should ensure that the return value + * does not change unless a call is made to `advance_mut` or any other + * function that is documented to change the `BufMut`'s current position. + * + * # Note + * + * `remaining_mut` may return value smaller than actual available space. + */ +export function remainingMut$BufMut_BytesMut$2(self: rt.BytesMut): rt.usize { + return 0x7fffffff - self.length as rt.usize; +} + +/** + * Returns the number of bytes that can be written from the current + * position until the end of the buffer is reached. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk_mut()`. + * + * Writing to a `BufMut` may involve allocating more memory on the fly. + * Implementations may fail before reaching the number of bytes indicated + * by this method if they encounter an allocation failure. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 10]; + * let mut buf = &mut dst[..]; + * + * let original_remaining = buf.remaining_mut(); + * buf.put(&b"hello"[..]); + * + * assert_eq!(original_remaining - 5, buf.remaining_mut()); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining_mut` should ensure that the return value + * does not change unless a call is made to `advance_mut` or any other + * function that is documented to change the `BufMut`'s current position. + * + * # Note + * + * `remaining_mut` may return value smaller than actual available space. + */ +export function remainingMut$BufMut_Vec_u8(self: rt.Place): rt.usize { + return remainingMut$BufMut_Vec_u8$2(self.v); +} + +/** + * Returns the number of bytes that can be written from the current + * position until the end of the buffer is reached. + * + * This value is greater than or equal to the length of the slice returned + * by `chunk_mut()`. + * + * Writing to a `BufMut` may involve allocating more memory on the fly. + * Implementations may fail before reaching the number of bytes indicated + * by this method if they encounter an allocation failure. + * + * # Examples + * + * ``` + * use bytes::BufMut; + * + * let mut dst = [0; 10]; + * let mut buf = &mut dst[..]; + * + * let original_remaining = buf.remaining_mut(); + * buf.put(&b"hello"[..]); + * + * assert_eq!(original_remaining - 5, buf.remaining_mut()); + * ``` + * + * # Implementer notes + * + * Implementations of `remaining_mut` should ensure that the return value + * does not change unless a call is made to `advance_mut` or any other + * function that is documented to change the `BufMut`'s current position. + * + * # Note + * + * `remaining_mut` may return value smaller than actual available space. + */ +export function remainingMut$BufMut_Vec_u8$2(self: rt.ByteVec): rt.usize { + return 0x7fffffff - self.length as rt.usize; +} + +//# sourceMappingURL=buf_mut.ts.map diff --git a/ts/fixtures/stock/src/buf.rs b/ts/fixtures/stock/src/buf.rs index 085b91632..3ba9eb2d9 100644 --- a/ts/fixtures/stock/src/buf.rs +++ b/ts/fixtures/stock/src/buf.rs @@ -197,18 +197,41 @@ impl Buf for Pieces { } } -/// The same reads off a `Bytes`, a `BytesMut`, and a buffer in pieces: each scalar, and -/// what remains. +/// A buffer in pieces with only `Buf`'s required methods, so `copy_to_bytes` is the +/// provided one, which reads it through a `Take<&mut Self>`. +struct Provided(Pieces); + +impl Buf for Provided { + fn remaining(&self) -> usize { + self.0.remaining() + } + + fn chunk(&self) -> &[u8] { + self.0.chunk() + } + + fn advance(&mut self, cnt: usize) { + self.0.advance(cnt); + } +} + +/// The same reads off a `Bytes`, a `BytesMut`, a `&[u8]`, buffers in pieces, and each +/// through the impl forwarding through a `&mut`: each scalar, and what remains. pub fn reads(data: &[u8], out: &mut Vec) { let [kind, cut, ops @ ..] = data else { return; }; let (ops, input) = ops.split_at(ops.len() / 2); let cut = *cut as usize % (input.len() + 1); - let rest = match kind % 3 { + let rest = match kind % 8 { 0 => read_all(&mut Bytes::copy_from_slice(input), ops, read, out), 1 => read_all(&mut BytesMut::from(input), ops, read, out), - _ => read_all(&mut Pieces::new(input, cut), ops, read_pieces, out), + 2 => read_all(&mut Pieces::new(input, cut), ops, read_pieces, out), + 3 => read_all(&mut &input[..], ops, read, out), + 4 => read_all(&mut Provided(Pieces::new(input, cut)), ops, read_pieces, out), + 5 => read_all(&mut &mut Bytes::copy_from_slice(input), ops, read, out), + 6 => read_all(&mut &mut &input[..], ops, read, out), + _ => read_all(&mut &mut Pieces::new(input, cut), ops, read_pieces, out), }; out.extend_from_slice(&rest); // Put whole, chunk by chunk. @@ -223,7 +246,7 @@ pub fn reads(data: &[u8], out: &mut Vec) { /// The reads of `Buf`'s provided methods that translate for a buffer of the crate's own: /// those whose MIR reads no bytes as another type. -fn read_pieces(buf: &mut Pieces, n: usize) -> u128 { +fn read_pieces(buf: &mut B, n: usize) -> u128 { match n % 2 { 0 => buf.get_u8().into(), _ => { @@ -248,12 +271,18 @@ fn read_all(buf: &mut B, ops: &[u8], read: fn(&mut B, usize) -> u128, ou buf.copy_to_bytes(n).to_vec() } -/// The same writes into a `Vec` and a `BytesMut`, which must match. +/// The same writes into a `Vec` and a `BytesMut`, which must match, and through the +/// impl forwarding through a `&mut`. pub fn writes(data: &[u8], out: &mut Vec) { let mut vec = Vec::new(); let mut buf = BytesMut::new(); write_all(&mut vec, data); write_all(&mut buf, data); + let (mut through_vec, mut through_buf) = (Vec::new(), BytesMut::new()); + write_through(&mut &mut through_vec, data); + write_through(&mut &mut through_buf, data); + out.extend_from_slice(&through_vec); + out.extend_from_slice(&through_buf); out.push((vec == buf) as u8); out.push((vec.remaining_mut() == buf.remaining_mut()) as u8); out.push(buf.has_remaining_mut() as u8); @@ -287,6 +316,28 @@ fn write_all(buf: &mut B, data: &[u8]) { } } +/// A write by each pair of `data`'s bytes, of those that `&mut T` forwards, and of those +/// whose provided body calls only those. +fn write_through(buf: &mut B, data: &[u8]) { + let mut data = data; + while let [op, n, rest @ ..] = data { + data = rest; + let (op, n) = (*op, *n); + let v = u64::from(n) * 0x0101_0101_0101_0101; + match op % 9 { + 0 => buf.put_u8(n), + 1 => buf.put_i8(n as i8), + 2 => buf.put_u16_le(v as u16), + 3 => buf.put_i32(v as i32), + 4 => buf.put_u64(v), + 5 => buf.put_slice(&[op, n]), + 6 => buf.put_i128_le(i128::from(v) << 40), + 7 => buf.put_f64(f64::from(n) / 3.0), + _ => buf.put_u8(buf.has_remaining_mut() as u8 + (buf.remaining_mut() % 7) as u8), + } + } +} + /// `Bytes`' own edits, through a `&mut`, and `slice_ref` of a part of it. pub fn edits(data: &[u8], out: &mut Vec) { let [kind, a, rest @ ..] = data else { diff --git a/ts/fixtures/task/expected/drops/objects.ts b/ts/fixtures/task/expected/drops/objects.ts index 4cab78ef2..638742333 100644 --- a/ts/fixtures/task/expected/drops/objects.ts +++ b/ts/fixtures/task/expected/drops/objects.ts @@ -293,7 +293,7 @@ export function fns(log: Log.Log, id: rt.u32): void { }, (): void => { captured5[Symbol.dispose](); }); - const part4 = rt.place(() => slot, (value) => slot = value).v(); + const part4 = slot(); const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part4, f)]; Log.note(log, rt.fmtFormat(["slot ", args8[0]])); const captured6 = guard(6); @@ -304,7 +304,7 @@ export function fns(log: Log.Log, id: rt.u32): void { }); rt.drop(slot); slot = _88; - const part5 = rt.place(() => slot, (value2) => slot = value2).v(); + const part5 = slot(); const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part5, f)]; Log.note(log, rt.fmtFormat(["slot ", args10[0]])); const _104: [Guard.Guard, Guard.Guard] = [guard(7), guard(8)]; @@ -339,7 +339,7 @@ export function fns(log: Log.Log, id: rt.u32): void { const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part7, f)]; Log.note(log, rt.fmtFormat(["shared ", args14[0]])); other[Symbol.dispose](); - const part8 = rt.place(() => slot, (value3) => slot = value3).v(); + const part8 = slot(); const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(part8, f)]; Log.note(log, rt.fmtFormat(["slot ", args16[0]])); const captured10 = guard(10); diff --git a/ts/fixtures/task/expected/futures.ts b/ts/fixtures/task/expected/futures.ts index 43c41ac3e..eb440a605 100644 --- a/ts/fixtures/task/expected/futures.ts +++ b/ts/fixtures/task/expected/futures.ts @@ -314,9 +314,9 @@ export class boxedFuture { let captured2 = next; const captured3 = waiting; const _108: rt.Future = new rt.DynFuture(wait$boxed_closure0_closure3_u64(rt.closure((waiter: Waiter.Waiter): rt.Poll => { - return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value: rt.u64 | undefined): rt.u64 => { + return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value2: rt.u64 | undefined): rt.u64 => { Guard.note(captured3, "waited"); - return rt.u64Add(unwrapOr$Option_u64(value, 0), 2); + return rt.u64Add(unwrapOr$Option_u64(value2, 0), 2); }); }, (): void => { captured2[Symbol.dispose](); @@ -353,8 +353,8 @@ export class boxedFuture { if (!((captured6.length === 0))) { return rt.Pending; } - return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value3: rt.u64): rt.u64 => { - return rt.u64Add(captured7, value3); + return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value4: rt.u64): rt.u64 => { + return rt.u64Add(captured7, value4); }); }, (): void => { rt.dropAll(captured6); diff --git a/ts/runtime/rt/bytes.ts b/ts/runtime/rt/bytes.ts index 4bf5cef85..4aa237388 100644 --- a/ts/runtime/rt/bytes.ts +++ b/ts/runtime/rt/bytes.ts @@ -167,6 +167,50 @@ export function bytesAdvance(p: Place, cnt: usize): void { p.v = new ByteSlice(b.data, b.start + cnt, b.length - cnt); } +/** `<&[u8] as Buf>::advance`, which panics as reads past the end do. */ +export function byteSliceAdvance(p: Place, cnt: usize): void { + const b = p.v; + if (cnt > b.length) panicAdvance(cnt, b.length); + p.v = new ByteSlice(b.data, b.start + cnt, b.length - cnt); +} + +/** `<&[u8] as Buf>::copy_to_bytes`: a copy of its first `len` bytes, read past. */ +export function byteSliceCopyToBytes(p: Place, len: usize): Bytes { + const b = p.v; + if (len > b.length) panicAdvance(len, b.length); + p.v = new ByteSlice(b.data, b.start + len, b.length - len); + return bytesCopyFromSlice(new ByteSlice(b.data, b.start, len)); +} + +/** + * `Buf::copy_to_bytes` as `bytes` provides it, of a buffer read through its own methods: + * `BytesMut::put` of a `Take` of `len` of it into a new `BytesMut` of capacity `len`, which + * isn't 0 once anything remains, so it reserves and copies chunk by chunk, then freezes. + */ +export function bufCopyToBytes( + src: B, + len: usize, + remaining: (src: B) => usize, + chunk: (src: B) => ByteSlice, + advance: (src: B, cnt: usize) => void, +): Bytes { + if (remaining(src) < len) panicAdvance(len, remaining(src)); + const out = bytesMutWithCapacity(len); + let limit: number = len; + // The `Take`'s `remaining`, which reads the buffer's each time. + const left = () => Math.min(remaining(src), limit); + if (left() === 0) return bytesMutFreeze(out); + bytesMutReserve(out, left() as usize); + while (left() !== 0) { + const c = chunk(src); + const s = c.length > limit ? new ByteSlice(c.data, c.start, limit) : c; + bytesMutExtend(out, s); + advance(src, s.length as usize); + limit -= s.length; + } + return bytesMutFreeze(out); +} + /** `Buf::get_*` of `Bytes`: its first `n` bytes, the other way around if `le`, read past. */ export function bytesRead(p: Place, n: usize, le: boolean): Uint8Array { const b = p.v; diff --git a/ts/src/census.rs b/ts/src/census.rs index ca5a30f76..6351d2801 100644 --- a/ts/src/census.rs +++ b/ts/src/census.rs @@ -141,6 +141,7 @@ const VERBATIM: &[&str] = &[ ".await", "?", "Binary", + "Buf::copy_to_bytes", "BufMut::put", "Bytes::from_owner", "BytesMut", diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index fb266568c..4fff5145c 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -114,6 +114,7 @@ pub fn next<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, iter: Expr) -> Expr /// each, and the crate's own iterator what drops it. pub fn into_iter<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, value: Expr, span: Span) -> Option { let tcx = b.t.tcx; + let (ty, value) = peel_mut(ty, value); let owned = !ty.is_ref(); if b.t.iter_item(ty).is_some() { not_bound(b, ty, span); @@ -230,6 +231,21 @@ pub(super) fn iter_of<'tcx>(t: &Translator<'_, 'tcx>, ty: Ty<'tcx>) -> Option) -> bool { + matches!(*ty.kind(), ty::Ref(_, inner, ty::Mutability::Mut) if inner.is_ref()) +} + +/// `value`, a `ty`, read through each `&mut` to a `&mut`, which std's `Iterator` for `&mut I` +/// forwards through, down to the last `&mut` and its JS value. +fn peel_mut<'tcx>(mut ty: Ty<'tcx>, mut value: Expr) -> (Ty<'tcx>, Expr) { + while through_mut(ty) { + value = value.member("v"); + ty = ty.builtin_deref(true).expect("a reference"); + } + (ty, value) +} + /// Refuse iterating `ty`, an iterator, if a binding stands in for it: it is no `rt.Iter`, /// which std's adaptors and `for` take every iterator but the crate's own for. fn not_bound<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) { @@ -275,6 +291,8 @@ pub fn call<'tcx>( } return Some(Expr::rt("iterOption", args)); } + // A `&mut` to a `&mut` iterator is itself, an `rt.Place` that each use reads through. + ("IntoIterator", "into_iter") if through_mut(targ(0)?) => return args.pop(), ("IntoIterator", "into_iter") => { let value = args.pop()?; return into_iter(b, targ(0)?, value, span); @@ -337,7 +355,7 @@ pub fn call<'tcx>( let item = b.t.iter_item(self_ty.peel_refs())?; not_bound(b, self_ty, span); let mut values = args.into_iter(); - let recv = values.next()?; + let (self_ty, recv) = peel_mut(self_ty, values.next()?); let rest: Vec = values.collect(); // `next` by the protocol, as an `Option`. diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 2b36d6497..b9e4844e5 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -55,8 +55,20 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if crate::lower::iter::is_next(tcx, def_id) && dest.as_local().is_some_and(|l| self.next_results.contains(&l)) => { - let iter_ty = gargs.skip_binder().type_at(0); - let recv = self.operand_frozen(&args[0].node, span, &mut pre); + let mut iter_ty = gargs.skip_binder().type_at(0); + // Through std's `Iterator` for `&mut I`, whose `&mut` to it is an `rt.Place`: the + // place it borrows, then what each `&mut` points at. + let mut recv = match args[0].node.place() { + Some(p) if iter_ty.is_ref() => { + iter_ty = iter_ty.builtin_deref(true).expect("a reference"); + self.place_expr(tcx.mk_place_deref(p), span, &mut pre) + } + _ => self.operand_frozen(&args[0].node, span, &mut pre), + }; + while let ty::Ref(_, inner, rustc_ast::Mutability::Mut) = *iter_ty.kind() { + recv = recv.member("v"); + iter_ty = inner; + } if self.range_nexts.contains(&dest.local) && let Some(name) = self.var(dest.local) { @@ -287,13 +299,19 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if let ty::FnDef(inner, inner_args) = *callee_ty.peel_refs().kind() { return self.b.call_def(inner, inner_args.skip_binder(), values, span, out); } - // A `&mut` to a function JS copies, such as a box of one, is its place: call what is there. - let f = match callee.node.place() { + // A `&mut` to a function JS copies, such as a box of one, is its place: call what is + // there, through each `&mut` std's impls for one forward through. + let mut f = match callee.node.place() { Some(p) if self.b.t.place_pointee(p.ty(&self.mir.local_decls, tcx).ty).is_some() => { self.place_expr(tcx.mk_place_deref(p), span, out) } _ => self.operand(&callee.node, span, out), }; + let mut through = callee_ty; + while let Some(inner) = self.b.t.place_pointee(through) { + f = f.member("v"); + through = inner; + } // `FnOnce::call_once` of a closure that `Fn` or `FnMut` call, or of a box of one, // drops it after, as rustc's shim does, where an `FnOnce` closure's body drops // what it owns. diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 6db80de7a..664e575ef 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -3172,13 +3172,20 @@ fn subst(e: &mut Expr, name: &str, value: &Expr) -> bool { return false; } // The payload of a `Result` made here is what it was made of, which `tsc` reads - // where it can't narrow the `Result`. - if let (Expr::Call(f, args), ts::Key::Name(key)) = (step::peel(base), &*key) - && let Expr::Rt(ctor) = step::peel(f) - && matches!((ctor.as_str(), key.as_str()), ("Ok", "value") | ("Err", "error")) - && let [payload] = args.as_slice() - { - *e = payload.clone(); + // where it can't narrow the `Result`, and so is what an `rt.Place` made here holds. + let folded = match (step::peel(base), &*key) { + (Expr::Call(f, args), ts::Key::Name(key)) + if let Expr::Rt(ctor) = step::peel(f) + && matches!((ctor.as_str(), key.as_str()), ("Ok", "value") | ("Err", "error")) + && let [payload] = args.as_slice() => + { + Some(payload.clone()) + } + (base, ts::Key::Name(key)) if key == "v" => base.place_read().cloned(), + _ => None, + }; + if let Some(folded) = folded { + *e = folded; } true } diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 8c1227cf0..6785ba329 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -1170,15 +1170,14 @@ 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, - /// or an object its clones may share, as an `Arc`'s and a `Waker`'s are, pinned or boxed - /// too, which JS erases, 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. + /// Whether a JS value of `ty` is a copy that no JS value can point at, such as a number + /// or a reference, or an object its clones may share, as an `Arc`'s and a `Waker`'s are, + /// pinned or boxed too, which JS erases, so a `&mut` to it is an `rt.Place`: where the + /// value is, read and written through `v`. pub fn needs_place(&self, ty: Ty<'tcx>) -> bool { use library::Std; if self.object_kind(ty).is_none() { - return !ty.is_ref(); + return true; } let mut erased = ty; while let ty::Adt(adt, args) = erased.kind() @@ -1237,13 +1236,6 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { 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, - format!("`{ty}`: a JS value of `{inner}` is a copy, so a reference can't change it"), - ); - Type::Builtin("unknown") - } ty::RawPtr(inner, _) => self.pointer_ty(*inner, span), ty::Ref(..) if bytes_ref(ty) => Type::Rt("ByteSlice", vec![]), ty::Ref(_, inner, _) => self.ty(*inner, span), diff --git a/ts/src/lower/stock.rs b/ts/src/lower/stock.rs index b64c547e2..ec061184d 100644 --- a/ts/src/lower/stock.rs +++ b/ts/src/lower/stock.rs @@ -1,9 +1,9 @@ //! Well-known crates that translation maps itself, as it maps std, so a consumer binds //! none of them: `bytes`' `Bytes`, which is the `rt.ByteSlice` a `&[u8]` is, and //! `BytesMut`, which is `rt.BytesMut`, and `rand`'s thread-local generator, which draws -//! from the platform's cryptographic source. The rest of `bytes`, such as `Buf`'s provided -//! methods of the crate's own buffers, translates from its MIR. `tracing`'s events are -//! left out where they are written, by [`super::Translator::ignored_site`]. +//! from the platform's cryptographic source. The rest of `bytes`, such as most of `Buf`'s +//! provided methods of the crate's own buffers, translates from its MIR. `tracing`'s +//! events are left out where they are written, by [`super::Translator::ignored_site`]. use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId}; @@ -65,13 +65,18 @@ pub fn mapped(tcx: TyCtxt<'_>, did: DefId) -> bool { /// Whether `instance`, a provided method of `Buf` or `BufMut`, maps for its `Self`, which /// [`mapped`] can't tell from the method alone: one the mapping names, of a buffer whose -/// impl maps. The others lower from their MIR, as for the crate's own buffers. +/// impl maps, and `copy_to_bytes` of any other, whose `BytesMut::put` reads a capacity. +/// The others lower from their MIR, as for the crate's own buffers. pub fn maps<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool { let did = instance.def_id(); - tcx.crate_name(did.krate).as_str() == "bytes" - && tcx.trait_of_assoc(did).is_some() - && mapped_self(tcx, instance.args.type_at(0)) - && (BUF.contains(&tcx.item_name(did).as_str()) || BUF_MUT.contains(&tcx.item_name(did).as_str())) + if tcx.crate_name(did.krate).as_str() != "bytes" || tcx.trait_of_assoc(did).is_none() { + return false; + } + let name = tcx.item_name(did); + match mapped_self(tcx, instance.args.type_at(0)) { + true => BUF.contains(&name.as_str()) || BUF_MUT.contains(&name.as_str()), + false => name.as_str() == "copy_to_bytes", + } } /// `Buf`'s methods that the mapping names for its buffers. @@ -169,7 +174,7 @@ enum Buffer { /// A `Bytes`, whose `&mut` is an `rt.Place`. Bytes, BytesMut, - /// A `&[u8]`, which `Buf` reads through `&self` only: a `&mut` to it is refused. + /// A `&[u8]`, whose `&mut` is an `rt.Place` too. Slice, /// A `Vec`, which `BufMut` writes. Vec, @@ -322,7 +327,12 @@ fn bytes<'tcx>( Some(Std::BytesMut) => return bytes_mut(b, call, name, args, out), _ => {} } - let buffer = Buffer::of(tcx, targ(call.args, 0))?; + let Some(buffer) = Buffer::of(tcx, targ(call.args, 0)) else { + return match (owner, name) { + ("Buf", "copy_to_bytes") => provided_copy_to_bytes(b, call, args), + _ => None, + }; + }; match owner { "Buf" => buf(b, call, buffer, name, args), "BufMut" => buf_mut(b, call, buffer, name, args), @@ -434,12 +444,12 @@ fn buf<'tcx>( ) -> Option { let mut args = args.into_iter(); let this = args.next()?; - // What reads past the front: a `Bytes`'s place, or a `BytesMut`. A `&[u8]`'s would be a - // `&mut` to a reference, which is not supported yet. + // What reads past the front: a `Bytes`'s or a `&[u8]`'s place, which `bytes` reads + // alike but to advance and copy out, or a `BytesMut`. let prefix = match buffer { - Buffer::Bytes => Some("bytes"), + Buffer::Bytes | Buffer::Slice => Some("bytes"), Buffer::BytesMut => Some("bytesMut"), - Buffer::Slice | Buffer::Vec => None, + Buffer::Vec => None, }; let rt = |f: &str, args: Vec| Some(Expr::rt(format!("{}{f}", prefix?), args)); Some(match name { @@ -447,12 +457,14 @@ fn buf<'tcx>( "has_remaining" => this.member("length").binary("!==", Expr::lit("0")), "chunk" if buffer == Buffer::BytesMut => view(this), "chunk" => this, + "advance" if buffer == Buffer::Slice => Expr::rt("byteSliceAdvance", vec![this, args.next()?]), "advance" => rt("Advance", vec![this, args.next()?])?, "copy_to_slice" => rt("CopyToSlice", vec![this, args.next()?])?, "copy_to_bytes" if buffer == Buffer::BytesMut => Expr::rt( "bytesMutFreeze", vec![Expr::rt("bytesMutSplitTo", vec![this, args.next()?])], ), + "copy_to_bytes" if buffer == Buffer::Slice => Expr::rt("byteSliceCopyToBytes", vec![this, args.next()?]), "copy_to_bytes" => rt("SplitTo", vec![this, args.next()?])?, _ => { let (ty, le) = scalar(name.strip_prefix("get_")?); @@ -567,24 +579,11 @@ fn put<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, buffer: Buffer, this ); return Some(b.err(call.span, msg)); } - let buf = tcx - .traits(call.def_id.krate) - .iter() - .copied() - .find(|&tr| tcx.item_name(tr).as_str() == "Buf")?; - let mut method = |name: &str| { - let f = tcx - .associated_items(buf) - .in_definition_order() - .find(|i| i.is_fn() && i.name().as_str() == name)? - .def_id; - Some(b.fn_value(f, tcx.mk_args(&[ty.into()]), call.span)) - }; let (has, remaining, chunk, advance) = ( - method("has_remaining")?, - method("remaining")?, - method("chunk")?, - method("advance")?, + buf_method(b, call, ty, "has_remaining")?, + buf_method(b, call, ty, "remaining")?, + buf_method(b, call, ty, "chunk")?, + buf_method(b, call, ty, "advance")?, ); Some(Expr::rt( "byteVecPutBuf", @@ -592,6 +591,41 @@ fn put<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, buffer: Buffer, this )) } +/// `Buf::copy_to_bytes` as `bytes` provides it, of a buffer the mapping doesn't read: it +/// puts a `Take` of the buffer into a new `BytesMut` of the capacity asked for, which +/// copies chunk by chunk through the buffer's own methods, as the runtime does. +fn provided_copy_to_bytes<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec) -> Option { + let ty = targ(call.args, 0); + if b.t.needs_place(ty) { + let msg = format!("`Buf::copy_to_bytes` of `{ty}`, a value JS copies, which is not supported"); + return Some(b.err(call.span, msg)); + } + let mut args = args.into_iter(); + let (this, len) = (args.next()?, args.next()?); + let (remaining, chunk, advance) = ( + buf_method(b, call, ty, "remaining")?, + buf_method(b, call, ty, "chunk")?, + buf_method(b, call, ty, "advance")?, + ); + Some(Expr::rt("bufCopyToBytes", vec![this, len, remaining, chunk, advance])) +} + +/// The function value of `Buf`'s method `name` for the buffer `ty`, of the crate `call` is to. +fn buf_method<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, ty: Ty<'tcx>, name: &str) -> Option { + let tcx = b.t.tcx; + let buf = tcx + .traits(call.def_id.krate) + .iter() + .copied() + .find(|&tr| tcx.item_name(tr).as_str() == "Buf")?; + let f = tcx + .associated_items(buf) + .in_definition_order() + .find(|i| i.is_fn() && i.name().as_str() == name)? + .def_id; + Some(b.fn_value(f, tcx.mk_args(&[ty.into()]), call.span)) +} + /// A `get_` or `put_` method's scalar, and whether its bytes are little-endian, as /// wasm32's native order is. fn scalar(name: &str) -> (&str, bool) { diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index 265dbc08c..af6fcddac 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -290,6 +290,12 @@ pub fn call<'tcx>( // A box's JS value is what it holds. ("Box", "pin") => first(args), ("Future", "poll") => match self_ty.map(Ty::kind) { + // A `&mut` polls what it points at, whose pinned `&mut` is an `rt.Place` of it. + Some(ty::Ref(_, inner, _)) => { + let [future, cx] = two(args); + let args = vec![future.member("v"), cx]; + b.call_def(call.def_id, tcx.mk_args(&[(*inner).into()]), args, call.span, out) + } // std's futures and a `dyn Future` are `rt.Future`s, which poll themselves. _ if matches!(self_std, Some(Std::PollFn | Std::Pending)) || self_ty.is_some_and(|ty| b.t.dyn_future(ty).is_some()) => @@ -297,8 +303,7 @@ pub fn call<'tcx>( let [future, cx] = two(args); future.member("poll").call(vec![cx]) } - // A pinned pointer, a box, or a `&mut` polls what it points at, which its JS - // value is. + // A pinned pointer or a box polls what it points at, which its JS value is. Some(ty::Adt(adt, adt_args)) if matches!(Std::of(tcx, adt.did()), Some(Std::Pin | Std::Box)) => { let inner = match Std::of(tcx, adt.did()) { Some(Std::Pin) => adt_args.type_at(0).builtin_deref(true), @@ -307,9 +312,6 @@ pub fn call<'tcx>( let Some(inner) = inner else { return Err(args) }; b.call_def(call.def_id, tcx.mk_args(&[inner.into()]), args, call.span, out) } - Some(ty::Ref(_, inner, _)) => { - b.call_def(call.def_id, tcx.mk_args(&[(*inner).into()]), args, call.span, out) - } _ => return Err(args), }, ("Context", "waker" | "from_waker") diff --git a/ts/src/ts.rs b/ts/src/ts.rs index d31ce0f19..4963ec0de 100644 --- a/ts/src/ts.rs +++ b/ts/src/ts.rs @@ -77,6 +77,15 @@ impl Expr { Self::Member(Box::new(self), Key::Name(name.into())) } + /// What `self` reads, if it is an `rt.Place` made here: `rt.place(() => read, set)`. + pub fn place_read(&self) -> Option<&Expr> { + let Self::Call(f, args) = self else { return None }; + match (&**f, args.as_slice()) { + (Self::Rt(name), [Self::Lambda(params, read), _]) if name == "place" && params.is_empty() => Some(read), + _ => None, + } + } + pub fn field(self, field: FieldId) -> Self { Self::Member(Box::new(self), Key::Field(field)) } From 310fd04a6e8ac2f3f16e54e2dff569f18946a99e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:22:20 -0700 Subject: [PATCH 3/9] test(ts): a &mut to a slice reference taken and moved past by a closure Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/refs.ts | 50 +++++++++++++++++++------------ ts/fixtures/lang/src/refs.rs | 12 ++++++++ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 3a82e720e..49b78b671 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -1148,12 +1148,12 @@ export function nextTwo$Copied_Iter_u8$2(it: rt.Iter): rt.u8 { } /** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ -export function callTwice$to_refs_closure2(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { +export function callTwice$to_refs_closure3(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { return rt.u8WrappingAdd(f.v(1), f.v(2)); } /** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ -export function callTwice$to_refs_closure2$2(f: (a0: rt.u8) => rt.u8): rt.u8 { +export function callTwice$to_refs_closure3$2(f: (a0: rt.u8) => rt.u8): rt.u8 { return rt.u8WrappingAdd(f(1), f(2)); } @@ -1209,13 +1209,25 @@ export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { const old2 = b3; b3 = rt.byteSliceFrom(Uint8Array.of()); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.length & 0xff, b3.length & 0xff, old2.length & 0xff))); + const taken2 = a; + a = rt.byteSliceFrom(new Uint8Array(0)); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.length & 0xff, taken2.length & 0xff))); + let left: rt.ByteSlice = rt.byteSliceRange(data, 1); + const skip_: (a0: rt.usize) => rt.usize = (n2: rt.usize): rt.usize => { + const at: rt.usize = rt.min(n2, left.length); + left = rt.byteSliceRange(left, at); + return at; + }; + rt.byteVecPush(out, skip_(rt.usizeRem(n, 3)) & 0xff); + rt.byteVecPush(out, skip_(1) & 0xff); + rt.byteVecPush(out, left.length & 0xff); const pairs: Pair.Pair[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))), (_22: rt.u8): Pair.Pair => { return { n: _22 }; })); const first: Pair.Pair = { n: 0 }; let largest: Pair.Pair = first; - for (const _117 of pairs) { - keepLarger(rt.place(() => largest, (value3) => largest = value3), _117); + for (const _147 of pairs) { + keepLarger(rt.place(() => largest, (value3) => largest = value3), _147); } rt.byteVecPush(out, largest.n); let x: rt.u32 = 0; @@ -1227,26 +1239,26 @@ export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(y))); let count: rt.u32 = 0; const pair: Pair.Pair = { n: 1 }; - let _152: rt.Place = rt.place(() => count, (value7) => count = value7); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32$2(rt.place(() => _152, (value8) => _152 = value8), rt.byteSliceRange(data, 1))))); - let _159: Pair.Pair = pair; - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$Pair(rt.place(() => _159, (value9) => _159 = value9), rt.byteSliceRange(data, 1))))); - let _167: rt.Place = rt.place(() => count, (value10) => count = value10); - let _166: rt.Place> = rt.place(() => _167, (value11) => _167 = value11); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32(rt.place(() => _166, (value12) => _166 = value12), rt.byteSliceRange(data, 1))))); + let _182: rt.Place = rt.place(() => count, (value7) => count = value7); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32$2(rt.place(() => _182, (value8) => _182 = value8), rt.byteSliceRange(data, 1))))); + let _189: Pair.Pair = pair; + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$Pair(rt.place(() => _189, (value9) => _189 = value9), rt.byteSliceRange(data, 1))))); + let _197: rt.Place = rt.place(() => count, (value10) => count = value10); + let _196: rt.Place> = rt.place(() => _197, (value11) => _197 = value11); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32(rt.place(() => _196, (value12) => _196 = value12), rt.byteSliceRange(data, 1))))); rt.byteVecPush(out, pair.n); const it: rt.Iter = rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))); rt.byteVecPush(out, nextTwo$Copied_Iter_u8$2(it)); - let _178: rt.Iter = it; - rt.byteVecPush(out, nextTwo$Copied_Iter_u8(rt.place(() => _178, (value13) => _178 = value13))); + let _208: rt.Iter = it; + rt.byteVecPush(out, nextTwo$Copied_Iter_u8(rt.place(() => _208, (value13) => _208 = value13))); let r2: rt.Iter = it; const iter3: rt.Place> = rt.place(() => r2, (value14) => r2 = value14); while (true) { - const _183: rt.u8 | rt.Done = iter3.v.next(); - if (_183 === rt.DONE) { + const _213: rt.u8 | rt.Done = iter3.v.next(); + if (_213 === rt.DONE) { break; } - const b4: rt.u8 = _183; + const b4: rt.u8 = _213; if (!(rt.u8Rem(b4, 3) === 0)) { rt.byteVecPush(out, b4); } else { @@ -1259,9 +1271,9 @@ export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { calls = rt.u8WrappingAdd(calls, b6); return calls; }; - rt.byteVecPush(out, callTwice$to_refs_closure2$2(counted)); - let _204: (a0: rt.u8) => rt.u8 = counted; - rt.byteVecPush(out, callTwice$to_refs_closure2(rt.place(() => _204, (value15) => _204 = value15))); + rt.byteVecPush(out, callTwice$to_refs_closure3$2(counted)); + let _234: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$to_refs_closure3(rt.place(() => _234, (value15) => _234 = value15))); } } diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index 2bc029632..580728a65 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -813,6 +813,18 @@ pub fn to_refs(data: &[u8], out: &mut Vec) { std::mem::swap(&mut a, &mut b); let old = std::mem::replace(&mut b, &[]); out.extend_from_slice(&[a.len() as u8, b.len() as u8, old.len() as u8]); + let taken = std::mem::take(&mut a); + out.extend_from_slice(&[a.len() as u8, taken.len() as u8]); + // Moved past by a closure that captured it by `&mut`. + let mut left = rest; + let mut skip = |n: usize| { + let at = n.min(left.len()); + left = &left[at..]; + at + }; + out.push(skip(n % 3) as u8); + out.push(skip(1) as u8); + out.push(left.len() as u8); // A reference to an object, replaced. let pairs: Vec = rest.iter().map(|&n| Pair { n }).collect(); let first = Pair { n: 0 }; From 7367a13beece555fa111be7c34c7eb4ffea04fe7 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:28:24 -0700 Subject: [PATCH 4/9] chore(quest): finish ts-mut-ref, plan returning a std iterator's next Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 2 +- quest/m3/ts-mut-ref.md | 25 ------------------------- quest/m3/ts-next-return.md | 15 +++++++++++++++ quest/m3/ts-unsafe.md | 4 ++-- 4 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 quest/m3/ts-mut-ref.md create mode 100644 quest/m3/ts-next-return.md diff --git a/quest/m3/README.md b/quest/m3/README.md index 0d20fa142..c49af489d 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -17,7 +17,6 @@ generic std gap is planned here even when moq never calls it. - [Relink without rebuilding](/quest/m3/relink.md) - measure upstream's skip of dependency-only rebuilds on moq's edits once it reaches nightly - [Unsafe code the translator can model](/quest/m3/ts-unsafe.md) - a dependency using only `unsafe` the translator can model translates from source - [f32](/quest/m3/ts-f32.md) - `f32` and `Duration`'s `f32` methods translate as `f64` does -- [A mutable reference to a reference](/quest/m3/ts-mut-ref.md) - `&mut &[u8]` and `&mut &mut T` translate, so `Buf` of a `&[u8]` and `bytes`' forwarding impls do - [The capacity of a BytesMut](/quest/m3/ts-bytes-capacity.md) - `BytesMut::capacity` and what reads it translate with `bytes`' values - [Trait objects](/quest/m3/ts-dyn.md) - `dyn Error`, `dyn Iterator`, and `dyn Buf` translate, so a consumer neither rewrites nor binds them - [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library @@ -28,6 +27,7 @@ generic std gap is planned here even when moq never calls it. - [Ordering in std](/quest/m3/ts-ordering.md) - `cmp::max`/`min`, `is_sorted`, and `BinaryHeap`, and #173's cost on integers measured - [Arc's unique-access functions](/quest/m3/ts-arc-mut.md) - `Arc::get_mut`, `make_mut`, `pin`, and `as_deref` of an `Option` translate - [Debug and Display of Arc and ranges](/quest/m3/ts-fmt-wrappers.md) - `Arc` formats as `T`, and ranges as std's `Debug` +- [Return a std iterator's next from a generic function](/quest/m3/ts-next-return.md) - `it.next()` returned from a generic function is an `Option`, as `tsc` expects - [Fold a match a bool decided](/quest/m3/ts-fold-bool.md) - `if matches!` and derived `==` drop a later match's dead arms - [Rename one instance](/quest/m3/ffi-instance-rename.md) - `rename` by an instance's path, once a consumer's clash needs it - [Into targets through a chain of From implementations](/quest/m3/ffi-from-chains.md) - `sources` follows more than one level, once a consumer's parameter needs it diff --git a/quest/m3/ts-mut-ref.md b/quest/m3/ts-mut-ref.md deleted file mode 100644 index cf0f2fab0..000000000 --- a/quest/m3/ts-mut-ref.md +++ /dev/null @@ -1,25 +0,0 @@ -# [M] A mutable reference to a reference - -## Goal - -[rust2-ts](/ts/README.md) translates a `&mut` to a reference, such as `&mut &[u8]` and -`&mut &mut T`, proven by differential tests against native Rust. Then `bytes`' `Buf` of a -`&[u8]` advances, the `Buf` and `BufMut` impls forwarding through `&mut T` translate from -`bytes`' MIR, and so does `Buf::copy_to_bytes` of a crate's own buffer, which reads it -through a `Take<&mut Self>`. - -## Plan - -Found by [#222](https://github.com/kixelated/rust2/pull/222) on 2026-10-29: a `&mut` to a -type JS copies is an `rt.Place`, but a reference is never one, so `&mut &[u8]` is refused -where it is made. moq-net's census refuses `<&mut &[u8] as Buf>::remaining` and -`has_remaining` and `<&[u8] as Buf>::copy_to_bytes` in `transport/memory.rs`, which writes -a `&[u8]` through `poll_write_buf`. - -- Writing a whole reference through it, `*r = &r[n..]`, is what `<&[u8] as Buf>::advance` - does, so a place of the reference is the likely shape, as for a value JS copies. -- Where only what the inner reference points at is read or written, as the forwarding - impls do, the outer reference could be the inner one's value instead. Measure whether - the codec's decode on the [TS benchmark](/ts/README.md#bench) cares. - -Public API: the translator's output. diff --git a/quest/m3/ts-next-return.md b/quest/m3/ts-next-return.md new file mode 100644 index 000000000..8fe098f83 --- /dev/null +++ b/quest/m3/ts-next-return.md @@ -0,0 +1,15 @@ +# [S] Return a std iterator's next from a generic function + +## Goal + +rust2-ts translates a generic function that returns `next` of a std iterator it was given, +`fn first>(mut it: I) -> Option { it.next() }` with `I` a +`Copied>`, proven by a differential test against native Rust. + +## Plan + +Found while testing `&mut &mut I` on 2026-10-29: the translation is `return it.next();`, +the protocol's item or `rt.DONE` rather than the `Option` the signature declares, so `tsc` +refuses it. A `next` read into a local first, as `it.next().unwrap_or(0)`, converts. + +Public API: the translator's output. diff --git a/quest/m3/ts-unsafe.md b/quest/m3/ts-unsafe.md index 5ffab38ef..e078e4319 100644 --- a/quest/m3/ts-unsafe.md +++ b/quest/m3/ts-unsafe.md @@ -43,7 +43,7 @@ none of its own `unsafe`. ([#222](https://github.com/kixelated/rust2/pull/222)): the bytes keep their type, so this reinterprets nothing. Those getters also need `<[u8]>::get` and `get_mut` of a range, and each integer's `from_le_bytes` and `from_ne_bytes`, and `chunks_vectored` - needs `std::io::IoSlice`: 184 of moq-net's 197 refusals in `bytes`, the rest being 12 - of [`f32`](/quest/m3/ts-f32.md) and one of [`&mut &[u8]`](/quest/m3/ts-mut-ref.md). + needs `std::io::IoSlice`: 184 of moq-net's 196 refusals in `bytes`, the rest being 12 + of [`f32`](/quest/m3/ts-f32.md). Public API: the translator's output. From 94bf2fb6bf357b170ffdae36bea6191bbdc13bc3 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:34:13 -0700 Subject: [PATCH 5/9] fix(ts): box a dyn Future of a &mut to a &mut through its place Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/task/expected/futures.ts | 171 +++++++++++++++------------ ts/fixtures/task/src/futures.rs | 7 +- ts/src/lower/task.rs | 11 +- 3 files changed, 110 insertions(+), 79 deletions(-) diff --git a/ts/fixtures/task/expected/futures.ts b/ts/fixtures/task/expected/futures.ts index eb440a605..ac1c19602 100644 --- a/ts/fixtures/task/expected/futures.ts +++ b/ts/fixtures/task/expected/futures.ts @@ -172,7 +172,7 @@ export function relayed(task: rt.Waker, log: Log.Log, id: rt.u32): rt.Waker { /** * Boxed futures over a channel: `Box::pin` of an async fn, awaited, and of a `&mut` to a - * `poll_fn`, whose box drops without dropping it, then a queue of + * `poll_fn` and to a `&mut` to it, whose box drops without dropping it, then a queue of * `Pin>`s of an async block, kio's `Pending`, a struct of the crate's, * and a `poll_fn`, each owning a guard. A `poll_fn` boxed in a [`Forward`] polls the * queue in turn through [`poll_unsized`], as moq's tasks do through kio's @@ -193,10 +193,11 @@ export class boxedFuture { #id!: rt.u32; #log!: Log.Log; #lend!: rt.Future; - #lent!: rt.u64; #awaitee$2!: rt.Future; + #lent!: rt.u64; + #awaitee$3!: rt.Future; #pinned!: Pending.Pending<(a0: Waiter.Waiter) => rt.Poll>; - #awaitee$3!: Forward.Forward; + #awaitee$4!: Forward.Forward; #saved!: boolean; #saved$2!: boolean; @@ -218,9 +219,11 @@ export class boxedFuture { } if (this.#state === 4) { rt.drop(this.#awaitee$2); - } else if (this.#state !== 5) { - if (this.#state === 6) { - this.#awaitee$3[Symbol.dispose](); + } else if (this.#state === 5) { + rt.drop(this.#awaitee$3); + } else if (this.#state !== 6) { + if (this.#state === 7) { + this.#awaitee$4[Symbol.dispose](); this.#pinned[Symbol.dispose](); } else { return; @@ -243,87 +246,105 @@ export class boxedFuture { b0: { b1: { b2: { - if (this.#state === 0) { - this.#saved$2 = false; - this.#saved = false; - this.#saved$2 = true; - this.#awaitee = new recvFuture(this.#rx); - } else if (this.#state === 1) { - rt.asyncFnResumed(); - } else if (this.#state !== 3) { - if (this.#state === 4) { - break b2; + b3: { + if (this.#state === 0) { + this.#saved$2 = false; + this.#saved = false; + this.#saved$2 = true; + this.#awaitee = new recvFuture(this.#rx); + } else if (this.#state === 1) { + rt.asyncFnResumed(); + } else if (this.#state !== 3) { + if (this.#state === 4) { + break b3; + } + if (this.#state === 5) { + break b2; + } + if (this.#state === 6) { + break b1; + } + break b0; } - if (this.#state === 5) { - break b1; + const _7: rt.Poll = this.#awaitee.poll(_2); + if (_7 !== rt.Pending) { + const result: rt.u64 | undefined = _7; + rt.drop(this.#awaitee); + this.#first = unwrapOr$Option_u64(result, 0); + const arg = this.#first; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; + const _17: string = rt.fmtFormat(["first ", args2[0]]); + Guard.note(this.#guard, _17); + const _28: [rt.u32, Log.Log] = [Guard.id(this.#guard), Log.clone$Clone(Guard.log(this.#guard))]; + this.#id = _28[0]; + this.#log = _28[1]; + const captured = Guard.new(rt.u32Add(this.#id, 900), Log.clone$Clone(this.#log)); + this.#lend = new rt.PollFn(rt.closure((_22: rt.Context): rt.Poll => { + Guard.note(captured, "lent"); + return 4; + }, (): void => { + captured[Symbol.dispose](); + }), rt.drop); + this.#saved = true; + this.#awaitee$2 = new rt.DynFuture(this.#lend, rt.futurePoll); + } else { + this.#state = 3; + return rt.Pending; } - break b0; } - const _7: rt.Poll = this.#awaitee.poll(_2); - if (_7 !== rt.Pending) { - const result: rt.u64 | undefined = _7; - rt.drop(this.#awaitee); - this.#first = unwrapOr$Option_u64(result, 0); - const arg = this.#first; - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; - const _17: string = rt.fmtFormat(["first ", args2[0]]); - Guard.note(this.#guard, _17); - const _28: [rt.u32, Log.Log] = [Guard.id(this.#guard), Log.clone$Clone(Guard.log(this.#guard))]; - this.#id = _28[0]; - this.#log = _28[1]; - const captured = Guard.new(rt.u32Add(this.#id, 900), Log.clone$Clone(this.#log)); - this.#lend = new rt.PollFn(rt.closure((_22: rt.Context): rt.Poll => { - Guard.note(captured, "lent"); - return 4; - }, (): void => { - captured[Symbol.dispose](); - }), rt.drop); - this.#saved = true; - this.#awaitee$2 = new rt.DynFuture(this.#lend, rt.futurePoll); + const _45: rt.Poll = this.#awaitee$2.poll(_2); + if (_45 !== rt.Pending) { + const lent2: rt.u64 = _45; + rt.drop(this.#awaitee$2); + this.#awaitee$2 = this.#lend; + const twice: rt.Future = new rt.DynFuture(this.#awaitee$2, rt.futurePoll); + this.#lent = lent2; + this.#awaitee$3 = twice; } else { - this.#state = 3; + this.#state = 4; return rt.Pending; } } - const _45: rt.Poll = this.#awaitee$2.poll(_2); - if (_45 !== rt.Pending) { - this.#lent = _45; - rt.drop(this.#awaitee$2); - this.#awaitee$2 = this.#lend; + const _57: rt.Poll = this.#awaitee$3.poll(_2); + if (_57 !== rt.Pending) { + const result2: rt.u64 = _57; + rt.drop(this.#awaitee$3); + this.#lent = rt.u64Add(this.#lent, result2); + this.#awaitee$3 = this.#lend; } else { - this.#state = 4; + this.#state = 5; return rt.Pending; } } - const _55: rt.Poll = this.#awaitee$2.poll(_2); - if (_55 !== rt.Pending) { - this.#lent = rt.u64Add(this.#lent, _55); + const _68: rt.Poll = this.#awaitee$3.poll(_2); + if (_68 !== rt.Pending) { + this.#lent = rt.u64Add(this.#lent, _68); const arg2 = this.#lent; const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg2, f)]; - const _66: string = rt.fmtFormat(["lent ", args4[0]]); - Guard.note(this.#guard, _66); + const _79: string = rt.fmtFormat(["lent ", args4[0]]); + Guard.note(this.#guard, _79); this.#saved = false; this.#lend[Symbol.dispose](); - const _82: [Guard.Guard, Guard.Guard, Guard.Guard] = [Guard.new(rt.u32Add(this.#id, 500), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 600), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 700), Log.clone$Clone(this.#log))]; - const block: Guard.Guard = _82[0]; - const waiting: Guard.Guard = _82[1]; - const ready: Guard.Guard = _82[2]; + const _95: [Guard.Guard, Guard.Guard, Guard.Guard] = [Guard.new(rt.u32Add(this.#id, 500), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 600), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 700), Log.clone$Clone(this.#log))]; + const block: Guard.Guard = _95[0]; + const waiting: Guard.Guard = _95[1]; + const ready: Guard.Guard = _95[2]; const next: Consumer.Consumer = Consumer.clone$Clone(this.#rx); this.#saved$2 = false; - const _105: rt.Future = new boxedFuture$2(this.#rx, block); + const _118: rt.Future = new boxedFuture$2(this.#rx, block); let captured2 = next; const captured3 = waiting; - const _108: rt.Future = new rt.DynFuture(wait$boxed_closure0_closure3_u64(rt.closure((waiter: Waiter.Waiter): rt.Poll => { - return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value2: rt.u64 | undefined): rt.u64 => { + const _121: rt.Future = new rt.DynFuture(wait$boxed_closure0_closure3_u64(rt.closure((waiter: Waiter.Waiter): rt.Poll => { + return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value3: rt.u64 | undefined): rt.u64 => { Guard.note(captured3, "waited"); - return rt.u64Add(unwrapOr$Option_u64(value2, 0), 2); + return rt.u64Add(unwrapOr$Option_u64(value3, 0), 2); }); }, (): void => { captured2[Symbol.dispose](); captured3[Symbol.dispose](); })), Pending.poll$Future_boxed_closure0_closure3, rt.drop); const captured4 = ready; - const queue: rt.Future[] = [_105, _108, new rt.PollFn(rt.closure((_23: rt.Context): rt.Poll => { + const queue: rt.Future[] = [_118, _121, new rt.PollFn(rt.closure((_23: rt.Context): rt.Poll => { Guard.note(captured4, "ready"); return 3; }, (): void => { @@ -339,12 +360,12 @@ export class boxedFuture { let captured6 = queue; let captured7: rt.u64 = 0; let captured8 = last; - this.#awaitee$3 = new Forward.Forward(new rt.PollFn(rt.closure((cx: rt.Context): rt.Poll => { + this.#awaitee$4 = new Forward.Forward(new rt.PollFn(rt.closure((cx: rt.Context): rt.Poll => { let i: rt.usize = 0; while (i < captured6.length) { - const _88: rt.Poll = pollUnsized$dyn_Future_u64(captured6[rt.idx(captured6, i)], cx); - if (_88 !== rt.Pending) { - captured7 = rt.u64Add(captured7, _88); + const _84: rt.Poll = pollUnsized$dyn_Future_u64(captured6[rt.idx(captured6, i)], cx); + if (_84 !== rt.Pending) { + captured7 = rt.u64Add(captured7, _84); rt.drop(rt.vecSwapRemove(captured6, i)); } else { i = rt.usizeAdd(i, 1); @@ -353,24 +374,24 @@ export class boxedFuture { if (!((captured6.length === 0))) { return rt.Pending; } - return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value4: rt.u64): rt.u64 => { - return rt.u64Add(captured7, value4); + return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value5: rt.u64): rt.u64 => { + return rt.u64Add(captured7, value5); }); }, (): void => { rt.dropAll(captured6); }), rt.drop)); } else { - this.#state = 5; + this.#state = 6; return rt.Pending; } } - const _133: rt.Poll = Forward.poll$Future(this.#awaitee$3, _2); - if (_133 !== rt.Pending) { - const total: rt.u64 = _133; - this.#awaitee$3[Symbol.dispose](); + const _146: rt.Poll = Forward.poll$Future(this.#awaitee$4, _2); + if (_146 !== rt.Pending) { + const total: rt.u64 = _146; + this.#awaitee$4[Symbol.dispose](); const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(total, f)]; - const _143: string = rt.fmtFormat(["boxed ", args6[0]]); - Guard.note(this.#guard, _143); + const _156: string = rt.fmtFormat(["boxed ", args6[0]]); + Guard.note(this.#guard, _156); this.#pinned[Symbol.dispose](); this.#saved = false; this.#log[Symbol.dispose](); @@ -379,7 +400,7 @@ export class boxedFuture { this.#state = 1; return total; } - this.#state = 6; + this.#state = 7; return rt.Pending; } } diff --git a/ts/fixtures/task/src/futures.rs b/ts/fixtures/task/src/futures.rs index 179e1b7d1..83166edaa 100644 --- a/ts/fixtures/task/src/futures.rs +++ b/ts/fixtures/task/src/futures.rs @@ -109,7 +109,7 @@ impl Wake for Plain { type Boxed<'a> = Pin + 'a>>; /// Boxed futures over a channel: `Box::pin` of an async fn, awaited, and of a `&mut` to a -/// `poll_fn`, whose box drops without dropping it, then a queue of +/// `poll_fn` and to a `&mut` to it, whose box drops without dropping it, then a queue of /// `Pin>`s of an async block, kio's `Pending`, a struct of the crate's, /// and a `poll_fn`, each owning a guard. A `poll_fn` boxed in a [`Forward`] polls the /// queue in turn through [`poll_unsized`], as moq's tasks do through kio's @@ -126,7 +126,10 @@ pub async fn boxed(mut rx: Consumer, guard: Guard) -> u64 { Poll::Ready(4) }); let erased: Boxed<'_> = Box::pin(&mut lend); - let lent = erased.await + (&mut lend).await; + let lent = erased.await; + let mut lending = &mut lend; + let twice: Boxed<'_> = Box::pin(&mut lending); + let lent = lent + twice.await + (&mut lend).await; guard.note(&format!("lent {lent}")); drop(lend); let (block, waiting, ready) = ( diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index af6fcddac..337bc4021 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -73,8 +73,15 @@ impl<'tcx> Body<'_, '_, 'tcx> { let tcx = self.t.tcx; let object = match from.kind() { ty::Dynamic(..) | ty::Coroutine(..) => true, - // What a reference or a box points at, which its JS value is. - ty::Ref(_, inner, _) => return self.future_object(*inner, value, true, dropped, span), + // What a reference or a box points at, which its JS value is, but for a `&mut` to a + // reference, which is an `rt.Place` of it. + ty::Ref(_, inner, _) => { + let value = match self.t.place_pointee(from).is_some_and(|t| t.is_ref()) { + true => value.member("v"), + false => value, + }; + return self.future_object(*inner, value, true, dropped, span); + } ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { Some(Std::PollFn | Std::Pending) => true, Some(Std::Box | Std::Pin) => { From a8f52ebfb87cd71b79a8a5bb5b2e29585e5dd03b Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:40:06 -0700 Subject: [PATCH 6/9] fix(ts): read a &mut to a reference through its place in dyn Future coercions and FnOnce calls Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/refs.ts | 27 +++- ts/fixtures/lang/src/refs.rs | 8 + ts/fixtures/task/expected/futures.ts | 214 +++++++++++++++------------ ts/fixtures/task/src/futures.rs | 8 +- ts/src/lower/mir/call.rs | 9 +- ts/src/lower/mod.rs | 7 +- ts/src/lower/task.rs | 14 +- 7 files changed, 169 insertions(+), 118 deletions(-) diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 49b78b671..0506df3fe 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -871,8 +871,8 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { if (_363 === rt.DONE) { break; } - let o4: [rt.u8, rt.u8] | undefined = copy$Option_u8_u8(_363); - const iter22: rt.Iter<[rt.u8, rt.u8]> = rt.iterOption(rt.place(() => o4, (value6) => o4 = value6).v); + const o4: [rt.u8, rt.u8] | undefined = copy$Option_u8_u8(_363); + const iter22: rt.Iter<[rt.u8, rt.u8]> = rt.iterOption(o4); while (true) { const _371: [rt.u8, rt.u8] | rt.Done = iter22.next(); if (_371 === rt.DONE) { @@ -880,7 +880,7 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { } _371[0] = _371[0] ^ 90; } - rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o4, (value7) => o4 = value7).v)) & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterOption(o4)) & 0xff); rt.byteVecPush(out, mapOr$Option_u8_u8_u8_btree_maps_closure0(o4, 238, (p: [rt.u8, rt.u8]): rt.u8 => { return p[0]; })); @@ -1157,6 +1157,21 @@ export function callTwice$to_refs_closure3$2(f: (a0: rt.u8) => rt.u8): rt.u8 { return rt.u8WrappingAdd(f(1), f(2)); } +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3(f: rt.Place rt.u8>>): rt.u8 { + return f.v.v(3); +} + +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3$2(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return f.v(3); +} + +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3$3(f: (a0: rt.u8) => rt.u8): rt.u8 { + return f(3); +} + /** * A `&mut` to a reference: replaced, read, and written through, held, passed on, swapped, * and through an impl that forwards a trait through `&mut T`. @@ -1274,6 +1289,12 @@ export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, callTwice$to_refs_closure3$2(counted)); let _234: (a0: rt.u8) => rt.u8 = counted; rt.byteVecPush(out, callTwice$to_refs_closure3(rt.place(() => _234, (value15) => _234 = value15))); + rt.byteVecPush(out, callOnce$to_refs_closure3$3(counted)); + let _241: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callOnce$to_refs_closure3$2(rt.place(() => _241, (value16) => _241 = value16))); + let _246: (a0: rt.u8) => rt.u8 = counted; + let _245: rt.Place<(a0: rt.u8) => rt.u8> = rt.place(() => _246, (value17) => _246 = value17); + rt.byteVecPush(out, callOnce$to_refs_closure3(rt.place(() => _245, (value18) => _245 = value18))); } } diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index 580728a65..dab4125a2 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -770,6 +770,11 @@ fn call_twice u8>(mut f: F) -> u8 { f(1).wrapping_add(f(2)) } +/// Called once, through std's `FnOnce` for `&mut F` when `f` is one. +fn call_once u8>(f: F) -> u8 { + f(3) +} + /// A `&mut` to a reference: replaced, read, and written through, held, passed on, swapped, /// and through an impl that forwards a trait through `&mut T`. pub fn to_refs(data: &[u8], out: &mut Vec) { @@ -865,4 +870,7 @@ pub fn to_refs(data: &[u8], out: &mut Vec) { }; out.push(call_twice(&mut counted)); out.push(call_twice(&mut &mut counted)); + out.push(call_once(&mut counted)); + out.push(call_once(&mut &mut counted)); + out.push(call_once(&mut &mut &mut counted)); } diff --git a/ts/fixtures/task/expected/futures.ts b/ts/fixtures/task/expected/futures.ts index ac1c19602..465abc0cf 100644 --- a/ts/fixtures/task/expected/futures.ts +++ b/ts/fixtures/task/expected/futures.ts @@ -172,7 +172,8 @@ export function relayed(task: rt.Waker, log: Log.Log, id: rt.u32): rt.Waker { /** * Boxed futures over a channel: `Box::pin` of an async fn, awaited, and of a `&mut` to a - * `poll_fn` and to a `&mut` to it, whose box drops without dropping it, then a queue of + * `poll_fn` and to a `&mut` to it, whose box drops without dropping it, and a `&mut dyn + * Future` of a `&mut` to it, then a queue of * `Pin>`s of an async block, kio's `Pending`, a struct of the crate's, * and a `poll_fn`, each owning a guard. A `poll_fn` boxed in a [`Forward`] polls the * queue in turn through [`poll_unsized`], as moq's tasks do through kio's @@ -194,12 +195,13 @@ export class boxedFuture { #log!: Log.Log; #lend!: rt.Future; #awaitee$2!: rt.Future; - #lent!: rt.u64; + #saved!: rt.u64; #awaitee$3!: rt.Future; + #awaitee$4!: rt.Future; #pinned!: Pending.Pending<(a0: Waiter.Waiter) => rt.Poll>; - #awaitee$4!: Forward.Forward; - #saved!: boolean; + #awaitee$5!: Forward.Forward; #saved$2!: boolean; + #saved$3!: boolean; constructor(rx: Consumer.Consumer, guard: Guard.Guard) { this.#rx = rx; @@ -221,25 +223,25 @@ export class boxedFuture { rt.drop(this.#awaitee$2); } else if (this.#state === 5) { rt.drop(this.#awaitee$3); - } else if (this.#state !== 6) { - if (this.#state === 7) { - this.#awaitee$4[Symbol.dispose](); + } else if (!(this.#state === 6 || this.#state === 7)) { + if (this.#state === 8) { + this.#awaitee$5[Symbol.dispose](); this.#pinned[Symbol.dispose](); } else { return; } } - if (this.#saved) { + if (this.#saved$2) { this.#lend[Symbol.dispose](); } - this.#saved = false; + this.#saved$2 = false; this.#log[Symbol.dispose](); } this.#guard[Symbol.dispose](); - if (this.#saved$2) { + if (this.#saved$3) { this.#rx[Symbol.dispose](); } - this.#saved$2 = false; + this.#saved$3 = false; } poll(_2: rt.Context): rt.Poll { @@ -247,104 +249,120 @@ export class boxedFuture { b1: { b2: { b3: { - if (this.#state === 0) { - this.#saved$2 = false; - this.#saved = false; - this.#saved$2 = true; - this.#awaitee = new recvFuture(this.#rx); - } else if (this.#state === 1) { - rt.asyncFnResumed(); - } else if (this.#state !== 3) { - if (this.#state === 4) { - break b3; - } - if (this.#state === 5) { - break b2; + b4: { + if (this.#state === 0) { + this.#saved$3 = false; + this.#saved$2 = false; + this.#saved$3 = true; + this.#awaitee = new recvFuture(this.#rx); + } else if (this.#state === 1) { + rt.asyncFnResumed(); + } else if (this.#state !== 3) { + if (this.#state === 4) { + break b4; + } + if (this.#state === 5) { + break b3; + } + if (this.#state === 6) { + break b2; + } + if (this.#state === 7) { + break b1; + } + break b0; } - if (this.#state === 6) { - break b1; + const _7: rt.Poll = this.#awaitee.poll(_2); + if (_7 !== rt.Pending) { + const result: rt.u64 | undefined = _7; + rt.drop(this.#awaitee); + this.#first = unwrapOr$Option_u64(result, 0); + const arg = this.#first; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; + const _17: string = rt.fmtFormat(["first ", args2[0]]); + Guard.note(this.#guard, _17); + const _28: [rt.u32, Log.Log] = [Guard.id(this.#guard), Log.clone$Clone(Guard.log(this.#guard))]; + this.#id = _28[0]; + this.#log = _28[1]; + const captured = Guard.new(rt.u32Add(this.#id, 900), Log.clone$Clone(this.#log)); + this.#lend = new rt.PollFn(rt.closure((_22: rt.Context): rt.Poll => { + Guard.note(captured, "lent"); + return 4; + }, (): void => { + captured[Symbol.dispose](); + }), rt.drop); + this.#saved$2 = true; + this.#awaitee$2 = new rt.DynFuture(this.#lend, rt.futurePoll); + } else { + this.#state = 3; + return rt.Pending; } - break b0; } - const _7: rt.Poll = this.#awaitee.poll(_2); - if (_7 !== rt.Pending) { - const result: rt.u64 | undefined = _7; - rt.drop(this.#awaitee); - this.#first = unwrapOr$Option_u64(result, 0); - const arg = this.#first; - const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg, f)]; - const _17: string = rt.fmtFormat(["first ", args2[0]]); - Guard.note(this.#guard, _17); - const _28: [rt.u32, Log.Log] = [Guard.id(this.#guard), Log.clone$Clone(Guard.log(this.#guard))]; - this.#id = _28[0]; - this.#log = _28[1]; - const captured = Guard.new(rt.u32Add(this.#id, 900), Log.clone$Clone(this.#log)); - this.#lend = new rt.PollFn(rt.closure((_22: rt.Context): rt.Poll => { - Guard.note(captured, "lent"); - return 4; - }, (): void => { - captured[Symbol.dispose](); - }), rt.drop); - this.#saved = true; - this.#awaitee$2 = new rt.DynFuture(this.#lend, rt.futurePoll); + const _45: rt.Poll = this.#awaitee$2.poll(_2); + if (_45 !== rt.Pending) { + const lent2: rt.u64 = _45; + rt.drop(this.#awaitee$2); + this.#awaitee$2 = this.#lend; + const twice: rt.Future = new rt.DynFuture(this.#awaitee$2, rt.futurePoll); + this.#saved = lent2; + this.#awaitee$3 = twice; } else { - this.#state = 3; + this.#state = 4; return rt.Pending; } } - const _45: rt.Poll = this.#awaitee$2.poll(_2); - if (_45 !== rt.Pending) { - const lent2: rt.u64 = _45; - rt.drop(this.#awaitee$2); - this.#awaitee$2 = this.#lend; - const twice: rt.Future = new rt.DynFuture(this.#awaitee$2, rt.futurePoll); - this.#lent = lent2; - this.#awaitee$3 = twice; + const _58: rt.Poll = this.#awaitee$3.poll(_2); + if (_58 !== rt.Pending) { + const result2: rt.u64 = _58; + rt.drop(this.#awaitee$3); + const lent3: rt.u64 = rt.u64Add(this.#saved, result2); + this.#awaitee$3 = this.#lend; + const direct: rt.Future = this.#awaitee$3; + this.#saved = lent3; + this.#awaitee$4 = direct; } else { - this.#state = 4; + this.#state = 5; return rt.Pending; } } - const _57: rt.Poll = this.#awaitee$3.poll(_2); - if (_57 !== rt.Pending) { - const result2: rt.u64 = _57; - rt.drop(this.#awaitee$3); - this.#lent = rt.u64Add(this.#lent, result2); - this.#awaitee$3 = this.#lend; + const _70: rt.Poll = this.#awaitee$4.poll(_2); + if (_70 !== rt.Pending) { + this.#saved = rt.u64Add(this.#saved, _70); + this.#awaitee$4 = this.#lend; } else { - this.#state = 5; + this.#state = 6; return rt.Pending; } } - const _68: rt.Poll = this.#awaitee$3.poll(_2); - if (_68 !== rt.Pending) { - this.#lent = rt.u64Add(this.#lent, _68); - const arg2 = this.#lent; + const _81: rt.Poll = this.#awaitee$4.poll(_2); + if (_81 !== rt.Pending) { + this.#saved = rt.u64Add(this.#saved, _81); + const arg2 = this.#saved; const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(arg2, f)]; - const _79: string = rt.fmtFormat(["lent ", args4[0]]); - Guard.note(this.#guard, _79); - this.#saved = false; + const _92: string = rt.fmtFormat(["lent ", args4[0]]); + Guard.note(this.#guard, _92); + this.#saved$2 = false; this.#lend[Symbol.dispose](); - const _95: [Guard.Guard, Guard.Guard, Guard.Guard] = [Guard.new(rt.u32Add(this.#id, 500), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 600), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 700), Log.clone$Clone(this.#log))]; - const block: Guard.Guard = _95[0]; - const waiting: Guard.Guard = _95[1]; - const ready: Guard.Guard = _95[2]; + const _108: [Guard.Guard, Guard.Guard, Guard.Guard] = [Guard.new(rt.u32Add(this.#id, 500), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 600), Log.clone$Clone(this.#log)), Guard.new(rt.u32Add(this.#id, 700), Log.clone$Clone(this.#log))]; + const block: Guard.Guard = _108[0]; + const waiting: Guard.Guard = _108[1]; + const ready: Guard.Guard = _108[2]; const next: Consumer.Consumer = Consumer.clone$Clone(this.#rx); - this.#saved$2 = false; - const _118: rt.Future = new boxedFuture$2(this.#rx, block); + this.#saved$3 = false; + const _131: rt.Future = new boxedFuture$2(this.#rx, block); let captured2 = next; const captured3 = waiting; - const _121: rt.Future = new rt.DynFuture(wait$boxed_closure0_closure3_u64(rt.closure((waiter: Waiter.Waiter): rt.Poll => { - return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value3: rt.u64 | undefined): rt.u64 => { + const _134: rt.Future = new rt.DynFuture(wait$boxed_closure0_closure3_u64(rt.closure((waiter: Waiter.Waiter): rt.Poll => { + return map$Poll_Option_u64_u64_boxed_closure0_closure3_closure0(Consumer.pollRecv(captured2, waiter), (value5: rt.u64 | undefined): rt.u64 => { Guard.note(captured3, "waited"); - return rt.u64Add(unwrapOr$Option_u64(value3, 0), 2); + return rt.u64Add(unwrapOr$Option_u64(value5, 0), 2); }); }, (): void => { captured2[Symbol.dispose](); captured3[Symbol.dispose](); })), Pending.poll$Future_boxed_closure0_closure3, rt.drop); const captured4 = ready; - const queue: rt.Future[] = [_118, _121, new rt.PollFn(rt.closure((_23: rt.Context): rt.Poll => { + const queue: rt.Future[] = [_131, _134, new rt.PollFn(rt.closure((_23: rt.Context): rt.Poll => { Guard.note(captured4, "ready"); return 3; }, (): void => { @@ -360,12 +378,12 @@ export class boxedFuture { let captured6 = queue; let captured7: rt.u64 = 0; let captured8 = last; - this.#awaitee$4 = new Forward.Forward(new rt.PollFn(rt.closure((cx: rt.Context): rt.Poll => { + this.#awaitee$5 = new Forward.Forward(new rt.PollFn(rt.closure((cx: rt.Context): rt.Poll => { let i: rt.usize = 0; while (i < captured6.length) { - const _84: rt.Poll = pollUnsized$dyn_Future_u64(captured6[rt.idx(captured6, i)], cx); - if (_84 !== rt.Pending) { - captured7 = rt.u64Add(captured7, _84); + const _83: rt.Poll = pollUnsized$dyn_Future_u64(captured6[rt.idx(captured6, i)], cx); + if (_83 !== rt.Pending) { + captured7 = rt.u64Add(captured7, _83); rt.drop(rt.vecSwapRemove(captured6, i)); } else { i = rt.usizeAdd(i, 1); @@ -374,33 +392,33 @@ export class boxedFuture { if (!((captured6.length === 0))) { return rt.Pending; } - return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value5: rt.u64): rt.u64 => { - return rt.u64Add(captured7, value5); + return map$Poll_u64_u64_boxed_closure0_closure1_closure0(pollUnsized$dyn_Future_u64(new rt.DynFuture(captured8, Pending.poll$Future_boxed_closure0_closure5), cx), (value7: rt.u64): rt.u64 => { + return rt.u64Add(captured7, value7); }); }, (): void => { rt.dropAll(captured6); }), rt.drop)); } else { - this.#state = 6; + this.#state = 7; return rt.Pending; } } - const _146: rt.Poll = Forward.poll$Future(this.#awaitee$4, _2); - if (_146 !== rt.Pending) { - const total: rt.u64 = _146; - this.#awaitee$4[Symbol.dispose](); + const _159: rt.Poll = Forward.poll$Future(this.#awaitee$5, _2); + if (_159 !== rt.Pending) { + const total: rt.u64 = _159; + this.#awaitee$5[Symbol.dispose](); const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(total, f)]; - const _156: string = rt.fmtFormat(["boxed ", args6[0]]); - Guard.note(this.#guard, _156); + const _169: string = rt.fmtFormat(["boxed ", args6[0]]); + Guard.note(this.#guard, _169); this.#pinned[Symbol.dispose](); - this.#saved = false; + this.#saved$2 = false; this.#log[Symbol.dispose](); this.#guard[Symbol.dispose](); - this.#saved$2 = false; + this.#saved$3 = false; this.#state = 1; return total; } - this.#state = 7; + this.#state = 8; return rt.Pending; } } diff --git a/ts/fixtures/task/src/futures.rs b/ts/fixtures/task/src/futures.rs index 83166edaa..b1fef44d9 100644 --- a/ts/fixtures/task/src/futures.rs +++ b/ts/fixtures/task/src/futures.rs @@ -109,7 +109,8 @@ impl Wake for Plain { type Boxed<'a> = Pin + 'a>>; /// Boxed futures over a channel: `Box::pin` of an async fn, awaited, and of a `&mut` to a -/// `poll_fn` and to a `&mut` to it, whose box drops without dropping it, then a queue of +/// `poll_fn` and to a `&mut` to it, whose box drops without dropping it, and a `&mut dyn +/// Future` of a `&mut` to it, then a queue of /// `Pin>`s of an async block, kio's `Pending`, a struct of the crate's, /// and a `poll_fn`, each owning a guard. A `poll_fn` boxed in a [`Forward`] polls the /// queue in turn through [`poll_unsized`], as moq's tasks do through kio's @@ -129,7 +130,10 @@ pub async fn boxed(mut rx: Consumer, guard: Guard) -> u64 { let lent = erased.await; let mut lending = &mut lend; let twice: Boxed<'_> = Box::pin(&mut lending); - let lent = lent + twice.await + (&mut lend).await; + let lent = lent + twice.await; + let mut lending = &mut lend; + let direct: &mut (dyn Future + Unpin) = &mut lending; + let lent = lent + direct.await + (&mut lend).await; guard.note(&format!("lent {lent}")); drop(lend); let (block, waiting, ready) = ( diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index b9e4844e5..08e1b310c 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -299,15 +299,16 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if let ty::FnDef(inner, inner_args) = *callee_ty.peel_refs().kind() { return self.b.call_def(inner, inner_args.skip_binder(), values, span, out); } - // A `&mut` to a function JS copies, such as a box of one, is its place: call what is - // there, through each `&mut` std's impls for one forward through. + // A `&mut` to a function JS copies, such as a box of one, or to a reference to one, as + // std's impls for a `&mut` forward through, is its place: call what is there. + let mut through = callee.node.ty(&self.mir.local_decls, tcx); let mut f = match callee.node.place() { - Some(p) if self.b.t.place_pointee(p.ty(&self.mir.local_decls, tcx).ty).is_some() => { + Some(p) if let Some(pointee) = self.b.t.place_pointee(through) => { + through = pointee; self.place_expr(tcx.mk_place_deref(p), span, out) } _ => self.operand(&callee.node, span, out), }; - let mut through = callee_ty; while let Some(inner) = self.b.t.place_pointee(through) { f = f.member("v"); through = inner; diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 6785ba329..ba2a987d1 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -1200,9 +1200,10 @@ 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, + match (self.place_pointee(ty), value.place_read()) { + (Some(_), Some(read)) => read.clone(), + (Some(_), None) => value.member("v"), + (None, _) => value, } } diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index 337bc4021..f2f7002f2 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -42,14 +42,16 @@ impl<'tcx> Translator<'_, 'tcx> { impl<'tcx> Body<'_, '_, 'tcx> { /// `value`, a `from` coerced to `to`, which points at a `dyn Future` through - /// references, boxes, and pins, whose JS value is what they point at. + /// references, boxes, and pins, whose JS value is what they point at, or an `rt.Place` + /// of it for a `&mut` to a reference. pub fn dyn_future(&mut self, from: Ty<'tcx>, to: Ty<'tcx>, value: Expr, span: Span) -> Expr { let tcx = self.t.tcx; - let (mut pointee, mut target, mut borrowed) = (from, to, false); + let (mut pointee, mut target, mut borrowed, mut value) = (from, to, false, value); while !matches!(target.kind(), ty::Dynamic(..)) { (pointee, target) = match (pointee.kind(), target.kind()) { (ty::Ref(_, a, _), ty::Ref(_, b, _)) => { borrowed = true; + value = self.t.pointee_value(pointee, value); (*a, *b) } (ty::Adt(a, a_args), ty::Adt(b, b_args)) @@ -73,13 +75,9 @@ impl<'tcx> Body<'_, '_, 'tcx> { let tcx = self.t.tcx; let object = match from.kind() { ty::Dynamic(..) | ty::Coroutine(..) => true, - // What a reference or a box points at, which its JS value is, but for a `&mut` to a - // reference, which is an `rt.Place` of it. + // What a reference or a box points at, which its JS value is, or an `rt.Place` of. ty::Ref(_, inner, _) => { - let value = match self.t.place_pointee(from).is_some_and(|t| t.is_ref()) { - true => value.member("v"), - false => value, - }; + let value = self.t.pointee_value(from, value); return self.future_object(*inner, value, true, dropped, span); } ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { From 629111531114b9b06c5a4befb41b4070ac83cbc9 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:48:34 -0700 Subject: [PATCH 7/9] fix(ts): read a box of a &mut to a reference through its place in closure calls and iterators Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/refs.ts | 60 ++++++++++++++++++++++++------- ts/fixtures/lang/src/refs.rs | 9 +++++ ts/src/lower/iter.rs | 25 ++++++++----- ts/src/lower/mir/call.rs | 36 ++++++++++--------- 4 files changed, 93 insertions(+), 37 deletions(-) diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 0506df3fe..ea3a14482 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -1137,6 +1137,11 @@ export function retarget(r: rt.Place>, other: rt.Place, r.v.v = rt.u32Add(r.v.v, 1); } +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Box_Copied_Iter_u8(it: rt.Place>): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 221)); +} + /** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ export function nextTwo$Copied_Iter_u8(it: rt.Place>): rt.u8 { return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 221)); @@ -1147,6 +1152,16 @@ export function nextTwo$Copied_Iter_u8$2(it: rt.Iter): rt.u8 { return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.next()), 221)); } +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$Box_to_refs_closure3(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return rt.u8WrappingAdd(f.v(1), f.v(2)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$Box_to_refs_closure3$2(f: (a0: rt.u8) => rt.u8): rt.u8 { + return rt.u8WrappingAdd(f(1), f(2)); +} + /** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ export function callTwice$to_refs_closure3(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { return rt.u8WrappingAdd(f.v(1), f.v(2)); @@ -1266,35 +1281,54 @@ export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, nextTwo$Copied_Iter_u8$2(it)); let _208: rt.Iter = it; rt.byteVecPush(out, nextTwo$Copied_Iter_u8(rt.place(() => _208, (value13) => _208 = value13))); + let _213: rt.Iter = it; + rt.byteVecPush(out, nextTwo$Box_Copied_Iter_u8(rt.place(() => _213, (value14) => _213 = value14))); let r2: rt.Iter = it; - const iter3: rt.Place> = rt.place(() => r2, (value14) => r2 = value14); + const iter3: rt.Place> = rt.place(() => r2, (value15) => r2 = value15); while (true) { - const _213: rt.u8 | rt.Done = iter3.v.next(); - if (_213 === rt.DONE) { + const _218: rt.u8 | rt.Done = iter3.v.next(); + if (_218 === rt.DONE) { break; } - const b4: rt.u8 = _213; + const b4: rt.u8 = _218; if (!(rt.u8Rem(b4, 3) === 0)) { rt.byteVecPush(out, b4); } else { break; } } + let _229: rt.Iter = it; + const iter4: rt.Place> = rt.place(() => _229, (value16) => _229 = value16); + while (true) { + const _231: rt.u8 | rt.Done = iter4.v.next(); + if (_231 === rt.DONE) { + break; + } + const b5: rt.u8 = _231; + if (!(rt.u8Rem(b5, 4) === 0)) { + rt.byteVecPush(out, b5); + } else { + break; + } + } rt.byteVecPush(out, rt.iterCount(it) & 0xff); let calls: rt.u8 = 0; - const counted: (a0: rt.u8) => rt.u8 = (b6: rt.u8): rt.u8 => { - calls = rt.u8WrappingAdd(calls, b6); + const counted: (a0: rt.u8) => rt.u8 = (b7: rt.u8): rt.u8 => { + calls = rt.u8WrappingAdd(calls, b7); return calls; }; rt.byteVecPush(out, callTwice$to_refs_closure3$2(counted)); - let _234: (a0: rt.u8) => rt.u8 = counted; - rt.byteVecPush(out, callTwice$to_refs_closure3(rt.place(() => _234, (value15) => _234 = value15))); + let _252: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$to_refs_closure3(rt.place(() => _252, (value17) => _252 = value17))); rt.byteVecPush(out, callOnce$to_refs_closure3$3(counted)); - let _241: (a0: rt.u8) => rt.u8 = counted; - rt.byteVecPush(out, callOnce$to_refs_closure3$2(rt.place(() => _241, (value16) => _241 = value16))); - let _246: (a0: rt.u8) => rt.u8 = counted; - let _245: rt.Place<(a0: rt.u8) => rt.u8> = rt.place(() => _246, (value17) => _246 = value17); - rt.byteVecPush(out, callOnce$to_refs_closure3(rt.place(() => _245, (value18) => _245 = value18))); + let _259: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callOnce$to_refs_closure3$2(rt.place(() => _259, (value18) => _259 = value18))); + let _264: (a0: rt.u8) => rt.u8 = counted; + let _263: rt.Place<(a0: rt.u8) => rt.u8> = rt.place(() => _264, (value19) => _264 = value19); + rt.byteVecPush(out, callOnce$to_refs_closure3(rt.place(() => _263, (value20) => _263 = value20))); + rt.byteVecPush(out, callTwice$Box_to_refs_closure3$2(counted)); + let _273: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$Box_to_refs_closure3(rt.place(() => _273, (value21) => _273 = value21))); } } diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index dab4125a2..2e6237e6f 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -855,6 +855,7 @@ pub fn to_refs(data: &[u8], out: &mut Vec) { let mut it = rest.iter().copied(); out.push(next_two(&mut it)); out.push(next_two(&mut &mut it)); + out.push(next_two(Box::new(&mut &mut it))); let mut r = &mut it; for b in &mut r { if b % 3 == 0 { @@ -862,6 +863,12 @@ pub fn to_refs(data: &[u8], out: &mut Vec) { } out.push(b); } + for b in Box::new(&mut &mut it) { + if b % 4 == 0 { + break; + } + out.push(b); + } out.push(it.count() as u8); let mut calls = 0u8; let mut counted = |b: u8| { @@ -873,4 +880,6 @@ pub fn to_refs(data: &[u8], out: &mut Vec) { out.push(call_once(&mut counted)); out.push(call_once(&mut &mut counted)); out.push(call_once(&mut &mut &mut counted)); + out.push(call_twice(Box::new(&mut counted))); + out.push(call_twice(Box::new(&mut &mut counted))); } diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index 4fff5145c..c46d5cc6d 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -231,17 +231,26 @@ pub(super) fn iter_of<'tcx>(t: &Translator<'_, 'tcx>, ty: Ty<'tcx>) -> Option) -> bool { - matches!(*ty.kind(), ty::Ref(_, inner, ty::Mutability::Mut) if inner.is_ref()) +/// Whether `ty` is a `&mut` to a `&mut`, which is an `rt.Place` of it, or a box of one, +/// which is what it holds. +pub fn through_mut(ty: Ty<'_>) -> bool { + match ty.boxed_ty() { + Some(inner) => through_mut(inner), + None => matches!(*ty.kind(), ty::Ref(_, inner, ty::Mutability::Mut) if inner.is_ref()), + } } -/// `value`, a `ty`, read through each `&mut` to a `&mut`, which std's `Iterator` for `&mut I` -/// forwards through, down to the last `&mut` and its JS value. -fn peel_mut<'tcx>(mut ty: Ty<'tcx>, mut value: Expr) -> (Ty<'tcx>, Expr) { +/// `value`, a `ty`, read through each box and `&mut` to a `&mut` that std's `Iterator` for +/// `Box` and `&mut I` forward through, down to the last `&mut` and its JS value. +pub fn peel_mut<'tcx>(mut ty: Ty<'tcx>, mut value: Expr) -> (Ty<'tcx>, Expr) { while through_mut(ty) { - value = value.member("v"); - ty = ty.builtin_deref(true).expect("a reference"); + ty = match ty.boxed_ty() { + Some(inner) => inner, + None => { + value = value.member("v"); + ty.builtin_deref(true).expect("a reference") + } + }; } (ty, value) } diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 08e1b310c..233307e7f 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -55,20 +55,17 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { if crate::lower::iter::is_next(tcx, def_id) && dest.as_local().is_some_and(|l| self.next_results.contains(&l)) => { - let mut iter_ty = gargs.skip_binder().type_at(0); - // Through std's `Iterator` for `&mut I`, whose `&mut` to it is an `rt.Place`: the - // place it borrows, then what each `&mut` points at. - let mut recv = match args[0].node.place() { - Some(p) if iter_ty.is_ref() => { - iter_ty = iter_ty.builtin_deref(true).expect("a reference"); - self.place_expr(tcx.mk_place_deref(p), span, &mut pre) + let self_ty = gargs.skip_binder().type_at(0); + let (iter_ty, recv) = match args[0].node.place() { + // Through std's `Iterator` for `&mut I` and `Box`: what the last `&mut` + // points at, read through the `rt.Place` of each `&mut` to a `&mut` before it. + Some(p) if self_ty.is_ref() || crate::lower::iter::through_mut(self_ty) => { + let value = self.place_expr(tcx.mk_place_deref(p), span, &mut pre); + let (last, value) = crate::lower::iter::peel_mut(self_ty, value); + (last.builtin_deref(true).unwrap_or(last), value) } - _ => self.operand_frozen(&args[0].node, span, &mut pre), + _ => (self_ty, self.operand_frozen(&args[0].node, span, &mut pre)), }; - while let ty::Ref(_, inner, rustc_ast::Mutability::Mut) = *iter_ty.kind() { - recv = recv.member("v"); - iter_ty = inner; - } if self.range_nexts.contains(&dest.local) && let Some(name) = self.var(dest.local) { @@ -300,7 +297,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { return self.b.call_def(inner, inner_args.skip_binder(), values, span, out); } // A `&mut` to a function JS copies, such as a box of one, or to a reference to one, as - // std's impls for a `&mut` forward through, is its place: call what is there. + // std's impls for a `&mut` and a box forward through, is its place: call what is + // there. A box is what it holds. let mut through = callee.node.ty(&self.mir.local_decls, tcx); let mut f = match callee.node.place() { Some(p) if let Some(pointee) = self.b.t.place_pointee(through) => { @@ -309,9 +307,15 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } _ => self.operand(&callee.node, span, out), }; - while let Some(inner) = self.b.t.place_pointee(through) { - f = f.member("v"); - through = inner; + loop { + through = match (through.boxed_ty(), self.b.t.place_pointee(through)) { + (Some(inner), _) => inner, + (None, Some(inner)) => { + f = f.member("v"); + inner + } + (None, None) => break, + }; } // `FnOnce::call_once` of a closure that `Fn` or `FnMut` call, or of a box of one, // drops it after, as rustc's shim does, where an `FnOnce` closure's body drops From 59d5714261b32d7331018d2b992c6febfe7af2eb Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:33:21 -0700 Subject: [PATCH 8/9] test(ts): regenerate the lang snapshots after merging origin/main Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/harness.ts | 104 +++++----- ts/fixtures/lang/expected/refs.ts | 285 ++++++++++++++++++++++++++- 2 files changed, 333 insertions(+), 56 deletions(-) diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index ef6837c17..6331a21ed 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -29,7 +29,7 @@ import { locks, relock, rwlocks } from "./locks.ts"; import { nested } from "./nested.ts"; import { objects } from "./objects.ts"; import { lists, shared as pointers_shared, places, unchecked, nested as pointers_nested, copies, sentinels } from "./pointers.ts"; -import { refs } from "./refs.ts"; +import { refs, toRefs } from "./refs.ts"; import { copies as shapes_copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { splits } from "./splits.ts"; import { statics } from "./statics.ts"; @@ -42,105 +42,107 @@ import { wrappers } from "./wrappers.ts"; * case added at the end moves no other. */ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void][] { - return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_282: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { + return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_285: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { convert(data, out); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_283: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_286: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { shapes_copies(data2, out2); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_284: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_287: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { loops(data3, out3); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_285: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_288: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { patterns(data4, out4); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_286: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_289: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { closures(data5, out5); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_287: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_290: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { discriminants(data6, out6); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_288: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_291: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { library(data7, out7); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_289: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_292: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { strings(data8, out8); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_290: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_293: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { derived(data9, out9); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_291: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_294: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { written(data10, out10); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_292: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_295: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { methods(data11, out11); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_293: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_296: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { ranges(data12, out12); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_294: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_297: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { options(data13, out13); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_295: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_298: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { own(data14, out14); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_296: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_299: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { values(data15, out15); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_297: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_2100: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { order(data16, out16); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_298: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_2101: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { deques(data17, out17); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_299: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_2102: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { flows(data18, out18); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2100: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2103: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { vecs(data19, out19); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2101: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2104: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { stores(data20, out20); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2102: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2105: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { refs(data21, out21); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2103: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2106: 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", (_2104: rt.u8, _310: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2107: rt.u8, _310: 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", (_2105: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { + }] 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", (_2108: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2106: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2109: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { shared(data24, out25); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2107: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2110: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { locks(data25, out26); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2108: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2111: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { relock(data26, out27); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2109: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2112: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { locals(data27, out28); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2110: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2113: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { statics(data28, out29); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2111: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2114: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { rwlocks(data29, out30); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2112: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2115: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { borrows(data30, out31); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2113: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2116: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { defaults(data31, out32); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2114: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2117: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { arcs(data32, out33); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2115: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2118: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { rcs(data33, out34); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2116: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2119: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { cyclicArcs(data34, out35); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2117: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2120: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { cyclicRcs(data35, out36); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2118: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2121: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { uniqueArcs(data36, out37); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2119: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2122: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { uniqueRcs(data37, out38); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2120: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2123: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { anys(data38, out39); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2121: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2124: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { fns(data39, out40); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2122: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2125: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { copies(data40, out41); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2123: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2126: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { lists(data41, out42); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2124: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2127: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { pointers_nested(data42, out43); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2125: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2128: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { places(data43, out44); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2126: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2129: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { sentinels(data44, out45); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2127: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2130: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { pointers_shared(data45, out46); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2128: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2131: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { unchecked(data46, out47); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2129: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2132: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { fromFns(data47, out48); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2130: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2133: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { objects(data48, out49); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::to_refs", (_2134: rt.u8, data49: rt.ByteSlice, out50: rt.ByteVec): void => { + toRefs(data49, out50); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index 5a82d688d..0e3dffc7a 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -10,8 +10,9 @@ import type * as Fetch from "./refs.Fetch.ts"; import type * as Held from "./refs.Held.ts"; import * as Listing from "./refs.Listing.ts"; import type * as Nest from "./refs.Nest.ts"; -import type * as Pair from "./refs.Pair.ts"; +import * as Pair from "./refs.Pair.ts"; import type * as Pair2 from "./refs.Pair2.ts"; +import * as Reader from "./refs.Reader.ts"; export function bump(x: rt.Place, by: rt.u8): void { x.v = rt.u32Add(x.v, by as rt.u32); @@ -873,8 +874,8 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { if (_363 === rt.DONE) { break; } - let o4: [rt.u8, rt.u8] | undefined = copy$Option_u8_u8(_363); - const iter22: rt.Iter<[rt.u8, rt.u8]> = rt.iterOption(rt.place(() => o4, (value6) => o4 = value6).v); + const o4: [rt.u8, rt.u8] | undefined = copy$Option_u8_u8(_363); + const iter22: rt.Iter<[rt.u8, rt.u8]> = rt.iterOption(o4); while (true) { const _371: [rt.u8, rt.u8] | rt.Done = iter22.next(); if (_371 === rt.DONE) { @@ -882,7 +883,7 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { } _371[0] = _371[0] ^ 90; } - rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o4, (value7) => o4 = value7).v)) & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterOption(o4)) & 0xff); rt.byteVecPush(out, mapOr$Option_u8_u8_u8_btree_maps_closure0(o4, 238, (p: [rt.u8, rt.u8]): rt.u8 => { return p[0]; })); @@ -895,7 +896,7 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { break; } let o6: rt.Place | undefined = _391; - rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o6, (value9) => o6 = value9).v)) & 0xff); + rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.optionAsMut(rt.place(() => o6, (value9) => o6 = value9)))) & 0xff); } rt.byteVecPush(out, n); let _406: rt.u8 | undefined = seenOf(data); @@ -1102,4 +1103,278 @@ export function bumpByte(x: rt.Place): void { x.v = rt.u8WrappingAdd(x.v, 1); } +/** + * The front of a slice taken through a `&mut` to it, which it moves past: out of bounds + * past the end, it panics. + */ +export function takeFront(s: rt.Place, n: rt.usize): rt.ByteSlice { + const slice: rt.ByteSlice = s.v; + if (n > slice.length) { + rt.panic("mid > len"); + } + const front: rt.ByteSlice = new rt.ByteSlice(slice.data, slice.start, n); + s.v = new rt.ByteSlice(slice.data, slice.start + n, slice.length - n); + return front; +} + +export function tally$Tally_u32(self: rt.Place, n: rt.u8): void { + self.v = rt.u32Add(self.v, n as rt.u32); +} + +export function total$Tally_u32(self: rt.u32): rt.u32 { + return self; +} + +export function tally$Tally_u32$2(self: rt.Place>>, n: rt.u8): void { + tally$Tally_u32$3(self.v, n); +} + +export function tally$Tally_u32$3(self: rt.Place>, n: rt.u8): void { + tally$Tally_u32(self.v, n); +} + +export function total$Tally_u32$2(self: rt.Place>>): rt.u32 { + return total$Tally_u32$3(self.v); +} + +export function total$Tally_u32$3(self: rt.Place>): rt.u32 { + return total$Tally_u32$4(self.v); +} + +export function total$Tally_u32$4(self: rt.Place): rt.u32 { + return total$Tally_u32(self.v); +} + +export function tallyAll$Pair(t: rt.Place, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + Pair.tally$Tally$2(t, _5); + } + return Pair.total$Tally$2(t); +} + +export function tallyAll$u32(t: rt.Place>>, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + tally$Tally_u32$2(t, _5); + } + return total$Tally_u32$2(t); +} + +export function tallyAll$u32$2(t: rt.Place>, data: rt.ByteSlice): rt.u32 { + for (const _5 of rt.byteSliceView(data)) { + tally$Tally_u32$3(t, _5); + } + return total$Tally_u32$3(t); +} + +/** The larger of two references, replacing the one a `&mut` points at. */ +export function keepLarger(r: rt.Place, other: Pair.Pair): void { + if (other.n > r.v.n) { + r.v = other; + } +} + +/** A `&mut` to a `&mut`, written through twice over, then pointed elsewhere. */ +export function retarget(r: rt.Place>, other: rt.Place, by: rt.u8): void { + r.v.v = rt.u32Add(r.v.v, by as rt.u32); + if (rt.u8Rem(by, 2) === 0) { + r.v = other; + } + r.v.v = rt.u32Add(r.v.v, 1); +} + +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Box_Copied_Iter_u8(it: rt.Place>): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 221)); +} + +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Copied_Iter_u8(it: rt.Place>): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.v.next()), 221)); +} + +/** The next two items, through std's `Iterator` for `&mut I` when `it` is one. */ +export function nextTwo$Copied_Iter_u8$2(it: rt.Iter): rt.u8 { + return rt.u8WrappingAdd(unwrapOr$Option_u8(rt.iterToOption(it.next()), 238), unwrapOr$Option_u8(rt.iterToOption(it.next()), 221)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$Box_to_refs_closure3(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return rt.u8WrappingAdd(f.v(1), f.v(2)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$Box_to_refs_closure3$2(f: (a0: rt.u8) => rt.u8): rt.u8 { + return rt.u8WrappingAdd(f(1), f(2)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$to_refs_closure3(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return rt.u8WrappingAdd(f.v(1), f.v(2)); +} + +/** Called twice, through std's `FnMut` for `&mut F` when `f` is one. */ +export function callTwice$to_refs_closure3$2(f: (a0: rt.u8) => rt.u8): rt.u8 { + return rt.u8WrappingAdd(f(1), f(2)); +} + +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3(f: rt.Place rt.u8>>): rt.u8 { + return f.v.v(3); +} + +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3$2(f: rt.Place<(a0: rt.u8) => rt.u8>): rt.u8 { + return f.v(3); +} + +/** Called once, through std's `FnOnce` for `&mut F` when `f` is one. */ +export function callOnce$to_refs_closure3$3(f: (a0: rt.u8) => rt.u8): rt.u8 { + return f(3); +} + +/** + * A `&mut` to a reference: replaced, read, and written through, held, passed on, swapped, + * and through an impl that forwards a trait through `&mut T`. + */ +export function toRefs(data: rt.ByteSlice, out: rt.ByteVec): void { + if (data.length >= 1) { + const n: rt.usize = data.data[data.start] as rt.usize; + let bytes: rt.ByteSlice = rt.byteSliceRange(data, 1); + const _12: rt.usize = rt.usizeRem(n, rt.usizeAdd(rt.byteSliceRange(data, 1).length, 2)); + rt.byteVecExtendFromSlice(out, takeFront(rt.place(() => bytes, (value) => bytes = value), _12)); + rt.byteVecPush(out, bytes.length & 0xff); + const reader: Reader.Reader = { rest: rt.place(() => bytes, (value2) => bytes = value2) }; + while (true) { + const slice: rt.ByteSlice = Reader.rest(reader).v; + if (slice.length !== 0) { + const b: rt.u8 = slice.data[slice.start]; + Reader.rest(reader).v = new rt.ByteSlice(slice.data, slice.start + 1, slice.length - 1); + if (!(rt.u8Rem(b, 5) === 0)) { + rt.byteVecPush(out, b); + } else { + break; + } + } else { + break; + } + } + rt.byteVecPush(out, bytes.length & 0xff); + let tail2: rt.u32[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))), (_2: rt.u8): rt.u32 => { + return (((_2 as rt.u32)) << 8) >>> 0; + })); + while (tail2.length >= 1) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tail2[0]))); + tail2 = tail2.slice(1, tail2.length - 0); + } + let text: string = ""; + for (const _59 of rt.byteSliceView(rt.byteSliceRange(data, 1))) { + text = text + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(_59, 26)) as rt.char); + } + let s: string = text; + const part = rt.min(rt.usizeRem(n, 3), rt.stringLen(s)); + s = rt.strSlice(s, part); + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s)); + const part2 = rt.usizeDiv(rt.byteSliceRange(data, 1).length, 2); + const _85: rt.ByteSlice = rt.byteSliceRange(rt.byteSliceRange(data, 1), part2); + let a: rt.ByteSlice = rt.byteSliceRange(data, 1); + let b3: rt.ByteSlice = _85; + const swapped = a; + a = b3; + b3 = swapped; + const old2 = b3; + b3 = rt.byteSliceFrom(Uint8Array.of()); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.length & 0xff, b3.length & 0xff, old2.length & 0xff))); + const taken2 = a; + a = rt.byteSliceFrom(new Uint8Array(0)); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a.length & 0xff, taken2.length & 0xff))); + let left: rt.ByteSlice = rt.byteSliceRange(data, 1); + const skip_: (a0: rt.usize) => rt.usize = (n2: rt.usize): rt.usize => { + const at: rt.usize = rt.min(n2, left.length); + left = rt.byteSliceRange(left, at); + return at; + }; + rt.byteVecPush(out, skip_(rt.usizeRem(n, 3)) & 0xff); + rt.byteVecPush(out, skip_(1) & 0xff); + rt.byteVecPush(out, left.length & 0xff); + const pairs: Pair.Pair[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))), (_22: rt.u8): Pair.Pair => { + return { n: _22 }; + })); + const first: Pair.Pair = { n: 0 }; + let largest: Pair.Pair = first; + for (const _147 of pairs) { + keepLarger(rt.place(() => largest, (value3) => largest = value3), _147); + } + rt.byteVecPush(out, largest.n); + let x: rt.u32 = 0; + let y: rt.u32 = 100; + let r: rt.Place = rt.place(() => x, (value4) => x = value4); + retarget(rt.place(() => r, (value5) => r = value5), rt.place(() => y, (value6) => y = value6), n & 0xff); + r.v = rt.u32Add(r.v, 1000); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(y))); + let count: rt.u32 = 0; + const pair: Pair.Pair = { n: 1 }; + let _182: rt.Place = rt.place(() => count, (value7) => count = value7); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32$2(rt.place(() => _182, (value8) => _182 = value8), rt.byteSliceRange(data, 1))))); + let _189: Pair.Pair = pair; + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$Pair(rt.place(() => _189, (value9) => _189 = value9), rt.byteSliceRange(data, 1))))); + let _197: rt.Place = rt.place(() => count, (value10) => count = value10); + let _196: rt.Place> = rt.place(() => _197, (value11) => _197 = value11); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(tallyAll$u32(rt.place(() => _196, (value12) => _196 = value12), rt.byteSliceRange(data, 1))))); + rt.byteVecPush(out, pair.n); + const it: rt.Iter = rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 1))); + rt.byteVecPush(out, nextTwo$Copied_Iter_u8$2(it)); + let _208: rt.Iter = it; + rt.byteVecPush(out, nextTwo$Copied_Iter_u8(rt.place(() => _208, (value13) => _208 = value13))); + let _213: rt.Iter = it; + rt.byteVecPush(out, nextTwo$Box_Copied_Iter_u8(rt.place(() => _213, (value14) => _213 = value14))); + let r2: rt.Iter = it; + const iter3: rt.Place> = rt.place(() => r2, (value15) => r2 = value15); + while (true) { + const _218: rt.u8 | rt.Done = iter3.v.next(); + if (_218 === rt.DONE) { + break; + } + const b4: rt.u8 = _218; + if (!(rt.u8Rem(b4, 3) === 0)) { + rt.byteVecPush(out, b4); + } else { + break; + } + } + let _229: rt.Iter = it; + const iter4: rt.Place> = rt.place(() => _229, (value16) => _229 = value16); + while (true) { + const _231: rt.u8 | rt.Done = iter4.v.next(); + if (_231 === rt.DONE) { + break; + } + const b5: rt.u8 = _231; + if (!(rt.u8Rem(b5, 4) === 0)) { + rt.byteVecPush(out, b5); + } else { + break; + } + } + rt.byteVecPush(out, rt.iterCount(it) & 0xff); + let calls: rt.u8 = 0; + const counted: (a0: rt.u8) => rt.u8 = (b7: rt.u8): rt.u8 => { + calls = rt.u8WrappingAdd(calls, b7); + return calls; + }; + rt.byteVecPush(out, callTwice$to_refs_closure3$2(counted)); + let _252: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$to_refs_closure3(rt.place(() => _252, (value17) => _252 = value17))); + rt.byteVecPush(out, callOnce$to_refs_closure3$3(counted)); + let _259: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callOnce$to_refs_closure3$2(rt.place(() => _259, (value18) => _259 = value18))); + let _264: (a0: rt.u8) => rt.u8 = counted; + let _263: rt.Place<(a0: rt.u8) => rt.u8> = rt.place(() => _264, (value19) => _264 = value19); + rt.byteVecPush(out, callOnce$to_refs_closure3(rt.place(() => _263, (value20) => _263 = value20))); + rt.byteVecPush(out, callTwice$Box_to_refs_closure3$2(counted)); + let _273: (a0: rt.u8) => rt.u8 = counted; + rt.byteVecPush(out, callTwice$Box_to_refs_closure3(rt.place(() => _273, (value21) => _273 = value21))); + } +} + //# sourceMappingURL=refs.ts.map From d8eb6857915eea222e040d954454e983f49bfb67 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:45:57 -0700 Subject: [PATCH 9/9] test(ts): regenerate the lang harness snapshot after merging origin/main Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/harness.ts | 104 ++++++++++++++------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 4f40b1c5d..4c0ec0dc5 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -29,7 +29,7 @@ import { locks, relock, rwlocks } from "./locks.ts"; import { nested } from "./nested.ts"; import { objects } from "./objects.ts"; import { lists, shared as pointers_shared, places, unchecked, nested as pointers_nested, copies, sentinels } from "./pointers.ts"; -import { refs } from "./refs.ts"; +import { refs, toRefs } from "./refs.ts"; import { copies as shapes_copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts"; import { splits } from "./splits.ts"; import { statics } from "./statics.ts"; @@ -42,106 +42,108 @@ import { wrappers } from "./wrappers.ts"; * case added at the end moves no other. */ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void][] { - return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_285: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { + return copy$str_forabfnu8au8bmutstdvecVecu8s([["ints::u8_op", u8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u16_op", u16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u32_op", u32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u64_op", u64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::u128_op", u128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::usize_op", usizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i8_op", i8Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i16_op", i16Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i32_op", i32Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i64_op", i64Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::i128_op", i128Op] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::isize_op", isizeOp] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::neg", neg] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::cast", cast] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::convert", (_288: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void => { convert(data, out); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_286: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::copies", (_289: rt.u8, data2: rt.ByteSlice, out2: rt.ByteVec): void => { shapes_copies(data2, out2); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_287: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::loops", (_290: rt.u8, data3: rt.ByteSlice, out3: rt.ByteVec): void => { loops(data3, out3); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_288: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::patterns", (_291: rt.u8, data4: rt.ByteSlice, out4: rt.ByteVec): void => { patterns(data4, out4); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_289: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::closures", (_292: rt.u8, data5: rt.ByteSlice, out5: rt.ByteVec): void => { closures(data5, out5); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_290: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::discriminants", (_293: rt.u8, data6: rt.ByteSlice, out6: rt.ByteVec): void => { discriminants(data6, out6); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_291: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::library", (_294: rt.u8, data7: rt.ByteSlice, out7: rt.ByteVec): void => { library(data7, out7); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_292: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::ints", ints] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::strings", (_295: rt.u8, data8: rt.ByteSlice, out8: rt.ByteVec): void => { strings(data8, out8); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_293: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::derived", (_296: rt.u8, data9: rt.ByteSlice, out9: rt.ByteVec): void => { derived(data9, out9); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_294: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::written", (_297: rt.u8, data10: rt.ByteSlice, out10: rt.ByteVec): void => { written(data10, out10); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_295: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::panics", panics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["generics::methods", (_298: rt.u8, data11: rt.ByteSlice, out11: rt.ByteVec): void => { methods(data11, out11); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_296: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::adaptors", adaptors] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::consumers", consumers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranges", (_299: rt.u8, data12: rt.ByteSlice, out12: rt.ByteVec): void => { ranges(data12, out12); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_297: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::options", (_2100: rt.u8, data13: rt.ByteSlice, out13: rt.ByteVec): void => { options(data13, out13); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_298: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::own", (_2101: rt.u8, data14: rt.ByteSlice, out14: rt.ByteVec): void => { own(data14, out14); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_299: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::values", (_2102: rt.u8, data15: rt.ByteSlice, out15: rt.ByteVec): void => { values(data15, out15); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_2100: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::order", (_2103: rt.u8, data16: rt.ByteSlice, out16: rt.ByteVec): void => { order(data16, out16); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_2101: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::hash_maps", hashMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::sets", sets] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::btree_maps", btreeMaps] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::deques", (_2104: rt.u8, data17: rt.ByteSlice, out17: rt.ByteVec): void => { deques(data17, out17); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_2102: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::flows", (_2105: rt.u8, data18: rt.ByteSlice, out18: rt.ByteVec): void => { flows(data18, out18); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2103: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::keys", keys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chars::chars", chars] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::strs", strs] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::vecs", (_2106: rt.u8, data19: rt.ByteSlice, out19: rt.ByteVec): void => { vecs(data19, out19); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2104: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["strs::slices", slices] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::stores", (_2107: rt.u8, data20: rt.ByteSlice, out20: rt.ByteVec): void => { stores(data20, out20); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2105: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["chunks::chunks", chunks] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cows::cows", cows] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["durations::durations", durations] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["combinators::combinators", combinators] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["splits::splits", splits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["nested::nested", nested] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::refs", (_2108: rt.u8, data21: rt.ByteSlice, out21: rt.ByteVec): void => { refs(data21, out21); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2106: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2109: 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", (_2107: rt.u8, _310: rt.ByteSlice, out23: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2110: rt.u8, _310: 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", (_2108: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { + }] 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", (_2111: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => { dyns(data23, out24); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2109: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["cells::cells", cells] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::shared", (_2112: rt.u8, data24: rt.ByteSlice, out25: rt.ByteVec): void => { shared(data24, out25); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2110: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::ranked", ranked] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["captures::captures", captures] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::locks", (_2113: rt.u8, data25: rt.ByteSlice, out26: rt.ByteVec): void => { locks(data25, out26); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2111: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::relock", (_2114: rt.u8, data26: rt.ByteSlice, out27: rt.ByteVec): void => { relock(data26, out27); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2112: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locals::locals", (_2115: rt.u8, data27: rt.ByteSlice, out28: rt.ByteVec): void => { locals(data27, out28); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2113: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["statics::statics", (_2116: rt.u8, data28: rt.ByteSlice, out29: rt.ByteVec): void => { statics(data28, out29); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2114: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["locks::rwlocks", (_2117: rt.u8, data29: rt.ByteSlice, out30: rt.ByteVec): void => { rwlocks(data29, out30); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2115: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["borrows::borrows", (_2118: rt.u8, data30: rt.ByteSlice, out31: rt.ByteVec): void => { borrows(data30, out31); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2116: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["defaults::defaults", (_2119: rt.u8, data31: rt.ByteSlice, out32: rt.ByteVec): void => { defaults(data31, out32); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2117: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::arcs", (_2120: rt.u8, data32: rt.ByteSlice, out33: rt.ByteVec): void => { arcs(data32, out33); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2118: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::rcs", (_2121: rt.u8, data33: rt.ByteSlice, out34: rt.ByteVec): void => { rcs(data33, out34); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2119: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_arcs", (_2122: rt.u8, data34: rt.ByteSlice, out35: rt.ByteVec): void => { cyclicArcs(data34, out35); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2120: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::cyclic_rcs", (_2123: rt.u8, data35: rt.ByteSlice, out36: rt.ByteVec): void => { cyclicRcs(data35, out36); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2121: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_arcs", (_2124: rt.u8, data36: rt.ByteSlice, out37: rt.ByteVec): void => { uniqueArcs(data36, out37); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2122: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["counts::unique_rcs", (_2125: rt.u8, data37: rt.ByteSlice, out38: rt.ByteVec): void => { uniqueRcs(data37, out38); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2123: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::anys", (_2126: rt.u8, data38: rt.ByteSlice, out39: rt.ByteVec): void => { anys(data38, out39); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2124: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::fns", (_2127: rt.u8, data39: rt.ByteSlice, out40: rt.ByteVec): void => { fns(data39, out40); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2125: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::copies", (_2128: rt.u8, data40: rt.ByteSlice, out41: rt.ByteVec): void => { copies(data40, out41); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2126: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::lists", (_2129: rt.u8, data41: rt.ByteSlice, out42: rt.ByteVec): void => { lists(data41, out42); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2127: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::nested", (_2130: rt.u8, data42: rt.ByteSlice, out43: rt.ByteVec): void => { pointers_nested(data42, out43); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2128: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::places", (_2131: rt.u8, data43: rt.ByteSlice, out44: rt.ByteVec): void => { places(data43, out44); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2129: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::sentinels", (_2132: rt.u8, data44: rt.ByteSlice, out45: rt.ByteVec): void => { sentinels(data44, out45); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2130: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::shared", (_2133: rt.u8, data45: rt.ByteSlice, out46: rt.ByteVec): void => { pointers_shared(data45, out46); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2131: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["pointers::unchecked", (_2134: rt.u8, data46: rt.ByteSlice, out47: rt.ByteVec): void => { unchecked(data46, out47); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2132: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::bytes", bytes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::from_fns", (_2135: rt.u8, data47: rt.ByteSlice, out48: rt.ByteVec): void => { fromFns(data47, out48); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2133: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["collections::optionals", optionals] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["objects::objects", (_2136: rt.u8, data48: rt.ByteSlice, out49: rt.ByteVec): void => { objects(data48, out49); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::wrapped", (_2134: rt.u8, data49: rt.ByteSlice, out50: rt.ByteVec): void => { + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["holds::holds", holds] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::wrapped", (_2137: rt.u8, data49: rt.ByteSlice, out50: rt.ByteVec): void => { wrapped(data49, out50); + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["refs::to_refs", (_2138: rt.u8, data50: rt.ByteSlice, out51: rt.ByteVec): void => { + toRefs(data50, out51); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8); }