Skip to content

Conversation

@kafkas
Copy link
Member

@kafkas kafkas commented Oct 14, 2025

Description

Linear ticket: FER-7122

This PR is a foundational refactor of naming and reference resolution in the Swift generator. We replace the prior flat, name-only registry with a graph-backed name registry built on a lexical scope chain. During a single discovery pass, every symbol (modules, schema types, nested discriminated union variants, etc.) is registered as a node in the graph. All references are then resolved through the graph and emitted via swift.TypeReference.

We aim to emit concise identifiers like String and Int when unambiguous; when ambiguity or shadowing exists (e.g., nested user types colliding with Foundation), the resolver deterministically disambiguates and renames them. This is a major change that unifies registration, lookup, and emission under a single, scope-aware system.

Changes Made

  • Extended as-is file definitions to include the shapes of exported symbols so they can be precisely registered in the new registry.
  • Updated AbstractSwiftGeneratorContext to register the symbols to the new name registry and replace getSwiftTypeForTypeReference with getSwiftTypeReferenceFromScope that computes the type reference based on the current lexical scope.
  • Added Referencer, responsible for constructing swift.TypeReference instances from a given symbol scope; all cross-scope lookups now route through it.
  • Removed the old SourceSymbolRegistry and TestSymbolRegistry in favor of the graph-backed NameRegistry.
  • Introduced the TypeReference AST node, which carries a resolved reference to a symbol and is used when rendering types.
  • Updated various AST nodes like ComputedProperty, Expression, Method to use TypeReference instead of Type during emission.
  • Added the swift.Symbol class to represent a symbol in a project with a unique ID, name and some helper methods
  • Added swift.Symbol to represent a symbol with a stable ID, human-readable name, and helpers for generators.
  • Added SymbolGraph to store the Symbol nodes for a given project and resolve references according to a lexical scope chain
  • Added SymbolRegistry, a low-level registry primitive that internally relies on a SymbolGraph
  • Deleted LocalContext, LocalSymbolRegistry in favor of the new name registry.
  • Updated SDKGeneratorCli and all generators like StructGenerator, DiscriminatedUnionGenerator, WireTestSuiteGenerator etc. to pull the names from the new registry and use the scope-aware Referencer to create resolved type references.
  • Deleted getQueryParamCaseName that relied on swift.Type in favor of the EndpointMethodGenerator.inferQueryParamCaseName() that relies on swift.TypeReference
  • Minor changes in core-utils to add new assertion types and export all assertion utils from assert.ts
  • Updated Seed snapshots

Testing

  • Unit tests added/updated
  • Manual testing completed

@kafkas kafkas marked this pull request as ready for review October 15, 2025 09:44
@kafkas kafkas force-pushed the anar/fer-7122-symbol-registry-improvements branch from 46140c5 to 54dace0 Compare October 15, 2025 19:40
@kafkas kafkas changed the title fix(swift): symbol registry improvements feat(swift): lexical scope chain + symbol graph for naming & resolution Oct 16, 2025
@kafkas kafkas changed the title feat(swift): lexical scope chain + symbol graph for naming & resolution feat(swift): lexical scope chain with graph-backed naming and resolution Oct 16, 2025
@kafkas kafkas force-pushed the anar/fer-7122-symbol-registry-improvements branch from 6f7961c to ad2bc10 Compare October 22, 2025 23:08
@kafkas kafkas force-pushed the anar/fer-7122-symbol-registry-improvements branch from c311fca to 83c5d7d Compare October 23, 2025 17:19
@fern-support fern-support force-pushed the anar/fer-7122-symbol-registry-improvements branch from 83c5d7d to 03b3b7b Compare October 24, 2025 16:13
@kafkas kafkas merged commit c412342 into main Oct 24, 2025
109 checks passed
@kafkas kafkas deleted the anar/fer-7122-symbol-registry-improvements branch October 24, 2025 16:25
devin-ai-integration bot pushed a commit that referenced this pull request Oct 25, 2025
…ion (#9870)

* Implement SymbolReference

* Symbol nodes

* Add `assertNonNull`

* Add method

* Symbol graph and basic tests

* Swift symbol registry

* Fix qualified path

* Add more tests

* Rename

* More tests for references to built-in types

* Don't fully qualify at all times

* Handle ambiguous imports

* Improved tests

* Some refactor and improvements

* Don't expose mutable types

* Name registry v2

* Start migrating

* Refactor

* More refactor

* Symbol references

* Init TypeReference

* Export

* Implement `getSwiftTypeForTypeReference()`

* Rely on TypeReference in codegen

* Fix compiler errors

* Add todo

* Various improvements

* Start switching to new mapper

* Rename

* Implement resolver

* Fix endpoint method check

* Keep migrating

* Delete unused SymbolReference

* Delete

* Keep migrating

* Remove `getSwiftTypeForTypeReference()` and adjust dependent code

* Delete SourceSymbolRegistry

* Remove redundant type

* Remove unused

* Use swift.Symbol

* Declare Foundation and Swift types in symbol

* Use swift.Symbol in generators

* Register nested literal enum symbols

* More fixes

* Start using referencer

* Keep switching to referencer

* Use Referencer in struct generator

* Use TypeReference member access when needed

* Remove migration type

* Fix literal enum generation

* Fix unqualified reference

* Implement `inferQueryParamCaseName`

* Undiscriminated union variant registration

* Update lockfile

* Create referencer before all else

* Fix incorrect type

* Fix literal enum registration

* Fix initialization error

* Fix request type name registration

* Store shape info in symbol nodes

* Fix reference to .rawValue in endpoint method generator

* Update seed snapshots

* Fix type literals

* Resolve alias types in query params

* Update snapshots

* Export asserts from one file

* Remove redundant

* Keep both source and test modules in TargetSymbolRegistry

* Rename srcNameRegistry to nameRegistry

* Rename dirs

* Fix wire tests

* Remove todo

* Update dynamic snippet snapshots

* Don't use Type in Expression

* Fix incorrect request type registration

* Fix object generator tests

* Register literal enums in request structs

* Update snapshots

* Register discriminated union variants

* Wire test type fixes

* Fix registration order

* Add discu variants to the graph

* Update seed snapshots

* Rename `TargetSymbolRegistry` to `SymbolRegistry`

* Add changelog entry

* Fix ref

* Register sanitized names

* Register literals in union variants

* Fix query param arg

* Don't store discriminated union variant type refs

* Generate nested types for undiscriminated union

* Update seed snapshots

* Update snapshots

* Filter out nop expressions when passing args

* Update file-upload snapshots

* Update seed snapshots

* Update changelog

* Update dynamic snippets snapshots

* Add allowed failure

* Remove allowed failure

* Retry

* Remove file-upload from allowed failures

* Update snapshot

---------

Co-authored-by: Fern Support <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants