Clang: Set indexing time stamp by dependent sources

Instead of using the time stamp from clang we simply set one time stamp
for all dependent sources.

Change-Id: I0adbe59d46c88ddd1ac491a7f7db568bcf2ac540
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-07-24 16:13:10 +02:00
parent ac22760043
commit cdda564946
8 changed files with 91 additions and 33 deletions

View File

@@ -177,11 +177,12 @@ public:
} }
} }
void insertOrUpdateIndexingTimeStamps(const FileStatuses &fileStatuses) override void insertOrUpdateIndexingTimeStampsWithoutTransaction(const FilePathIds &filePathIds,
TimeStamp indexingTimeStamp) override
{ {
for (FileStatus fileStatus : fileStatuses) { for (FilePathId filePathId : filePathIds) {
inserOrUpdateIndexingTimesStampStatement.write(fileStatus.filePathId.filePathId, inserOrUpdateIndexingTimesStampStatement.write(filePathId.filePathId,
fileStatus.lastModified); indexingTimeStamp.value);
} }
} }

View File

@@ -59,7 +59,9 @@ public:
virtual FilePathIds fetchPchSources(ProjectPartId projectPartId) const = 0; virtual FilePathIds fetchPchSources(ProjectPartId projectPartId) const = 0;
virtual FilePathIds fetchSources(ProjectPartId projectPartId) const = 0; virtual FilePathIds fetchSources(ProjectPartId projectPartId) const = 0;
virtual void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, TimeStamp indexingTimeStamp) = 0; virtual void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, TimeStamp indexingTimeStamp) = 0;
virtual void insertOrUpdateIndexingTimeStamps(const FileStatuses &fileStatuses) = 0; virtual void insertOrUpdateIndexingTimeStampsWithoutTransaction(const FilePathIds &filePathIds,
TimeStamp indexingTimeStamp)
= 0;
virtual SourceTimeStamps fetchIndexingTimeStamps() const = 0; virtual SourceTimeStamps fetchIndexingTimeStamps() const = 0;
virtual SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const = 0; virtual SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const = 0;
virtual FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const = 0; virtual FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const = 0;

View File

