Skip to content

Commit 2c8373c

Browse files
meg-guptanate-chandler
authored andcommitted
Update assertion for partial_apply [on_stack] lifetime ends in lifetime completion
Since partial_apply [on_stack] is considered as a BorrowingOperand now, and BorrowingOperand::visitScopeEndingUses can be called on the its forwarded values lifetime ends, update the assertion to reflect this.
1 parent 7680a91 commit 2c8373c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

include/swift/SIL/OwnershipUseVisitor.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,14 @@ bool OwnershipUseVisitor<Impl>::visitInnerBorrowScopeEnd(Operand *borrowEnd) {
290290
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
291291
}
292292
case OperandOwnership::DestroyingConsume: {
293-
// partial_apply [on_stack] can introduce borrowing operand and can have destroy_value consumes.
293+
// partial_apply [on_stack] can introduce borrowing operand and can have
294+
// destroy_value consumes.
294295
auto *pai = dyn_cast<PartialApplyInst>(borrowEnd->get());
295-
assert(pai && pai->isOnStack());
296+
// TODO: When we have ForwardingInstruction abstraction, walk the use-def
297+
// chain to ensure we have a partial_apply [on_stack] def.
298+
assert(pai && pai->isOnStack() ||
299+
OwnershipForwardingMixin::get(
300+
cast<SingleValueInstruction>(borrowEnd->get())));
296301
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
297302
}
298303

test/SILOptimizer/ossa_lifetime_completion.sil

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bb10:
171171
sil @foo : $@convention(thin) (@guaranteed C) -> ()
172172

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

197+
// Ensure no assert fires while handling lifetime end of partial_apply
198+
sil [ossa] @testPartialApplyStack2 : $@convention(thin) (@guaranteed C) -> () {
199+
bb0(%0 : @guaranteed $C):
200+
test_specification "ossa-lifetime-completion @instruction[1]"
201+
%2 = alloc_stack $C
202+
%3 = copy_value %0 : $C
203+
%4 = begin_borrow %3 : $C
204+
%5 = function_ref @foo : $@convention(thin) (@guaranteed C) -> ()
205+
%6 = partial_apply [callee_guaranteed] [on_stack] %5(%4) : $@convention(thin) (@guaranteed C) -> ()
206+
%7 = mark_dependence %6 : $@noescape @callee_guaranteed () -> () on %2 : $*C
207+
destroy_value %7 : $@noescape @callee_guaranteed () -> ()
208+
end_borrow %4 : $C
209+
destroy_value %3 : $C
210+
dealloc_stack %2 : $*C
211+
%12 = tuple ()
212+
return %12 : $()
213+
}
214+

0 commit comments

Comments
 (0)