-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] Requestify local type declarations #70737
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
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 |
---|---|---|
|
@@ -1444,7 +1444,8 @@ void SourceFile::getPrecedenceGroups( | |
} | ||
|
||
void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const { | ||
Results.append(LocalTypeDecls.begin(), LocalTypeDecls.end()); | ||
auto decls = getLocalTypeDecls(); | ||
Results.append(decls.begin(), decls.end()); | ||
} | ||
|
||
void | ||
|
@@ -1456,7 +1457,7 @@ const { | |
|
||
TypeDecl *SourceFile::lookupLocalType(llvm::StringRef mangledName) const { | ||
ASTContext &ctx = getASTContext(); | ||
for (auto typeDecl : LocalTypeDecls) { | ||
for (auto typeDecl : getLocalTypeDecls()) { | ||
auto typeMangledName = evaluateOrDefault(ctx.evaluator, | ||
MangleLocalTypeDeclRequest { typeDecl }, | ||
std::string()); | ||
|
@@ -4245,6 +4246,50 @@ ASTNode GetSourceFileAsyncNode::evaluate(Evaluator &eval, | |
return ASTNode(); | ||
} | ||
|
||
ArrayRef<TypeDecl *> SourceFile::getLocalTypeDecls() const { | ||
auto *mutableThis = const_cast<SourceFile *>(this); | ||
return evaluateOrDefault(getASTContext().evaluator, | ||
LocalTypeDeclsRequest{mutableThis}, {}); | ||
} | ||
|
||
namespace { | ||
class LocalTypeDeclCollector : public ASTWalker { | ||
SmallVectorImpl<TypeDecl *> &results; | ||
|
||
public: | ||
LocalTypeDeclCollector(SmallVectorImpl<TypeDecl *> &results) | ||
: results(results) {} | ||
|
||
MacroWalking getMacroWalkingBehavior() const override { | ||
return MacroWalking::Expansion; | ||
} | ||
|
||
PreWalkAction walkToDeclPre(Decl *D) override { | ||
switch (D->getKind()) { | ||
case DeclKind::Enum: | ||
case DeclKind::Struct: | ||
case DeclKind::Class: | ||
case DeclKind::Protocol: | ||
case DeclKind::TypeAlias: | ||
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 not really sure we need 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. It seems reasonable to keep type aliases here so that this request returns all local types, even if IRGen and SILGen don't care. Debugging and module emission probably care, for example. |
||
if (D->getDeclContext()->isLocalContext()) | ||
results.push_back(cast<TypeDecl>(D)); | ||
break; | ||
default: | ||
break; | ||
} | ||
return PreWalkAction::Continue; | ||
} | ||
}; | ||
} // namespace | ||
|
||
ArrayRef<TypeDecl *> LocalTypeDeclsRequest::evaluate(Evaluator &evaluator, | ||
SourceFile *sf) const { | ||
SmallVector<TypeDecl *> results; | ||
LocalTypeDeclCollector collector(results); | ||
sf->walk(collector); | ||
return sf->getASTContext().AllocateCopy(results); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SynthesizedFileUnit Implementation | ||
//===----------------------------------------------------------------------===// | ||
|
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 might be missing a reference, but I believe the only two uses of this can just be replaced with
getLocalTypeDecls()
- neither use mutates the vector after retrieving them.Uh oh!
There was an error while loading. Please reload this page.
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.
Module::getLocalTypeDecl()
callsFileUnit::getLocalTypeDecls(SmallVectorImpl<TypeDecl*>)
. SinceSerializedASTFile
doesn't hold them as a list ofTypeDecl *
we can't simply make it returnArrayRef
.