Skip to content

Commit 757ee55

Browse files
committed
[SourceKit] Remove ability to specify fixed snapshots to use when building an AST
The feature was never used and just complicated the implementation.
1 parent 2668223 commit 757ee55

File tree

2 files changed

+24
-62
lines changed

2 files changed

+24
-62
lines changed

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 23 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,17 @@ class ASTBuildOperation
372372

373373
/// Create a vector of text snapshots containing all files explicitly
374374
/// 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.
378376
std::pair<std::vector<ImmutableTextSnapshotRef>, std::vector<BufferStamp>>
379-
snapshotAndStampsForFilesInCompilerInvocation(
380-
ArrayRef<ImmutableTextSnapshotRef> FixedSnapshots);
377+
snapshotAndStampsForFilesInCompilerInvocation();
381378

382379
public:
383380
ASTBuildOperation(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
384-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
385381
SwiftInvocationRef InvokRef, SwiftASTManagerRef ASTManager,
386382
std::function<void(void)> DidFinishCallback)
387383
: InvokRef(InvokRef), FileSystem(FileSystem), ASTManager(ASTManager),
388384
DidFinishCallback(DidFinishCallback) {
389-
auto SnapshotsAndStamps =
390-
snapshotAndStampsForFilesInCompilerInvocation(Snapshots);
385+
auto SnapshotsAndStamps = snapshotAndStampsForFilesInCompilerInvocation();
391386
// const_cast is fine here. We just want to guard against modifying these
392387
// fields later on. It's fine to set them in the constructor.
393388
const_cast<std::vector<ImmutableTextSnapshotRef> &>(this->Snapshots) =
@@ -441,8 +436,7 @@ class ASTBuildOperation
441436
/// listed in the input files. As such, this might be \c true before the AST
442437
/// build and \c false after the AST has been built. See documentation on \c
443438
/// DependencyStamps for more info.
444-
bool matchesSourceState(IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
445-
ArrayRef<ImmutableTextSnapshotRef> Snapshots);
439+
bool matchesSourceState(IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem);
446440

447441
/// Called when a consumer is cancelled. This calls \c cancelled on the
448442
/// 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> {
495489

496490
/// Returns the latest build operation which can serve the \p Consumer or
497491
/// \c nullptr if no such build operation exists.
498-
/// \p FileSystem and \p Snapshots describe the source state that the \p
499-
/// Consumer expects.
500492
///
501493
/// Assumes that \c BuildOperationsMtx has been claimed.
502494
ASTBuildOperationRef getBuildOperationForConsumer(
503495
SwiftASTConsumerRef Consumer,
504496
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
505-
ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr);
497+
SwiftASTManagerRef Mgr);
506498

