Skip to content

SILGen: Cleanup visitMakeTemporarilyEscapableExpr #15402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5482,47 +5482,35 @@ RValue RValueEmitter::visitMakeTemporarilyEscapableExpr(
auto escapingFnTy = SGF.getLoweredType(E->getOpaqueValue()->getType());
auto silFnTy = escapingFnTy.castTo<SILFunctionType>();

// Handle @convention(block). No withoutActuallyEscaping verification yet.
if (silFnTy->getExtInfo().getRepresentation() !=
SILFunctionTypeRepresentation::Thick) {
RValue rvalue;
auto escapingClosure =
SGF.emitManagedRValueWithCleanup(SGF.B.createConvertFunction(
E, functionValue.ensurePlusOne(SGF, E).forward(SGF), escapingFnTy));
auto visitSubExpr = [&](ManagedValue escapingClosure,
bool isClosureConsumable) -> RValue {
// Bind the opaque value to the escaping function.
SILGenFunction::OpaqueValueState opaqueValue{
escapingClosure,
/*consumable*/ true,
/*consumable*/ isClosureConsumable,
/*hasBeenConsumed*/ false,
};
SILGenFunction::OpaqueValueRAII pushOpaqueValue(SGF, E->getOpaqueValue(),
opaqueValue);

// Emit the guarded expression.
rvalue = visit(E->getSubExpr(), C);
return rvalue;
return visit(E->getSubExpr(), C);
};

// Handle @convention(block). No withoutActuallyEscaping verification yet.
if (silFnTy->getExtInfo().getRepresentation() !=
SILFunctionTypeRepresentation::Thick) {
auto escapingClosure =
SGF.B.createConvertFunction(E, functionValue, escapingFnTy);
return visitSubExpr(escapingClosure, true /*isClosureConsumable*/);
}

// Convert it to an escaping function value.
auto escapingClosure =
SGF.createWithoutActuallyEscapingClosure(E, functionValue, escapingFnTy);

RValue rvalue;
auto loc = SILLocation(E);
auto borrowedClosure = escapingClosure.borrow(SGF, loc);
{
// Bind the opaque value to the escaping function.
SILGenFunction::OpaqueValueState opaqueValue{
borrowedClosure,
/*consumable*/ false,
/*hasBeenConsumed*/ false,
};
SILGenFunction::OpaqueValueRAII pushOpaqueValue(SGF, E->getOpaqueValue(),
opaqueValue);

// Emit the guarded expression.
rvalue = visit(E->getSubExpr(), C);
}
RValue rvalue = visitSubExpr(borrowedClosure, false /* isClosureConsumable */);

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