Skip to content

Commit 63ed61d

Browse files
committed
Clean up AutoClosureExpr::getUnwrappedCurryThunkExpr().
Replace a hand-rolled variant of the subject function used for actor isolation checking with a call to it. This exposed some limitations of the function, which would assert() when dealing with partial applications that involved optionals. Fix those as well.
1 parent 37c3a52 commit 63ed61d

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

lib/AST/Expr.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,17 +2007,37 @@ Expr *AutoClosureExpr::getSingleExpressionBody() const {
20072007
}
20082008

20092009
Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
2010+
auto maybeUnwrapOpenExistential = [](Expr *expr) {
2011+
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
2012+
expr = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2013+
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(expr))
2014+
expr = ICE->getSyntacticSubExpr();
2015+
}
2016+
2017+
return expr;
2018+
};
2019+
2020+
auto maybeUnwrapOptionalEval = [](Expr *expr) {
2021+
if (auto optEval = dyn_cast<OptionalEvaluationExpr>(expr))
2022+
expr = optEval->getSubExpr();
2023+
if (auto inject = dyn_cast<InjectIntoOptionalExpr>(expr))
2024+
expr = inject->getSubExpr();
2025+
if (auto erasure = dyn_cast<ErasureExpr>(expr))
2026+
expr = erasure->getSubExpr();
2027+
if (auto bind = dyn_cast<BindOptionalExpr>(expr))
2028+
expr = bind->getSubExpr();
2029+
return expr;
2030+
};
2031+
20102032
switch (getThunkKind()) {
20112033
case AutoClosureExpr::Kind::None:
20122034
break;
20132035

20142036
case AutoClosureExpr::Kind::SingleCurryThunk: {
20152037
auto *body = getSingleExpressionBody();
20162038
body = body->getSemanticsProvidingExpr();
2017-
2018-
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(body)) {
2019-
body = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2020-
}
2039+
body = maybeUnwrapOpenExistential(body);
2040+
body = maybeUnwrapOptionalEval(body);
20212041

20222042
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
20232043
return outerCall->getFn();
@@ -2034,18 +2054,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
20342054
AutoClosureExpr::Kind::SingleCurryThunk);
20352055
auto *innerBody = innerClosure->getSingleExpressionBody();
20362056
innerBody = innerBody->getSemanticsProvidingExpr();
2037-
2038-
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(innerBody)) {
2039-
innerBody = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2040-
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(innerBody))
2041-
innerBody = ICE->getSyntacticSubExpr();
2042-
}
2057+
innerBody = maybeUnwrapOpenExistential(innerBody);
2058+
innerBody = maybeUnwrapOptionalEval(innerBody);
20432059

20442060
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
20452061
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {
2046-
if (auto *declRef = dyn_cast<DeclRefExpr>(innerCall->getFn())) {
2047-
return declRef;
2048-
}
2062+
return innerCall->getFn();
20492063
}
20502064
}
20512065
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,8 @@ static Optional<PartialApplyThunkInfo> decomposePartialApplyThunk(
358358
!= AutoClosureExpr::Kind::DoubleCurryThunk)
359359
return None;
360360

361-
// Check for the inner closure in the thunk.
362-
auto innerAutoclosure = dyn_cast<AutoClosureExpr>(
363-
outerAutoclosure->getSingleExpressionBody());
364-
if (!innerAutoclosure ||
365-
innerAutoclosure->getThunkKind()
366-
!= AutoClosureExpr::Kind::SingleCurryThunk)
367-
return None;
368-
369-
auto innerCall = dyn_cast<CallExpr>(
370-
innerAutoclosure->getSingleExpressionBody());
371-
if (!innerCall)
372-
return None;
373-
374-
auto memberCall = dyn_cast<DotSyntaxCallExpr>(innerCall->getFn());
375-
if (!memberCall)
361+
auto memberFn = outerAutoclosure->getUnwrappedCurryThunkExpr();
362+
if (!memberFn)
376363
return None;
377364

378365
// Determine whether the partial apply thunk was immediately converted to
@@ -383,8 +370,7 @@ static Optional<PartialApplyThunkInfo> decomposePartialApplyThunk(
383370
isEscaping = fnType && !fnType->isNoEscape();
384371
}
385372

386-
return PartialApplyThunkInfo{
387-
apply->getArg(), memberCall->getFn(), isEscaping};
373+
return PartialApplyThunkInfo{apply->getArg(), memberFn, isEscaping};
388374
}
389375

390376
/// Find the immediate member reference in the given expression.

0 commit comments

Comments
 (0)