Skip to content

Commit ed5c7ef

Browse files
committed
[BitwiseCopyable] Promote to feature.
SE-0426 was accepted.
1 parent fae5d2c commit ed5c7ef

29 files changed

+42
-97
lines changed

include/swift/Basic/Features.def

+2-3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ LANGUAGE_FEATURE(BuiltinCreateTask, 0, "Builtin.createTask and Builtin.createDis
177177
SUPPRESSIBLE_LANGUAGE_FEATURE(AssociatedTypeImplements, 0, "@_implements on associated types")
178178
LANGUAGE_FEATURE(BuiltinAddressOfRawLayout, 0, "Builtin.addressOfRawLayout")
179179
LANGUAGE_FEATURE(MoveOnlyPartialConsumption, 429, "Partial consumption of noncopyable values")
180+
/// Enable bitwise-copyable feature.
181+
LANGUAGE_FEATURE(BitwiseCopyable, 426, "BitwiseCopyable protocol")
180182

181183
// Swift 6
182184
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -343,9 +345,6 @@ EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
343345
/// Enable the @extractConstantsFromMembers attribute.
344346
EXPERIMENTAL_FEATURE(ExtractConstantsFromMembers, false)
345347

346-
/// Enable bitwise-copyable feature.
347-
EXPERIMENTAL_FEATURE(BitwiseCopyable, true)
348-
349348
/// Enable the suppression of inferred, non-invertible, protocols via ~.
350349
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ConformanceSuppression, true)
351350

lib/AST/LifetimeDependence.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ static LifetimeDependenceKind getLifetimeDependenceKindFromDecl(
173173
}
174174

