[Type Checker] Introduce a request for “overridden declarations”.

Introduce a new request kind to capture the computation of the set of
overridden declarations of a given declaration, eliminating the
stateful “setOverriddenDecls()” calls from the type checker.
This commit is contained in:
Doug Gregor
2018-07-11 07:46:42 -07:00
parent 5815a81922
commit 8f23915334
14 changed files with 208 additions and 183 deletions

View File

@@ -2022,6 +2022,18 @@ CanType ValueDecl::getOverloadSignatureType() const {
return CanType();
}
SmallVector<ValueDecl *, 1> ValueDecl::getOverriddenDecls() const {
ASTContext &ctx = getASTContext();
return ctx.evaluator(OverriddenDeclsRequest{const_cast<ValueDecl *>(this)});
}
void ValueDecl::setOverriddenDecls(ArrayRef<ValueDecl *> overridden) {
SmallVector<ValueDecl *, 1> overriddenVec(overridden.begin(),
overridden.end());
OverriddenDeclsRequest request{const_cast<ValueDecl *>(this)};
request.cacheResult(overriddenVec);
}
bool ValueDecl::isObjC() const {
if (LazySemanticInfo.isObjCComputed)
return LazySemanticInfo.isObjC;
@@ -2866,6 +2878,15 @@ SourceRange AssociatedTypeDecl::getSourceRange() const {
return SourceRange(KeywordLoc, endLoc);
}
SmallVector<AssociatedTypeDecl *, 1>
AssociatedTypeDecl::getOverriddenDecls() const {
SmallVector<AssociatedTypeDecl *, 1> assocTypes;
for (auto decl : AbstractTypeParamDecl::getOverriddenDecls()) {
assocTypes.push_back(cast<AssociatedTypeDecl>(decl));
}
return assocTypes;
}
AssociatedTypeDecl *AssociatedTypeDecl::getAssociatedTypeAnchor() const {
auto overridden = getOverriddenDecls();