Skip to content

Commit 72c7284

Browse files
authored
Merge pull request #41678 from etcwilde/ewilde/protect-unavailable-from-async
Check unavailable from async in interface file
2 parents c88a3d6 + 8220973 commit 72c7284

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_special
7575
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
7676
SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor", true)
7777
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes, 0, "Primary associated types", true)
78+
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
79+
7880
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
7981
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,19 @@ static void suppressingFeaturePrimaryAssociatedTypes(PrintOptions &options,
30023002
options.PrintPrimaryAssociatedTypes = originalPrintPrimaryAssociatedTypes;
30033003
}
30043004

3005+
static bool usesFeatureUnavailableFromAsync(Decl *decl) {
3006+
return decl->getAttrs().hasAttribute<UnavailableFromAsyncAttr>();
3007+
}
3008+
3009+
static void
3010+
suppressingFeatureUnavailableFromAsync(PrintOptions &options,
3011+
llvm::function_ref<void()> action) {
3012+
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3013+
options.ExcludeAttrList.push_back(DAK_UnavailableFromAsync);
3014+
action();
3015+
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3016+
}
3017+
30053018
/// Suppress the printing of a particular feature.
30063019
static void suppressingFeature(PrintOptions &options, Feature feature,
30073020
llvm::function_ref<void()> action) {

test/ModuleInterface/features.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,12 @@ public func unsafeInheritExecutor() async {}
177177
@_specialize(exported: true, availability: SwiftStdlib 5.1, *; where T == Int)
178178
public func multipleSuppressible<T>(value: T) async {}
179179

180+
// CHECK: #if compiler(>=5.3) && $UnavailableFromAsync
181+
// CHECK-NEXT: @_unavailableFromAsync(message: "Test") public func unavailableFromAsyncFunc()
182+
// CHECK-NEXT: #else
183+
// CHECK-NEXT: public func unavailableFromAsyncFunc()
184+
// CHECK-NEXT: #endif
185+
@_unavailableFromAsync(message: "Test")
186+
public func unavailableFromAsyncFunc() { }
187+
180188
// CHECK-NOT: extension FeatureTest.MyActor : Swift.Sendable

0 commit comments

Comments
 (0)