mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +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.
|
||||
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
||||
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);
|
||||
responses->Enqueue(response);
|
||||
time.ResetAndPrint("Loading cached index");
|
||||
@ -296,16 +308,43 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||
optional<IndexedFile> old_index = LoadCachedFile(request->path);
|
||||
time.ResetAndPrint("Loading previous 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.
|
||||
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);
|
||||
time.ResetAndPrint("Creating delta index update/response");
|
||||
responses->Enqueue(response);
|
||||
time.ResetAndPrint("Sending update to server");
|
||||
}
|
||||
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.
|
||||
IndexUpdate update = IndexUpdate::CreateImport(new_index);
|
||||
IndexUpdate update = IndexUpdate::CreateImport(new_id_map, new_index);
|
||||
IndexTranslationUnitResponse response(update);
|
||||
time.ResetAndPrint("Creating index update/response");
|
||||
responses->Enqueue(response);
|
||||
|
200
src/query.cc
200
src/query.cc
@ -14,124 +14,108 @@
|
||||
// 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 IdCache& id_cache, const IndexTypeId& id) {
|
||||
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 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());
|
||||
return id_map.local_ids.type_id_to_usr.find(id)->second;
|
||||
}
|
||||
Usr MapIdToUsr(const IdCache& id_cache, const IndexFuncId& id) {
|
||||
assert(id_cache.func_id_to_usr.find(id) != id_cache.func_id_to_usr.end());
|
||||
return id_cache.func_id_to_usr.find(id)->second;
|
||||
Usr MapIdToUsr(const IdMap& id_map, const IndexFuncId& id) {
|
||||
assert(id_map.local_ids.func_id_to_usr.find(id) != id_map.local_ids.func_id_to_usr.end());
|
||||
return id_map.local_ids.func_id_to_usr.find(id)->second;
|
||||
}
|
||||
Usr MapIdToUsr(const IdCache& id_cache, const IndexVarId& id) {
|
||||
assert(id_cache.var_id_to_usr.find(id) != id_cache.var_id_to_usr.end());
|
||||
return id_cache.var_id_to_usr.find(id)->second;
|
||||
Usr MapIdToUsr(const IdMap& id_map, const IndexVarId& id) {
|
||||
assert(id_map.local_ids.var_id_to_usr.find(id) != id_map.local_ids.var_id_to_usr.end());
|
||||
return id_map.local_ids.var_id_to_usr.find(id)->second;
|
||||
}
|
||||
QueryableLocation MapIdToUsr(const IdCache& id_cache, const Range& range) {
|
||||
return QueryableLocation(id_cache.primary_file, range);
|
||||
QueryableLocation MapIdToUsr(const IdMap& id_map, const Range& range) {
|
||||
return QueryableLocation(id_map.local_ids.primary_file, range);
|
||||
}
|
||||
UsrRef MapIdToUsr(const IdCache& id_cache, const FuncRef& id) {
|
||||
assert(id_cache.func_id_to_usr.find(id.id) != id_cache.func_id_to_usr.end());
|
||||
UsrRef MapIdToUsr(const IdMap& id_map, const FuncRef& id) {
|
||||
assert(id_map.local_ids.func_id_to_usr.find(id.id) != id_map.local_ids.func_id_to_usr.end());
|
||||
return UsrRef(
|
||||
id_cache.func_id_to_usr.find(id.id)->second /*usr*/,
|
||||
MapIdToUsr(id_cache, id.loc) /*loc*/);
|
||||
id_map.local_ids.func_id_to_usr.find(id.id)->second /*usr*/,
|
||||
MapIdToUsr(id_map, id.loc) /*loc*/);
|
||||
}
|
||||
|
||||
// Mapps for vectors of elements. We have to explicitly instantiate each
|
||||
// template instance because C++ cannot deduce the return type template
|
||||
// parameter.
|
||||
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;
|
||||
result.reserve(input.size());
|
||||
for (const In& in : input)
|
||||
result.push_back(MapIdToUsr(id_cache, in));
|
||||
result.push_back(MapIdToUsr(id_map, in));
|
||||
return result;
|
||||
}
|
||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexTypeId>& ids) {
|
||||
return Transform<IndexTypeId, Usr>(id_cache, ids);
|
||||
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexTypeId>& ids) {
|
||||
return Transform<IndexTypeId, Usr>(id_map, ids);
|
||||
}
|
||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexFuncId>& ids) {
|
||||
return Transform<IndexFuncId, Usr>(id_cache, ids);
|
||||
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexFuncId>& ids) {
|
||||
return Transform<IndexFuncId, Usr>(id_map, ids);
|
||||
}
|
||||
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<IndexVarId>& ids) {
|
||||
return Transform<IndexVarId, Usr>(id_cache, ids);
|
||||
std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexVarId>& ids) {
|
||||
return Transform<IndexVarId, Usr>(id_map, ids);
|
||||
}
|
||||
std::vector<UsrRef> MapIdToUsr(const IdCache& id_cache, const std::vector<FuncRef>& ids) {
|
||||
return Transform<FuncRef, UsrRef>(id_cache, ids);
|
||||
std::vector<UsrRef> MapIdToUsr(const IdMap& id_map, const std::vector<FuncRef>& ids) {
|
||||
return Transform<FuncRef, UsrRef>(id_map, ids);
|
||||
}
|
||||
std::vector<QueryableLocation> MapIdToUsr(const IdCache& id_cache, const std::vector<Range>& ids) {
|
||||
return Transform<Range, QueryableLocation>(id_cache, ids);
|
||||
std::vector<QueryableLocation> MapIdToUsr(const IdMap& id_map, const std::vector<Range>& 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);
|
||||
result.short_name = def.short_name;
|
||||
result.qualified_name = def.qualified_name;
|
||||
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)
|
||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
||||
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||
if (def.alias_of)
|
||||
result.alias_of = MapIdToUsr(id_cache, def.alias_of.value());
|
||||
result.parents = MapIdToUsr(id_cache, def.parents);
|
||||
result.types = MapIdToUsr(id_cache, def.types);
|
||||
result.funcs = MapIdToUsr(id_cache, def.funcs);
|
||||
result.vars = MapIdToUsr(id_cache, def.vars);
|
||||
result.alias_of = MapIdToUsr(id_map, def.alias_of.value());
|
||||
result.parents = MapIdToUsr(id_map, def.parents);
|
||||
result.types = MapIdToUsr(id_map, def.types);
|
||||
result.funcs = MapIdToUsr(id_map, def.funcs);
|
||||
result.vars = MapIdToUsr(id_map, def.vars);
|
||||
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);
|
||||
result.short_name = def.short_name;
|
||||
result.qualified_name = def.qualified_name;
|
||||
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)
|
||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
||||
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||
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)
|
||||
result.base = MapIdToUsr(id_cache, def.base.value());
|
||||
result.locals = MapIdToUsr(id_cache, def.locals);
|
||||
result.callees = MapIdToUsr(id_cache, def.callees);
|
||||
result.base = MapIdToUsr(id_map, def.base.value());
|
||||
result.locals = MapIdToUsr(id_map, def.locals);
|
||||
result.callees = MapIdToUsr(id_map, def.callees);
|
||||
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);
|
||||
result.short_name = def.short_name;
|
||||
result.qualified_name = def.qualified_name;
|
||||
if (def.declaration)
|
||||
result.declaration = MapIdToUsr(id_cache, def.declaration.value());
|
||||
result.declaration = MapIdToUsr(id_map, def.declaration.value());
|
||||
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)
|
||||
result.definition_extent = MapIdToUsr(id_cache, def.definition_extent.value());
|
||||
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||
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)
|
||||
result.declaring_type = MapIdToUsr(id_cache, def.declaring_type.value());
|
||||
result.declaring_type = MapIdToUsr(id_map, def.declaring_type.value());
|
||||
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;
|
||||
def.usr = indexed.path;
|
||||
|
||||
auto add_outline = [&def, &indexed](Usr usr, Range range) {
|
||||
def.outline.push_back(UsrRef(usr, MapIdToUsr(indexed.id_cache, range)));
|
||||
auto add_outline = [&def, &id_map](Usr usr, Range range) {
|
||||
def.outline.push_back(UsrRef(usr, MapIdToUsr(id_map, range)));
|
||||
};
|
||||
auto add_all_symbols = [&def, &indexed](Usr usr, Range range) {
|
||||
def.all_symbols.push_back(UsrRef(usr, MapIdToUsr(indexed.id_cache, range)));
|
||||
auto add_all_symbols = [&def, &id_map](Usr usr, Range range) {
|
||||
def.all_symbols.push_back(UsrRef(usr, MapIdToUsr(id_map, range)));
|
||||
};
|
||||
|
||||
for (const IndexedTypeDef& def : indexed.types) {
|
||||
@ -197,27 +181,27 @@ QueryableFile::Def BuildFileDef(const IndexedFile& indexed) {
|
||||
return def;
|
||||
}
|
||||
|
||||
QueryableFile::QueryableFile(const IndexedFile& indexed)
|
||||
: def(BuildFileDef(indexed)) {}
|
||||
QueryableFile::QueryableFile(const IdMap& id_map, const IndexedFile& indexed)
|
||||
: def(BuildFileDef(id_map, indexed)) {}
|
||||
|
||||
QueryableTypeDef::QueryableTypeDef(IdCache& id_cache, const IndexedTypeDef& indexed)
|
||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
||||
derived = MapIdToUsr(id_cache, indexed.derived);
|
||||
instantiations = MapIdToUsr(id_cache, indexed.instantiations);
|
||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
||||
QueryableTypeDef::QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& indexed)
|
||||
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||
derived = MapIdToUsr(id_map, indexed.derived);
|
||||
instantiations = MapIdToUsr(id_map, indexed.instantiations);
|
||||
uses = MapIdToUsr(id_map, indexed.uses);
|
||||
}
|
||||
|
||||
QueryableFuncDef::QueryableFuncDef(IdCache& id_cache, const IndexedFuncDef& indexed)
|
||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
||||
declarations = MapIdToUsr(id_cache, indexed.declarations);
|
||||
derived = MapIdToUsr(id_cache, indexed.derived);
|
||||
callers = MapIdToUsr(id_cache, indexed.callers);
|
||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
||||
QueryableFuncDef::QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed)
|
||||
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||
declarations = MapIdToUsr(id_map, indexed.declarations);
|
||||
derived = MapIdToUsr(id_map, indexed.derived);
|
||||
callers = MapIdToUsr(id_map, indexed.callers);
|
||||
uses = MapIdToUsr(id_map, indexed.uses);
|
||||
}
|
||||
|
||||
QueryableVarDef::QueryableVarDef(IdCache& id_cache, const IndexedVarDef& indexed)
|
||||
: def(MapIdToUsr(id_cache, indexed.def)) {
|
||||
uses = MapIdToUsr(id_cache, indexed.uses);
|
||||
QueryableVarDef::QueryableVarDef(const IdMap& id_map, const IndexedVarDef& indexed)
|
||||
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||
uses = MapIdToUsr(id_map, indexed.uses);
|
||||
}
|
||||
|
||||
|
||||
@ -372,19 +356,19 @@ void CompareGroups(
|
||||
|
||||
|
||||
// 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
|
||||
// added.
|
||||
IndexedFile previous(file.path);
|
||||
return IndexUpdate(previous, file);
|
||||
return IndexUpdate(id_map, id_map, previous, file);
|
||||
}
|
||||
|
||||
// static
|
||||
IndexUpdate IndexUpdate::CreateDelta(IndexedFile& current, IndexedFile& updated) {
|
||||
return IndexUpdate(current, updated);
|
||||
IndexUpdate IndexUpdate::CreateDelta(const IdMap& current_id_map, const IdMap& previous_id_map, IndexedFile& current, IndexedFile& 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.
|
||||
// |index_name| is the name of the variable on the index type.
|
||||
// |type| is the type of the variable.
|
||||
@ -392,8 +376,8 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
||||
{ \
|
||||
/* Check for changes. */ \
|
||||
std::vector<type> removed, added; \
|
||||
auto previous = MapIdToUsr(previous_file.id_cache, previous_def->index_name); \
|
||||
auto current = MapIdToUsr(current_file.id_cache, current_def->index_name); \
|
||||
auto previous = MapIdToUsr(previous_id_map, previous_def->index_name); \
|
||||
auto current = MapIdToUsr(current_id_map, current_def->index_name); \
|
||||
bool did_add = ComputeDifferenceForUpdate( \
|
||||
previous, current, \
|
||||
&removed, &added); \
|
||||
@ -404,23 +388,23 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
||||
}
|
||||
|
||||
// File
|
||||
files_def_update.push_back(BuildFileDef(current_file));
|
||||
files_def_update.push_back(BuildFileDef(current_id_map, current_file));
|
||||
|
||||
// Types
|
||||
CompareGroups<IndexedTypeDef>(previous_file.types, current_file.types,
|
||||
/*onRemoved:*/[this](IndexedTypeDef* def) {
|
||||
types_removed.push_back(def->def.usr);
|
||||
},
|
||||
/*onAdded:*/[this, ¤t_file](IndexedTypeDef* def) {
|
||||
QueryableTypeDef query(current_file.id_cache, *def);
|
||||
/*onAdded:*/[this, ¤t_id_map](IndexedTypeDef* def) {
|
||||
QueryableTypeDef query(current_id_map, *def);
|
||||
types_def_update.push_back(query.def);
|
||||
types_derived.push_back(QueryableTypeDef::DerivedUpdate(query.def.usr, query.derived));
|
||||
types_instantiations.push_back(QueryableTypeDef::InstantiationsUpdate(query.def.usr, query.instantiations));
|
||||
types_uses.push_back(QueryableTypeDef::UsesUpdate(query.def.usr, query.uses));
|
||||
},
|
||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
||||
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
||||
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||
if (previous_remapped_def != 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) {
|
||||
funcs_removed.push_back(def->def.usr);
|
||||
},
|
||||
/*onAdded:*/[this, ¤t_file](IndexedFuncDef* def) {
|
||||
QueryableFuncDef query(current_file.id_cache, *def);
|
||||
/*onAdded:*/[this, ¤t_id_map](IndexedFuncDef* def) {
|
||||
QueryableFuncDef query(current_id_map, *def);
|
||||
funcs_def_update.push_back(query.def);
|
||||
funcs_declarations.push_back(QueryableFuncDef::DeclarationsUpdate(query.def.usr, query.declarations));
|
||||
funcs_derived.push_back(QueryableFuncDef::DerivedUpdate(query.def.usr, query.derived));
|
||||
funcs_callers.push_back(QueryableFuncDef::CallersUpdate(query.def.usr, query.callers));
|
||||
funcs_uses.push_back(QueryableFuncDef::UsesUpdate(query.def.usr, query.uses));
|
||||
},
|
||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
||||
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
||||
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||
if (previous_remapped_def != 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) {
|
||||
vars_removed.push_back(def->def.usr);
|
||||
},
|
||||
/*onAdded:*/[this, ¤t_file](IndexedVarDef* def) {
|
||||
QueryableVarDef query(current_file.id_cache, *def);
|
||||
/*onAdded:*/[this, ¤t_id_map](IndexedVarDef* def) {
|
||||
QueryableVarDef query(current_id_map, *def);
|
||||
vars_def_update.push_back(query.def);
|
||||
vars_uses.push_back(QueryableVarDef::UsesUpdate(query.def.usr, query.uses));
|
||||
},
|
||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
||||
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
||||
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_id_map, previous_def->def);
|
||||
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(current_id_map, current_def->def);
|
||||
if (previous_remapped_def != 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 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
|
||||
// 'interesting' from location when that is cleaned up.
|
||||
|
||||
@ -109,7 +137,7 @@ struct QueryableFile {
|
||||
DefUpdate def;
|
||||
|
||||
QueryableFile() {}
|
||||
QueryableFile(const IndexedFile& indexed);
|
||||
QueryableFile(const IdMap& id_map, const IndexedFile& indexed);
|
||||
};
|
||||
|
||||
struct QueryableTypeDef {
|
||||
@ -124,7 +152,7 @@ struct QueryableTypeDef {
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
QueryableTypeDef() : def("") {}
|
||||
QueryableTypeDef(IdCache& id_cache, const IndexedTypeDef& indexed);
|
||||
QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& indexed);
|
||||
};
|
||||
|
||||
struct QueryableFuncDef {
|
||||
@ -141,7 +169,7 @@ struct QueryableFuncDef {
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
QueryableFuncDef() : def("") {}
|
||||
QueryableFuncDef(IdCache& id_cache, const IndexedFuncDef& indexed);
|
||||
QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed);
|
||||
};
|
||||
|
||||
struct QueryableVarDef {
|
||||
@ -152,7 +180,7 @@ struct QueryableVarDef {
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
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 };
|
||||
@ -167,8 +195,8 @@ struct SymbolIdx {
|
||||
|
||||
struct IndexUpdate {
|
||||
// Creates a new IndexUpdate that will import |file|.
|
||||
static IndexUpdate CreateImport(IndexedFile& file);
|
||||
static IndexUpdate CreateDelta(IndexedFile& current, IndexedFile& updated);
|
||||
static IndexUpdate CreateImport(const IdMap& id_map, IndexedFile& file);
|
||||
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
|
||||
// work can be parallelized.
|
||||
@ -202,7 +230,7 @@ struct IndexUpdate {
|
||||
// Creates an index update assuming that |previous| is already
|
||||
// in the index, so only the delta between |previous| and |current|
|
||||
// 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