mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user