Skip to content

Commit 375d246

Browse files
authored
Merge pull request #36176 from slavapestov/reasync-call-site-checking
Implementing checking for 'reasync' call sites
2 parents 23bde5a + 2c19e70 commit 375d246

File tree

6 files changed

+359
-124
lines changed

6 files changed

+359
-124
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,8 @@ ERROR(rethrows_without_throwing_parameter,none,
30243024
ERROR(override_reasync_with_non_reasync,none,
30253025
"override of 'reasync' %select{method|initializer}0 should also "
30263026
"be 'reasync'", (bool))
3027+
ERROR(reasync_without_async_parameter,none,
3028+
"'reasync' function must take an 'async' function argument", ())
30273029

30283030
ERROR(autoclosure_function_type,none,
30293031
"@autoclosure attribute only applies to function types",

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ ParserStatus Parser::parseEffectsSpecifiers(SourceLoc existingArrowLoc,
851851

852852
while (true) {
853853
// 'async'
854-
bool isReasync = Tok.isContextualKeyword("reasync");
854+
bool isReasync = (shouldParseExperimentalConcurrency() &&
855+
Tok.isContextualKeyword("reasync"));
855856
if (Tok.isContextualKeyword("async") ||
856857
isReasync) {
857858
if (asyncLoc.isValid()) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
131131
IGNORED_ATTR(NoDerivative)
132132
IGNORED_ATTR(SpecializeExtension)
133133
IGNORED_ATTR(Concurrent)
134+
IGNORED_ATTR(AtRethrows)
135+
IGNORED_ATTR(AtReasync)
134136
#undef IGNORED_ATTR
135137

136138
void visitAlignmentAttr(AlignmentAttr *attr) {
@@ -225,7 +227,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
225227
void visitNSCopyingAttr(NSCopyingAttr *attr);
226228
void visitRequiredAttr(RequiredAttr *attr);
227229
void visitRethrowsAttr(RethrowsAttr *attr);
228-
void visitAtRethrowsAttr(AtRethrowsAttr *attr);
229230

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

282283
void visitReasyncAttr(ReasyncAttr *attr);
283-
void visitAtReasyncAttr(AtReasyncAttr *attr);
284284
};
285285
} // end anonymous namespace
286286

@@ -2064,8 +2064,8 @@ void AttributeChecker::visitRequiredAttr(RequiredAttr *attr) {
20642064
}
20652065

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

2079-
void AttributeChecker::visitAtRethrowsAttr(AtRethrowsAttr *attr) {}
2080-
20812079
/// Collect all used generic parameter types from a given type.
20822080
static void collectUsedGenericParameters(
20832081
Type Ty, SmallPtrSetImpl<TypeBase *> &ConstrainedGenericParams) {
@@ -5566,10 +5564,17 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
55665564
}
55675565

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

5572-
void AttributeChecker::visitAtReasyncAttr(AtReasyncAttr *attr) {}
5575+
diagnose(attr->getLocation(), diag::reasync_without_async_parameter);
5576+
attr->setInvalid();
5577+
}
55735578

55745579
namespace {
55755580

0 commit comments

Comments
 (0)