@@ -6317,24 +6317,16 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6317
6317
// Coercion from one function type to another, this produces a
6318
6318
// FunctionConversionExpr in its full generality.
6319
6319
if (auto fromFunc = fromType->getAs <FunctionType>()) {
6320
- // If toType is a NoEscape or NoReturn function type and the expression is
6321
- // a ClosureExpr, propagate these bits onto the ClosureExpr. Do not
6322
- // *remove* any bits that are already on the closure though.
6323
- // Note that in this case, we do not want to propagate the 'throws' bit
6324
- // to the closure type, as the closure has already been analyzed for
6325
- // throwing subexpressions. We also don't want to change the convention
6326
- // of the original closure.
6320
+ // If we have a ClosureExpr, then we can safely propagate the 'no escape'
6321
+ // bit to the closure without invalidating prior analysis.
6327
6322
auto fromEI = fromFunc->getExtInfo (), toEI = toFunc->getExtInfo ();
6328
6323
if (toEI.isNoEscape () && !fromEI.isNoEscape ()) {
6329
- swift::AnyFunctionType::ExtInfo newEI (fromEI.getRepresentation (),
6330
- toEI.isAutoClosure (),
6331
- toEI.isNoEscape () | fromEI.isNoEscape (),
6332
- toEI.throws () & fromEI.throws ());
6333
- auto newToType = FunctionType::get (fromFunc->getInput (),
6334
- fromFunc->getResult (), newEI);
6335
- if (applyTypeToClosureExpr (cs, expr, newToType)) {
6336
- fromFunc = newToType;
6337
- // Propagating the bits in might have satisfied the entire
6324
+ auto newFromFunc = FunctionType::get (fromFunc->getInput (),
6325
+ fromFunc->getResult (),
6326
+ fromEI.withNoEscape ());
6327
+ if (applyTypeToClosureExpr (cs, expr, newFromFunc)) {
6328
+ fromFunc = newFromFunc;
6329
+ // Propagating the 'no escape' bit might have satisfied the entire
6338
6330
// conversion. If so, we're done, otherwise keep converting.
6339
6331
if (fromFunc->isEqual (toType))
6340
6332
return expr;
0 commit comments