Skip to content

Implementing checking for 'reasync' call sites #36176

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 4 commits into from
Mar 4, 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
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,8 @@ ERROR(rethrows_without_throwing_parameter,none,
ERROR(override_reasync_with_non_reasync,none,
"override of 'reasync' %select{method|initializer}0 should also "
"be 'reasync'", (bool))
ERROR(reasync_without_async_parameter,none,
"'reasync' function must take an 'async' function argument", ())

ERROR(autoclosure_function_type,none,
"@autoclosure attribute only applies to function types",
Expand Down
3 changes: 2 additions & 1 deletion lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ ParserStatus Parser::parseEffectsSpecifiers(SourceLoc existingArrowLoc,

while (true) {
// 'async'
bool isReasync = Tok.isContextualKeyword("reasync");
bool isReasync = (shouldParseExperimentalConcurrency() &&
Tok.isContextualKeyword("reasync"));
if (Tok.isContextualKeyword("async") ||
isReasync) {
if (asyncLoc.isValid()) {
Expand Down
23 changes: 14 additions & 9 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
IGNORED_ATTR(NoDerivative)
IGNORED_ATTR(SpecializeExtension)
IGNORED_ATTR(Concurrent)
IGNORED_ATTR(AtRethrows)
IGNORED_ATTR(AtReasync)
#undef IGNORED_ATTR

void visitAlignmentAttr(AlignmentAttr *attr) {
Expand Down Expand Up @@ -225,7 +227,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
void visitNSCopyingAttr(NSCopyingAttr *attr);
void visitRequiredAttr(RequiredAttr *attr);
void visitRethrowsAttr(RethrowsAttr *attr);
void visitAtRethrowsAttr(AtRethrowsAttr *attr);

void checkApplicationMainAttribute(DeclAttribute *attr,
Identifier Id_ApplicationDelegate,
Expand Down Expand Up @@ -280,7 +281,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
void visitMarkerAttr(MarkerAttr *attr);

void visitReasyncAttr(ReasyncAttr *attr);
void visitAtReasyncAttr(AtReasyncAttr *attr);
};
} // end anonymous namespace

Expand Down Expand Up @@ -2054,8 +2054,8 @@ void AttributeChecker::visitRequiredAttr(RequiredAttr *attr) {
}

void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) {
// 'rethrows' only applies to functions that take throwing functions
// as parameters.
// Make sure the function takes a 'throws' function argument or a
// conformance to a '@rethrows' protocol.
auto fn = dyn_cast<AbstractFunctionDecl>(D);
if (fn->getPolymorphicEffectKind(EffectKind::Throws)
!= PolymorphicEffectKind::Invalid) {
Expand All @@ -2066,8 +2066,6 @@ void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) {
attr->setInvalid();
}

void AttributeChecker::visitAtRethrowsAttr(AtRethrowsAttr *attr) {}

/// Collect all used generic parameter types from a given type.
static void collectUsedGenericParameters(
Type Ty, SmallPtrSetImpl<TypeBase *> &ConstrainedGenericParams) {
Expand Down Expand Up @@ -5489,10 +5487,17 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
}

void AttributeChecker::visitReasyncAttr(ReasyncAttr *attr) {
// FIXME
}
// Make sure the function takes a 'throws' function argument or a
// conformance to a '@rethrows' protocol.
auto fn = dyn_cast<AbstractFunctionDecl>(D);
if (fn->getPolymorphicEffectKind(EffectKind::Async)
!= PolymorphicEffectKind::Invalid) {
return;
}

void AttributeChecker::visitAtReasyncAttr(AtReasyncAttr *attr) {}
diagnose(attr->getLocation(), diag::reasync_without_async_parameter);
attr->setInvalid();
}

namespace {

Expand Down
Loading