diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 0154fcebf90..f8f90c2e523 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -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(decl)) { + if (Type type = value->getInterfaceType()) { + bool hasAsync = type.findIf([](Type type) { + if (auto fnType = type->getAs()) { + 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(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 getFeaturesUsed(Decl *decl) { std::vector 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) \ diff --git a/test/ModuleInterface/features.swift b/test/ModuleInterface/features.swift index caeabc17e12..2a293873d47 100644 --- a/test/ModuleInterface/features.swift +++ b/test/ModuleInterface/features.swift @@ -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