diff --git a/src/messages/cquery_base.cc b/src/messages/cquery_base.cc index 3563b453..d380230f 100644 --- a/src/messages/cquery_base.cc +++ b/src/messages/cquery_base.cc @@ -39,13 +39,13 @@ struct CqueryBaseHandler : BaseMessageHandler { if (!type.def) continue; std::vector locations = - ToQueryLocation(db, &type.def->parents); + ToQueryLocation(db, type.def->parents); out.result = GetLsLocations(db, working_files, locations); break; } else if (ref.idx.kind == SymbolKind::Func) { QueryFunc& func = db->funcs[ref.idx.idx]; std::vector locations = - ToQueryLocation(db, &func.def->base); + ToQueryLocation(db, func.def->base); out.result = GetLsLocations(db, working_files, locations); break; } diff --git a/src/messages/cquery_derived.cc b/src/messages/cquery_derived.cc index d119ee17..5019ab15 100644 --- a/src/messages/cquery_derived.cc +++ b/src/messages/cquery_derived.cc @@ -37,13 +37,13 @@ struct CqueryDerivedHandler : BaseMessageHandler { if (ref.idx.kind == SymbolKind::Type) { QueryType& type = db->types[ref.idx.idx]; std::vector locations = - ToQueryLocation(db, &type.derived); + ToQueryLocation(db, type.derived); out.result = GetLsLocations(db, working_files, locations); break; } else if (ref.idx.kind == SymbolKind::Func) { QueryFunc& func = db->funcs[ref.idx.idx]; std::vector locations = - ToQueryLocation(db, &func.derived); + ToQueryLocation(db, func.derived); out.result = GetLsLocations(db, working_files, locations); break; } diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc index f7f2aac4..05130dae 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/cquery_member_hierarchy.cc @@ -66,7 +66,7 @@ ExpandNode(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) { entry.name = var.def->ShortName(); // FIXME WithGen entry.type_id = - var.def->variable_type ? var.def->variable_type->value.id : RawId(-1); + var.def->variable_type ? var.def->variable_type->id : RawId(-1); if (var.def->definition_spelling) { optional loc = GetLsLocation(db, working_files, *var.def->definition_spelling); @@ -101,7 +101,7 @@ struct CqueryMemberHierarchyInitialHandler if (ref.idx.kind == SymbolKind::Var) { QueryVar& var = db->vars[ref.idx.idx]; if (var.def && var.def->variable_type) - out.result = BuildInitial(db, working_files, var.def->variable_type->value); + out.result = BuildInitial(db, working_files, *var.def->variable_type); break; } } diff --git a/src/messages/cquery_type_hierarchy_tree.cc b/src/messages/cquery_type_hierarchy_tree.cc index ba1a2b3b..e816a806 100644 --- a/src/messages/cquery_type_hierarchy_tree.cc +++ b/src/messages/cquery_type_hierarchy_tree.cc @@ -95,7 +95,7 @@ BuildParentInheritanceHierarchyForFunc(QueryDatabase* db, // FIXME WithGen for (auto parent_id : root_func.def->base) { - QueryFunc& parent_func = db->funcs[parent_id.value.id]; + QueryFunc& parent_func = db->funcs[parent_id.id]; if (!parent_func.def) continue; @@ -105,7 +105,7 @@ BuildParentInheritanceHierarchyForFunc(QueryDatabase* db, parent_entry.location = GetLsLocation( db, working_files, *parent_func.def->definition_spelling); parent_entry.children = - BuildParentInheritanceHierarchyForFunc(db, working_files, parent_id.value); + BuildParentInheritanceHierarchyForFunc(db, working_files, parent_id); entries.push_back(parent_entry); } @@ -141,10 +141,9 @@ BuildInheritanceHierarchyForFunc(QueryDatabase* db, entry.children.push_back(base); // Add derived. - // FIXME WithGen for (auto derived : root_func.derived) { auto derived_entry = - BuildInheritanceHierarchyForFunc(db, working_files, derived.value); + BuildInheritanceHierarchyForFunc(db, working_files, derived); if (derived_entry) entry.children.push_back(*derived_entry); } diff --git a/src/messages/cquery_vars.cc b/src/messages/cquery_vars.cc index facb9e4b..c6521b85 100644 --- a/src/messages/cquery_vars.cc +++ b/src/messages/cquery_vars.cc @@ -33,13 +33,13 @@ struct CqueryVarsHandler : BaseMessageHandler { QueryVar& var = db->vars[id]; if (!var.def || !var.def->variable_type) continue; - id = var.def->variable_type->value.id; + id = var.def->variable_type->id; } // fallthrough case SymbolKind::Type: { QueryType& type = db->types[id]; std::vector locations = - ToQueryLocation(db, &type.instances); + ToQueryLocation(db, type.instances); out.result = GetLsLocations(db, working_files, locations); break; } diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc index d7358b07..cdff4518 100644 --- a/src/messages/text_document_code_action.cc +++ b/src/messages/text_document_code_action.cc @@ -159,7 +159,7 @@ optional BuildAutoImplementForFunction(QueryDatabase* db, optional type_name; optional same_file_insert_end; if (func.def->declaring_type) { - QueryType& declaring_type = db->types[func.def->declaring_type->value.id]; + QueryType& declaring_type = db->types[func.def->declaring_type->id]; if (declaring_type.def) { type_name = std::string(declaring_type.def->ShortName()); optional ls_type_def_extent = GetLsRange( diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index e90fe4f5..3a85d4eb 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -159,10 +159,10 @@ struct TextDocumentCodeLensHandler true /*force_display*/); AddCodeLens("derived", "derived", &common, ref.loc.OffsetStartColumn(1), - ToQueryLocation(db, &type.derived), nullopt, + ToQueryLocation(db, type.derived), nullopt, false /*force_display*/); AddCodeLens("var", "vars", &common, ref.loc.OffsetStartColumn(2), - ToQueryLocation(db, &type.instances), nullopt, + ToQueryLocation(db, type.instances), nullopt, false /*force_display*/); break; } @@ -216,14 +216,14 @@ struct TextDocumentCodeLensHandler AddCodeLens("derived", "derived", &common, ref.loc.OffsetStartColumn(offset++), - ToQueryLocation(db, &func.derived), nullopt, + ToQueryLocation(db, func.derived), nullopt, false /*force_display*/); // "Base" if (func.def->base.size() == 1) { // FIXME WithGen optional base_loc = - GetDefinitionSpellingOfSymbol(db, func.def->base[0].value); + GetDefinitionSpellingOfSymbol(db, func.def->base[0]); if (base_loc) { optional ls_base = GetLsLocation(db, working_files, *base_loc); @@ -245,7 +245,7 @@ struct TextDocumentCodeLensHandler } } else { AddCodeLens("base", "base", &common, ref.loc.OffsetStartColumn(1), - ToQueryLocation(db, &func.def->base), nullopt, + ToQueryLocation(db, func.def->base), nullopt, false /*force_display*/); } diff --git a/src/messages/text_document_definition.cc b/src/messages/text_document_definition.cc index 973912c7..07d6995e 100644 --- a/src/messages/text_document_definition.cc +++ b/src/messages/text_document_definition.cc @@ -36,7 +36,7 @@ std::vector GetGotoDefinitionTargets(QueryDatabase* db, if (var.def && var.def->variable_type) { std::vector types = GetDeclarationsOfSymbolForGotoDefinition( - db, SymbolIdx(SymbolKind::Type, var.def->variable_type->value.id)); + db, SymbolIdx(SymbolKind::Type, var.def->variable_type->id)); ret.insert(ret.end(), types.begin(), types.end()); } return ret; diff --git a/src/query.cc b/src/query.cc index 4f129cc5..4e18ddfc 100644 --- a/src/query.cc +++ b/src/query.cc @@ -44,11 +44,11 @@ optional ToQuery(const IdMap& id_map, result.comments = type.comments; result.definition_spelling = id_map.ToQuery(type.definition_spelling); result.definition_extent = id_map.ToQuery(type.definition_extent); - result.alias_of = id_map.ToQuery(type.alias_of,0); - result.parents = id_map.ToQuery(type.parents,0); - result.types = id_map.ToQuery(type.types,0); - result.funcs = id_map.ToQuery(type.funcs,0); - result.vars = id_map.ToQuery(type.vars,0); + result.alias_of = id_map.ToQuery(type.alias_of); + result.parents = id_map.ToQuery(type.parents); + result.types = id_map.ToQuery(type.types); + result.funcs = id_map.ToQuery(type.funcs); + result.vars = id_map.ToQuery(type.vars); return result; } @@ -67,9 +67,9 @@ optional ToQuery(const IdMap& id_map, result.comments = func.comments; result.definition_spelling = id_map.ToQuery(func.definition_spelling); result.definition_extent = id_map.ToQuery(func.definition_extent); - result.declaring_type = id_map.ToQuery(func.declaring_type,0); - result.base = id_map.ToQuery(func.base,0); - result.locals = id_map.ToQuery(func.locals,0); + result.declaring_type = id_map.ToQuery(func.declaring_type); + result.base = id_map.ToQuery(func.base); + result.locals = id_map.ToQuery(func.locals); result.callees = id_map.ToQuery(func.callees); return result; } @@ -86,7 +86,7 @@ optional ToQuery(const IdMap& id_map, const IndexVar::Def& var) { result.comments = var.comments; result.definition_spelling = id_map.ToQuery(var.definition_spelling); result.definition_extent = id_map.ToQuery(var.definition_extent); - result.variable_type = id_map.ToQuery(var.variable_type,0); + result.variable_type = id_map.ToQuery(var.variable_type); result.parent_id = var.parent_id; result.parent_kind = var.parent_kind; result.kind = var.kind; @@ -355,64 +355,6 @@ Maybe GetQueryVarIdFromUsr(QueryDatabase* query_db, return QueryVarId(idx); } -template -void AddRangeWithGen(std::vector>* dest, const std::vector& to_add, Generation gen) { - for (auto& x : to_add) - dest->push_back(WithGen{gen, x}); -} - -template -void RemoveRangeWithGen(std::vector>* dest, const std::vector& to_remove) { - dest->erase(std::remove_if(dest->begin(), dest->end(), - [&](const WithGen& t) { - // TODO: make to_remove a set? - return std::find(to_remove.begin(), - to_remove.end(), - t.value) != to_remove.end(); - }), - dest->end()); -} - -void UpdateGen(QueryDatabase* db, WithGen& ref) { - ref.gen = db->funcs[ref.value.id].gen; -} -void UpdateGen(QueryDatabase* db, WithGen& ref) { - ref.gen = db->types[ref.value.id].gen; -} -void UpdateGen(QueryDatabase* db, WithGen& ref) { - ref.gen = db->vars[ref.value.id].gen; -} - -template -void UpdateGen(QueryDatabase* db, Maybe& ref) { - if (ref) - UpdateGen(db, *ref); -} - -template -void UpdateGen(QueryDatabase* db, std::vector& ref) { - for (T& x : ref) - UpdateGen(db, x); -} - -void UpdateGen(QueryDatabase* db, QueryFunc::Def& def) { - UpdateGen(db, def.declaring_type); - UpdateGen(db, def.base); - UpdateGen(db, def.locals); -} - -void UpdateGen(QueryDatabase* db, QueryType::Def& def) { - UpdateGen(db, def.alias_of); - UpdateGen(db, def.parents); - UpdateGen(db, def.funcs); - UpdateGen(db, def.types); - UpdateGen(db, def.vars); -} - -void UpdateGen(QueryDatabase* db, QueryVar::Def& def) { - UpdateGen(db, def.variable_type); -} - } // namespace template <> @@ -476,20 +418,6 @@ QueryVarId IdMap::ToQuery(IndexVarId id) const { assert(cached_var_ids_.find(id) != cached_var_ids_.end()); return QueryVarId(cached_var_ids_.find(id)->second); } -WithGen IdMap::ToQuery(IndexTypeId id,int) const { - assert(cached_type_ids_.find(id) != cached_type_ids_.end()); - return QueryTypeId(cached_type_ids_.find(id)->second); -} -WithGen IdMap::ToQuery(IndexFuncId id,int) const { - if (id == IndexFuncId()) - return QueryFuncId(); - assert(cached_func_ids_.find(id) != cached_func_ids_.end()); - return QueryFuncId(cached_func_ids_.find(id)->second); -} -WithGen IdMap::ToQuery(IndexVarId id,int) const { - assert(cached_var_ids_.find(id) != cached_var_ids_.end()); - return QueryVarId(cached_var_ids_.find(id)->second); -} QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const { return QueryFuncRef(ToQuery(ref.id), ToQuery(ref.loc), ref.is_implicit); } @@ -857,13 +785,6 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { RemoveRange(&def.def_var_name, merge_update.to_remove); \ VerifyUnique(def.def_var_name); \ } -#define HANDLE_MERGEABLE_WITH_GEN(update_var_name, def_var_name, storage_name) \ - for (auto merge_update : update->update_var_name) { \ - auto& def = storage_name[merge_update.id.id]; \ - AddRangeWithGen(&def.def_var_name, merge_update.to_add, def.gen); \ - RemoveRangeWithGen(&def.def_var_name, merge_update.to_remove); \ - VerifyUnique(def.def_var_name); \ - } for (const std::string& filename : update->files_removed) files[usr_to_file[NormalizedPath(filename)].id].def = nullopt; @@ -871,14 +792,14 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { RemoveUsrs(SymbolKind::Type, update->types_removed); ImportOrUpdate(update->types_def_update); - HANDLE_MERGEABLE_WITH_GEN(types_derived, derived, types); - HANDLE_MERGEABLE_WITH_GEN(types_instances, instances, types); + HANDLE_MERGEABLE(types_derived, derived, types); + HANDLE_MERGEABLE(types_instances, instances, types); HANDLE_MERGEABLE(types_uses, uses, types); RemoveUsrs(SymbolKind::Func, update->funcs_removed); ImportOrUpdate(update->funcs_def_update); HANDLE_MERGEABLE(funcs_declarations, declarations, funcs); - HANDLE_MERGEABLE_WITH_GEN(funcs_derived, derived, funcs); + HANDLE_MERGEABLE(funcs_derived, derived, funcs); HANDLE_MERGEABLE(funcs_callers, callers, funcs); RemoveUsrs(SymbolKind::Var, update->vars_removed); @@ -925,7 +846,6 @@ void QueryDatabase::ImportOrUpdate( UpdateSymbols(&existing.symbol_idx, SymbolKind::Type, it->second.id); } - UpdateGen(this, *existing.def); } } @@ -949,7 +869,6 @@ void QueryDatabase::ImportOrUpdate( UpdateSymbols(&existing.symbol_idx, SymbolKind::Func, it->second.id); } - UpdateGen(this, *existing.def); } } @@ -974,7 +893,6 @@ void QueryDatabase::ImportOrUpdate( UpdateSymbols(&existing.symbol_idx, SymbolKind::Var, it->second.id); } - UpdateGen(this, *existing.def); } } diff --git a/src/query.h b/src/query.h index 5805f347..8f26efab 100644 --- a/src/query.h +++ b/src/query.h @@ -249,9 +249,9 @@ MAKE_REFLECT_STRUCT(QueryFile::Def, dependencies); struct QueryType { - using Def = TypeDefDefinitionData, - WithGen, - WithGen, + using Def = TypeDefDefinitionData; using DefUpdate = WithUsr; using DerivedUpdate = MergeableUpdate; @@ -262,17 +262,17 @@ struct QueryType { Generation gen; Maybe> symbol_idx; optional def; - std::vector> derived; - std::vector> instances; + std::vector derived; + std::vector instances; std::vector uses; explicit QueryType(const Usr& usr) : usr(usr), gen(0) {} }; struct QueryFunc { - using Def = FuncDefDefinitionData, - WithGen, - WithGen, + using Def = FuncDefDefinitionData; using DefUpdate = WithUsr; @@ -285,16 +285,16 @@ struct QueryFunc { Maybe> symbol_idx; optional def; std::vector declarations; - std::vector> derived; + std::vector derived; std::vector callers; explicit QueryFunc(const Usr& usr) : usr(usr), gen(0) {} }; struct QueryVar { - using Def = VarDefDefinitionData, - WithGen, - WithGen, + using Def = VarDefDefinitionData; using DefUpdate = WithUsr; using DeclarationsUpdate = MergeableUpdate; @@ -452,9 +452,6 @@ struct IdMap { QueryTypeId ToQuery(IndexTypeId id) const; QueryFuncId ToQuery(IndexFuncId id) const; QueryVarId ToQuery(IndexVarId id) const; - WithGen ToQuery(IndexTypeId id, int) const; - WithGen ToQuery(IndexFuncId id, int) const; - WithGen ToQuery(IndexVarId id, int) const; QueryFuncRef ToQuery(IndexFuncRef ref) const; QueryLocation ToQuery(IndexFunc::Declaration decl) const; template diff --git a/src/query_utils.cc b/src/query_utils.cc index 3b59f735..5762bef2 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -14,25 +14,16 @@ int ComputeRangeSize(const Range& range) { } template -std::vector ToQueryLocation( +std::vector ToQueryLocationHelper( QueryDatabase* db, - std::vector QueryDatabase::*collection, - std::vector>>* ids_) { - auto& ids = *ids_; + const std::vector>& ids) { std::vector locs; locs.reserve(ids.size()); - size_t j = 0; - for (size_t i = 0; i < ids.size(); i++) { - Q& obj = (db->*collection)[ids[i].value.id]; - if (obj.gen == ids[i].gen) { - optional loc = - GetDefinitionSpellingOfSymbol(db, ids[i].value); - if (loc) - locs.push_back(*loc); - ids[j++] = ids[i]; - } + for (auto id : ids) { + optional loc = GetDefinitionSpellingOfSymbol(db, id); + if (loc) + locs.push_back(*loc); } - ids.resize(j); return locs; } @@ -171,42 +162,17 @@ std::vector ToQueryLocation( std::vector ToQueryLocation( QueryDatabase* db, const std::vector& ids) { - std::vector locs; - locs.reserve(ids.size()); - for (const QueryTypeId& id : ids) { - optional loc = GetDefinitionSpellingOfSymbol(db, id); - if (loc) - locs.push_back(loc.value()); - } - return locs; + return ToQueryLocationHelper(db, ids); } std::vector ToQueryLocation( QueryDatabase* db, const std::vector& ids) { - std::vector locs; - locs.reserve(ids.size()); - for (const QueryFuncId& id : ids) { - optional loc = GetDefinitionSpellingOfSymbol(db, id); - if (loc) - locs.push_back(loc.value()); - } - return locs; -} - -std::vector ToQueryLocation( - QueryDatabase* db, - std::vector>* ids_) { - return ToQueryLocation(db, &QueryDatabase::funcs, ids_); + return ToQueryLocationHelper(db, ids); } std::vector ToQueryLocation( QueryDatabase* db, - std::vector>* ids_) { - return ToQueryLocation(db, &QueryDatabase::types, ids_); -} -std::vector ToQueryLocation( - QueryDatabase* db, - std::vector>* ids_) { - return ToQueryLocation(db, &QueryDatabase::vars, ids_); + const std::vector& ids) { + return ToQueryLocationHelper(db, ids); } std::vector GetUsesOfSymbol(QueryDatabase* db, @@ -514,8 +480,7 @@ optional GetSymbolInfo(QueryDatabase* db, info.kind = lsSymbolKind::Function; if (func.def->declaring_type.has_value()) { - // FIXME WithGen - QueryType& container = db->types[func.def->declaring_type->value.id]; + QueryType& container = db->types[func.def->declaring_type->id]; if (container.def) info.kind = lsSymbolKind::Method; } diff --git a/src/query_utils.h b/src/query_utils.h index 309ed6a4..7a06fd14 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -25,12 +25,9 @@ std::vector ToQueryLocation( std::vector ToQueryLocation( QueryDatabase* db, const std::vector& refs); -std::vector ToQueryLocation(QueryDatabase* db, - std::vector>*); -std::vector ToQueryLocation(QueryDatabase* db, - std::vector>*); -std::vector ToQueryLocation(QueryDatabase* db, - std::vector>*); +std::vector ToQueryLocation( + QueryDatabase* db, + const std::vector& refs); std::vector ToQueryLocation(QueryDatabase* db, const std::vector& ids); std::vector GetUsesOfSymbol(QueryDatabase* db, @@ -74,8 +71,8 @@ void EmitDiagnostics(WorkingFiles* working_files, std::vector diagnostics); template -void EachWithGen(std::vector& collection, WithGen> x, Fn fn) { - Q& obj = collection[x.value.id]; +void EachWithGen(std::vector& collection, Id x, Fn fn) { + Q& obj = collection[x.id]; // FIXME Deprecate optional def // if (obj.gen == x.gen && obj.def) if (obj.def) @@ -83,15 +80,10 @@ void EachWithGen(std::vector& collection, WithGen> x, Fn fn) { } template -void EachWithGen(std::vector& collection, std::vector>>& ids, Fn fn) { - size_t j = 0; - for (WithGen> x : ids) { - Q& obj = collection[x.value.id]; - if (1 /*obj.gen == x.gen*/) { - if (obj.def) // FIXME Deprecate optional def - fn(obj); - ids[j++] = x; - } +void EachWithGen(std::vector& collection, std::vector>& ids, Fn fn) { + for (Id x : ids) { + Q& obj = collection[x.id]; + if (obj.def) // FIXME Deprecate optional def + fn(obj); } - ids.resize(j); }