@@ -52,7 +52,8 @@ class BuilderClosureVisitor
52
52
// / Produce a builder call to the given named function with the given arguments.
53
53
Expr *buildCallIfWanted (SourceLoc loc,
54
54
Identifier fnName, ArrayRef<Expr *> args,
55
- ArrayRef<Identifier> argLabels = {}) {
55
+ ArrayRef<Identifier> argLabels,
56
+ bool allowOneWay) {
56
57
if (!wantExpr)
57
58
return nullptr ;
58
59
@@ -86,7 +87,7 @@ class BuilderClosureVisitor
86
87
/* trailing closure*/ nullptr ,
87
88
/* implicit*/ true );
88
89
89
- if (ctx.LangOpts .FunctionBuilderOneWayConstraints ) {
90
+ if (ctx.LangOpts .FunctionBuilderOneWayConstraints && allowOneWay ) {
90
91
// Form a one-way constraint to prevent backward propagation.
91
92
result = new (ctx) OneWayExpr (result);
92
93
}
@@ -176,7 +177,9 @@ class BuilderClosureVisitor
176
177
177
178
// Call Builder.buildBlock(... args ...)
178
179
return buildCallIfWanted (braceStmt->getStartLoc (),
179
- ctx.Id_buildBlock , expressions);
180
+ ctx.Id_buildBlock , expressions,
181
+ /* argLabels=*/ { },
182
+ /* allowOneWay=*/ true );
180
183
}
181
184
182
185
Expr *visitReturnStmt (ReturnStmt *stmt) {
@@ -201,7 +204,8 @@ class BuilderClosureVisitor
201
204
if (!arg)
202
205
return nullptr ;
203
206
204
- return buildCallIfWanted (doStmt->getStartLoc (), ctx.Id_buildDo , arg);
207
+ return buildCallIfWanted (doStmt->getStartLoc (), ctx.Id_buildDo , arg,
208
+ /* argLabels=*/ { }, /* allowOneWay=*/ true );
205
209
}
206
210
207
211
CONTROL_FLOW_STMT (Yield)
@@ -286,7 +290,12 @@ class BuilderClosureVisitor
286
290
// so we just need to call `buildIf` now, since we're at the top level.
287
291
if (isOptional) {
288
292
chainExpr = buildCallIfWanted (ifStmt->getStartLoc (),
289
- ctx.Id_buildIf , chainExpr);
293
+ ctx.Id_buildIf , chainExpr,
294
+ /* argLabels=*/ { },
295
+ /* allowOneWay=*/ true );
296
+ } else if (ctx.LangOpts .FunctionBuilderOneWayConstraints ) {
297
+ // Form a one-way constraint to prevent backward propagation.
298
+ chainExpr = new (ctx) OneWayExpr (chainExpr);
290
299
}
291
300
292
301
return chainExpr;
@@ -406,7 +415,8 @@ class BuilderClosureVisitor
406
415
bool isSecond = (path & 1 );
407
416
operand = buildCallIfWanted (operand->getStartLoc (),
408
417
ctx.Id_buildEither , operand,
409
- {isSecond ? ctx.Id_second : ctx.Id_first });
418
+ {isSecond ? ctx.Id_second : ctx.Id_first },
419
+ /* allowOneWay=*/ false );
410
420
}
411
421
412
422
// Inject into Optional if required. We'll be adding the call to
0 commit comments