[CodeComplete] More efficient skipping for completions in if/switch exprs

Skip type-checking multi-statement branches if the
completion is in a single-expression branch, and
skip type-checking the expression as a whole if
the completion is in a multi-statement branch.
This commit is contained in:
Hamish Knight
2023-08-01 15:21:29 +01:00
parent d8d8db987b
commit 1dd86fccdb
6 changed files with 313 additions and 18 deletions

View File

@@ -883,11 +883,15 @@ bool ConjunctionStep::attempt(const ConjunctionElement &element) {
assert(!ModifiedOptions.has_value() &&
"Previously modified options should have been restored in resume");
if (CS.isForCodeCompletion() &&
!element.mightContainCodeCompletionToken(CS)) {
!element.mightContainCodeCompletionToken(CS) &&
!getLocator()->isForSingleValueStmtConjunctionOrBrace()) {
ModifiedOptions.emplace(CS.Options);
// If we know that this conjunction element doesn't contain the code
// completion token, type check it in normal mode without any special
// behavior that is intended for the code completion token.
// Avoid doing this for SingleValueStmtExprs, because we can more eagerly
// prune branches in that case, which requires us to detect the code
// completion option while solving the conjunction.
CS.Options -= ConstraintSystemFlags::ForCodeCompletion;
}