Skip to content

Commit 4031070

Browse files
authored
Merge pull request #25935 from benlangmuir/cc-dsl-slow-51
[5.1] [code-completion] Disable diagnostics in @functionBuilder bodies
2 parents 2efadfd + 32d3c54 commit 4031070

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class SourceManager {
103103
rangeContainsTokenLoc(Enclosing, Inner.End);
104104
}
105105

106+
/// Returns true if range \p R contains the code-completion location, if any.
107+
bool rangeContainsCodeCompletionLoc(SourceRange R) const {
108+
return CodeCompletionBufferID
109+
? rangeContainsTokenLoc(R, getCodeCompletionLoc())
110+
: false;
111+
}
112+
106113
/// Returns the buffer ID for the specified *valid* location.
107114
///
108115
/// Because a valid source location always corresponds to a source buffer,

lib/Sema/BuilderTransform.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,18 @@ bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
484484
if (!returnType || returnType->hasError())
485485
return true;
486486

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+
487495
// Type-check the single result expression.
488496
Type returnExprType = typeCheckExpression(returnExpr, FD,
489497
TypeLoc::withoutLoc(returnType),
490-
CTP_ReturnStmt);
498+
CTP_ReturnStmt, options);
491499
if (!returnExprType)
492500
return true;
493501
assert(returnExprType->isEqual(returnType));
@@ -562,6 +570,12 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
562570
assert(!builderType->hasTypeParameter());
563571
}
564572

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+
565579
BuilderClosureVisitor visitor(getASTContext(), this,
566580
/*wantExpr=*/true, builderType);
567581
Expr *singleExpr = visitor.visit(closure->getBody());

0 commit comments

Comments
 (0)