diff --git a/quest/m2/README.md b/quest/m2/README.md index 44168a1ee..1e9b2c2e6 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -23,7 +23,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); - [MIR's codec as fast as THIR's](/quest/m2/ts-mir-codec.md) - the codec from MIR no slower than from THIR in any engine - [Lower bodies from MIR](/quest/m2/ts-mir.md) - the MIR spike's prototype becomes the only lowering, and the THIR one goes -- [Stable names](/quest/m2/ts-stable-names.md) - generic instances and trait-impl methods always carry their suffix, so callers' names never shift - [Struct update on a std range](/quest/m2/ts-range-update.md) - `Range { start, ..r }` reads its base, or is refused with a span, instead of dropping it or panicking the driver - [Cheaper byte slices](/quest/m2/ts-byte-views.md) - splitting a `&[u8]` stops making a `Uint8Array` view per split - [Wide-integer fast paths](/quest/m2/ts-wide-fast.md) - a fused `from_halves` and an unboxed limb product, kept only if measured faster diff --git a/quest/m2/ts-stable-names.md b/quest/m2/ts-stable-names.md deleted file mode 100644 index b4c6d9f99..000000000 --- a/quest/m2/ts-stable-names.md +++ /dev/null @@ -1,21 +0,0 @@ -# [S] Stable names in the TypeScript translator - -## Goal - -A caller's translated names never change when unrelated code adds a generic -instance or a trait impl. Every generic instance always prints its type-argument -suffix (`foo$u8`, `Wrap.get$Wrap_Pair`), and every trait-impl function always prints its -trait (`Pair.fmt$Display`), even when it is the only one. - -## Plan - -Decided with the maintainer on 2026-10-24: always suffix, in today's Rust-like -suffix format, not a hash. Today a generic function with one instance is `foo` -until a root reaches a second instance, and a type with only `Debug` gets `fmt` -until it also has `Display`; either change renames calls in code the new root -never reaches. Found in [#18](https://github.com/kixelated/rust2/pull/18) and -[#27](https://github.com/kixelated/rust2/pull/27), which notes that numbered `$2` -suffixes can shift the same way. - -Public API: the translator's output names for generic instances and trait-impl -methods. diff --git a/ts/MIGRATE.md b/ts/MIGRATE.md index 72fefc98a..ce202373c 100644 --- a/ts/MIGRATE.md +++ b/ts/MIGRATE.md @@ -10,8 +10,14 @@ `import * as Decoder from "./coding/decode.Decoder.ts"`, and name the type `Decoder.Decoder`. - A function of a type takes `self` first: `dec.slice(4)` is `Decoder.slice(dec, 4)`, - `group.encode(w, v)` is `Group.encode(group, w, v)`, and `Decoder.new(buf, form)` - keeps its spelling, from the type's module. + `group.encode(w, v)` is `Group.encode$Encode_Version(group, w, v)`, and + `Decoder.new(buf, form)` keeps its spelling, from the type's module. - An enum's functions move from its companion object to its module: `DecodeError.fmt$Display(err, f)` keeps its spelling, after `import * as DecodeError from "./coding/decode.DecodeError.ts"`. +- A function's suffix no longer depends on what else is reached. A trait impl's function + always names its trait, with the trait's type arguments, and a generic instance or a + function of a generic type always names its type arguments: `Log.clone` is + `Log.clone$Clone`, `Version.encode` is `Version.encode$Encode_Version`, and + `Wrap.fmt$Pair` is `Wrap.fmt$Debug_Pair`. A closure type in a suffix is named for where + it is defined, `decode_closure0`. diff --git a/ts/README.md b/ts/README.md index 2913885a1..b23f68e05 100644 --- a/ts/README.md +++ b/ts/README.md @@ -119,10 +119,15 @@ std's adaptors through `rt.iter.from`. A caller calls `next()` for one item, or an `rt.Iter` with `for ... of`. Functions and members are camelCase. Functions are monomorphized: each instance is its -own function, and instances that share a name are suffixed by type, as in -`roundtripLite$Group` or `Wrap.get$Wrap_Pair`. Types are translated once, generically, so -a function of a generic type is one instance's, declaring the instance it takes as -`self`: `fmt$Pair(self: Wrap, f: rt.Formatter)`. A type's module exports the +own function, suffixed after a `$` by its trait, then by its type's type arguments and +its own, as in `roundtripLite$Group`, `Wrap.get$Wrap_Pair`, `Pair.fmt$Debug`, and +`DecodeError.from$From_BoundsExceeded`. The suffix is there even when no other instance +is, so reaching one renames nothing. A closure type goes by where it is defined, +`methods_closure1` for `methods::{closure#1}`, and instances whose suffixes still match, +such as of two types of one name, are numbered `$2` on in the order of their full type +arguments. Types are translated once, generically, so a function of a generic type is one +instance's, declaring the instance it takes as `self`: +`fmt$Debug_Pair(self: Wrap, f: rt.Formatter)`. A type's module exports the type by its own name, which a caller writes `Decoder.Decoder`, and a function whose name and exports it as its own: `function new_` is `Decoder.new`. A `Copy` struct, tuple, or array, or an `Option` or `Result` holding one, is copied where Rust copies it, since JS @@ -144,8 +149,8 @@ microtask and yielding to a macrotask after 128 polls. A file's items follow the Rust source, whatever order translation reaches them in, so adding a root moves nothing it does not reach. What a macro makes sits where the macro is called. The instances of one function sit -together, sorted by their suffix (`Pair` in `fmt$Pair`) and then by their full type -arguments. +together, sorted by their suffix (`Debug_Pair` in `fmt$Debug_Pair`) and then by their +full type arguments. Imports name the `.ts` file, which Node, Bun, and bundlers run as is. A `tsc` build sets `rewriteRelativeImportExtensions`, or `allowImportingTsExtensions` with `noEmit`. diff --git a/ts/fixtures/codec/expected/bench.ts b/ts/fixtures/codec/expected/bench.ts index b67937064..f7934aacf 100644 --- a/ts/fixtures/codec/expected/bench.ts +++ b/ts/fixtures/codec/expected/bench.ts @@ -106,7 +106,7 @@ export function encodeFrames(data: Uint8Array, version: Version.Version, out: rt const [keyEvery, data6] = takeU64(data5); const [keySize, ] = takeU64(data6); const [delta2, keyEvery2] = [rt.i64.cast(delta), rt.u64.low(keyEvery)] as [rt.i64, rt.usize]; - let w: Encoder.Encoder = Encoder.new(out, Form.from(version)); + let w: Encoder.Encoder = Encoder.new(out, Form.from$From_Version(version)); const end = rt.u64.low(count); for (let n = 0; n < end; n++) { let value: [rt.i64, rt.u64]; @@ -137,7 +137,7 @@ export function encodeFrames(data: Uint8Array, version: Version.Version, out: rt /** Every FRAME header on the wire: how many, their total size, and the last delta. */ export function decodeFrames(wire: Uint8Array, version: Version.Version, out: rt.ByteVec): rt.Result { - let r: Decoder.Decoder = Decoder.new(wire, Form.from(version)); + let r: Decoder.Decoder = Decoder.new(wire, Form.from$From_Version(version)); let count: rt.usize = 0; let total: rt.u64 = 0; let last: rt.i64 = 0; @@ -179,7 +179,7 @@ export function decodeSplit(data: Uint8Array, version: Version.Version, out: rt. while (end < wire.length) { end = rt.min(wire.length, rt.usize.add(end, read2)); while (start < end) { - let r: Decoder.Decoder = Decoder.new(rt.slice.range(wire, start, end), Form.from(version)); + let r: Decoder.Decoder = Decoder.new(rt.slice.range(wire, start, end), Form.from$From_Version(version)); const frameHeader_ = frameHeader(r); if (frameHeader_.ok) { const delta = frameHeader_.value[0]; @@ -227,7 +227,7 @@ export function encodeGroup(data: Uint8Array, version: Version.Version, out: rt. const [subscribe, data2] = takeU64(data); const [sequence, ] = takeU64(data2); const group = { subscribe, sequence, frameStart: 0 }; - return Group.encode(group, Encoder.new(out, Form.from(version)), version); + return Group.encode$Encode_Version(group, Encoder.new(out, Form.from$From_Version(version)), version); } /** @@ -283,7 +283,7 @@ export function iterate(chain: rt.u8, data: Uint8Array, out: rt.ByteVec): void { } export function decodeGroup(wire: Uint8Array, version: Version.Version, out: rt.ByteVec): rt.Result { - const decodeSlice = Group.decodeSlice(wire, version); + const decodeSlice = Group.decodeSlice$Decode_Version(wire, version); if (!decodeSlice.ok) { return rt.Err(decodeSlice.error); } diff --git a/ts/fixtures/codec/expected/coding/decode.DecodeError.ts b/ts/fixtures/codec/expected/coding/decode.DecodeError.ts index 706cb63a4..a596c2547 100644 --- a/ts/fixtures/codec/expected/coding/decode.DecodeError.ts +++ b/ts/fixtures/codec/expected/coding/decode.DecodeError.ts @@ -55,7 +55,7 @@ export function fmt$Display(self: DecodeError, __formatter: rt.Formatter): rt.Re } } -export function from$FromUtf8Error(source: rt.FromUtf8Error): DecodeError { +export function from$From_FromUtf8Error(source: rt.FromUtf8Error): DecodeError { return { tag: "InvalidString", _0: source }; } @@ -138,7 +138,7 @@ export function complete(self: DecodeError): DecodeError { } } -export function from$BoundsExceeded(_: BoundsExceeded.BoundsExceeded): DecodeError { +export function from$From_BoundsExceeded(_: BoundsExceeded.BoundsExceeded): DecodeError { return { tag: "BoundsExceeded" }; } diff --git a/ts/fixtures/codec/expected/coding/decode.Decoder.ts b/ts/fixtures/codec/expected/coding/decode.Decoder.ts index 031a0c624..4b7731f54 100644 --- a/ts/fixtures/codec/expected/coding/decode.Decoder.ts +++ b/ts/fixtures/codec/expected/coding/decode.Decoder.ts @@ -173,7 +173,7 @@ export function string(self: Decoder): rt.Result { const write_ = write(v, self.form, self.buf); if (!write_.ok) { - return rt.Err(EncodeError.from(write_.error)); + return rt.Err(EncodeError.from$From_BoundsExceeded(write_.error)); } return rt.Ok(write_.value); } @@ -126,7 +126,7 @@ export function fill(self: Encoder, prefix: Prefix.Prefix): rt.Result { +export function decode$Decode_Form(r: Decoder.Decoder, _: Form.Form): rt.Result { const varint = Decoder.varint(r); if (!varint.ok) { return rt.Err(varint.error); @@ -23,7 +23,7 @@ export function decode(r: Decoder.Decoder, _: Form.Form): rt.Result { +export function encode$Encode_Form(self: Version, w: Encoder.Encoder, _: Form.Form): rt.Result { const varint = Encoder.varint(w, self._0); if (!varint.ok) { return rt.Err(varint.error); @@ -32,7 +32,7 @@ export function encode$Form(self: Version, w: Encoder.Encoder, _: Form.Form): rt } /** Encode the value to the given encoder, which may hold partial output on error. */ -export function encode$Version(self: Version, w: Encoder.Encoder, _: version_Version.Version): rt.Result { +export function encode$Encode_Version(self: Version, w: Encoder.Encoder, _: version_Version.Version): rt.Result { const varint = Encoder.varint(w, self._0); if (!varint.ok) { return rt.Err(varint.error); diff --git a/ts/fixtures/codec/expected/coding/version.Versions.ts b/ts/fixtures/codec/expected/coding/version.Versions.ts index 1f7388a13..a63cf77ce 100644 --- a/ts/fixtures/codec/expected/coding/version.Versions.ts +++ b/ts/fixtures/codec/expected/coding/version.Versions.ts @@ -10,13 +10,13 @@ import * as Version from "../coding/version.Version.ts"; import type * as version_Version from "../lite/version.Version.ts"; /** Decode the value from the front of `buf`, returning it and the bytes it took. */ -export function decodeSlice(buf: Uint8Array, version: Form.Form): rt.Result<[Versions, rt.usize], DecodeError.DecodeError> { +export function decodeSlice$Decode_Form(buf: Uint8Array, version: Form.Form): rt.Result<[Versions, rt.usize], DecodeError.DecodeError> { let r: Decoder.Decoder = Decoder.new(buf, version); - const decode_ = decode(r, version); - if (!decode_.ok) { - return rt.Err(decode_.error); + const decode = decode$Decode_Form(r, version); + if (!decode.ok) { + return rt.Err(decode.error); } - const value = decode_.value; + const value = decode.value; return rt.Ok([value, rt.usize.sub(buf.length, Decoder.remaining(r))]); } @@ -26,7 +26,7 @@ export interface Versions { } /** Decode the version list. */ -export function decode(r: Decoder.Decoder, version: Form.Form): rt.Result { +export function decode$Decode_Form(r: Decoder.Decoder, version: Form.Form): rt.Result { const varint = Decoder.varint(r); if (!varint.ok) { return rt.Err(varint.error); @@ -35,24 +35,24 @@ export function decode(r: Decoder.Decoder, version: Form.Form): rt.Result { +export function encode$Encode_Form(self: Versions, w: Encoder.Encoder, version: Form.Form): rt.Result { const varint = Encoder.varint(w, self._0.length as rt.u64); if (!varint.ok) { return rt.Err(varint.error); } for (const v of self._0) { - const encode = Version.encode$Form(v, w, version); + const encode = Version.encode$Encode_Form(v, w, version); if (!encode.ok) { return rt.Err(encode.error); } @@ -61,13 +61,13 @@ export function encode$Form(self: Versions, w: Encoder.Encoder, version: Form.Fo } /** Encode the version list. */ -export function encode$Version(self: Versions, w: Encoder.Encoder, version: version_Version.Version): rt.Result { +export function encode$Encode_Version(self: Versions, w: Encoder.Encoder, version: version_Version.Version): rt.Result { const varint = Encoder.varint(w, self._0.length as rt.u64); if (!varint.ok) { return rt.Err(varint.error); } for (const v of self._0) { - const encode = Version.encode$Version(v, w, version); + const encode = Version.encode$Encode_Version(v, w, version); if (!encode.ok) { return rt.Err(encode.error); } @@ -75,7 +75,7 @@ export function encode$Version(self: Versions, w: Encoder.Encoder, version: vers return rt.Ok(undefined); } -export function from(vs: Version.Version[]): Versions { +export function from$From_Versions(vs: Version.Version[]): Versions { return { _0: rt.slice.toVec(vs) }; } diff --git a/ts/fixtures/codec/expected/harness.ts b/ts/fixtures/codec/expected/harness.ts index 4f42f449a..c688abfdc 100644 --- a/ts/fixtures/codec/expected/harness.ts +++ b/ts/fixtures/codec/expected/harness.ts @@ -34,7 +34,7 @@ export function run(input: Uint8Array): rt.ByteVec { } else if (value === 3) { sizes(data, out); } else if (value === 4) { - roundtrip(data, out); + roundtrip$Versions(data, out); } else if (value === 5) { roundtripLite$Group(data, out); } else if (value === 6) { @@ -398,7 +398,7 @@ export function sizes(data: Uint8Array, out: rt.ByteVec): void { } /** Decode a `T` from the wire, then encode what came out. */ -export function roundtrip(data: Uint8Array, out: rt.ByteVec): void { +export function roundtrip$Versions(data: Uint8Array, out: rt.ByteVec): void { const splitFirst = rt.slice.splitFirst(data); if (splitFirst === undefined) { return; @@ -406,13 +406,13 @@ export function roundtrip(data: Uint8Array, out: rt.ByteVec): void { const selector = splitFirst[0]; const wire = splitFirst[1]; const form_ = form(selector); - const decodeSlice = Versions.decodeSlice(wire, form_); + const decodeSlice = Versions.decodeSlice$Decode_Form(wire, form_); if (decodeSlice.ok) { const value = decodeSlice.value[0]; const used = decodeSlice.value[1]; putUsize(out, used); let buf: rt.ByteVec = new rt.ByteVec(); - const encode = Versions.encode$Form(value, Encoder.new(buf, form_), form_); + const encode = Versions.encode$Encode_Form(value, Encoder.new(buf, form_), form_); if (encode.ok) { out.extendFromSlice(buf.view()); } else { @@ -434,13 +434,13 @@ export function roundtripLite$Group(data: Uint8Array, out: rt.ByteVec): void { const selector = splitFirst[0]; const wire = splitFirst[1]; const version = liteVersion(selector); - const decodeSlice = Group.decodeSlice(wire, version); + const decodeSlice = Group.decodeSlice$Decode_Version(wire, version); if (decodeSlice.ok) { const value = decodeSlice.value[0]; const used = decodeSlice.value[1]; putUsize(out, used); let buf: rt.ByteVec = new rt.ByteVec(); - const encode = Group.encode(value, Encoder.new(buf, Form.from(version)), version); + const encode = Group.encode$Encode_Version(value, Encoder.new(buf, Form.from$From_Version(version)), version); if (encode.ok) { out.extendFromSlice(buf.view()); } else { @@ -462,13 +462,13 @@ export function roundtripLite$Probe(data: Uint8Array, out: rt.ByteVec): void { const selector = splitFirst[0]; const wire = splitFirst[1]; const version = liteVersion(selector); - const decodeSlice = Probe.decodeSlice(wire, version); + const decodeSlice = Probe.decodeSlice$Decode_Version(wire, version); if (decodeSlice.ok) { const value = decodeSlice.value[0]; const used = decodeSlice.value[1]; putUsize(out, used); let buf: rt.ByteVec = new rt.ByteVec(); - const encode = Probe.encode(value, Encoder.new(buf, Form.from(version)), version); + const encode = Probe.encode$Encode_Version(value, Encoder.new(buf, Form.from$From_Version(version)), version); if (encode.ok) { out.extendFromSlice(buf.view()); } else { @@ -499,9 +499,9 @@ export function encodeMessages(data: Uint8Array, out: rt.ByteVec): void { encodeMessage$Group(group, version, out); const probe = { bitrate: rt.u64.checkedSub(bitrate, 1), rtt: rt.thenSome(rt.u64.rem(rtt, 3) !== 0, rtt) }; encodeMessage$Probe(probe, version, out); - const versions = Versions.from([{ _0: subscribe }, { _0: sequence }]); + const versions = Versions.from$From_Versions([{ _0: subscribe }, { _0: sequence }]); let buf: rt.ByteVec = new rt.ByteVec(); - const encode = Versions.encode$Version(versions, Encoder.new(buf, Form.from(version)), version); + const encode = Versions.encode$Encode_Version(versions, Encoder.new(buf, Form.from$From_Version(version)), version); if (encode.ok) { out.extendFromSlice(buf.view()); } else { @@ -512,8 +512,8 @@ export function encodeMessages(data: Uint8Array, out: rt.ByteVec): void { export function encodeMessage$Group(msg: Group.Group, version: Version.Version, out: rt.ByteVec): void { let buf: rt.ByteVec = new rt.ByteVec(); - let w: Encoder.Encoder = Encoder.new(buf, Form.from(version)); - const encode = Group.encode(msg, w, version); + let w: Encoder.Encoder = Encoder.new(buf, Form.from$From_Version(version)); + const encode = Group.encode$Encode_Version(msg, w, version); if (encode.ok) { out.push(w.control !== undefined ? 1 : 0); putUsize(out, buf.length); @@ -526,8 +526,8 @@ export function encodeMessage$Group(msg: Group.Group, version: Version.Version, export function encodeMessage$Probe(msg: Probe.Probe, version: Version.Version, out: rt.ByteVec): void { let buf: rt.ByteVec = new rt.ByteVec(); - let w: Encoder.Encoder = Encoder.new(buf, Form.from(version)); - const encode = Probe.encode(msg, w, version); + let w: Encoder.Encoder = Encoder.new(buf, Form.from$From_Version(version)); + const encode = Probe.encode$Encode_Version(msg, w, version); if (encode.ok) { out.push(w.control !== undefined ? 1 : 0); putUsize(out, buf.length); @@ -566,7 +566,7 @@ export function errors(data: Uint8Array, out: rt.ByteVec): void { err = { tag: "InvalidString", _0: e }; } } else if (value2 === 5) { - err = DecodeError.from$BoundsExceeded({}); + err = DecodeError.from$From_BoundsExceeded({}); } else if (value2 === 6) { const bounds = {}; putText(out, rt.fmt.toString((f: rt.Formatter) => BoundsExceeded.fmt$Display(bounds, f)), rt.fmt.format([(f: rt.Formatter) => BoundsExceeded.fmt$Debug(bounds, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => BoundsExceeded.fmt$Debug(bounds, f))])); diff --git a/ts/fixtures/codec/expected/lite/group.Group.ts b/ts/fixtures/codec/expected/lite/group.Group.ts index 197f817ac..d0512235a 100644 --- a/ts/fixtures/codec/expected/lite/group.Group.ts +++ b/ts/fixtures/codec/expected/lite/group.Group.ts @@ -6,17 +6,17 @@ import * as Decoder from "../coding/decode.Decoder.ts"; import type * as EncodeError from "../coding/encode.EncodeError.ts"; import * as Encoder from "../coding/encode.Encoder.ts"; import * as Form from "../coding/varint.Form.ts"; -import { decodeWith$Group } from "../lite/message.ts"; +import { decodeWith$Group_decode_closure0 } from "../lite/message.ts"; import * as Version from "../lite/version.Version.ts"; /** Decode the value from the front of `buf`, returning it and the bytes it took. */ -export function decodeSlice(buf: Uint8Array, version: Version.Version): rt.Result<[Group, rt.usize], DecodeError.DecodeError> { - let r: Decoder.Decoder = Decoder.new(buf, Form.from(version)); - const decode_ = decode(r, version); - if (!decode_.ok) { - return rt.Err(decode_.error); +export function decodeSlice$Decode_Version(buf: Uint8Array, version: Version.Version): rt.Result<[Group, rt.usize], DecodeError.DecodeError> { + let r: Decoder.Decoder = Decoder.new(buf, Form.from$From_Version(version)); + const decode = decode$Decode_Version(r, version); + if (!decode.ok) { + return rt.Err(decode.error); } - const value = decode_.value; + const value = decode.value; return rt.Ok([value, rt.usize.sub(buf.length, Decoder.remaining(r))]); } @@ -27,7 +27,7 @@ export interface Group { } /** Decode a message body (without size prefix). */ -export function decodeMsg(r: Decoder.Decoder, version: Version.Version): rt.Result { +export function decodeMsg$Message(r: Decoder.Decoder, version: Version.Version): rt.Result { const varint = Decoder.varint(r); if (!varint.ok) { return rt.Err(varint.error); @@ -52,7 +52,7 @@ export function decodeMsg(r: Decoder.Decoder, version: Version.Version): rt.Resu } /** Encode this message body (without size prefix). */ -export function encodeMsg(self: Group, w: Encoder.Encoder, version: Version.Version): rt.Result { +export function encodeMsg$Message(self: Group, w: Encoder.Encoder, version: Version.Version): rt.Result { const varint = Encoder.varint(w, self.subscribe); if (!varint.ok) { return rt.Err(varint.error); @@ -73,11 +73,11 @@ export function encodeMsg(self: Group, w: Encoder.Encoder, version: Version.Vers } /** Encode the value to the given encoder, which may hold partial output on error. */ -export function encode(self: Group, w: Encoder.Encoder, version: Version.Version): rt.Result { +export function encode$Encode_Version(self: Group, w: Encoder.Encoder, version: Version.Version): rt.Result { const prefix = Encoder.prefixVarint(w); - const encodeMsg_ = encodeMsg(self, w, version); - if (!encodeMsg_.ok) { - return rt.Err(encodeMsg_.error); + const encodeMsg = encodeMsg$Message(self, w, version); + if (!encodeMsg.ok) { + return rt.Err(encodeMsg.error); } if (Encoder.since(w, prefix) > 65535) { Encoder.discard(w, prefix); @@ -92,9 +92,9 @@ export function encode(self: Group, w: Encoder.Encoder, version: Version.Version } /** Decode the value from the front of the decoder. */ -export function decode(r: Decoder.Decoder, version: Version.Version): rt.Result { - return decodeWith$Group(r, (body: Decoder.Decoder): rt.Result => { - return decodeMsg(body, version); +export function decode$Decode_Version(r: Decoder.Decoder, version: Version.Version): rt.Result { + return decodeWith$Group_decode_closure0(r, (body: Decoder.Decoder): rt.Result => { + return decodeMsg$Message(body, version); }); } diff --git a/ts/fixtures/codec/expected/lite/message.ts b/ts/fixtures/codec/expected/lite/message.ts index c6a676405..b232ee69a 100644 --- a/ts/fixtures/codec/expected/lite/message.ts +++ b/ts/fixtures/codec/expected/lite/message.ts @@ -30,7 +30,7 @@ export function decodeSize(r: Decoder.Decoder, max: rt.usize): rt.Result rt.Result): rt.Result { +export function decodeWith$Group_decode_closure0(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result): rt.Result { const decodeSize_ = decodeSize(r, 65535); if (!decodeSize_.ok) { return rt.Err(decodeSize_.error); @@ -58,7 +58,7 @@ export function decodeWith$Group(r: Decoder.Decoder, decode: (a0: Decoder.Decode * Decode a size-prefixed `T`, reading its body with `decode` in place of * [`Message::decode_msg`], for a body whose bounds come from the session. */ -export function decodeWith$Probe(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result): rt.Result { +export function decodeWith$Probe_decode_closure0(r: Decoder.Decoder, decode: (a0: Decoder.Decoder) => rt.Result): rt.Result { const decodeSize_ = decodeSize(r, 65535); if (!decodeSize_.ok) { return rt.Err(decodeSize_.error); diff --git a/ts/fixtures/codec/expected/lite/probe.Probe.ts b/ts/fixtures/codec/expected/lite/probe.Probe.ts index 37bcb5a9b..65d08bd16 100644 --- a/ts/fixtures/codec/expected/lite/probe.Probe.ts +++ b/ts/fixtures/codec/expected/lite/probe.Probe.ts @@ -6,27 +6,27 @@ import * as Decoder from "../coding/decode.Decoder.ts"; import type * as EncodeError from "../coding/encode.EncodeError.ts"; import * as Encoder from "../coding/encode.Encoder.ts"; import * as Form from "../coding/varint.Form.ts"; -import { decodeWith$Probe } from "../lite/message.ts"; +import { decodeWith$Probe_decode_closure0 } from "../lite/message.ts"; import * as Version from "../lite/version.Version.ts"; import type * as Control from "../stats.Control.ts"; /** Decode the value from the front of `buf`, returning it and the bytes it took. */ -export function decodeSlice(buf: Uint8Array, version: Version.Version): rt.Result<[Probe, rt.usize], DecodeError.DecodeError> { - let r: Decoder.Decoder = Decoder.new(buf, Form.from(version)); - const decode_ = decode(r, version); - if (!decode_.ok) { - return rt.Err(decode_.error); +export function decodeSlice$Decode_Version(buf: Uint8Array, version: Version.Version): rt.Result<[Probe, rt.usize], DecodeError.DecodeError> { + let r: Decoder.Decoder = Decoder.new(buf, Form.from$From_Version(version)); + const decode = decode$Decode_Version(r, version); + if (!decode.ok) { + return rt.Err(decode.error); } - const value = decode_.value; + const value = decode.value; return rt.Ok([value, rt.usize.sub(buf.length, Decoder.remaining(r))]); } /** Encode the value to the given encoder, which may hold partial output on error. */ -export function encode(self: Probe, w: Encoder.Encoder, version: Version.Version): rt.Result { +export function encode$Encode_Version(self: Probe, w: Encoder.Encoder, version: Version.Version): rt.Result { const prefix = Encoder.prefixVarint(w); - const encodeMsg_ = encodeMsg(self, w, version); - if (!encodeMsg_.ok) { - return rt.Err(encodeMsg_.error); + const encodeMsg = encodeMsg$Message(self, w, version); + if (!encodeMsg.ok) { + return rt.Err(encodeMsg.error); } if (Encoder.since(w, prefix) > 65535) { Encoder.discard(w, prefix); @@ -41,9 +41,9 @@ export function encode(self: Probe, w: Encoder.Encoder, version: Version.Version } /** Decode the value from the front of the decoder. */ -export function decode(r: Decoder.Decoder, version: Version.Version): rt.Result { - return decodeWith$Probe(r, (body: Decoder.Decoder): rt.Result => { - return decodeMsg(body, version); +export function decode$Decode_Version(r: Decoder.Decoder, version: Version.Version): rt.Result { + return decodeWith$Probe_decode_closure0(r, (body: Decoder.Decoder): rt.Result => { + return decodeMsg$Message(body, version); }); } @@ -59,7 +59,7 @@ export interface Probe { } /** Decode a message body (without size prefix). */ -export function decodeMsg(r: Decoder.Decoder, version: Version.Version): rt.Result { +export function decodeMsg$Message(r: Decoder.Decoder, version: Version.Version): rt.Result { if (version === "Lite01" || version === "Lite02") { return rt.Err({ tag: "Version" }); } @@ -93,7 +93,7 @@ export function decodeMsg(r: Decoder.Decoder, version: Version.Version): rt.Resu } /** Encode this message body (without size prefix). */ -export function encodeMsg(self: Probe, w: Encoder.Encoder, version: Version.Version): rt.Result { +export function encodeMsg$Message(self: Probe, w: Encoder.Encoder, version: Version.Version): rt.Result { if (version === "Lite01" || version === "Lite02") { return rt.Err("Version"); } diff --git a/ts/fixtures/lang/expected/fmt.Bare.ts b/ts/fixtures/lang/expected/fmt.Bare.ts index c077a22ef..1edb19cc8 100644 --- a/ts/fixtures/lang/expected/fmt.Bare.ts +++ b/ts/fixtures/lang/expected/fmt.Bare.ts @@ -2,11 +2,11 @@ import * as rt from "./rt.ts"; -export function fmt(_self: Bare, f: rt.Formatter): rt.Result { +export function fmt$Debug(_self: Bare, f: rt.Formatter): rt.Result { return f.writeStr("Bare"); } -export function eq(_self: Bare, _other: Bare): boolean { +export function eq$PartialEq(_self: Bare, _other: Bare): boolean { return true; } diff --git a/ts/fixtures/lang/expected/fmt.Braced.ts b/ts/fixtures/lang/expected/fmt.Braced.ts index 3861890be..66fddac24 100644 --- a/ts/fixtures/lang/expected/fmt.Braced.ts +++ b/ts/fixtures/lang/expected/fmt.Braced.ts @@ -2,11 +2,11 @@ import * as rt from "./rt.ts"; -export function fmt(_self: Braced, f: rt.Formatter): rt.Result { +export function fmt$Debug(_self: Braced, f: rt.Formatter): rt.Result { return f.writeStr("Braced"); } -export function eq(_self: Braced, _other: Braced): boolean { +export function eq$PartialEq(_self: Braced, _other: Braced): boolean { return true; } diff --git a/ts/fixtures/lang/expected/fmt.Fails.ts b/ts/fixtures/lang/expected/fmt.Fails.ts index e5a0e4ea6..365b8ebbd 100644 --- a/ts/fixtures/lang/expected/fmt.Fails.ts +++ b/ts/fixtures/lang/expected/fmt.Fails.ts @@ -7,7 +7,7 @@ export interface Fails { _0: rt.u8; } -export function fmt(self: Fails, f: rt.Formatter): rt.Result { +export function fmt$Display(self: Fails, f: rt.Formatter): rt.Result { if (rt.u8.rem(self._0, 2) === 0) { return f.writeStr("fine"); } diff --git a/ts/fixtures/lang/expected/fmt.Fault.ts b/ts/fixtures/lang/expected/fmt.Fault.ts index d0af8d0bd..096fa125a 100644 --- a/ts/fixtures/lang/expected/fmt.Fault.ts +++ b/ts/fixtures/lang/expected/fmt.Fault.ts @@ -15,7 +15,7 @@ export function fmt$Debug(self: Fault, f: rt.Formatter): rt.Result rt.usize.display(__self02, f)).field("max", (f: rt.Formatter) => rt.usize.display(__self1, f)).finish(); } else { const __self03 = self._0; - return f.debugTuple("At").field((f: rt.Formatter) => Pair.fmt(__self03, f)).finish(); + return f.debugTuple("At").field((f: rt.Formatter) => Pair.fmt$Debug(__self03, f)).finish(); } } @@ -41,7 +41,7 @@ export function fmt$Display(self: Fault, f: rt.Formatter): rt.Result rt.usize.display(size, f), " bytes exceeds the ", (f: rt.Formatter) => rt.usize.display(max, f), " byte limit"]); } else { const pair = self._0; - return f.writeFmt(["at ", (f: rt.Formatter) => Pair.fmt(pair, f)]); + return f.writeFmt(["at ", (f: rt.Formatter) => Pair.fmt$Debug(pair, f)]); } } diff --git a/ts/fixtures/lang/expected/fmt.Kind.ts b/ts/fixtures/lang/expected/fmt.Kind.ts index 69dd2dab2..6c4e507fc 100644 --- a/ts/fixtures/lang/expected/fmt.Kind.ts +++ b/ts/fixtures/lang/expected/fmt.Kind.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(self: Kind, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Kind, f: rt.Formatter): rt.Result { if (self.tag === "Empty") { return f.writeStr("Empty"); } else if (self.tag === "Braced") { diff --git a/ts/fixtures/lang/expected/fmt.Manual.ts b/ts/fixtures/lang/expected/fmt.Manual.ts index cff171c51..5d5771161 100644 --- a/ts/fixtures/lang/expected/fmt.Manual.ts +++ b/ts/fixtures/lang/expected/fmt.Manual.ts @@ -8,7 +8,7 @@ export interface Manual { list: rt.u16[]; } -export function fmt(self: Manual, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Manual, f: rt.Formatter): rt.Result { return f.debugStruct("Manual").field("id", (f: rt.Formatter) => rt.u8.display(self.id, f)).field("list", (f: rt.Formatter) => rt.fmt.list(self.list, f, rt.u16.display)).finishNonExhaustive(); } diff --git a/ts/fixtures/lang/expected/fmt.Nested.ts b/ts/fixtures/lang/expected/fmt.Nested.ts index 4776b61a8..d5288aa47 100644 --- a/ts/fixtures/lang/expected/fmt.Nested.ts +++ b/ts/fixtures/lang/expected/fmt.Nested.ts @@ -6,9 +6,9 @@ import * as Pair from "./fmt.Pair.ts"; import * as Point from "./shapes.Point.ts"; import * as Shape from "./shapes.Shape.ts"; -export function fmt(self: Nested, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Nested, f: rt.Formatter): rt.Result { const names = ["name", "point", "shape", "tags", "pairs", "maybe", "none", "result", "list", "tuple", "single", "empty", "unit", "boxed"]; - const values = [(f: rt.Formatter) => rt.fmt.str(self.name, f), (f: rt.Formatter) => Point.fmt(self.point, f), (f: rt.Formatter) => Shape.fmt(self.shape, f), (f: rt.Formatter) => rt.fmt.list(self.tags.view(), f, rt.u8.display), (f: rt.Formatter) => rt.fmt.list(self.pairs, f, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt(value, f)), (f: rt.Formatter) => rt.fmt.option(self.maybe, f, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt(value, f)), (f: rt.Formatter) => rt.fmt.option(self.none, f, rt.u8.display), (f: rt.Formatter) => rt.fmt.result(self.result, f, rt.u8.display, rt.fmt.str), (f: rt.Formatter) => rt.fmt.list(self.list, f, rt.i16.display), (f: rt.Formatter) => rt.fmt.tuple([(f: rt.Formatter) => rt.u8.display(self.tuple[0], f), (f: rt.Formatter) => rt.fmt.bool(self.tuple[1], f), (f: rt.Formatter) => rt.fmt.str(self.tuple[2], f)], f), (f: rt.Formatter) => rt.fmt.tuple([(f: rt.Formatter) => rt.u8.display(self.single[0], f)], f), (f: rt.Formatter) => rt.fmt.list(self.empty.view(), f, rt.u8.display), (f: rt.Formatter) => rt.fmt.unit(self.unit, f), (f: rt.Formatter) => Kind.fmt(self.boxed, f)]; + const values = [(f: rt.Formatter) => rt.fmt.str(self.name, f), (f: rt.Formatter) => Point.fmt$Debug(self.point, f), (f: rt.Formatter) => Shape.fmt$Debug(self.shape, f), (f: rt.Formatter) => rt.fmt.list(self.tags.view(), f, rt.u8.display), (f: rt.Formatter) => rt.fmt.list(self.pairs, f, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt$Debug(value, f)), (f: rt.Formatter) => rt.fmt.option(self.maybe, f, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt$Debug(value, f)), (f: rt.Formatter) => rt.fmt.option(self.none, f, rt.u8.display), (f: rt.Formatter) => rt.fmt.result(self.result, f, rt.u8.display, rt.fmt.str), (f: rt.Formatter) => rt.fmt.list(self.list, f, rt.i16.display), (f: rt.Formatter) => rt.fmt.tuple([(f: rt.Formatter) => rt.u8.display(self.tuple[0], f), (f: rt.Formatter) => rt.fmt.bool(self.tuple[1], f), (f: rt.Formatter) => rt.fmt.str(self.tuple[2], f)], f), (f: rt.Formatter) => rt.fmt.tuple([(f: rt.Formatter) => rt.u8.display(self.single[0], f)], f), (f: rt.Formatter) => rt.fmt.list(self.empty.view(), f, rt.u8.display), (f: rt.Formatter) => rt.fmt.unit(self.unit, f), (f: rt.Formatter) => Kind.fmt$Debug(self.boxed, f)]; return f.debugStructFields("Nested", names, values); } diff --git a/ts/fixtures/lang/expected/fmt.Padded.ts b/ts/fixtures/lang/expected/fmt.Padded.ts index 2bdbb9b6a..3d8cf6d2b 100644 --- a/ts/fixtures/lang/expected/fmt.Padded.ts +++ b/ts/fixtures/lang/expected/fmt.Padded.ts @@ -2,12 +2,12 @@ import * as rt from "./rt.ts"; -/** `Display` through `pad`, which keeps the options. */ +/** `Display` through `pad`, which keeps the options. Only `added` prints its `Debug`. */ export interface Padded { _0: string; } -export function fmt(self: Padded, f: rt.Formatter): rt.Result { +export function fmt$Display(self: Padded, f: rt.Formatter): rt.Result { const width = f.width(); arms: { if (width !== undefined) { diff --git a/ts/fixtures/lang/expected/fmt.Pair.ts b/ts/fixtures/lang/expected/fmt.Pair.ts index 5611277bc..dd95558d9 100644 --- a/ts/fixtures/lang/expected/fmt.Pair.ts +++ b/ts/fixtures/lang/expected/fmt.Pair.ts @@ -2,11 +2,11 @@ import * as rt from "./rt.ts"; -export function fmt(self: Pair, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Pair, f: rt.Formatter): rt.Result { return f.debugTuple("Pair").field((f: rt.Formatter) => rt.u8.display(self._0, f)).field((f: rt.Formatter) => rt.i64.display(self._1, f)).finish(); } -export function eq(self: Pair, other: Pair): boolean { +export function eq$PartialEq(self: Pair, other: Pair): boolean { return self._0 === other._0 && rt.i64.eq(self._1, other._1); } diff --git a/ts/fixtures/lang/expected/fmt.Seq.ts b/ts/fixtures/lang/expected/fmt.Seq.ts index 805fa13fd..d1617a3fe 100644 --- a/ts/fixtures/lang/expected/fmt.Seq.ts +++ b/ts/fixtures/lang/expected/fmt.Seq.ts @@ -7,8 +7,8 @@ export interface Seq { _0: Pair.Pair[]; } -export function fmt(self: Seq, f: rt.Formatter): rt.Result { - return f.debugList().entries(self._0, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt(value, f)).finish(); +export function fmt$Debug(self: Seq, f: rt.Formatter): rt.Result { + return f.debugList().entries(self._0, (value: Pair.Pair, f: rt.Formatter) => Pair.fmt$Debug(value, f)).finish(); } //# sourceMappingURL=fmt.Seq.ts.map diff --git a/ts/fixtures/lang/expected/fmt.Six.ts b/ts/fixtures/lang/expected/fmt.Six.ts index 11b6ec36d..c7764b23d 100644 --- a/ts/fixtures/lang/expected/fmt.Six.ts +++ b/ts/fixtures/lang/expected/fmt.Six.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(self: Six, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Six, f: rt.Formatter): rt.Result { const values = [(f: rt.Formatter) => rt.u8.display(self._0, f), (f: rt.Formatter) => rt.u8.display(self._1, f), (f: rt.Formatter) => rt.u8.display(self._2, f), (f: rt.Formatter) => rt.u8.display(self._3, f), (f: rt.Formatter) => rt.u8.display(self._4, f), (f: rt.Formatter) => rt.u8.display(self._5, f)]; return f.debugTupleFields("Six", values); } diff --git a/ts/fixtures/lang/expected/fmt.Tup.ts b/ts/fixtures/lang/expected/fmt.Tup.ts index a7e153ac8..eaeecfe1b 100644 --- a/ts/fixtures/lang/expected/fmt.Tup.ts +++ b/ts/fixtures/lang/expected/fmt.Tup.ts @@ -7,7 +7,7 @@ export interface Tup { _1: rt.u8 | undefined; } -export function fmt(self: Tup, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Tup, f: rt.Formatter): rt.Result { if (self._1 !== undefined) { return f.debugTuple("Tup").field((f: rt.Formatter) => rt.u8.display(self._0, f)).field((f: rt.Formatter) => rt.fmt.option(self._1, f, rt.u8.display)).finish(); } else { diff --git a/ts/fixtures/lang/expected/fmt.Unit.ts b/ts/fixtures/lang/expected/fmt.Unit.ts index 5a278757e..84bc6ae5f 100644 --- a/ts/fixtures/lang/expected/fmt.Unit.ts +++ b/ts/fixtures/lang/expected/fmt.Unit.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(_self: Unit, f: rt.Formatter): rt.Result { +export function fmt$Debug(_self: Unit, f: rt.Formatter): rt.Result { return f.writeStr("Unit"); } diff --git a/ts/fixtures/lang/expected/fmt.Wide.ts b/ts/fixtures/lang/expected/fmt.Wide.ts index a1bd37cf3..f09bd394e 100644 --- a/ts/fixtures/lang/expected/fmt.Wide.ts +++ b/ts/fixtures/lang/expected/fmt.Wide.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(self: Wide, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Wide, f: rt.Formatter): rt.Result { const names = ["a", "b", "c", "d", "e", "f"]; const values = [(f: rt.Formatter) => rt.u8.display(self.a, f), (f: rt.Formatter) => rt.u16.display(self.b, f), (f: rt.Formatter) => rt.u32.display(self.c, f), (f: rt.Formatter) => rt.u64.display(self.d, f), (f: rt.Formatter) => rt.i8.display(self.e, f), (f: rt.Formatter) => rt.fmt.bool(self.f, f)]; return f.debugStructFields("Wide", names, values); diff --git a/ts/fixtures/lang/expected/fmt.ts b/ts/fixtures/lang/expected/fmt.ts index 5a5fb310a..a6cf2cd29 100644 --- a/ts/fixtures/lang/expected/fmt.ts +++ b/ts/fixtures/lang/expected/fmt.ts @@ -194,24 +194,24 @@ export function derived(data: Uint8Array, out: rt.ByteVec): void { return rt.option.unwrapOr(rt.slice.get(data, i), 0); }; const value = nested(data); - put(out, rt.fmt.format([(f: rt.Formatter) => Nested.fmt(value, f)])); - put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Nested.fmt(value, f))])); + put(out, rt.fmt.format([(f: rt.Formatter) => Nested.fmt$Debug(value, f)])); + put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Nested.fmt$Debug(value, f))])); const wide = { a: at(0), b: 300, c: 70_000, d: rt.u64.of(18446744073709551615n), e: -1, f: at(1) > 10 }; const six = { _0: at(0), _1: 1, _2: 2, _3: 3, _4: 4, _5: at(1) }; const arg3 = out; const arg = {}; const arg2 = {}; - put(arg3, rt.fmt.format([(f: rt.Formatter) => Wide.fmt(wide, f), " ", (f: rt.Formatter) => Six.fmt(six, f), " ", (f: rt.Formatter) => Unit.fmt(arg, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Unit.fmt(arg2, f))])); - put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Wide.fmt(wide, f)), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Six.fmt(six, f))])); + put(arg3, rt.fmt.format([(f: rt.Formatter) => Wide.fmt$Debug(wide, f), " ", (f: rt.Formatter) => Six.fmt$Debug(six, f), " ", (f: rt.Formatter) => Unit.fmt$Debug(arg, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Unit.fmt$Debug(arg2, f))])); + put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Wide.fmt$Debug(wide, f)), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Six.fmt$Debug(six, f))])); const point = { x: at(2) as rt.i32, y: -1 }; const arg5 = out; const arg4 = { _0: at(3), _1: -9 }; - put(arg5, rt.fmt.format([rt.fmt.spec({ width: 5 }, (f: rt.Formatter) => Point.fmt(point, f)), "|", rt.fmt.spec({ align: "<", width: 4 }, (f: rt.Formatter) => Point.fmt(point, f)), "|", rt.fmt.spec({ alternate: true, width: 4 }, (f: rt.Formatter) => Point.fmt(point, f)), "|", rt.fmt.spec({ align: ">", width: 3 }, (f: rt.Formatter) => Pair.fmt(arg4, f))])); + put(arg5, rt.fmt.format([rt.fmt.spec({ width: 5 }, (f: rt.Formatter) => Point.fmt$Debug(point, f)), "|", rt.fmt.spec({ align: "<", width: 4 }, (f: rt.Formatter) => Point.fmt$Debug(point, f)), "|", rt.fmt.spec({ alternate: true, width: 4 }, (f: rt.Formatter) => Point.fmt$Debug(point, f)), "|", rt.fmt.spec({ align: ">", width: 3 }, (f: rt.Formatter) => Pair.fmt$Debug(arg4, f))])); const kinds = [{ tag: "Empty" } as Kind.Kind, { tag: "One", _0: at(4) } as Kind.Kind, { tag: "Braced" } as Kind.Kind, { tag: "Bare" } as Kind.Kind, { tag: "Many", count: 0, items: new rt.ByteVec() } as Kind.Kind]; const arg7 = out; const arg6 = kinds[1]; - put(arg7, rt.fmt.format([(f: rt.Formatter) => rt.fmt.list(kinds, f, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt(value, f)), " ", (f: rt.Formatter) => Kind.fmt(arg6, f)])); - put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => rt.fmt.list(kinds, f, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt(value, f)))])); + put(arg7, rt.fmt.format([(f: rt.Formatter) => rt.fmt.list(kinds, f, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt$Debug(value, f)), " ", (f: rt.Formatter) => Kind.fmt$Debug(arg6, f)])); + put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => rt.fmt.list(kinds, f, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt$Debug(value, f)))])); const bytes = data; const words = [at(5) as rt.u16, 0xffff]; const arg10 = out; @@ -223,8 +223,8 @@ export function derived(data: Uint8Array, out: rt.ByteVec): void { const arg12 = {}; const arg13 = {}; const arg14 = {}; - put(arg15, rt.fmt.format([(f: rt.Formatter) => Braced.fmt(arg11, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Braced.fmt(arg12, f)), " ", (f: rt.Formatter) => Bare.fmt(arg13, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Bare.fmt(arg14, f))])); - out.extendFromSlice(Uint8Array.of(Braced.eq({}, {}) ? 1 : 0, Bare.eq({}, {}) ? 1 : 0)); + put(arg15, rt.fmt.format([(f: rt.Formatter) => Braced.fmt$Debug(arg11, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Braced.fmt$Debug(arg12, f)), " ", (f: rt.Formatter) => Bare.fmt$Debug(arg13, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Bare.fmt$Debug(arg14, f))])); + out.extendFromSlice(Uint8Array.of(Braced.eq$PartialEq({}, {}) ? 1 : 0, Bare.eq$PartialEq({}, {}) ? 1 : 0)); } /** Written `Display` and `Debug`, and a `Display` that fails inside `format!`. */ @@ -236,17 +236,17 @@ export function written(data: Uint8Array, out: rt.ByteVec): void { put(out, rt.fmt.format([(f: rt.Formatter) => Hex.fmt$Display(hex, f), "|", rt.fmt.spec({ align: ">", width: 12 }, (f: rt.Formatter) => Hex.fmt$Display(hex, f)), "|", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Hex.fmt$Display(hex, f)), "|", (f: rt.Formatter) => Hex.fmt$Debug(hex, f), "|", rt.fmt.spec({ align: ">", width: 6 }, (f: rt.Formatter) => Hex.fmt$Debug(hex, f)), "|", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Hex.fmt$Debug(hex, f))])); put(out, rt.fmt.toString((f: rt.Formatter) => Hex.fmt$Display(hex, f))); const padded = { _0: "pad" }; - put(out, rt.fmt.format([(f: rt.Formatter) => Padded.fmt(padded, f), "|", rt.fmt.spec({ align: ">", width: 6 }, (f: rt.Formatter) => Padded.fmt(padded, f)), "|", rt.fmt.spec({ fill: "_", align: "^", width: 9 }, (f: rt.Formatter) => Padded.fmt(padded, f)), "|", rt.fmt.spec({ width: 30 }, (f: rt.Formatter) => Padded.fmt(padded, f)), "|"])); + put(out, rt.fmt.format([(f: rt.Formatter) => Padded.fmt$Display(padded, f), "|", rt.fmt.spec({ align: ">", width: 6 }, (f: rt.Formatter) => Padded.fmt$Display(padded, f)), "|", rt.fmt.spec({ fill: "_", align: "^", width: 9 }, (f: rt.Formatter) => Padded.fmt$Display(padded, f)), "|", rt.fmt.spec({ width: 30 }, (f: rt.Formatter) => Padded.fmt$Display(padded, f)), "|"])); const manual = { id: at(1), list: rt.slice.toVec([1, at(2) as rt.u16]) }; const empty = { id: 0, list: [] }; - put(out, rt.fmt.format([(f: rt.Formatter) => Manual.fmt(manual, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Manual.fmt(manual, f)), " ", (f: rt.Formatter) => Manual.fmt(empty, f)])); + put(out, rt.fmt.format([(f: rt.Formatter) => Manual.fmt$Debug(manual, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Manual.fmt$Debug(manual, f)), " ", (f: rt.Formatter) => Manual.fmt$Debug(empty, f)])); const seq = { _0: rt.slice.toVec([{ _0: at(3), _1: 0 }, { _0: 1, _1: -1 }]) }; const none = { _0: [] }; - put(out, rt.fmt.format([(f: rt.Formatter) => Seq.fmt(seq, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Seq.fmt(seq, f)), " ", (f: rt.Formatter) => Seq.fmt(none, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Seq.fmt(none, f))])); + put(out, rt.fmt.format([(f: rt.Formatter) => Seq.fmt$Debug(seq, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Seq.fmt$Debug(seq, f)), " ", (f: rt.Formatter) => Seq.fmt$Debug(none, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Seq.fmt$Debug(none, f))])); const tup = { _0: at(4), _1: rt.u8.rem(at(5), 2) === 0 ? at(5) : undefined }; - put(out, rt.fmt.format([(f: rt.Formatter) => Tup.fmt(tup, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Tup.fmt(tup, f))])); + put(out, rt.fmt.format([(f: rt.Formatter) => Tup.fmt$Debug(tup, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Tup.fmt$Debug(tup, f))])); const fine = { _0: at(6) & (~1 & 0xff) }; - put(out, rt.fmt.format([(f: rt.Formatter) => Fails.fmt(fine, f), " ", rt.fmt.spec({ align: ">", width: 9 }, (f: rt.Formatter) => Fails.fmt(fine, f))])); + put(out, rt.fmt.format([(f: rt.Formatter) => Fails.fmt$Display(fine, f), " ", rt.fmt.spec({ align: ">", width: 9 }, (f: rt.Formatter) => Fails.fmt$Display(fine, f))])); const arg3 = out; const arg = at(7); const arg2 = at(8); @@ -265,7 +265,7 @@ export function panics(kind: rt.u8, rest: Uint8Array, out: rt.ByteVec): void { } else if (value === 2) { if (!(n > 200)) { const arg2 = { _0: n, _1: 0 }; - rt.panic(["small ", (f: rt.Formatter) => rt.u8.display(n, f), " ", (f: rt.Formatter) => Pair.fmt(arg2, f)]); + rt.panic(["small ", (f: rt.Formatter) => rt.u8.display(n, f), " ", (f: rt.Formatter) => Pair.fmt$Debug(arg2, f)]); } } else if (value === 3) { if (!(n > 200)) { @@ -283,9 +283,9 @@ export function panics(kind: rt.u8, rest: Uint8Array, out: rt.ByteVec): void { const value3 = [{ _0: n, _1: 1 }, { _0: n, _1: 1 }] as [Pair.Pair, Pair.Pair]; const leftVal2 = value3[0]; const rightVal2 = value3[1]; - if (Pair.eq(leftVal2, rightVal2)) { + if (Pair.eq$PartialEq(leftVal2, rightVal2)) { const kind3 = "!="; - rt.assertFailed(kind3, (f: rt.Formatter) => Pair.fmt(leftVal2, f), (f: rt.Formatter) => Pair.fmt(rightVal2, f), ["same ", (f: rt.Formatter) => rt.u8.display(n, f)]); + rt.assertFailed(kind3, (f: rt.Formatter) => Pair.fmt$Debug(leftVal2, f), (f: rt.Formatter) => Pair.fmt$Debug(rightVal2, f), ["same ", (f: rt.Formatter) => rt.u8.display(n, f)]); } } else if (value === 6) { const value4 = [n, 9] as [rt.u8, rt.u8]; @@ -298,17 +298,17 @@ export function panics(kind: rt.u8, rest: Uint8Array, out: rt.ByteVec): void { } else if (value === 7) { const r = rt.u8.rem(n, 2) === 0 ? rt.Err({ tag: "One", _0: n } as Kind.Kind) : rt.Err({ tag: "Many", count: 1, items: rt.slice.toByteVec(Uint8Array.of(n)) } as Kind.Kind); const arg4 = out; - const arg3 = rt.result.unwrap(r, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt(value, f)); + const arg3 = rt.result.unwrap(r, (value: Kind.Kind, f: rt.Formatter) => Kind.fmt$Debug(value, f)); put(arg4, rt.fmt.toString((f: rt.Formatter) => rt.u8.display(arg3, f))); } else if (value === 8) { const r2 = n > 128 ? rt.Ok(n) : rt.Err({ _0: n, _1: -2 }); const arg6 = out; - const arg5 = rt.result.expect(rt.copy(r2), "expected a byte", (value: Pair.Pair, f: rt.Formatter) => Pair.fmt(value, f)); + const arg5 = rt.result.expect(rt.copy(r2), "expected a byte", (value: Pair.Pair, f: rt.Formatter) => Pair.fmt$Debug(value, f)); put(arg6, rt.fmt.toString((f: rt.Formatter) => rt.u8.display(arg5, f))); } else if (value === 9) { const r3 = rt.Ok({ x: n as rt.i32, y: 0 }); const arg8 = out; - const arg7 = rt.result.unwrapErr(rt.copy(r3), (value: Point.Point, f: rt.Formatter) => Point.fmt(value, f)); + const arg7 = rt.result.unwrapErr(rt.copy(r3), (value: Point.Point, f: rt.Formatter) => Point.fmt$Debug(value, f)); put(arg8, rt.fmt.toString((f: rt.Formatter) => rt.u8.display(arg7, f))); } else if (value === 10) { const missing = rt.slice.get(rest, 200); @@ -318,15 +318,15 @@ export function panics(kind: rt.u8, rest: Uint8Array, out: rt.ByteVec): void { } else if (value === 11) { const arg12 = out; const arg11 = { _0: n }; - put(arg12, rt.fmt.format([(f: rt.Formatter) => Fails.fmt(arg11, f)])); + put(arg12, rt.fmt.format([(f: rt.Formatter) => Fails.fmt$Display(arg11, f)])); } else if (value === 12) { const arg14 = out; const arg13 = { _0: n }; - put(arg14, rt.fmt.toString((f: rt.Formatter) => Fails.fmt(arg13, f))); + put(arg14, rt.fmt.toString((f: rt.Formatter) => Fails.fmt$Display(arg13, f))); } else if (value === 13) { const arg15 = { _0: n as rt.u32 }; const arg16 = { _0: n }; - rt.panic([(f: rt.Formatter) => Hex.fmt$Display(arg15, f), " then ", (f: rt.Formatter) => Fails.fmt(arg16, f)]); + rt.panic([(f: rt.Formatter) => Hex.fmt$Display(arg15, f), " then ", (f: rt.Formatter) => Fails.fmt$Display(arg16, f)]); } else if (value === 14) { const [start, end] = [rt.u8.rem(n, 8) as rt.usize, rt.u8.div(n, 32) as rt.usize] as [rt.usize, rt.usize]; const arg19 = out; diff --git a/ts/fixtures/lang/expected/generics.Either.ts b/ts/fixtures/lang/expected/generics.Either.ts index 4aeadbfd7..c2664bf09 100644 --- a/ts/fixtures/lang/expected/generics.Either.ts +++ b/ts/fixtures/lang/expected/generics.Either.ts @@ -3,10 +3,10 @@ import * as rt from "./rt.ts"; import * as Point from "./shapes.Point.ts"; -export function fmt$Point_u8(self: Either, f: rt.Formatter): rt.Result { +export function fmt$Debug_Point_u8(self: Either, f: rt.Formatter): rt.Result { if (self.tag === "Left") { const __self0 = self._0; - return f.debugTuple("Left").field((f: rt.Formatter) => Point.fmt(__self0, f)).finish(); + return f.debugTuple("Left").field((f: rt.Formatter) => Point.fmt$Debug(__self0, f)).finish(); } else if (self.tag === "Right") { const __self02 = self.value; return f.debugStruct("Right").field("value", (f: rt.Formatter) => rt.u8.display(__self02, f)).finish(); @@ -15,19 +15,19 @@ export function fmt$Point_u8(self: Either, f: rt.Formatter): } } -export function fmt$u8_Point(self: Either, f: rt.Formatter): rt.Result { +export function fmt$Debug_u8_Point(self: Either, f: rt.Formatter): rt.Result { if (self.tag === "Left") { const __self0 = self._0; return f.debugTuple("Left").field((f: rt.Formatter) => rt.u8.display(__self0, f)).finish(); } else if (self.tag === "Right") { const __self02 = self.value; - return f.debugStruct("Right").field("value", (f: rt.Formatter) => Point.fmt(__self02, f)).finish(); + return f.debugStruct("Right").field("value", (f: rt.Formatter) => Point.fmt$Debug(__self02, f)).finish(); } else { return f.writeStr("Neither"); } } -export function fmt$u8_u16(self: Either, f: rt.Formatter): rt.Result { +export function fmt$Debug_u8_u16(self: Either, f: rt.Formatter): rt.Result { if (self.tag === "Left") { const __self0 = self._0; return f.debugTuple("Left").field((f: rt.Formatter) => rt.u8.display(__self0, f)).finish(); @@ -69,7 +69,7 @@ export function left$u8_u16(self: Either): rt.u8 | undefined { } } -export function flip(self: Either): Either { +export function flip$u8_Point(self: Either): Either { if (self.tag === "Left") { const l = self._0; return { tag: "Right", value: l }; diff --git a/ts/fixtures/lang/expected/generics.Tagged.ts b/ts/fixtures/lang/expected/generics.Tagged.ts index 15ba36316..d491605eb 100644 --- a/ts/fixtures/lang/expected/generics.Tagged.ts +++ b/ts/fixtures/lang/expected/generics.Tagged.ts @@ -4,8 +4,8 @@ import * as rt from "./rt.ts"; import * as Either from "./generics.Either.ts"; import * as Wrap from "./generics.Wrap.ts"; -export function fmt(self: Tagged, rt.i16>, f: rt.Formatter): rt.Result { - return f.debugStruct("Tagged").field("key", (f: rt.Formatter) => Either.fmt$u8_u16(self.key, f)).field("inner", (f: rt.Formatter) => Wrap.fmt$i16(self.inner, f)).field("all", (f: rt.Formatter) => rt.fmt.list(self.all, f, (value: Wrap.Wrap, f: rt.Formatter) => Wrap.fmt$i16(value, f))).finish(); +export function fmt$Debug_Either_u8_u16_i16(self: Tagged, rt.i16>, f: rt.Formatter): rt.Result { + return f.debugStruct("Tagged").field("key", (f: rt.Formatter) => Either.fmt$Debug_u8_u16(self.key, f)).field("inner", (f: rt.Formatter) => Wrap.fmt$Debug_i16(self.inner, f)).field("all", (f: rt.Formatter) => rt.fmt.list(self.all, f, (value: Wrap.Wrap, f: rt.Formatter) => Wrap.fmt$Debug_i16(value, f))).finish(); } /** Two parameters, one nested in another generic type. */ @@ -21,7 +21,7 @@ export class Tagged { } } -export function first(self: Tagged, rt.i16>): Wrap.Wrap | undefined { +export function first$Either_u8_u16_i16(self: Tagged, rt.i16>): Wrap.Wrap | undefined { return rt.copy(rt.slice.first(self.all)); } diff --git a/ts/fixtures/lang/expected/generics.Wrap.ts b/ts/fixtures/lang/expected/generics.Wrap.ts index 588f9b775..8fa511e74 100644 --- a/ts/fixtures/lang/expected/generics.Wrap.ts +++ b/ts/fixtures/lang/expected/generics.Wrap.ts @@ -6,44 +6,44 @@ import * as Meters from "./shapes.Meters.ts"; import * as Point from "./shapes.Point.ts"; import * as Shape from "./shapes.Shape.ts"; -export function fmt$Option_u8(self: Wrap, f: rt.Formatter): rt.Result { +export function fmt$Debug_Option_u8(self: Wrap, f: rt.Formatter): rt.Result { return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.fmt.option(self.value, f, rt.u8.display)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Pair(self: Wrap, f: rt.Formatter): rt.Result { - return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Pair.fmt(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); +export function fmt$Debug_Pair(self: Wrap, f: rt.Formatter): rt.Result { + return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Pair.fmt$Debug(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Point(self: Wrap, f: rt.Formatter): rt.Result { - return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Point.fmt(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); +export function fmt$Debug_Point(self: Wrap, f: rt.Formatter): rt.Result { + return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Point.fmt$Debug(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Result_u8_Shape(self: Wrap>, f: rt.Formatter): rt.Result { - return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.fmt.result(self.value, f, rt.u8.display, (value: Shape.Shape, f: rt.Formatter) => Shape.fmt(value, f))).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); +export function fmt$Debug_Result_u8_Shape(self: Wrap>, f: rt.Formatter): rt.Result { + return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.fmt.result(self.value, f, rt.u8.display, (value: Shape.Shape, f: rt.Formatter) => Shape.fmt$Debug(value, f))).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Shape(self: Wrap, f: rt.Formatter): rt.Result { - return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Shape.fmt(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); +export function fmt$Debug_Shape(self: Wrap, f: rt.Formatter): rt.Result { + return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => Shape.fmt$Debug(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Vec_u16(self: Wrap, f: rt.Formatter): rt.Result { +export function fmt$Debug_Vec_u16(self: Wrap, f: rt.Formatter): rt.Result { return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.fmt.list(self.value, f, rt.u16.display)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$Wrap_Pair(self: Wrap>, f: rt.Formatter): rt.Result { - return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => fmt$Pair(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); +export function fmt$Debug_Wrap_Pair(self: Wrap>, f: rt.Formatter): rt.Result { + return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => fmt$Debug_Pair(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$i16(self: Wrap, f: rt.Formatter): rt.Result { +export function fmt$Debug_i16(self: Wrap, f: rt.Formatter): rt.Result { return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.i16.display(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function fmt$u8(self: Wrap, f: rt.Formatter): rt.Result { +export function fmt$Debug_u8(self: Wrap, f: rt.Formatter): rt.Result { return f.debugStruct("Wrap").field("value", (f: rt.Formatter) => rt.u8.display(self.value, f)).field("count", (f: rt.Formatter) => rt.u8.display(self.count, f)).finish(); } -export function eq(self: Wrap, other: Wrap): boolean { - return self.count === other.count && Pair.eq(self.value, other.value); +export function eq$PartialEq_Pair(self: Wrap, other: Wrap): boolean { + return self.count === other.count && Pair.eq$PartialEq(self.value, other.value); } /** A generic struct, with methods on every instance, on some, and on one. */ @@ -116,45 +116,45 @@ export function bump$u8(self: Wrap): rt.u8 { return self.count; } -export function intoInner(self: Wrap): Point.Point { +export function intoInner$Point(self: Wrap): Point.Point { return rt.copy(self.value); } /** A method with its own type parameter. */ -export function map(self: Wrap, f: (a0: rt.u8) => Pair.Pair): Wrap { +export function map$u8_Pair_methods_closure1(self: Wrap, f: (a0: rt.u8) => Pair.Pair): Wrap { return new Wrap({ value: f(self.value), count: self.count }); } export function scaled$Meters(self: Wrap): rt.u64 { - return rt.u64.saturatingAdd(Meters.area(self.value), self.count as rt.u64); + return rt.u64.saturatingAdd(Meters.area$Area(self.value), self.count as rt.u64); } export function scaled$Shape(self: Wrap): rt.u64 { - return rt.u64.saturatingAdd(Shape.area(self.value), self.count as rt.u64); + return rt.u64.saturatingAdd(Shape.area$Area(self.value), self.count as rt.u64); } -export function double(self: Wrap): rt.u16 { +export function double$u8(self: Wrap): rt.u16 { return rt.u16.mul(self.value as rt.u16, 2); } -export function area$Meters(self: Wrap): rt.u64 { - return Meters.area(self.value); +export function area$Area_Meters(self: Wrap): rt.u64 { + return Meters.area$Area(self.value); } -export function area$Shape(self: Wrap): rt.u64 { - return Shape.area(self.value); +export function area$Area_Shape(self: Wrap): rt.u64 { + return Shape.area$Area(self.value); } /** A default method, monomorphized for each type. */ -export function describe$Meters(self: Wrap, out: rt.ByteVec): void { +export function describe$Area_Meters(self: Wrap, out: rt.ByteVec): void { out.push(0); - out.extendFromSlice(rt.u64.toBeBytes(area$Meters(self))); + out.extendFromSlice(rt.u64.toBeBytes(area$Area_Meters(self))); } /** A default method, monomorphized for each type. */ -export function describe$Shape(self: Wrap, out: rt.ByteVec): void { +export function describe$Area_Shape(self: Wrap, out: rt.ByteVec): void { out.push(4); - out.extendFromSlice(rt.u64.toBeBytes(area$Shape(self))); + out.extendFromSlice(rt.u64.toBeBytes(area$Area_Shape(self))); } //# sourceMappingURL=generics.Wrap.ts.map diff --git a/ts/fixtures/lang/expected/generics.ts b/ts/fixtures/lang/expected/generics.ts index c98e8a4ee..6ce3cf633 100644 --- a/ts/fixtures/lang/expected/generics.ts +++ b/ts/fixtures/lang/expected/generics.ts @@ -21,29 +21,29 @@ export function methods(data: Uint8Array, out: rt.ByteVec): void { Wrap.bump$u8(byte); const nested = Wrap.new$Wrap_Pair(Wrap.new$Pair({ _0: at(2), _1: -3 })); const meters = new Wrap.Wrap({ value: { _0: at(3) as rt.u64 }, count: at(4) }); - const shape = Wrap.new$Shape({ tag: "Rect", corner: Wrap.intoInner(rt.copy(point)), width: at(5) as rt.u16, height: 3 }); - put(out, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Point(point, f), " ", (f: rt.Formatter) => Wrap.fmt$u8(byte, f), " ", (f: rt.Formatter) => Wrap.fmt$Wrap_Pair(nested, f), " ", (f: rt.Formatter) => Wrap.fmt$Shape(shape, f)])); - put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Wrap.fmt$Wrap_Pair(nested, f))])); - out.extendFromSlice(rt.u16.toBeBytes(Wrap.double(byte))); + const shape = Wrap.new$Shape({ tag: "Rect", corner: Wrap.intoInner$Point(rt.copy(point)), width: at(5) as rt.u16, height: 3 }); + put(out, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Debug_Point(point, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_u8(byte, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_Wrap_Pair(nested, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_Shape(shape, f)])); + put(out, rt.fmt.format([rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Wrap.fmt$Debug_Wrap_Pair(nested, f))])); + out.extendFromSlice(rt.u16.toBeBytes(Wrap.double$u8(byte))); out.push(Wrap.get$u8(byte)); out.push(Wrap.get$Pair(Wrap.get$Wrap_Pair(nested))._0); out.extendFromSlice(rt.u64.toBeBytes(Wrap.scaled$Meters(meters))); out.extendFromSlice(rt.u64.toBeBytes(Wrap.scaled$Shape(shape))); - Wrap.describe$Meters(meters, out); - Wrap.describe$Shape(shape, out); - const mapped = Wrap.map(rt.copy(byte), (b: rt.u8): Pair.Pair => { + Wrap.describe$Area_Meters(meters, out); + Wrap.describe$Area_Shape(shape, out); + const mapped = Wrap.map$u8_Pair_methods_closure1(rt.copy(byte), (b: rt.u8): Pair.Pair => { return { _0: b, _1: at(6) as rt.i64 }; }); const arg2 = out; - const arg = Wrap.eq(mapped, Wrap.new$Pair({ _0: at(1), _1: 0 })); - put(arg2, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Pair(mapped, f), " ", (f: rt.Formatter) => rt.fmt.bool(arg, f)])); + const arg = Wrap.eq$PartialEq_Pair(mapped, Wrap.new$Pair({ _0: at(1), _1: 0 })); + put(arg2, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Debug_Pair(mapped, f), " ", (f: rt.Formatter) => rt.fmt.bool(arg, f)])); const eithers = [{ tag: "Left", _0: at(7) } as Either.Either, { tag: "Right", value: Point.new(1, -1) } as Either.Either, { tag: "Neither" } as Either.Either]; for (const either of rt.copy(eithers)) { - const flipped = Either.flip(either); + const flipped = Either.flip$u8_Point(either); const arg5 = out; const arg3 = Either.left$u8_Point(either); const arg4 = Either.left$Point_u8(flipped); - put(arg5, rt.fmt.format([(f: rt.Formatter) => Either.fmt$u8_Point(either, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Either.fmt$Point_u8(flipped, f)), " ", (f: rt.Formatter) => rt.fmt.option(arg3, f, rt.u8.display), " ", (f: rt.Formatter) => rt.fmt.option(arg4, f, (value: Point.Point, f: rt.Formatter) => Point.fmt(value, f))])); + put(arg5, rt.fmt.format([(f: rt.Formatter) => Either.fmt$Debug_u8_Point(either, f), " ", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Either.fmt$Debug_Point_u8(flipped, f)), " ", (f: rt.Formatter) => rt.fmt.option(arg3, f, rt.u8.display), " ", (f: rt.Formatter) => rt.fmt.option(arg4, f, (value: Point.Point, f: rt.Formatter) => Point.fmt$Debug(value, f))])); } let list: Wrap.Wrap = new Wrap.Wrap({ value: [], count: 1 }); list.value.push(at(10) as rt.u16); @@ -53,11 +53,11 @@ export function methods(data: Uint8Array, out: rt.ByteVec): void { const err = new Wrap.Wrap({ value: rt.Err({ tag: "Dot" } as Shape.Shape), count: 2 }); const arg7 = out; const arg6 = rt.option.unwrapOr(Wrap.get$Option_u8(none), some.count); - put(arg7, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Vec_u16(list, f), " ", (f: rt.Formatter) => Wrap.fmt$Option_u8(none, f), " ", (f: rt.Formatter) => Wrap.fmt$Option_u8(some, f), " ", (f: rt.Formatter) => Wrap.fmt$Result_u8_Shape(err, f), " ", (f: rt.Formatter) => rt.u8.display(arg6, f)])); + put(arg7, rt.fmt.format([(f: rt.Formatter) => Wrap.fmt$Debug_Vec_u16(list, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_Option_u8(none, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_Option_u8(some, f), " ", (f: rt.Formatter) => Wrap.fmt$Debug_Result_u8_Shape(err, f), " ", (f: rt.Formatter) => rt.u8.display(arg6, f)])); const tagged = new Tagged.Tagged({ key: { tag: "Right", value: 500 } as Either.Either, inner: Wrap.new$i16(rt.i16.sub(at(8) as rt.i16, 100)), all: rt.slice.toVec([Wrap.new$i16(-1), Wrap.new$i16(at(9) as rt.i16)]) }); const arg9 = out; - const arg8 = Tagged.first(tagged); - put(arg9, rt.fmt.format([(f: rt.Formatter) => Tagged.fmt(tagged, f), " ", (f: rt.Formatter) => rt.fmt.option(arg8, f, (value: Wrap.Wrap, f: rt.Formatter) => Wrap.fmt$i16(value, f))])); + const arg8 = Tagged.first$Either_u8_u16_i16(tagged); + put(arg9, rt.fmt.format([(f: rt.Formatter) => Tagged.fmt$Debug_Either_u8_u16_i16(tagged, f), " ", (f: rt.Formatter) => rt.fmt.option(arg8, f, (value: Wrap.Wrap, f: rt.Formatter) => Wrap.fmt$Debug_i16(value, f))])); out.extendFromSlice(rt.i16.toBeBytes(tagged.inner.value)); out.push(rt.option.unwrapOr(Either.left$u8_u16(tagged.key), 0)); } diff --git a/ts/fixtures/lang/expected/iters.Bumped.ts b/ts/fixtures/lang/expected/iters.Bumped.ts index d181a2289..5641e6870 100644 --- a/ts/fixtures/lang/expected/iters.Bumped.ts +++ b/ts/fixtures/lang/expected/iters.Bumped.ts @@ -7,7 +7,7 @@ export interface Bumped { _0: rt.u8; } -export function clone(self: Bumped): Bumped { +export function clone$Clone(self: Bumped): Bumped { return { _0: rt.u8.wrappingAdd(self._0, 1) }; } diff --git a/ts/fixtures/lang/expected/iters.Countdown.ts b/ts/fixtures/lang/expected/iters.Countdown.ts index b4fe898a9..cfe1911f8 100644 --- a/ts/fixtures/lang/expected/iters.Countdown.ts +++ b/ts/fixtures/lang/expected/iters.Countdown.ts @@ -8,7 +8,7 @@ export interface Countdown { step: rt.u8; } -export function next(self: Countdown): rt.u8 | rt.Done { +export function next$Iterator(self: Countdown): rt.u8 | rt.Done { if (self.left === 0) { return rt.DONE; } else { diff --git a/ts/fixtures/lang/expected/iters.Doubled.ts b/ts/fixtures/lang/expected/iters.Doubled.ts index 4b4c115f0..5d74d5c44 100644 --- a/ts/fixtures/lang/expected/iters.Doubled.ts +++ b/ts/fixtures/lang/expected/iters.Doubled.ts @@ -7,7 +7,7 @@ export interface Doubled { _0: Uint8Array; } -export function fmt(self: Doubled, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Doubled, f: rt.Formatter): rt.Result { return f.debugList().entries(rt.iter.slice(self._0).map((arg: rt.u8): rt.u16 => { const b = arg; return rt.u16.mul(b as rt.u16, 2); diff --git a/ts/fixtures/lang/expected/iters.Evens.ts b/ts/fixtures/lang/expected/iters.Evens.ts index 8eddffbb4..de20cd58b 100644 --- a/ts/fixtures/lang/expected/iters.Evens.ts +++ b/ts/fixtures/lang/expected/iters.Evens.ts @@ -7,13 +7,13 @@ export interface Evens { inner: rt.Iter; } -export function next(self: Evens): rt.u8 | rt.Done { +export function next$Iterator(self: Evens): rt.u8 | rt.Done { while (true) { - const next_ = self.inner.next(); - if (next_ === rt.DONE) { + const next = self.inner.next(); + if (next === rt.DONE) { return rt.DONE; } - const b = next_; + const b = next; if (rt.u8.rem(b, 2) === 0) { return b; } diff --git a/ts/fixtures/lang/expected/iters.Gaps.ts b/ts/fixtures/lang/expected/iters.Gaps.ts index 12245771e..e6bb38eef 100644 --- a/ts/fixtures/lang/expected/iters.Gaps.ts +++ b/ts/fixtures/lang/expected/iters.Gaps.ts @@ -8,7 +8,7 @@ export interface Gaps { at: rt.usize; } -export function next(self: Gaps): rt.u8 | undefined | rt.Done { +export function next$Iterator(self: Gaps): rt.u8 | undefined | rt.Done { const get = rt.slice.get(self.data, self.at); if (get === undefined) { return rt.DONE; diff --git a/ts/fixtures/lang/expected/iters.Halving.ts b/ts/fixtures/lang/expected/iters.Halving.ts index d7a23e3bf..426a34b91 100644 --- a/ts/fixtures/lang/expected/iters.Halving.ts +++ b/ts/fixtures/lang/expected/iters.Halving.ts @@ -11,13 +11,13 @@ export class Halving { } } -export function next$Iterator(self: Halving): rt.u8 | rt.Done { +export function next$Iterator_u8(self: Halving): rt.u8 | rt.Done { const value = self.value; self.value = rt.u8.div(self.value, 2); return rt.iter.fromOption(rt.thenSome(value !== 0, value)); } -export function next$Iterator$2(self: Halving): rt.u64 | rt.Done { +export function next$Iterator_u64(self: Halving): rt.u64 | rt.Done { if (self.value === 0) { return rt.DONE; } else { diff --git a/ts/fixtures/lang/expected/iters.Tag.ts b/ts/fixtures/lang/expected/iters.Tag.ts index 0a1f11336..39c6ddd19 100644 --- a/ts/fixtures/lang/expected/iters.Tag.ts +++ b/ts/fixtures/lang/expected/iters.Tag.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function clone(self: Tag): Tag { +export function clone$Clone(self: Tag): Tag { return { bytes: rt.ByteVec.from(self.bytes.view()) }; } diff --git a/ts/fixtures/lang/expected/iters.Wrapper.ts b/ts/fixtures/lang/expected/iters.Wrapper.ts index 27e6e3067..407930d68 100644 --- a/ts/fixtures/lang/expected/iters.Wrapper.ts +++ b/ts/fixtures/lang/expected/iters.Wrapper.ts @@ -2,8 +2,8 @@ import * as Bumped from "./iters.Bumped.ts"; -export function clone(self: Wrapper): Wrapper { - return new Wrapper(Bumped.clone(self._0)); +export function clone$Clone_Bumped(self: Wrapper): Wrapper { + return new Wrapper(Bumped.clone$Clone(self._0)); } export class Wrapper { diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index a5ef90775..f20e66720 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -78,7 +78,7 @@ export function adaptors(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void { out.push(skipped.length & 0xff); out.extendFromSlice(mapped.view()); } else if (value === 4) { - const words = chunksByZero(data); + const words = chunksByZero$ChunksByZero_u8s(data); const flat = rt.iter.slice(words).flatMap((w: rt.ByteVec): rt.Iter => { return rt.iter.slice(w.view()).rev(); }).toByteVec(); @@ -160,7 +160,7 @@ export function adaptors(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void { } /** The runs between zero bytes. */ -export function chunksByZero(self: Uint8Array): rt.ByteVec[] { +export function chunksByZero$ChunksByZero_u8s(self: Uint8Array): rt.ByteVec[] { let words: rt.ByteVec[] = []; let word: rt.ByteVec = new rt.ByteVec(); for (const item of self) { @@ -266,7 +266,7 @@ export function consumers(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void } let back: rt.Iter<[rt.u8, rt.u8]> = rt.iter.slice(data).map((arg12: rt.u8): rt.u8 => { const b15 = arg12; - return rotateFree(b15); + return rotateFree$RotateFree_u8(b15); }).zip(rt.iter.slice(short), true); const nextBack = rt.iter.toOption(back.nextBack()); if (nextBack !== undefined) { @@ -307,7 +307,7 @@ export function consumers(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void out.extendFromSlice(rt.u32.toBeBytes(folded)); rt.iter.slice(data).forEach((arg17: rt.u8): void => { const b21 = arg17; - log.push(rotateFree(b21)); + log.push(rotateFree$RotateFree_u8(b21)); }); } else if (value === 4) { const total = rt.iter.slice(data).sum(rt.u8.add, 0); @@ -347,7 +347,7 @@ export function consumers(kind: rt.u8, data: Uint8Array, out: rt.ByteVec): void out.extendFromSlice(log.view()); } -export function rotateFree(self: rt.u8): rt.u8 { +export function rotateFree$RotateFree_u8(self: rt.u8): rt.u8 { return ((self << 1) & 0xff) | (self >> 7); } @@ -477,7 +477,7 @@ export function options(data: Uint8Array, out: rt.ByteVec): void { return o !== undefined; }).count(); out.push(somes & 0xff); - out.push(rt.option.unwrapOr(second(rt.iter.slice(data).map(maybe)), 0xcd)); + out.push(rt.option.unwrapOr(second$Map_Iter_u8_options_closure0(rt.iter.slice(data).map(maybe)), 0xcd)); const first = rt.slice.first(data); const iter2 = rt.iter.option(first).chain(rt.iter.once(0x99)); while (true) { @@ -496,7 +496,7 @@ export function options(data: Uint8Array, out: rt.ByteVec): void { out.extendFromSlice(counted.view()); const gaps = { data, at: 0 }; while (true) { - const gap = Gaps.next(gaps); + const gap = Gaps.next$Iterator(gaps); if (gap === rt.DONE) { break; } @@ -507,7 +507,7 @@ export function options(data: Uint8Array, out: rt.ByteVec): void { } /** The second item of an iterator of options, through `?`, which tests for its end. */ -export function second(items: rt.Iter): rt.u8 | undefined { +export function second$Map_Iter_u8_options_closure0(items: rt.Iter): rt.u8 | undefined { const next = items.next(); if (next === rt.DONE) { return undefined; @@ -526,19 +526,19 @@ export function own(data: Uint8Array, out: rt.ByteVec): void { const step = rt.max(rt.option.unwrapOr(rt.slice.get(data, 1), 1), 1); const iter = { left, step }; while (true) { - const n = Countdown.next(iter); + const n = Countdown.next$Iterator(iter); if (n === rt.DONE) { break; } out.push(n); } - const total = rt.iter.from({ left, step }, (it: Countdown.Countdown) => Countdown.next(it)).map((n2: rt.u8): rt.u64 => { + const total = rt.iter.from({ left, step }, (it: Countdown.Countdown) => Countdown.next$Iterator(it)).map((n2: rt.u8): rt.u64 => { return rt.u64.div(rt.u64.mul(n2 as rt.u64, 1000), 7); }).sum(rt.u64.add, 0); out.extendFromSlice(rt.u64.toBeBytes(total)); let down: Countdown.Countdown = { left, step }; while (true) { - const next = rt.iter.toOption(Countdown.next(down)); + const next = rt.iter.toOption(Countdown.next$Iterator(down)); if (next !== undefined) { const n3 = next; if (rt.u8.rem(n3, 5) === 0) { @@ -549,15 +549,15 @@ export function own(data: Uint8Array, out: rt.ByteVec): void { } } out.push(down.left); - const evens = rt.iter.from({ inner: rt.iter.slice(data) }, (it: Evens.Evens) => Evens.next(it)).toByteVec(); + const evens = rt.iter.from({ inner: rt.iter.slice(data) }, (it: Evens.Evens) => Evens.next$Iterator(it)).toByteVec(); out.extendFromSlice(evens.view()); let byRef: Evens.Evens = { inner: rt.iter.slice(rt.slice.range(data, rt.min(data.length, 1))) }; - const firsts = rt.iter.from(byRef, (it: Evens.Evens) => Evens.next(it)).take(2).toByteVec(); + const firsts = rt.iter.from(byRef, (it: Evens.Evens) => Evens.next$Iterator(it)).take(2).toByteVec(); out.extendFromSlice(firsts.view()); - out.push(rt.iter.from(byRef, (it: Evens.Evens) => Evens.next(it)).count() & 0xff); - const halves = rt.iter.from(new Halving.Halving({ value: left }), (it: Halving.Halving) => Halving.next$Iterator(it)).toByteVec(); + out.push(rt.iter.from(byRef, (it: Evens.Evens) => Evens.next$Iterator(it)).count() & 0xff); + const halves = rt.iter.from(new Halving.Halving({ value: left }), (it: Halving.Halving) => Halving.next$Iterator_u8(it)).toByteVec(); out.extendFromSlice(halves.view()); - const total2 = rt.iter.from(new Halving.Halving({ value: rt.u64.mul(left as rt.u64, 0x1_0000_0001) }), (it: Halving.Halving) => Halving.next$Iterator$2(it)).sum(rt.u64.add, 0); + const total2 = rt.iter.from(new Halving.Halving({ value: rt.u64.mul(left as rt.u64, 0x1_0000_0001) }), (it: Halving.Halving) => Halving.next$Iterator_u64(it)).sum(rt.u64.add, 0); out.extendFromSlice(rt.u64.toBeBytes(total2)); } @@ -599,13 +599,13 @@ export function values(data: Uint8Array, out: rt.ByteVec): void { } const arg = { _0: data }; const arg2 = { _0: rt.slice.range(data, 0, rt.min(data.length, 2)) }; - const printed = rt.fmt.format([(f: rt.Formatter) => Doubled.fmt(arg, f), "|", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Doubled.fmt(arg2, f))]); + const printed = rt.fmt.format([(f: rt.Formatter) => Doubled.fmt$Debug(arg, f), "|", rt.fmt.spec({ alternate: true }, (f: rt.Formatter) => Doubled.fmt$Debug(arg2, f))]); out.extendFromSlice(rt.string.asBytes(printed)); const tags = rt.iter.slice(data).map((arg3: rt.u8): Tag.Tag => { const b3 = arg3; return { bytes: rt.slice.toByteVec(Uint8Array.of(b3, ~b3 & 0xff)) }; }).toArray(); - let cloned: Tag.Tag[] = rt.iter.slice(tags).map(Tag.clone).toArray(); + let cloned: Tag.Tag[] = rt.iter.slice(tags).map(Tag.clone$Clone).toArray(); const iter3 = rt.iter.slice(cloned); while (true) { const tag = iter3.next(); @@ -626,7 +626,7 @@ export function values(data: Uint8Array, out: rt.ByteVec): void { const b4 = arg4; return { _0: b4 }; }).toArray(); - rt.iter.extend(out, rt.iter.slice(bumps).map(Bumped.clone).map((b5: Bumped.Bumped): rt.u8 => { + rt.iter.extend(out, rt.iter.slice(bumps).map(Bumped.clone$Clone).map((b5: Bumped.Bumped): rt.u8 => { return b5._0; })); rt.iter.extend(out, rt.iter.slice(bumps).map(rt.copy).map((b6: Bumped.Bumped): rt.u8 => { @@ -636,7 +636,7 @@ export function values(data: Uint8Array, out: rt.ByteVec): void { const b7 = arg5; return new Wrapper.Wrapper({ _0: b7 }); }).toArray(); - rt.iter.extend(out, rt.iter.slice(wrapped).map(Wrapper.clone).map((w: Wrapper.Wrapper): rt.u8 => { + rt.iter.extend(out, rt.iter.slice(wrapped).map(Wrapper.clone$Clone_Bumped).map((w: Wrapper.Wrapper): rt.u8 => { return w._0._0; })); } diff --git a/ts/fixtures/lang/expected/shapes.Meters.ts b/ts/fixtures/lang/expected/shapes.Meters.ts index fcbd9c287..7a0247f77 100644 --- a/ts/fixtures/lang/expected/shapes.Meters.ts +++ b/ts/fixtures/lang/expected/shapes.Meters.ts @@ -7,12 +7,12 @@ export interface Meters { _0: rt.u64; } -export function area(self: Meters): rt.u64 { +export function area$Area(self: Meters): rt.u64 { return self._0; } /** A default method, monomorphized for each type. */ -export function describe(self: Meters, out: rt.ByteVec): void { +export function describe$Area(self: Meters, out: rt.ByteVec): void { out.push(0xaa); out.extendFromSlice(rt.u64.toBeBytes(self._0)); } diff --git a/ts/fixtures/lang/expected/shapes.Moved.ts b/ts/fixtures/lang/expected/shapes.Moved.ts index 37b241c1b..e314d26d2 100644 --- a/ts/fixtures/lang/expected/shapes.Moved.ts +++ b/ts/fixtures/lang/expected/shapes.Moved.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(self: Moved, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Moved, f: rt.Formatter): rt.Result { return f.debugTuple("Moved").field((f: rt.Formatter) => rt.u8.display(self._0, f)).field((f: rt.Formatter) => rt.u16.display(self._1, f)).finish(); } diff --git a/ts/fixtures/lang/expected/shapes.Point.ts b/ts/fixtures/lang/expected/shapes.Point.ts index 30ac72c83..ab537ccf2 100644 --- a/ts/fixtures/lang/expected/shapes.Point.ts +++ b/ts/fixtures/lang/expected/shapes.Point.ts @@ -2,11 +2,11 @@ import * as rt from "./rt.ts"; -export function fmt(self: Point, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Point, f: rt.Formatter): rt.Result { return f.debugStruct("Point").field("x", (f: rt.Formatter) => rt.i32.display(self.x, f)).field("y", (f: rt.Formatter) => rt.i32.display(self.y, f)).finish(); } -export function eq(self: Point, other: Point): boolean { +export function eq$PartialEq(self: Point, other: Point): boolean { return self.x === other.x && self.y === other.y; } diff --git a/ts/fixtures/lang/expected/shapes.Shape.ts b/ts/fixtures/lang/expected/shapes.Shape.ts index 7fad6689f..c2415c339 100644 --- a/ts/fixtures/lang/expected/shapes.Shape.ts +++ b/ts/fixtures/lang/expected/shapes.Shape.ts @@ -3,18 +3,18 @@ import * as rt from "./rt.ts"; import * as Point from "./shapes.Point.ts"; -export function fmt(self: Shape, f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Shape, f: rt.Formatter): rt.Result { if (self.tag === "Dot") { return f.writeStr("Dot"); } else if (self.tag === "Line") { const __self0 = self._0; const __self1 = self._1; - return f.debugTuple("Line").field((f: rt.Formatter) => Point.fmt(__self0, f)).field((f: rt.Formatter) => Point.fmt(__self1, f)).finish(); + return f.debugTuple("Line").field((f: rt.Formatter) => Point.fmt$Debug(__self0, f)).field((f: rt.Formatter) => Point.fmt$Debug(__self1, f)).finish(); } else { const __self02 = self.corner; const __self12 = self.width; const __self2 = self.height; - return f.debugStruct("Rect").field("corner", (f: rt.Formatter) => Point.fmt(__self02, f)).field("width", (f: rt.Formatter) => rt.u16.display(__self12, f)).field("height", (f: rt.Formatter) => rt.u16.display(__self2, f)).finish(); + return f.debugStruct("Rect").field("corner", (f: rt.Formatter) => Point.fmt$Debug(__self02, f)).field("width", (f: rt.Formatter) => rt.u16.display(__self12, f)).field("height", (f: rt.Formatter) => rt.u16.display(__self2, f)).finish(); } } @@ -25,12 +25,12 @@ export type Shape = | { tag: "Rect"; corner: Point.Point; width: rt.u16; height: rt.u16 }; /** A default method, monomorphized for each type. */ -export function describe(self: Shape, out: rt.ByteVec): void { +export function describe$Area(self: Shape, out: rt.ByteVec): void { out.push(4); - out.extendFromSlice(rt.u64.toBeBytes(area(self))); + out.extendFromSlice(rt.u64.toBeBytes(area$Area(self))); } -export function area(self: Shape): rt.u64 { +export function area$Area(self: Shape): rt.u64 { if (self.tag === "Dot") { return 0; } else if (self.tag === "Line") { diff --git a/ts/fixtures/lang/expected/shapes.Void.ts b/ts/fixtures/lang/expected/shapes.Void.ts index 9ea2447b4..ed108a3d6 100644 --- a/ts/fixtures/lang/expected/shapes.Void.ts +++ b/ts/fixtures/lang/expected/shapes.Void.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function fmt(self: Void, _f: rt.Formatter): rt.Result { +export function fmt$Debug(self: Void, _f: rt.Formatter): rt.Result { rt.unreachable(self); } diff --git a/ts/fixtures/lang/expected/shapes.ts b/ts/fixtures/lang/expected/shapes.ts index 3cc26c31c..41a9a3700 100644 --- a/ts/fixtures/lang/expected/shapes.ts +++ b/ts/fixtures/lang/expected/shapes.ts @@ -14,8 +14,8 @@ import type * as Wide from "./shapes.Wide.ts"; export function total$Meters(items: Meters.Meters[], out: rt.ByteVec): rt.u64 { let sum: rt.u64 = 0; for (const item of items) { - Meters.describe(item, out); - sum = rt.u64.saturatingAdd(sum, Meters.area(item)); + Meters.describe$Area(item, out); + sum = rt.u64.saturatingAdd(sum, Meters.area$Area(item)); } return sum; } @@ -23,13 +23,13 @@ export function total$Meters(items: Meters.Meters[], out: rt.ByteVec): rt.u64 { export function total$Shape(items: Shape.Shape[], out: rt.ByteVec): rt.u64 { let sum: rt.u64 = 0; for (const item of items) { - Shape.describe(item, out); - sum = rt.u64.saturatingAdd(sum, Shape.area(item)); + Shape.describe$Area(item, out); + sum = rt.u64.saturatingAdd(sum, Shape.area$Area(item)); } return sum; } -export function from(dir_: Dir.Dir): rt.u8 { +export function from$From_Dir_u8(dir_: Dir.Dir): rt.u8 { return { North: 1, East: 2, South: 4, West: 8 }[dir_]; } @@ -92,7 +92,7 @@ export function copies(data: Uint8Array, out: rt.ByteVec): void { } out.push(saved[1]); out.push(pair[1]); - out.push(Point.eq(p, saved[0]) ? 1 : 0); + out.push(Point.eq$PartialEq(p, saved[0]) ? 1 : 0); let a: Point.Point = Point.new(1, 2); let b: Point.Point = Point.new(3, 4); const swapped = a; @@ -203,7 +203,7 @@ export function order(data: Uint8Array, out: rt.ByteVec): void { const arg3 = logged(data, out); const field10 = rt.min(mark(out, 14), len); const slice = rt.slice.range(arg3, rt.usize.div(rt.min(mark(out, 15), len), 2), field10); - const text = rt.fmt.format([(f: rt.Formatter) => Shape.fmt(rect, f), " ", (f: rt.Formatter) => Shape.fmt(line, f), " ", (f: rt.Formatter) => Pair.fmt(pair, f), " ", (f: rt.Formatter) => Point.fmt(read, f), " ", (f: rt.Formatter) => Moved.fmt(updated, f), " ", (f: rt.Formatter) => Shape.fmt(taken, f), " ", (f: rt.Formatter) => rt.usize.display(range.start, f), " ", (f: rt.Formatter) => rt.usize.display(range.end, f), " ", (f: rt.Formatter) => rt.usize.display(sum, f), " ", (f: rt.Formatter) => rt.fmt.list(slice, f, rt.u8.display)]); + const text = rt.fmt.format([(f: rt.Formatter) => Shape.fmt$Debug(rect, f), " ", (f: rt.Formatter) => Shape.fmt$Debug(line, f), " ", (f: rt.Formatter) => Pair.fmt$Debug(pair, f), " ", (f: rt.Formatter) => Point.fmt$Debug(read, f), " ", (f: rt.Formatter) => Moved.fmt$Debug(updated, f), " ", (f: rt.Formatter) => Shape.fmt$Debug(taken, f), " ", (f: rt.Formatter) => rt.usize.display(range.start, f), " ", (f: rt.Formatter) => rt.usize.display(range.end, f), " ", (f: rt.Formatter) => rt.usize.display(sum, f), " ", (f: rt.Formatter) => rt.fmt.list(slice, f, rt.u8.display)]); out.extendFromSlice(rt.string.asBytes(text)); } @@ -319,7 +319,7 @@ export function loops(data: Uint8Array, out: rt.ByteVec): void { out.push(firstRepeat(data)); out.extendFromSlice(rt.u16.toBeBytes(tailBreak(data))); out.push(armLoop(data)); - out.extendFromSlice(rt.u32.toBeBytes(position(data, 0) as rt.u32)); + out.extendFromSlice(rt.u32.toBeBytes(position$u8(data, 0) as rt.u32)); const settle = (x: rt.u8): rt.u8 => { while (true) { if (x < 10) { @@ -399,12 +399,12 @@ export function madeNever(): (a0: rt.u8) => never { */ export function genericNever(b: rt.u8, len: rt.usize): void { if (b === 0xf1) { - pass(bail(b)); + pass$never(bail(b)); } if (b === 0xf6) { let value: never; rt.panic(["passed ", (f: rt.Formatter) => rt.u8.display(b, f)]); - pass(value); + pass$never(value); } if (b === 0xf9) { let o: never | undefined; @@ -415,18 +415,18 @@ export function genericNever(b: rt.u8, len: rt.usize): void { rt.panic(["some ", (f: rt.Formatter) => rt.u8.display(b, f)]); o = value2; } - unwrapOrBail(o, b); + unwrapOrBail$never(o, b); } } -export function pass(x: never): never { +export function pass$never(x: never): never { rt.unreachable(x); } -export function unwrapOrBail(o: never | undefined, b: rt.u8): never { +export function unwrapOrBail$never(o: never | undefined, b: rt.u8): never { if (o !== undefined) { const x = o; - pass(rt.unreachable(x)); + pass$never(rt.unreachable(x)); } else { bail(b); } @@ -695,7 +695,7 @@ export function armLoop(data: Uint8Array): rt.u8 { } /** A generic function ending in a loop. */ -export function position(items: Uint8Array, want: rt.u8): rt.usize { +export function position$u8(items: Uint8Array, want: rt.u8): rt.usize { let i: rt.usize = 0; while (true) { if (i === items.length || items[rt.idx(items, i)] === want) { @@ -783,7 +783,7 @@ export function patterns(data: Uint8Array, out: rt.ByteVec): void { if (dir_ !== undefined) { const d = dir_; if (b2 > 10) { - out.push(from(d)); + out.push(from$From_Dir_u8(d)); break chain; } } @@ -843,7 +843,7 @@ export function patterns(data: Uint8Array, out: rt.ByteVec): void { const v3 = parsed.value; c = v3; out.extendFromSlice(Uint8Array.of(a3, b4, c, early(a3))); - out.extendFromSlice(rt.string.asBytes(rt.fmt.format([(f: rt.Formatter) => rt.fmt.result(parsed, f, rt.u8.display, (value: Void.Void, f: rt.Formatter) => Void.fmt(value, f))]))); + out.extendFromSlice(rt.string.asBytes(rt.fmt.format([(f: rt.Formatter) => rt.fmt.result(parsed, f, rt.u8.display, (value: Void.Void, f: rt.Formatter) => Void.fmt$Debug(value, f))]))); } /** A value holding a `Void` can't exist either. */ @@ -872,7 +872,7 @@ export function closures(data: Uint8Array, out: rt.ByteVec): void { const scale = (v2: rt.u32): rt.u32 => { return rt.u32.add(rt.u32.mul(v2, 3), base); }; - out.extendFromSlice(rt.u32.toBeBytes(apply(scale, sum))); + out.extendFromSlice(rt.u32.toBeBytes(apply$closures_closure1(scale, sum))); let whole: Uint8Array = Uint8Array.of(data.length & 0xff); overwrite(whole); out.push(whole[0]); @@ -883,7 +883,7 @@ export function closures(data: Uint8Array, out: rt.ByteVec): void { } let tags: rt.ByteVec = new rt.ByteVec(); for (const d of parsed) { - tags.push(rt.option.unwrapOr(rt.option.map(d, from), 0)); + tags.push(rt.option.unwrapOr(rt.option.map(d, from$From_Dir_u8), 0)); } out.extendFromSlice(tags.view()); } @@ -896,7 +896,7 @@ export function overwrite(a: Uint8Array): void { write(); } -export function apply(f: (a0: rt.u32) => rt.u32, v: rt.u32): rt.u32 { +export function apply$closures_closure1(f: (a0: rt.u32) => rt.u32, v: rt.u32): rt.u32 { return f(v); } diff --git a/ts/fixtures/lang/src/fmt.rs b/ts/fixtures/lang/src/fmt.rs index 7c2f5e660..67ee6347a 100644 --- a/ts/fixtures/lang/src/fmt.rs +++ b/ts/fixtures/lang/src/fmt.rs @@ -5,6 +5,7 @@ use std::fmt; +use crate::generics::Wrap; use crate::shapes::{Point, Shape}; /// Take an integer's big-endian bytes from the front of `data`, zero-padded. @@ -255,7 +256,8 @@ impl fmt::Debug for Hex { } } -/// `Display` through `pad`, which keeps the options. +/// `Display` through `pad`, which keeps the options. Only `added` prints its `Debug`. +#[derive(Debug)] pub struct Padded(&'static str); impl fmt::Display for Padded { @@ -452,3 +454,11 @@ pub fn printed(data: &[u8]) -> Vec { let fault = Fault::new(data); format!("{fault}|{fault:>16}|{fault:?}|{fault:#?}").into_bytes() } + +/// A root only the `stable_names` test adds, reaching another instance of what `run` +/// reaches one of: a generic method's, a closure's, and an impl's of another trait. +pub fn added(out: &mut Vec) { + out.push(Wrap::new(1u8).into_inner()); + let mapped = Wrap::new(2u8).map(|b| Pair(b, 0)); + put(out, &format!("{mapped:?} {:?}", Padded("added"))); +} diff --git a/ts/fixtures/task/expected/kio.Consumer.ts b/ts/fixtures/task/expected/kio.Consumer.ts index e95ebe98b..1bacc0bf2 100644 --- a/ts/fixtures/task/expected/kio.Consumer.ts +++ b/ts/fixtures/task/expected/kio.Consumer.ts @@ -5,7 +5,7 @@ import { recvBody } from "./kio.ts"; import type * as State from "./kio.State.ts"; import * as Waiter from "./kio.Waiter.ts"; -export function clone(self: Consumer): Consumer { +export function clone$Clone(self: Consumer): Consumer { return new Consumer({ state: self.state.clone(), next: self.next }); } diff --git a/ts/fixtures/task/expected/kio.Park.ts b/ts/fixtures/task/expected/kio.Park.ts index 303e7a80d..4e37d6764 100644 --- a/ts/fixtures/task/expected/kio.Park.ts +++ b/ts/fixtures/task/expected/kio.Park.ts @@ -3,7 +3,7 @@ import * as rt from "./rt.ts"; import * as Waiter from "./kio.Waiter.ts"; -function default_(): Park { +export function default$Default(): Park { return new Park(undefined); } @@ -40,6 +40,4 @@ export function hold(self: Park, cx: rt.Context): Waiter.Waiter { return rt.option.unwrap(self._0); } -export { default_ as default }; - //# sourceMappingURL=kio.Park.ts.map diff --git a/ts/fixtures/task/expected/kio.Pending.ts b/ts/fixtures/task/expected/kio.Pending.ts index 23b07a69f..5eb0ca08f 100644 --- a/ts/fixtures/task/expected/kio.Pending.ts +++ b/ts/fixtures/task/expected/kio.Pending.ts @@ -20,7 +20,7 @@ export class Pending { } } -export function poll(self: Pending<(a0: Waiter.Waiter) => rt.Poll>, cx: rt.Context): rt.Poll { +export function poll$Future_recv_closure0_closure0(self: Pending<(a0: Waiter.Waiter) => rt.Poll>, cx: rt.Context): rt.Poll { const this_ = self; const waiter = Park.hold(this_.park, cx); return this_.poll(waiter); diff --git a/ts/fixtures/task/expected/kio.Producer.ts b/ts/fixtures/task/expected/kio.Producer.ts index 6a33e53b4..346a658fb 100644 --- a/ts/fixtures/task/expected/kio.Producer.ts +++ b/ts/fixtures/task/expected/kio.Producer.ts @@ -14,7 +14,7 @@ export class Producer { } [Symbol.dispose](): void { - drop(this); + drop$Drop(this); rt.drop(this.state); } } @@ -36,12 +36,12 @@ export function consume(self: Producer): Consumer.Consumer { return new Consumer.Consumer({ state: self.state.clone(), next: 0 }); } -export function clone(self: Producer): Producer { +export function clone$Clone(self: Producer): Producer { self.state.value.value.producers = rt.usize.add(self.state.value.value.producers, 1); return new Producer({ state: self.state.clone() }); } -export function drop(self: Producer): void { +export function drop$Drop(self: Producer): void { let state: rt.Mutex = self.state.value; state.value.producers = rt.usize.sub(state.value.producers, 1); if (state.value.producers > 0) { diff --git a/ts/fixtures/task/expected/kio.ts b/ts/fixtures/task/expected/kio.ts index 7edaa783e..5618f5f14 100644 --- a/ts/fixtures/task/expected/kio.ts +++ b/ts/fixtures/task/expected/kio.ts @@ -7,18 +7,18 @@ import * as Pending from "./kio.Pending.ts"; import type * as Waiter from "./kio.Waiter.ts"; /** A future from a poll function that receives a [`Waiter`]. */ -export function wait(poll: (a0: Waiter.Waiter) => rt.Poll): Pending.Pending<(a0: Waiter.Waiter) => rt.Poll> { - return new Pending.Pending({ poll, park: Park.default() }); +export function wait$recv_closure0_closure0_Option_u64(poll: (a0: Waiter.Waiter) => rt.Poll): Pending.Pending<(a0: Waiter.Waiter) => rt.Poll> { + return new Pending.Pending({ poll, park: Park.default$Default() }); } export function* recvBody(_taskContext: rt.Context, self: Consumer.Consumer): Generator { const self2 = self; - let __awaitee: Pending.Pending<(a0: Waiter.Waiter) => rt.Poll> = wait((waiter: Waiter.Waiter): rt.Poll => { + let __awaitee: Pending.Pending<(a0: Waiter.Waiter) => rt.Poll> = wait$recv_closure0_closure0_Option_u64((waiter: Waiter.Waiter): rt.Poll => { return Consumer.pollRecv(self2, waiter); }); try { while (true) { - const poll = Pending.poll(__awaitee, _taskContext); + const poll = Pending.poll$Future_recv_closure0_closure0(__awaitee, _taskContext); if (poll !== rt.Pending) { const result = poll; return result; diff --git a/ts/fixtures/task/expected/log.Log.ts b/ts/fixtures/task/expected/log.Log.ts index 923d18164..8d5e1f05a 100644 --- a/ts/fixtures/task/expected/log.Log.ts +++ b/ts/fixtures/task/expected/log.Log.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; -export function clone(self: Log): Log { +export function clone$Clone(self: Log): Log { return new Log(self._0.clone()); } diff --git a/ts/fixtures/task/expected/model.Channel.ts b/ts/fixtures/task/expected/model.Channel.ts index 763124693..cc47c826b 100644 --- a/ts/fixtures/task/expected/model.Channel.ts +++ b/ts/fixtures/task/expected/model.Channel.ts @@ -50,7 +50,7 @@ export function open(): Channel { /** A consumer that reads every value from the first. */ export function consumer(self: Channel): Consumer.Consumer { - return Consumer.clone(self.consumer); + return Consumer.clone$Clone(self.consumer); } /** Send `value` through the first producer, if one is open. */ @@ -90,7 +90,7 @@ export function cloneProducer(self: Channel): boolean { const first = rt.slice.first(self.producers); if (first !== undefined) { const producer = first; - clone = Producer.clone(producer); + clone = Producer.clone$Clone(producer); } else { return false; } diff --git a/ts/fixtures/task/expected/model.Guard.ts b/ts/fixtures/task/expected/model.Guard.ts index 09c2b84d5..ac92e8482 100644 --- a/ts/fixtures/task/expected/model.Guard.ts +++ b/ts/fixtures/task/expected/model.Guard.ts @@ -14,7 +14,7 @@ export class Guard { } [Symbol.dispose](): void { - drop(this); + drop$Drop(this); rt.drop(this.log); } } @@ -45,7 +45,7 @@ export function finish(self: Guard, event: string): rt.u32 { } } -export function drop(self: Guard): void { +export function drop$Drop(self: Guard): void { Log.note(self.log, rt.fmt.format(["g", (f: rt.Formatter) => rt.u32.display(self.id, f), " drop"])); } diff --git a/ts/fixtures/task/expected/model.ts b/ts/fixtures/task/expected/model.ts index 1413f2271..fb611bf8a 100644 --- a/ts/fixtures/task/expected/model.ts +++ b/ts/fixtures/task/expected/model.ts @@ -24,7 +24,7 @@ export function* sumBody(_taskContext: rt.Context, rx: Consumer.Consumer, guard: const guard2 = guard; guard = undefined!; try { - const inner = Guard.new(rt.u32.add(guard2.id, 100), Log.clone(guard2.log)); + const inner = Guard.new(rt.u32.add(guard2.id, 100), Log.clone$Clone(guard2.log)); try { let total: rt.u64 = 0; while (true) { @@ -90,9 +90,9 @@ export function* blocksBody(_taskContext: rt.Context, rx: Consumer.Consumer, gua guard = undefined!; try { const moves2 = moves; - let first = Guard.new(rt.u32.add(guard2.id, 200), Log.clone(guard2.log)); + let first = Guard.new(rt.u32.add(guard2.id, 200), Log.clone$Clone(guard2.log)); try { - let second = Guard.new(rt.u32.add(guard2.id, 300), Log.clone(guard2.log)); + let second = Guard.new(rt.u32.add(guard2.id, 300), Log.clone$Clone(guard2.log)); try { rt.drop(rt.future(blocksBody$2, undefined, first)); turns(guard2.log, rt.u32.rem(guard2.id, 5)); @@ -137,13 +137,13 @@ export function* blocksBody(_taskContext: rt.Context, rx: Consumer.Consumer, gua rt.drop(__awaitee2); } Guard.note(guard2, rt.fmt.format(["mark ", (f: rt.Formatter) => rt.u32.display(replaced, f), " ", (f: rt.Formatter) => rt.u32.display(mark.n, f)])); - let cycle = new Outer.Outer({ inner: undefined, guard: Guard.new(rt.u32.add(guard2.id, 800), Log.clone(guard2.log)) }); + let cycle = new Outer.Outer({ inner: undefined, guard: Guard.new(rt.u32.add(guard2.id, 800), Log.clone$Clone(guard2.log)) }); try { const cycle2 = cycle; cycle = undefined!; const _nested = new Inner.Inner({ outer: cycle2 }); try { - let third = Guard.new(rt.u32.add(guard2.id, 400), Log.clone(guard2.log)); + let third = Guard.new(rt.u32.add(guard2.id, 400), Log.clone$Clone(guard2.log)); try { let chosen: Guard.Guard = undefined!; try { @@ -253,7 +253,7 @@ export function* blocksBody$6(_taskContext6: rt.Context, first: Guard.Guard, sec try { Guard.note(first, "reads"); Guard.note(second, "reads"); - const _held = Guard.new(rt.u32.add(second.id, 100), Log.clone(second.log)); + const _held = Guard.new(rt.u32.add(second.id, 100), Log.clone$Clone(second.log)); try { let option: rt.u64 | undefined; let __awaitee3: rt.Future = Consumer.recv(rx2); @@ -316,24 +316,24 @@ export function pick(log: Log.Log, i: rt.usize): rt.usize { * guard a method takes by value, which drops inside it. */ export function turns(log: Log.Log, count: rt.u32): void { - const pair = [Guard.new(rt.u32.add(count, 10), Log.clone(log)), Guard.new(rt.u32.add(count, 20), Log.clone(log))]; + const pair = [Guard.new(rt.u32.add(count, 10), Log.clone$Clone(log)), Guard.new(rt.u32.add(count, 20), Log.clone$Clone(log))]; try { const kept = pair[0]; pair[0] = undefined!; try { Guard.note(kept, "kept"); - const pinned = Guard.new(rt.u32.add(count, 40), Log.clone(log)); + const pinned = Guard.new(rt.u32.add(count, 40), Log.clone$Clone(log)); try { Guard.note(pinned, "pinned"); - const held = Guard.new(rt.u32.add(count, 50), Log.clone(log)); + const held = Guard.new(rt.u32.add(count, 50), Log.clone$Clone(log)); try { const borrowed = held; Guard.note(borrowed, "borrowed"); - const extended = Guard.new(rt.u32.add(count, 60), Log.clone(log)); + const extended = Guard.new(rt.u32.add(count, 60), Log.clone$Clone(log)); try { Guard.note(extended, "extended"); let value: rt.u32; - const inner = Guard.new(rt.u32.add(count, 90), Log.clone(log)); + const inner = Guard.new(rt.u32.add(count, 90), Log.clone$Clone(log)); try { value = inner.id; } finally { @@ -341,13 +341,13 @@ export function turns(log: Log.Log, count: rt.u32): void { } const scoped = value; Log.note(log, rt.fmt.format(["after ", (f: rt.Formatter) => rt.u32.display(scoped, f)])); - const boxed = Guard.new(rt.u32.add(count, 100), Log.clone(log)); + const boxed = Guard.new(rt.u32.add(count, 100), Log.clone$Clone(log)); try { const once = boxed.id; Log.note(log, rt.fmt.format(["boxed ", (f: rt.Formatter) => rt.u32.display(once, f), " ", (f: rt.Formatter) => rt.u32.display(boxed.id, f)])); - const finished = Guard.finish(Guard.new(rt.u32.add(count, 110), Log.clone(log)), "finishing"); + const finished = Guard.finish(Guard.new(rt.u32.add(count, 110), Log.clone$Clone(log)), "finishing"); Log.note(log, rt.fmt.format(["finished ", (f: rt.Formatter) => rt.u32.display(finished, f)])); - const spares = [Guard.new(rt.u32.add(count, 70), Log.clone(log)), Guard.new(rt.u32.add(count, 80), Log.clone(log))]; + const spares = [Guard.new(rt.u32.add(count, 70), Log.clone$Clone(log)), Guard.new(rt.u32.add(count, 80), Log.clone$Clone(log))]; try { const index = pick(log, rt.usize.rem(count as rt.usize, 2)); spares[rt.idx(spares, index)]; @@ -360,7 +360,7 @@ export function turns(log: Log.Log, count: rt.u32): void { if (n < 4) { let left: rt.u32 = n; while (true) { - const turn = Guard.new(left, Log.clone(log)); + const turn = Guard.new(left, Log.clone$Clone(log)); try { if (left === 1) { break; diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index b83889575..af233e977 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -2802,7 +2802,8 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { Expr::rt("future", args) } - /// A module-level function in `parent`'s module, by the name `base`. + /// A module-level function in `parent`'s module, by the name `base` and the suffix of + /// the instance of `parent` it is part of. #[expect(clippy::too_many_arguments, reason = "a function's parts")] fn hoist( &mut self, @@ -2818,7 +2819,7 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { let sym = self.t.program.sym(crate::program::Symbol { module: self.t.module_of(parent), base, - suffix: String::new(), + suffix: self.t.suffix(Instance::new_raw(parent, self.args)), owner: None, kind: SymKind::Function, order, diff --git a/ts/src/lower/mir/coroutine.rs b/ts/src/lower/mir/coroutine.rs index b8e4cb081..f8292873f 100644 --- a/ts/src/lower/mir/coroutine.rs +++ b/ts/src/lower/mir/coroutine.rs @@ -44,10 +44,15 @@ pub fn info<'tcx>(t: &mut Translator<'_, 'tcx>, def_id: DefId, args: GenericArgs let tcx = t.tcx; let parent = tcx.typeck_root_def_id(def_id); let base = format!("{}Future", crate::lower::camel(tcx.item_name(parent).as_str())); + // The suffix of the instance of `parent` it is part of. + let suffix = t.suffix(Instance::new_raw( + parent, + args.truncate_to(tcx, tcx.generics_of(parent)), + )); let sym = t.program.sym(Symbol { module: t.module_of(parent), base, - suffix: String::new(), + suffix, owner: None, kind: SymKind::Struct, order: t.order(tcx.def_span(def_id)), diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 4a01888fe..828339d0f 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -566,38 +566,45 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some(self.adt(*adt, span).sym) } - /// What tells this instance apart from others of the same name. + /// What tells this instance apart from others of its item: the trait it implements, then + /// the type arguments its type and itself take, as `Display_Pair` for `Wrap`'s + /// `Display::fmt`. It is printed whether or not another instance is reached, so reaching + /// one renames nothing; empty for a function that is neither generic, of a generic type, + /// nor of a trait. fn suffix(&self, instance: Instance<'tcx>) -> String { let tcx = self.tcx; - let mut parts = Vec::new(); let def_id = instance.def_id(); - if let Some(imp) = tcx.trait_impl_of_assoc(def_id) { - let trait_ref = tcx.impl_trait_ref(imp).skip_binder(); - let args = self.subst(instance.args, trait_ref.args); - parts.extend(args.types().skip(1).map(|t| short_name(tcx, t))); + let mut parts = Vec::new(); + let trait_ref = match tcx.trait_impl_of_assoc(def_id) { + Some(imp) => Some(self.subst(instance.args, tcx.impl_trait_ref(imp).skip_binder())), + // A trait's own method, which an impl did not override. + None => tcx + .trait_of_assoc(def_id) + .map(|trait_id| ty::TraitRef::from_assoc(tcx, trait_id, instance.args)), + }; + if let Some(trait_ref) = trait_ref { + parts.push(tcx.item_name(trait_ref.def_id).to_string()); + // Without defaults, as `PartialEq`'s `Self`. + let args = tcx + .generics_of(trait_ref.def_id) + .own_args_no_defaults(tcx, trait_ref.args); + parts.extend(args.iter().filter_map(|arg| arg.as_type()).map(|t| short_name(tcx, t))); } - // The type whose class or companion this is on goes without saying, but not its - // arguments, such as a default method's on `Wrap`. - let owner = self - .self_ty(instance) - .map(Ty::peel_refs) - .filter(|t| matches!(t.kind(), ty::Adt(adt, _) if adt.did().is_local())); - // A closure or function type follows from the others, and has no name. - let named = |t: &Ty<'tcx>| !matches!(t.kind(), ty::Closure(..) | ty::FnDef(..) | ty::FnPtr(..)); - for t in instance.args.types().filter(named) { - match (owner == Some(t), t.kind()) { - (true, ty::Adt(_, args)) => parts.extend(args.types().map(|t| short_name(tcx, t))), - _ => parts.push(short_name(tcx, t)), + // The type whose module this is in goes without saying, but not its arguments; any + // other self type, such as `u64`'s in a trait impl, is spelled out. + if let Some(self_ty) = self.self_ty(instance) { + match self_ty.peel_refs().kind() { + ty::Adt(adt, args) if adt.did().is_local() => parts.extend(args.types().map(|t| short_name(tcx, t))), + _ => parts.push(short_name(tcx, self_ty)), } } - parts.dedup(); - // Impls of traits without arguments, such as `Display::fmt` and `Debug::fmt`, are - // told apart by their trait. - if parts.is_empty() - && let Some(imp) = tcx.trait_impl_of_assoc(def_id) - { - let trait_id = tcx.impl_trait_ref(imp).skip_binder().def_id; - parts.push(tcx.item_name(trait_id).to_string()); + let own = tcx.generics_of(def_id).parent_count; + for arg in &instance.args[own..] { + match arg.kind() { + ty::GenericArgKind::Type(t) => parts.push(short_name(tcx, t)), + ty::GenericArgKind::Const(c) => parts.push(c.to_string().replace(|c: char| !c.is_alphanumeric(), "")), + ty::GenericArgKind::Lifetime(_) => {} + } } parts.join("_") } @@ -1171,12 +1178,36 @@ pub fn short_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String { .join("_") } ty::Ref(_, inner, _) => short_name(tcx, *inner), + // Named, since a suffix without its part would read as no instance. + ty::Tuple(tys) if tys.is_empty() => "unit".into(), + ty::Never => "never".into(), ty::Tuple(tys) => tys.iter().map(|t| short_name(tcx, t)).collect::>().join("_"), ty::Array(elem, _) | ty::Slice(elem) => format!("{}s", short_name(tcx, *elem)), + // By where it is defined, not by its span, which code above it moves. + ty::Closure(def_id, _) | ty::Coroutine(def_id, _) | ty::CoroutineClosure(def_id, _) | ty::FnDef(def_id, _) => { + def_name(tcx, *def_id) + } _ => ty.to_string().replace(|c: char| !c.is_alphanumeric(), ""), } } +/// A function's name, or a closure's as Rust numbers it in what defines it: `run_closure0` +/// for `run::{closure#0}`. A tuple struct's constructor goes by the struct's name. +fn def_name(tcx: TyCtxt<'_>, def_id: DefId) -> String { + use rustc_hir::definitions::{DefPathData, DefPathDataName}; + let path = tcx.def_path(def_id).data; + let named = path.iter().rposition(|part| part.data.get_opt_name().is_some()); + path[named.unwrap_or(0)..] + .iter() + .filter(|part| part.data != DefPathData::Ctor) + .map(|part| match part.data.name() { + DefPathDataName::Named(name) => name.to_string(), + DefPathDataName::Anon { namespace } => format!("{namespace}{}", part.disambiguator), + }) + .collect::>() + .join("_") +} + /// `snake_case` to `camelCase`, keeping leading underscores. pub fn camel(name: &str) -> String { let name = name.strip_prefix("r#").unwrap_or(name); diff --git a/ts/src/program.rs b/ts/src/program.rs index 00af54621..fd62f9672 100644 --- a/ts/src/program.rs +++ b/ts/src/program.rs @@ -25,7 +25,8 @@ pub struct Symbol { pub module: ModPath, /// The name it would like, before collisions are resolved. pub base: String, - /// Appended, after a `$`, when the base collides; empty for a numbered suffix. + /// Appended after a `$`, whether or not another instance of its item is reached: + /// what tells the instance apart, such as `Display_Pair`. Empty for none. pub suffix: String, /// The class a method belongs to. pub owner: Option, @@ -137,27 +138,17 @@ impl Program { // What a class already defines. Scope::Owner(_) => taken.extend(["constructor".to_string(), "prototype".to_string()]), } - // Instances sharing a name are all told apart, so none looks like the only one. - let mut shared: HashMap<&str, usize> = HashMap::new(); - for &id in &ids { - *shared.entry(self.syms[id].base.as_str()).or_default() += 1; - } - let shared: HashSet = shared - .into_iter() - .filter(|(_, n)| *n > 1) - .map(|(b, _)| b.to_string()) - .collect(); for id in ids { let sym = &self.syms[id]; - let base = match shared.contains(&sym.base) && !sym.suffix.is_empty() { - true => format!("{}${}", sym.base, sym.suffix), - false => sym.base.clone(), + let base = match sym.suffix.is_empty() { + true => sym.base.clone(), + false => format!("{}${}", sym.base, sym.suffix), }; let escaped = match sym.kind { SymKind::Function => crate::lower::escape(&base), _ => base.clone(), }; - let name = unique(&mut taken, &escaped, ""); + let name = unique(&mut taken, &escaped); self.syms[id].alias = (name == escaped && escaped != base).then_some(base); self.syms[id].name = name; } @@ -168,7 +159,7 @@ impl Program { true => format!("_{}", field.base), false => field.base.clone(), }; - field.name = unique(&mut taken, &base, ""); + field.name = unique(&mut taken, &base); } } } @@ -221,11 +212,9 @@ enum Scope { Owner(SymId), } -fn unique(taken: &mut HashSet, base: &str, suffix: &str) -> String { +/// `base`, or the first of `base$2`, `base$3`, and on that is not taken. +fn unique(taken: &mut HashSet, base: &str) -> String { let mut name = base.to_string(); - if taken.contains(&name) && !suffix.is_empty() { - name = format!("{base}${suffix}"); - } let mut n = 2; while taken.contains(&name) { name = format!("{base}${n}"); diff --git a/ts/tests/fixtures.rs b/ts/tests/fixtures.rs index 38e78c361..8a56e08dc 100644 --- a/ts/tests/fixtures.rs +++ b/ts/tests/fixtures.rs @@ -266,34 +266,57 @@ fn codec_mir() { /// text and order, though translation reaches it in another order. #[test] fn source_order() { - let config = std::fs::read_to_string(fixture("codec").join("ts.toml")).unwrap(); - let roots = r#"roots = ["harness::run", "bench::run"]"#; - assert!(config.contains(roots), "codec's roots changed: update this test"); - let dir = scratch().join("codec").join("order"); + added_root( + "codec", + r#"roots = ["harness::run", "bench::run"]"#, + r#"roots = ["harness::run"]"#, + // First, so that translation reaches what both share in another order. + r#"roots = ["bench::run", "harness::run"]"#, + ); +} + +/// Adding a root that reaches another instance of a generic function, or another trait's +/// impl of a method, renames nothing the old roots reach. +#[test] +fn stable_names() { + let roots = r#"roots = ["harness::run", "fmt::Fault"]"#; + added_root( + "lang", + roots, + roots, + r#"roots = ["fmt::added", "harness::run", "fmt::Fault"]"#, + ); +} + +/// Translate fixture `name` with its config's `roots` line replaced by `base`, then by +/// `added`, and check that every line of the first output stays, in order, in the second. +fn added_root(name: &str, roots: &str, base: &str, added: &str) { + let config = std::fs::read_to_string(fixture(name).join("ts.toml")).unwrap(); + assert!(config.contains(roots), "{name}'s roots changed: update this test"); + let dir = scratch().join(name).join("order"); std::fs::create_dir_all(&dir).unwrap(); - let run = |name: &str, with: &str| { - let path = dir.join(format!("{name}.toml")); + let run = |file: &str, with: &str| { + let path = dir.join(format!("{file}.toml")); std::fs::write(&path, config.replace(roots, with)).unwrap(); - let out = dir.join(name); - let output = driver("codec", &path, &["--out".as_ref(), out.as_ref()], "order"); + let out = dir.join(file); + let output = driver(name, &path, &["--out".as_ref(), out.as_ref()], "order"); assert!( output.status.success(), - "translating codec with {with} failed:\n{}", + "translating {name} with {with} failed:\n{}", String::from_utf8_lossy(&output.stderr) ); sources(&out) }; - let base = run("base", r#"roots = ["harness::run"]"#); - // First, so that translation reaches what both share in another order. - let added = run("added", r#"roots = ["bench::run", "harness::run"]"#); + let base = run("base", base); + let more = run("added", added); for (rel, text) in &base { - let more = added.iter().find(|(r, _)| r == rel).map(|(_, text)| text); - let more = more.unwrap_or_else(|| panic!("{} is gone once bench::run is added", rel.display())); + let more = more.iter().find(|(r, _)| r == rel).map(|(_, text)| text); + let more = more.unwrap_or_else(|| panic!("{} is gone once {added}", rel.display())); let mut rest = lines(more).into_iter(); for line in lines(text) { assert!( rest.any(|l| l == line), - "{}: this line changed or moved once bench::run was added:\n{line}", + "{}: this line changed or moved once {added}:\n{line}", rel.display() ); } diff --git a/ts/tests/task.ts b/ts/tests/task.ts index 4cbfb666a..cc9c3d2e7 100644 --- a/ts/tests/task.ts +++ b/ts/tests/task.ts @@ -31,7 +31,7 @@ export interface Fixture { "new"(): Log; note(log: Log, event: string): void; text(log: Log): { view(): Uint8Array }; - clone(log: Log): Log; + clone$Clone(log: Log): Log; }; Channel: { open(): Channel; @@ -200,7 +200,7 @@ export function harness(f: Fixture, unwind = false): (input: Uint8Array) = channels.push(f.Channel.open()); break; case 1: - if (c !== undefined) exec.spawn(f.sum(f.Channel.consumer(channels[c]), f.Guard.new(exec.tasks.length, f.Log.clone(log)))); + if (c !== undefined) exec.spawn(f.sum(f.Channel.consumer(channels[c]), f.Guard.new(exec.tasks.length, f.Log.clone$Clone(log)))); break; case 2: if (c !== undefined) exec.spawn(f.drain(f.Channel.consumer(channels[c]), [1, 4, 16][(arg >> 4) % 3])); @@ -241,7 +241,7 @@ export function harness(f: Fixture, unwind = false): (input: Uint8Array) = } default: if (c !== undefined) { - exec.spawn(f.blocks(f.Channel.consumer(channels[c]), f.Guard.new(exec.tasks.length, f.Log.clone(log)), arg >= 128)); + exec.spawn(f.blocks(f.Channel.consumer(channels[c]), f.Guard.new(exec.tasks.length, f.Log.clone$Clone(log)), arg >= 128)); } } }