-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SwiftLexicalLookup] New unqualified lookup implementation validation #77140
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
[SwiftLexicalLookup] New unqualified lookup implementation validation #77140
Conversation
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.
I'm really excited about SwiftLexicalLookup, I just have some minor nitpicks
include/swift/AST/ASTBridging.h
Outdated
BridgedConsumedLookupResult(swift::Identifier name, | ||
swift::SourceLoc sourceLoc, | ||
SwiftInt flag | ||
) : Name(BridgedIdentifier(name)), |
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.
Nit: we typically put the ) on the same line and : on the following. @gottesmm can also help you set up clang-format if you'd rather fix stylistic issues automatically
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.
Thank you for pointing this out! I manually run clang-format now for this part of the file. Is there maybe a way to automate this process and run with every commit or just run it on my changes?
lib/AST/ASTScope.cpp
Outdated
if (auto *extDecl = dyn_cast<ExtensionDecl>(scopeDC)) { | ||
recordedElements.push_back(BridgedConsumedLookupResult( | ||
Identifier(), extDecl->getExtendedTypeRepr()->getLoc(), | ||
0b10 + result)); |
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 the magic constant should be named, or you could use a bitfield or something
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.
This is a good idea. I documented those on the Swift side, but forgot about explaining them here. I moved 0b10
to a constant shouldLookInMembers
and also renamed result
to endOfLookup
.
} else if parent.is(FunctionDeclSyntax.self) || parent.is(SubscriptDeclSyntax.self) | ||
|| result.scope.range.contains(lookupToken.position) | ||
{ | ||
// If a result from function generic parameter clause or lookup started within it, reverse introduced names. |
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.
I guess the old code has some funky behaviors :)
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.
Yes, we've encountered some really fun behavior of ASTScope
when working on the library.
This particular case happens when looking up generic parameter from generic parameter clause which is part of a function or subscript or the lookup is started within the clause:
func foo<A, B: Int>(a: A, b: B) {
print(a, b)
}
ASTScope
for some reason decides to first introduce generic parameters in wrong order just to introduce them correctly right afterwards :). Interestingly, similar behavior doesn't happen inside nominal type declarations.
-----> Lookup started at: 2:3 ("print") finishInSequentialScope: false
| ASTScope | SwiftLexicalLookup
> ✅ | a 1:21 | a 1:21
> ✅ | b 1:27 | b 1:27
> ✅ | B 1:13 | ↕️ B 1:13
> ✅ | A 1:10 | ↕️ A 1:10
> ℹ️ | Omitted ASTScope name: A 1:10
> ℹ️ | Omitted ASTScope name: B 1:13
With those comments, this validation function slowly becomes a documentation of "weird" ASTScope
behavior. It might be necessary to revisit some of those heuristics in the future if it turns out there's a valid reason for this behavior and we should actually adjust SwiftLexicalLookup
. That's why I tried to be more explicit in this part of the validation algorithm.
… in `LoggingASTScopeDeclConsumer`. Format `BridgedConsumedLookupResult`.
@swift-ci please build toolchain |
@swift-ci please smoke test |
@swift-ci please build toolchain |
@swift-ci Please test |
@swift-ci Please smoke test |
…MAJKFL/swift into swift-lexical-lookup-validation
…ty with ARM windows.
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
@swift-ci Please smoke test |
@swift-ci please test Windows |
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.
This is excellent. I have one request, though: can you add a test that demonstrates that this experimental mode is working? It doesn't have to be comprehensive, but it should have some nontrivial Swift code in it and use %target-typecheck-verify-swift -enable-experimental-feature UnqualifiedLookupValidation
. That will make sure this functionality doesn't regress based on other changes to the compiler code base.
Over time, we can add this experimental feature to more places to improve our testing coverage.
…guredRegions` to unqualified lookup validation.
…MAJKFL/swift into swift-lexical-lookup-validation
@swift-ci Please smoke test |
…okup validation test.
@swift-ci Please smoke test |
…ftlexicalLookup` test.
@swift-ci Please smoke test |
This PR introduces a function used to validate output of
SwiftLexicalLookup
lookup againstASTScope
unqualified lookup. It’s part of the GSoC project I worked on with @DougGregor. The goal is to be able to automatically compare outputs of the two implementations, run it for large amounts of source files and fix any discrepancies to bring the new implementation closer to the current one. To perform validation, use-enable-experimental-feature UnqualifiedLookupValidation
.Example output of a failed validation for a file from the Swift standard library:
This PR depends on PR 2883 in
swift-syntax
that brings#if
handling throughSwiftIfConfig
toSwiftLexicalLookup
.