Skip to content

Commit 3f933d0

Browse files
authored
Merge pull request swiftlang#63315 from jckarter/withoutActuallyEscaping-not-actually-escaping-param
Coerce the parameter of the parameter to `withoutActuallyEscaping` to actually be escaping.
2 parents d5446cf + 5e46ca5 commit 3f933d0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7804,18 +7804,27 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
78047804
auto *body = args->getExpr(1);
78057805
auto bodyTy = cs.getType(body)->getWithoutSpecifierType();
78067806
auto bodyFnTy = bodyTy->castTo<FunctionType>();
7807-
auto escapableParams = bodyFnTy->getParams();
78087807
auto resultType = bodyFnTy->getResult();
78097808

78107809
// The body is immediately called, so is obviously noescape.
7810+
// Coerce the argument function to be escaping even if it happens to
7811+
// be nonescaping, since we need the dynamic state of the escaping
7812+
// closure to do the dynamic noescape check.
7813+
auto bodyArgFnTy = bodyFnTy->getParams()[0].getPlainType()
7814+
->castTo<FunctionType>();
7815+
7816+
bodyArgFnTy = cast<FunctionType>(
7817+
bodyArgFnTy->withExtInfo(bodyArgFnTy->getExtInfo().withNoEscape(false)));
78117818
bodyFnTy = cast<FunctionType>(
7812-
bodyFnTy->withExtInfo(bodyFnTy->getExtInfo().withNoEscape()));
7819+
FunctionType::get(bodyFnTy->getParams()[0].withType(bodyArgFnTy),
7820+
bodyFnTy->getResult())
7821+
->withExtInfo(bodyFnTy->getExtInfo().withNoEscape()));
78137822
body = coerceToType(body, bodyFnTy, locator);
78147823
assert(body && "can't make nonescaping?!");
78157824

78167825
auto escapable = new (ctx)
78177826
OpaqueValueExpr(apply->getFn()->getSourceRange(), Type());
7818-
cs.setType(escapable, escapableParams[0].getOldType());
7827+
cs.setType(escapable, bodyArgFnTy);
78197828

78207829
auto *argList = ArgumentList::forImplicitUnlabeled(ctx, {escapable});
78217830
auto callSubExpr = CallExpr::createImplicit(ctx, body, argList);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-emit-silgen -verify %s
2+
3+
func foo(_ f: (() -> Void) -> Void, _ b: () -> Void) {
4+
return withoutActuallyEscaping(b, do: f)
5+
}

0 commit comments

Comments
 (0)