Skip to content

Commit 48040ba

Browse files
authored
Merge pull request #25922 from benlangmuir/cc-dsl-slow
[code-completion] Disable diagnostics in @functionBuilder bodies
2 parents 7211a51 + c6eade1 commit 48040ba

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
496496
options |= TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType;
497497
}
498498

499+
// If we are performing code-completion inside the functions body, supress
500+
// diagnostics to workaround typechecking performance problems.
501+
if (Context.SourceMgr.rangeContainsCodeCompletionLoc(
502+
FD->getBody()->getSourceRange()))
503+
options |= TypeCheckExprFlags::SuppressDiagnostics;
504+
499505
// Type-check the single result expression.
500506
Type returnExprType = typeCheckExpression(returnExpr, FD,
501507
TypeLoc::withoutLoc(returnType),
@@ -574,6 +580,12 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
574580
assert(!builderType->hasTypeParameter());
575581
}
576582

583+
// If we are performing code-completion inside the closure body, supress
584+
// diagnostics to workaround typechecking performance problems.
585+
if (getASTContext().SourceMgr.rangeContainsCodeCompletionLoc(
586+
closure->getSourceRange()))
587+
Options |= ConstraintSystemFlags::SuppressDiagnostics;
588+
577589
BuilderClosureVisitor visitor(getASTContext(), this,
578590
/*wantExpr=*/true, builderType);
579591
Expr *singleExpr = visitor.visit(closure->getBody());

0 commit comments

Comments
 (0)