Skip to content

Commit a391043

Browse files
authored
Merge pull request #59260 from amritpan/multi-statement-closure-output
[CSApply] Fixed type-checked subexpression output bug for multi-state…
2 parents 63a4114 + d7266d6 commit a391043

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8152,6 +8152,11 @@ namespace {
81528152
return false;
81538153
}
81548154

8155+
/// Check if there are any closures or tap expressions left to process separately.
8156+
bool hasDelayedTasks() {
8157+
return !ClosuresToTypeCheck.empty() || !TapsToTypeCheck.empty();
8158+
}
8159+
81558160
/// Process delayed closure bodies and `Tap` expressions.
81568161
///
81578162
/// \returns true if any part of the processing fails.
@@ -9015,8 +9020,31 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
90159020
result.setExpr(resultExpr);
90169021

90179022
if (cs.isDebugMode()) {
9023+
// If target is a multi-statement closure or
9024+
// a tap expression, expression will not be fully
9025+
// type checked until these expressions are visited in
9026+
// processDelayed().
9027+
bool isPartial = false;
9028+
resultExpr->forEachChildExpr([&](Expr *child) -> Expr * {
9029+
if (auto *closure = dyn_cast<ClosureExpr>(child)) {
9030+
if (!closure->hasSingleExpressionBody()) {
9031+
isPartial = true;
9032+
return nullptr;
9033+
}
9034+
}
9035+
if (isa<TapExpr>(child)) {
9036+
isPartial = true;
9037+
return nullptr;
9038+
}
9039+
return child;
9040+
});
9041+
90189042
auto &log = llvm::errs();
9019-
log << "---Type-checked expression---\n";
9043+
if (isPartial) {
9044+
log << "---Partially type-checked expression---\n";
9045+
} else {
9046+
log << "---Type-checked expression---\n";
9047+
}
90209048
resultExpr->dump(log);
90219049
log << "\n";
90229050
}
@@ -9069,6 +9097,8 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90699097
if (!resultTarget)
90709098
return None;
90719099

9100+
auto needsPostProcessing = walker.hasDelayedTasks();
9101+
90729102
// Visit closures that have non-single expression bodies, tap expressions,
90739103
// and possibly other types of AST nodes which could only be processed
90749104
// after contextual expression.
@@ -9077,7 +9107,18 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90779107
// If any of them failed to type check, bail.
90789108
if (hadError)
90799109
return None;
9080-
9110+
9111+
if (isDebugMode()) {
9112+
// If we had partially type-checked expressions, lets print
9113+
// fully type-checked expression after processDelayed is done.
9114+
if (needsPostProcessing) {
9115+
auto &log = llvm::errs();
9116+
log << "---Fully type-checked expression---\n";
9117+
resultTarget->getAsExpr()->dump(log);
9118+
log << "\n";
9119+
}
9120+
}
9121+
90819122
rewriter.finalize();
90829123

90839124
return resultTarget;

0 commit comments

Comments
 (0)