@@ -372,22 +372,17 @@ class ASTBuildOperation
372
372
373
373
// / Create a vector of text snapshots containing all files explicitly
374
374
// / referenced by the compiler invocation and a vector of buffer stamps of
375
- // / those files. For all files that have a snapshot specified in \p
376
- // / FixedSnapshots, that snapshot is used. For all other files \p FileSystem
377
- // / will be consulted for the current contents of the file.
375
+ // / those files.
378
376
std::pair<std::vector<ImmutableTextSnapshotRef>, std::vector<BufferStamp>>
379
- snapshotAndStampsForFilesInCompilerInvocation (
380
- ArrayRef<ImmutableTextSnapshotRef> FixedSnapshots);
377
+ snapshotAndStampsForFilesInCompilerInvocation ();
381
378
382
379
public:
383
380
ASTBuildOperation (IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
384
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
385
381
SwiftInvocationRef InvokRef, SwiftASTManagerRef ASTManager,
386
382
std::function<void (void )> DidFinishCallback)
387
383
: InvokRef(InvokRef), FileSystem(FileSystem), ASTManager(ASTManager),
388
384
DidFinishCallback (DidFinishCallback) {
389
- auto SnapshotsAndStamps =
390
- snapshotAndStampsForFilesInCompilerInvocation (Snapshots);
385
+ auto SnapshotsAndStamps = snapshotAndStampsForFilesInCompilerInvocation ();
391
386
// const_cast is fine here. We just want to guard against modifying these
392
387
// fields later on. It's fine to set them in the constructor.
393
388
const_cast <std::vector<ImmutableTextSnapshotRef> &>(this ->Snapshots ) =
@@ -441,8 +436,7 @@ class ASTBuildOperation
441
436
// / listed in the input files. As such, this might be \c true before the AST
442
437
// / build and \c false after the AST has been built. See documentation on \c
443
438
// / DependencyStamps for more info.
444
- bool matchesSourceState (IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
445
- ArrayRef<ImmutableTextSnapshotRef> Snapshots);
439
+ bool matchesSourceState (IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem);
446
440
447
441
// / Called when a consumer is cancelled. This calls \c cancelled on the
448
442
// / consumer, removes it from the \c Consumers severed by this build operation
@@ -495,14 +489,12 @@ class ASTProducer : public std::enable_shared_from_this<ASTProducer> {
495
489
496
490
// / Returns the latest build operation which can serve the \p Consumer or
497
491
// / \c nullptr if no such build operation exists.
498
- // / \p FileSystem and \p Snapshots describe the source state that the \p
499
- // / Consumer expects.
500
492
// /
501
493
// / Assumes that \c BuildOperationsMtx has been claimed.
502
494
ASTBuildOperationRef getBuildOperationForConsumer (
503
495
SwiftASTConsumerRef Consumer,
504
496
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
505
- ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr);
497
+ SwiftASTManagerRef Mgr);
506
498
507
499
public:
508
500
explicit ASTProducer (SwiftInvocationRef InvokRef)
@@ -513,7 +505,6 @@ class ASTProducer : public std::enable_shared_from_this<ASTProducer> {
513
505
// / cancelled, \c failed or \c handlePrimaryAST callback.
514
506
void enqueueConsumer (SwiftASTConsumerRef Consumer,
515
507
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
516
- ArrayRef<ImmutableTextSnapshotRef> Snapshots,
517
508
SwiftASTManagerRef Mgr);
518
509
519
510
size_t getMemoryCost () const {
@@ -754,8 +745,7 @@ SwiftInvocationRef SwiftASTManager::getInvocation(
754
745
void SwiftASTManager::processASTAsync (
755
746
SwiftInvocationRef InvokRef, SwiftASTConsumerRef ASTConsumer,
756
747
const void *OncePerASTToken, SourceKitCancellationToken CancellationToken,
757
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
758
- ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
748
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem) {
759
749
assert (fileSystem);
760
750
ASTProducerRef Producer = Impl.getASTProducer (InvokRef);
761
751
@@ -775,8 +765,7 @@ void SwiftASTManager::processASTAsync(
775
765
Impl.ScheduledConsumers .push_back ({ASTConsumer, OncePerASTToken});
776
766
}
777
767
778
- Producer->enqueueConsumer (ASTConsumer, fileSystem, Snapshots,
779
- shared_from_this ());
768
+ Producer->enqueueConsumer (ASTConsumer, fileSystem, shared_from_this ());
780
769
781
770
auto WeakConsumer = SwiftASTConsumerWeakRef (ASTConsumer);
782
771
Impl.ReqTracker ->setCancellationHandler (CancellationToken, [WeakConsumer] {
@@ -860,26 +849,12 @@ SwiftASTManager::Implementation::getMemoryBuffer(
860
849
return nullptr ;
861
850
}
862
851
863
- // / If \p Snapshots contains a snapshot for the given \p Filename return it.
864
- // / Otherwise, return \c None.
865
- Optional<ImmutableTextSnapshotRef>
866
- findSnapshot (ArrayRef<ImmutableTextSnapshotRef> Snapshots,
867
- const std::string &Filename) {
868
- for (auto &Snap : Snapshots) {
869
- if (Snap->getFilename () == Filename) {
870
- return Snap;
871
- }
872
- }
873
- return None;
874
- }
875
-
876
852
std::pair<std::vector<ImmutableTextSnapshotRef>, std::vector<BufferStamp>>
877
- ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation (
878
- ArrayRef<ImmutableTextSnapshotRef> FixedSnapshots) {
853
+ ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation () {
879
854
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
880
855
std::string Error; // is ignored
881
856
882
- std::vector<ImmutableTextSnapshotRef> Snapshots = FixedSnapshots. vec () ;
857
+ std::vector<ImmutableTextSnapshotRef> Snapshots;
883
858
std::vector<BufferStamp> Stamps;
884
859
Stamps.reserve (Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
885
860
@@ -889,15 +864,11 @@ ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation(
889
864
Opts.Invok .getFrontendOptions ().InputsAndOutputs .getAllInputs ()) {
890
865
const std::string &Filename = input.getFileName ();
891
866
bool IsPrimary = input.isPrimary ();
892
- if (auto FoundSnapshot = findSnapshot (Snapshots, Filename)) {
893
- Stamps.push_back (FoundSnapshot.getValue ()->getStamp ());
894
- } else {
895
- auto Content = ASTManager->Impl .getFileContent (Filename, IsPrimary,
896
- FileSystem, Error);
897
- Stamps.push_back (Content.Stamp );
898
- if (Content.Snapshot ) {
899
- Snapshots.push_back (Content.Snapshot );
900
- }
867
+ auto Content =
868
+ ASTManager->Impl .getFileContent (Filename, IsPrimary, FileSystem, Error);
869
+ Stamps.push_back (Content.Stamp );
870
+ if (Content.Snapshot ) {
871
+ Snapshots.push_back (Content.Snapshot );
901
872
}
902
873
}
903
874
assert (Stamps.size () ==
@@ -906,8 +877,7 @@ ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation(
906
877
}
907
878
908
879
bool ASTBuildOperation::matchesSourceState (
909
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem,
910
- ArrayRef<ImmutableTextSnapshotRef> OtherSnapshots) {
880
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem) {
911
881
const SwiftInvocation::Implementation &Invok = InvokRef->Impl ;
912
882
913
883
// Check if the inputs changed.
@@ -918,13 +888,8 @@ bool ASTBuildOperation::matchesSourceState(
918
888
// snapshotAndStampsForFilesInCompilerInvocation.
919
889
for (const auto &input :
920
890
Invok.Opts .Invok .getFrontendOptions ().InputsAndOutputs .getAllInputs ()) {
921
- const std::string &File = input.getFileName ();
922
- if (auto FoundSnapshot = findSnapshot (OtherSnapshots, File)) {
923
- InputStamps.push_back (FoundSnapshot.getValue ()->getStamp ());
924
- } else {
925
- InputStamps.push_back (
926
- ASTManager->Impl .getBufferStamp (File, OtherFileSystem));
927
- }
891
+ InputStamps.push_back (
892
+ ASTManager->Impl .getBufferStamp (input.getFileName (), OtherFileSystem));
928
893
}
929
894
assert (InputStamps.size () ==
930
895
Invok.Opts .Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
@@ -1249,12 +1214,12 @@ bool ASTBuildOperation::addConsumer(SwiftASTConsumerRef Consumer) {
1249
1214
ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer (
1250
1215
SwiftASTConsumerRef Consumer,
1251
1216
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
1252
- ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr) {
1217
+ SwiftASTManagerRef Mgr) {
1253
1218
for (auto &BuildOp : llvm::reverse (BuildOperations)) {
1254
1219
if (BuildOp->isCancelled ()) {
1255
1220
continue ;
1256
1221
}
1257
- if (BuildOp->matchesSourceState (FileSystem, Snapshots )) {
1222
+ if (BuildOp->matchesSourceState (FileSystem)) {
1258
1223
++Mgr->Impl .Stats ->numASTCacheHits ;
1259
1224
return BuildOp;
1260
1225
} else if (Consumer->canUseASTWithSnapshots (BuildOp->getSnapshots ())) {
@@ -1268,19 +1233,18 @@ ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer(
1268
1233
void ASTProducer::enqueueConsumer (
1269
1234
SwiftASTConsumerRef Consumer,
1270
1235
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
1271
- ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr) {
1236
+ SwiftASTManagerRef Mgr) {
1272
1237
// We can't use a llvm::sys::ScopedLock here because we need to unlock it
1273
1238
// before calling enqueueConsumer again in the !WasAdded case below.
1274
1239
std::unique_lock<llvm::sys::Mutex> BuildOperationsLock (BuildOperationsMtx);
1275
- if (auto BuildOp =
1276
- getBuildOperationForConsumer (Consumer, FileSystem, Snapshots, Mgr)) {
1240
+ if (auto BuildOp = getBuildOperationForConsumer (Consumer, FileSystem, Mgr)) {
1277
1241
bool WasAdded = BuildOp->addConsumer (Consumer);
1278
1242
if (!WasAdded) {
1279
1243
// The build operation was cancelled after the call to
1280
1244
// getBuildOperationForConsumer but before the consumer could be added.
1281
1245
// This should be an absolute edge case. Let's just try again.
1282
1246
BuildOperationsLock.unlock ();
1283
- enqueueConsumer (Consumer, FileSystem, Snapshots, Mgr);
1247
+ enqueueConsumer (Consumer, FileSystem, Mgr);
1284
1248
return ;
1285
1249
}
1286
1250
} else {
@@ -1296,7 +1260,7 @@ void ASTProducer::enqueueConsumer(
1296
1260
}
1297
1261
};
1298
1262
ASTBuildOperationRef NewBuildOp = std::make_shared<ASTBuildOperation>(
1299
- FileSystem, Snapshots, InvokRef, Mgr, DidFinishCallback);
1263
+ FileSystem, InvokRef, Mgr, DidFinishCallback);
1300
1264
BuildOperations.push_back (NewBuildOp);
1301
1265
NewBuildOp->addConsumer (Consumer);
1302
1266
NewBuildOp->schedule (Mgr->Impl .ASTBuildQueue );
0 commit comments