Repository navigation
feat(ts): stable names for generic instances and trait impls - #47
Conversation
Quest-Claim: 3421d0df197d3cf6
A generic instance always prints its type arguments, and a trait impl's function its trait, whether or not another is reached. Closure types in a suffix are named by where they are defined, so they stop being numbered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A closure in an anonymous constant has no named typeck root, and a tuple struct's constructor goes by the struct. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 71b439f
No actionable bugs found. Deriving suffixes from each instance rather than the reached symbol set is a sound simplification; carrying that rule through generated async symbols and adding the root-expansion regression addresses the intended instability. The latest definition-path fix avoids assuming every type-checking root has a name. The documented short-name collision fallback remains a limitation, so this is not a guarantee of globally unique stable names.
Verification: static inspection of naming/lowering changes, surrounding code, migration notes, tests and snapshots, including the latest incremental commit. I did not run the compiler, TypeScript checks or tests.
Regenerates the snapshots for the cases #48 and #49 added, and names `!` and `()` in a suffix (`pass$never`), which printed as an empty part. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: a90f179
No actionable bugs found since 71b439f. After separating merged main changes, explicitly naming unit and never types is a sensible extension of instance-based naming: these arguments no longer disappear from suffixes. Regenerated fixtures consistently use suffixed names, including pass$never and unwrapOrBail$never. The documented short-name collision limitation is unchanged.
Verification: static inspection of incremental naming change, surrounding code and merged fixture snapshots. No compiler runs, TypeScript checks or tests.
|
Merging after #48 and #49, per the maintainer's merge order.
(written by Opus 5.5) |
Problem
A translated function's name depended on what else was reached. A generic function with one instance was
foountil a root reached a second, and a type with onlyDebuggotfmtuntil it also hadDisplay; either renamed calls in code the new root never reached. Instances whose suffixes matched, such as two closures, were numbered$2by their full type arguments, so a new instance could shift them too.Approach
Program::namealways prints a non-empty suffix; the "shared base" pass is gone.Translator::suffixis a pure function of the instance: the trait (impl or provided method) with its non-default type arguments, then the self type's arguments (or the whole self type when it is not a local type), then the function's own type and const arguments.dedupis dropped.short_namenames closures, coroutines, and function items by def path (methods_closure1formethods::{closure#1}), not by span. Closures used to be dropped from the suffix, which is what made them collide and get numbered.fooBody) and a MIR coroutine class (fooFuture) take their parent instance's suffix, so two instances of a genericasync fnno longer tie on the sort key. Both lowerings share the same naming.stable_namestest: translateslangwith its roots, then withfmt::addedadded first, which reaches a secondinto_inner, a second closure instance ofmap, andPadded'sDebugbeside itsDisplay. Every line of the first output must stay, in order, in the second. It fails onmain(fmt.Padded.ts).source_ordernow shares the helper.blocksBody$2), which follow that function's source. moq-net's translation has none.Impact
Log.clone$Clone,Pair.fmt$Debug,Version.encode$Encode_Version). Functions of generic types and generic instances always name their type arguments (Wrap.intoInner$Point,Halving.next$Iterator_u64,Wrap.fmt$Debug_Pair). Closure types appear in suffixes (decodeWith$Group_decode_closure0).ts/MIGRATE.mdhas the entry, and the earlier UnreleasedGroup.encodeexample is corrected.just ts moqtype-checks.Alternatives
$2, which shifts.short_nameinjective (refs, array lengths, same-named types from different modules): those still fall back to$2. That is rare and nothing reaches it today.Follow-ups
&TvsT, and arrays of different lengths can still collide and be numbered. If moq ever hits this, qualifyshort_namefurther.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
(written by Opus 5.5)