mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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 6d89bca765)
This commit is contained in:
@@ -527,6 +527,9 @@ EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
|
||||
/// Enable @_lifetime attribute
|
||||
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)
|
||||
|
||||
/// Allow use of `@extensible` on public enums
|
||||
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExtensibleAttribute, false)
|
||||
|
||||
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
|
||||
#undef EXPERIMENTAL_FEATURE
|
||||
#undef UPCOMING_FEATURE
|
||||
|
||||
@@ -407,7 +407,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
|
||||
DeclAttrKind::RestatedObjCConformance,
|
||||
DeclAttrKind::NonSendable,
|
||||
DeclAttrKind::AllowFeatureSuppression,
|
||||
DeclAttrKind::Extensible,
|
||||
};
|
||||
|
||||
return result;
|
||||
@@ -3326,6 +3325,13 @@ suppressingFeatureAddressableTypes(PrintOptions &options,
|
||||
action();
|
||||
}
|
||||
|
||||
static void
|
||||
suppressingFeatureExtensibleAttribute(PrintOptions &options,
|
||||
llvm::function_ref<void()> action) {
|
||||
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Extensible);
|
||||
action();
|
||||
}
|
||||
|
||||
/// Suppress the printing of a particular feature.
|
||||
static void suppressingFeature(PrintOptions &options, Feature feature,
|
||||
llvm::function_ref<void()> action) {
|
||||
|
||||
@@ -656,6 +656,10 @@ static bool usesFeatureAsyncExecutionBehaviorAttributes(Decl *decl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool usesFeatureExtensibleAttribute(Decl *decl) {
|
||||
return decl->getAttrs().hasAttribute<ExtensibleAttr>();
|
||||
}
|
||||
|
||||
UNINTERESTING_FEATURE(BuiltinSelect)
|
||||
|
||||
static bool usesFeatureAlwaysInheritActorContext(Decl *decl) {
|
||||
|
||||
@@ -112,11 +112,3 @@ public struct TestPlacementOfAttrsAndSpecifiers {
|
||||
// CHECK: public func test3<T>(_: inout () async -> T)
|
||||
public func test3<T>(_: inout () async -> T) {}
|
||||
}
|
||||
|
||||
// CHECK-NOT: @extensible
|
||||
// CHECK: public enum TestExtensible
|
||||
@extensible
|
||||
public enum TestExtensible {
|
||||
case a
|
||||
case b
|
||||
}
|
||||
|
||||
18
test/ModuleInterface/extensible_attr.swift
Normal file
18
test/ModuleInterface/extensible_attr.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-feature ExtensibleAttribute -module-name Library
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-feature ExtensibleAttribute -module-name Library
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
|
||||
// RUN: %FileCheck %s < %t/Library.swiftinterface
|
||||
|
||||
// REQUIRES: swift_feature_ExtensibleAttribute
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $ExtensibleAttribute
|
||||
// CHECK-NEXT: @extensible public enum E {
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: #else
|
||||
// CHECK-NEXT: public enum E {
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: #endif
|
||||
@extensible
|
||||
public enum E {
|
||||
}
|
||||
Reference in New Issue
Block a user