@@ -92,21 +92,40 @@ void SymbolIndexer::updateProjectParts(ProjectPartContainers &&projectParts)
} }
namespace { namespace {
void store(SymbolStorageInterface &symbolStorage, void store(SymbolStorageInterface &symbolStorage,
BuildDependenciesStorageInterface &buildDependencyStorage, BuildDependenciesStorageInterface &buildDependencyStorage,
Sqlite::TransactionInterface &transactionInterface, Sqlite::TransactionInterface &transactionInterface,
SymbolsCollectorInterface &symbolsCollector) SymbolsCollectorInterface &symbolsCollector,
const FilePathIds &dependentSources)
{ {
try { try {
long long now = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
Sqlite::ImmediateTransaction transaction{transactionInterface}; Sqlite::ImmediateTransaction transaction{transactionInterface};
buildDependencyStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses()); buildDependencyStorage.insertOrUpdateIndexingTimeStampsWithoutTransaction(dependentSources,
now);
symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(), symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
symbolsCollector.sourceLocations()); symbolsCollector.sourceLocations());
transaction.commit(); transaction.commit();
} catch (const Sqlite::StatementIsBusy &) { } catch (const Sqlite::StatementIsBusy &) {
store(symbolStorage, buildDependencyStorage, transactionInterface, symbolsCollector); store(symbolStorage,
buildDependencyStorage,
transactionInterface,
symbolsCollector,
dependentSources);
} }
} }
FilePathIds toFilePathIds(const SourceTimeStamps &sourceTimeStamps)
{
return Utils::transform<FilePathIds>(sourceTimeStamps, [](SourceTimeStamp sourceTimeStamp) {
return sourceTimeStamp.sourceId;
});
}
} // namespace } // namespace
void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
@@ -124,6 +143,7 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
auto indexing = [projectPart, auto indexing = [projectPart,
sourcePathId, sourcePathId,
preIncludeSearchPath = m_environment.preIncludeSearchPath(), preIncludeSearchPath = m_environment.preIncludeSearchPath(),
dependentSources = toFilePathIds(dependentTimeStamps),
this](SymbolsCollectorInterface &symbolsCollector) { this](SymbolsCollectorInterface &symbolsCollector) {
auto collect = [&](const FilePath &pchPath) { auto collect = [&](const FilePath &pchPath) {
using Builder = CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>; using Builder = CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>;
@@ -147,17 +167,20 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
store(m_symbolStorage, store(m_symbolStorage,
m_buildDependencyStorage, m_buildDependencyStorage,
m_transactionInterface, m_transactionInterface,
symbolsCollector); symbolsCollector,
dependentSources);
} else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) { } else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) {
store(m_symbolStorage, store(m_symbolStorage,
m_buildDependencyStorage, m_buildDependencyStorage,
m_transactionInterface, m_transactionInterface,
symbolsCollector); symbolsCollector,
dependentSources);
} else if (collect({})) { } else if (collect({})) {
store(m_symbolStorage, store(m_symbolStorage,
m_buildDependencyStorage, m_buildDependencyStorage,
m_transactionInterface, m_transactionInterface,
symbolsCollector); symbolsCollector,
dependentSources);
} }
}; };
@@ -196,6 +219,7 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
auto indexing = [optionalArtefact = std::move(optionalArtefact), auto indexing = [optionalArtefact = std::move(optionalArtefact),
filePathId, filePathId,
preIncludeSearchPath = m_environment.preIncludeSearchPath(), preIncludeSearchPath = m_environment.preIncludeSearchPath(),
dependentSources = toFilePathIds(dependentTimeStamps),
this](SymbolsCollectorInterface &symbolsCollector) { this](SymbolsCollectorInterface &symbolsCollector) {
auto collect = [&](const FilePath &pchPath) { auto collect = [&](const FilePath &pchPath) {
const ProjectPartArtefact &artefact = *optionalArtefact; const ProjectPartArtefact &artefact = *optionalArtefact;
@@ -218,11 +242,23 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
optionalArtefact->projectPartId); optionalArtefact->projectPartId);
if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) { if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) {
store(m_symbolStorage, m_buildDependencyStorage, m_transactionInterface, symbolsCollector); store(m_symbolStorage,
m_buildDependencyStorage,
m_transactionInterface,
symbolsCollector,
dependentSources);
} else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) { } else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) {
store(m_symbolStorage, m_buildDependencyStorage, m_transactionInterface, symbolsCollector); store(m_symbolStorage,
m_buildDependencyStorage,
m_transactionInterface,
symbolsCollector,
dependentSources);
} else if (collect({})) { } else if (collect({})) {
store(m_symbolStorage, m_buildDependencyStorage, m_transactionInterface, symbolsCollector); store(m_symbolStorage,
m_buildDependencyStorage,
m_transactionInterface,
symbolsCollector,
dependentSources);
} }
}; };

View File

