1616#include " swift/AST/DiagnosticEngine.h"
1717#include " swift/AST/DiagnosticsFrontend.h"
1818#include " swift/AST/Module.h"
19+ #include " swift/AST/PrettyStackTrace.h"
1920#include " swift/AST/SourceFile.h"
2021#include " swift/Basic/LangOptions.h"
22+ #include " swift/Basic/PrettyStackTrace.h"
2123#include " swift/Basic/SourceManager.h"
2224#include " swift/Driver/FrontendUtil.h"
2325#include " swift/Frontend/Frontend.h"
@@ -167,6 +169,8 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
167169 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
168170 DiagnosticConsumer *DiagC,
169171 llvm::function_ref<void (CompilerInstance &, bool )> Callback) {
172+ llvm::PrettyStackTraceString trace (
173+ " While performing cached completion if possible" );
170174
171175 if (!CachedCI)
172176 return false ;
@@ -218,7 +222,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
218222
219223 auto &newInfo = newState->getCodeCompletionDelayedDeclState ();
220224 unsigned newBufferID;
221-
225+ DeclContext *traceDC = nullptr ;
222226 switch (newInfo.Kind ) {
223227 case CodeCompletionDelayedDeclKind::FunctionBody: {
224228 // If the interface has changed, AST must be refreshed.
@@ -285,6 +289,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
285289 if (AFD->isBodySkipped ())
286290 AFD->setBodyDelayed (AFD->getBodySourceRange ());
287291
292+ traceDC = AFD;
288293 break ;
289294 }
290295 case CodeCompletionDelayedDeclKind::Decl:
@@ -329,6 +334,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
329334 performImportResolution (*newSF);
330335 bindExtensions (*newSF);
331336
337+ traceDC = newM;
332338#ifndef NDEBUG
333339 const auto *reparsedState = newSF->getDelayedParserState ();
334340 assert (reparsedState->hasCodeCompletionDelayedDeclState () &&
@@ -341,13 +347,17 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
341347 }
342348 }
343349
344- if (DiagC)
345- CI. addDiagnosticConsumer (DiagC );
350+ {
351+ PrettyStackTraceDeclContext trace ( " performing cached completion " , traceDC );
346352
347- Callback (CI, /* reusingASTContext=*/ true );
353+ if (DiagC)
354+ CI.addDiagnosticConsumer (DiagC);
348355
349- if (DiagC)
350- CI.removeDiagnosticConsumer (DiagC);
356+ Callback (CI, /* reusingASTContext=*/ true );
357+
358+ if (DiagC)
359+ CI.removeDiagnosticConsumer (DiagC);
360+ }
351361
352362 CachedReuseCount += 1 ;
353363
@@ -360,6 +370,7 @@ bool CompletionInstance::performNewOperation(
360370 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
361371 std::string &Error, DiagnosticConsumer *DiagC,
362372 llvm::function_ref<void (CompilerInstance &, bool )> Callback) {
373+ llvm::PrettyStackTraceString trace (" While performing new completion" );
363374
364375 auto TheInstance = std::make_unique<CompilerInstance>();
365376 {
0 commit comments