Skip to content

Commit 71e0041

Browse files
Merge pull request #72313 from nate-chandler/rdar124552608
[BitwiseCopyable] Loosen validation assertion.
2 parents 4035b99 + f43d4f0 commit 71e0041

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,15 +3196,18 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31963196
if (hasNoNonconformingNode) {
31973197
llvm::errs() << "Trivial type without a BitwiseCopyable conformance!?:\n"
31983198
<< substType << "\n"
3199-
<< "of " << origType << "\n";
3199+
<< "of " << origType << "\n"
3200+
<< "Disable this validation with -Xllvm "
3201+
"-type-lowering-disable-verification.\n";
32003202
assert(false);
32013203
}
32023204
}
32033205

32043206
if (!lowering.isTrivial() && conformance) {
3205-
// A non-trivial type can have a conformance in one case:
3207+
// A non-trivial type can have a conformance in a few cases:
32063208
// (1) contains a conforming archetype
32073209
// (2) is resilient with minimal expansion
3210+
// (3) containing or being ~Escapable
32083211
bool hasNoConformingArchetypeNode = visitAggregateLeaves(
32093212
origType, substType, forExpansion,
32103213
/*isLeaf=*/
@@ -3217,6 +3220,12 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32173220
ResilienceExpansion::Minimal) {
32183221
return true;
32193222
}
3223+
// A type that may not be escapable is non-trivial but can conform
3224+
// (case (3)).
3225+
if (nominal &&
3226+
nominal->canBeEscapable() != TypeDecl::CanBeInvertible::Always) {
3227+
return true;
3228+
}
32203229
// Walk into every aggregate.
32213230
return false;
32223231
},
@@ -3236,6 +3245,13 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32363245
return false;
32373246
}
32383247

3248+
// A type that may not be escapable is non-trivial but can conform
3249+
// (case (3)).
3250+
if (nominal &&
3251+
nominal->canBeEscapable() != TypeDecl::CanBeInvertible::Always) {
3252+
return false;
3253+
}
3254+
32393255
// An archetype may conform but be non-trivial (case (1)).
32403256
if (origTy.isTypeParameter())
32413257
return false;
@@ -3246,7 +3262,9 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32463262
llvm::errs() << "Non-trivial type with _BitwiseCopyable conformance!?:\n"
32473263
<< substType << "\n";
32483264
conformance.print(llvm::errs());
3249-
llvm::errs() << "\n";
3265+
llvm::errs() << "\n"
3266+
<< "Disable this validation with -Xllvm "
3267+
"-type-lowering-disable-verification.\n";
32503268
assert(false);
32513269
}
32523270
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// R N: %target-swift-frontend -enable-experimental-feature NonescapableTypes -enable-experimental-feature BuiltinModule -enable-experimental-feature NoncopyableGenerics -parse-stdlib -module-name Swift -DEMPTY -emit-sil -verify %s
2+
3+
// RUN: %target-swift-frontend \
4+
// RUN: -emit-sil \
5+
// RUN: %s \
6+
// RUN: -parse-stdlib \
7+
// RUN: -module-name Swift \
8+
// RUN: -disable-availability-checking \
9+
// RUN: -enable-experimental-feature BuiltinModule \
10+
// RUN: -enable-experimental-feature BitwiseCopyable \
11+
// RUN: -enable-experimental-feature NoncopyableGenerics \
12+
// RUN: -enable-experimental-feature NonescapableTypes \
13+
// RUN: -enable-builtin-module
14+
15+
// REQUIRES: asserts
16+
17+
// Force verification of TypeLowering's isTrivial.
18+
19+
import Builtin
20+
21+
@_marker public protocol Copyable: ~Escapable {}
22+
@_marker public protocol Escapable: ~Copyable {}
23+
@_marker public protocol _BitwiseCopyable : ~Escapable {}
24+
25+
struct Storage : ~Escapable, _BitwiseCopyable {}
26+
27+
28+
func take<T : _BitwiseCopyable & ~Escapable>(_ t: T) {}
29+
30+
func passStorage(_ s: Storage) { take(s) }

0 commit comments

Comments
 (0)