Skip to content

Commit a0ab1dc

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. (cherry picked from commit 6d89bca)
1 parent 4579afb commit a0ab1dc

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
@@ -527,6 +527,9 @@ EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
527527
/// Enable @_lifetime attribute
528528
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)
529529

530+
/// Allow use of `@extensible` on public enums
531+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExtensibleAttribute, false)
532+
530533
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
531534
#undef EXPERIMENTAL_FEATURE
532535
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
407407
DeclAttrKind::RestatedObjCConformance,
408408
DeclAttrKind::NonSendable,
409409
DeclAttrKind::AllowFeatureSuppression,
410-
DeclAttrKind::Extensible,
411410
};
412411

413412
return result;
@@ -3326,6 +3325,13 @@ suppressingFeatureAddressableTypes(PrintOptions &options,
33263325
action();
33273326
}
33283327

3328+
static void
3329+
suppressingFeatureExtensibleAttribute(PrintOptions &options,
3330+
llvm::function_ref<void()> action) {
3331+
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Extensible);
3332+
action();
3333+
}
3334+
33293335
/// Suppress the printing of a particular feature.
33303336
static void suppressingFeature(PrintOptions &options, Feature feature,
33313337
llvm::function_ref<void()> action) {

lib/AST/FeatureSet.cpp

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

659+
static bool usesFeatureExtensibleAttribute(Decl *decl) {
660+
return decl->getAttrs().hasAttribute<ExtensibleAttr>();
661+
}
662+
659663
UNINTERESTING_FEATURE(BuiltinSelect)
660664

661665
static bool usesFeatureAlwaysInheritActorContext(Decl *decl) {

test/ModuleInterface/attrs.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,3 @@ public struct TestPlacementOfAttrsAndSpecifiers {
112112
// CHECK: public func test3<T>(_: inout () async -> T)
113113
public func test3<T>(_: inout () async -> T) {}
114114
}
115-
116-
// CHECK-NOT: @extensible
117-
// CHECK: public enum TestExtensible
118-
@extensible
119-
public enum TestExtensible {
120-
case a
121-
case b
122-
}
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)