Skip to content

Commit 902a22d

Browse files
Merge pull request #71298 from nate-chandler/bitwise-copyable/remove-unchecked
[BitwiseCopyable] Remove @unchecked behavior.
2 parents 2e20aa5 + 05b4820 commit 902a22d

File tree

10 files changed

+21
-92
lines changed

10 files changed

+21
-92
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "swift/AST/Pattern.h"
2929
#include "swift/AST/PrettyStackTrace.h"
3030
#include "swift/AST/PropertyWrappers.h"
31-
#include "swift/AST/ProtocolConformance.h"
3231
#include "swift/AST/TypeDifferenceVisitor.h"
3332
#include "swift/AST/Types.h"
3433
#include "swift/ClangImporter/ClangModule.h"
@@ -3010,21 +3009,6 @@ void TypeConverter::verifyLexicalLowering(const TypeLowering &lowering,
30103009
}
30113010
}
30123011

3013-
static bool isUnchecked(ProtocolConformanceRef conformance) {
3014-
if (!conformance)
3015-
return false;
3016-
if (!conformance.isConcrete())
3017-
return false;
3018-
auto concrete = conformance.getConcrete();
3019-
assert(concrete);
3020-
auto *root = concrete->getRootConformance();
3021-
assert(root);
3022-
auto *normal = dyn_cast<NormalProtocolConformance>(root);
3023-
if (!normal)
3024-
return false;
3025-
return normal->isUnchecked();
3026-
}
3027-
30283012
void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30293013
AbstractionPattern origType,
30303014
CanType substType,
@@ -3058,17 +3042,10 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30583042
if (!nominal)
30593043
return false;
30603044

3061-
// Don't walk into types whose conformance is unchecked--such
3062-
// conformances obstruct automatic inference of BitwiseCopyable.
3063-
auto conformance = M.checkConformance(ty, bitwiseCopyableProtocol);
3064-
if (isUnchecked(conformance)) {
3065-
return true;
3066-
}
3067-
3068-
// Nominals with fields that conditionally conform to BitwiseCopyable
3069-
// must be explicitly conditionally conformed. Such a field must be a
3070-
// generic context.
3071-
if (nominal->isGenericContext()) {
3045+
// Nominals with generic parameters must be explicitly conformed to
3046+
// BitwiseCopyable.
3047+
auto *generic = ty.getAnyGeneric();
3048+
if (generic && generic->isGenericContext()) {
30723049
return true;
30733050
}
30743051

@@ -3082,12 +3059,10 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30823059
// Return false to indicate seeing a leaf which justifies the type
30833060
// being trivial but not conforming to BitwiseCopyable.
30843061

3085-
// A BitwiseCopyable conformer appearing within its layout explains a
3086-
// non-conformance iff the conformance is @unchecked.
3087-
auto conformance = M.checkConformance(ty, bitwiseCopyableProtocol);
3088-
if (conformance) {
3089-
return !isUnchecked(conformance);
3090-
}
3062+
// A BitwiseCopyable conformer appearing within its layout doesn't
3063+
// explain why substType doesn't itself conform.
3064+
if (M.checkConformance(ty, bitwiseCopyableProtocol))
3065+
return true;
30913066

30923067
// ModuleTypes are trivial but don't warrant being given a conformance
30933068
// to BitwiseCopyable.
@@ -3124,15 +3099,15 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31243099
return true;
31253100
}
31263101

