@@ -8151,6 +8151,11 @@ namespace {
8151
8151
// with already-type-checked expressions. Don't walk into them.
8152
8152
return false ;
8153
8153
}
8154
+
8155
+ // / Check if there are any closures or tap expressions left to process.
8156
+ bool shouldPrintFullyChecked () {
8157
+ return ClosuresToTypeCheck.empty () && TapsToTypeCheck.empty ();
8158
+ }
8154
8159
8155
8160
// / Process delayed closure bodies and `Tap` expressions.
8156
8161
// /
@@ -8995,14 +9000,31 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
8995
9000
if (cs.isDebugMode ()) {
8996
9001
// If target is a multi-statement closure or
8997
9002
// 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
8999
9004
// 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
+
9000
9020
auto &log = llvm::errs ();
9001
- if (!ClosuresToTypeCheck. empty () || !TapsToTypeCheck. empty () ) {
9021
+ if (isPartial ) {
9002
9022
log << " ---Partially type-checked expression---\n " ;
9003
- resultExpr-> dump (log);
9004
- log << " \n " ;
9023
+ } else {
9024
+ log << " ---Type-checked expression--- \n " ;
9005
9025
}
9026
+ resultExpr->dump (log);
9027
+ log << " \n " ;
9006
9028
}
9007
9029
}
9008
9030
@@ -9052,7 +9074,7 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9052
9074
auto resultTarget = walker.rewriteTarget (target);
9053
9075
if (!resultTarget)
9054
9076
return None;
9055
-
9077
+
9056
9078
// Visit closures that have non-single expression bodies, tap expressions,
9057
9079
// and possibly other types of AST nodes which could only be processed
9058
9080
// after contextual expression.
@@ -9061,16 +9083,18 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9061
9083
// If any of them failed to type check, bail.
9062
9084
if (hadError)
9063
9085
return None;
9064
-
9065
- rewriter.finalize ();
9066
9086
9067
- if (isDebugMode ()) {
9087
+ // If there are no more closures or tap expressions to check,
9088
+ // print expression.
9089
+ if (walker.shouldPrintFullyChecked ()) {
9068
9090
auto &log = llvm::errs ();
9069
9091
log << " ---Fully type-checked expression---\n " ;
9070
9092
resultTarget->getAsExpr ()->dump (log);
9071
9093
log << " \n " ;
9072
9094
}
9073
9095
9096
+ rewriter.finalize ();
9097
+
9074
9098
return resultTarget;
9075
9099
}
9076
9100
0 commit comments