Skip to content

Commit 88c0638

Browse files
committed
AST: Introduce a ValueDecl convenience for looking up the renamed decl.
Wrap `RenamedDeclRequest` instead of evaluating it directly.
1 parent 6221b29 commit 88c0638

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,10 @@ class ValueDecl : public Decl {
32623262
/// @_dynamicReplacement(for: ...), compute the original declaration
32633263
/// that this declaration dynamically replaces.
32643264
ValueDecl *getDynamicallyReplacedDecl() const;
3265+
3266+
/// Performs a request to look up the decl that this decl has been renamed to
3267+
/// if `attr` indicates that it has been renamed.
3268+
ValueDecl *getRenamedDecl(const AvailableAttr *attr) const;
32653269
};
32663270

32673271
/// This is a common base class for declarations which declare a type.

lib/AST/Decl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,6 +4231,11 @@ bool ValueDecl::canInferObjCFromRequirement(ValueDecl *requirement) {
42314231
return false;
42324232
}
42334233

4234+
ValueDecl *ValueDecl::getRenamedDecl(const AvailableAttr *attr) const {
4235+
return evaluateOrDefault(getASTContext().evaluator,
4236+
RenamedDeclRequest{this, attr}, nullptr);
4237+
}
4238+
42344239
SourceLoc Decl::getAttributeInsertionLoc(bool forModifier) const {
42354240
// Some decls have a parent/child split where the introducer keyword is on the
42364241
// parent, but the attributes are on the children. If this is a child in such
@@ -9259,8 +9264,7 @@ AbstractFunctionDecl *AbstractFunctionDecl::getAsyncAlternative() const {
92599264
}
92609265
}
92619266

9262-
auto *renamedDecl = evaluateOrDefault(
9263-
getASTContext().evaluator, RenamedDeclRequest{this, avAttr}, nullptr);
9267+
auto *renamedDecl = getRenamedDecl(avAttr);
92649268
auto *alternative = dyn_cast_or_null<AbstractFunctionDecl>(renamedDecl);
92659269
if (!alternative || !alternative->hasAsync())
92669270
return nullptr;

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,7 @@ class DeclAndTypePrinter::Implementation
18351835
const ValueDecl *D, bool includeQuotes) {
18361836
assert(!AvAttr->Rename.empty());
18371837

1838-
auto *renamedDecl = evaluateOrDefault(
1839-
getASTContext().evaluator, RenamedDeclRequest{D, AvAttr}, nullptr);
1838+
auto *renamedDecl = D->getRenamedDecl(AvAttr);
18401839
if (renamedDecl) {
18411840
assert(shouldInclude(renamedDecl) &&
18421841
"ObjC printer logic mismatch with renamed decl");

0 commit comments

Comments
 (0)