Skip to content

Commit 7e797a1

Browse files
Merge pull request #15402 from aschwaighofer/silgen_cleanup_without_actually_escaping
SILGen: Cleanup visitMakeTemporarilyEscapableExpr
2 parents e4679cb + 3fe9472 commit 7e797a1

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,47 +5482,35 @@ RValue RValueEmitter::visitMakeTemporarilyEscapableExpr(
54825482
auto escapingFnTy = SGF.getLoweredType(E->getOpaqueValue()->getType());
54835483
auto silFnTy = escapingFnTy.castTo<SILFunctionType>();
54845484

5485-
// Handle @convention(block). No withoutActuallyEscaping verification yet.
5486-
if (silFnTy->getExtInfo().getRepresentation() !=
5487-
SILFunctionTypeRepresentation::Thick) {
5488-
RValue rvalue;
5489-
auto escapingClosure =
5490-
SGF.emitManagedRValueWithCleanup(SGF.B.createConvertFunction(
5491-
E, functionValue.ensurePlusOne(SGF, E).forward(SGF), escapingFnTy));
5485+
auto visitSubExpr = [&](ManagedValue escapingClosure,
5486+
bool isClosureConsumable) -> RValue {
54925487
// Bind the opaque value to the escaping function.
54935488
SILGenFunction::OpaqueValueState opaqueValue{
54945489
escapingClosure,
5495-
/*consumable*/ true,
5490+
/*consumable*/ isClosureConsumable,
54965491
/*hasBeenConsumed*/ false,
54975492
};
54985493
SILGenFunction::OpaqueValueRAII pushOpaqueValue(SGF, E->getOpaqueValue(),
54995494
opaqueValue);
55005495

55015496
// Emit the guarded expression.
5502-
rvalue = visit(E->getSubExpr(), C);
5503-
return rvalue;
5497+
return visit(E->getSubExpr(), C);
5498+
};
5499+
5500+
// Handle @convention(block). No withoutActuallyEscaping verification yet.
5501+
if (silFnTy->getExtInfo().getRepresentation() !=
5502+
SILFunctionTypeRepresentation::Thick) {
5503+
auto escapingClosure =
5504+
SGF.B.createConvertFunction(E, functionValue, escapingFnTy);
5505+
return visitSubExpr(escapingClosure, true /*isClosureConsumable*/);
55045506
}
55055507

55065508
// Convert it to an escaping function value.
55075509
auto escapingClosure =
55085510
SGF.createWithoutActuallyEscapingClosure(E, functionValue, escapingFnTy);
5509-
5510-
RValue rvalue;
55115511
auto loc = SILLocation(E);
55125512
auto borrowedClosure = escapingClosure.borrow(SGF, loc);
5513-
{
5514-
// Bind the opaque value to the escaping function.
5515-
SILGenFunction::OpaqueValueState opaqueValue{
5516-
borrowedClosure,
5517-
/*consumable*/ false,
5518-
/*hasBeenConsumed*/ false,
5519-
};
5520-
SILGenFunction::OpaqueValueRAII pushOpaqueValue(SGF, E->getOpaqueValue(),
5521-
opaqueValue);
5522-
5523-
// Emit the guarded expression.
5524-
rvalue = visit(E->getSubExpr(), C);
5525-
}
5513+
RValue rvalue = visitSubExpr(borrowedClosure, false /* isClosureConsumable */);
55265514

55275515
// Now create the verification of the withoutActuallyEscaping operand.
55285516
// Either we fail the uniquenes check (which means the closure has escaped)

0 commit comments

Comments
 (0)