Skip to content

Commit 88a5c00

Browse files
authored
Merge pull request #25672 from akyrtzi/index-remove-module-hash
2 parents 15bcd23 + 3332b37 commit 88a5c00

30 files changed

+477
-495
lines changed

include/swift/Index/Index.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ class DeclContext;
2323
namespace index {
2424

2525
void indexDeclContext(DeclContext *DC, IndexDataConsumer &consumer);
26-
void indexSourceFile(SourceFile *SF, StringRef hash,
27-
IndexDataConsumer &consumer);
28-
void indexModule(ModuleDecl *module, StringRef hash,
29-
IndexDataConsumer &consumer);
26+
void indexSourceFile(SourceFile *SF, IndexDataConsumer &consumer);
27+
void indexModule(ModuleDecl *module, IndexDataConsumer &consumer);
3028

3129
} // end namespace index
3230
} // end namespace swift

include/swift/Index/IndexDataConsumer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class IndexDataConsumer {
3232
virtual void failed(StringRef error) = 0;
3333
virtual void warning(StringRef warning) {}
3434

35-
virtual bool recordHash(StringRef hash, bool isKnown) = 0;
3635
virtual bool startDependency(StringRef name, StringRef path, bool isClangModule,
37-
bool isSystem, StringRef hash) = 0;
36+
bool isSystem) = 0;
3837
virtual bool finishDependency(bool isClangModule) = 0;
3938
virtual Action startSourceEntity(const IndexSymbol &symbol) = 0;
4039
virtual bool finishSourceEntity(SymbolInfo symInfo, SymbolRoleSet roles) = 0;