@@ -302,14 +302,32 @@ TEST_F(BuildDependenciesStorage, FetchIndexingTimeStampsIsBusy)
storage.fetchIndexingTimeStamps(); storage.fetchIndexingTimeStamps();
} }
TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampWithoutTransaction)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin()).Times(0);
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit()).Times(0);
storage.insertOrUpdateIndexingTimeStampsWithoutTransaction({1, 2}, 34);
}
TEST_F(BuildDependenciesStorage, InsertIndexingTimeStamp) TEST_F(BuildDependenciesStorage, InsertIndexingTimeStamp)
{ {
ClangBackEnd::FileStatuses fileStatuses{{1, 0, 34}, {2, 0, 37}}; InSequence s;
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, write(TypedEq<int>(1), TypedEq<int>(34))); EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, write(TypedEq<int>(2), TypedEq<int>(37))); EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit());
storage.insertOrUpdateIndexingTimeStamps(fileStatuses); storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34);
} }
TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampsIsBusy) TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampsIsBusy)
@@ -318,8 +336,10 @@ TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampsIsBusy)
EXPECT_CALL(mockDatabase, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""})); EXPECT_CALL(mockDatabase, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, immediateBegin()); EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, write(TypedEq<int>(1), TypedEq<int>(34))); EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, write(TypedEq<int>(2), TypedEq<int>(34))); write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit()); EXPECT_CALL(mockDatabase, commit());
storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34);
@@ -386,19 +406,11 @@ TEST_F(BuildDependenciesStorageSlow, UpdateIndexingTimeStamps)
ElementsAre(SourceTimeStamp{1, 37}, SourceTimeStamp{2, 34})); ElementsAre(SourceTimeStamp{1, 37}, SourceTimeStamp{2, 34}));
} }
TEST_F(BuildDependenciesStorageSlow, InsertIndexingTimeStamp)
{
storage.insertOrUpdateIndexingTimeStamps({{1, 0, 34}, {2, 0, 37}});
ASSERT_THAT(storage.fetchIndexingTimeStamps(),
ElementsAre(SourceTimeStamp{1, 34}, SourceTimeStamp{2, 37}));
}
TEST_F(BuildDependenciesStorageSlow, UpdateIndexingTimeStamp) TEST_F(BuildDependenciesStorageSlow, UpdateIndexingTimeStamp)
{ {
storage.insertOrUpdateIndexingTimeStamps({{1, 0, 34}, {2, 0, 34}}); storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34);
storage.insertOrUpdateIndexingTimeStamps({{2, 0, 37}}); storage.insertOrUpdateIndexingTimeStamps({2}, 37);
ASSERT_THAT(storage.fetchIndexingTimeStamps(), ASSERT_THAT(storage.fetchIndexingTimeStamps(),
ElementsAre(SourceTimeStamp{1, 34}, SourceTimeStamp{2, 37})); ElementsAre(SourceTimeStamp{1, 34}, SourceTimeStamp{2, 37}));

View File

@@ -58,6 +58,9 @@ public:
MOCK_METHOD2(insertOrUpdateIndexingTimeStamps, MOCK_METHOD2(insertOrUpdateIndexingTimeStamps,
void(const ClangBackEnd::FilePathIds &filePathIds, void(const ClangBackEnd::FilePathIds &filePathIds,
ClangBackEnd::TimeStamp indexingTimeStamp)); ClangBackEnd::TimeStamp indexingTimeStamp));
MOCK_METHOD2(insertOrUpdateIndexingTimeStampsWithoutTransaction,
void(const ClangBackEnd::FilePathIds &filePathIds,
ClangBackEnd::TimeStamp indexingTimeStamp));
MOCK_METHOD1(insertOrUpdateIndexingTimeStamps, void(const ClangBackEnd::FileStatuses &)); MOCK_METHOD1(insertOrUpdateIndexingTimeStamps, void(const ClangBackEnd::FileStatuses &));
MOCK_CONST_METHOD0(fetchIndexingTimeStamps, ClangBackEnd::SourceTimeStamps()); MOCK_CONST_METHOD0(fetchIndexingTimeStamps, ClangBackEnd::SourceTimeStamps());
MOCK_CONST_METHOD1(fetchIncludedIndexingTimeStamps, MOCK_CONST_METHOD1(fetchIncludedIndexingTimeStamps,

View File

@@ -95,6 +95,8 @@ public:
MOCK_METHOD1(write, MOCK_METHOD1(write,
void (int)); void (int));
MOCK_METHOD2(write, void(int, long long));
MOCK_METHOD2(write, MOCK_METHOD2(write,
void (int, int)); void (int, int));

View File

@@ -290,7 +290,7 @@ TEST_F(PchManagerServer, ResetTimeStampForChangedFilesInDatabase)
{ {
EXPECT_CALL(mockBuildDependenciesStorage, EXPECT_CALL(mockBuildDependenciesStorage,
insertOrUpdateIndexingTimeStamps(ElementsAre(FilePathId{1}, FilePathId{3}, FilePathId{5}), insertOrUpdateIndexingTimeStamps(ElementsAre(FilePathId{1}, FilePathId{3}, FilePathId{5}),
TypedEq<ClangBackEnd::TimeStamp>(0))); TypedEq<ClangBackEnd::TimeStamp>(-1)));
server.pathsChanged({1, 3, 5}); server.pathsChanged({1, 3, 5});
} }

View File

@@ -872,7 +872,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsFetchIncludedIndexingTimeStamps)
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1)); EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateIndexingTimeStamps(_)); EXPECT_CALL(mockBuildDependenciesStorage,
insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _));
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _));
EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockSqliteTransactionBackend, commit());
@@ -887,7 +888,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsIsBusyInStoringData)
.WillOnce(Throw(Sqlite::StatementIsBusy{""})); .WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1)); EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateIndexingTimeStamps(_)); EXPECT_CALL(mockBuildDependenciesStorage,
insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _));
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _));
EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockSqliteTransactionBackend, commit());