175175
static bool isBitwiseCopyable(Type type, ModuleDecl *mod, ASTContext &ctx) {
176-
if (!ctx.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
177-
return false;
178-
}
179176
auto *bitwiseCopyableProtocol =
180177
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
181178
if (!bitwiseCopyableProtocol) {

lib/AST/ProtocolConformance.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,7 @@ static SmallVector<ProtocolConformance *, 2> findSynthesizedConformances(
12841284
for (auto ip : InvertibleProtocolSet::allKnown())
12851285
trySynthesize(getKnownProtocolKind(ip));
12861286

1287-
if (nominal->getASTContext().LangOpts.hasFeature(
1288-
Feature::BitwiseCopyable)) {
1289-
trySynthesize(KnownProtocolKind::BitwiseCopyable);
1290-
}
1287+
trySynthesize(KnownProtocolKind::BitwiseCopyable);
12911288
}
12921289

12931290
/// Distributed actors can synthesize Encodable/Decodable, so look for those

lib/ClangImporter/ImportDecl.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -8029,8 +8029,6 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
80298029
}
80308030

80318031
if (swiftAttr->getAttribute() == "_BitwiseCopyable") {
8032-
if (!SwiftContext.LangOpts.hasFeature(Feature::BitwiseCopyable))
8033-
continue;
80348032
auto *protocol =
80358033
SwiftContext.getProtocol(KnownProtocolKind::BitwiseCopyable);
80368034
auto *nominal = dyn_cast<NominalTypeDecl>(MappedDecl);

lib/SIL/IR/TypeLowering.cpp

+26-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/DiagnosticEngine.h"
2121
#include "swift/AST/DiagnosticsSIL.h"
2222
#include "swift/AST/Expr.h"
23+
#include "swift/AST/FileUnit.h"
2324
#include "swift/AST/GenericEnvironment.h"
2425
#include "swift/AST/LazyResolver.h"
2526
#include "swift/AST/Module.h"
@@ -28,6 +29,7 @@
2829
#include "swift/AST/Pattern.h"
2930
#include "swift/AST/PrettyStackTrace.h"
3031
#include "swift/AST/PropertyWrappers.h"
32+
#include "swift/AST/SourceFile.h"
3133
#include "swift/AST/TypeDifferenceVisitor.h"
3234
#include "swift/AST/Types.h"
3335
#include "swift/ClangImporter/ClangModule.h"
@@ -3041,8 +3043,6 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30413043
AbstractionPattern origType,
30423044
CanType substType,
30433045
TypeExpansionContext forExpansion) {
3044-
if (!Context.LangOpts.hasFeature(Feature::BitwiseCopyable))
3045-
return;
30463046
auto *bitwiseCopyableProtocol =
30473047
Context.getProtocol(KnownProtocolKind::BitwiseCopyable);
30483048
if (!bitwiseCopyableProtocol)
@@ -3057,10 +3057,20 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30573057

30583058
if (auto *nominal = substType.getAnyNominal()) {
30593059
auto *module = nominal->getModuleContext();
3060-
if (module && module->isBuiltFromInterface()) {
3061-
// Don't verify for types in modules built from interfaces; the feature
3062-
// may not have been enabled in them.
3063-
return;
3060+
if (module) {
3061+
if (module->isBuiltFromInterface()) {
3062+
// Don't verify for types in modules built from interfaces; the feature
3063+
// may not have been enabled in them.
3064+
return;
3065+
}
3066+
auto *file = dyn_cast_or_null<FileUnit>(module->getModuleScopeContext());
3067+
if (file && file->getKind() == FileUnitKind::Source) {
3068+
auto sourceFile = nominal->getParentSourceFile();
3069+
if (sourceFile && sourceFile->Kind == SourceFileKind::SIL) {
3070+
// Don't verify for types in SIL files.
3071+
return;
3072+
}
3073+
}
30643074
}
30653075
}
30663076

@@ -3086,6 +3096,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30863096
// unconditionally but does in this case
30873097
// (8) being or containing the error type
30883098
// (9) explicitly suppressing conformance
3099+
// (10) a layout constrained archetype
30893100
bool hasNoNonconformingNode = visitAggregateLeaves(
30903101
origType, substType, forExpansion,
30913102
/*isLeafAggregate=*/
@@ -3155,7 +3166,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31553166

31563167
// ModuleTypes are trivial but don't warrant being given a
31573168
// conformance to BitwiseCopyable (case (3)).
3158-
if (isa<ModuleType, SILTokenType>(ty)) {
3169+
if (isa<ModuleType>(ty) || isa<SILTokenType>(ty)) {
31593170
// These types should never appear within aggregates.
31603171
assert(isTopLevel && "aggregate containing marker type!?");
31613172
// If they did, though, they would not justify the aggregate's
@@ -3174,6 +3185,14 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31743185
return !isTopLevel;
31753186
}
31763187

3188+
// Case (10): a layout-constrained archetype.
3189+
if (auto archetype = dyn_cast<ArchetypeType>(ty)) {
3190+
auto constraint = archetype->getLayoutConstraint();
3191+
if (constraint && constraint->isTrivial()) {
3192+
return false;
3193+
}
3194+
}
3195+
31773196
auto *nominal = ty.getAnyNominal();
31783197

31793198
// Non-nominal types (besides case (3) handled above) are trivial iff

lib/Sema/TypeCheckDecl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
682682
ProtocolDecl *decl) const {
683683
// Marker protocols always self-conform.
684684
if (decl->isMarkerProtocol()) {
685-
// Except for BitwiseCopyable an existential of which is non-trivial.
686-
if (decl->getASTContext().LangOpts.hasFeature(Feature::BitwiseCopyable) &&
687-
decl->getKnownProtocolKind() == KnownProtocolKind::BitwiseCopyable) {
685+
// Except for BitwiseCopyable an existential of which is not bitwise
686+
// copyable.
687+
if (decl->getKnownProtocolKind() == KnownProtocolKind::BitwiseCopyable) {
688688
return false;
689689
}
690690
return true;

lib/Sema/TypeCheckProtocol.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -6117,11 +6117,9 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61176117
break;
61186118
}
61196119
case KnownProtocolKind::BitwiseCopyable: {
6120-
if (Context.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
6121-
checkBitwiseCopyableConformance(
6122-
conformance, /*isImplicit=*/conformance->getSourceKind() ==
6123-
ConformanceEntryKind::Synthesized);
6124-
}
6120+
checkBitwiseCopyableConformance(
6121+
conformance, /*isImplicit=*/conformance->getSourceKind() ==
6122+
ConformanceEntryKind::Synthesized);
61256123
break;
61266124
}
61276125
default:

stdlib/public/core/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-enable-experimental-concis
315315
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Macros")
316316
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "FreestandingMacros")
317317
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "Extern")
318-
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "BitwiseCopyable")
319318
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "BorrowingSwitch")
320319
list(APPEND swift_stdlib_compile_flags "-enable-experimental-feature" "ConformanceSuppression")
321320

test/Frontend/bitwise-copyable-flag.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend \
2-
// RUN: -enable-experimental-feature BitwiseCopyable \
32
// RUN: %s \
43
// RUN: -typecheck -verify
54

test/IRGen/bitwise-copyable-derived-loadRaw.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature BuiltinModule -enable-experimental-feature BitwiseCopyable) | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature BuiltinModule) | %FileCheck %s
22

