Peer into the types of declarations to find async/actors/etc.

This commit is contained in:
Doug Gregor
2021-02-08 22:50:48 -08:00
parent 627e4f03a3
commit 643ce71a09
2 changed files with 44 additions and 5 deletions

View File

@@ -2405,6 +2405,23 @@ static bool usesFeatureAsyncAwait(Decl *decl) {
return true;
}
// Check for async functions in the types of declarations.
if (auto value = dyn_cast<ValueDecl>(decl)) {
if (Type type = value->getInterfaceType()) {
bool hasAsync = type.findIf([](Type type) {
if (auto fnType = type->getAs<AnyFunctionType>()) {
if (fnType->isAsync())
return true;
}
return false;
});
if (hasAsync)
return true;
}
}
return false;
}
@@ -2472,6 +2489,23 @@ static bool usesFeatureActors(Decl *decl) {
return true;
}
// Check for actors in the types of declarations.
if (auto value = dyn_cast<ValueDecl>(decl)) {
if (Type type = value->getInterfaceType()) {
bool hasActor = type.findIf([](Type type) {
if (auto classDecl = type->getClassOrBoundGenericClass()) {
if (classDecl->isActor())
return true;
}
return false;
});
if (hasActor)
return true;
}
}
return false;
}
@@ -2482,11 +2516,6 @@ static bool usesFeatureActors(Decl *decl) {
static std::vector<Feature> getFeaturesUsed(Decl *decl) {
std::vector<Feature> features;
// Only type- and module-scope declarations have any features to speak of.
auto dc = decl->getDeclContext();
if (!dc->isTypeContext() && !dc->isModuleScopeContext())
return features;
// Go through each of the features, checking whether the declaration uses that
// feature. This also ensures that the resulting set is in sorted order.
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \

View File

@@ -63,6 +63,16 @@ extension OldSchool: UnsafeConcurrentValue { }
// CHECK-NEXT: }
// CHECK-NEXT: #endif
// CHECK: #if compiler(>=5.3) && $AsyncAwait
// CHECK-NEXT: func runSomethingSomewhere
// CHECK-NEXT: #endif
public func runSomethingSomewhere(body: () async -> Void) { }
// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: func stage
// CHECK-NEXT: #endif
public func stage(with actor: MyActor) { }
// CHECK: #if compiler(>=5.3) && $MarkerProtocol
// CHECK-NEXT: extension FeatureTest.MyActor : Swift.ConcurrentValue {}
// CHECK-NEXT: #endif