mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
wip towards id migration, use IdMap isntead of IdCache
This commit is contained in:
parent
2d93ceb6db
commit
c5dc7a7ac7
@ -273,7 +273,19 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
|||||||
// from the primary file though, so that should be ok. We need to cleanup indexer output.
|
// from the primary file though, so that should be ok. We need to cleanup indexer output.
|
||||||
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
||||||
if (old_index.has_value()) {
|
if (old_index.has_value()) {
|
||||||
IndexUpdate update = IndexUpdate::CreateImport(old_index.value());
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO: We need to create IdMap on QueryDb thread.
|
||||||
|
IdMap old_id_map(old_index->id_cache);
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
IndexUpdate update = IndexUpdate::CreateImport(old_id_map, old_index.value());
|
||||||
IndexTranslationUnitResponse response(update);
|
IndexTranslationUnitResponse response(update);
|
||||||
responses->Enqueue(response);
|
responses->Enqueue(response);
|
||||||
time.ResetAndPrint("Loading cached index");
|
time.ResetAndPrint("Loading cached index");
|
||||||
@ -296,16 +308,43 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
|||||||
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
||||||
time.ResetAndPrint("Loading previous index");
|
time.ResetAndPrint("Loading previous index");
|
||||||
if (old_index) {
|
if (old_index) {
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO: We need to create IdMap on QueryDb thread.
|
||||||
|
IdMap old_id_map(old_index->id_cache);
|
||||||
|
IdMap new_id_map(new_index.id_cache);
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
|
||||||
// Apply delta update.
|
// Apply delta update.
|
||||||
IndexUpdate update = IndexUpdate::CreateDelta(old_index.value(), new_index);
|
IndexUpdate update = IndexUpdate::CreateDelta(old_id_map, new_id_map, old_index.value(), new_index);
|
||||||
IndexTranslationUnitResponse response(update);
|
IndexTranslationUnitResponse response(update);
|
||||||
time.ResetAndPrint("Creating delta index update/response");
|
time.ResetAndPrint("Creating delta index update/response");
|
||||||
responses->Enqueue(response);
|
responses->Enqueue(response);
|
||||||
time.ResetAndPrint("Sending update to server");
|
time.ResetAndPrint("Sending update to server");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO: We need to create IdMap on QueryDb thread.
|
||||||
|
IdMap new_id_map(new_index.id_cache);
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
// TODO/FIXME/TODO
|
||||||
|
|
||||||
// Apply full update.
|
// Apply full update.
|
||||||
IndexUpdate update = IndexUpdate::CreateImport(new_index);
|
IndexUpdate update = IndexUpdate::CreateImport(new_id_map, new_index);
|
||||||
IndexTranslationUnitResponse response(update);
|
IndexTranslationUnitResponse response(update);
|
||||||
time.ResetAndPrint("Creating index update/response");
|
time.ResetAndPrint("Creating index update/response");
|
||||||
responses->Enqueue(response);
|
responses->Enqueue(response);
|
||||||
|
200
src/query.cc
200
src/query.cc
@ -14,124 +14,108 @@
|
|||||||
// TODO: Make all copy constructors explicit.
|
// TODO: Make all copy constructors explicit.
|
||||||
|
|
||||||
|
|
||||||
struct IdGlobalizer {
|
|
||||||
// TODO threading model
|
|
||||||
// - [querydb] Create IdGlobalizer mapping from every id registered in local_ids
|
|
||||||
// - [indexer] Create IndexUpdate using IdGlobalizer cached state
|
|
||||||
// - [querydb] Apply IndexUpdate
|
|
||||||
//
|
|
||||||
// Then lookup in cached_* should *never* fail.
|
|
||||||
|
|
||||||
const IdCache& local_ids;
|
|
||||||
QueryFileId index_file_id;
|
|
||||||
std::unordered_map<IndexTypeId, QueryTypeId> cached_type_ids_;
|
|
||||||
std::unordered_map<IndexFuncId, QueryFuncId> cached_func_ids_;
|
|
||||||
std::unordered_map<IndexVarId, QueryVarId> cached_var_ids_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usr MapIdToUsr(const IdMap& id_map, const IndexTypeId& id) {
|
||||||
|
assert(id_map.local_ids.type_id_to_usr.find(id) != id_map.local_ids.type_id_to_usr.end());
|
||||||
Usr MapIdToUsr(const IdCache& id_cache, const IndexTypeId& id) {
|
return id_map.local_ids.type_id_to_usr.find(id)->second;
|
||||||
assert(id_cache.type_id_to_usr.find(id) != id_cache.type_id_to_usr.end());
|
|
||||||
return id_cache.type_id_to_usr.find(id)->second;
|
|
||||||
}
|
}
|
||||||
Usr MapIdToUsr(const IdCache& id_cache, const IndexFuncId& id) {
|
Usr MapIdToUsr(const IdMap& id_map, const IndexFuncId& id) {
|
||||||
assert(id_cache.func_id_to_usr.find(id) != id_cache.func_id_to_usr.end());
|
assert(id_map.local_ids.func_id_to_usr.find(id) != id_map.local_ids.func_id_to_usr.end());
|
||||||
return id_cache.func_id_to_usr.find(id)->second;
|
return id_map.local_ids.func_id_to_usr.find(id)->second;
|
||||||
}
|
}
|
||||||
Usr MapIdToUsr(const IdCache& id_cache, const IndexVarId& id) {
|
Usr MapIdToUsr(const IdMap& id_map, const IndexVarId& id) {
|
||||||
assert(id_cache.var_id_to_usr.find(id) != id_cache.var_id_to_usr.end());
|
assert(id_map.local_ids.var_id_to_usr.find(id) != id_map.local_ids.var_id_to_usr.end());
|
||||||
return id_cache.var_id_to_usr.find(id)->second;
|
return id_map.local_ids.var_id_to_usr.find(id)->second;
|
||||||
}
|
}
|
||||||
QueryableLocation MapIdToUsr(const IdCache& id_cache, const Range& range) {
|
QueryableLocation MapIdToUsr(const IdMap& id_map, const Range& range) {
|
||||||
return QueryableLocation(id_cache.primary_file, range);
|
return QueryableLocation(id_map.local_ids.primary_file, range);
|
||||||
}
|
}
|
||||||
UsrRef MapIdToUsr(const IdCache& id_cache, const FuncRef& id) {
|
UsrRef MapIdToUsr(const IdMap& id_map, const FuncRef& id) {
|
||||||
assert(id_cache.func_id_to_usr.find(id.id) != id_cache.func_id_to_usr.end());
|
assert(id_map.local_ids.func_id_to_usr.find(id.id) != id_map.local_ids.func_id_to_usr.end());
|
||||||
return UsrRef(
|
return UsrRef(
|
||||||
id_cache.func_id_to_usr.find(id.id)->second /*usr*/,
|
id_map.local_ids.func_id_to_usr.find(id.id)->second /*usr*/,
|
||||||
MapIdToUsr(id_cache, id.loc) /*loc*/);
|
MapIdToUsr(id_map, id.loc) /*loc*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapps for vectors of elements. We have to explicitly instantiate each
|
// Mapps for vectors of elements. We have to explicitly instantiate each
|
||||||
// template instance because C++ cannot deduce the return type template
|
// template instance because C++ cannot deduce the return type template
|
||||||
// parameter.
|
// parameter.
|
||||||
template<typename In, typename Out>
|
template<typename In, typename Out>
|
||||||
std::vector<Out> Transform(const IdCache& id_cache, const std::vector<In>& input) {
|
std::vector<Out> Transform(const IdMap& id_map, const std::vector<In>& input) {
|
||||||
std::vector<Out> result;
|
std::vector<Out> result;
|
||||||
result.reserve(input.size());
|
result.reserve(input.size());
|
||||||
for (const In& in : input)
|
for (const In& in : input)
|
||||||
result.push_back(MapIdToUsr(id_cache, in));
|
result.push_back(MapIdToUsr(id_map, in));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexTypeId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexTypeId>& ids) {
|
||||||
return Transform<IndexTypeId, Usr>(id_cache, ids);
|
return Transform<IndexTypeId, Usr>(id_map, ids);
|
||||||
}
|
}
|
||||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexFuncId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexFuncId>& ids) {
|
||||||
return Transform<IndexFuncId, Usr>(id_cache, ids);
|
return Transform<IndexFuncId, Usr>(id_map, ids);
|
||||||
}
|
}
|
||||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexVarId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexVarId>& ids) {
|
||||||
return Transform<IndexVarId, Usr>(id_cache, ids);
|
return Transform<IndexVarId, Usr>(id_map, ids);
|
||||||
}
|
}
|
||||||
std::vector<UsrRef> MapIdToUsr(const IdCache& id_cache, const std::vector<FuncRef>& ids) {
|
std::vector<UsrRef> MapIdToUsr(const IdMap& id_map, const std::vector<FuncRef>& ids) {
|
||||||
return Transform<FuncRef, UsrRef>(id_cache, ids);
|
return Transform<FuncRef, UsrRef>(id_map, ids);
|
||||||
}
|
}
|
||||||
std::vector<QueryableLocation> MapIdToUsr(const IdCache& id_cache, const std::vector<Range>& ids) {
|
std::vector<QueryableLocation> MapIdToUsr(const IdMap& id_map, const std::vector<Range>& ids) {
|
||||||
return Transform<Range, QueryableLocation>(id_cache, ids);
|
return Transform<Range, QueryableLocation>(id_map, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QueryableTypeDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedTypeDef::Def& def) {
|
QueryableTypeDef::DefUpdate MapIdToUsr(const IdMap& id_map, const IndexedTypeDef::Def& def) {
|
||||||
QueryableTypeDef::DefUpdate result(def.usr);
|
QueryableTypeDef::DefUpdate result(def.usr);
|
||||||
result.short_name = def.short_name;
|
result.short_name = def.short_name;
|
||||||
result.qualified_name = def.qualified_name;
|
result.qualified_name = def.qualified_name;
|
||||||
if (def.definition_spelling)
|
if (def.definition_spelling)
|
||||||
result.definition_spelling = MapIdToUsr(id_cache, def.definition_spelling.value());
|
result.definition_spelling = MapIdToUsr(id_map, def.definition_spelling.value());
|
||||||
if (def.definition_extent)
|
if (def.definition_extent)
|
||||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||||
if (def.alias_of)
|
if (def.alias_of)
|
||||||
result.alias_of = MapIdToUsr(id_cache, def.alias_of.value());
|
result.alias_of = MapIdToUsr(id_map, def.alias_of.value());
|
||||||
result.parents = MapIdToUsr(id_cache, def.parents);
|
result.parents = MapIdToUsr(id_map, def.parents);
|
||||||
result.types = MapIdToUsr(id_cache, def.types);
|
result.types = MapIdToUsr(id_map, def.types);
|
||||||
result.funcs = MapIdToUsr(id_cache, def.funcs);
|
result.funcs = MapIdToUsr(id_map, def.funcs);
|
||||||
result.vars = MapIdToUsr(id_cache, def.vars);
|
result.vars = MapIdToUsr(id_map, def.vars);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QueryableFuncDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedFuncDef::Def& def) {
|
QueryableFuncDef::DefUpdate MapIdToUsr(const IdMap& id_map, const IndexedFuncDef::Def& def) {
|
||||||
QueryableFuncDef::DefUpdate result(def.usr);
|
QueryableFuncDef::DefUpdate result(def.usr);
|
||||||
result.short_name = def.short_name;
|
result.short_name = def.short_name;
|
||||||
result.qualified_name = def.qualified_name;
|
result.qualified_name = def.qualified_name;
|
||||||
if (def.definition_spelling)
|
if (def.definition_spelling)
|
||||||
result.definition_spelling = MapIdToUsr(id_cache, def.definition_spelling.value());
|
result.definition_spelling = MapIdToUsr(id_map, def.definition_spelling.value());
|
||||||
if (def.definition_extent)
|
if (def.definition_extent)
|
||||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||||
if (def.declaring_type)
|
if (def.declaring_type)
|
||||||
result.declaring_type = MapIdToUsr(id_cache, def.declaring_type.value());
|
result.declaring_type = MapIdToUsr(id_map, def.declaring_type.value());
|
||||||
if (def.base)
|
if (def.base)
|
||||||
result.base = MapIdToUsr(id_cache, def.base.value());
|
result.base = MapIdToUsr(id_map, def.base.value());
|
||||||
result.locals = MapIdToUsr(id_cache, def.locals);
|
result.locals = MapIdToUsr(id_map, def.locals);
|
||||||
result.callees = MapIdToUsr(id_cache, def.callees);
|
result.callees = MapIdToUsr(id_map, def.callees);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QueryableVarDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedVarDef::Def& def) {
|
QueryableVarDef::DefUpdate MapIdToUsr(const IdMap& id_map, const IndexedVarDef::Def& def) {
|
||||||
QueryableVarDef::DefUpdate result(def.usr);
|
QueryableVarDef::DefUpdate result(def.usr);
|
||||||
result.short_name = def.short_name;
|
result.short_name = def.short_name;
|
||||||
result.qualified_name = def.qualified_name;
|
result.qualified_name = def.qualified_name;
|
||||||
if (def.declaration)
|
if (def.declaration)
|
||||||
result.declaration = MapIdToUsr(id_cache, def.declaration.value());
|
result.declaration = MapIdToUsr(id_map, def.declaration.value());
|
||||||
if (def.definition_spelling)
|
if (def.definition_spelling)
|
||||||
result.definition_spelling = MapIdToUsr(id_cache, def.definition_spelling.value());
|
result.definition_spelling = MapIdToUsr(id_map, def.definition_spelling.value());
|
||||||
if (def.definition_extent)
|
if (def.definition_extent)
|
||||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||||
if (def.variable_type)
|
if (def.variable_type)
|
||||||
result.variable_type = MapIdToUsr(id_cache, def.variable_type.value());
|
result.variable_type = MapIdToUsr(id_map, def.variable_type.value());
|
||||||
if (def.declaring_type)
|
if (def.declaring_type)
|
||||||
result.declaring_type = MapIdToUsr(id_cache, def.declaring_type.value());
|
result.declaring_type = MapIdToUsr(id_map, def.declaring_type.value());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,15 +131,15 @@ QueryableVarDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedVarD
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
QueryableFile::Def BuildFileDef(const IndexedFile& indexed) {
|
QueryableFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) {
|
||||||
QueryableFile::Def def;
|
QueryableFile::Def def;
|
||||||
def.usr = indexed.path;
|
def.usr = indexed.path;
|
||||||
|
|
||||||
auto add_outline = [&def, &indexed](Usr usr, Range range) {
|
auto add_outline = [&def, &id_map](Usr usr, Range range) {
|
||||||
def.outline.push_back(UsrRef(usr, MapIdToUsr(indexed.id_cache, range)));
|
def.outline.push_back(UsrRef(usr, MapIdToUsr(id_map, range)));
|
||||||
};
|
};
|
||||||
auto add_all_symbols = [&def, &indexed](Usr usr, Range range) {
|
auto add_all_symbols = [&def, &id_map](Usr usr, Range range) {
|
||||||
def.all_symbols.push_back(UsrRef(usr, MapIdToUsr(indexed.id_cache, range)));
|
def.all_symbols.push_back(UsrRef(usr, MapIdToUsr(id_map, range)));
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const IndexedTypeDef& def : indexed.types) {
|
for (const IndexedTypeDef& def : indexed.types) {
|
||||||
@ -197,27 +181,27 @@ QueryableFile::Def BuildFileDef(const IndexedFile& indexed) {
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryableFile::QueryableFile(const IndexedFile& indexed)
|
QueryableFile::QueryableFile(const IdMap& id_map, const IndexedFile& indexed)
|
||||||
: def(BuildFileDef(indexed)) {}
|
: def(BuildFileDef(id_map, indexed)) {}
|
||||||
|
|
||||||
QueryableTypeDef::QueryableTypeDef(IdCache& id_cache, const IndexedTypeDef& indexed)
|
QueryableTypeDef::QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& indexed)
|
||||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||||
derived = MapIdToUsr(id_cache, indexed.derived);
|
derived = MapIdToUsr(id_map, indexed.derived);
|
||||||
instantiations = MapIdToUsr(id_cache, indexed.instantiations);
|
instantiations = MapIdToUsr(id_map, indexed.instantiations);
|
||||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
uses = MapIdToUsr(id_map, indexed.uses);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryableFuncDef::QueryableFuncDef(IdCache& id_cache, const IndexedFuncDef& indexed)
|
QueryableFuncDef::QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed)
|
||||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||||
declarations = MapIdToUsr(id_cache, indexed.declarations);
|
declarations = MapIdToUsr(id_map, indexed.declarations);
|
||||||
derived = MapIdToUsr(id_cache, indexed.derived);
|
derived = MapIdToUsr(id_map, indexed.derived);
|
||||||
callers = MapIdToUsr(id_cache, indexed.callers);
|
callers = MapIdToUsr(id_map, indexed.callers);
|
||||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
uses = MapIdToUsr(id_map, indexed.uses);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryableVarDef::QueryableVarDef(IdCache& id_cache, const IndexedVarDef& indexed)
|
QueryableVarDef::QueryableVarDef(const IdMap& id_map, const IndexedVarDef& indexed)
|
||||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
uses = MapIdToUsr(id_map, indexed.uses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -372,19 +356,19 @@ void CompareGroups(
|
|||||||
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
IndexUpdate IndexUpdate::CreateImport(IndexedFile& file) {
|
IndexUpdate IndexUpdate::CreateImport(const IdMap& id_map, IndexedFile& file) {
|
||||||
// Return standard diff constructor but with an empty file so everything is
|
// Return standard diff constructor but with an empty file so everything is
|
||||||
// added.
|
// added.
|
||||||
IndexedFile previous(file.path);
|
IndexedFile previous(file.path);
|
||||||
return IndexUpdate(previous, file);
|
return IndexUpdate(id_map, id_map, previous, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
IndexUpdate IndexUpdate::CreateDelta(IndexedFile& current, IndexedFile& updated) {
|
IndexUpdate IndexUpdate::CreateDelta(const IdMap& current_id_map, const IdMap& previous_id_map, IndexedFile& current, IndexedFile& updated) {
|
||||||
return IndexUpdate(current, updated);
|
return IndexUpdate(current_id_map, previous_id_map, current, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file) {
|
IndexUpdate::IndexUpdate(const IdMap& current_id_map, const IdMap& previous_id_map, IndexedFile& previous_file, IndexedFile& current_file) {
|
||||||
// |query_name| is the name of the variable on the query type.
|
// |query_name| is the name of the variable on the query type.
|
||||||
// |index_name| is the name of the variable on the index type.
|
// |index_name| is the name of the variable on the index type.
|
||||||
// |type| is the type of the variable.
|
// |type| is the type of the variable.
|
||||||
@ -392,8 +376,8 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
{ \
|
{ \
|
||||||
/* Check for changes. */ \
|
/* Check for changes. */ \
|
||||||
std::vector<type> removed, added; \
|
std::vector<type> removed, added; \
|
||||||
auto previous = MapIdToUsr(previous_file.id_cache, previous_def->index_name); \
|
auto previous = MapIdToUsr(previous_id_map, previous_def->index_name); \
|
||||||
auto current = MapIdToUsr(current_file.id_cache, current_def->index_name); \
|
auto current = MapIdToUsr(current_id_map, current_def->index_name); \
|
||||||
bool did_add = ComputeDifferenceForUpdate( \
|
bool did_add = ComputeDifferenceForUpdate( \
|
||||||
previous, current, \
|
previous, current, \
|
||||||
&removed, &added); \
|
&removed, &added); \
|
||||||
@ -404,23 +388,23 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// File
|
// File
|
||||||
files_def_update.push_back(BuildFileDef(current_file));
|
files_def_update.push_back(BuildFileDef(current_id_map, current_file));
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
CompareGroups<IndexedTypeDef>(previous_file.types, current_file.types,
|
CompareGroups<IndexedTypeDef>(previous_file.types, current_file.types,
|
||||||
/*onRemoved:*/[this](IndexedTypeDef* def) {
|
/*onRemoved:*/[this](IndexedTypeDef* def) {
|
||||||
types_removed.push_back(def->def.usr);
|
types_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedTypeDef* def) {
|
/*onAdded:*/[this, ¤t_id_map](IndexedTypeDef* def) {
|
||||||
QueryableTypeDef query(current_file.id_cache, *def);
|
QueryableTypeDef query(current_id_map, *def);
|
||||||
types_def_update.push_back(query.def);
|
types_def_update.push_back(query.def);
|
||||||
types_derived.push_back(QueryableTypeDef::DerivedUpdate(query.def.usr, query.derived));
|
types_derived.push_back(QueryableTypeDef::DerivedUpdate(query.def.usr, query.derived));
|
||||||
types_instantiations.push_back(QueryableTypeDef::InstantiationsUpdate(query.def.usr, query.instantiations));
|
types_instantiations.push_back(QueryableTypeDef::InstantiationsUpdate(query.def.usr, query.instantiations));
|
||||||
types_uses.push_back(QueryableTypeDef::UsesUpdate(query.def.usr, query.uses));
|
types_uses.push_back(QueryableTypeDef::UsesUpdate(query.def.usr, query.uses));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
||||||
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||||
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
types_def_update.push_back(current_remapped_def);
|
types_def_update.push_back(current_remapped_def);
|
||||||
|
|
||||||
@ -434,17 +418,17 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
/*onRemoved:*/[this](IndexedFuncDef* def) {
|
/*onRemoved:*/[this](IndexedFuncDef* def) {
|
||||||
funcs_removed.push_back(def->def.usr);
|
funcs_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedFuncDef* def) {
|
/*onAdded:*/[this, ¤t_id_map](IndexedFuncDef* def) {
|
||||||
QueryableFuncDef query(current_file.id_cache, *def);
|
QueryableFuncDef query(current_id_map, *def);
|
||||||
funcs_def_update.push_back(query.def);
|
funcs_def_update.push_back(query.def);
|
||||||
funcs_declarations.push_back(QueryableFuncDef::DeclarationsUpdate(query.def.usr, query.declarations));
|
funcs_declarations.push_back(QueryableFuncDef::DeclarationsUpdate(query.def.usr, query.declarations));
|
||||||
funcs_derived.push_back(QueryableFuncDef::DerivedUpdate(query.def.usr, query.derived));
|
funcs_derived.push_back(QueryableFuncDef::DerivedUpdate(query.def.usr, query.derived));
|
||||||
funcs_callers.push_back(QueryableFuncDef::CallersUpdate(query.def.usr, query.callers));
|
funcs_callers.push_back(QueryableFuncDef::CallersUpdate(query.def.usr, query.callers));
|
||||||
funcs_uses.push_back(QueryableFuncDef::UsesUpdate(query.def.usr, query.uses));
|
funcs_uses.push_back(QueryableFuncDef::UsesUpdate(query.def.usr, query.uses));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
||||||
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||||
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
funcs_def_update.push_back(current_remapped_def);
|
funcs_def_update.push_back(current_remapped_def);
|
||||||
|
|
||||||
@ -459,14 +443,14 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
/*onRemoved:*/[this](IndexedVarDef* def) {
|
/*onRemoved:*/[this](IndexedVarDef* def) {
|
||||||
vars_removed.push_back(def->def.usr);
|
vars_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedVarDef* def) {
|
/*onAdded:*/[this, ¤t_id_map](IndexedVarDef* def) {
|
||||||
QueryableVarDef query(current_file.id_cache, *def);
|
QueryableVarDef query(current_id_map, *def);
|
||||||
vars_def_update.push_back(query.def);
|
vars_def_update.push_back(query.def);
|
||||||
vars_uses.push_back(QueryableVarDef::UsesUpdate(query.def.usr, query.uses));
|
vars_uses.push_back(QueryableVarDef::UsesUpdate(query.def.usr, query.uses));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
||||||
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||||
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
vars_def_update.push_back(current_remapped_def);
|
vars_def_update.push_back(current_remapped_def);
|
||||||
|
|
||||||
|
42
src/query.h
42
src/query.h
@ -15,6 +15,34 @@ using QueryTypeId = Id<QueryableTypeDef>;
|
|||||||
using QueryFuncId = Id<QueryableFuncDef>;
|
using QueryFuncId = Id<QueryableFuncDef>;
|
||||||
using QueryVarId = Id<QueryableVarDef>;
|
using QueryVarId = Id<QueryableVarDef>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct IdMap {
|
||||||
|
// TODO threading model
|
||||||
|
// - [querydb] Create IdMap mapping from every id registered in local_ids
|
||||||
|
// - [indexer] Create IndexUpdate using IdMap cached state
|
||||||
|
// - [querydb] Apply IndexUpdate
|
||||||
|
//
|
||||||
|
// Then lookup in cached_* should *never* fail.
|
||||||
|
|
||||||
|
const IdCache& local_ids;
|
||||||
|
|
||||||
|
IdMap(const IdCache& local_ids) : local_ids(local_ids) {}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
private:
|
||||||
|
QueryFileId index_file_id;
|
||||||
|
std::unordered_map<IndexTypeId, QueryTypeId> cached_type_ids_;
|
||||||
|
std::unordered_map<IndexFuncId, QueryFuncId> cached_func_ids_;
|
||||||
|
std::unordered_map<IndexVarId, QueryVarId> cached_var_ids_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: in types, store refs separately from irefs. Then we can drop
|
// TODO: in types, store refs separately from irefs. Then we can drop
|
||||||
// 'interesting' from location when that is cleaned up.
|
// 'interesting' from location when that is cleaned up.
|
||||||
|
|
||||||
@ -109,7 +137,7 @@ struct QueryableFile {
|
|||||||
DefUpdate def;
|
DefUpdate def;
|
||||||
|
|
||||||
QueryableFile() {}
|
QueryableFile() {}
|
||||||
QueryableFile(const IndexedFile& indexed);
|
QueryableFile(const IdMap& id_map, const IndexedFile& indexed);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryableTypeDef {
|
struct QueryableTypeDef {
|
||||||
@ -124,7 +152,7 @@ struct QueryableTypeDef {
|
|||||||
std::vector<QueryableLocation> uses;
|
std::vector<QueryableLocation> uses;
|
||||||
|
|
||||||
QueryableTypeDef() : def("") {}
|
QueryableTypeDef() : def("") {}
|
||||||
QueryableTypeDef(IdCache& id_cache, const IndexedTypeDef& indexed);
|
QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& indexed);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryableFuncDef {
|
struct QueryableFuncDef {
|
||||||
@ -141,7 +169,7 @@ struct QueryableFuncDef {
|
|||||||
std::vector<QueryableLocation> uses;
|
std::vector<QueryableLocation> uses;
|
||||||
|
|
||||||
QueryableFuncDef() : def("") {}
|
QueryableFuncDef() : def("") {}
|
||||||
QueryableFuncDef(IdCache& id_cache, const IndexedFuncDef& indexed);
|
QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryableVarDef {
|
struct QueryableVarDef {
|
||||||
@ -152,7 +180,7 @@ struct QueryableVarDef {
|
|||||||
std::vector<QueryableLocation> uses;
|
std::vector<QueryableLocation> uses;
|
||||||
|
|
||||||
QueryableVarDef() : def("") {}
|
QueryableVarDef() : def("") {}
|
||||||
QueryableVarDef(IdCache& id_cache, const IndexedVarDef& indexed);
|
QueryableVarDef(const IdMap& id_map, const IndexedVarDef& indexed);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SymbolKind { Invalid, File, Type, Func, Var };
|
enum class SymbolKind { Invalid, File, Type, Func, Var };
|
||||||
@ -167,8 +195,8 @@ struct SymbolIdx {
|
|||||||
|
|
||||||
struct IndexUpdate {
|
struct IndexUpdate {
|
||||||
// Creates a new IndexUpdate that will import |file|.
|
// Creates a new IndexUpdate that will import |file|.
|
||||||
static IndexUpdate CreateImport(IndexedFile& file);
|
static IndexUpdate CreateImport(const IdMap& id_map, IndexedFile& file);
|
||||||
static IndexUpdate CreateDelta(IndexedFile& current, IndexedFile& updated);
|
static IndexUpdate CreateDelta(const IdMap& current_id_map, const IdMap& previous_id_map, IndexedFile& current, IndexedFile& updated);
|
||||||
|
|
||||||
// Merge |update| into this update; this can reduce overhead / index update
|
// Merge |update| into this update; this can reduce overhead / index update
|
||||||
// work can be parallelized.
|
// work can be parallelized.
|
||||||
@ -202,7 +230,7 @@ struct IndexUpdate {
|
|||||||
// Creates an index update assuming that |previous| is already
|
// Creates an index update assuming that |previous| is already
|
||||||
// in the index, so only the delta between |previous| and |current|
|
// in the index, so only the delta between |previous| and |current|
|
||||||
// will be applied.
|
// will be applied.
|
||||||
IndexUpdate(IndexedFile& previous, IndexedFile& current);
|
IndexUpdate(const IdMap& current_id_map, const IdMap& previous_id_map, IndexedFile& previous, IndexedFile& current);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user