Give surviving anonymous structs a synthetic name - #81
Merged
Conversation
A multi-field anonymous struct (a `sequence` with no `meta.name`) was named by `getName`, which via `findDeepName` steals the struct's first field name - colliding with that field and producing `params.X.X` access paths (e.g. `params.fractional_intensity.fractional_intensity` for the FSL bet shape). Add `freshStructName` to `NamingStrategy`: a synthetic `structN` (dedicated counter) that dodges the struct's own field keys. The genuine-struct and empty-struct-with-outputs branches use `node.meta?.name ?? freshStructName`, so named sets keep their name and only anonymous aggregates get `structN`. Key each sequence field by the child's registered binding name rather than the pre-computed `childName` - backends look up `structType.fields[binding.name]`, so the key must track the (possibly renamed) binding. The two are identical for every case except the renamed struct; collapsed children fall back to childName. If a synthetic name still clashes with a sibling literally named `structN`, re-mint the struct so no parameter is silently overwritten.
Merged
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.
Problem
A multi-field anonymous struct (a
sequencenode with nometa.name) was named bygetName, which viafindDeepNamesteals the struct's first field name. That name then collides with the field itself, producing doubled access paths - e.g. the FSLbetshape yieldedparams.fractional_intensity.fractional_intensity.Fix
freshStructNametoNamingStrategy: a syntheticstructN(backed by a dedicated counter) that dodges the struct's own field keys. The genuine-struct and empty-struct-with-outputs branches now name their bindingnode.meta?.name ?? freshStructName(fields), so named sets keep their name and only truly anonymous aggregates getstructN.childName. Backends look upstructType.fields[binding.name](collect-field-info,resolve-field-binding), so the key must track the renamed binding. The two are identical for every case except the renamed struct; collapsed children fall back tochildName.structN: re-mint whichever colliding party is the auto-named struct so no parameter is silently overwritten (covers both field orderings).Tests
struct1(notfractional_intensity) with a cleanparams.struct1.fractional_intensitypath; own-field conflict skipsstruct1->struct2; sibling-collision in both orderings keeps both parameters. SharedexpectNoRepeatedFieldSegmentshelper asserts noparams.X.Xanywhere.execution.test.tscases that had encoded the old buggy name (host->struct1); the joined struct is genuinely anonymous sostruct1is the correct key.Verification
npm test- 1273 passedtsc --noEmit(CI typecheck gate) - cleancorpus:roundtripover the niwrap catalog - 1919/1919 round-trip cleanlytypecheck:codegen(generates Python + TS, runs mypy--strict+ tsc) - cleanNote
structNis user-visible in generated type/field names. This is inherent: a genuinely anonymous aggregate has no stable semantic name, and this replaces previously-broken colliding names. Deriving a nicer synthetic (e.g. field-name-joined) instead of a bare ordinal is a possible follow-up.