@@ -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.
@@ -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
@@ -9053,6 +9075,8 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9053
9075
if (!resultTarget)
9054
9076
return None;
9055
9077
9078
+ auto needsPostProcessing = walker.hasDelayedTasks ();
9079
+
9056
9080
// Visit closures that have non-single expression bodies, tap expressions,
9057
9081
// and possibly other types of AST nodes which could only be processed
9058
9082
// after contextual expression.
@@ -9061,15 +9085,19 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
9061
9085
// If any of them failed to type check, bail.
9062
9086
if (hadError)
9063
9087
return None;
9064
-
9065
- rewriter.finalize ();
9066
9088
9067
9089
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
+ }
9072
9098
}
9099
+
9100
+ rewriter.finalize ();
9073
9101
9074
9102
return resultTarget;
9075
9103
}
0 commit comments