@@ -8152,6 +8152,11 @@ namespace {
8152
8152
return false ;
8153
8153
}
8154
8154
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
+
8155
8160
// / Process delayed closure bodies and `Tap` expressions.
8156
8161
// /
8157
8162
// / \returns true if any part of the processing fails.
@@ -9015,8 +9020,31 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
9015
9020
result.setExpr (resultExpr);
9016
9021
9017
9022
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
+
9018
9042
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
+ }
9020
9048
resultExpr->dump (log);
9021
9049
log << " \n " ;
9022
9050
}
@@ -9069,6 +9097,8 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9069
9097
if (!resultTarget)
9070
9098
return None;
9071
9099
9100
+ auto needsPostProcessing = walker.hasDelayedTasks ();
9101
+
9072
9102
// Visit closures that have non-single expression bodies, tap expressions,
9073
9103
// and possibly other types of AST nodes which could only be processed
9074
9104
// after contextual expression.
@@ -9077,7 +9107,18 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9077
9107
// If any of them failed to type check, bail.
9078
9108
if (hadError)
9079
9109
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
+
9081
9122
rewriter.finalize ();
9082
9123
9083
9124
return resultTarget;
0 commit comments