Skip to content

Commit 7601283

Browse files
committed
Fix SILGenFunction::emitValueConstructor for library evolution.
Always call createMarkUnresolvedNonCopyableValueInst for a constructor with move-only 'self'. Handle 'self' that is either returned by value or as an indirect result Fixes rdar://142690658 (In ~Copyable public struct, an init with COW type param causes compiler error) (cherry picked from commit f05a8fa)
1 parent 2b28374 commit 7601283

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,14 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
772772

773773
auto cleanupLoc = CleanupLocation(ctor);
774774

775+
if (selfLV.getType().isMoveOnly()) {
776+
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
777+
cleanupLoc, selfLV,
778+
MarkUnresolvedNonCopyableValueInst::CheckKind::
779+
AssignableButNotConsumable);
780+
}
775781
if (!F.getConventions().hasIndirectSILResults()) {
776782
// Otherwise, load and return the final 'self' value.
777-
if (selfLV.getType().isMoveOnly()) {
778-
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
779-
cleanupLoc, selfLV,
780-
MarkUnresolvedNonCopyableValueInst::CheckKind::
781-
AssignableButNotConsumable);
782-
}
783-
784783
selfValue = lowering.emitLoad(B, cleanupLoc, selfLV.getValue(),
785784
LoadOwnershipQualifier::Copy);
786785

test/SILGen/moveonly_library_evolution.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,16 @@ func useUsableFromInlineTestKlass() {
106106
let k = UsableFromInlineTestKlass()
107107
k.e = E()
108108
}
109+
110+
// rdar://142690658 (In ~Copyable public struct, an init with COW type param causes compiler error)
111+
//
112+
// CHECK-LABEL: sil hidden [ossa] @$s26moveonly_library_evolution19NonCopyableWithInitV1sACSS_tcfC :
113+
// CHECK-SAME: $@convention(method) (@owned String, @thin NonCopyableWithInit.Type) -> @out NonCopyableWithInit {
114+
// CHECK: bb0(%0 : $*NonCopyableWithInit, %1 : @owned $String, %2 : $@thin NonCopyableWithInit.Type):
115+
// CHECK: [[BOX:%.*]] = project_box %5, 0
116+
// CHECK: store %{{.*}} to [init] [[BOX]]
117+
// CHECK: [[MD:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[BOX]]
118+
// CHECK: copy_addr [[MD]] to [init] %0
119+
public struct NonCopyableWithInit: ~Copyable {
120+
init(s: String) {}
121+
}

0 commit comments

Comments
 (0)