From d43b994557a948211d2f8e2d7e22b998ef837fb0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 3 Dec 2018 09:42:16 -0800 Subject: [PATCH] query: fix UpdateUses when a new entity is seen; simplify {DeclRef,Use,Usr}Update Thanks to Leszek Swirski --- src/query.cc | 2 +- src/query.hh | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/query.cc b/src/query.cc index 0906ee24..48247fac 100644 --- a/src/query.cc +++ b/src/query.cc @@ -264,7 +264,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) { diff --git a/src/query.hh b/src/query.hh index 60f23433..a624b04f 100644 --- a/src/query.hh +++ b/src/query.hh @@ -73,13 +73,9 @@ template struct QueryEntity { } }; -using DeclRefUpdate = - std::unordered_map, std::vector>>; -using UseUpdate = - std::unordered_map, std::vector>>; -using UsrUpdate = - std::unordered_map, std::vector>>; +template +using Update = + std::unordered_map, std::vector>>; struct QueryFunc : QueryEntity { Usr usr; @@ -126,25 +122,25 @@ struct IndexUpdate { int funcs_hint; std::vector> funcs_removed; std::vector> funcs_def_update; - DeclRefUpdate funcs_declarations; - UseUpdate funcs_uses; - UsrUpdate funcs_derived; + Update funcs_declarations; + Update funcs_uses; + Update funcs_derived; // Type updates. int types_hint; std::vector> types_removed; std::vector> types_def_update; - DeclRefUpdate types_declarations; - UseUpdate types_uses; - UsrUpdate types_derived; - UsrUpdate types_instances; + Update types_declarations; + Update types_uses; + Update types_derived; + Update types_instances; // Variable updates. int vars_hint; std::vector> vars_removed; std::vector> vars_def_update; - DeclRefUpdate vars_declarations; - UseUpdate vars_uses; + Update vars_declarations; + Update vars_uses; }; struct DenseMapInfoForUsr {