From b885e6bdeeb1023df53b3f292cfe301448eeaeef Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 9 Mar 2021 19:09:02 +0100 Subject: Delete `ContainerId` --- crates/hir_def/src/adt.rs | 21 +++++++------- crates/hir_def/src/attr.rs | 2 +- crates/hir_def/src/data.rs | 4 +-- crates/hir_def/src/lib.rs | 50 +++++++++++---------------------- crates/hir_def/src/nameres/collector.rs | 23 ++++++++------- crates/hir_def/src/resolver.rs | 17 +++-------- 6 files changed, 45 insertions(+), 72 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs index ed36c3109..efbde17d8 100644 --- a/crates/hir_def/src/adt.rs +++ b/crates/hir_def/src/adt.rs @@ -21,8 +21,7 @@ use crate::{ trace::Trace, type_ref::TypeRef, visibility::RawVisibility, - EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, - VariantId, + EnumId, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, }; use cfg::CfgOptions; @@ -92,10 +91,10 @@ fn parse_repr_tt(tt: &Subtree) -> Option { impl StructData { pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc { let loc = id.lookup(db); - let krate = loc.container.module(db).krate; + let krate = loc.container.krate; let item_tree = db.item_tree(loc.id.file_id); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); let strukt = &item_tree[loc.id.value]; let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &strukt.fields, None); @@ -107,10 +106,10 @@ impl StructData { } pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc { let loc = id.lookup(db); - let krate = loc.container.module(db).krate; + let krate = loc.container.krate; let item_tree = db.item_tree(loc.id.file_id); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); let union = &item_tree[loc.id.value]; let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &union.fields, None); @@ -126,7 +125,7 @@ impl StructData { impl EnumData { pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc { let loc = e.lookup(db); - let krate = loc.container.module(db).krate; + let krate = loc.container.krate; let item_tree = db.item_tree(loc.id.file_id); let cfg_options = db.crate_graph()[krate].cfg_options.clone(); @@ -168,7 +167,7 @@ impl HasChildSource for EnumId { ) -> InFile> { let src = self.lookup(db).source(db); let mut trace = Trace::new_for_map(); - lower_enum(db, &mut trace, &src, self.lookup(db).container.module(db)); + lower_enum(db, &mut trace, &src, self.lookup(db).container); src.with_value(trace.into_map()) } } @@ -238,10 +237,10 @@ impl HasChildSource for VariantId { // I don't really like the fact that we call into parent source // here, this might add to more queries then necessary. let src = it.parent.child_source(db); - (src.map(|map| map[it.local_id].kind()), it.parent.lookup(db).container.module(db)) + (src.map(|map| map[it.local_id].kind()), it.parent.lookup(db).container) } VariantId::StructId(it) => { - (it.lookup(db).source(db).map(|it| it.kind()), it.lookup(db).container.module(db)) + (it.lookup(db).source(db).map(|it| it.kind()), it.lookup(db).container) } VariantId::UnionId(it) => ( it.lookup(db).source(db).map(|it| { @@ -249,7 +248,7 @@ impl HasChildSource for VariantId { .map(ast::StructKind::Record) .unwrap_or(ast::StructKind::Unit) }), - it.lookup(db).container.module(db), + it.lookup(db).container, ), }; let mut expander = CfgExpander::new(db, src.file_id, module_id.krate); diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index b716d5f6e..97cdbbb9e 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -267,7 +267,7 @@ impl Attrs { db: &dyn DefDatabase, e: EnumId, ) -> Arc> { - let krate = e.lookup(db).container.module(db).krate; + let krate = e.lookup(db).container.krate; let src = e.child_source(db); let mut res = ArenaMap::default(); diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index d3380e0f4..aea53d527 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -97,7 +97,7 @@ impl TraitData { let tr_def = &item_tree[tr_loc.id.value]; let name = tr_def.name.clone(); let auto = tr_def.auto; - let module_id = tr_loc.container.module(db); + let module_id = tr_loc.container; let container = AssocContainerId::TraitId(tr); let mut expander = Expander::new(db, tr_loc.id.file_id, module_id); @@ -147,7 +147,7 @@ impl ImplData { let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone()); let target_type = item_tree[impl_def.target_type].clone(); let is_negative = impl_def.is_negative; - let module_id = impl_loc.container.module(db); + let module_id = impl_loc.container; let container = AssocContainerId::ImplId(id); let mut expander = Expander::new(db, impl_loc.id.file_id, module_id); diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index ab3b17f6c..6d11c5be4 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs @@ -108,7 +108,7 @@ pub type LocalModuleId = Idx; #[derive(Debug)] pub struct ItemLoc { - pub container: ContainerId, + pub container: ModuleId, pub id: ItemTreeId, } @@ -278,12 +278,6 @@ pub struct ConstParamId { } pub type LocalConstParamId = Idx; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum ContainerId { - ModuleId(ModuleId), - DefWithBodyId(DefWithBodyId), -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum AssocContainerId { ModuleId(ModuleId), @@ -447,21 +441,12 @@ pub trait HasModule { fn module(&self, db: &dyn db::DefDatabase) -> ModuleId; } -impl HasModule for ContainerId { - fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { - match *self { - ContainerId::ModuleId(it) => it, - ContainerId::DefWithBodyId(it) => it.module(db), - } - } -} - impl HasModule for AssocContainerId { fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { match *self { AssocContainerId::ModuleId(it) => it, - AssocContainerId::ImplId(it) => it.lookup(db).container.module(db), - AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), + AssocContainerId::ImplId(it) => it.lookup(db).container, + AssocContainerId::TraitId(it) => it.lookup(db).container, } } } @@ -479,16 +464,15 @@ impl HasModule for AdtId { AdtId::UnionId(it) => it.lookup(db).container, AdtId::EnumId(it) => it.lookup(db).container, } - .module(db) } } impl HasModule for VariantId { fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { match self { - VariantId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), - VariantId::StructId(it) => it.lookup(db).container.module(db), - VariantId::UnionId(it) => it.lookup(db).container.module(db), + VariantId::EnumVariantId(it) => it.parent.lookup(db).container, + VariantId::StructId(it) => it.lookup(db).container, + VariantId::UnionId(it) => it.lookup(db).container, } } } @@ -518,18 +502,18 @@ impl HasModule for GenericDefId { match self { GenericDefId::FunctionId(it) => it.lookup(db).module(db), GenericDefId::AdtId(it) => it.module(db), - GenericDefId::TraitId(it) => it.lookup(db).container.module(db), + GenericDefId::TraitId(it) => it.lookup(db).container, GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), - GenericDefId::ImplId(it) => it.lookup(db).container.module(db), - GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), + GenericDefId::ImplId(it) => it.lookup(db).container, + GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, GenericDefId::ConstId(it) => it.lookup(db).module(db), } } } impl HasModule for StaticLoc { - fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { - self.container.module(db) + fn module(&self, _db: &dyn db::DefDatabase) -> ModuleId { + self.container } } @@ -542,10 +526,10 @@ impl ModuleDefId { ModuleDefId::ModuleId(id) => *id, ModuleDefId::FunctionId(id) => id.lookup(db).module(db), ModuleDefId::AdtId(id) => id.module(db), - ModuleDefId::EnumVariantId(id) => id.parent.lookup(db).container.module(db), + ModuleDefId::EnumVariantId(id) => id.parent.lookup(db).container, ModuleDefId::ConstId(id) => id.lookup(db).container.module(db), - ModuleDefId::StaticId(id) => id.lookup(db).container.module(db), - ModuleDefId::TraitId(id) => id.lookup(db).container.module(db), + ModuleDefId::StaticId(id) => id.lookup(db).container, + ModuleDefId::TraitId(id) => id.lookup(db).container, ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db), ModuleDefId::BuiltinType(_) => return None, }) @@ -559,12 +543,12 @@ impl AttrDefId { AttrDefId::FieldId(it) => it.parent.module(db).krate, AttrDefId::AdtId(it) => it.module(db).krate, AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate, - AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db).krate, + AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.krate, AttrDefId::StaticId(it) => it.lookup(db).module(db).krate, AttrDefId::ConstId(it) => it.lookup(db).module(db).krate, - AttrDefId::TraitId(it) => it.lookup(db).container.module(db).krate, + AttrDefId::TraitId(it) => it.lookup(db).container.krate, AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate, - AttrDefId::ImplId(it) => it.lookup(db).container.module(db).krate, + AttrDefId::ImplId(it) => it.lookup(db).container.krate, AttrDefId::GenericParamId(it) => { match it { GenericParamId::TypeParamId(it) => it.parent, diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 5bf2ba721..9ed48c506 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -37,9 +37,9 @@ use crate::{ path::{ImportAlias, ModPath, PathKind}, per_ns::PerNs, visibility::{RawVisibility, Visibility}, - AdtId, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, - ImplLoc, Intern, LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, - UnionLoc, UnresolvedMacro, + AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, + LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, + UnresolvedMacro, }; const GLOB_RECURSION_LIMIT: usize = 100; @@ -1042,7 +1042,6 @@ impl ModCollector<'_, '_> { } } let module = self.def_collector.def_map.module_id(self.module_id); - let container = ContainerId::ModuleId(module); let mut def = None; match item { @@ -1109,9 +1108,9 @@ impl ModCollector<'_, '_> { } ModItem::Impl(imp) => { let module = self.def_collector.def_map.module_id(self.module_id); - let container = ContainerId::ModuleId(module); - let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } - .intern(self.def_collector.db); + let impl_id = + ImplLoc { container: module, id: ItemTreeId::new(self.file_id, imp) } + .intern(self.def_collector.db); self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id) } ModItem::Function(id) => { @@ -1140,7 +1139,7 @@ impl ModCollector<'_, '_> { self.collect_derives(&attrs, it.ast_id.upcast()); def = Some(DefData { - id: StructLoc { container, id: ItemTreeId::new(self.file_id, id) } + id: StructLoc { container: module, id: ItemTreeId::new(self.file_id, id) } .intern(self.def_collector.db) .into(), name: &it.name, @@ -1157,7 +1156,7 @@ impl ModCollector<'_, '_> { self.collect_derives(&attrs, it.ast_id.upcast()); def = Some(DefData { - id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) } + id: UnionLoc { container: module, id: ItemTreeId::new(self.file_id, id) } .intern(self.def_collector.db) .into(), name: &it.name, @@ -1174,7 +1173,7 @@ impl ModCollector<'_, '_> { self.collect_derives(&attrs, it.ast_id.upcast()); def = Some(DefData { - id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) } + id: EnumLoc { container: module, id: ItemTreeId::new(self.file_id, id) } .intern(self.def_collector.db) .into(), name: &it.name, @@ -1203,7 +1202,7 @@ impl ModCollector<'_, '_> { let it = &self.item_tree[id]; def = Some(DefData { - id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) } + id: StaticLoc { container: module, id: ItemTreeId::new(self.file_id, id) } .intern(self.def_collector.db) .into(), name: &it.name, @@ -1215,7 +1214,7 @@ impl ModCollector<'_, '_> { let it = &self.item_tree[id]; def = Some(DefData { - id: TraitLoc { container, id: ItemTreeId::new(self.file_id, id) } + id: TraitLoc { container: module, id: ItemTreeId::new(self.file_id, id) } .intern(self.def_collector.db) .into(), name: &it.name, diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 6f036c8c4..42736171e 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -19,10 +19,10 @@ use crate::{ path::{ModPath, PathKind}, per_ns::PerNs, visibility::{RawVisibility, Visibility}, - AdtId, AssocContainerId, ConstId, ConstParamId, ContainerId, DefWithBodyId, EnumId, - EnumVariantId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, - LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, - TypeParamId, VariantId, + AdtId, AssocContainerId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, + FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, LocalModuleId, + Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, + VariantId, }; #[derive(Debug, Clone, Default)] @@ -688,15 +688,6 @@ impl HasResolver for DefWithBodyId { } } -impl HasResolver for ContainerId { - fn resolver(self, db: &dyn DefDatabase) -> Resolver { - match self { - ContainerId::ModuleId(it) => it.resolver(db), - ContainerId::DefWithBodyId(it) => it.module(db).resolver(db), - } - } -} - impl HasResolver for AssocContainerId { fn resolver(self, db: &dyn DefDatabase) -> Resolver { match self { -- cgit v1.2.3