mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
wip IdMap
This commit is contained in:
parent
c5dc7a7ac7
commit
6f071cfeb8
@ -279,7 +279,7 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
// TODO: We need to create IdMap on QueryDb thread.
|
||||
IdMap old_id_map(old_index->id_cache);
|
||||
IdMap old_id_map(nullptr, old_index->id_cache);
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
@ -314,8 +314,8 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||
// 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);
|
||||
IdMap old_id_map(nullptr, old_index->id_cache);
|
||||
IdMap new_id_map(nullptr, new_index.id_cache);
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
@ -336,7 +336,7 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
// TODO: We need to create IdMap on QueryDb thread.
|
||||
IdMap new_id_map(new_index.id_cache);
|
||||
IdMap new_id_map(nullptr, new_index.id_cache);
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
// TODO/FIXME/TODO
|
||||
|
153
src/query.cc
153
src/query.cc
@ -345,6 +345,139 @@ void CompareGroups(
|
||||
|
||||
|
||||
|
||||
// TODO: consider having separate lookup maps so they are smaller (maybe
|
||||
// lookups will go faster).
|
||||
|
||||
QueryFileId GetQueryFileIdFromUsr(QueryableDatabase* query_db, const Usr& usr) {
|
||||
auto it = query_db->usr_to_symbol.find(usr);
|
||||
if (it != query_db->usr_to_symbol.end()) {
|
||||
assert(it->second.kind == SymbolKind::File);
|
||||
return it->second.idx;
|
||||
}
|
||||
|
||||
int idx = query_db->files.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::File, idx);
|
||||
query_db->files.push_back(QueryableFile(usr));
|
||||
return idx;
|
||||
}
|
||||
|
||||
QueryTypeId GetQueryTypeIdFromUsr(QueryableDatabase* query_db, const Usr& usr) {
|
||||
auto it = query_db->usr_to_symbol.find(usr);
|
||||
if (it != query_db->usr_to_symbol.end()) {
|
||||
assert(it->second.kind == SymbolKind::Type);
|
||||
return it->second.idx;
|
||||
}
|
||||
|
||||
int idx = query_db->types.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Type, idx);
|
||||
query_db->types.push_back(QueryableTypeDef(usr));
|
||||
return idx;
|
||||
}
|
||||
|
||||
QueryFuncId GetQueryFuncIdFromUsr(QueryableDatabase* query_db, const Usr& usr) {
|
||||
auto it = query_db->usr_to_symbol.find(usr);
|
||||
if (it != query_db->usr_to_symbol.end()) {
|
||||
assert(it->second.kind == SymbolKind::Func);
|
||||
return it->second.idx;
|
||||
}
|
||||
|
||||
int idx = query_db->funcs.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Func, idx);
|
||||
query_db->funcs.push_back(QueryableFuncDef(usr));
|
||||
return idx;
|
||||
}
|
||||
|
||||
QueryVarId GetQueryVarIdFromUsr(QueryableDatabase* query_db, const Usr& usr) {
|
||||
auto it = query_db->usr_to_symbol.find(usr);
|
||||
if (it != query_db->usr_to_symbol.end()) {
|
||||
assert(it->second.kind == SymbolKind::Var);
|
||||
return it->second.idx;
|
||||
}
|
||||
|
||||
int idx = query_db->vars.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(SymbolKind::Var, idx);
|
||||
query_db->vars.push_back(QueryableVarDef(usr));
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
#if false
|
||||
int GetOrAddSymbol(QueryableDatabase* query_db, SymbolKind kind, const Usr& usr) {
|
||||
// TODO: consider having separate lookup maps so they are smaller (maybe
|
||||
// lookups will go faster).
|
||||
auto it = query_db->usr_to_symbol.find(usr);
|
||||
|
||||
// Found; return existing symbol.
|
||||
if (it != query_db->usr_to_symbol.end()) {
|
||||
assert(it->second.kind == kind);
|
||||
return it->second.idx;
|
||||
}
|
||||
|
||||
// Not found; add a new symbol.
|
||||
switch (kind) {
|
||||
case SymbolKind::File: {
|
||||
int idx = query_db->files.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(kind, idx);
|
||||
query_db->files.push_back(QueryableFile(usr));
|
||||
return idx;
|
||||
}
|
||||
case SymbolKind::Type: {
|
||||
int idx = query_db->types.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(kind, idx);
|
||||
query_db->types.push_back(QueryableTypeDef(usr));
|
||||
return idx;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
int idx = query_db->funcs.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(kind, idx);
|
||||
query_db->funcs.push_back(QueryableFuncDef(usr));
|
||||
return idx;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
int idx = query_db->vars.size();
|
||||
query_db->usr_to_symbol[usr] = SymbolIdx(kind, idx);
|
||||
query_db->vars.push_back(QueryableVarDef(usr));
|
||||
return idx;
|
||||
}
|
||||
case SymbolKind::Invalid: {
|
||||
assert(false);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
IdMap::IdMap(QueryableDatabase* query_db, const IdCache& local_ids)
|
||||
: local_ids(local_ids) {
|
||||
assert(query_db); // TODO: remove after testing.
|
||||
|
||||
index_file_id = GetQueryFileIdFromUsr(query_db, local_ids.primary_file);
|
||||
|
||||
cached_type_ids_.reserve(local_ids.type_id_to_usr.size());
|
||||
for (const auto& entry : local_ids.type_id_to_usr)
|
||||
cached_type_ids_[entry.first] = GetQueryTypeIdFromUsr(query_db, entry.second);
|
||||
|
||||
cached_func_ids_.reserve(local_ids.func_id_to_usr.size());
|
||||
for (const auto& entry : local_ids.func_id_to_usr)
|
||||
cached_func_ids_[entry.first] = GetQueryFuncIdFromUsr(query_db, entry.second);
|
||||
|
||||
cached_var_ids_.reserve(local_ids.var_id_to_usr.size());
|
||||
for (const auto& entry : local_ids.var_id_to_usr)
|
||||
cached_var_ids_[entry.first] = GetQueryVarIdFromUsr(query_db, entry.second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -525,10 +658,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFile::DefUpdat
|
||||
qualified_names.push_back(def.usr);
|
||||
symbols.push_back(SymbolIdx(SymbolKind::File, files.size()));
|
||||
usr_to_symbol[def.usr] = SymbolIdx(SymbolKind::File, files.size());
|
||||
|
||||
QueryableFile query;
|
||||
query.def = def;
|
||||
files.push_back(query);
|
||||
files.push_back(QueryableFile(def));
|
||||
}
|
||||
else {
|
||||
QueryableFile& existing = files[it->second.idx];
|
||||
@ -544,10 +674,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableTypeDef::DefUp
|
||||
qualified_names.push_back(def.qualified_name);
|
||||
symbols.push_back(SymbolIdx(SymbolKind::Type, types.size()));
|
||||
usr_to_symbol[def.usr] = SymbolIdx(SymbolKind::Type, types.size());
|
||||
|
||||
QueryableTypeDef query;
|
||||
query.def = def;
|
||||
types.push_back(query);
|
||||
types.push_back(QueryableTypeDef(def));
|
||||
}
|
||||
else {
|
||||
QueryableTypeDef& existing = types[it->second.idx];
|
||||
@ -564,10 +691,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableFuncDef::DefUp
|
||||
qualified_names.push_back(def.qualified_name);
|
||||
symbols.push_back(SymbolIdx(SymbolKind::Func, funcs.size()));
|
||||
usr_to_symbol[def.usr] = SymbolIdx(SymbolKind::Func, funcs.size());
|
||||
|
||||
QueryableFuncDef query;
|
||||
query.def = def;
|
||||
funcs.push_back(query);
|
||||
funcs.push_back(QueryableFuncDef(def));
|
||||
}
|
||||
else {
|
||||
QueryableFuncDef& existing = funcs[it->second.idx];
|
||||
@ -584,10 +708,7 @@ void QueryableDatabase::ImportOrUpdate(const std::vector<QueryableVarDef::DefUpd
|
||||
qualified_names.push_back(def.qualified_name);
|
||||
symbols.push_back(SymbolIdx(SymbolKind::Var, vars.size()));
|
||||
usr_to_symbol[def.usr] = SymbolIdx(SymbolKind::Var, vars.size());
|
||||
|
||||
QueryableVarDef query;
|
||||
query.def = def;
|
||||
vars.push_back(query);
|
||||
vars.push_back(QueryableVarDef(def));
|
||||
}
|
||||
else {
|
||||
QueryableVarDef& existing = vars[it->second.idx];
|
||||
|
58
src/query.h
58
src/query.h
@ -20,26 +20,7 @@ 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_;
|
||||
};
|
||||
|
||||
struct IdMap;
|
||||
|
||||
|
||||
|
||||
@ -136,7 +117,8 @@ struct QueryableFile {
|
||||
|
||||
DefUpdate def;
|
||||
|
||||
QueryableFile() {}
|
||||
QueryableFile(const Usr& usr) { def.usr = usr; }
|
||||
QueryableFile(const Def& def) : def(def) {}
|
||||
QueryableFile(const IdMap& id_map, const IndexedFile& indexed);
|
||||
};
|
||||
|
||||
@ -151,7 +133,8 @@ struct QueryableTypeDef {
|
||||
std::vector<Usr> instantiations;
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
QueryableTypeDef() : def("") {}
|
||||
QueryableTypeDef(const Usr& usr) : def(usr) {}
|
||||
QueryableTypeDef(const DefUpdate& def) : def(def) {}
|
||||
QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& indexed);
|
||||
};
|
||||
|
||||
@ -168,7 +151,8 @@ struct QueryableFuncDef {
|
||||
std::vector<UsrRef> callers;
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
QueryableFuncDef() : def("") {}
|
||||
QueryableFuncDef(const Usr& usr) : def(usr) {}
|
||||
QueryableFuncDef(const DefUpdate& def) : def(def) {}
|
||||
QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed);
|
||||
};
|
||||
|
||||
@ -179,7 +163,8 @@ struct QueryableVarDef {
|
||||
DefUpdate def;
|
||||
std::vector<QueryableLocation> uses;
|
||||
|
||||
QueryableVarDef() : def("") {}
|
||||
QueryableVarDef(const Usr& usr) : def(usr) {}
|
||||
QueryableVarDef(const DefUpdate& def) : def(def) {}
|
||||
QueryableVarDef(const IdMap& id_map, const IndexedVarDef& indexed);
|
||||
};
|
||||
|
||||
@ -259,4 +244,27 @@ struct QueryableDatabase {
|
||||
void ImportOrUpdate(const std::vector<QueryableTypeDef::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryableFuncDef::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryableVarDef::DefUpdate>& updates);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
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(QueryableDatabase* query_db, const IdCache& 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_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user