3127-
/// A field of conditionally-BitwiseCopyable type justifies the
3128-
/// aggregate not conforming because the aggregate must be conformed
3129-
/// explicitly in that case.
3130-
if (nominal->isGenericContext()) {
3102+
/// A non-conforming generic nominal type justifies substType not
3103+
/// conforming.
3104+
auto *generic = ty.getAnyGeneric();
3105+
if (generic && generic->isGenericContext()) {
31313106
return false;
31323107
}
31333108

31343109
// The field is trivial and the whole type is nonconforming. That's
3135-
// legal iff the field's type is public.
3110+
// legal iff the type is public.
31363111
return !nominal
31373112
->getFormalAccessScope(
31383113
/*useDC=*/nullptr,
@@ -3173,7 +3148,6 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31733148
llvm::errs() << "Non-trivial type with _BitwiseCopyable conformance!?:\n"
31743149
<< substType << "\n";
31753150
conformance.print(llvm::errs());
3176-
llvm::errs() << "\n";
31773151
assert(false);
31783152
}
31793153
}

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class BitwiseCopyableStorageVisitor : public StorageVisitor {
106106

107107
bool visitMemberDecl(ValueDecl *storage, Type ty);
108108
bool visitMemberType(Type type, SourceLoc loc);
109-
bool isUnchecked(ProtocolConformanceRef conformance);
110109
bool visitNonconformingMemberType(Type type, SourceLoc loc);
111110
void emitNonconformingMemberTypeDiagnostic(Type ty, SourceLoc loc);
112111
};
@@ -137,13 +136,6 @@ bool BitwiseCopyableStorageVisitor::visitMemberType(Type ty, SourceLoc loc) {
137136
return visitNonconformingMemberType(ty, loc);
138137
}
139138

