[GenericSpecializer] Nest at inline+lower OSSA.

MandatoryGenericSpecializer inlines transparent functions that it
specializes.

Now that in OSSA `partial_apply [on_stack]`s are represented as owned
values rather than stack locations, it is possible for their destroys to
violate stack discipline.  A direct lowering of the instructions to
non-OSSA would violate stack nesting.

Previously, when inlining during MandatoryGenericSpecializer, it was
assumed that the callee maintained stack discipline.  And, when inlining
an OSSA function into a non-OSSA function, OSSA instructions were
lowered directly.  The result was that stack discipline would be
violated when directly lowering callees with `partial_apply [on_stack]`s
that violate stack discipline.

Here, when MandatoryGenericSpecializer inlines a specialized generic
function in OSSA form into a function lowered out of OSSA form, stack
nesting is fixed up.
This commit is contained in:
Nate Chandler
2023-03-01 15:26:47 -08:00
parent 3dae89e83e
commit 1dda30e6ba
2 changed files with 39 additions and 0 deletions

View File

@@ -353,6 +353,8 @@ optimizeInst(SILInstruction *inst, SILOptFunctionBuilder &funcBuilder,
// If the de-virtualized callee is a transparent function, inline it.
SILInliner::inlineFullApply(fas, SILInliner::InlineKind::MandatoryInline,
funcBuilder, deleter);
if (callee->hasOwnership() && !inst->getFunction()->hasOwnership())
invalidatedStackNesting = true;
return true;
}
if (auto *bi = dyn_cast<BuiltinInst>(inst)) {