Skip to content

Commit 9216af8

Browse files
committed
Sema: Set ApplyExpr::isNoAsync() for 'reasync' function calls that are known not to 'await'
1 parent 375d246 commit 9216af8

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

include/swift/AST/Expr.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,11 @@ class alignas(8) Expr {
335335
NumCaptures : 32
336336
);
337337

338-
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1+1,
338+
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1+1+1,
339339
ThrowsIsSet : 1,
340340
Throws : 1,
341-
ImplicitlyAsync : 1
341+
ImplicitlyAsync : 1,
342+
NoAsync : 1
342343
);
343344

344345
SWIFT_INLINE_BITFIELD_FULL(CallExpr, ApplyExpr, 1+1+16,
@@ -4359,6 +4360,7 @@ class ApplyExpr : public Expr {
43594360
assert(validateArg(Arg) && "Arg is not a permitted expr kind");
43604361
Bits.ApplyExpr.ThrowsIsSet = false;
43614362
Bits.ApplyExpr.ImplicitlyAsync = false;
4363+
Bits.ApplyExpr.NoAsync = false;
43624364
}
43634365

43644366
public:
@@ -4397,6 +4399,15 @@ class ApplyExpr : public Expr {
43974399
Bits.ApplyExpr.Throws = throws;
43984400
}
43994401

4402+
/// Is this a 'rethrows' function that is known not to throw?
4403+
bool isNoThrows() const { return !throws(); }
4404+
4405+
/// Is this a 'reasync' function that is known not to 'await'?
4406+
bool isNoAsync() const { return Bits.ApplyExpr.NoAsync; }
4407+
void setNoAsync(bool noAsync) {
4408+
Bits.ApplyExpr.NoAsync = noAsync;
4409+
}
4410+
44004411
/// Is this application _implicitly_ required to be an async call?
44014412
/// Note that this is _not_ a check for whether the callee is async!
44024413
/// Only meaningful after complete type-checking.

lib/Sema/TypeCheckEffects.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,12 +2266,17 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
22662266

22672267
checkThrowAsyncSite(E, /*requiresTry*/ true, classification);
22682268

2269-
// HACK: functions can get queued multiple times in
2270-
// definedFunctions, so be sure to be idempotent.
2271-
if (!E->isThrowsSet() && !classification.isInvalid()) {
2272-
auto throwsKind = classification.getConditionalKind(EffectKind::Throws);
2273-
E->setThrows(throwsKind == ConditionalEffectKind::Conditional ||
2274-
throwsKind == ConditionalEffectKind::Always);
2269+
if (!classification.isInvalid()) {
2270+
// HACK: functions can get queued multiple times in
2271+
// definedFunctions, so be sure to be idempotent.
2272+
if (!E->isThrowsSet()) {
2273+
auto throwsKind = classification.getConditionalKind(EffectKind::Throws);
2274+
E->setThrows(throwsKind == ConditionalEffectKind::Conditional ||
2275+
throwsKind == ConditionalEffectKind::Always);
2276+
}
2277+
2278+
auto asyncKind = classification.getConditionalKind(EffectKind::Async);
2279+
E->setNoAsync(asyncKind == ConditionalEffectKind::None);
22752280
}
22762281

22772282
// If current apply expression did not type-check, don't attempt

0 commit comments

Comments
 (0)