Skip to content

Commit cbf42ee

Browse files
committed
[SourceKit] Don't store Stamps in ASTBuildOperation
FileContents already contains the stamps.
1 parent eaf14ab commit cbf42ee

File tree

1 file changed

+16
-38
lines changed

1 file changed

+16
-38
lines changed

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,10 @@ class ASTBuildOperation
302302
const SwiftInvocationRef InvokRef;
303303
const IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
304304

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.
306307
const std::vector<FileContentRef> FileContents;
307308

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-
313309
/// \c DependencyStamps contains the stamps of all module depenecies needed
314310
/// for the AST build. These stamps are only known after the AST is built.
315311
/// Before the AST has been built, we thus assume that all dependency stamps
@@ -369,25 +365,19 @@ class ASTBuildOperation
369365
}
370366

371367
/// 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();
376370

377371
public:
378372
ASTBuildOperation(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
379373
SwiftInvocationRef InvokRef, SwiftASTManagerRef ASTManager,
380374
std::function<void(void)> DidFinishCallback)
381375
: InvokRef(InvokRef), FileSystem(FileSystem), ASTManager(ASTManager),
382376
DidFinishCallback(DidFinishCallback) {
383-
auto FileContentsAndStamps =
384-
fileContentsAndStampsForFilesInCompilerInvocation();
385377
// const_cast is fine here. We just want to guard against modifying these
386378
// fields later on. It's fine to set them in the constructor.
387379
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();
391381
}
392382

393383
~ASTBuildOperation() {
@@ -413,7 +403,7 @@ class ASTBuildOperation
413403

414404
size_t getMemoryCost() {
415405
return sizeof(*this) + getVectorMemoryCost(FileContents) +
416-
getVectorMemoryCost(Stamps) + Result.getMemoryCost();
406+
Result.getMemoryCost();
417407
}
418408

419409
/// Schedule building this AST on the given \p Queue.
@@ -849,16 +839,14 @@ SwiftASTManager::Implementation::getMemoryBuffer(
849839
return nullptr;
850840
}
851841

852-
std::pair<std::vector<FileContentRef>, std::vector<BufferStamp>>
853-
ASTBuildOperation::fileContentsAndStampsForFilesInCompilerInvocation() {
842+
std::vector<FileContentRef>
843+
ASTBuildOperation::fileContentsForFilesInCompilerInvocation() {
854844
const InvocationOptions &Opts = InvokRef->Impl.Opts;
855845
std::string Error; // is ignored
856846

857847
std::vector<FileContentRef> FileContents;
858-
std::vector<BufferStamp> Stamps;
859848
FileContents.reserve(
860849
Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
861-
Stamps.reserve(Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
862850

863851
// IMPORTANT: The computation of stamps must match the one in
864852
// matchesSourceState.
@@ -875,35 +863,25 @@ ASTBuildOperation::fileContentsAndStampsForFilesInCompilerInvocation() {
875863
Content->Buffer =
876864
llvm::WritableMemoryBuffer::getNewMemBuffer(0, Filename);
877865
}
878-
Stamps.push_back(Content->Stamp);
879866
FileContents.push_back(Content);
880867
}
881-
assert(Stamps.size() ==
882-
Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
883868
assert(FileContents.size() ==
884869
Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
885-
return std::make_pair(FileContents, Stamps);
870+
return FileContents;
886871
}
887872

888873
bool ASTBuildOperation::matchesSourceState(
889874
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> OtherFileSystem) {
890875
const InvocationOptions &Opts = InvokRef->Impl.Opts;
891876

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+
}
902884
}
903-
assert(InputStamps.size() ==
904-
Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
905-
if (Stamps != InputStamps)
906-
return false;
907885

908886
for (auto &Dependency : DependencyStamps) {
909887
if (Dependency.second !=

0 commit comments

Comments
 (0)