140-
if (isImplicit(check) && isUnchecked(conformance)) {
141-
// Do not automatically derive conformance if one of the field's
142-
// conformance is @unchecked.
143-
invalid = true;
144-
return true;
145-
}
146-
147139
// Walk the conformance, diagnosing any missing BitwiseCopyable conformances.
148140
bool anyMissing = false;
149141
conformance.forEachMissingConformance(
@@ -158,20 +150,6 @@ bool BitwiseCopyableStorageVisitor::visitMemberType(Type ty, SourceLoc loc) {
158150
return anyMissing;
159151
}
160152

161-
bool BitwiseCopyableStorageVisitor::isUnchecked(
162-
ProtocolConformanceRef conformance) {
163-
if (!conformance.isConcrete())
164-
return false;
165-
auto concrete = conformance.getConcrete();
166-
assert(concrete);
167-
auto *root = concrete->getRootConformance();
168-
assert(root);
169-
auto *normal = dyn_cast<NormalProtocolConformance>(root);
170-
if (!normal)
171-
return false;
172-
return normal->isUnchecked();
173-
}
174-
175153
bool BitwiseCopyableStorageVisitor::visitNonconformingMemberType(
176154
Type ty, SourceLoc loc) {
177155
if (ty->hasError())

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,8 +2165,7 @@ static void diagnoseConformanceImpliedByConditionalConformance(
21652165
/// to the given protocol. This should return true when @unchecked can be
21662166
/// used to disable those semantic checks.
21672167
static bool hasAdditionalSemanticChecks(ProtocolDecl *proto) {
2168-
return proto->isSpecificProtocol(KnownProtocolKind::Sendable) ||
2169-
proto->isSpecificProtocol(KnownProtocolKind::BitwiseCopyable);
2168+
return proto->isSpecificProtocol(KnownProtocolKind::Sendable);
21702169
}
21712170

21722171
/// Determine whether the type \c T conforms to the protocol \c Proto,

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public func _getBridgedNonVerbatimObjectiveCType<T>(_: T.Type) -> Any.Type?
407407
/// already have writeback-scoped lifetime.
408408
@frozen
409409
public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
410-
: _Pointer, @unchecked _BitwiseCopyable {
410+
: _Pointer {
411411

412412
public let _rawValue: Builtin.RawPointer
413413

stdlib/public/core/CTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public typealias CBool = Bool
142142
/// Opaque pointers are used to represent C pointers to types that
143143
/// cannot be represented in Swift, such as incomplete struct types.
144144
@frozen
145-
public struct OpaquePointer : @unchecked _BitwiseCopyable {
145+
public struct OpaquePointer {
146146
@usableFromInline
147147
internal var _rawValue: Builtin.RawPointer
148148

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
/// collection with an `${Self}` instance copies the instances out of the
3131
/// referenced memory and into the new collection.
3232
@frozen // unsafe-performance
33-
public struct Unsafe${Mutable}BufferPointer<Element>
34-
: @unchecked _BitwiseCopyable {
33+
public struct Unsafe${Mutable}BufferPointer<Element> {
3534

3635
@usableFromInline
3736
let _position: Unsafe${Mutable}Pointer<Element>?

stdlib/public/core/UnsafePointer.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
/// let numberPointer = UnsafePointer<Int>(&number)
206206
/// // Accessing 'numberPointer' is undefined behavior.
207207
@frozen // unsafe-performance
208-
public struct UnsafePointer<Pointee>: _Pointer, @unchecked _BitwiseCopyable {
208+
public struct UnsafePointer<Pointee>: _Pointer {
209209

210210
/// A type that represents the distance between two pointers.
211211
public typealias Distance = Int
@@ -578,8 +578,7 @@ public struct UnsafePointer<Pointee>: _Pointer, @unchecked _BitwiseCopyable {
578578
/// let numberPointer = UnsafeMutablePointer<Int>(&number)
579579
/// // Accessing 'numberPointer' is undefined behavior.
580580
@frozen // unsafe-performance
581-
public struct UnsafeMutablePointer<Pointee>
582-
: _Pointer, @unchecked _BitwiseCopyable {
581+
public struct UnsafeMutablePointer<Pointee>: _Pointer {
583582

584583
/// A type that represents the distance between two pointers.
585584
public typealias Distance = Int

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
/// let numberPointer = UnsafeRawPointer(&number)
170170
/// // Accessing 'numberPointer' is undefined behavior.
171171
@frozen
172-
public struct UnsafeRawPointer: _Pointer, @unchecked _BitwiseCopyable {
172+
public struct UnsafeRawPointer: _Pointer {
173173

174174
public typealias Pointee = UInt8
175175

@@ -727,7 +727,7 @@ extension UnsafeRawPointer {
727727
/// let numberPointer = UnsafeMutableRawPointer(&number)
728728
/// // Accessing 'numberPointer' is undefined behavior.
729729
@frozen
730-
public struct UnsafeMutableRawPointer: _Pointer, @unchecked _BitwiseCopyable {
730+
public struct UnsafeMutableRawPointer: _Pointer {
731731

732732
public typealias Pointee = UInt8
733733

test/Sema/bitwise_copyable.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,6 @@ struct S_Explicit_With_Metatype_Optional_AnyObject : _BitwiseCopyable {
9696
var ty: Optional<AnyObject>.Type
9797
}
9898

99-
struct S_Unchecked : @unchecked _BitwiseCopyable {}
100-
101-
struct S_Implicit_With_S_Unchecked {
102-
var s: S_Unchecked
103-
}
104-
105-
func passS_Implicit_With_S_Unchecked(_ s: S_Implicit_With_S_Unchecked) {
106-
take1(s) // expected-error{{type_does_not_conform_decl_owner}}
107-
// expected-note@-92 {{where_requirement_failure_one_subst}}
108-
}
109-
110-
struct S_Explicit_With_S_Unchecked : _BitwiseCopyable {
111-
var s: S_Unchecked
112-
}
113-
11499
//==============================================================================
115100
//===========================DEPENDENCY-FREE TESTS=(END)======================}}
116101
//==============================================================================

test/SourceKit/DocSupport/doc_clang_module.swift.response

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5654,11 +5654,6 @@ var FooSubUnnamedEnumeratorA1: Int { get }
56545654
key.kind: source.lang.swift.ref.protocol,
56555655
key.name: "_Pointer",
56565656
key.usr: "s:s8_PointerP"
5657-
},
5658-
{
5659-
key.kind: source.lang.swift.ref.protocol,
5660-
key.name: "_BitwiseCopyable",
5661-
key.usr: "s:s16_BitwiseCopyableP"
56625657
}
56635658
]
56645659
},

0 commit comments

Comments
 (0)