Skip to content

[6.1] Fix SILGenFunction::emitValueConstructor for library evolution. #78569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/SILGen/SILGenConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,14 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {

auto cleanupLoc = CleanupLocation(ctor);

if (selfLV.getType().isMoveOnly()) {
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
cleanupLoc, selfLV,
MarkUnresolvedNonCopyableValueInst::CheckKind::
AssignableButNotConsumable);
}
if (!F.getConventions().hasIndirectSILResults()) {
// Otherwise, load and return the final 'self' value.
if (selfLV.getType().isMoveOnly()) {
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
cleanupLoc, selfLV,
MarkUnresolvedNonCopyableValueInst::CheckKind::
AssignableButNotConsumable);
}

selfValue = lowering.emitLoad(B, cleanupLoc, selfLV.getValue(),
LoadOwnershipQualifier::Copy);

Expand Down
13 changes: 13 additions & 0 deletions test/SILGen/moveonly_library_evolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ func useUsableFromInlineTestKlass() {
let k = UsableFromInlineTestKlass()
k.e = E()
}

// rdar://142690658 (In ~Copyable public struct, an init with COW type param causes compiler error)
//
// CHECK-LABEL: sil hidden [ossa] @$s26moveonly_library_evolution19NonCopyableWithInitV1sACSS_tcfC :
// CHECK-SAME: $@convention(method) (@owned String, @thin NonCopyableWithInit.Type) -> @out NonCopyableWithInit {
// CHECK: bb0(%0 : $*NonCopyableWithInit, %1 : @owned $String, %2 : $@thin NonCopyableWithInit.Type):
// CHECK: [[BOX:%.*]] = project_box %{{.*}} : ${ var NonCopyableWithInit }, 0
// CHECK: store %{{.*}} to [init] [[BOX]]
// CHECK: [[MD:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[BOX]]
// CHECK: copy_addr [[MD]] to [init] %0
public struct NonCopyableWithInit: ~Copyable {
init(s: String) {}
}