Skip to content

Keep track and report the unit files that contain test symbols #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/IndexStoreDB/Database/ImportTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class INDEXSTOREDB_EXPORT ImportTransaction {

IDCode getUnitCode(StringRef unitName);
IDCode addProviderName(StringRef name, bool *wasInserted = nullptr);
// Marks a provider as containing test symbols.
void setProviderContainsTestSymbols(IDCode provider);
bool providerContainsTestSymbols(IDCode provider);
/// \returns a IDCode of the USR.
IDCode addSymbolInfo(IDCode provider,
StringRef USR, StringRef symbolName, SymbolInfo symInfo,
Expand All @@ -56,6 +59,7 @@ class INDEXSTOREDB_EXPORT UnitDataImport {
CanonicalFilePath Sysroot;
llvm::sys::TimePoint<> ModTime;
Optional<bool> IsSystem;
Optional<bool> HasTestSymbols;
Optional<SymbolProviderKind> SymProviderKind;
std::string Target;

Expand Down Expand Up @@ -83,6 +87,7 @@ class INDEXSTOREDB_EXPORT UnitDataImport {
bool isMissing() const { return IsMissing; }
bool isUpToDate() const { return IsUpToDate; }
Optional<bool> getIsSystem() const { return IsSystem; }
Optional<bool> getHasTestSymbols() const { return HasTestSymbols; }
Optional<SymbolProviderKind> getSymbolProviderKind() const { return SymProviderKind; }

IDCode getPrevMainFileCode() const {
Expand Down
2 changes: 2 additions & 0 deletions include/IndexStoreDB/Database/ReadTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class INDEXSTOREDB_EXPORT ReadTransaction {
bool foreachProviderAndFileCodeReference(function_ref<bool(IDCode unitCode)> unitFilter,
function_ref<bool(IDCode provider, IDCode pathCode, IDCode unitCode, llvm::sys::TimePoint<> modTime, IDCode moduleNameCode, bool isSystem)> receiver);

bool foreachProviderContainingTestSymbols(function_ref<bool(IDCode provider)> receiver);

/// Returns USR codes in batches.
bool foreachUSROfGlobalSymbolKind(SymbolKind symKind, llvm::function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver);

Expand Down
1 change: 1 addition & 0 deletions include/IndexStoreDB/Database/UnitInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct UnitInfo {
bool HasMainFile;
bool HasSysroot;
bool IsSystem;
bool HasTestSymbols;
SymbolProviderKind SymProviderKind;
ArrayRef<IDCode> FileDepends;
ArrayRef<IDCode> UnitDepends;
Expand Down
2 changes: 1 addition & 1 deletion include/IndexStoreDB/Index/IndexSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class INDEXSTOREDB_EXPORT IndexSystem {

/// Returns unit test class/method occurrences that are referenced from units associated with the provided output file paths.
/// \returns `false` if the receiver returned `false` to stop receiving symbols, `true` otherwise.
bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<StringRef> FilePaths,
bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths,
function_ref<bool(SymbolOccurrenceRef Occur)> Receiver);

private:
Expand Down
11 changes: 11 additions & 0 deletions include/IndexStoreDB/Index/StoreUnitInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ struct StoreUnitInfo {
std::string UnitName;
CanonicalFilePath MainFilePath;
CanonicalFilePath OutFilePath;
bool HasTestSymbols = false;
llvm::sys::TimePoint<> ModTime;

StoreUnitInfo() = default;
StoreUnitInfo(std::string unitName, CanonicalFilePath mainFilePath,
CanonicalFilePath outFilePath, bool hasTestSymbols,
llvm::sys::TimePoint<> modTime)
: UnitName(unitName),
MainFilePath(mainFilePath),
OutFilePath(outFilePath),
HasTestSymbols(hasTestSymbols),
ModTime(modTime) {}
};

} // namespace index
Expand Down
2 changes: 1 addition & 1 deletion include/IndexStoreDB/Index/SymbolIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SymbolIndex {
bool foreachCanonicalSymbolOccurrenceByKind(SymbolKind symKind, bool workspaceOnly,
function_ref<bool(SymbolOccurrenceRef Occur)> Receiver);

bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePath> FilePaths,
bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths,
function_ref<bool(SymbolOccurrenceRef Occur)> Receiver);

private:
Expand Down
7 changes: 4 additions & 3 deletions lib/Database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
using namespace IndexStoreDB;
using namespace IndexStoreDB::db;

const unsigned Database::DATABASE_FORMAT_VERSION = 12;
const unsigned Database::DATABASE_FORMAT_VERSION = 13;

static const char *DeadProcessDBSuffix = "-dead";

Expand Down Expand Up @@ -144,7 +144,7 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
db->SavedPath = savedPathBuf.str();
db->ProcessPath = processPathBuf.str();
db->DBEnv = lmdb::env::create();
db->DBEnv.set_max_dbs(13);
db->DBEnv.set_max_dbs(14);

// Start with 64MB. We'll update with the actual size after we open the database.
db->MapSize = initialDBSize.getValueOr(64ULL*1024ULL*1024ULL);
Expand All @@ -168,6 +168,7 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
db->DBISymbolProvidersByUSR = lmdb::dbi::open(txn, "usrs", MDB_INTEGERKEY|MDB_DUPSORT|MDB_DUPFIXED|MDB_CREATE);
db->DBISymbolProvidersByUSR.set_dupsort(txn, providersForUSR_compare);
db->DBISymbolProviderNameByCode = lmdb::dbi::open(txn, "providers", MDB_INTEGERKEY|MDB_CREATE);
db->DBISymbolProvidersWithTestSymbols = lmdb::dbi::open(txn, "providers-with-test-symbols", MDB_INTEGERKEY|MDB_CREATE);
db->DBIUSRsBySymbolName = lmdb::dbi::open(txn, "symbol-names", MDB_DUPSORT|MDB_DUPFIXED|MDB_INTEGERDUP|MDB_CREATE);
db->DBIUSRsByGlobalSymbolKind = lmdb::dbi::open(txn, "symbol-kinds", MDB_INTEGERKEY|MDB_DUPSORT|MDB_DUPFIXED|MDB_INTEGERDUP|MDB_CREATE);
db->DBIDirNameByCode = lmdb::dbi::open(txn, "directories", MDB_INTEGERKEY|MDB_CREATE);
Expand Down Expand Up @@ -240,7 +241,7 @@ UnitInfo Database::Implementation::getUnitInfo(IDCode unitCode, lmdb::txn &Txn)
llvm::sys::TimePoint<> modTime = llvm::sys::TimePoint<>(std::chrono::nanoseconds(infoData.NanoTime));
return UnitInfo{ unitName, unitCode, modTime,
infoData.OutFileCode, infoData.MainFileCode, infoData.SysrootCode, infoData.TargetCode,
infoData.HasMainFile, infoData.HasSysroot, infoData.IsSystem,
infoData.HasMainFile, infoData.HasSysroot, infoData.IsSystem, infoData.HasTestSymbols,
SymbolProviderKind(infoData.SymProviderKind),
fileDepends, unitDepends, providerDepends };
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Database/DatabaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Database::Implementation {
lmdb::env DBEnv{nullptr};
lmdb::dbi DBISymbolProvidersByUSR{0};
lmdb::dbi DBISymbolProviderNameByCode{0};
lmdb::dbi DBISymbolProvidersWithTestSymbols{0};
lmdb::dbi DBIUSRsBySymbolName{0};
lmdb::dbi DBIUSRsByGlobalSymbolKind{0};
lmdb::dbi DBIDirNameByCode{0};
Expand Down Expand Up @@ -59,6 +60,7 @@ class Database::Implementation {
lmdb::env &getDBEnv() { return DBEnv; }
lmdb::dbi &getDBISymbolProvidersByUSR() { return DBISymbolProvidersByUSR; }
lmdb::dbi &getDBISymbolProviderNameByCode() { return DBISymbolProviderNameByCode; }
lmdb::dbi &getDBISymbolProvidersWithTestSymbols() { return DBISymbolProvidersWithTestSymbols; }
lmdb::dbi &getDBIUSRsBySymbolName() { return DBIUSRsBySymbolName; }
lmdb::dbi &getDBIUSRsByGlobalSymbolKind() { return DBIUSRsByGlobalSymbolKind; }
lmdb::dbi &getDBIDirNameByCode() { return DBIDirNameByCode; }
Expand Down Expand Up @@ -137,6 +139,7 @@ struct UnitInfoData {
bool HasMainFile : 1;
bool HasSysroot : 1;
bool IsSystem : 1;
bool HasTestSymbols : 1;
uint32_t FileDependSize;
uint32_t UnitDependSize;
uint32_t ProviderDependSize;
Expand Down
31 changes: 30 additions & 1 deletion lib/Database/ImportTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ IDCode ImportTransaction::Implementation::addProviderName(StringRef name, bool *
return code;
}

void ImportTransaction::Implementation::setProviderContainsTestSymbols(IDCode provider) {
lmdb::val key{&provider, sizeof(provider)};
lmdb::val val{nullptr, 0};
DBase->impl().getDBISymbolProvidersWithTestSymbols().put(Txn, key, val, MDB_NOOVERWRITE);
}

bool ImportTransaction::Implementation::providerContainsTestSymbols(IDCode provider) {
return DBase->impl().getDBISymbolProvidersWithTestSymbols().get(Txn, provider);
}

IDCode ImportTransaction::Implementation::addSymbolInfo(IDCode provider, StringRef USR, StringRef symbolName,
SymbolInfo symInfo,
SymbolRoleSet roles, SymbolRoleSet relatedRoles) {
Expand Down Expand Up @@ -225,7 +235,7 @@ void ImportTransaction::Implementation::addUnitInfo(const UnitInfo &info) {
nanoTime,
static_cast<uint16_t>(info.UnitName.size()),
uint8_t(info.SymProviderKind),
info.HasMainFile, info.HasSysroot, info.IsSystem,
info.HasMainFile, info.HasSysroot, info.IsSystem, info.HasTestSymbols,
static_cast<uint32_t>(info.FileDepends.size()),
static_cast<uint32_t>(info.UnitDepends.size()),
static_cast<uint32_t>(info.ProviderDepends.size()),
Expand Down Expand Up @@ -350,6 +360,14 @@ IDCode ImportTransaction::addProviderName(StringRef name, bool *wasInserted) {
return Impl->addProviderName(name, wasInserted);
}

void ImportTransaction::setProviderContainsTestSymbols(IDCode provider) {
return Impl->setProviderContainsTestSymbols(provider);
}

bool ImportTransaction::providerContainsTestSymbols(IDCode provider) {
return Impl->providerContainsTestSymbols(provider);
}

IDCode ImportTransaction::addSymbolInfo(IDCode provider, StringRef USR, StringRef symbolName,
SymbolInfo symInfo,
SymbolRoleSet roles, SymbolRoleSet relatedRoles) {
Expand Down Expand Up @@ -383,6 +401,7 @@ UnitDataImport::UnitDataImport(ImportTransaction &import, StringRef unitName, ll
return; // Does not already exist.

IsSystem = dbUnit.IsSystem;
HasTestSymbols = dbUnit.HasTestSymbols;
SymProviderKind = dbUnit.SymProviderKind;
PrevMainFileCode = dbUnit.MainFileCode;
PrevOutFileCode = dbUnit.OutFileCode;
Expand Down Expand Up @@ -532,6 +551,15 @@ void UnitDataImport::commit() {
import.addTargetName(Target);
}

// Update the `HasTestSymbols` value.
HasTestSymbols = false;
for (const UnitInfo::Provider &prov : ProviderDepends) {
if (import.providerContainsTestSymbols(prov.ProviderCode)) {
HasTestSymbols = true;
break;
}
}

UnitInfo info{
UnitName,
UnitCode,
Expand All @@ -543,6 +571,7 @@ void UnitDataImport::commit() {
hasMainFile,
hasSysroot,
IsSystem.getValue(),
HasTestSymbols.getValue(),
SymProviderKind.getValue(),
FileDepends,
UnitDepends,
Expand Down
3 changes: 3 additions & 0 deletions lib/Database/ImportTransactionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class ImportTransaction::Implementation {

IDCode getUnitCode(StringRef unitName);
IDCode addProviderName(StringRef name, bool *wasInserted);
// Marks a provider as containing test symbols.
void setProviderContainsTestSymbols(IDCode provider);
bool providerContainsTestSymbols(IDCode provider);
/// \returns a IDCode of the USR.
IDCode addSymbolInfo(IDCode provider, StringRef USR, StringRef symbolName, SymbolInfo symInfo,
SymbolRoleSet roles, SymbolRoleSet relatedRoles);
Expand Down
18 changes: 18 additions & 0 deletions lib/Database/ReadTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ static bool passMultipleIDCodes(lmdb::cursor &cursor, lmdb::val &key, lmdb::val
return true;
}

bool ReadTransaction::Implementation::foreachProviderContainingTestSymbols(function_ref<bool(IDCode provider)> receiver) {
auto &db = DBase->impl();
auto cursor = lmdb::cursor::open(Txn, db.getDBISymbolProvidersWithTestSymbols());

lmdb::val key{};
lmdb::val value{};
while (cursor.get(key, value, MDB_NEXT)) {
IDCode providerCode = *(IDCode*)key.data();
if (!receiver(providerCode))
return false;
}
return true;
}

bool ReadTransaction::Implementation::foreachUSROfGlobalSymbolKind(SymbolKind symKind,
llvm::function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver) {
auto globalKindOpt = getGlobalSymbolKind(symKind);
Expand Down Expand Up @@ -665,6 +679,10 @@ bool ReadTransaction::foreachProviderAndFileCodeReference(
return Impl->foreachProviderAndFileCodeReference(std::move(unitFilter), std::move(receiver));
}

bool ReadTransaction::foreachProviderContainingTestSymbols(function_ref<bool(IDCode provider)> receiver) {
return Impl->foreachProviderContainingTestSymbols(std::move(receiver));
}

bool ReadTransaction::foreachUSROfGlobalSymbolKind(SymbolKind symKind, llvm::function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver) {
return Impl->foreachUSROfGlobalSymbolKind(symKind, std::move(receiver));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Database/ReadTransactionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ReadTransaction::Implementation {
bool foreachProviderAndFileCodeReference(function_ref<bool(IDCode unitCode)> unitFilter,
function_ref<bool(IDCode provider, IDCode pathCode, IDCode unitCode, llvm::sys::TimePoint<> modTime, IDCode moduleNameCode, bool isSystem)> receiver);

bool foreachProviderContainingTestSymbols(function_ref<bool(IDCode provider)> receiver);

bool foreachUSROfGlobalSymbolKind(SymbolKind symKind, llvm::function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver);
bool foreachUSROfGlobalUnitTestSymbol(llvm::function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver);
bool foreachUSROfGlobalSymbolKind(GlobalSymbolKind globalSymKind, function_ref<bool(ArrayRef<IDCode> usrCodes)> receiver);
Expand Down
10 changes: 7 additions & 3 deletions lib/Index/IndexDatastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
IDCode unitCode;
bool needDatabaseUpdate;
Optional<bool> optIsSystem;
Optional<bool> PrevHasTestSymbols;
IDCode PrevMainFileCode;
IDCode PrevOutFileCode;
Optional<StoreUnitInfo> StoreUnitInfoOpt;
Expand All @@ -312,6 +313,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
if (!needDatabaseUpdate) {
PrevMainFileCode = unitImport.getPrevMainFileCode();
PrevOutFileCode = unitImport.getPrevOutFileCode();
PrevHasTestSymbols = unitImport.getHasTestSymbols();
return false;
}

Expand All @@ -333,7 +335,6 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
}
CanonicalFilePath CanonOutFile = CanonPathCache->getCanonicalPath(Reader.getOutputFile(), WorkDir);
unitImport.setOutFile(CanonOutFile);
StoreUnitInfoOpt = StoreUnitInfo{unitName, CanonMainFile, CanonOutFile, unitModTime};

CanonicalFilePath CanonSysroot = CanonPathCache->getCanonicalPath(Reader.getSysrootPath(), WorkDir);
unitImport.setSysroot(CanonSysroot);
Expand Down Expand Up @@ -385,6 +386,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
});

unitImport.commit();
StoreUnitInfoOpt = StoreUnitInfo{unitName, CanonMainFile, CanonOutFile, unitImport.getHasTestSymbols().getValue(), unitModTime};
import.commit();
return false;
};
Expand All @@ -397,7 +399,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName) {
ReadTransaction reader(SymIndex->getDBase());
CanonicalFilePath mainFile = reader.getFullFilePathFromCode(PrevMainFileCode);
CanonicalFilePath outFile = reader.getFullFilePathFromCode(PrevOutFileCode);
StoreUnitInfoOpt = StoreUnitInfo{unitName, mainFile, outFile, unitModTime};
StoreUnitInfoOpt = StoreUnitInfo{unitName, mainFile, outFile, PrevHasTestSymbols.getValue(), unitModTime};
}
Delegate->processedStoreUnit(StoreUnitInfoOpt.getValue());
}
Expand Down Expand Up @@ -501,6 +503,7 @@ void StoreUnitRepo::onUnitOutOfDate(IDCode unitCode, StringRef unitName,
bool synchronous) {
CanonicalFilePath MainFilePath;
CanonicalFilePath OutFilePath;
bool hasTestSymbols = false;
llvm::sys::TimePoint<> CurrModTime;
SmallVector<IDCode, 8> dependentUnits;
{
Expand All @@ -511,13 +514,14 @@ void StoreUnitRepo::onUnitOutOfDate(IDCode unitCode, StringRef unitName,
MainFilePath = reader.getFullFilePathFromCode(unitInfo.MainFileCode);
}
OutFilePath = reader.getFullFilePathFromCode(unitInfo.OutFileCode);
hasTestSymbols = unitInfo.HasTestSymbols;
CurrModTime = unitInfo.ModTime;
}
reader.getDirectDependentUnits(unitCode, dependentUnits);
}

if (!MainFilePath.empty() && Delegate) {
StoreUnitInfo unitInfo{unitName, MainFilePath, OutFilePath, CurrModTime};
StoreUnitInfo unitInfo{unitName, MainFilePath, OutFilePath, hasTestSymbols, CurrModTime};
Delegate->unitIsOutOfDate(unitInfo, outOfDateModTime, hint, synchronous);
}

Expand Down
13 changes: 4 additions & 9 deletions lib/Index/IndexSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class IndexSystemImpl {
bool foreachFileIncludedByFile(StringRef SourcePath,
function_ref<bool(CanonicalFilePathRef TargetPath, unsigned Line)> Receiver);

bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<StringRef> FilePaths,
bool foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths,
function_ref<bool(SymbolOccurrenceRef Occur)> Receiver);
};

Expand Down Expand Up @@ -522,13 +522,8 @@ bool IndexSystemImpl::foreachFileIncludedByFile(StringRef SourcePath,
return PathIndex->foreachFileIncludedByFile(canonSourcePath, Receiver);
}

bool IndexSystemImpl::foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<StringRef> FilePaths, function_ref<bool(SymbolOccurrenceRef Occur)> Receiver) {
SmallVector<CanonicalFilePath, 8> canonPaths;
canonPaths.reserve(FilePaths.size());
for (StringRef path : FilePaths) {
canonPaths.push_back(PathIndex->getCanonicalPath(path));
}
return SymIndex->foreachUnitTestSymbolReferencedByOutputPaths(canonPaths, std::move(Receiver));
bool IndexSystemImpl::foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths, function_ref<bool(SymbolOccurrenceRef Occur)> Receiver) {
return SymIndex->foreachUnitTestSymbolReferencedByOutputPaths(FilePaths, std::move(Receiver));
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -709,7 +704,7 @@ bool IndexSystem::foreachFileIncludedByFile(StringRef SourcePath,
return IMPL->foreachFileIncludedByFile(SourcePath, Receiver);
}

bool IndexSystem::foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<StringRef> FilePaths,
bool IndexSystem::foreachUnitTestSymbolReferencedByOutputPaths(ArrayRef<CanonicalFilePathRef> FilePaths,
function_ref<bool(SymbolOccurrenceRef Occur)> Receiver) {
return IMPL->foreachUnitTestSymbolReferencedByOutputPaths(FilePaths, std::move(Receiver));
}
Loading