@@ -302,14 +302,10 @@ class ASTBuildOperation
302
302
const SwiftInvocationRef InvokRef;
303
303
const IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
304
304
305
- // / The contents of all explicit input files of the compiler invoation.
305
+ // / The contents of all explicit input files of the compiler invoation, which
306
+ // / can be determined at construction time of the \c ASTBuildOperation.
306
307
const std::vector<FileContentRef> FileContents;
307
308
308
- // / Stamps of files used to build the AST. \c Stamps contains the stamps of
309
- // / all explicit input files, which can be determined at construction time of
310
- // / the \c ASTBuildOperation.
311
- const std::vector<BufferStamp> Stamps;
312
-
313
309
// / \c DependencyStamps contains the stamps of all module depenecies needed
314
310
// / for the AST build. These stamps are only known after the AST is built.
315
311
// / Before the AST has been built, we thus assume that all dependency stamps
@@ -369,25 +365,19 @@ class ASTBuildOperation
369
365
}
370
366
371
367
// / Create a vector of \c FileContents containing all files explicitly
372
- // / referenced by the compiler invocation and a vector of buffer stamps of
373
- // / those files.
374
- std::pair<std::vector<FileContentRef>, std::vector<BufferStamp>>
375
- fileContentsAndStampsForFilesInCompilerInvocation ();
368
+ // / referenced by the compiler invocation.
369
+ std::vector<FileContentRef> fileContentsForFilesInCompilerInvocation ();
376
370
377
371
public:
378
372
ASTBuildOperation (IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
379
373
SwiftInvocationRef InvokRef, SwiftASTManagerRef ASTManager,
380
374
std::function<void (void )> DidFinishCallback)
381
375
: InvokRef(InvokRef), FileSystem(FileSystem), ASTManager(ASTManager),
382
376
DidFinishCallback (DidFinishCallback) {
383
- auto FileContentsAndStamps =
384
- fileContentsAndStampsForFilesInCompilerInvocation ();
385
377
// const_cast is fine here. We just want to guard against modifying these
386
378
// fields later on. It's fine to set them in the constructor.
387
379
const_cast <std::vector<FileContentRef> &>(this ->FileContents ) =
388
- std::move (FileContentsAndStamps.first );
389
- const_cast <std::vector<BufferStamp> &>(this ->Stamps ) =
390
- FileContentsAndStamps.second ;
380
+ fileContentsForFilesInCompilerInvocation ();
391
381
}
392
382
393
383
~ASTBuildOperation () {
@@ -413,7 +403,7 @@ class ASTBuildOperation
413
403
414
404
size_t getMemoryCost () {
415
405
return sizeof (*this ) + getVectorMemoryCost (FileContents) +
416
- getVectorMemoryCost (Stamps) + Result.getMemoryCost ();
406
+ Result.getMemoryCost ();
417
407
}
418
408
419
409
// / Schedule building this AST on the given \p Queue.
@@ -849,16 +839,14 @@ SwiftASTManager::Implementation::getMemoryBuffer(
849
839
return nullptr ;
850
840
}
851
841
852
- std::pair<std:: vector<FileContentRef>, std::vector<BufferStamp> >
853
- ASTBuildOperation::fileContentsAndStampsForFilesInCompilerInvocation () {
842
+ std::vector<FileContentRef>
843
+ ASTBuildOperation::fileContentsForFilesInCompilerInvocation () {
854
844
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
855
845
std::string Error; // is ignored
856
846
857
847
std::vector<FileContentRef> FileContents;
858
- std::vector<BufferStamp> Stamps;
859
848
FileContents.reserve (
860
849
Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
861
- Stamps.reserve (Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
862
850
863
851
// IMPORTANT: The computation of stamps must match the one in
864
852
// matchesSourceState.
@@ -875,35 +863,25 @@ ASTBuildOperation::fileContentsAndStampsForFilesInCompilerInvocation() {
875
863
Content->Buffer =
876
864
llvm::WritableMemoryBuffer::getNewMemBuffer (0 , Filename);
877
865
}
878
- Stamps.push_back (Content->Stamp );
879
866
FileContents.push_back (Content);
880
867
}
881
- assert (Stamps.size () ==
882
- Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
883
868
assert (FileContents.size () ==
884
869
Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
885
- return std::make_pair ( FileContents, Stamps) ;
870
+ return FileContents;
886
871
}
887
872
888
873
bool ASTBuildOperation::matchesSourceState (
889
874
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem) {
890
875
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
891
876
892
- // Check if the inputs changed.
893
- std::vector<BufferStamp> InputStamps;
894
- InputStamps.reserve (
895
- Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
896
- // IMPORTANT: The computation of stamps must match the one in
897
- // snapshotAndStampsForFilesInCompilerInvocation.
898
- for (const auto &input :
899
- Opts.Invok .getFrontendOptions ().InputsAndOutputs .getAllInputs ()) {
900
- InputStamps.push_back (
901
- ASTManager->Impl .getBufferStamp (input.getFileName (), OtherFileSystem));
877
+ auto Inputs = Opts.Invok .getFrontendOptions ().InputsAndOutputs .getAllInputs ();
878
+ for (size_t I = 0 ; I < Inputs.size (); I++) {
879
+ if (getFileContents ()[I]->Stamp !=
880
+ ASTManager->Impl .getBufferStamp (Inputs[I].getFileName (),
881
+ OtherFileSystem)) {
882
+ return false ;
883
+ }
902
884
}
903
- assert (InputStamps.size () ==
904
- Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
905
- if (Stamps != InputStamps)
906
- return false ;
907
885
908
886
for (auto &Dependency : DependencyStamps) {
909
887
if (Dependency.second !=
0 commit comments