@@ -169,11 +169,10 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
169169// / returns \c true. Returns \c true if any callback call returns \c true, \c
170170// / false otherwise.
171171static bool
172- forEachDependencyUntilTrue (CompilerInstance &CI, ModuleDecl *CurrentModule,
173- unsigned excludeBufferID,
172+ forEachDependencyUntilTrue (CompilerInstance &CI, unsigned excludeBufferID,
174173 llvm::function_ref<bool (StringRef)> callback) {
175174 // Check files in the current module.
176- for (FileUnit *file : CurrentModule ->getFiles ()) {
175+ for (FileUnit *file : CI. getMainModule () ->getFiles ()) {
177176 StringRef filename;
178177 if (auto SF = dyn_cast<SourceFile>(file)) {
179178 if (SF->getBufferID () == excludeBufferID)
@@ -203,12 +202,11 @@ forEachDependencyUntilTrue(CompilerInstance &CI, ModuleDecl *CurrentModule,
203202
204203// / Collect hash codes of the dependencies into \c Map.
205204static void cacheDependencyHashIfNeeded (CompilerInstance &CI,
206- ModuleDecl *CurrentModule,
207205 unsigned excludeBufferID,
208206 llvm::StringMap<llvm::hash_code> &Map) {
209207 auto &FS = CI.getFileSystem ();
210208 forEachDependencyUntilTrue (
211- CI, CurrentModule, excludeBufferID, [&](StringRef filename) {
209+ CI, excludeBufferID, [&](StringRef filename) {
212210 if (Map.count (filename))
213211 return false ;
214212
@@ -229,12 +227,12 @@ static void cacheDependencyHashIfNeeded(CompilerInstance &CI,
229227
230228// / Check if any dependent files are modified since \p timestamp.
231229static bool areAnyDependentFilesInvalidated (
232- CompilerInstance &CI, ModuleDecl *CurrentModule, llvm::vfs::FileSystem &FS,
230+ CompilerInstance &CI, llvm::vfs::FileSystem &FS,
233231 unsigned excludeBufferID, llvm::sys::TimePoint<> timestamp,
234232 llvm::StringMap<llvm::hash_code> &Map) {
235233
236234 return forEachDependencyUntilTrue (
237- CI, CurrentModule, excludeBufferID, [&](StringRef filePath) {
235+ CI, excludeBufferID, [&](StringRef filePath) {
238236 auto stat = FS.status (filePath);
239237 if (!stat)
240238 // Missing.
@@ -291,7 +289,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
291289 return false ;
292290
293291 auto &CI = *CachedCI;
294- auto *oldSF = CI.getCodeCompletionFile (). get () ;
292+ auto *oldSF = CI.getCodeCompletionFile ();
295293
296294 auto *oldState = oldSF->getDelayedParserState ();
297295 assert (oldState->hasCodeCompletionDelayedDeclState ());
@@ -304,7 +302,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
304302
305303 if (shouldCheckDependencies ()) {
306304 if (areAnyDependentFilesInvalidated (
307- CI, CurrentModule, *FileSystem, SM.getCodeCompletionBufferID (),
305+ CI, *FileSystem, SM.getCodeCompletionBufferID (),
308306 DependencyCheckedTimestamp, InMemoryDependencyHash))
309307 return false ;
310308 DependencyCheckedTimestamp = std::chrono::system_clock::now ();
@@ -441,22 +439,21 @@ bool CompletionInstance::performCachedOperationIfPossible(
441439
442440 // Create a new module and a source file using the current AST context.
443441 auto &Ctx = oldM->getASTContext ();
444- auto *newM =
445- ModuleDecl::create (oldM-> getName (), Ctx, oldM->getImplicitImportInfo ());
442+ auto *newM = ModuleDecl::createMainModule (Ctx, oldM-> getName (),
443+ oldM->getImplicitImportInfo ());
446444 auto *newSF =
447445 new (Ctx) SourceFile (*newM, SourceFileKind::Main, newBufferID);
448446 newM->addFile (*newSF);
449447 newSF->enableInterfaceHash ();
450448
451- // Tell the compiler instance we've replaced the code completion file .
452- CI.setCodeCompletionFile (newSF );
449+ // Tell the compiler instance we've replaced the main module .
450+ CI.setMainModule (newM );
453451
454452 // Re-process the whole file (parsing will be lazily triggered). Still
455453 // re-use imported modules.
456454 performImportResolution (*newSF);
457455 bindExtensions (*newM);
458456
459- CurrentModule = newM;
460457 traceDC = newM;
461458#ifndef NDEBUG
462459 const auto *reparsedState = newSF->getDelayedParserState ();
@@ -483,7 +480,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
483480 }
484481
485482 CachedReuseCount += 1 ;
486- cacheDependencyHashIfNeeded (CI, CurrentModule, SM.getCodeCompletionBufferID (),
483+ cacheDependencyHashIfNeeded (CI, SM.getCodeCompletionBufferID (),
487484 InMemoryDependencyHash);
488485
489486 return true ;
@@ -536,8 +533,7 @@ bool CompletionInstance::performNewOperation(
536533 CI.performParseAndResolveImportsOnly ();
537534
538535 // If we didn't find a code completion token, bail.
539- auto completionFile = CI.getCodeCompletionFile ();
540- auto *state = completionFile.get ()->getDelayedParserState ();
536+ auto *state = CI.getCodeCompletionFile ()->getDelayedParserState ();
541537 if (!state->hasCodeCompletionDelayedDeclState ())
542538 return true ;
543539
@@ -554,14 +550,13 @@ bool CompletionInstance::performNewOperation(
554550void CompletionInstance::cacheCompilerInstance (
555551 std::unique_ptr<CompilerInstance> CI, llvm::hash_code ArgsHash) {
556552 CachedCI = std::move (CI);
557- CurrentModule = CachedCI->getMainModule ();
558553 CachedArgHash = ArgsHash;
559554 auto now = std::chrono::system_clock::now ();
560555 DependencyCheckedTimestamp = now;
561556 CachedReuseCount = 0 ;
562557 InMemoryDependencyHash.clear ();
563558 cacheDependencyHashIfNeeded (
564- *CachedCI, CurrentModule,
559+ *CachedCI,
565560 CachedCI->getASTContext ().SourceMgr .getCodeCompletionBufferID (),
566561 InMemoryDependencyHash);
567562}
0 commit comments