Skip to content

Commit 21a0696

Browse files
committed
[Concurrency] Clean up inference logic for @asyncHandler.
1 parent 3a651a6 commit 21a0696

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@
2525

2626
using namespace swift;
2727

28+
/// Determine whether it makes sense to infer an attribute in the given
29+
/// context.
30+
static bool shouldInferAttributeInContext(const DeclContext *dc) {
31+
auto sourceFile = dc->getParentSourceFile();
32+
if (!sourceFile)
33+
return false;
34+
35+
switch (sourceFile->Kind) {
36+
case SourceFileKind::Interface:
37+
case SourceFileKind::SIL:
38+
return false;
39+
40+
case SourceFileKind::Library:
41+
case SourceFileKind::Main:
42+
return true;
43+
}
44+
}
45+
2846
/// Check whether the @asyncHandler attribute can be applied to the given
2947
/// function declaration.
3048
///
@@ -108,7 +126,7 @@ bool IsAsyncHandlerRequest::evaluate(
108126
return true;
109127
}
110128

111-
if (!func->getASTContext().LangOpts.EnableExperimentalConcurrency)
129+
if (!shouldInferAttributeInContext(func->getDeclContext()))
112130
return false;
113131

114132
// Are we in a context where inference is possible?
@@ -1135,20 +1153,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
11351153
}
11361154

11371155
// Disable inference of actor attributes outside of normal Swift source files.
1138-
if (auto sourceFile = value->getDeclContext()->getParentSourceFile()) {
1139-
switch (sourceFile->Kind) {
1140-
case SourceFileKind::Interface:
1141-
case SourceFileKind::SIL:
1142-
return defaultIsolation;
1143-
1144-
case SourceFileKind::Library:
1145-
case SourceFileKind::Main:
1146-
// Attempt inference below.
1147-
break;
1148-
}
1149-
} else {
1156+
if (!shouldInferAttributeInContext(value->getDeclContext()))
11501157
return defaultIsolation;
1151-
}
11521158

11531159
// Function used when returning an inferred isolation.
11541160
auto inferredIsolation = [&](ActorIsolation inferred) {

0 commit comments

Comments
 (0)