@@ -285,15 +285,14 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
285
285
assert (Cancelled || ManuallyVisitedAccessorStack.empty ());
286
286
}
287
287
288
- void visitModule (ModuleDecl &Mod, StringRef Hash );
288
+ void visitModule (ModuleDecl &Mod);
289
289
void visitDeclContext (DeclContext *DC);
290
290
291
291
private:
292
292
bool visitImports (SourceFileOrModule Mod,
293
293
llvm::SmallPtrSetImpl<ModuleDecl *> &Visited);
294
294
295
- bool handleSourceOrModuleFile (SourceFileOrModule SFOrMod, StringRef KnownHash,
296
- bool &HashIsKnown);
295
+ bool handleSourceOrModuleFile (SourceFileOrModule SFOrMod);
297
296
298
297
bool walkToDeclPre (Decl *D, CharSourceRange Range) override {
299
298
// Do not handle unavailable decls.
@@ -565,10 +564,6 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
565
564
// / \returns false if AST visitation should stop.
566
565
bool handleWitnesses (Decl *D, SmallVectorImpl<IndexedWitness> &explicitWitnesses);
567
566
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);
572
567
void getRecursiveModuleImports (ModuleDecl &Mod,
573
568
SmallVectorImpl<ModuleDecl *> &Imports);
574
569
void
@@ -601,7 +596,7 @@ void IndexSwiftASTWalker::visitDeclContext(DeclContext *Context) {
601
596
ManuallyVisitedAccessorStack.pop_back ();
602
597
}
603
598
604
- void IndexSwiftASTWalker::visitModule (ModuleDecl &Mod, StringRef KnownHash ) {
599
+ void IndexSwiftASTWalker::visitModule (ModuleDecl &Mod) {
605
600
SourceFile *SrcFile = nullptr ;
606
601
for (auto File : Mod.getFiles ()) {
607
602
if (auto SF = dyn_cast<SourceFile>(File)) {
@@ -613,41 +608,23 @@ void IndexSwiftASTWalker::visitModule(ModuleDecl &Mod, StringRef KnownHash) {
613
608
}
614
609
}
615
610
616
- bool HashIsKnown;
617
611
if (SrcFile != nullptr ) {
618
612
IsModuleFile = false ;
619
- if (!handleSourceOrModuleFile (*SrcFile, KnownHash, HashIsKnown ))
613
+ if (!handleSourceOrModuleFile (*SrcFile))
620
614
return ;
621
- if (HashIsKnown)
622
- return ; // No need to report symbols.
623
615
walk (*SrcFile);
624
616
} else {
625
617
IsModuleFile = true ;
626
618
isSystemModule = Mod.isSystemModule ();
627
- if (!handleSourceOrModuleFile (Mod, KnownHash, HashIsKnown ))
619
+ if (!handleSourceOrModuleFile (Mod))
628
620
return ;
629
- if (HashIsKnown)
630
- return ; // No need to report symbols.
631
621
walk (Mod);
632
622
}
633
623
}
634
624
635
- bool IndexSwiftASTWalker::handleSourceOrModuleFile (SourceFileOrModule SFOrMod,
636
- StringRef KnownHash,
637
- bool &HashIsKnown) {
625
+ bool IndexSwiftASTWalker::handleSourceOrModuleFile (SourceFileOrModule SFOrMod) {
638
626
// Common reporting for TU/module file.
639
627
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.
651
628
llvm::SmallPtrSet<ModuleDecl *, 16 > Visited;
652
629
return visitImports (SFOrMod, Visited);
653
630
}
@@ -703,16 +680,8 @@ bool IndexSwiftASTWalker::visitImports(
703
680
continue ;
704
681
bool IsClangModule = *IsClangModuleOpt;
705
682
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
-
714
683
if (!IdxConsumer.startDependency (Mod->getName ().str (), Path, IsClangModule,
715
- Mod->isSystemModule (), Hash ))
684
+ Mod->isSystemModule ()))
716
685
return false ;
717
686
if (!IsClangModule)
718
687
if (!visitImports (*Mod, Visited))
@@ -1441,43 +1410,6 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
1441
1410
return !Cancelled;
1442
1411
}
1443
1412
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
-
1481
1413
void IndexSwiftASTWalker::getRecursiveModuleImports (
1482
1414
ModuleDecl &Mod, SmallVectorImpl<ModuleDecl *> &Imports) {
1483
1415
auto It = ImportsMap.find (&Mod);
@@ -1575,13 +1507,6 @@ void IndexSwiftASTWalker::collectRecursiveModuleImports(
1575
1507
}
1576
1508
}
1577
1509
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
-
1585
1510
static Type getContextFreeInterfaceType (ValueDecl *VD) {
1586
1511
if (auto AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
1587
1512
return AFD->getMethodInterfaceType ();
@@ -1661,19 +1586,17 @@ void index::indexDeclContext(DeclContext *DC, IndexDataConsumer &consumer) {
1661
1586
consumer.finish ();
1662
1587
}
1663
1588
1664
- void index::indexSourceFile (SourceFile *SF, StringRef hash,
1665
- IndexDataConsumer &consumer) {
1589
+ void index::indexSourceFile (SourceFile *SF, IndexDataConsumer &consumer) {
1666
1590
assert (SF);
1667
1591
unsigned bufferID = SF->getBufferID ().getValue ();
1668
1592
IndexSwiftASTWalker walker (consumer, SF->getASTContext (), bufferID);
1669
- walker.visitModule (*SF->getParentModule (), hash );
1593
+ walker.visitModule (*SF->getParentModule ());
1670
1594
consumer.finish ();
1671
1595
}
1672
1596
1673
- void index::indexModule (ModuleDecl *module , StringRef hash,
1674
- IndexDataConsumer &consumer) {
1597
+ void index::indexModule (ModuleDecl *module , IndexDataConsumer &consumer) {
1675
1598
assert (module );
1676
1599
IndexSwiftASTWalker walker (consumer, module ->getASTContext ());
1677
- walker.visitModule (*module , hash );
1600
+ walker.visitModule (*module );
1678
1601
consumer.finish ();
1679
1602
}
0 commit comments