507499
public:
508500
explicit ASTProducer(SwiftInvocationRef InvokRef)
@@ -513,7 +505,6 @@ class ASTProducer : public std::enable_shared_from_this<ASTProducer> {
513505
/// cancelled, \c failed or \c handlePrimaryAST callback.
514506
void enqueueConsumer(SwiftASTConsumerRef Consumer,
515507
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
516-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
517508
SwiftASTManagerRef Mgr);
518509

519510
size_t getMemoryCost() const {
@@ -754,8 +745,7 @@ SwiftInvocationRef SwiftASTManager::getInvocation(
754745
void SwiftASTManager::processASTAsync(
755746
SwiftInvocationRef InvokRef, SwiftASTConsumerRef ASTConsumer,
756747
const void *OncePerASTToken, SourceKitCancellationToken CancellationToken,
757-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
758-
ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
748+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem) {
759749
assert(fileSystem);
760750
ASTProducerRef Producer = Impl.getASTProducer(InvokRef);
761751

@@ -775,8 +765,7 @@ void SwiftASTManager::processASTAsync(
775765
Impl.ScheduledConsumers.push_back({ASTConsumer, OncePerASTToken});
776766
}
777767

778-
Producer->enqueueConsumer(ASTConsumer, fileSystem, Snapshots,
779-
shared_from_this());
768+
Producer->enqueueConsumer(ASTConsumer, fileSystem, shared_from_this());
780769

781770
auto WeakConsumer = SwiftASTConsumerWeakRef(ASTConsumer);
782771
Impl.ReqTracker->setCancellationHandler(CancellationToken, [WeakConsumer] {
@@ -860,26 +849,12 @@ SwiftASTManager::Implementation::getMemoryBuffer(
860849
return nullptr;
861850
}
862851

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-
876852
std::pair<std::vector<ImmutableTextSnapshotRef>, std::vector<BufferStamp>>
877-
ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation(
878-
ArrayRef<ImmutableTextSnapshotRef> FixedSnapshots) {
853+
ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation() {
879854
const InvocationOptions &Opts = InvokRef->Impl.Opts;
880855
std::string Error; // is ignored
881856

882-
std::vector<ImmutableTextSnapshotRef> Snapshots = FixedSnapshots.vec();
857+
std::vector<ImmutableTextSnapshotRef> Snapshots;
883858
std::vector<BufferStamp> Stamps;
884859
Stamps.reserve(Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
885860

@@ -889,15 +864,11 @@ ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation(
889864
Opts.Invok.getFrontendOptions().InputsAndOutputs.getAllInputs()) {
890865
const std::string &Filename = input.getFileName();
891866
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);
901872
}
902873
}
903874
assert(Stamps.size() ==
@@ -906,8 +877,7 @@ ASTBuildOperation::snapshotAndStampsForFilesInCompilerInvocation(
906877
}
907878

908879
bool ASTBuildOperation::matchesSourceState(
909-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem,
910-
ArrayRef<ImmutableTextSnapshotRef> OtherSnapshots) {
880+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem) {
911881
const SwiftInvocation::Implementation &Invok = InvokRef->Impl;
912882

913883
// Check if the inputs changed.
@@ -918,13 +888,8 @@ bool ASTBuildOperation::matchesSourceState(
918888
// snapshotAndStampsForFilesInCompilerInvocation.
919889
for (const auto &input :
920890
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));
928893
}
929894
assert(InputStamps.size() ==
930895
Invok.Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
@@ -1249,12 +1214,12 @@ bool ASTBuildOperation::addConsumer(SwiftASTConsumerRef Consumer) {
12491214
ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer(
12501215
SwiftASTConsumerRef Consumer,
12511216
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
1252-
ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr) {
1217+
SwiftASTManagerRef Mgr) {
12531218
for (auto &BuildOp : llvm::reverse(BuildOperations)) {
12541219
if (BuildOp->isCancelled()) {
12551220
continue;
12561221
}
1257-
if (BuildOp->matchesSourceState(FileSystem, Snapshots)) {
1222+
if (BuildOp->matchesSourceState(FileSystem)) {
12581223
++Mgr->Impl.Stats->numASTCacheHits;
12591224
return BuildOp;
12601225
} else if (Consumer->canUseASTWithSnapshots(BuildOp->getSnapshots())) {
@@ -1268,19 +1233,18 @@ ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer(
12681233
void ASTProducer::enqueueConsumer(
12691234
SwiftASTConsumerRef Consumer,
12701235
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
1271-
ArrayRef<ImmutableTextSnapshotRef> Snapshots, SwiftASTManagerRef Mgr) {
1236+
SwiftASTManagerRef Mgr) {
12721237
// We can't use a llvm::sys::ScopedLock here because we need to unlock it
12731238
// before calling enqueueConsumer again in the !WasAdded case below.
12741239
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)) {
12771241
bool WasAdded = BuildOp->addConsumer(Consumer);
12781242
if (!WasAdded) {
12791243
// The build operation was cancelled after the call to
12801244
// getBuildOperationForConsumer but before the consumer could be added.
12811245
// This should be an absolute edge case. Let's just try again.
12821246
BuildOperationsLock.unlock();
1283-
enqueueConsumer(Consumer, FileSystem, Snapshots, Mgr);
1247+
enqueueConsumer(Consumer, FileSystem, Mgr);
12841248
return;
12851249
}
12861250
} else {
@@ -1296,7 +1260,7 @@ void ASTProducer::enqueueConsumer(
12961260
}
12971261
};
12981262
ASTBuildOperationRef NewBuildOp = std::make_shared<ASTBuildOperation>(
1299-
FileSystem, Snapshots, InvokRef, Mgr, DidFinishCallback);
1263+
FileSystem, InvokRef, Mgr, DidFinishCallback);
13001264
BuildOperations.push_back(NewBuildOp);
13011265
NewBuildOp->addConsumer(Consumer);
13021266
NewBuildOp->schedule(Mgr->Impl.ASTBuildQueue);

tools/SourceKit/lib/SwiftLang/SwiftASTManager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ class SwiftASTManager : public std::enable_shared_from_this<SwiftASTManager> {
248248
processASTAsync(SwiftInvocationRef Invok, SwiftASTConsumerRef ASTConsumer,
249249
const void *OncePerASTToken,
250250
SourceKitCancellationToken CancellationToken,
251-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
252-
ArrayRef<ImmutableTextSnapshotRef> Snapshots =
253-
ArrayRef<ImmutableTextSnapshotRef>());
251+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem);
254252

255253
std::unique_ptr<llvm::MemoryBuffer> getMemoryBuffer(StringRef Filename,
256254
std::string &Error);

0 commit comments

Comments
 (0)