@@ -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.
@@ -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
@@ -9053,6 +9075,8 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90539075 if (!resultTarget)
90549076 return None;
90559077
9078+ auto needsPostProcessing = walker.hasDelayedTasks ();
9079+
90569080 // Visit closures that have non-single expression bodies, tap expressions,
90579081 // and possibly other types of AST nodes which could only be processed
90589082 // after contextual expression.
@@ -9061,15 +9085,19 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
90619085 // If any of them failed to type check, bail.
90629086 if (hadError)
90639087 return None;
9064-
9065- rewriter.finalize ();
90669088
90679089 if (isDebugMode ()) {
9068- auto &log = llvm::errs ();
9069- log << " ---Fully type-checked expression---\n " ;
9070- resultTarget->getAsExpr ()->dump (log);
9071- log << " \n " ;
9090+ // If we had partially type-checked expressions, lets print
9091+ // fully type-checked expression after processDelayed is done.
9092+ if (needsPostProcessing) {
9093+ auto &log = llvm::errs ();
9094+ log << " ---Fully type-checked expression---\n " ;
9095+ resultTarget->getAsExpr ()->dump (log);
9096+ log << " \n " ;
9097+ }
90729098 }
9099+
9100+ rewriter.finalize ();
90739101
90749102 return resultTarget;
90759103}
0 commit comments