Skip to content

Commit

Permalink
Kill include error concept. It has not proven useful.
Browse files Browse the repository at this point in the history
c#
  • Loading branch information
Andersbakken committed May 24, 2019
1 parent a66e5c7 commit c4672b4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(rtags)
set(RTAGS_VERSION_MAJOR 2)
set(RTAGS_VERSION_MINOR 31)
set(RTAGS_VERSION_DATABASE 128)
set(RTAGS_VERSION_SOURCES_FILE 14)
set(RTAGS_VERSION_SOURCES_FILE 15)
set(RTAGS_VERSION ${RTAGS_VERSION_MAJOR}.${RTAGS_VERSION_MINOR}.${RTAGS_VERSION_DATABASE})
set(RTAGS_BINARY_ROOT_DIR ${PROJECT_BINARY_DIR})

Expand Down
1 change: 0 additions & 1 deletion src/ClangIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ void ClangIndexer::handleInclude(const CXCursor &cursor, CXCursorKind kind, Loca
}
}

mIndexDataMessage.files()[location.fileId()] |= IndexDataMessage::IncludeError;
error() << "handleInclude failed" << includedFile << cursor;
}

Expand Down
3 changes: 1 addition & 2 deletions src/IndexDataMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class IndexDataMessage : public RTagsMessage
Includes &includes() { return mIncludes; }
enum FileFlag {
NoFileFlag = 0x0,
Visited = 0x1,
IncludeError = 0x2
Visited = 0x1
};
Hash<uint32_t, Flags<FileFlag> > &files() { return mFiles; }
const Hash<uint32_t, Flags<FileFlag> > &files() const { return mFiles; }
Expand Down
75 changes: 17 additions & 58 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ static bool loadDependencies(DataFile &file, Dependencies &dependencies)
file >> fileId;
if (!fileId)
return false;
Flags<DependencyNode::Flag> flags;
file >> flags;
dependencies[fileId] = new DependencyNode(fileId, flags);
dependencies[fileId] = new DependencyNode(fileId);
}
for (int i=0; i<size; ++i) {
int links;
Expand Down Expand Up @@ -250,7 +248,7 @@ static void saveDependencies(DataFile &file, const Dependencies &dependencies)
{
file << static_cast<int>(dependencies.size());
for (const auto &it : dependencies) {
file << it.first << it.second->flags;
file << it.first;
}
for (const auto &it : dependencies) {
file << static_cast<int>(it.second->dependents.size());
Expand Down Expand Up @@ -349,10 +347,12 @@ bool Project::init()

String err;
if (!Project::readSources(mSourcesFilePath, mIndexParseData, &err)) {
if (!err.isEmpty())
if (!err.isEmpty()) {
error("Sources restore error %s: %s", mPath.constData(), err.constData());
return false;
}

return false;
return true;
}

auto reindexAll = [this]() {
Expand Down Expand Up @@ -381,7 +381,6 @@ bool Project::init()
{
std::lock_guard<std::mutex> lock(mMutex);
file >> mVisitedFiles;
Sandbox::decode(mVisitedFiles);
}
file >> mDiagnostics;
for (const auto &info : mIndexParseData.compileCommands)
Expand Down Expand Up @@ -815,7 +814,7 @@ void Project::onJobFinished(const std::shared_ptr<IndexerJob> &job, const std::s

Set<uint32_t> visited = msg->visitedFiles();
updateFixIts(visited, msg->fixIts());
updateDependencies(fileId, msg, job->unsavedFiles);
updateDependencies(fileId, msg);
if (success) {
forEachSources([&msg, fileId](Sources &sources) -> VisitResult {
// error() << "finished with" << Location::path(fileId) << sources.contains(fileId) << msg->parseTime();
Expand Down Expand Up @@ -912,11 +911,7 @@ bool Project::save()
}
{
std::lock_guard<std::mutex> lock(mMutex);
if (Sandbox::hasRoot()) {
file << Sandbox::encoded(mVisitedFiles);
} else {
file << mVisitedFiles;
}
file << mVisitedFiles;
}
file << mDiagnostics;
saveDependencies(file, mDependencies);
Expand Down Expand Up @@ -1104,12 +1099,11 @@ void Project::removeDependencies(uint32_t fileId)
}
}

void Project::updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDataMessage> &msg, const UnsavedFiles &unsavedFiles)
void Project::updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDataMessage> &msg)
{
static_cast<void>(fileId);
const bool prune = !(msg->flags() & IndexDataMessage::ParseFailure);
// error() << "updateDependencies" << Location::path(fileId) << prune;
Set<uint32_t> includeErrors, dirty;
for (auto pair : msg->files()) {
assert(pair.first);
DependencyNode *&node = mDependencies[pair.first];
Expand All @@ -1118,32 +1112,13 @@ void Project::updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDat
node = new DependencyNode(pair.first);
}

if (pair.second & IndexDataMessage::Visited) {
if (pair.second & IndexDataMessage::IncludeError) {
node->flags |= DependencyNode::Flag_IncludeError;
includeErrors.insert(pair.first);
// error() << "got include error for" << Location::path(pair.first);
} else if (node->flags & DependencyNode::Flag_IncludeError) {
// error() << "used to have include error for" << Location::path(pair.first) << node->includes.size();
node->flags &= ~DependencyNode::Flag_IncludeError;
dirty.insert(pair.first);
// for (auto dep : node->includes) {
// dirty.insert(dep.first);
// // error() << "dirty" << Location::path(dep.first);
// }
for (auto dep : node->dependents) {
dirty.insert(dep.first);
// error() << "dirty" << Location::path(dep.first);
}
}
if (prune) {
for (auto it : node->includes) {
it.second->dependents.remove(pair.first);
// error() << "removing" << Location::path(pair.first) << "from" << Location::path(it.first);
}
// error() << "Removing all includes for" << Location::path(pair.first) << node->includes.size();
node->includes.clear();
if (pair.second & IndexDataMessage::Visited && prune) {
for (auto it : node->includes) {
it.second->dependents.remove(pair.first);
// error() << "removing" << Location::path(pair.first) << "from" << Location::path(it.first);
}
// error() << "Removing all includes for" << Location::path(pair.first) << node->includes.size();
node->includes.clear();
}
watchFile(pair.first);
}
Expand All @@ -1162,22 +1137,6 @@ void Project::updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDat
includer->include(inclusiary);
}

if (!includeErrors.isEmpty()) {
// error() << "releasing files";
// for (uint32_t f : includeErrors) {
// error() << Location::path(f);
// }
releaseFileIds(includeErrors);
}
if (!dirty.isEmpty()) {
// error() << "dirtying";
// for (uint32_t f : dirty) {
// error() << Location::path(f);
// }
SimpleDirty simple;
simple.init(shared_from_this(), dirty);
startDirtyJobs(&simple, IndexerJob::Dirty, unsavedFiles);
}
// for (auto node : mDependencies) {
// for (auto inc : node.second->includes) {
// if (!inc.second->dependents.contains(node.first)) {
Expand Down Expand Up @@ -2969,8 +2928,8 @@ Set<Symbol> Project::findDeadFunctions(uint32_t fileId)
};
if (!fileId) {
Set<String> seenUsrs;
for (const auto &file : mVisitedFiles) {
processFile(file.first, &seenUsrs);
for (uint32_t id : mVisitedFiles) {
processFile(id, &seenUsrs);
}
} else {
processFile(fileId);
Expand Down
31 changes: 12 additions & 19 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ class Match;
class RestoreThread;
struct DependencyNode
{
enum Flag {
Flag_None = 0x0,
Flag_IncludeError = 0x1
};
DependencyNode(uint32_t f, Flags<Flag> l = NullFlags)
: fileId(f), flags(l)
DependencyNode(uint32_t f)
: fileId(f)
{}
void include(DependencyNode *dependee)
{
Expand All @@ -60,12 +56,8 @@ struct DependencyNode

Dependencies dependents, includes;
uint32_t fileId;

Flags<Flag> flags;
};

RCT_FLAGS(DependencyNode::Flag);

class Project : public std::enable_shared_from_this<Project>
{
public:
Expand Down Expand Up @@ -198,7 +190,7 @@ class Project : public std::enable_shared_from_this<Project>
Source source(uint32_t fileId, int buildIndex) const;
bool hasSource(uint32_t fileId) const;
bool isActiveJob(uint32_t sourceFileId) { return !sourceFileId || mActiveJobs.contains(sourceFileId); }
inline bool visitFile(uint32_t fileId, const Path &path, uint32_t sourceFileId);
inline bool visitFile(uint32_t fileId, uint32_t sourceFileId);
inline void releaseFileIds(const Set<uint32_t> &fileIds);
String fixIts(uint32_t fileId) const;
int reindex(const Match &match,
Expand Down Expand Up @@ -227,15 +219,18 @@ class Project : public std::enable_shared_from_this<Project>
void dumpFileMaps(const std::shared_ptr<QueryMessage> &msg, const std::shared_ptr<Connection> &conn);
void removeSources(const Hash<uint32_t, uint32_t> &sources); // key fileid, value fileid for compile_commands.json
void removeSource(uint32_t fileId);
Hash<uint32_t, Path> visitedFiles() const
Set<uint32_t> visitedFiles() const
{
std::lock_guard<std::mutex> lock(mMutex);
return mVisitedFiles;
}
void encodeVisitedFiles(Serializer &serializer)
{
std::lock_guard<std::mutex> lock(mMutex);
serializer << mVisitedFiles;
serializer << static_cast<uint32_t>(mVisitedFiles.size());
for (uint32_t fileId : mVisitedFiles) {
serializer << fileId << Location::path(fileId);
}
}

enum ScopeFlag { None = 0x0, NoValidate = 0x1 };
Expand Down Expand Up @@ -318,7 +313,7 @@ class Project : public std::enable_shared_from_this<Project>
};
bool validate(uint32_t fileId, ValidateMode mode, String *error = 0) const;
void removeDependencies(uint32_t fileId);
void updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDataMessage> &msg, const UnsavedFiles &unsavedFiles);
void updateDependencies(uint32_t fileId, const std::shared_ptr<IndexDataMessage> &msg);
void loadFailed(uint32_t fileId);
void updateFixIts(const Set<uint32_t> &visited, FixIts &fixIts);
int startDirtyJobs(Dirty *dirty,
Expand Down Expand Up @@ -447,7 +442,7 @@ class Project : public std::enable_shared_from_this<Project>

Files mFiles;

Hash<uint32_t, Path> mVisitedFiles;
Set<uint32_t> mVisitedFiles;
int mJobCounter, mJobsStarted;

time_t mLastIdleTime;
Expand Down Expand Up @@ -478,18 +473,16 @@ class Project : public std::enable_shared_from_this<Project>
RCT_FLAGS(Project::WatchMode);
RCT_FLAGS(Project::ScopeFlag);

inline bool Project::visitFile(uint32_t visitFileId, const Path &path, uint32_t id)
inline bool Project::visitFile(uint32_t visitFileId, uint32_t id)
{
assert(id);
std::lock_guard<std::mutex> lock(mMutex);
assert(visitFileId);
Path &p = mVisitedFiles[visitFileId];
assert(id);
assert(mActiveJobs.contains(id));
std::shared_ptr<IndexerJob> &job = mActiveJobs[id];
assert(job);
if (p.isEmpty()) {
p = path;
if (mVisitedFiles.insert(visitFileId)) {
job->visited.insert(visitFileId);
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ std::shared_ptr<Project> Server::addProject(const Path &path)
project.reset(new Project(path));
if (!project->init()) {
Path::rmdir(project->projectDataDir());
mProjects.erase(path);
return std::shared_ptr<Project>();
}
}
return project;
Expand Down Expand Up @@ -2132,7 +2134,7 @@ void Server::handleVisitFileMessage(const std::shared_ptr<VisitFileMessage> &mes
if (project && project->isActiveJob(id)) {
assert(message->file() == message->file().resolved());
fileId = Location::insertFile(message->file());
visit = project->visitFile(fileId, message->file(), id);
visit = project->visitFile(fileId, id);
}
VisitFileResponseMessage msg(fileId, visit);
conn->send(msg);
Expand Down

0 comments on commit c4672b4

Please sign in to comment.