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 04e80544b9
commit d43b994557
2 changed files with 13 additions and 17 deletions

View File

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

View File

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