Repository navigation
Fix #90: derive stable-name hash from structure, not type.id (no churn across versions/edits) - #140
Merged
Merged
Conversation
The finalization pass gives a genuinely-colliding shape (same base, same home) a content-hash suffix, but the hash was seeded from entrySig/recordSig — which embed the checker's `type.id` through entry ref-keys. `type.id` is assigned in encounter order, so an unrelated upstream edit OR a compiler-version bump renumbered it and a byte-identical shape got a different name (fooConfig3 <-> fooConfig) — source-breaking churn for downstream consumers who annotated the old name. New `structuralSig` seeds the hash from STRUCTURE only: field names/optionality + recursively the referenced types' shapes (cycle- and diamond-guarded by an add-only seen set, so it's linear on deep DAGs), with no `type.id`. The id-based entrySig/recordSig are untouched for dedup/merge (correct within a run). One line in stabilizeNames swaps the hash seed. Identical shape => identical name across compiler versions and unrelated edits. Verified: blend generates byte-identical type names on TypeScript 5.9 and 6.0.3; an unrelated upstream type addition no longer renames unchanged shapes. Guarded by a renumber-invariance smoke check (shapeHash/structuralSig exported for it). One-time rename of the affected hash-suffixed names in this release (the golden + benchmark-baseline diff); stable thereafter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Benchmark: ✅ PASS
|
commit: |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #90.
Problem
The finalization pass (
stabilizeNames) gives a genuinely-colliding shape — same base name, same home, distinct shape — a content-hash suffix instead of an encounter-order counter, so a byte-identical shape should keep its name. But the hash was seeded fromentrySig/recordSig, which encode a field's referenced type as its entry key — and keys are'id:' + type.id. The checker assignstype.idin encounter order, so:→ the "stable" hash changes and a byte-identical shape gets a different name (
fooConfig3⇄fooConfig). That's source-breaking churn for every downstream consumer who annotated the old name, with zero semantic change upstream — exactly what a typed-API generator must not do.Fix
A new
structuralSigseeds the hash from structure only: field names + optionality, and recursively the shapes of referenced types (not their id-keys), cycle- and diamond-guarded by an add-onlyseenset (linear on deep DAGs — blend's ~2600-node--webapigraph is fine). The id-basedentrySig/recordSigare untouched for dedup and the merge, wheretype.idis correct within a run. The change is one line instabilizeNames— swapping the hash seed.Guarantee
Identical shape ⇒ identical name, across compiler versions and unrelated upstream edits. Only a real shape change changes a name.
Verified three ways:
type.id) no longer renames the unchangedSizeTokenshapes.One-time cost
Because the hash function changes, the currently hash-suffixed names rename once in this release (the golden + benchmark-baseline diff —
portalStyleQn0e4 → portalStyleV1dkur, byte-identical shapes). This is the last forced rename; ship it with a version bump and a consumer note. All metrics are unchanged (name-only, equal-or-better on all 9 benchmark packages).Verification
🤖 Generated with Claude Code