From a9e339b9739bfa1e323bcf47a2cddb25b000509a Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Fri, 29 Aug 2025 16:18:30 +0100 Subject: [PATCH] [CS] Strengthen check for completion in CSApply Turns out we don't always set a completion callback for some unqualified completion positions. Upgrade the check for a completion callback to a check for a completion buffer to account for this. This avoids unnecessary type-checker work as well as fixing a couple of double-type-checking crashers. --- lib/Sema/CSApply.cpp | 4 ++-- .../IDE/{crashers => crashers_fixed}/ce6e7a44344828a0.swift | 2 +- .../IDE/{crashers => crashers_fixed}/e7327cfd8bafcd86.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename validation-test/IDE/{crashers => crashers_fixed}/ce6e7a44344828a0.swift (51%) rename validation-test/IDE/{crashers => crashers_fixed}/e7327cfd8bafcd86.swift (76%) diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index a77a10efcd88d..b0cd6c89c5de1 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -452,7 +452,7 @@ namespace { void addLocalDeclToTypeCheck(Decl *D) { // If we're doing code completion, avoid doing any further type-checking, // that should instead be handled by TypeCheckASTNodeAtLocRequest. - if (ctx.CompletionCallback) + if (ctx.SourceMgr.hasIDEInspectionTargetBuffer()) return; LocalDeclsToTypeCheck.push_back(D); @@ -461,7 +461,7 @@ namespace { void addMacroToExpand(MacroExpansionExpr *E) { // If we're doing code completion, avoid doing any further type-checking, // that should instead be handled by TypeCheckASTNodeAtLocRequest. - if (ctx.CompletionCallback) + if (ctx.SourceMgr.hasIDEInspectionTargetBuffer()) return; MacrosToExpand.push_back(E); diff --git a/validation-test/IDE/crashers/ce6e7a44344828a0.swift b/validation-test/IDE/crashers_fixed/ce6e7a44344828a0.swift similarity index 51% rename from validation-test/IDE/crashers/ce6e7a44344828a0.swift rename to validation-test/IDE/crashers_fixed/ce6e7a44344828a0.swift index ef882f61632e3..64f07d0c0af4d 100644 --- a/validation-test/IDE/crashers/ce6e7a44344828a0.swift +++ b/validation-test/IDE/crashers_fixed/ce6e7a44344828a0.swift @@ -1,5 +1,5 @@ // {"kind":"complete","signature":"(anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*)"} -// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s +// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s enum a } { var b: a func c { switch b { diff --git a/validation-test/IDE/crashers/e7327cfd8bafcd86.swift b/validation-test/IDE/crashers_fixed/e7327cfd8bafcd86.swift similarity index 76% rename from validation-test/IDE/crashers/e7327cfd8bafcd86.swift rename to validation-test/IDE/crashers_fixed/e7327cfd8bafcd86.swift index 5ea05ca79487b..8423f8cac3b42 100644 --- a/validation-test/IDE/crashers/e7327cfd8bafcd86.swift +++ b/validation-test/IDE/crashers_fixed/e7327cfd8bafcd86.swift @@ -1,5 +1,5 @@ // {"kind":"complete","original":"bc7ab9d8","signature":"swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl*, swift::FunctionRefInfo, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext*, swift::constraints::PreparedOverloadBuilder*)","signatureAssert":"Assertion failed: (func->isOperator() && \"Lookup should only find operators\"), function getTypeOfReference"} -// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s +// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s { func a(query: String) { {