Skip to content

Commit 146f19c

Browse files
committed
infrastructure to record whether an ApplyExpr is implicitly async
1 parent e066d43 commit 146f19c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

include/swift/AST/Expr.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ class alignas(8) Expr {
334334
NumCaptures : 32
335335
);
336336

337-
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1,
337+
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1+1,
338338
ThrowsIsSet : 1,
339-
Throws : 1
339+
Throws : 1,
340+
ImplicitlyAsync : 1
340341
);
341342

342343
SWIFT_INLINE_BITFIELD_FULL(CallExpr, ApplyExpr, 1+1+16,
@@ -4308,6 +4309,7 @@ class ApplyExpr : public Expr {
43084309
assert(classof((Expr*)this) && "ApplyExpr::classof out of date");
43094310
assert(validateArg(Arg) && "Arg is not a permitted expr kind");
43104311
Bits.ApplyExpr.ThrowsIsSet = false;
4312+
Bits.ApplyExpr.ImplicitlyAsync = false;
43114313
}
43124314

43134315
public:
@@ -4346,6 +4348,29 @@ class ApplyExpr : public Expr {
43464348
Bits.ApplyExpr.Throws = throws;
43474349
}
43484350

4351+
/// Is this application _implicitly_ required to be an async call?
4352+
/// Note that this is _not_ a check for whether the callee is async!
4353+
/// Only meaningful after complete type-checking.
4354+
///
4355+
/// Generally, this comes up only when we have a non-self call to an actor
4356+
/// instance's synchronous method. Such calls are conceptually treated as if
4357+
/// they are wrapped with an async closure. For example,
4358+
///
4359+
/// act.syncMethod(a, b)
4360+
///
4361+
/// is equivalent to the eta-expanded version of act.syncMethod,
4362+
///
4363+
/// { (a1, b1) async in act.syncMethod(a1, b1) }(a, b)
4364+
///
4365+
/// where the new closure is declared to be async.
4366+
///
4367+
bool implicitlyAsync() const {
4368+
return Bits.ApplyExpr.ImplicitlyAsync;
4369+
}
4370+
void setImplicitlyAsync(bool flag) {
4371+
Bits.ApplyExpr.ImplicitlyAsync = flag;
4372+
}
4373+
43494374
ValueDecl *getCalledValue() const;
43504375

43514376
/// Retrieve the argument labels provided at the call site.

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class ApplyClassifier {
463463
auto fnType = type->getAs<AnyFunctionType>();
464464
if (!fnType) return Classification::forInvalidCode();
465465

466-
bool isAsync = fnType->isAsync();
466+
bool isAsync = fnType->isAsync() || E->implicitlyAsync();
467467

468468
// If the function doesn't throw at all, we're done here.
469469
if (!fnType->isThrowing())

0 commit comments

Comments
 (0)