Skip to content

[IndexDatastore] For the out-of-date trigger notifications report all the out-of-date files without any coalescing #8

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
Feb 7, 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
3 changes: 3 additions & 0 deletions include/IndexStoreDB/Index/IndexSystemDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace index {
class OutOfDateTriggerHint {
public:
virtual ~OutOfDateTriggerHint() {}
virtual std::string originalFileTrigger() = 0;
virtual std::string description() = 0;

private:
Expand All @@ -44,6 +45,7 @@ class DependentFileOutOfDateTriggerHint : public OutOfDateTriggerHint {
return std::make_shared<DependentFileOutOfDateTriggerHint>(filePath);
}

virtual std::string originalFileTrigger() override;
virtual std::string description() override;
};

Expand All @@ -59,6 +61,7 @@ class DependentUnitOutOfDateTriggerHint : public OutOfDateTriggerHint {
return std::make_shared<DependentUnitOutOfDateTriggerHint>(unitName, std::move(depHint));
}

virtual std::string originalFileTrigger() override;
virtual std::string description() override;
};

Expand Down
48 changes: 31 additions & 17 deletions lib/Index/IndexDatastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,23 @@ class IndexDatastoreImpl {
};

class UnitMonitor {
struct OutOfDateTrigger {
OutOfDateTriggerHintRef hint;
sys::TimeValue outOfDateModTime;

std::string getTriggerFilePath() const {
return hint->originalFileTrigger();
}
};

std::weak_ptr<StoreUnitRepo> UnitRepo;
IDCode UnitCode;
std::string UnitName;
sys::TimeValue ModTime;

mutable llvm::sys::Mutex StateMtx;
Optional<sys::TimeValue> OutOfDateModTime;
OutOfDateTriggerHintRef OutOfDateHint;
/// Map of out-of-date file path to its associated info.
StringMap<OutOfDateTrigger> OutOfDateTriggers;

public:
UnitMonitor(std::shared_ptr<StoreUnitRepo> unitRepo);
Expand All @@ -178,8 +187,7 @@ class UnitMonitor {
StringRef getUnitName() const { return UnitName; }
sys::TimeValue getModTime() const { return ModTime; }

Optional<sys::TimeValue> getOutOfDateModTime() const;
OutOfDateTriggerHintRef getOutOfDateHint() const { return OutOfDateHint; }
std::vector<OutOfDateTrigger> getOutOfDateTriggers() const;

void checkForOutOfDate(sys::TimeValue outOfDateModTime, StringRef filePath, bool synchronous=false);
void markOutOfDate(sys::TimeValue outOfDateModTime, OutOfDateTriggerHintRef hint, bool synchronous=false);
Expand Down Expand Up @@ -584,12 +592,11 @@ void UnitMonitor::initialize(IDCode unitCode,
this->ModTime = modTime;
for (IDCode unitDepCode : userUnitDepends) {
if (auto depMonitor = unitRepo->getUnitMonitor(unitDepCode)) {
if (auto optDepOutOfDateTime = depMonitor->getOutOfDateModTime()) {
if (optDepOutOfDateTime.getValue() > modTime) {
markOutOfDate(optDepOutOfDateTime.getValue(),
for (const auto &trigger : depMonitor->getOutOfDateTriggers()) {
if (trigger.outOfDateModTime > modTime) {
markOutOfDate(trigger.outOfDateModTime,
DependentUnitOutOfDateTriggerHint::create(depMonitor->getUnitName(),
depMonitor->getOutOfDateHint()));
return;
trigger.hint));
}
}
}
Expand All @@ -609,26 +616,33 @@ void UnitMonitor::initialize(IDCode unitCode,

UnitMonitor::~UnitMonitor() {}

Optional<sys::TimeValue> UnitMonitor::getOutOfDateModTime() const {
std::vector<UnitMonitor::OutOfDateTrigger> UnitMonitor::getOutOfDateTriggers() const {
sys::ScopedLock L(StateMtx);
return OutOfDateModTime;
std::vector<OutOfDateTrigger> triggers;
for (const auto &entry : OutOfDateTriggers) {
triggers.push_back(entry.getValue());
}
return triggers;
}

void UnitMonitor::checkForOutOfDate(sys::TimeValue outOfDateModTime, StringRef filePath, bool synchronous) {
sys::ScopedLock L(StateMtx);
if (OutOfDateModTime.hasValue())
return; // already marked as out-of-date.
auto findIt = OutOfDateTriggers.find(filePath);
if (findIt != OutOfDateTriggers.end() && findIt->getValue().outOfDateModTime >= outOfDateModTime) {
return; // already marked as out-of-date related to this trigger file.
}
if (ModTime < outOfDateModTime)
markOutOfDate(outOfDateModTime, DependentFileOutOfDateTriggerHint::create(filePath), synchronous);
}

void UnitMonitor::markOutOfDate(sys::TimeValue outOfDateModTime, OutOfDateTriggerHintRef hint, bool synchronous) {
{
sys::ScopedLock L(StateMtx);
if (OutOfDateModTime.hasValue())
return; // already marked as out-of-date.
this->OutOfDateModTime = outOfDateModTime;
this->OutOfDateHint = hint;
OutOfDateTrigger trigger{ hint, outOfDateModTime};
auto &entry = OutOfDateTriggers[trigger.getTriggerFilePath()];
if (entry.outOfDateModTime >= outOfDateModTime)
return; // already marked as out-of-date related to this trigger file.
entry = trigger;
}
if (auto localUnitRepo = UnitRepo.lock())
localUnitRepo->onUnitOutOfDate(UnitCode, UnitName, outOfDateModTime, hint, synchronous);
Expand Down
8 changes: 8 additions & 0 deletions lib/Index/IndexSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,18 @@ bool IndexSystemImpl::foreachFileIncludedByFile(StringRef SourcePath,

void OutOfDateTriggerHint::_anchor() {}

std::string DependentFileOutOfDateTriggerHint::originalFileTrigger() {
return FilePath;
}

std::string DependentFileOutOfDateTriggerHint::description() {
return FilePath;
}

std::string DependentUnitOutOfDateTriggerHint::originalFileTrigger() {
return DepHint->originalFileTrigger();
}

std::string DependentUnitOutOfDateTriggerHint::description() {
std::string desc;
llvm::raw_string_ostream OS(desc);
Expand Down