Skip to content

Commit

Permalink
[Concurrency] Clean up inference logic for @asyncHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
DougGregor committed Oct 14, 2020
1 parent 3a651a6 commit 21a0696
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/Sema/TypeCheckConcurrency.cpp
Expand Up @@ -25,6 +25,24 @@

using namespace swift;

/// Determine whether it makes sense to infer an attribute in the given
/// context.
static bool shouldInferAttributeInContext(const DeclContext *dc) {
auto sourceFile = dc->getParentSourceFile();
if (!sourceFile)
return false;

switch (sourceFile->Kind) {
case SourceFileKind::Interface:
case SourceFileKind::SIL:
return false;

case SourceFileKind::Library:
case SourceFileKind::Main:
return true;
}
}

/// Check whether the @asyncHandler attribute can be applied to the given
/// function declaration.
///
Expand Down Expand Up @@ -108,7 +126,7 @@ bool IsAsyncHandlerRequest::evaluate(
return true;
}

if (!func->getASTContext().LangOpts.EnableExperimentalConcurrency)
if (!shouldInferAttributeInContext(func->getDeclContext()))
return false;

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

// Disable inference of actor attributes outside of normal Swift source files.
if (auto sourceFile = value->getDeclContext()->getParentSourceFile()) {
switch (sourceFile->Kind) {
case SourceFileKind::Interface:
case SourceFileKind::SIL:
return defaultIsolation;

case SourceFileKind::Library:
case SourceFileKind::Main:
// Attempt inference below.
break;
}
} else {
if (!shouldInferAttributeInContext(value->getDeclContext()))
return defaultIsolation;
}

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

0 comments on commit 21a0696

Please sign in to comment.