@@ -77,16 +77,10 @@ struct InvocationOptions {
77
77
const std::string PrimaryFile;
78
78
const CompilerInvocation Invok;
79
79
80
- // / All filesystem operations resulting from this invocation should use this
81
- // / filesystem.
82
- const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
83
-
84
80
InvocationOptions (ArrayRef<const char *> CArgs, StringRef PrimaryFile,
85
- CompilerInvocation Invok,
86
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem)
81
+ CompilerInvocation Invok)
87
82
: Args(_convertArgs(CArgs)), PrimaryFile(PrimaryFile),
88
- Invok (std::move(Invok)), FileSystem(FileSystem) {
89
- assert (FileSystem);
83
+ Invok (std::move(Invok)) {
90
84
// Assert invocation with a primary file. We want to avoid full typechecking
91
85
// for all files.
92
86
assert (!this ->PrimaryFile .empty ());
@@ -168,7 +162,6 @@ void InvocationOptions::profile(llvm::FoldingSetNodeID &ID) const {
168
162
for (auto &Arg : Args)
169
163
ID.AddString (Arg);
170
164
ID.AddString (PrimaryFile);
171
- ID.AddPointer (FileSystem.get ());
172
165
}
173
166
174
167
// ===----------------------------------------------------------------------===//
@@ -298,10 +291,13 @@ class ASTProducer : public ThreadSafeRefCountedBase<ASTProducer> {
298
291
return AST;
299
292
}
300
293
301
- void getASTUnitAsync (std::shared_ptr<SwiftASTManager> Mgr,
302
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
303
- std::function<void (ASTUnitRef Unit, StringRef Error)> Receiver);
294
+ void getASTUnitAsync (
295
+ std::shared_ptr<SwiftASTManager> Mgr,
296
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
297
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots,
298
+ std::function<void (ASTUnitRef Unit, StringRef Error)> Receiver);
304
299
bool shouldRebuild (SwiftASTManager::Implementation &MgrImpl,
300
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
305
301
ArrayRef<ImmutableTextSnapshotRef> Snapshots);
306
302
307
303
void enqueueConsumer (SwiftASTConsumerRef Consumer,
@@ -320,18 +316,23 @@ class ASTProducer : public ThreadSafeRefCountedBase<ASTProducer> {
320
316
}
321
317
322
318
private:
323
- ASTUnitRef getASTUnitImpl (SwiftASTManager::Implementation &MgrImpl,
324
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
325
- std::string &Error);
326
-
327
- ASTUnitRef createASTUnit (SwiftASTManager::Implementation &MgrImpl,
328
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
329
- std::string &Error);
330
-
331
- void findSnapshotAndOpenFiles (SwiftASTManager::Implementation &MgrImpl,
332
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
333
- SmallVectorImpl<FileContent> &Contents,
334
- std::string &Error) const ;
319
+ ASTUnitRef
320
+ getASTUnitImpl (SwiftASTManager::Implementation &MgrImpl,
321
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
322
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots,
323
+ std::string &Error);
324
+
325
+ ASTUnitRef
326
+ createASTUnit (SwiftASTManager::Implementation &MgrImpl,
327
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
328
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots,
329
+ std::string &Error);
330
+
331
+ void findSnapshotAndOpenFiles (
332
+ SwiftASTManager::Implementation &MgrImpl,
333
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
334
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots,
335
+ SmallVectorImpl<FileContent> &Contents, std::string &Error) const ;
335
336
};
336
337
337
338
typedef IntrusiveRefCntPtr<ASTProducer> ASTProducerRef;
@@ -598,15 +599,17 @@ SwiftInvocationRef SwiftASTManager::getInvocation(
598
599
return nullptr ;
599
600
}
600
601
601
- InvocationOptions Opts (OrigArgs, PrimaryFile, CompInvok, FileSystem );
602
+ InvocationOptions Opts (OrigArgs, PrimaryFile, CompInvok);
602
603
return new SwiftInvocation (
603
604
*new SwiftInvocation::Implementation (std::move (Opts)));
604
605
}
605
606
606
- void SwiftASTManager::processASTAsync (SwiftInvocationRef InvokRef,
607
- SwiftASTConsumerRef ASTConsumer,
608
- const void *OncePerASTToken,
609
- ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
607
+ void SwiftASTManager::processASTAsync (
608
+ SwiftInvocationRef InvokRef, SwiftASTConsumerRef ASTConsumer,
609
+ const void *OncePerASTToken,
610
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
611
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
612
+ assert (fileSystem);
610
613
ASTProducerRef Producer = Impl.getASTProducer (InvokRef);
611
614
612
615
if (ASTUnitRef Unit = Producer->getExistingAST ()) {
@@ -619,13 +622,13 @@ void SwiftASTManager::processASTAsync(SwiftInvocationRef InvokRef,
619
622
620
623
Producer->enqueueConsumer (ASTConsumer, Snapshots, OncePerASTToken);
621
624
622
- auto handleAST = [this , Producer, ASTConsumer](ASTUnitRef unit,
623
- StringRef error) {
625
+ auto handleAST = [this , Producer, ASTConsumer, fileSystem ](ASTUnitRef unit,
626
+ StringRef error) {
624
627
auto consumers = Producer->takeConsumers (
625
628
[&](SwiftASTConsumer *consumer,
626
629
ArrayRef<ImmutableTextSnapshotRef> snapshots) {
627
630
return consumer == ASTConsumer.get () ||
628
- !Producer->shouldRebuild (Impl, snapshots) ||
631
+ !Producer->shouldRebuild (Impl, fileSystem, snapshots) ||
629
632
(unit && consumer->canUseASTWithSnapshots (snapshots));
630
633
});
631
634
@@ -637,7 +640,8 @@ void SwiftASTManager::processASTAsync(SwiftInvocationRef InvokRef,
637
640
}
638
641
};
639
642
640
- Producer->getASTUnitAsync (shared_from_this (), Snapshots, std::move (handleAST));
643
+ Producer->getASTUnitAsync (shared_from_this (), fileSystem, Snapshots,
644
+ std::move (handleAST));
641
645
}
642
646
643
647
void SwiftASTManager::removeCachedAST (SwiftInvocationRef Invok) {
@@ -714,25 +718,31 @@ SwiftASTManager::Implementation::getMemoryBuffer(
714
718
return nullptr ;
715
719
}
716
720
717
- void ASTProducer::getASTUnitAsync (std::shared_ptr<SwiftASTManager> Mgr,
718
- ArrayRef<ImmutableTextSnapshotRef> Snaps,
719
- std::function<void (ASTUnitRef Unit, StringRef Error)> Receiver) {
721
+ void ASTProducer::getASTUnitAsync (
722
+ std::shared_ptr<SwiftASTManager> Mgr,
723
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
724
+ ArrayRef<ImmutableTextSnapshotRef> Snaps,
725
+ std::function<void (ASTUnitRef Unit, StringRef Error)> Receiver) {
720
726
721
727
ASTProducerRef ThisProducer = this ;
722
728
SmallVector<ImmutableTextSnapshotRef, 4 > Snapshots;
723
729
Snapshots.append (Snaps.begin (), Snaps.end ());
724
730
725
- Mgr->Impl .ASTBuildQueue .dispatch ([ThisProducer, Mgr, Snapshots, Receiver] {
726
- std::string Error;
727
- ASTUnitRef Unit = ThisProducer->getASTUnitImpl (Mgr->Impl , Snapshots, Error);
728
- Receiver (Unit, Error);
729
- }, /* isStackDeep=*/ true );
731
+ Mgr->Impl .ASTBuildQueue .dispatch (
732
+ [ThisProducer, Mgr, fileSystem, Snapshots, Receiver] {
733
+ std::string Error;
734
+ ASTUnitRef Unit = ThisProducer->getASTUnitImpl (Mgr->Impl , fileSystem,
735
+ Snapshots, Error);
736
+ Receiver (Unit, Error);
737
+ },
738
+ /* isStackDeep=*/ true );
730
739
}
731
740
732
- ASTUnitRef ASTProducer::getASTUnitImpl (SwiftASTManager::Implementation &MgrImpl,
733
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
734
- std::string &Error) {
735
- if (!AST || shouldRebuild (MgrImpl, Snapshots)) {
741
+ ASTUnitRef ASTProducer::getASTUnitImpl (
742
+ SwiftASTManager::Implementation &MgrImpl,
743
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
744
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots, std::string &Error) {
745
+ if (!AST || shouldRebuild (MgrImpl, fileSystem, Snapshots)) {
736
746
bool IsRebuild = AST != nullptr ;
737
747
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
738
748
@@ -746,7 +756,7 @@ ASTUnitRef ASTProducer::getASTUnitImpl(SwiftASTManager::Implementation &MgrImpl,
746
756
Log->getOS () << Opts.Invok .getModuleName () << ' /' << Opts.PrimaryFile ;
747
757
}
748
758
749
- auto NewAST = createASTUnit (MgrImpl, Snapshots, Error);
759
+ auto NewAST = createASTUnit (MgrImpl, fileSystem, Snapshots, Error);
750
760
{
751
761
// FIXME: ThreadSafeRefCntPtr is racy.
752
762
llvm::sys::ScopedLock L (Mtx);
@@ -799,8 +809,10 @@ ASTProducer::takeConsumers(ConsumerPredicate predicate) {
799
809
return consumers;
800
810
}
801
811
802
- bool ASTProducer::shouldRebuild (SwiftASTManager::Implementation &MgrImpl,
803
- ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
812
+ bool ASTProducer::shouldRebuild (
813
+ SwiftASTManager::Implementation &MgrImpl,
814
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
815
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
804
816
const SwiftInvocation::Implementation &Invok = InvokRef->Impl ;
805
817
806
818
// Check if the inputs changed.
@@ -819,8 +831,7 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
819
831
}
820
832
}
821
833
if (!FoundSnapshot)
822
- InputStamps.push_back (
823
- MgrImpl.getBufferStamp (File, Invok.Opts .FileSystem ));
834
+ InputStamps.push_back (MgrImpl.getBufferStamp (File, fileSystem));
824
835
}
825
836
assert (InputStamps.size () ==
826
837
Invok.Opts .Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
@@ -829,7 +840,7 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
829
840
830
841
for (auto &Dependency : DependencyStamps) {
831
842
if (Dependency.second !=
832
- MgrImpl.getBufferStamp (Dependency.first , Invok. Opts . FileSystem ))
843
+ MgrImpl.getBufferStamp (Dependency.first , fileSystem ))
833
844
return true ;
834
845
}
835
846
@@ -895,16 +906,17 @@ static void collectModuleDependencies(ModuleDecl *TopMod,
895
906
896
907
static std::atomic<uint64_t > ASTUnitGeneration{ 0 };
897
908
898
- ASTUnitRef ASTProducer::createASTUnit (SwiftASTManager::Implementation &MgrImpl,
899
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
900
- std::string &Error) {
909
+ ASTUnitRef ASTProducer::createASTUnit (
910
+ SwiftASTManager::Implementation &MgrImpl,
911
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
912
+ ArrayRef<ImmutableTextSnapshotRef> Snapshots, std::string &Error) {
901
913
++MgrImpl.Stats ->numASTBuilds ;
902
914
903
915
Stamps.clear ();
904
916
DependencyStamps.clear ();
905
917
906
918
SmallVector<FileContent, 8 > Contents;
907
- findSnapshotAndOpenFiles (MgrImpl, Snapshots, Contents, Error);
919
+ findSnapshotAndOpenFiles (MgrImpl, fileSystem, Snapshots, Contents, Error);
908
920
909
921
for (auto &Content : Contents)
910
922
Stamps.push_back (Content.Stamp );
@@ -936,7 +948,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
936
948
937
949
Invocation.getLangOptions ().CollectParsedToken = true ;
938
950
939
- CompIns.getSourceMgr ().setFileSystem (InvokRef-> Impl . Opts . FileSystem );
951
+ CompIns.getSourceMgr ().setFileSystem (fileSystem );
940
952
if (CompIns.setup (Invocation)) {
941
953
// FIXME: Report the diagnostic.
942
954
LOG_WARN_FUNC (" Compilation setup failed!!!" );
@@ -959,9 +971,8 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
959
971
// FIXME: There exists a small window where the module file may have been
960
972
// modified after compilation finished and before we get its stamp.
961
973
for (auto &Filename : Filenames) {
962
- DependencyStamps.push_back (std::make_pair (
963
- Filename,
964
- MgrImpl.getBufferStamp (Filename, InvokRef->Impl .Opts .FileSystem )));
974
+ DependencyStamps.push_back (
975
+ std::make_pair (Filename, MgrImpl.getBufferStamp (Filename, fileSystem)));
965
976
}
966
977
967
978
// Since we only typecheck the primary file (plus referenced constructs
@@ -995,6 +1006,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
995
1006
996
1007
void ASTProducer::findSnapshotAndOpenFiles (
997
1008
SwiftASTManager::Implementation &MgrImpl,
1009
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
998
1010
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
999
1011
SmallVectorImpl<FileContent> &Contents, std::string &Error) const {
1000
1012
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
@@ -1013,8 +1025,7 @@ void ASTProducer::findSnapshotAndOpenFiles(
1013
1025
if (FoundSnapshot)
1014
1026
continue ;
1015
1027
1016
- auto Content =
1017
- MgrImpl.getFileContent (File, IsPrimary, Opts.FileSystem , Error);
1028
+ auto Content = MgrImpl.getFileContent (File, IsPrimary, fileSystem, Error);
1018
1029
if (!Content.Buffer ) {
1019
1030
LOG_WARN_FUNC (" failed getting file contents for " << File << " : "
1020
1031
<< Error);
0 commit comments