@@ -288,51 +288,31 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,
288
288
289
289
if (auto *ternary = dyn_cast<TernaryExpr>(Op)) {
290
290
// Resolve the ternary expression.
291
- if (!Ctx.CompletionCallback ) {
292
- // In code completion we might call preCheckTarget twice - once for
293
- // the first pass and once for the second pass. This is fine since
294
- // preCheckTarget is idempotent.
295
- assert (!ternary->isFolded () && " already folded if expr in sequence?!" );
296
- }
291
+ ASSERT (!ternary->isFolded () && " already folded if expr in sequence?!" );
297
292
ternary->setCondExpr (LHS);
298
293
ternary->setElseExpr (RHS);
299
294
return ternary;
300
295
}
301
296
302
297
if (auto *assign = dyn_cast<AssignExpr>(Op)) {
303
298
// Resolve the assignment expression.
304
- if (!Ctx.CompletionCallback ) {
305
- // In code completion we might call preCheckTarget twice - once for
306
- // the first pass and once for the second pass. This is fine since
307
- // preCheckTarget is idempotent.
308
- assert (!assign->isFolded () && " already folded assign expr in sequence?!" );
309
- }
299
+ ASSERT (!assign->isFolded () && " already folded assign expr in sequence?!" );
310
300
assign->setDest (LHS);
311
301
assign->setSrc (RHS);
312
302
return assign;
313
303
}
314
304
315
305
if (auto *as = dyn_cast<ExplicitCastExpr>(Op)) {
316
306
// Resolve the 'as' or 'is' expression.
317
- if (!Ctx.CompletionCallback ) {
318
- // In code completion we might call preCheckTarget twice - once for
319
- // the first pass and once for the second pass. This is fine since
320
- // preCheckTarget is idempotent.
321
- assert (!as->isFolded () && " already folded 'as' expr in sequence?!" );
322
- }
307
+ ASSERT (!as->isFolded () && " already folded 'as' expr in sequence?!" );
323
308
assert (RHS == as && " 'as' with non-type RHS?!" );
324
309
as->setSubExpr (LHS);
325
310
return as;
326
311
}
327
312
328
313
if (auto *arrow = dyn_cast<ArrowExpr>(Op)) {
329
314
// Resolve the '->' expression.
330
- if (!Ctx.CompletionCallback ) {
331
- // In code completion we might call preCheckTarget twice - once for
332
- // the first pass and once for the second pass. This is fine since
333
- // preCheckTarget is idempotent.
334
- assert (!arrow->isFolded () && " already folded '->' expr in sequence?!" );
335
- }
315
+ ASSERT (!arrow->isFolded () && " already folded '->' expr in sequence?!" );
336
316
arrow->setArgsExpr (LHS);
337
317
arrow->setResultExpr (RHS);
338
318
return arrow;
@@ -633,6 +613,15 @@ swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
633
613
}
634
614
635
615
Expr *TypeChecker::foldSequence (SequenceExpr *expr, DeclContext *dc) {
616
+ // We may end up running pre-checking multiple times for completion and
617
+ // pattern type-checking, just use the folded expression if we've already
618
+ // folded the sequence.
619
+ // FIXME: We ought to fix these cases to not pre-check multiple times,
620
+ // strictly speaking it isn't idempotent (e.g for things like
621
+ // `markDirectCallee`).
622
+ if (auto *folded = expr->getFoldedExpr ())
623
+ return folded;
624
+
636
625
// First resolve any unresolved decl references in operator positions.
637
626
for (auto i : indices (expr->getElements ())) {
638
627
if (i % 2 == 0 )
0 commit comments