-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unified: Add static name binding pass #22299
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
asgerf
wants to merge
28
commits into
github:main
Choose a base branch
from
asgerf:unified/static-name-binding
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.
+1,866
−121
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
60baec6
unified: Add test showing problem with literal getValue()
asgerf 51fe273
unified: Fix extraction of literals
asgerf b71ff8f
unified: Factor some code into CommentUtil.qll
asgerf c9fc793
unified: Fix mapping for compound type names
asgerf f50c80a
unified: Initial static name binding pass
asgerf 375924e
unified: Track through aliases
asgerf db8b97a
unified: Add inheritance steps
asgerf 6341bba
unified: Support unqualified access
asgerf ee8753b
unified: Allow numbers in key=value comments
asgerf 7e3a4e3
unified: Cross-file name binding
asgerf 574a5c9
unified: Handle bracketed generic array constructors
asgerf 55b96f1
unified: Handle bracketed generic array metatypes
asgerf 171aa7a
unified: Use '.' as location for inferred_type_expr
asgerf a9792e5
unified: Fix handling of exprPattern
asgerf 8080bac
unified: Add newlines at EOF
asgerf 0cf2871
unified: Update comment
asgerf a3f21a5
unified: Support scoped imports
asgerf 50f934b
unified: Don't track trivial name aliasse
asgerf a79c32a
unified: Bulk imports
asgerf 05fe395
unified: Fix access level in test case
asgerf 659da08
unified: Fix incorrect expectation
asgerf 35c54b1
unified: Fix toString and getLocation for TLocalNamespace
asgerf af2f5a2
unified: Remove location of TModuleRoot
asgerf 970e4c6
unified: Fix handling of unscoped imports
asgerf f596a67
unified: Fix Swift source folder documentation
asgerf d6164c3
unified: Preserve array constructor trailing closures
asgerf a658c77
unified: Add test showing AST mapping error
asgerf c58a096
unified: Fix translation of callee in constructor pattern
asgerf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,12 @@ signature module LocalNameBindingInputSig<LocationSig Location> { | |
| * full control of scope resolution for specific types of references. | ||
| */ | ||
| default predicate lookupStartsAt(AstNode n, AstNode scope) { none() } | ||
|
|
||
| /** | ||
| * Holds if the set of names available in `scope` is not known ahead of time, | ||
| * and thus any lookup chain that goes through `scope` may need to be reconciled at a later stage. | ||
| */ | ||
| default predicate uncertainScope(AstNode scope) { none() } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -154,6 +160,8 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location> | |
| implicitDeclInScope(_, this) | ||
| or | ||
| isTopScope(this) | ||
| or | ||
| uncertainScope(this) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -353,6 +361,27 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location> | |
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `name`, when resolved from `lookup`, may resolve to one of the uncertain members of `scope`. | ||
| */ | ||
| pragma[nomagic] | ||
| private predicate lookupInUncertainScope(string name, Scope lookup, Scope scope) { | ||
| lookupInScope(name, lookup, scope) and | ||
| uncertainScope(scope) and | ||
| not declInScope(_, name, scope) and | ||
| not implicitDeclInScope(name, scope) | ||
| } | ||
|
|
||
| /** | ||
| * Gets an uncertain scope that the given `accessCand` pair may resolve to. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| */ | ||
| AstNode getAnUncertainScope(AstNode access, string name) { | ||
| exists(Scope lookup | | ||
| accessCandInLookupScope(access, name, lookup) and | ||
| lookupInUncertainScope(name, lookup, result) | ||
| ) | ||
| } | ||
|
|
||
| cached | ||
| private newtype TLocal = | ||
| TExplicitLocal(AstNode definingNode, string name, AstNode scope) { | ||
|
|
||
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
Large diffs are not rendered by default.
Oops, something went wrong.
236 changes: 236 additions & 0 deletions
236
unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| switch event { | ||
| case let .received(.some(value), timestamp): | ||
| print(value, timestamp) | ||
| case Type.some(let value): | ||
| print(value) | ||
| default: | ||
| break | ||
| } | ||
|
|
||
| --- | ||
|
|
||
| sourceFile | ||
| endOfFileToken: endOfFile | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| expressionStmt | ||
| expression: | ||
| switchExpr | ||
| leftBrace: { | ||
| rightBrace: } | ||
| cases: | ||
| switchCase | ||
| label: | ||
| switchCaseLabel | ||
| colon: : | ||
| caseKeyword: case | ||
| caseItems: | ||
| switchCaseItem | ||
| pattern: | ||
| valueBindingPattern | ||
| pattern: | ||
| expressionPattern | ||
| expression: | ||
| functionCallExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| functionCallExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| patternExpr | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "value" | ||
| additionalTrailingClosures: | ||
| calledExpression: | ||
| memberAccessExpr | ||
| period: . | ||
| declName: | ||
| declReferenceExpr | ||
| baseName: identifier "some" | ||
| trailingComma: , | ||
| labeledExpr | ||
| expression: | ||
| patternExpr | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "timestamp" | ||
| additionalTrailingClosures: | ||
| calledExpression: | ||
| memberAccessExpr | ||
| period: . | ||
| declName: | ||
| declReferenceExpr | ||
| baseName: identifier "received" | ||
| bindingSpecifier: let | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| functionCallExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| trailingComma: , | ||
| labeledExpr | ||
| expression: | ||
| declReferenceExpr | ||
| baseName: identifier "timestamp" | ||
| additionalTrailingClosures: | ||
| calledExpression: | ||
| declReferenceExpr | ||
| baseName: identifier "print" | ||
| switchCase | ||
| label: | ||
| switchCaseLabel | ||
| colon: : | ||
| caseKeyword: case | ||
| caseItems: | ||
| switchCaseItem | ||
| pattern: | ||
| expressionPattern | ||
| expression: | ||
| functionCallExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| patternExpr | ||
| pattern: | ||
| valueBindingPattern | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "value" | ||
| bindingSpecifier: let | ||
| additionalTrailingClosures: | ||
| calledExpression: | ||
| memberAccessExpr | ||
| period: . | ||
| declName: | ||
| declReferenceExpr | ||
| baseName: identifier "some" | ||
| base: | ||
| declReferenceExpr | ||
| baseName: identifier "Type" | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| functionCallExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| additionalTrailingClosures: | ||
| calledExpression: | ||
| declReferenceExpr | ||
| baseName: identifier "print" | ||
| switchCase | ||
| label: | ||
| switchDefaultLabel | ||
| colon: : | ||
| defaultKeyword: default | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| breakStmt | ||
| breakKeyword: break | ||
| subject: | ||
| declReferenceExpr | ||
| baseName: identifier "event" | ||
| switchKeyword: switch | ||
|
|
||
| --- | ||
|
|
||
| top_level | ||
| body: | ||
| block | ||
| stmt: | ||
| switch_expr | ||
| value: | ||
| name_expr | ||
| identifier: identifier "event" | ||
| case: | ||
| switch_case | ||
| pattern: | ||
| constructor_pattern | ||
| constructor: | ||
| member_access_expr | ||
| base: inferred_type_expr "." | ||
| member: identifier "received" | ||
| element: | ||
| pattern_element | ||
| pattern: | ||
| constructor_pattern | ||
| constructor: | ||
| member_access_expr | ||
| base: inferred_type_expr "." | ||
| member: identifier "some" | ||
| element: | ||
| pattern_element | ||
| pattern: | ||
| name_pattern | ||
| identifier: identifier "value" | ||
| pattern_element | ||
| pattern: | ||
| name_pattern | ||
| identifier: identifier "timestamp" | ||
| body: | ||
| block | ||
| stmt: | ||
| call_expr | ||
| callee: | ||
| name_expr | ||
| identifier: identifier "print" | ||
| argument: | ||
| argument | ||
| value: | ||
| name_expr | ||
| identifier: identifier "value" | ||
| argument | ||
| value: | ||
| name_expr | ||
| identifier: identifier "timestamp" | ||
| switch_case | ||
| pattern: | ||
| constructor_pattern | ||
| constructor: | ||
| member_access_expr | ||
| base: | ||
| name_expr | ||
| identifier: identifier "Type" | ||
| member: identifier "some" | ||
| element: | ||
| pattern_element | ||
| pattern: | ||
| name_pattern | ||
| identifier: identifier "value" | ||
| body: | ||
| block | ||
| stmt: | ||
| call_expr | ||
| callee: | ||
| name_expr | ||
| identifier: identifier "print" | ||
| argument: | ||
| argument | ||
| value: | ||
| name_expr | ||
| identifier: identifier "value" | ||
| switch_case | ||
| body: | ||
| block | ||
| stmt: break_expr "break" |
8 changes: 8 additions & 0 deletions
8
unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| switch event { | ||
| case let .received(.some(value), timestamp): | ||
| print(value, timestamp) | ||
| case Type.some(let value): | ||
| print(value) | ||
| default: | ||
| break | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps define
and use that here and inside
lookupInScope.