Skip to content

Commit a4a72ef

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 a4a72ef

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,6 +3302,13 @@ suppressingFeatureAddressableTypes(PrintOptions &options,
33023302
action();
33033303
}
33043304

3305+
static void
3306+
suppressingFeatureExtensibleAttribute(PrintOptions &options,
3307+
llvm::function_ref<void()> action) {
3308+
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Extensible);
3309+
action();
3310+
}
3311+
33053312
/// Suppress the printing of a particular feature.
33063313
static void suppressingFeature(PrintOptions &options, Feature feature,
33073314
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
// ----------------------------------------------------------------------------
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 Extern -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: 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)