Unified: Track all local name kinds in one pass - #22284
Open
asgerf wants to merge 18 commits into
Open
Conversation
asgerf
force-pushed
the
unified/local-type-names
branch
from
August 5, 2026 12:28
9ebfd45 to
d94ae9d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Swift name binding to resolve variables, functions, types, modules, and other local names through one unified pass.
Changes:
- Replaces variable-specific APIs with generalized local-name binding.
- Adds scope tests for top-level, class, and generic type names.
- Extracts generic parameters and constraints for nominal Swift types.
Show a summary per file
| File | Description |
|---|---|
unified/ql/test/library-tests/local-name-binding/top_level.swift |
Tests top-level name resolution. |
unified/ql/test/library-tests/local-name-binding/test.swift |
Adds type-name access coverage. |
unified/ql/test/library-tests/local-name-binding/test.ql |
Updates the test harness for generalized names. |
unified/ql/test/library-tests/local-name-binding/test.expected |
Adds expected query outputs. |
unified/ql/test/library-tests/local-name-binding/class_scope.swift |
Tests class and generic-parameter scopes. |
unified/ql/lib/unified.qll |
Exports the renamed binding module. |
unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll |
Implements generalized local-name binding. |
unified/ql/lib/codeql/unified/internal/AstExtra.qll |
Identifies top-level statements. |
unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.swift |
Adds generic-class extraction input. |
unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output |
Records expected generic-class AST output. |
unified/extractor/src/languages/swift/swift.rs |
Translates nominal-type parameters and constraints. |
Review details
Suppressed comments (1)
unified/extractor/src/languages/swift/swift.rs:1168
protocolDeclhas nogenericParameterClausefield inswift_node_types.yml; SwiftSyntax represents the angle-bracket list asprimaryAssociatedTypeClause. Consequently this optional capture is always empty and protocol primary associated-type names are never represented or bound. Please matchprimaryAssociatedTypeClauseand translate its names with the appropriate associated-type semantics.
genericParameterClause: (genericParameterClause parameters: _* @params)?
- Files reviewed: 10/11 changed files
- Comments generated: 1
- Review effort level: Balanced
These can also refer to type names and module names, so 'Variable' is not an appropriate term. Actual variables will be introduced at a later stage.
- Use PotentialLocalNameAccess to define accessCand(), not the other way around - Use the Identifier as the definingNode, not wrappers like NameExpr
asgerf
force-pushed
the
unified/local-type-names
branch
from
August 5, 2026 13:37
4a1e9b8 to
aaa2c1c
Compare
asgerf
marked this pull request as ready for review
August 5, 2026 13:43
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.
In Swift there is a single shared namespace for variables, functions, types, modules, etc. This PR updates the
Variables.qllpass to track all names at once, and renames it toLocalNameBinding.qllto account for the fact that this is not only for variables anymore.Also contains some drive-by AST mapping fixes. Commit-by-commit review recommended.
Why not treat different name kinds separately?
Some languages have distinct namespaces for variables and types, but trying to separate them for Swift leads to some complications. For example, we would have trouble resolving the references to
Cbelow, where both references would appear to refer to both the variable and the type -- if neither resolution pass knows about the other name kind, it gets hard to reason about shadowing among them.With that said, statement labels (
break/continuetargets) actually do have their own namespace, even in Swift, which lets us experiment with various solutions to this. I expect we can just add anamespacecolumn to the local name binding module, e.g. so we getaccessCand(AstNode n, string namespace, string name);and treat(namespace, name)as the "effective" name of a local. But I've left this for a future PR.Uncertain scopes
The old
VariableAccessclass is now calledPotentialLocalNameAccess; in a future we will reintroduce something likeVariableAccessonce we have the pieces needed to define it properly. The "potential" part is due to the fact that the local resolution might pass through a class scope, in which inherited members take precedence over outer lexical scopes:Since types mentioned in the base classes of a class can themselves be resolved through inherited names, we can't build the class hierarchy prior to name binding -- it has to be combined (this will be done in a future PR).