lib/IDE/Refactoring.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,7 @@ class RenameRangeCollector : public IndexDataConsumer {
552552
private:
553553
bool indexLocals() override { return true; }
554554
void failed(StringRef error) override {}
555-
bool recordHash(StringRef hash, bool isKnown) override { return true; }
556-
bool startDependency(StringRef name, StringRef path, bool isClangModule,
557-
bool isSystem, StringRef hash) override {
555+
bool startDependency(StringRef name, StringRef path, bool isClangModule, bool isSystem) override {
558556
return true;
559557
}
560558
bool finishDependency(bool isClangModule) override { return true; }

lib/Index/Index.cpp

Lines changed: 11 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,14 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
285285
assert(Cancelled || ManuallyVisitedAccessorStack.empty());
286286
}
287287

288-
void visitModule(ModuleDecl &Mod, StringRef Hash);
288+
void visitModule(ModuleDecl &Mod);
289289
void visitDeclContext(DeclContext *DC);
290290

291291
private:
292292
bool visitImports(SourceFileOrModule Mod,
293293
llvm::SmallPtrSetImpl<ModuleDecl *> &Visited);
294294

295-
bool handleSourceOrModuleFile(SourceFileOrModule SFOrMod, StringRef KnownHash,
296-
bool &HashIsKnown);
295+
bool handleSourceOrModuleFile(SourceFileOrModule SFOrMod);
297296

298297
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
299298
// Do not handle unavailable decls.
@@ -565,10 +564,6 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
565564
/// \returns false if AST visitation should stop.
566565
bool handleWitnesses(Decl *D, SmallVectorImpl<IndexedWitness> &explicitWitnesses);
567566

568-
void getModuleHash(SourceFileOrModule SFOrMod, llvm::raw_ostream &OS);
569-
llvm::hash_code hashModule(llvm::hash_code code, SourceFileOrModule SFOrMod);
570-
llvm::hash_code hashFileReference(llvm::hash_code code,
571-
SourceFileOrModule SFOrMod);
572567
void getRecursiveModuleImports(ModuleDecl &Mod,
573568
SmallVectorImpl<ModuleDecl *> &Imports);
574569
void
@@ -601,7 +596,7 @@ void IndexSwiftASTWalker::visitDeclContext(DeclContext *Context) {
601596
ManuallyVisitedAccessorStack.pop_back();
602597
}
603598

604-
void IndexSwiftASTWalker::visitModule(ModuleDecl &Mod, StringRef KnownHash) {
599+
void IndexSwiftASTWalker::visitModule(ModuleDecl &Mod) {
605600
SourceFile *SrcFile = nullptr;
606601
for (auto File : Mod.getFiles()) {
607602
if (auto SF = dyn_cast<SourceFile>(File)) {
@@ -613,41 +608,23 @@ void IndexSwiftASTWalker::visitModule(ModuleDecl &Mod, StringRef KnownHash) {
613608
}
614609
}
615610

616-
bool HashIsKnown;
617611
if (SrcFile != nullptr) {
618612
IsModuleFile = false;
619-
if (!handleSourceOrModuleFile(*SrcFile, KnownHash, HashIsKnown))
613+
if (!handleSourceOrModuleFile(*SrcFile))
620614
return;
621-
if (HashIsKnown)
622-
return; // No need to report symbols.
623615
walk(*SrcFile);
624616
} else {
625617
IsModuleFile = true;
626618
isSystemModule = Mod.isSystemModule();
627-
if (!handleSourceOrModuleFile(Mod, KnownHash, HashIsKnown))
619+
if (!handleSourceOrModuleFile(Mod))
628620
return;
629-
if (HashIsKnown)
630-
return; // No need to report symbols.
631621
walk(Mod);
632622
}
633623
}
634624

635-
bool IndexSwiftASTWalker::handleSourceOrModuleFile(SourceFileOrModule SFOrMod,
636-
StringRef KnownHash,
637-
bool &HashIsKnown) {
625+
bool IndexSwiftASTWalker::handleSourceOrModuleFile(SourceFileOrModule SFOrMod) {
638626
// Common reporting for TU/module file.
639627

640-
SmallString<32> HashBuf;
641-
{
642-
llvm::raw_svector_ostream HashOS(HashBuf);
643-
getModuleHash(SFOrMod, HashOS);
644-
StringRef Hash = HashOS.str();
645-
HashIsKnown = Hash == KnownHash;
646-
if (!IdxConsumer.recordHash(Hash, HashIsKnown))
647-
return false;
648-
}
649-
650-
// We always report the dependencies, even if the hash is known.
651628
llvm::SmallPtrSet<ModuleDecl *, 16> Visited;
652629
return visitImports(SFOrMod, Visited);
653630
}
@@ -703,16 +680,8 @@ bool IndexSwiftASTWalker::visitImports(
703680
continue;
704681
bool IsClangModule = *IsClangModuleOpt;
705682

706-
StringRef Hash;
707-
SmallString<32> HashBuf;
708-
if (!IsClangModule) {
709-
llvm::raw_svector_ostream HashOS(HashBuf);
710-
getModuleHash(*Mod, HashOS);
711-
Hash = HashOS.str();
712-
}
713-
714683
if (!IdxConsumer.startDependency(Mod->getName().str(), Path, IsClangModule,
715-
Mod->isSystemModule(), Hash))
684+
Mod->isSystemModule()))
716685
return false;
717686
if (!IsClangModule)
718687
if (!visitImports(*Mod, Visited))
@@ -1441,43 +1410,6 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
14411410
return !Cancelled;
14421411
}
14431412

1444-
llvm::hash_code
1445-
IndexSwiftASTWalker::hashFileReference(llvm::hash_code code,
1446-
SourceFileOrModule SFOrMod) {
1447-
StringRef Filename = SFOrMod.getFilename();
1448-
if (Filename.empty())
1449-
return code;
1450-
1451-
// FIXME: FileManager for swift ?
1452-
1453-
llvm::sys::fs::file_status Status;
1454-
if (std::error_code Ret = llvm::sys::fs::status(Filename, Status)) {
1455-
// Failure to read the file, just use filename to recover.
1456-
warn([&](llvm::raw_ostream &OS) {
1457-
OS << "failed to stat file: " << Filename << " (" << Ret.message() << ')';
1458-
});
1459-
return hash_combine(code, Filename);
1460-
}
1461-
1462-
// Don't use inode because it can easily change when you update the repository
1463-
// even though the file is supposed to be the same (same size/time).
1464-
code = hash_combine(code, Filename);
1465-
auto mtime = Status.getLastModificationTime().time_since_epoch().count();
1466-
return hash_combine(code, Status.getSize(), mtime);
1467-
}
1468-
1469-
llvm::hash_code IndexSwiftASTWalker::hashModule(llvm::hash_code code,
1470-
SourceFileOrModule SFOrMod) {
1471-
code = hashFileReference(code, SFOrMod);
1472-
1473-
SmallVector<ModuleDecl *, 16> Imports;
1474-
getRecursiveModuleImports(SFOrMod.getModule(), Imports);
1475-
for (auto Import : Imports)
1476-
code = hashFileReference(code, *Import);
1477-
1478-
return code;
1479-
}
1480-
14811413
void IndexSwiftASTWalker::getRecursiveModuleImports(
14821414
ModuleDecl &Mod, SmallVectorImpl<ModuleDecl *> &Imports) {
14831415
auto It = ImportsMap.find(&Mod);
@@ -1575,13 +1507,6 @@ void IndexSwiftASTWalker::collectRecursiveModuleImports(
15751507
}
15761508
}
15771509

1578-
void IndexSwiftASTWalker::getModuleHash(SourceFileOrModule Mod,
1579-
llvm::raw_ostream &OS) {
1580-
// FIXME: Use a longer hash string to minimize possibility for conflicts.
1581-
llvm::hash_code code = hashModule(0, Mod);
1582-
OS << llvm::APInt(64, code).toString(36, /*Signed=*/false);
1583-
}
1584-
15851510
static Type getContextFreeInterfaceType(ValueDecl *VD) {
15861511
if (auto AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
15871512
return AFD->getMethodInterfaceType();
@@ -1661,19 +1586,17 @@ void index::indexDeclContext(DeclContext *DC, IndexDataConsumer &consumer) {
16611586
consumer.finish();
16621587
}
16631588

1664-
void index::indexSourceFile(SourceFile *SF, StringRef hash,
1665-
IndexDataConsumer &consumer) {
1589+
void index::indexSourceFile(SourceFile *SF, IndexDataConsumer &consumer) {
16661590
assert(SF);
16671591
unsigned bufferID = SF->getBufferID().getValue();
16681592
IndexSwiftASTWalker walker(consumer, SF->getASTContext(), bufferID);
1669-
walker.visitModule(*SF->getParentModule(), hash);
1593+
walker.visitModule(*SF->getParentModule());
16701594
consumer.finish();
16711595
}
16721596

1673-
void index::indexModule(ModuleDecl *module, StringRef hash,
1674-
IndexDataConsumer &consumer) {
1597+
void index::indexModule(ModuleDecl *module, IndexDataConsumer &consumer) {
16751598
assert(module);
16761599
IndexSwiftASTWalker walker(consumer, module->getASTContext());
1677-
walker.visitModule(*module, hash);
1600+
walker.visitModule(*module);
16781601
consumer.finish();
16791602
}

lib/Index/IndexRecord.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ class IndexRecordingConsumer : public IndexDataConsumer {
164164
// FIXME: expose errors?
165165
}
166166

167-
bool recordHash(StringRef hash, bool isKnown) override { return true; }
168-
bool startDependency(StringRef name, StringRef path, bool isClangModule,
169-
bool isSystem, StringRef hash) override {
167+
bool startDependency(StringRef name, StringRef path, bool isClangModule, bool isSystem) override {
170168
return true;
171169
}
172170
bool finishDependency(bool isClangModule) override { return true; }
@@ -203,9 +201,7 @@ class StdlibGroupsIndexRecordingConsumer : public IndexDataConsumer {
203201
// FIXME: expose errors?
204202
}
205203

206-
bool recordHash(StringRef hash, bool isKnown) override { return true; }
207-
bool startDependency(StringRef name, StringRef path, bool isClangModule,
208-
bool isSystem, StringRef hash) override {
204+
bool startDependency(StringRef name, StringRef path, bool isClangModule, bool isSystem) override {
209205
return true;
210206
}
211207
bool finishDependency(bool isClangModule) override { return true; }
@@ -342,7 +338,7 @@ recordSourceFile(SourceFile *SF, StringRef indexStorePath,
342338
bool failed = false;
343339
auto consumer = makeRecordingConsumer(SF->getFilename(), indexStorePath,
344340
&diags, &recordFile, &failed);
345-
indexSourceFile(SF, /*Hash=*/"", *consumer);
341+
indexSourceFile(SF, *consumer);
346342

347343
if (!failed && !recordFile.empty())
348344
callback(recordFile, SF->getFilename());
@@ -482,7 +478,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
482478
bool failed = false;
483479
auto consumer = makeRecordingConsumer(filename, indexStorePath,
484480
&diags, &recordFile, &failed);
485-
indexModule(module, /*Hash=*/"", *consumer);
481+
indexModule(module, *consumer);
486482

487483
if (failed)
488484
return true;
@@ -531,7 +527,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
531527
records.emplace_back(outRecordFile, moduleName.str());
532528
return true;
533529
});
534-
indexModule(module, /*Hash=*/"", groupIndexConsumer);
530+
indexModule(module, groupIndexConsumer);
535531
if (failed)
536532
return true;
537533
}

test/SourceKit/Indexing/Inputs/implicit-vis/a.index.response

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
key.hash: <hash>,
32
key.dependencies: [
43
{
54
key.kind: source.lang.swift.import.module.swift,
65
key.name: "Swift",
76
key.filepath: Swift.swiftmodule,
8-
key.hash: <hash>,
97
key.is_system: 1
108
}
119
],

test/SourceKit/Indexing/Inputs/implicit-vis/b.index.response

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
key.hash: <hash>,
32
key.dependencies: [
43
{
54
key.kind: source.lang.swift.import.module.swift,
65
key.name: "Swift",
76
key.filepath: Swift.swiftmodule,
8-
key.hash: <hash>,
97
key.is_system: 1
108
}
119
],

test/SourceKit/Indexing/Inputs/test_module.index.response

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
{
2-
key.hash: <hash>,
32
key.dependencies: [
43
{
54
key.kind: source.lang.swift.import.module.swift,
65
key.name: "Swift",
76
key.filepath: Swift.swiftmodule,
8-
key.hash: <hash>,
97
key.is_system: 1
108
},
119
{
1210
key.kind: source.lang.swift.import.module.swift,
1311
key.name: "SwiftOnoneSupport",
1412
key.filepath: SwiftOnoneSupport.swiftmodule,
15-
key.hash: <hash>,
1613
key.is_system: 1,
1714
key.dependencies: [
1815
{
1916
key.kind: source.lang.swift.import.module.swift,
2017
key.name: "Swift",
2118
key.filepath: Swift.swiftmodule,
22-
key.hash: <hash>,
2319
key.is_system: 1
2420
}
2521
]

test/SourceKit/Indexing/index.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// FIXME(integers): %t.response content is non-deterministic with the new
2-
// integer protocols
3-
// XFAIL: *
4-
5-
// RUN: %sourcekitd-test -req=index %s -- -Xfrontend -serialize-diagnostics-path -Xfrontend %t.dia %s | %sed_clean > %t.response
1+
// RUN: %sourcekitd-test -req=index %s -- -Xfrontend -serialize-diagnostics-path -Xfrontend %t.dia %s | %sed_clean | sed -e 's/key.usr: \".*\"/key.usr: <usr>/g' > %t.response
62
// RUN: diff -u %s.response %t.response
73

84
var globV: Int

0 commit comments

Comments
 (0)