Skip to content

Commit 3d54cac

Browse files
committed
[BitwiseCopyable] Loosen validation assertion.
A function can return `some BitwiseCopyable`. The resulting value is (currently) non-trivial but conforms to `BitwiseCopyable`. rdar://125443922
1 parent f46e58a commit 3d54cac

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3205,9 +3205,10 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32053205

32063206
if (!lowering.isTrivial() && conformance) {
32073207
// A non-trivial type can have a conformance in a few cases:
3208-
// (1) contains a conforming archetype
3208+
// (1) containing or being a conforming archetype
32093209
// (2) is resilient with minimal expansion
32103210
// (3) containing or being ~Escapable
3211+
// (4) containing or being an opaque archetype
32113212
bool hasNoConformingArchetypeNode = visitAggregateLeaves(
32123213
origType, substType, forExpansion,
32133214
/*isLeaf=*/
@@ -3256,6 +3257,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32563257
if (origTy.isTypeParameter())
32573258
return false;
32583259

3260+
// An opaque archetype may conform but be non-trivial (case (4)).
3261+
if (isa<OpaqueTypeArchetypeType>(ty)) {
3262+
return false;
3263+
}
3264+
32593265
return true;
32603266
});
32613267
if (hasNoConformingArchetypeNode) {

test/SILGen/bitwise_copyable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ public enum E : _BitwiseCopyable {
4747
func take<T : _BitwiseCopyable>(_ t: T) {}
4848

4949
func pass(_ e: E) { take(e) }
50+
51+
func opacify() -> some _BitwiseCopyable {
52+
return Int()
53+
}

0 commit comments

Comments
 (0)