Skip to content

Commit 38d6ea8

Browse files
author
Amritpan Kaur
committed
[CSApply] changes.
1 parent 3a38d7a commit 38d6ea8

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

lib/Sema/CSApply.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8151,6 +8151,11 @@ namespace {
81518151
// with already-type-checked expressions. Don't walk into them.
81528152
return false;
81538153
}
8154+
8155+
/// Check if there are any closures or tap expressions left to process.
8156+
bool shouldPrintFullyChecked() {
8157+
return ClosuresToTypeCheck.empty() && TapsToTypeCheck.empty();
8158+
}
81548159

81558160
/// Process delayed closure bodies and `Tap` expressions.
81568161
///
@@ -8995,14 +9000,31 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
89959000
if (cs.isDebugMode()) {
89969001
// If target is a multi-statement closure or
89979002
// a tap expression, expression will not be fully
8998-
// type checked until these types are visited in
9003+
// type checked until these expressions are visited in
89999004
// processDelayed().
9005+
bool isPartial = false;
9006+
resultExpr->forEachChildExpr([&](Expr *child) -> Expr * {
9007+
if (auto *closure = dyn_cast<ClosureExpr>(child)) {
9008+
if (!closure->hasSingleExpressionBody()) {
9009+
isPartial = true;
9010+
return nullptr;
9011+
}
9012+
}
9013+
if (isa<TapExpr>(child)) {
9014+
isPartial = true;
9015+
return nullptr;
9016+
}
9017+
return child;
9018+
});
9019+
90009020
auto &log = llvm::errs();
9001-
if (!ClosuresToTypeCheck.empty() || !TapsToTypeCheck.empty()) {
9021+
if (isPartial) {
90029022
log << "---Partially type-checked expression---\n";
9003-
resultExpr->dump(log);
9004-
log << "\n";
9023+
} else {
9024+
log << "---Type-checked expression---\n";
90059025
}
9026+
resultExpr->dump(log);
9027+
log << "\n";
90069028
}
90079029
}
90089030

@@ -9052,7 +9074,7 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90529074
auto resultTarget = walker.rewriteTarget(target);
90539075
if (!resultTarget)
90549076
return None;
9055-
9077+
90569078
// Visit closures that have non-single expression bodies, tap expressions,
90579079
// and possibly other types of AST nodes which could only be processed
90589080
// after contextual expression.
@@ -9061,16 +9083,18 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90619083
// If any of them failed to type check, bail.
90629084
if (hadError)
90639085
return None;
9064-
9065-
rewriter.finalize();
90669086

9067-
if (isDebugMode()) {
9087+
// If there are no more closures or tap expressions to check,
9088+
// print expression.
9089+
if (walker.shouldPrintFullyChecked()) {
90689090
auto &log = llvm::errs();
90699091
log << "---Fully type-checked expression---\n";
90709092
resultTarget->getAsExpr()->dump(log);
90719093
log << "\n";
90729094
}
90739095

9096+
rewriter.finalize();
9097+
90749098
return resultTarget;
90759099
}
90769100

0 commit comments

Comments
 (0)