Skip to content

Commit 6d89bca

Browse files
committed
[Frontend] Add ExtensibleAttribute to guard use of @extensible attribute
Guard against condfails when older compilers get a swift interface that uses `@extensible` attribute. The attribute itself doesn't have any effect in swift interfaces yet since all of the public enums are already resilient in that mode.
1 parent 8226f20 commit 6d89bca

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
514514
/// Allow use of `@cdecl`
515515
EXPERIMENTAL_FEATURE(CDecl, false)
516516

517+
/// Allow use of `@extensible` on public enums
518+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExtensibleAttribute, false)
519+
517520
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
518521
#undef EXPERIMENTAL_FEATURE
519522
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
402402
DeclAttrKind::RestatedObjCConformance,
403403
DeclAttrKind::NonSendable,
404404
DeclAttrKind::AllowFeatureSuppression,
405-
DeclAttrKind::Extensible,
406405
};
407406

408407
return result;
@@ -3302,6 +3301,13 @@ suppressingFeatureAddressableTypes(PrintOptions &options,
33023301
action();
33033302
}
33043303

3304+
static void
3305+
suppressingFeatureExtensibleAttribute(PrintOptions &options,
3306+
llvm::function_ref<void()> action) {
3307+
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Extensible);
3308+
action();
3309+
}
3310+
33053311
/// Suppress the printing of a particular feature.
33063312
static void suppressingFeature(PrintOptions &options, Feature feature,
33073313
llvm::function_ref<void()> action) {

lib/AST/FeatureSet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ static bool usesFeatureAsyncExecutionBehaviorAttributes(Decl *decl) {
624624
return false;
625625
}
626626

627+
static bool usesFeatureExtensibleAttribute(Decl *decl) {
628+
return decl->getAttrs().hasAttribute<ExtensibleAttr>();
629+
}
630+
627631
// ----------------------------------------------------------------------------
628632
// MARK: - FeatureSet
629633
// ----------------------------------------------------------------------------

test/ModuleInterface/attrs.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ nonisolated(nonsending)
107107
public func testExecutionCaller() async {}
108108
// CHECK: nonisolated(nonsending) public func testExecutionCaller() async
109109

110-
// CHECK-NOT: @extensible
111-
// CHECK: public enum TestExtensible
112-
@extensible
113-
public enum TestExtensible {
114-
case a
115-
case b
116-
}
117-
118110
public struct TestPlacementOfAttrsAndSpecifiers {
119111
// CHECK: public func test1<T>(_: sending @autoclosure () -> T)
120112
public func test1<T>(_: sending @autoclosure () -> T) {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-feature ExtensibleAttribute -module-name Library
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-feature ExtensibleAttribute -module-name Library
4+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
5+
// RUN: %FileCheck %s < %t/Library.swiftinterface
6+
7+
// REQUIRES: swift_feature_ExtensibleAttribute
8+
9+
// CHECK: #if compiler(>=5.3) && $ExtensibleAttribute
10+
// CHECK-NEXT: @extensible public enum E {
11+
// CHECK-NEXT: }
12+
// CHECK-NEXT: #else
13+
// CHECK-NEXT: public enum E {
14+
// CHECK-NEXT: }
15+
// CHECK-NEXT: #endif
16+
@extensible
17+
public enum E {
18+
}

0 commit comments

Comments
 (0)