Skip to content

Commit

Permalink
Fix querydb corruption/invalid references accumulating over time.
Browse files Browse the repository at this point in the history
Hopefully this catches all of the issues. We will see in time.

This resolves issue MaskRay#443
  • Loading branch information
jacobdufault committed Feb 14, 2018
1 parent 0c4d826 commit 71a55ce
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions src/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,18 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
[this, &previous_id_map](IndexType* type) {
if (type->def.spell)
types_removed.push_back(type->usr);
else {
if (!type->derived.empty())
types_derived.push_back(QueryType::DerivedUpdate(
previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->derived)));
if (!type->instances.empty())
types_instances.push_back(QueryType::InstancesUpdate(
previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->instances)));
if (!type->uses.empty())
types_uses.push_back(
QueryType::UsesUpdate(previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->uses)));
}
if (!type->derived.empty())
types_derived.push_back(QueryType::DerivedUpdate(
previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->derived)));
if (!type->instances.empty())
types_instances.push_back(QueryType::InstancesUpdate(
previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->instances)));
if (!type->uses.empty())
types_uses.push_back(
QueryType::UsesUpdate(previous_id_map.ToQuery(type->id), {},
previous_id_map.ToQuery(type->uses)));
},
/*onAdded:*/
[this, &current_id_map](IndexType* type) {
Expand Down Expand Up @@ -571,22 +569,20 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
previous_file.funcs, current_file.funcs,
/*onRemoved:*/
[this, &previous_id_map](IndexFunc* func) {
if (func->def.spell) {
if (func->def.spell)
funcs_removed.push_back(func->usr);
} else {
if (!func->declarations.empty())
funcs_declarations.push_back(QueryFunc::DeclarationsUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->declarations)));
if (!func->derived.empty())
funcs_derived.push_back(QueryFunc::DerivedUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->derived)));
if (!func->uses.empty())
funcs_uses.push_back(QueryFunc::UsesUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->uses)));
}
if (!func->declarations.empty())
funcs_declarations.push_back(QueryFunc::DeclarationsUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->declarations)));
if (!func->derived.empty())
funcs_derived.push_back(QueryFunc::DerivedUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->derived)));
if (!func->uses.empty())
funcs_uses.push_back(QueryFunc::UsesUpdate(
previous_id_map.ToQuery(func->id), {},
previous_id_map.ToQuery(func->uses)));
},
/*onAdded:*/
[this, &current_id_map](IndexFunc* func) {
Expand Down Expand Up @@ -633,18 +629,16 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
previous_file.vars, current_file.vars,
/*onRemoved:*/
[this, &previous_id_map](IndexVar* var) {
if (var->def.spell) {
if (var->def.spell)
vars_removed.push_back(var->usr);
} else {
if (!var->declarations.empty())
vars_declarations.push_back(QueryVar::DeclarationsUpdate(
previous_id_map.ToQuery(var->id), {},
previous_id_map.ToQuery(var->declarations)));
if (!var->uses.empty())
vars_uses.push_back(
QueryVar::UsesUpdate(previous_id_map.ToQuery(var->id), {},
previous_id_map.ToQuery(var->uses)));
}
if (!var->declarations.empty())
vars_declarations.push_back(QueryVar::DeclarationsUpdate(
previous_id_map.ToQuery(var->id), {},
previous_id_map.ToQuery(var->declarations)));
if (!var->uses.empty())
vars_uses.push_back(
QueryVar::UsesUpdate(previous_id_map.ToQuery(var->id), {},
previous_id_map.ToQuery(var->uses)));
},
/*onAdded:*/
[this, &current_id_map](IndexVar* var) {
Expand Down Expand Up @@ -1225,7 +1219,6 @@ TEST_SUITE("query") {
db.ApplyIndexUpdate(&delta_update);
}
REQUIRE(db.vars.size() == 1);
// FIXME/TODO: See https://github.com/cquery-project/cquery/issues/443.
// REQUIRE(db.vars[0].uses.size() == 0);
REQUIRE(db.vars[0].uses.size() == 0);
}
}

0 comments on commit 71a55ce

Please sign in to comment.