Skip to content

[Refactoring] Use known alternative in async refactoring if one exists #38689

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

Merged
merged 2 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6220,7 +6220,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
/// handler if \p asyncAlternative is not set (with the same conditions on
/// its type as above).
Optional<unsigned> findPotentialCompletionHandlerParam(
AbstractFunctionDecl *asyncAlternative = nullptr) const;
const AbstractFunctionDecl *asyncAlternative = nullptr) const;

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

/// A representation of the name to be displayed to users. \c getNameStr
/// for anything other than a getter or setter.
void printUserFacingName(llvm::raw_ostream &out) const;

static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Accessor;
}
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ NOTE(decl_declared_here,none,
"%0 declared here", (DeclName))
NOTE(kind_declared_here,none,
"%0 declared here", (DescriptiveDeclKind))
NOTE(descriptive_decl_declared_here,none,
"'%0' declared here", (StringRef))
NOTE(implicit_member_declared_here,none,
"%1 '%0' is implicitly declared", (StringRef, StringRef))
NOTE(extended_type_declared_here,none,
Expand Down
15 changes: 4 additions & 11 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,17 +886,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
} else if (Attr->RenameDecl) {
Printer << ", renamed: \"";
if (auto *Accessor = dyn_cast<AccessorDecl>(Attr->RenameDecl)) {
switch (Accessor->getAccessorKind()) {
case AccessorKind::Get:
Printer << "getter:";
break;
case AccessorKind::Set:
Printer << "setter:";
break;
default:
break;
}
Printer << Accessor->getStorage()->getName() << "()";
SmallString<32> Name;
llvm::raw_svector_ostream OS(Name);
Accessor->printUserFacingName(OS);
Printer << Name.str();
} else {
Printer << Attr->RenameDecl->getName();
}
Expand Down
26 changes: 24 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7120,7 +7120,7 @@ static bool isPotentialCompletionHandler(const ParamDecl *param) {
}

Optional<unsigned> AbstractFunctionDecl::findPotentialCompletionHandlerParam(
AbstractFunctionDecl *asyncAlternative) const {
const AbstractFunctionDecl *asyncAlternative) const {
const ParameterList *params = getParameters();
if (params->size() == 0)
return None;
Expand Down Expand Up @@ -7203,7 +7203,7 @@ Optional<unsigned> AbstractFunctionDecl::findPotentialCompletionHandlerParam(

// The next original param should match the current async, so don't
// increment the async index
potentialParam = asyncParamIndex;
potentialParam = paramIndex;
paramIndex++;
}
return potentialParam;
Expand Down Expand Up @@ -7910,6 +7910,28 @@ bool AccessorDecl::isSimpleDidSet() const {
SimpleDidSetRequest{mutableThis}, false);
}

void AccessorDecl::printUserFacingName(raw_ostream &out) const {
switch (getAccessorKind()) {
case AccessorKind::Get:
out << "getter:";
break;
case AccessorKind::Set:
out << "setter:";
break;
default:
out << getName();
return;
}

out << getStorage()->getName() << "(";
if (this->isSetter()) {
for (const auto *param : *getParameters()) {
out << param->getName() << ":";
}
}
out << ")";
}

StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
assert(getDeclContext()->isTypeContext());
if (!isStatic())
Expand Down
Loading