Use presence of 'await' to make top-level async

To help maintain source-compatibility, the presence of an `await` in
top-level code to kick the top-level code over to being a concurrent
context.

This, of course, means that in the test cases that exist today, they
will go back to behaving identically to how they did before I added all
of this because they don't have any awaits in the top-level. I'll be
adding new tests to verify the differences in behavior between swift 5,
swift 6, with and without async top level enabled in the next commit.
This commit is contained in:
Evan Wilde
2022-01-27 16:10:01 -08:00
parent 4b182f6a61
commit 3b90b08582
7 changed files with 52 additions and 21 deletions

View File

@@ -3038,6 +3038,24 @@ SourceFile::lookupOpaqueResultType(StringRef MangledName) {
return nullptr;
}
bool SourceFile::isAsyncTopLevelSourceFile() const {
return isScriptMode() &&
(bool)evaluateOrDefault(getASTContext().evaluator,
GetSourceFileAsyncNode{this}, ASTNode());
}
ASTNode GetSourceFileAsyncNode::evaluate(Evaluator &eval,
const SourceFile *sf) const {
for (Decl *d : sf->getTopLevelDecls()) {
TopLevelCodeDecl *tld = dyn_cast<TopLevelCodeDecl>(d);
if (tld && tld->getBody()) {
if (ASTNode asyncNode = tld->getBody()->findAsyncNode())
return asyncNode;
}
}
return ASTNode();
}
//===----------------------------------------------------------------------===//
// SynthesizedFileUnit Implementation
//===----------------------------------------------------------------------===//