-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove ASTScope starting DeclContext hack #33976
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
Changes from all commits
0ddd093
df1b631
cfffb40
09bb3c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1946,7 +1946,33 @@ static DirectlyReferencedTypeDecls | |
directReferencesForUnqualifiedTypeLookup(DeclNameRef name, | ||
SourceLoc loc, DeclContext *dc, | ||
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. Seems a bit odd that we still pass in a DC here, esp. since passing in both a location and a DC. 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. I'm going to do a separate PR that redoes the user-facing unqualified lookup entry point to take a SourceFile instead of a DC. The first step was making sure the DC wasn't actually used internally :) 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. Sounds good! |
||
LookupOuterResults lookupOuter) { | ||
// In a protocol or protocol extension, the 'where' clause can refer to | ||
// associated types without 'Self' qualification: | ||
// | ||
// protocol MyProto where AssocType : Q { ... } | ||
// | ||
// extension MyProto where AssocType == Int { ... } | ||
// | ||
// For this reason, ASTScope maps source locations inside the 'where' | ||
// clause to a scope that performs the lookup into the protocol or | ||
// protocol extension. | ||
// | ||
// However, protocol and protocol extensions can also put bounds on 'Self', | ||
// for example: | ||
// | ||
// protocol MyProto where Self : MyClass { ... } | ||
// | ||
// We must start searching for 'MyClass' at the top level, otherwise | ||
// we end up with a cycle, because qualified lookup wants to resolve | ||
// 'Self' bounds to build the set of declarations to search inside of. | ||
// | ||
// To make this work, we handle the top-level lookup case explicitly | ||
// here, bypassing unqualified lookup and ASTScope altogether. | ||
if (dc->isModuleScopeContext()) | ||
loc = SourceLoc(); | ||
|
||
Comment on lines
+1949
to
+1973
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. nice! |
||
DirectlyReferencedTypeDecls results; | ||
|
||
UnqualifiedLookupOptions options = | ||
UnqualifiedLookupFlags::TypeLookup | | ||
UnqualifiedLookupFlags::AllowProtocolMembers; | ||
|
@@ -1958,8 +1984,8 @@ directReferencesForUnqualifiedTypeLookup(DeclNameRef name, | |
auto lookup = evaluateOrDefault(ctx.evaluator, | ||
UnqualifiedLookupRequest{descriptor}, {}); | ||
for (const auto &result : lookup.allResults()) { | ||
if (auto typeDecl = dyn_cast<TypeDecl>(result.getValueDecl())) | ||
results.push_back(typeDecl); | ||
auto typeDecl = cast<TypeDecl>(result.getValueDecl()); | ||
results.push_back(typeDecl); | ||
Comment on lines
+1987
to
+1988
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. Interesting! I'd like to understand this change. Was the old check not needed? 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. Name lookup only returns TypeDecls if the TypesOnly flag is set, and we already rely on that being the case in other places in the compiler. 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. Thanks. |
||
} | ||
|
||
return results; | ||
|
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 a bit surprised you can do away with this.