Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 0a9b670

Browse files
committed
Generation
1 parent 3fa262f commit 0a9b670

File tree

3 files changed

+70
-36
lines changed

3 files changed

+70
-36
lines changed

src/query.cc

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,46 @@ void RemoveRangeWithGen(std::vector<WithGen<T>>* dest, const std::vector<T>& to_
373373
dest->end());
374374
}
375375

376+
void UpdateGen(QueryDatabase* db, WithGen<QueryFuncId>& ref) {
377+
ref.gen = db->funcs[ref.value.id].gen;
378+
}
379+
void UpdateGen(QueryDatabase* db, WithGen<QueryTypeId>& ref) {
380+
ref.gen = db->types[ref.value.id].gen;
381+
}
382+
void UpdateGen(QueryDatabase* db, WithGen<QueryVarId>& ref) {
383+
ref.gen = db->vars[ref.value.id].gen;
384+
}
385+
386+
template <typename T>
387+
void UpdateGen(QueryDatabase* db, Maybe<T>& ref) {
388+
if (ref)
389+
UpdateGen(db, *ref);
390+
}
391+
392+
template <typename T>
393+
void UpdateGen(QueryDatabase* db, std::vector<T>& ref) {
394+
for (T& x : ref)
395+
UpdateGen(db, x);
396+
}
397+
398+
void UpdateGen(QueryDatabase* db, QueryFunc::Def& def) {
399+
UpdateGen(db, def.declaring_type);
400+
UpdateGen(db, def.base);
401+
UpdateGen(db, def.locals);
402+
}
403+
404+
void UpdateGen(QueryDatabase* db, QueryType::Def& def) {
405+
UpdateGen(db, def.alias_of);
406+
UpdateGen(db, def.parents);
407+
UpdateGen(db, def.funcs);
408+
UpdateGen(db, def.types);
409+
UpdateGen(db, def.vars);
410+
}
411+
412+
void UpdateGen(QueryDatabase* db, QueryVar::Def& def) {
413+
UpdateGen(db, def.variable_type);
414+
}
415+
376416
} // namespace
377417

378418
template <>
@@ -769,6 +809,7 @@ void QueryDatabase::RemoveUsrs(SymbolKind usr_kind,
769809
if (type.symbol_idx)
770810
symbols[type.symbol_idx->id].kind = SymbolKind::Invalid;
771811
type.gen++;
812+
//type.def = QueryType::Def();
772813
type.def = nullopt;
773814
}
774815
break;
@@ -779,6 +820,7 @@ void QueryDatabase::RemoveUsrs(SymbolKind usr_kind,
779820
if (func.symbol_idx)
780821
symbols[func.symbol_idx->id].kind = SymbolKind::Invalid;
781822
func.gen++;
823+
//func.def = QueryFunc::Def();
782824
func.def = nullopt;
783825
}
784826
break;
@@ -789,6 +831,7 @@ void QueryDatabase::RemoveUsrs(SymbolKind usr_kind,
789831
if (var.symbol_idx)
790832
symbols[var.symbol_idx->id].kind = SymbolKind::Invalid;
791833
var.gen++;
834+
//var.def = QueryVar::Def();
792835
var.def = nullopt;
793836
}
794837
break;
@@ -820,6 +863,7 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) {
820863
AddRangeWithGen(&def.def_var_name, merge_update.to_add, def.gen); \
821864
RemoveRangeWithGen(&def.def_var_name, merge_update.to_remove); \
822865
VerifyUnique(def.def_var_name); \
866+
UpdateGen(this, def.def_var_name); \
823867
}
824868

825869
for (const std::string& filename : update->files_removed)
@@ -876,13 +920,13 @@ void QueryDatabase::ImportOrUpdate(
876920
QueryType& existing = types[it->second.id];
877921

878922
// Keep the existing definition if it is higher quality.
879-
if (existing.def && existing.def->definition_spelling &&
880-
!def.value.definition_spelling)
881-
continue;
882-
883-
existing.def = def.value;
884-
UpdateSymbols(&existing.symbol_idx, SymbolKind::Type,
885-
it->second.id);
923+
if (!(existing.def && existing.def->definition_spelling &&
924+
!def.value.definition_spelling)) {
925+
existing.def = def.value;
926+
UpdateSymbols(&existing.symbol_idx, SymbolKind::Type,
927+
it->second.id);
928+
}
929+
UpdateGen(this, *existing.def);
886930
}
887931
}
888932

