Skip to content

Commit 920669d

Browse files
committed
[Concurrency] Extract the check for async context to the namespace
It's useful not only inside of isolation checking but in the type-checker as well.
1 parent 0b4ec1c commit 920669d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,20 +1796,7 @@ namespace {
17961796
}
17971797

17981798
bool isInAsynchronousContext() const {
1799-
auto dc = getDeclContext();
1800-
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
1801-
return func->isAsyncContext();
1802-
}
1803-
1804-
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
1805-
if (auto type = closure->getType()) {
1806-
if (auto fnType = type->getAs<AnyFunctionType>()) {
1807-
return fnType->isAsync();
1808-
}
1809-
}
1810-
}
1811-
1812-
return false;
1799+
return isAsynchronousContext(getDeclContext());
18131800
}
18141801

18151802
enum class AsyncMarkingResult {
@@ -4282,3 +4269,19 @@ AnyFunctionType *swift::adjustFunctionTypeForConcurrency(
42824269
bool swift::completionContextUsesConcurrencyFeatures(const DeclContext *dc) {
42834270
return contextUsesConcurrencyFeatures(dc);
42844271
}
4272+
4273+
bool swift::isAsynchronousContext(const DeclContext *dc) {
4274+
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
4275+
return func->isAsyncContext();
4276+
}
4277+
4278+
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
4279+
if (auto type = closure->getType()) {
4280+
if (auto fnType = type->getAs<AnyFunctionType>()) {
4281+
return fnType->isAsync();
4282+
}
4283+
}
4284+
}
4285+
4286+
return false;
4287+
}

lib/Sema/TypeCheckConcurrency.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ bool isDispatchQueueOperationName(StringRef name);
328328
/// \returns true if an error occurred.
329329
bool checkSendableConformance(
330330
ProtocolConformance *conformance, SendableCheck check);
331+
332+
/// Check whether the given declaration context is asynchronous e.g.
333+
/// function or a closure declaration marked as `async`.
334+
bool isAsynchronousContext(const DeclContext *dc);
335+
331336
} // end namespace swift
332337

333338
#endif /* SWIFT_SEMA_TYPECHECKCONCURRENCY_H */

0 commit comments

Comments
 (0)