Skip to content

Commit 4420f27

Browse files
authored
Merge pull request #78615 from jckarter/addressable-as-suppressable-feature
`AddressableTypes` should be a SUPPRESSIBLE_LANGUAGE_FEATURE.
2 parents 556c9ff + b906219 commit 4420f27

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ EXPERIMENTAL_FEATURE(CoroutineAccessorsAllocateInCallee, false)
438438
EXPERIMENTAL_FEATURE(GenerateForceToMainActorThunks, false)
439439

440440
EXPERIMENTAL_FEATURE(AddressableParameters, true)
441-
EXPERIMENTAL_FEATURE(AddressableTypes, true)
441+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
442442

443443
/// Allow the @abi attribute.
444444
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ABIAttribute, true)

lib/AST/ASTPrinter.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,13 +3158,30 @@ suppressingFeatureIsolatedDeinit(PrintOptions &options,
31583158
action();
31593159
}
31603160

3161+
namespace {
3162+
struct ExcludeAttrRAII {
3163+
std::vector<AnyAttrKind> &ExcludeAttrList;
3164+
unsigned OriginalExcludeAttrCount;
3165+
3166+
ExcludeAttrRAII(std::vector<AnyAttrKind> &ExcludeAttrList,
3167+
DeclAttrKind excluded)
3168+
: ExcludeAttrList(ExcludeAttrList),
3169+
OriginalExcludeAttrCount(ExcludeAttrList.size())
3170+
{
3171+
ExcludeAttrList.push_back(excluded);
3172+
}
3173+
3174+
~ExcludeAttrRAII() {
3175+
ExcludeAttrList.resize(OriginalExcludeAttrCount);
3176+
}
3177+
};
3178+
}
3179+
31613180
static void
31623181
suppressingFeatureAllowUnsafeAttribute(PrintOptions &options,
31633182
llvm::function_ref<void()> action) {
3164-
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3165-
options.ExcludeAttrList.push_back(DeclAttrKind::Unsafe);
3183+
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Unsafe);
31663184
action();
3167-
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31683185
}
31693186

31703187
static void
@@ -3177,11 +3194,17 @@ suppressingFeatureCoroutineAccessors(PrintOptions &options,
31773194
static void
31783195
suppressingFeatureABIAttribute(PrintOptions &options,
31793196
llvm::function_ref<void()> action) {
3180-
llvm::SaveAndRestore<bool> scope(options.PrintSyntheticSILGenName, true);
3181-
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3182-
options.ExcludeAttrList.push_back(DeclAttrKind::ABI);
3197+
llvm::SaveAndRestore<bool> scope1(options.PrintSyntheticSILGenName, true);
3198+
ExcludeAttrRAII scope2(options.ExcludeAttrList, DeclAttrKind::ABI);
3199+
action();
3200+
}
3201+
3202+
static void
3203+
suppressingFeatureAddressableTypes(PrintOptions &options,
3204+
llvm::function_ref<void()> action) {
3205+
ExcludeAttrRAII scope(options.ExcludeAttrList,
3206+
DeclAttrKind::AddressableForDependencies);
31833207
action();
3184-
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31853208
}
31863209

31873210
/// Suppress the printing of a particular feature.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name attrs -enable-experimental-feature AddressableTypes
2+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name attrs
3+
// RUN: %FileCheck %s --input-file %t.swiftinterface
4+
5+
// REQUIRES: swift_feature_AddressableTypes
6+
7+
@_addressableForDependencies
8+
public struct Foo {}
9+
// CHECK: #if {{.*}} $AddressableTypes
10+
// CHECK: @_addressableForDependencies public struct Foo
11+
// CHECK: #else
12+
// CHECK: {{^}}public struct Foo {
13+
// CHECK: #endif

0 commit comments

Comments
 (0)