Skip to content

Commit b906219

Browse files
committed
AddressableTypes should be a SUPPRESSIBLE_LANGUAGE_FEATURE.
Types annotated as `@_addressableForDependencies` are still usable by older compilers that don't know about nonescapable types or lifetime dependencies, since it only affects the behavior of the type when it's the source of a dependency.
1 parent 23747bb commit b906219

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
@@ -434,7 +434,7 @@ EXPERIMENTAL_FEATURE(CoroutineAccessorsAllocateInCallee, false)
434434
EXPERIMENTAL_FEATURE(GenerateForceToMainActorThunks, false)
435435

436436
EXPERIMENTAL_FEATURE(AddressableParameters, true)
437-
EXPERIMENTAL_FEATURE(AddressableTypes, true)
437+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
438438

439439
/// Allow the @abi attribute.
440440
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ABIAttribute, true)

lib/AST/ASTPrinter.cpp

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

3163+
namespace {
3164+
struct ExcludeAttrRAII {
3165+
std::vector<AnyAttrKind> &ExcludeAttrList;
3166+
unsigned OriginalExcludeAttrCount;
3167+
3168+
ExcludeAttrRAII(std::vector<AnyAttrKind> &ExcludeAttrList,
3169+
DeclAttrKind excluded)
3170+
: ExcludeAttrList(ExcludeAttrList),
3171+
OriginalExcludeAttrCount(ExcludeAttrList.size())
3172+
{
3173+
ExcludeAttrList.push_back(excluded);
3174+
}
3175+
3176+
~ExcludeAttrRAII() {
3177+
ExcludeAttrList.resize(OriginalExcludeAttrCount);
3178+
}
3179+
};
3180+
}
3181+
31633182
static void
31643183
suppressingFeatureAllowUnsafeAttribute(PrintOptions &options,
31653184
llvm::function_ref<void()> action) {
3166-
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3167-
options.ExcludeAttrList.push_back(DeclAttrKind::Unsafe);
3185+
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Unsafe);
31683186
action();
3169-
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31703187
}
31713188

31723189
static void
@@ -3179,11 +3196,17 @@ suppressingFeatureCoroutineAccessors(PrintOptions &options,
31793196
static void
31803197
suppressingFeatureABIAttribute(PrintOptions &options,
31813198
llvm::function_ref<void()> action) {
3182-
llvm::SaveAndRestore<bool> scope(options.PrintSyntheticSILGenName, true);
3183-
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3184-
options.ExcludeAttrList.push_back(DeclAttrKind::ABI);
3199+
llvm::SaveAndRestore<bool> scope1(options.PrintSyntheticSILGenName, true);
3200+
ExcludeAttrRAII scope2(options.ExcludeAttrList, DeclAttrKind::ABI);
3201+
action();
3202+
}
3203+
3204+
static void
3205+
suppressingFeatureAddressableTypes(PrintOptions &options,
3206+
llvm::function_ref<void()> action) {
3207+
ExcludeAttrRAII scope(options.ExcludeAttrList,
3208+
DeclAttrKind::AddressableForDependencies);
31853209
action();
3186-
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31873210
}
31883211

31893212
/// 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)