Skip to content

Commit fe075dc

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)
1 parent eb07814 commit fe075dc

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/SILGen/SILGenConstructor.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,14 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
773773

774774
auto cleanupLoc = CleanupLocation(ctor);
775775

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

test/SILGen/moveonly_library_evolution.swift

+13
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 %{{.*}}, 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)