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
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