Skip to content

Update assertion for partial_apply [on_stack] lifetime ends in lifetime completion #65198

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
Apr 15, 2023
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
9 changes: 7 additions & 2 deletions include/swift/SIL/OwnershipUseVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,14 @@ bool OwnershipUseVisitor<Impl>::visitInnerBorrowScopeEnd(Operand *borrowEnd) {
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
}
case OperandOwnership::DestroyingConsume: {
// partial_apply [on_stack] can introduce borrowing operand and can have destroy_value consumes.
// partial_apply [on_stack] can introduce borrowing operand and can have
// destroy_value consumes.
auto *pai = dyn_cast<PartialApplyInst>(borrowEnd->get());
assert(pai && pai->isOnStack());
// TODO: When we have ForwardingInstruction abstraction, walk the use-def
// chain to ensure we have a partial_apply [on_stack] def.
assert(pai && pai->isOnStack() ||
OwnershipForwardingMixin::get(
cast<SingleValueInstruction>(borrowEnd->get())));
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
}

Expand Down
20 changes: 19 additions & 1 deletion test/SILOptimizer/ossa_lifetime_completion.sil
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bb10:
sil @foo : $@convention(thin) (@guaranteed C) -> ()

// Ensure no assert fires while handling lifetime end of partial_apply
sil [ossa] @testPartialApplyStack : $@convention(thin) (@guaranteed C) -> () {
sil [ossa] @testPartialApplyStack1 : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : @guaranteed $C):
test_specification "ossa-lifetime-completion @instruction[0]"
%8 = copy_value %0 : $C
Expand All @@ -194,3 +194,21 @@ bb3:
return %180 : $()
}

// Ensure no assert fires while handling lifetime end of partial_apply
sil [ossa] @testPartialApplyStack2 : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : @guaranteed $C):
test_specification "ossa-lifetime-completion @instruction[1]"
%2 = alloc_stack $C
%3 = copy_value %0 : $C
%4 = begin_borrow %3 : $C
%5 = function_ref @foo : $@convention(thin) (@guaranteed C) -> ()
%6 = partial_apply [callee_guaranteed] [on_stack] %5(%4) : $@convention(thin) (@guaranteed C) -> ()
%7 = mark_dependence %6 : $@noescape @callee_guaranteed () -> () on %2 : $*C
destroy_value %7 : $@noescape @callee_guaranteed () -> ()
end_borrow %4 : $C
destroy_value %3 : $C
dealloc_stack %2 : $*C
%12 = tuple ()
return %12 : $()
}