Skip to content

Commit b266abe

Browse files
committed
[BitwiseCopyable] Add a marker protocol.
Behind the experimental feature BitwiseCopyable.
1 parent 556c503 commit b266abe

File tree

7 files changed

+21
-0
lines changed

7 files changed

+21
-0
lines changed

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ PROTOCOL(AsyncIteratorProtocol)
137137
PROTOCOL(FloatingPoint)
138138

139139
INVERTIBLE_PROTOCOL_WITH_NAME(Copyable, "Copyable")
140+
PROTOCOL_(BitwiseCopyable)
140141

141142
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral, "Array", false)
142143
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral, "BooleanLiteralType", true)

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
266266
/// Enable the @extractConstantsFromMembers attribute.
267267
EXPERIMENTAL_FEATURE(ExtractConstantsFromMembers, false)
268268

269+
/// Enable bitwise-copyable feature.
270+
EXPERIMENTAL_FEATURE(BitwiseCopyable, true)
271+
269272
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
270273
#undef EXPERIMENTAL_FEATURE
271274
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,8 @@ static bool usesFeatureExtractConstantsFromMembers(Decl *decl) {
36943694
return decl->getAttrs().hasAttribute<ExtractConstantsFromMembersAttr>();
36953695
}
36963696

3697+
static bool usesFeatureBitwiseCopyable(Decl *decl) { return false; }
3698+
36973699
/// Suppress the printing of a particular feature.
36983700
static void suppressingFeature(PrintOptions &options, Feature feature,
36993701
llvm::function_ref<void()> action) {

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6577,6 +6577,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
65776577
case KnownProtocolKind::RangeReplaceableCollection:
65786578
case KnownProtocolKind::GlobalActor:
65796579
case KnownProtocolKind::Copyable:
6580+
case KnownProtocolKind::BitwiseCopyable:
65806581
return SpecialProtocol::None;
65816582
}
65826583

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-experimental-concis
301301
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Macros")
302302
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "FreestandingMacros")
303303
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Extern")
304+
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "BitwiseCopyable")
304305

305306
set(swift_core_incorporate_object_libraries)
306307
list(APPEND swift_core_incorporate_object_libraries swiftRuntime)

stdlib/public/core/Misc.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ public func _unsafePerformance<T>(_ c: () -> T) -> T {
168168

169169

170170
@_marker public protocol Copyable {}
171+
172+
#if $BitwiseCopyable
173+
@_marker public protocol _BitwiseCopyable {}
174+
#endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend \
2+
// RUN: -enable-experimental-feature BitwiseCopyable \
3+
// RUN: %s \
4+
// RUN: -typecheck -verify
5+
6+
// Verify that the BitwiseCopyable feature flag works both in asserts and noasserts builds.
7+
8+
struct S : _BitwiseCopyable {
9+
}

0 commit comments

Comments
 (0)