33
// REQUIRES: executable_test
44

test/IRGen/bitwise-copyable-loadRaw.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature BuiltinModule -enable-experimental-feature BitwiseCopyable -Xfrontend -disable-availability-checking) | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature BuiltinModule -Xfrontend -disable-availability-checking) | %FileCheck %s
22

33
// REQUIRES: executable_test
44

test/IRGen/bitwise_copyable.swift

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: -primary-file %s \
33
// RUN: -emit-ir \
44
// RUN: -disable-availability-checking \
5-
// RUN: -enable-experimental-feature BitwiseCopyable \
65
// RUN: -enable-builtin-module
76

87
// REQUIRES: asserts

test/IRGen/bitwise_copyable_onone.swift

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: -primary-file %s \
33
// RUN: -emit-ir \
44
// RUN: -disable-availability-checking \
5-
// RUN: -enable-experimental-feature BitwiseCopyable \
65
// RUN: -enable-builtin-module \
76
// RUN: | \
87
// RUN: %FileCheck %s

test/IRGen/bitwise_copyable_resilient.swift

-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
// RUN: %t/Library.swift \
66
// RUN: -emit-module \
77
// RUN: -enable-library-evolution \
8-
// RUN: -enable-experimental-feature BitwiseCopyable \
98
// RUN: -module-name Library \
109
// RUN: -emit-module-path %t/Library.swiftmodule
1110

1211
// RUN: %target-swift-frontend \
1312
// RUN: %t/Downstream.swift \
1413
// RUN: -typecheck -verify \
1514
// RUN: -debug-diagnostic-names \
16-
// RUN: -enable-experimental-feature BitwiseCopyable \
1715
// RUN: -I %t
1816

1917
//--- Library.swift

test/ModuleInterface/bitwise_copyable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test -enable-experimental-feature BitwiseCopyable
2+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test
33
// RUN: %FileCheck %s < %t.swiftinterface
44
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test
55

test/SIL/type_lowering_unit.sil

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %target-sil-opt -test-runner \
22
// RUN: -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature NonescapableTypes \
3-
// RUN: -enable-experimental-feature BitwiseCopyable \
43
// RUN: %s -o /dev/null 2>&1 | %FileCheck %s
54

65
sil_stage raw

test/SILGen/bitwise_copyable.swift

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: -emit-silgen \
44
// RUN: -disable-availability-checking \
55
// RUN: -enable-experimental-feature ConformanceSuppression \
6-
// RUN: -enable-experimental-feature BitwiseCopyable \
76
// RUN: -enable-builtin-module
87

98
// REQUIRES: asserts

test/SILGen/bitwise_copyable_stdlib.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// RUN: -module-name Swift \
88
// RUN: -disable-availability-checking \
99
// RUN: -enable-experimental-feature BuiltinModule \
10-
// RUN: -enable-experimental-feature BitwiseCopyable \
1110
// RUN: -enable-experimental-feature NoncopyableGenerics \
1211
// RUN: -enable-experimental-feature NonescapableTypes \
1312
// RUN: -enable-builtin-module

test/Sema/bitwise_copyable.swift

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: -disable-availability-checking \
33
// RUN: -enable-experimental-feature NonescapableTypes \
44
// RUN: -enable-experimental-feature NoncopyableGenerics \
5-
// RUN: -enable-experimental-feature BitwiseCopyable \
65
// RUN: -enable-builtin-module \
76
// RUN: -debug-diagnostic-names
87

@@ -241,22 +240,14 @@ func passPointer<T : _Pointer>(_ p: T) { take3(p) }
241240

242241
func take4<T : _BitwiseCopyable>(_ t: T) {}
243242

244-
func passCheckedContinuation<T : _BitwiseCopyable, U : Error & _BitwiseCopyable>(
245-
_ c: CheckedContinuation<T, U>
246-
)
247-
{
248-
take4(c) // expected-error {{type_does_not_conform_decl_owner}}
249-
// expected-note@-7 {{where_requirement_failure_one_subst}}
250-
}
251-
252243
func passUnsafeContinuation<T : _BitwiseCopyable, U : Error & _BitwiseCopyable>(
253244
_ c: UnsafeContinuation<T, U>
254245
)
255246
{
256247
take4(c)
257248
}
258249

