@@ -156,11 +156,14 @@ class IndexRecordingConsumer : public IndexDataConsumer {
156156 // we actually need it (once per Decl instead of once per occurrence).
157157 std::vector<IndexSymbol> symbolStack;
158158
159+ bool includeLocals;
160+
159161 std::function<void (SymbolTracker &)> onFinish;
160162
161163public:
162- IndexRecordingConsumer (std::function<void (SymbolTracker &)> onFinish)
163- : onFinish(std::move(onFinish)) {}
164+ IndexRecordingConsumer (bool includeLocals,
165+ std::function<void (SymbolTracker &)> onFinish)
166+ : includeLocals(includeLocals), onFinish(std::move(onFinish)) {}
164167
165168 void failed (StringRef error) override {
166169 // FIXME: expose errors?
@@ -183,6 +186,8 @@ class IndexRecordingConsumer : public IndexDataConsumer {
183186 }
184187
185188 void finish () override { onFinish (record); }
189+
190+ bool indexLocals () override { return includeLocals; }
186191};
187192
188193class StdlibGroupsIndexRecordingConsumer : public IndexDataConsumer {
@@ -323,24 +328,25 @@ static bool writeRecord(SymbolTracker &record, std::string Filename,
323328
324329static std::unique_ptr<IndexRecordingConsumer>
325330makeRecordingConsumer (std::string Filename, std::string indexStorePath,
326- DiagnosticEngine *diags,
331+ bool includeLocals, DiagnosticEngine *diags,
327332 std::string *outRecordFile,
328333 bool *outFailed) {
329- return std::make_unique<IndexRecordingConsumer>([=](SymbolTracker &record) {
334+ return std::make_unique<IndexRecordingConsumer>(includeLocals,
335+ [=](SymbolTracker &record) {
330336 *outFailed = writeRecord (record, Filename, indexStorePath, diags,
331337 *outRecordFile);
332338 });
333339}
334340
335341static bool
336342recordSourceFile (SourceFile *SF, StringRef indexStorePath,
337- DiagnosticEngine &diags,
343+ bool includeLocals, DiagnosticEngine &diags,
338344 llvm::function_ref<void (StringRef, StringRef)> callback) {
339345 std::string recordFile;
340346 bool failed = false ;
341347 auto consumer =
342348 makeRecordingConsumer (SF->getFilename ().str (), indexStorePath.str (),
343- &diags, &recordFile, &failed);
349+ includeLocals, &diags, &recordFile, &failed);
344350 indexSourceFile (SF, *consumer);
345351
346352 if (!failed && !recordFile.empty ())
@@ -379,6 +385,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
379385 bool indexClangModules,
380386 bool indexSystemModules,
381387 bool skipStdlib,
388+ bool includeLocals,
382389 StringRef targetTriple,
383390 const clang::CompilerInstance &clangCI,
384391 DiagnosticEngine &diags,
@@ -391,6 +398,7 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
391398 bool indexClangModules,
392399 bool indexSystemModules,
393400 bool skipStdlib,
401+ bool includeLocals,
394402 StringRef targetTriple,
395403 const clang::CompilerInstance &clangCI,
396404 DiagnosticEngine &diags,
@@ -448,7 +456,8 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
448456 emitDataForSwiftSerializedModule (mod, indexStorePath,
449457 indexClangModules,
450458 indexSystemModules, skipStdlib,
451- targetTriple, clangCI, diags,
459+ includeLocals, targetTriple,
460+ clangCI, diags,
452461 unitWriter,
453462 pathRemapper,
454463 initialFile);
@@ -479,6 +488,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
479488 bool indexClangModules,
480489 bool indexSystemModules,
481490 bool skipStdlib,
491+ bool includeLocals,
482492 StringRef targetTriple,
483493 const clang::CompilerInstance &clangCI,
484494 DiagnosticEngine &diags,
@@ -514,7 +524,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
514524 std::string recordFile;
515525 bool failed = false ;
516526 auto consumer = makeRecordingConsumer (filename.str (), indexStorePath.str (),
517- &diags, &recordFile, &failed);
527+ includeLocals, &diags, &recordFile, &failed);
518528 indexModule (module , *consumer);
519529
520530 if (failed)
@@ -602,9 +612,9 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
602612 ModuleDecl::ImportFilterKind::Default});
603613 StringScratchSpace moduleNameScratch;
604614 addModuleDependencies (imports, indexStorePath, indexClangModules,
605- indexSystemModules, skipStdlib, targetTriple, clangCI ,
606- diags, unitWriter, moduleNameScratch, pathRemapper ,
607- initialFile);
615+ indexSystemModules, skipStdlib, includeLocals ,
616+ targetTriple, clangCI, diags, unitWriter ,
617+ moduleNameScratch, pathRemapper, initialFile);
608618
609619 if (unitWriter.write (error)) {
610620 diags.diagnose (SourceLoc (), diag::error_write_index_unit, error);
@@ -618,7 +628,8 @@ static bool
618628recordSourceFileUnit (SourceFile *primarySourceFile, StringRef indexUnitToken,
619629 StringRef indexStorePath, bool indexClangModules,
620630 bool indexSystemModules, bool skipStdlib,
621- bool isDebugCompilation, StringRef targetTriple,
631+ bool includeLocals, bool isDebugCompilation,
632+ StringRef targetTriple,
622633 ArrayRef<const clang::FileEntry *> fileDependencies,
623634 const clang::CompilerInstance &clangCI,
624635 const PathRemapper &pathRemapper,
@@ -645,15 +656,15 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
645656 ModuleDecl::ImportFilterKind::ImplementationOnly});
646657 StringScratchSpace moduleNameScratch;
647658 addModuleDependencies (imports, indexStorePath, indexClangModules,
648- indexSystemModules, skipStdlib, targetTriple, clangCI ,
649- diags, unitWriter, moduleNameScratch, pathRemapper ,
650- primarySourceFile);
659+ indexSystemModules, skipStdlib, includeLocals ,
660+ targetTriple, clangCI, diags, unitWriter ,
661+ moduleNameScratch, pathRemapper, primarySourceFile);
651662
652663 // File dependencies.
653664 for (auto *F : fileDependencies)
654665 unitWriter.addFileDependency (F, /* FIXME:isSystem=*/ false , /* Module=*/ nullptr );
655666
656- recordSourceFile (primarySourceFile, indexStorePath, diags,
667+ recordSourceFile (primarySourceFile, indexStorePath, includeLocals, diags,
657668 [&](StringRef recordFile, StringRef filename) {
658669 auto file = fileMgr.getFile (filename);
659670 unitWriter.addRecordFile (
@@ -700,6 +711,7 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
700711 bool indexClangModules,
701712 bool indexSystemModules,
702713 bool skipStdlib,
714+ bool includeLocals,
703715 bool isDebugCompilation,
704716 StringRef targetTriple,
705717 const DependencyTracker &dependencyTracker,
@@ -729,7 +741,7 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
729741
730742 return recordSourceFileUnit (primarySourceFile, indexUnitToken,
731743 indexStorePath, indexClangModules,
732- indexSystemModules, skipStdlib,
744+ indexSystemModules, skipStdlib, includeLocals,
733745 isDebugCompilation, targetTriple,
734746 fileDependencies.getArrayRef (),
735747 clangCI, pathRemapper, diags);
@@ -742,6 +754,7 @@ bool index::indexAndRecord(ModuleDecl *module,
742754 bool indexClangModules,
743755 bool indexSystemModules,
744756 bool skipStdlib,
757+ bool includeLocals,
745758 bool isDebugCompilation,
746759 StringRef targetTriple,
747760 const DependencyTracker &dependencyTracker,
@@ -779,7 +792,7 @@ bool index::indexAndRecord(ModuleDecl *module,
779792 }
780793 if (recordSourceFileUnit (SF, indexUnitTokens[unitIndex],
781794 indexStorePath, indexClangModules,
782- indexSystemModules, skipStdlib,
795+ indexSystemModules, skipStdlib, includeLocals,
783796 isDebugCompilation, targetTriple,
784797 fileDependencies.getArrayRef (),
785798 clangCI, pathRemapper, diags))
0 commit comments