@@ -484,10 +484,18 @@ bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
484
484
if (!returnType || returnType->hasError ())
485
485
return true ;
486
486
487
+ TypeCheckExprOptions options = {};
488
+
489
+ // If we are performing code-completion inside the functions body, supress
490
+ // diagnostics to workaround typechecking performance problems.
491
+ if (Context.SourceMgr .rangeContainsCodeCompletionLoc (
492
+ FD->getBody ()->getSourceRange ()))
493
+ options |= TypeCheckExprFlags::SuppressDiagnostics;
494
+
487
495
// Type-check the single result expression.
488
496
Type returnExprType = typeCheckExpression (returnExpr, FD,
489
497
TypeLoc::withoutLoc (returnType),
490
- CTP_ReturnStmt);
498
+ CTP_ReturnStmt, options );
491
499
if (!returnExprType)
492
500
return true ;
493
501
assert (returnExprType->isEqual (returnType));
@@ -562,6 +570,12 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
562
570
assert (!builderType->hasTypeParameter ());
563
571
}
564
572
573
+ // If we are performing code-completion inside the closure body, supress
574
+ // diagnostics to workaround typechecking performance problems.
575
+ if (getASTContext ().SourceMgr .rangeContainsCodeCompletionLoc (
576
+ closure->getSourceRange ()))
577
+ Options |= ConstraintSystemFlags::SuppressDiagnostics;
578
+
565
579
BuilderClosureVisitor visitor (getASTContext (), this ,
566
580
/* wantExpr=*/ true , builderType);
567
581
Expr *singleExpr = visitor.visit (closure->getBody ());
0 commit comments