259-
extension UnsafeContinuation : @retroactive _BitwiseCopyable {} // expected-error{{conformance to 'BitwiseCopyable' must occur in the same module as generic struct 'UnsafeContinuation'}}
250+
extension CheckedContinuation : @retroactive _BitwiseCopyable {} // expected-error{{conformance to 'BitwiseCopyable' must occur in the same module as generic struct 'CheckedContinuation'}}
260251

261252
//==============================================================================
262253
//========================_CONCURRENCY-DEPENDENCY TESTS=(END)=================}}

test/Sema/bitwise_copyable_2.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-typecheck-verify-swift \
22
// RUN: -enable-experimental-feature NonescapableTypes \
33
// RUN: -enable-experimental-feature ConformanceSuppression \
4-
// RUN: -enable-experimental-feature BitwiseCopyable \
54
// RUN: -enable-builtin-module \
65
// RUN: -debug-diagnostic-names
76

test/Sema/bitwise_copyable_nonresilient.swift

-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
// RUN: %target-swift-frontend \
55
// RUN: %t/Library.swift \
66
// RUN: -emit-module \
7-
// RUN: -enable-experimental-feature BitwiseCopyable \
87
// RUN: -module-name Library \
98
// RUN: -emit-module-path %t/Library.swiftmodule
109

1110
// RUN: %target-swift-frontend \
1211
// RUN: %t/Downstream.swift \
1312
// RUN: -typecheck -verify \
1413
// RUN: -debug-diagnostic-names \
15-
// RUN: -enable-experimental-feature BitwiseCopyable \
1614
// RUN: -I %t
1715

1816
//--- Library.swift

test/Sema/bitwise_copyable_package_resilience.swift

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// RUN: -emit-module \
77
// RUN: -package-name Package \
88
// RUN: -enable-library-evolution \
9-
// RUN: -enable-experimental-feature BitwiseCopyable \
109
// RUN: -module-name Library \
1110
// RUN: -emit-module-path %t/Library.swiftmodule \
1211
// RUN: -emit-module-interface-path %t/Library.swiftinterface
@@ -16,7 +15,6 @@
1615
// RUN: -typecheck -verify \
1716
// RUN: -package-name Package \
1817
// RUN: -debug-diagnostic-names \
19-
// RUN: -enable-experimental-feature BitwiseCopyable \
2018
// RUN: -I %t
2119

2220
//--- Library.swift

test/Sema/bitwise_copyable_resilience.swift

-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
// RUN: %t/Library.swift \
66
// RUN: -emit-module \
77
// RUN: -enable-library-evolution \
8-
// RUN: -enable-experimental-feature BitwiseCopyable \
98
// RUN: -module-name Library \
109
// RUN: -emit-module-path %t/Library.swiftmodule
1110

1211
// RUN: %target-swift-frontend \
1312
// RUN: %t/Downstream.swift \
1413
// RUN: -typecheck -verify \
1514
// RUN: -debug-diagnostic-names \
16-
// RUN: -enable-experimental-feature BitwiseCopyable \
1715
// RUN: -I %t
1816

1917
//--- Library.swift

test/Sema/bitwise_copyable_resilience_legacy.swift

-36
This file was deleted.

test/Sema/bitwise_copyable_stdlib.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-typecheck-verify-swift \
22
// RUN: -parse-stdlib \
33
// RUN: -module-name Swift \
4-
// RUN: -enable-experimental-feature BitwiseCopyable \
54
// RUN: -disable-availability-checking \
65
// RUN: -debug-diagnostic-names
76

test/Sema/bitwse_copyable_import.swift

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// RUN: %t/Downstream.swift \
66
// RUN: -typecheck -verify \
77
// RUN: -enable-experimental-feature NonescapableTypes \
8-
// RUN: -enable-experimental-feature BitwiseCopyable \
98
// RUN: -enable-builtin-module \
109
// RUN: -debug-diagnostic-names \
1110
// RUN: -import-objc-header %t/Library.h

test/Sema/explicit_lifetime_dependence_specifiers1.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature BitwiseCopyable
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -enable-experimental-feature NoncopyableGenerics
22
// REQUIRES: asserts
33

44
struct Container {

0 commit comments

Comments
 (0)