Skip to content

Commit 40a0260

Browse files
Merge pull request #71738 from nate-chandler/noncopyable-bugs/20240219/1/implement-single-payload-enum-deinit
[IRGen] Noncopyable enums dont forward.
2 parents 0755fd3 + ca496e4 commit 40a0260

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,8 @@ namespace {
19531953
"extra inhabitant zero");
19541954

19551955
unsigned numTags = ElementsWithNoPayload.size();
1956-
if (payloadTI.canValueWitnessExtraInhabitantsUpTo(IGM, numTags-1)) {
1956+
if (payloadTI.canValueWitnessExtraInhabitantsUpTo(IGM, numTags - 1) &&
1957+
payloadTI.isCopyable(ResilienceExpansion::Maximal)) {
19571958
CopyDestroyKind = ForwardToPayload;
19581959
}
19591960
}

lib/IRGen/StructLayout.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ bool StructLayoutBuilder::addField(ElementLayout &elt,
387387
IsKnownBitwiseTakable &= eltTI.isBitwiseTakable(ResilienceExpansion::Maximal);
388388
IsKnownAlwaysFixedSize &= eltTI.isFixedSize(ResilienceExpansion::Minimal);
389389
IsLoadable &= eltTI.isLoadable();
390+
IsKnownCopyable &= eltTI.isCopyable(ResilienceExpansion::Maximal);
390391

391392
if (eltTI.isKnownEmpty(ResilienceExpansion::Maximal)) {
392393
addEmptyElement(elt);

lib/IRGen/TypeLayout.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,9 @@ void EnumTypeLayoutEntry::computeProperties() {
24192419

24202420
EnumTypeLayoutEntry::CopyDestroyStrategy
24212421
EnumTypeLayoutEntry::copyDestroyKind(IRGenModule &IGM) const {
2422-
if (isTriviallyDestroyable()) {
2422+
if (ty.isMoveOnly()) {
2423+
return Normal;
2424+
} else if (isTriviallyDestroyable()) {
24232425
return TriviallyDestroyable;
24242426
} else if (isSingleton()) {
24252427
return ForwardToPayload;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-emit-irgen \
2+
// RUN: -enable-experimental-feature NoncopyableGenerics \
3+
// RUN: %s \
4+
// RUN: | \
5+
// RUN: %FileCheck %s
6+
7+
// CHECK-LABEL: define{{.*}} void @"$s21moveonly_enum_deinits4ListOwxx"(
8+
// CHECK-SAME: ptr noalias %object,
9+
// CHECK-SAME: ptr %List)
10+
// CHECK: entry:
11+
// CHECK: br i1 {{%[^,]+}},
12+
// CHECK-SAME: label %[[EXIT:[^,]+]],
13+
// CHECK-SAME: label %[[PAYLOAD:[^,]+]]
14+
// CHECK: [[PAYLOAD]]:
15+
// CHECK: br label %[[EXIT]]
16+
// CHECK: [[EXIT]]:
17+
// CHECK: ret void
18+
// CHECK: }
19+
20+
struct Box<T : ~Copyable> : ~Copyable {
21+
public init(_ l: consuming T) {}
22+
23+
deinit {}
24+
}
25+
26+
enum List: ~Copyable {
27+
case end
28+
case more(Int, Box<List>)
29+
}

0 commit comments

Comments
 (0)