Skip to content

Commit a6444b2

Browse files
authored
Merge pull request #12468 from davezarzycki/nfc_simplify_ClosureExpr_coercion
[Sema] NFC: Simplify type coercion of ClosureExprs
2 parents 88c5441 + 835906c commit a6444b2

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6317,24 +6317,16 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
63176317
// Coercion from one function type to another, this produces a
63186318
// FunctionConversionExpr in its full generality.
63196319
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.
63276322
auto fromEI = fromFunc->getExtInfo(), toEI = toFunc->getExtInfo();
63286323
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
63386330
// conversion. If so, we're done, otherwise keep converting.
63396331
if (fromFunc->isEqual(toType))
63406332
return expr;

0 commit comments

Comments
 (0)