|
25 | 25 |
|
26 | 26 | using namespace swift;
|
27 | 27 |
|
| 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 | + |
28 | 46 | /// Check whether the @asyncHandler attribute can be applied to the given
|
29 | 47 | /// function declaration.
|
30 | 48 | ///
|
@@ -108,7 +126,7 @@ bool IsAsyncHandlerRequest::evaluate(
|
108 | 126 | return true;
|
109 | 127 | }
|
110 | 128 |
|
111 |
| - if (!func->getASTContext().LangOpts.EnableExperimentalConcurrency) |
| 129 | + if (!shouldInferAttributeInContext(func->getDeclContext())) |
112 | 130 | return false;
|
113 | 131 |
|
114 | 132 | // Are we in a context where inference is possible?
|
@@ -1135,20 +1153,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
|
1135 | 1153 | }
|
1136 | 1154 |
|
1137 | 1155 | // 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())) |
1150 | 1157 | return defaultIsolation;
|
1151 |
| - } |
1152 | 1158 |
|
1153 | 1159 | // Function used when returning an inferred isolation.
|
1154 | 1160 | auto inferredIsolation = [&](ActorIsolation inferred) {
|
|
0 commit comments