@@ -5482,47 +5482,35 @@ RValue RValueEmitter::visitMakeTemporarilyEscapableExpr(
5482
5482
auto escapingFnTy = SGF.getLoweredType (E->getOpaqueValue ()->getType ());
5483
5483
auto silFnTy = escapingFnTy.castTo <SILFunctionType>();
5484
5484
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 {
5492
5487
// Bind the opaque value to the escaping function.
5493
5488
SILGenFunction::OpaqueValueState opaqueValue{
5494
5489
escapingClosure,
5495
- /* consumable*/ true ,
5490
+ /* consumable*/ isClosureConsumable ,
5496
5491
/* hasBeenConsumed*/ false ,
5497
5492
};
5498
5493
SILGenFunction::OpaqueValueRAII pushOpaqueValue (SGF, E->getOpaqueValue (),
5499
5494
opaqueValue);
5500
5495
5501
5496
// 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*/ );
5504
5506
}
5505
5507
5506
5508
// Convert it to an escaping function value.
5507
5509
auto escapingClosure =
5508
5510
SGF.createWithoutActuallyEscapingClosure (E, functionValue, escapingFnTy);
5509
-
5510
- RValue rvalue;
5511
5511
auto loc = SILLocation (E);
5512
5512
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 */ );
5526
5514
5527
5515
// Now create the verification of the withoutActuallyEscaping operand.
5528
5516
// Either we fail the uniquenes check (which means the closure has escaped)
0 commit comments