-
Notifications
You must be signed in to change notification settings - Fork 262
feat(swift): lexical scope chain with graph-backed naming and resolution #9870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
46140c5 to
54dace0
Compare
6f7961c to
ad2bc10
Compare
c311fca to
83c5d7d
Compare
tjb9dc
approved these changes
Oct 23, 2025
83c5d7d to
03b3b7b
Compare
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
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.
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
StringandIntwhen unambiguous; when ambiguity or shadowing exists (e.g., nested user types colliding withFoundation), 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
AbstractSwiftGeneratorContextto register the symbols to the new name registry and replacegetSwiftTypeForTypeReferencewithgetSwiftTypeReferenceFromScopethat computes the type reference based on the current lexical scope.Referencer, responsible for constructingswift.TypeReferenceinstances from a given symbol scope; all cross-scope lookups now route through it.SourceSymbolRegistryandTestSymbolRegistryin favor of the graph-backed NameRegistry.TypeReferenceAST node, which carries a resolved reference to a symbol and is used when rendering types.ComputedProperty,Expression,Methodto useTypeReferenceinstead ofTypeduring emission.swift.Symbolclass to represent a symbol in a project with a unique ID, name and some helper methodsswift.Symbolto represent a symbol with a stable ID, human-readable name, and helpers for generators.SymbolGraphto store the Symbol nodes for a given project and resolve references according to a lexical scope chainSymbolRegistry, a low-level registry primitive that internally relies on aSymbolGraphLocalContext,LocalSymbolRegistryin favor of the new name registry.SDKGeneratorCliand all generators likeStructGenerator,DiscriminatedUnionGenerator,WireTestSuiteGeneratoretc. to pull the names from the new registry and use the scope-aware Referencer to create resolved type references.getQueryParamCaseNamethat relied onswift.Typein favor of theEndpointMethodGenerator.inferQueryParamCaseName()that relies onswift.TypeReferencecore-utilsto add new assertion types and export all assertion utils fromassert.tsTesting