Skip to content

Commit 7fb85c3

Browse files
authored
Merge pull request swiftlang#38689 from apple/use-known-alternative
[Refactoring] Use known alternative in async refactoring if one exists
2 parents f42bde3 + f6a8dab commit 7fb85c3

File tree

12 files changed

+654
-186
lines changed

12 files changed

+654
-186
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6220,7 +6220,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
62206220
/// handler if \p asyncAlternative is not set (with the same conditions on
62216221
/// its type as above).
62226222
Optional<unsigned> findPotentialCompletionHandlerParam(
6223-
AbstractFunctionDecl *asyncAlternative = nullptr) const;
6223+
const AbstractFunctionDecl *asyncAlternative = nullptr) const;
62246224

62256225
/// Determine whether this function is implicitly known to have its
62266226
/// parameters of function type be @_unsafeSendable.
@@ -6599,6 +6599,10 @@ class AccessorDecl final : public FuncDecl {
65996599
Bits.AccessorDecl.IsTransparentComputed = 1;
66006600
}
66016601

6602+
/// A representation of the name to be displayed to users. \c getNameStr
6603+
/// for anything other than a getter or setter.
6604+
void printUserFacingName(llvm::raw_ostream &out) const;
6605+
66026606
static bool classof(const Decl *D) {
66036607
return D->getKind() == DeclKind::Accessor;
66046608
}

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ NOTE(decl_declared_here,none,
3030
"%0 declared here", (DeclName))
3131
NOTE(kind_declared_here,none,
3232
"%0 declared here", (DescriptiveDeclKind))
33+
NOTE(descriptive_decl_declared_here,none,
34+
"'%0' declared here", (StringRef))
3335
NOTE(implicit_member_declared_here,none,
3436
"%1 '%0' is implicitly declared", (StringRef, StringRef))
3537
NOTE(extended_type_declared_here,none,

lib/AST/Attr.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -886,17 +886,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
886886
} else if (Attr->RenameDecl) {
887887
Printer << ", renamed: \"";
888888
if (auto *Accessor = dyn_cast<AccessorDecl>(Attr->RenameDecl)) {
889-
switch (Accessor->getAccessorKind()) {
890-
case AccessorKind::Get:
891-
Printer << "getter:";
892-
break;
893-
case AccessorKind::Set:
894-
Printer << "setter:";
895-
break;
896-
default:
897-
break;
898-
}
899-
Printer << Accessor->getStorage()->getName() << "()";
889+
SmallString<32> Name;
890+
llvm::raw_svector_ostream OS(Name);
891+
Accessor->printUserFacingName(OS);
892+
Printer << Name.str();
900893
} else {
901894
Printer << Attr->RenameDecl->getName();
902895
}

lib/AST/Decl.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7120,7 +7120,7 @@ static bool isPotentialCompletionHandler(const ParamDecl *param) {
71207120
}
71217121

71227122
Optional<unsigned> AbstractFunctionDecl::findPotentialCompletionHandlerParam(
7123-
AbstractFunctionDecl *asyncAlternative) const {
7123+
const AbstractFunctionDecl *asyncAlternative) const {
71247124
const ParameterList *params = getParameters();
71257125
if (params->size() == 0)
71267126
return None;
@@ -7203,7 +7203,7 @@ Optional<unsigned> AbstractFunctionDecl::findPotentialCompletionHandlerParam(
72037203

72047204
// The next original param should match the current async, so don't
72057205
// increment the async index
7206-
potentialParam = asyncParamIndex;
7206+
potentialParam = paramIndex;
72077207
paramIndex++;
72087208
}
72097209
return potentialParam;
@@ -7910,6 +7910,28 @@ bool AccessorDecl::isSimpleDidSet() const {
79107910
SimpleDidSetRequest{mutableThis}, false);
79117911
}
79127912

7913+
void AccessorDecl::printUserFacingName(raw_ostream &out) const {
7914+
switch (getAccessorKind()) {
7915+
case AccessorKind::Get:
7916+
out << "getter:";
7917+
break;
7918+
case AccessorKind::Set:
7919+
out << "setter:";
7920+
break;
7921+
default:
7922+
out << getName();
7923+
return;
7924+
}
7925+
7926+
out << getStorage()->getName() << "(";
7927+
if (this->isSetter()) {
7928+
for (const auto *param : *getParameters()) {
7929+
out << param->getName() << ":";
7930+
}
7931+
}
7932+
out << ")";
7933+
}
7934+
79137935
StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
79147936
assert(getDeclContext()->isTypeContext());
79157937
if (!isStatic())

0 commit comments

Comments
 (0)