Skip to content

Commit 643ce71

Browse files
committed
Peer into the types of declarations to find async/actors/etc.
1 parent 627e4f0 commit 643ce71

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,23 @@ static bool usesFeatureAsyncAwait(Decl *decl) {
24052405
return true;
24062406
}
24072407

2408+
// Check for async functions in the types of declarations.
2409+
if (auto value = dyn_cast<ValueDecl>(decl)) {
2410+
if (Type type = value->getInterfaceType()) {
2411+
bool hasAsync = type.findIf([](Type type) {
2412+
if (auto fnType = type->getAs<AnyFunctionType>()) {
2413+
if (fnType->isAsync())
2414+
return true;
2415+
}
2416+
2417+
return false;
2418+
});
2419+
2420+
if (hasAsync)
2421+
return true;
2422+
}
2423+
}
2424+
24082425
return false;
24092426
}
24102427

@@ -2472,6 +2489,23 @@ static bool usesFeatureActors(Decl *decl) {
24722489
return true;
24732490
}
24742491

2492+
// Check for actors in the types of declarations.
2493+
if (auto value = dyn_cast<ValueDecl>(decl)) {
2494+
if (Type type = value->getInterfaceType()) {
2495+
bool hasActor = type.findIf([](Type type) {
2496+
if (auto classDecl = type->getClassOrBoundGenericClass()) {
2497+
if (classDecl->isActor())
2498+
return true;
2499+
}
2500+
2501+
return false;
2502+
});
2503+
2504+
if (hasActor)
2505+
return true;
2506+
}
2507+
}
2508+
24752509
return false;
24762510
}
24772511

@@ -2482,11 +2516,6 @@ static bool usesFeatureActors(Decl *decl) {
24822516
static std::vector<Feature> getFeaturesUsed(Decl *decl) {
24832517
std::vector<Feature> features;
24842518

2485-
// Only type- and module-scope declarations have any features to speak of.
2486-
auto dc = decl->getDeclContext();
2487-
if (!dc->isTypeContext() && !dc->isModuleScopeContext())
2488-
return features;
2489-
24902519
// Go through each of the features, checking whether the declaration uses that
24912520
// feature. This also ensures that the resulting set is in sorted order.
24922521
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \

test/ModuleInterface/features.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ extension OldSchool: UnsafeConcurrentValue { }
6363
// CHECK-NEXT: }
6464
// CHECK-NEXT: #endif
6565

66+
// CHECK: #if compiler(>=5.3) && $AsyncAwait
67+
// CHECK-NEXT: func runSomethingSomewhere
68+
// CHECK-NEXT: #endif
69+
public func runSomethingSomewhere(body: () async -> Void) { }
70+
71+
// CHECK: #if compiler(>=5.3) && $Actors
72+
// CHECK-NEXT: func stage
73+
// CHECK-NEXT: #endif
74+
public func stage(with actor: MyActor) { }
75+
6676
// CHECK: #if compiler(>=5.3) && $MarkerProtocol
6777
// CHECK-NEXT: extension FeatureTest.MyActor : Swift.ConcurrentValue {}
6878
// CHECK-NEXT: #endif

0 commit comments

Comments
 (0)