query: fix UpdateUses when a new entity is seen; simplify {DeclRef,Use,Usr}Update

Thanks to Leszek Swirski
This commit is contained in:
Fangrui Song 2018-12-03 09:42:16 -08:00
parent cc11d30dad
commit 4416a258ae
2 changed files with 13 additions and 17 deletions

View File

@ -252,7 +252,7 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
auto &entities, auto &p, bool hint_implicit) {
auto R = entity_usr.try_emplace(usr, entity_usr.size());
if (R.second)
vars.emplace_back().usr = usr;
entities.emplace_back().usr = usr;
auto &entity = entities[R.first->second];
for (Use &use : p.first) {
if (hint_implicit && use.role & Role::Implicit) {

View File

@ -62,13 +62,9 @@ template <typename Q, typename QDef> struct QueryEntity {
}
};
using DeclRefUpdate =
std::unordered_map<Usr,
std::pair<std::vector<DeclRef>, std::vector<DeclRef>>>;
using UseUpdate =
std::unordered_map<Usr, std::pair<std::vector<Use>, std::vector<Use>>>;
using UsrUpdate =
std::unordered_map<Usr, std::pair<std::vector<Usr>, std::vector<Usr>>>;
template <typename T>
using Update =
std::unordered_map<Usr, std::pair<std::vector<T>, std::vector<T>>>;
struct QueryFunc : QueryEntity<QueryFunc, FuncDef> {
Usr usr;
@ -115,25 +111,25 @@ struct IndexUpdate {
int funcs_hint;
std::vector<std::pair<Usr, QueryFunc::Def>> funcs_removed;
std::vector<std::pair<Usr, QueryFunc::Def>> funcs_def_update;
DeclRefUpdate funcs_declarations;
UseUpdate funcs_uses;
UsrUpdate funcs_derived;
Update<DeclRef> funcs_declarations;
Update<Use> funcs_uses;
Update<Usr> funcs_derived;
// Type updates.
int types_hint;
std::vector<std::pair<Usr, QueryType::Def>> types_removed;
std::vector<std::pair<Usr, QueryType::Def>> types_def_update;
DeclRefUpdate types_declarations;
UseUpdate types_uses;
UsrUpdate types_derived;
UsrUpdate types_instances;
Update<DeclRef> types_declarations;
Update<Use> types_uses;
Update<Usr> types_derived;
Update<Usr> types_instances;
// Variable updates.
int vars_hint;
std::vector<std::pair<Usr, QueryVar::Def>> vars_removed;
std::vector<std::pair<Usr, QueryVar::Def>> vars_def_update;
DeclRefUpdate vars_declarations;
UseUpdate vars_uses;
Update<DeclRef> vars_declarations;
Update<Use> vars_uses;
};
struct DenseMapInfoForUsr {