@@ -900,13 +944,13 @@ void QueryDatabase::ImportOrUpdate(
900944
QueryFunc& existing = funcs[it->second.id];
901945

902946
// Keep the existing definition if it is higher quality.
903-
if (existing.def && existing.def->definition_spelling &&
904-
!def.value.definition_spelling)
905-
continue;
906-
907-
existing.def = def.value;
908-
UpdateSymbols(&existing.symbol_idx, SymbolKind::Func,
909-
it->second.id);
947+
if (!(existing.def && existing.def->definition_spelling &&
948+
!def.value.definition_spelling)) {
949+
existing.def = def.value;
950+
UpdateSymbols(&existing.symbol_idx, SymbolKind::Func,
951+
it->second.id);
952+
}
953+
UpdateGen(this, *existing.def);
910954
}
911955
}
912956

@@ -924,14 +968,14 @@ void QueryDatabase::ImportOrUpdate(
924968
QueryVar& existing = vars[it->second.id];
925969

926970
// Keep the existing definition if it is higher quality.
927-
if (existing.def && existing.def->definition_spelling &&
928-
!def.value.definition_spelling)
929-
continue;
930-
931-
existing.def = def.value;
932-
if (!def.value.is_local())
933-
UpdateSymbols(&existing.symbol_idx, SymbolKind::Var,
934-
it->second.id);
971+
if (!(existing.def && existing.def->definition_spelling &&
972+
!def.value.definition_spelling)) {
973+
existing.def = def.value;
974+
if (!def.value.is_local())
975+
UpdateSymbols(&existing.symbol_idx, SymbolKind::Var,
976+
it->second.id);
977+
}
978+
UpdateGen(this, *existing.def);
935979
}
936980
}
937981

@@ -994,6 +1038,7 @@ std::string_view QueryDatabase::GetSymbolShortName(RawId symbol_idx) const {
9941038
return "";
9951039
}
9961040

1041+
9971042
TEST_SUITE("query") {
9981043
IndexUpdate GetDelta(IndexFile previous, IndexFile current) {
9991044
QueryDatabase db;

src/query.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,18 +478,6 @@ struct IdMap {
478478
QueryFuncRef ToQuery(IndexFuncRef ref) const;
479479
QueryLocation ToQuery(IndexFunc::Declaration decl) const;
480480
template <typename I>
481-
optional<typename IndexToQuery<I>::type> ToQuery(optional<I> id) const {
482-
if (!id)
483-
return nullopt;
484-
return ToQuery(*id);
485-
}
486-
template <typename I>
487-
optional<WithGen<typename IndexToQuery<I>::type>> ToQuery(optional<I> id, int) const {
488-
if (!id)
489-
return nullopt;
490-
return ToQuery(*id, 0);
491-
}
492-
template <typename I>
493481
Maybe<typename IndexToQuery<I>::type> ToQuery(Maybe<I> id) const {
494482
if (!id)
495483
return nullopt;

src/query_utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ template <typename Q>
7777
void EachWithGen(std::vector<Q>& collection, WithGen<Id<Q>> x, std::function<void(Q&)> fn) {
7878
Q& obj = collection[x.value.id];
7979
// FIXME Deprecate optional<Def> def
80-
if (obj.gen == x.gen && obj.def)
80+
// if (obj.gen == x.gen && obj.def)
81+
if (obj.def)
8182
fn(obj);
8283
}
8384

@@ -86,7 +87,7 @@ void EachWithGen(std::vector<Q>& collection, std::vector<WithGen<Id<Q>>>& ids, s
8687
size_t j = 0;
8788
for (WithGen<Id<Q>> x : ids) {
8889
Q& obj = collection[x.value.id];
89-
if (obj.gen == x.gen) {
90+
if (1 /*obj.gen == x.gen*/) {
9091
if (obj.def) // FIXME Deprecate optional<Def> def
9192
fn(obj);
9293
ids[j++] = x;

0 commit comments

Comments
 (0)