Skip to content

[LifetimeCompletion] Handle owned project_box. #72595

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
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
5 changes: 5 additions & 0 deletions include/swift/SIL/OwnershipUseVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ bool OwnershipUseVisitor<Impl>::visitOwnedUse(Operand *use) {
return handleUsePoint(use, UseLifetimeConstraint::LifetimeEnding);

case OperandOwnership::PointerEscape:
// TODO: Change ProjectBox ownership to InteriorPointer and allow them to
// take owned values.
if (isa<ProjectBoxInst>(use->getUser())) {
return visitInteriorPointerUses(use);
}
if (!asImpl().handlePointerEscape(use))
return false;

Expand Down
41 changes: 41 additions & 0 deletions test/SILOptimizer/ossa_lifetime_completion.sil
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,44 @@ bb0(%0 : @owned $C):
store %0 to [init] %4 : $*C
unreachable
}

indirect enum IndirectEnumNontrivialPayload {
case c(C)
}

// CHECK-LABEL: sil [ossa] @project_box_owned : {{.*}} {
// CHECK: bb0([[IE:%[^,]+]] :
// CHECK: switch_enum [[IE]]
// CHECK-SAME: case #IndirectEnumNontrivialPayload.c!enumelt: [[ONE_CASE:bb[0-9]+]]
// CHECK: [[ONE_CASE]]([[BOX:%[^,]+]] :
// CHECK: [[C_ADDR:%[^,]+]] = project_box [[BOX]]
// CHECK: [[C:%[^,]+]] = load_borrow [[C_ADDR]]
// CHECK: cond_br undef, {{bb[0-9]+}}, [[BASIC_BLOCK4:bb[0-9]+]]
// CHECK: [[BASIC_BLOCK4]]:
// CHECK: end_borrow [[C]]
// CHECK: destroy_value [[BOX]]
// CHECK: unreachable
// CHECK-LABEL: } // end sil function 'project_box_owned'
sil [ossa] @project_box_owned : $@convention(thin) (@owned IndirectEnumNontrivialPayload) -> () {
entry(%ie : @owned $IndirectEnumNontrivialPayload):
switch_enum %ie : $IndirectEnumNontrivialPayload, case #IndirectEnumNontrivialPayload.c!enumelt: one_case

one_case(%box : @owned ${ var C }):
specify_test "ossa-lifetime-completion %box"
%c_addr = project_box %box : ${ var C }, 0
%c = load_borrow %c_addr : $*C
cond_br undef, left, right

left:
end_borrow %c : $C
destroy_value %box : ${ var C }
br exit

exit:
%retval = tuple ()
return %retval : $()

right:
end_borrow %c : $C
unreachable
}