Skip to content

Commit 1081d1e

Browse files
committed
Assert that there are no unexpected forwarding instructions when matching destroy_value to partial_apply [stack]
1 parent cf81c20 commit 1081d1e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,11 +1681,11 @@ static bool visitRecursivelyLifetimeEndingUses(
16811681

16821682
// There shouldn't be any dead-end consumptions of a nonescaping
16831683
// partial_apply that don't forward it along, aside from destroy_value.
1684-
assert(use->getUser()->hasResults());
1685-
for (auto result : use->getUser()->getResults()) {
1686-
if (!visitRecursivelyLifetimeEndingUses(result, noUsers, func)) {
1687-
return false;
1688-
}
1684+
assert(use->getUser()->hasResults()
1685+
&& use->getUser()->getNumResults() == 1);
1686+
if (!visitRecursivelyLifetimeEndingUses(use->getUser()->getResult(0),
1687+
noUsers, func)) {
1688+
return false;
16891689
}
16901690
}
16911691
return true;
@@ -1721,7 +1721,8 @@ DestroyValueInst::getNonescapingClosureAllocation() const {
17211721
if (auto mdi = dyn_cast<MarkDependenceInst>(operand)) {
17221722
operand = mdi->getValue();
17231723
continue;
1724-
} else if (isa<ConvertEscapeToNoEscapeInst>(operand)) {
1724+
} else if (isa<ConvertEscapeToNoEscapeInst>(operand)
1725+
|| isa<ThinToThickFunctionInst>(operand)) {
17251726
// Stop at a conversion from escaping closure, since there's no stack
17261727
// allocation in that case.
17271728
return nullptr;
@@ -1739,8 +1740,13 @@ DestroyValueInst::getNonescapingClosureAllocation() const {
17391740
// The original partial_apply instruction should only be forwarded
17401741
// through one of the above instructions. Anything else should lead us
17411742
// to a copy or borrow of the closure from somewhere else.
1742-
// TODO: Assert that this is one of those cases, such as a SILArgument,
1743-
// copy_value, etc.
1743+
assert((isa<CopyValueInst>(operand)
1744+
|| isa<SILArgument>(operand)
1745+
|| isa<DifferentiableFunctionInst>(operand)
1746+
|| isa<DifferentiableFunctionExtractInst>(operand)
1747+
|| isa<LoadInst>(operand)
1748+
|| (operand->dump(), false))
1749+
&& "unexpected forwarding instruction for noescape closure");
17441750
return nullptr;
17451751
}
17461752
}

0 commit comments

Comments
 (0)