-
Notifications
You must be signed in to change notification settings - Fork 260
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
Open
kafkas
wants to merge
101
commits into
main
Choose a base branch
from
anar/fer-7122-symbol-registry-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,614
−2,588
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
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