diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-18 00:57:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-18 00:57:48 +0000 |
commit | d704750ba982153d92ccff90cf236121641b9da3 (patch) | |
tree | 01c2914d7c92a91c70282b3be19f955c83aa1431 | |
parent | 5632e61f79ff8827816ccfab9f01ce2e349f3144 (diff) | |
parent | 5fbb97a0f0b78edd8f602e46c6a336b5a1aac7ae (diff) |
Merge #8080
8080: Change ItemTree API to accomodate creating an ItemTree per block expression r=jonas-schievink a=jonas-schievink
...which won't go through salsa because the AST is already cached anyways
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
-rw-r--r-- | crates/hir/src/db.rs | 8 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/adt.rs | 6 | ||||
-rw-r--r-- | crates/hir_def/src/attr.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/data.rs | 24 | ||||
-rw-r--r-- | crates/hir_def/src/db.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/generics.rs | 14 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 44 | ||||
-rw-r--r-- | crates/hir_def/src/nameres.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 20 | ||||
-rw-r--r-- | crates/hir_def/src/src.rs | 16 | ||||
-rw-r--r-- | crates/ide_db/src/apply_change.rs | 2 |
12 files changed, 92 insertions, 52 deletions
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs index d444f4bbb..1902a8d16 100644 --- a/crates/hir/src/db.rs +++ b/crates/hir/src/db.rs | |||
@@ -3,10 +3,10 @@ | |||
3 | pub use hir_def::db::{ | 3 | pub use hir_def::db::{ |
4 | AttrsQuery, BlockDefMapQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, | 4 | AttrsQuery, BlockDefMapQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, |
5 | CrateDefMapQueryQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, | 5 | CrateDefMapQueryQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, |
6 | ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, | 6 | ExprScopesQuery, FileItemTreeQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, |
7 | InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, | 7 | ImportMapQuery, InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery, |
8 | InternImplQuery, InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, | 8 | InternFunctionQuery, InternImplQuery, InternStaticQuery, InternStructQuery, InternTraitQuery, |
9 | InternUnionQuery, ItemTreeQuery, LangItemQuery, StaticDataQuery, StructDataQuery, | 9 | InternTypeAliasQuery, InternUnionQuery, LangItemQuery, StaticDataQuery, StructDataQuery, |
10 | TraitDataQuery, TypeAliasDataQuery, UnionDataQuery, | 10 | TraitDataQuery, TypeAliasDataQuery, UnionDataQuery, |
11 | }; | 11 | }; |
12 | pub use hir_expand::db::{ | 12 | pub use hir_expand::db::{ |
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index e0eb2a66d..15651bb22 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -574,7 +574,7 @@ impl<'db> SemanticsImpl<'db> { | |||
574 | } | 574 | } |
575 | 575 | ||
576 | fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { | 576 | fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { |
577 | let file_id = self.db.lookup_intern_trait(def.id).id.file_id; | 577 | let file_id = self.db.lookup_intern_trait(def.id).id.file_id(); |
578 | let resolver = def.id.resolver(self.db.upcast()); | 578 | let resolver = def.id.resolver(self.db.upcast()); |
579 | SemanticsScope { db: self.db, file_id, resolver } | 579 | SemanticsScope { db: self.db, file_id, resolver } |
580 | } | 580 | } |
diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs index 1b9bb8235..58e35353b 100644 --- a/crates/hir_def/src/adt.rs +++ b/crates/hir_def/src/adt.rs | |||
@@ -94,7 +94,7 @@ impl StructData { | |||
94 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { | 94 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { |
95 | let loc = id.lookup(db); | 95 | let loc = id.lookup(db); |
96 | let krate = loc.container.krate; | 96 | let krate = loc.container.krate; |
97 | let item_tree = db.item_tree(loc.id.file_id); | 97 | let item_tree = loc.id.item_tree(db); |
98 | let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); | 98 | let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); |
99 | let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); | 99 | let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); |
100 | 100 | ||
@@ -110,7 +110,7 @@ impl StructData { | |||
110 | pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { | 110 | pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { |
111 | let loc = id.lookup(db); | 111 | let loc = id.lookup(db); |
112 | let krate = loc.container.krate; | 112 | let krate = loc.container.krate; |
113 | let item_tree = db.item_tree(loc.id.file_id); | 113 | let item_tree = loc.id.item_tree(db); |
114 | let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); | 114 | let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); |
115 | let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); | 115 | let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); |
116 | 116 | ||
@@ -130,7 +130,7 @@ impl EnumData { | |||
130 | pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> { | 130 | pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> { |
131 | let loc = e.lookup(db); | 131 | let loc = e.lookup(db); |
132 | let krate = loc.container.krate; | 132 | let krate = loc.container.krate; |
133 | let item_tree = db.item_tree(loc.id.file_id); | 133 | let item_tree = loc.id.item_tree(db); |
134 | let cfg_options = db.crate_graph()[krate].cfg_options.clone(); | 134 | let cfg_options = db.crate_graph()[krate].cfg_options.clone(); |
135 | 135 | ||
136 | let enum_ = &item_tree[loc.id.value]; | 136 | let enum_ = &item_tree[loc.id.value]; |
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index b7353d868..e4c84afbf 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -530,7 +530,7 @@ where | |||
530 | } | 530 | } |
531 | 531 | ||
532 | fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase) -> RawAttrs { | 532 | fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase) -> RawAttrs { |
533 | let tree = db.item_tree(id.file_id); | 533 | let tree = id.item_tree(db); |
534 | let mod_item = N::id_to_mod_item(id.value); | 534 | let mod_item = N::id_to_mod_item(id.value); |
535 | tree.raw_attrs(mod_item.into()).clone() | 535 | tree.raw_attrs(mod_item.into()).clone() |
536 | } | 536 | } |
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index fefc31129..0be868ba2 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs | |||
@@ -38,7 +38,7 @@ impl FunctionData { | |||
38 | let krate = loc.container.module(db).krate; | 38 | let krate = loc.container.module(db).krate; |
39 | let crate_graph = db.crate_graph(); | 39 | let crate_graph = db.crate_graph(); |
40 | let cfg_options = &crate_graph[krate].cfg_options; | 40 | let cfg_options = &crate_graph[krate].cfg_options; |
41 | let item_tree = db.item_tree(loc.id.file_id); | 41 | let item_tree = loc.id.item_tree(db); |
42 | let func = &item_tree[loc.id.value]; | 42 | let func = &item_tree[loc.id.value]; |
43 | 43 | ||
44 | let enabled_params = func | 44 | let enabled_params = func |
@@ -89,7 +89,7 @@ impl TypeAliasData { | |||
89 | typ: TypeAliasId, | 89 | typ: TypeAliasId, |
90 | ) -> Arc<TypeAliasData> { | 90 | ) -> Arc<TypeAliasData> { |
91 | let loc = typ.lookup(db); | 91 | let loc = typ.lookup(db); |
92 | let item_tree = db.item_tree(loc.id.file_id); | 92 | let item_tree = loc.id.item_tree(db); |
93 | let typ = &item_tree[loc.id.value]; | 93 | let typ = &item_tree[loc.id.value]; |
94 | 94 | ||
95 | Arc::new(TypeAliasData { | 95 | Arc::new(TypeAliasData { |
@@ -115,23 +115,23 @@ pub struct TraitData { | |||
115 | impl TraitData { | 115 | impl TraitData { |
116 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { | 116 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { |
117 | let tr_loc = tr.lookup(db); | 117 | let tr_loc = tr.lookup(db); |
118 | let item_tree = db.item_tree(tr_loc.id.file_id); | 118 | let item_tree = tr_loc.id.item_tree(db); |
119 | let tr_def = &item_tree[tr_loc.id.value]; | 119 | let tr_def = &item_tree[tr_loc.id.value]; |
120 | let name = tr_def.name.clone(); | 120 | let name = tr_def.name.clone(); |
121 | let is_auto = tr_def.is_auto; | 121 | let is_auto = tr_def.is_auto; |
122 | let is_unsafe = tr_def.is_unsafe; | 122 | let is_unsafe = tr_def.is_unsafe; |
123 | let module_id = tr_loc.container; | 123 | let module_id = tr_loc.container; |
124 | let container = AssocContainerId::TraitId(tr); | 124 | let container = AssocContainerId::TraitId(tr); |
125 | let mut expander = Expander::new(db, tr_loc.id.file_id, module_id); | ||
126 | let visibility = item_tree[tr_def.visibility].clone(); | 125 | let visibility = item_tree[tr_def.visibility].clone(); |
127 | let bounds = tr_def.bounds.clone(); | 126 | let bounds = tr_def.bounds.clone(); |
127 | let mut expander = Expander::new(db, tr_loc.id.file_id(), module_id); | ||
128 | 128 | ||
129 | let items = collect_items( | 129 | let items = collect_items( |
130 | db, | 130 | db, |
131 | module_id, | 131 | module_id, |
132 | &mut expander, | 132 | &mut expander, |
133 | tr_def.items.iter().copied(), | 133 | tr_def.items.iter().copied(), |
134 | tr_loc.id.file_id, | 134 | tr_loc.id.file_id(), |
135 | container, | 135 | container, |
136 | 100, | 136 | 100, |
137 | ); | 137 | ); |
@@ -167,21 +167,21 @@ impl ImplData { | |||
167 | let _p = profile::span("impl_data_query"); | 167 | let _p = profile::span("impl_data_query"); |
168 | let impl_loc = id.lookup(db); | 168 | let impl_loc = id.lookup(db); |
169 | 169 | ||
170 | let item_tree = db.item_tree(impl_loc.id.file_id); | 170 | let item_tree = impl_loc.id.item_tree(db); |
171 | let impl_def = &item_tree[impl_loc.id.value]; | 171 | let impl_def = &item_tree[impl_loc.id.value]; |
172 | let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone()); | 172 | let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone()); |
173 | let target_type = item_tree[impl_def.target_type].clone(); | 173 | let target_type = item_tree[impl_def.target_type].clone(); |
174 | let is_negative = impl_def.is_negative; | 174 | let is_negative = impl_def.is_negative; |
175 | let module_id = impl_loc.container; | 175 | let module_id = impl_loc.container; |
176 | let container = AssocContainerId::ImplId(id); | 176 | let container = AssocContainerId::ImplId(id); |
177 | let mut expander = Expander::new(db, impl_loc.id.file_id, module_id); | 177 | let mut expander = Expander::new(db, impl_loc.id.file_id(), module_id); |
178 | 178 | ||
179 | let items = collect_items( | 179 | let items = collect_items( |
180 | db, | 180 | db, |
181 | module_id, | 181 | module_id, |
182 | &mut expander, | 182 | &mut expander, |
183 | impl_def.items.iter().copied(), | 183 | impl_def.items.iter().copied(), |
184 | impl_loc.id.file_id, | 184 | impl_loc.id.file_id(), |
185 | container, | 185 | container, |
186 | 100, | 186 | 100, |
187 | ); | 187 | ); |
@@ -202,7 +202,7 @@ pub struct ConstData { | |||
202 | impl ConstData { | 202 | impl ConstData { |
203 | pub(crate) fn const_data_query(db: &dyn DefDatabase, konst: ConstId) -> Arc<ConstData> { | 203 | pub(crate) fn const_data_query(db: &dyn DefDatabase, konst: ConstId) -> Arc<ConstData> { |
204 | let loc = konst.lookup(db); | 204 | let loc = konst.lookup(db); |
205 | let item_tree = db.item_tree(loc.id.file_id); | 205 | let item_tree = loc.id.item_tree(db); |
206 | let konst = &item_tree[loc.id.value]; | 206 | let konst = &item_tree[loc.id.value]; |
207 | 207 | ||
208 | Arc::new(ConstData { | 208 | Arc::new(ConstData { |
@@ -225,7 +225,7 @@ pub struct StaticData { | |||
225 | impl StaticData { | 225 | impl StaticData { |
226 | pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<StaticData> { | 226 | pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<StaticData> { |
227 | let node = konst.lookup(db); | 227 | let node = konst.lookup(db); |
228 | let item_tree = db.item_tree(node.id.file_id); | 228 | let item_tree = node.id.item_tree(db); |
229 | let statik = &item_tree[node.id.value]; | 229 | let statik = &item_tree[node.id.value]; |
230 | 230 | ||
231 | Arc::new(StaticData { | 231 | Arc::new(StaticData { |
@@ -251,7 +251,7 @@ fn collect_items( | |||
251 | return Vec::new(); | 251 | return Vec::new(); |
252 | } | 252 | } |
253 | 253 | ||
254 | let item_tree = db.item_tree(file_id); | 254 | let item_tree = db.file_item_tree(file_id); |
255 | let crate_graph = db.crate_graph(); | 255 | let crate_graph = db.crate_graph(); |
256 | let cfg_options = &crate_graph[module.krate].cfg_options; | 256 | let cfg_options = &crate_graph[module.krate].cfg_options; |
257 | 257 | ||
@@ -292,7 +292,7 @@ fn collect_items( | |||
292 | if let Ok(res) = res { | 292 | if let Ok(res) = res { |
293 | if let Some((mark, mac)) = res.value { | 293 | if let Some((mark, mac)) = res.value { |
294 | let src: InFile<ast::MacroItems> = expander.to_source(mac); | 294 | let src: InFile<ast::MacroItems> = expander.to_source(mac); |
295 | let item_tree = db.item_tree(src.file_id); | 295 | let item_tree = db.file_item_tree(src.file_id); |
296 | let iter = | 296 | let iter = |
297 | item_tree.top_level_items().iter().filter_map(ModItem::as_assoc_item); | 297 | item_tree.top_level_items().iter().filter_map(ModItem::as_assoc_item); |
298 | items.extend(collect_items( | 298 | items.extend(collect_items( |
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index cca5a086b..276caf5b3 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs | |||
@@ -48,8 +48,8 @@ pub trait InternDatabase: SourceDatabase { | |||
48 | 48 | ||
49 | #[salsa::query_group(DefDatabaseStorage)] | 49 | #[salsa::query_group(DefDatabaseStorage)] |
50 | pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | 50 | pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { |
51 | #[salsa::invoke(ItemTree::item_tree_query)] | 51 | #[salsa::invoke(ItemTree::file_item_tree_query)] |
52 | fn item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>; | 52 | fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>; |
53 | 53 | ||
54 | #[salsa::invoke(crate_def_map_wait)] | 54 | #[salsa::invoke(crate_def_map_wait)] |
55 | #[salsa::transparent] | 55 | #[salsa::transparent] |
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index a056ab797..7c6cbff11 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs | |||
@@ -97,43 +97,43 @@ impl GenericParams { | |||
97 | let generics = match def { | 97 | let generics = match def { |
98 | GenericDefId::FunctionId(id) => { | 98 | GenericDefId::FunctionId(id) => { |
99 | let id = id.lookup(db).id; | 99 | let id = id.lookup(db).id; |
100 | let tree = db.item_tree(id.file_id); | 100 | let tree = id.item_tree(db); |
101 | let item = &tree[id.value]; | 101 | let item = &tree[id.value]; |
102 | tree[item.generic_params].clone() | 102 | tree[item.generic_params].clone() |
103 | } | 103 | } |
104 | GenericDefId::AdtId(AdtId::StructId(id)) => { | 104 | GenericDefId::AdtId(AdtId::StructId(id)) => { |
105 | let id = id.lookup(db).id; | 105 | let id = id.lookup(db).id; |
106 | let tree = db.item_tree(id.file_id); | 106 | let tree = id.item_tree(db); |
107 | let item = &tree[id.value]; | 107 | let item = &tree[id.value]; |
108 | tree[item.generic_params].clone() | 108 | tree[item.generic_params].clone() |
109 | } | 109 | } |
110 | GenericDefId::AdtId(AdtId::EnumId(id)) => { | 110 | GenericDefId::AdtId(AdtId::EnumId(id)) => { |
111 | let id = id.lookup(db).id; | 111 | let id = id.lookup(db).id; |
112 | let tree = db.item_tree(id.file_id); | 112 | let tree = id.item_tree(db); |
113 | let item = &tree[id.value]; | 113 | let item = &tree[id.value]; |
114 | tree[item.generic_params].clone() | 114 | tree[item.generic_params].clone() |
115 | } | 115 | } |
116 | GenericDefId::AdtId(AdtId::UnionId(id)) => { | 116 | GenericDefId::AdtId(AdtId::UnionId(id)) => { |
117 | let id = id.lookup(db).id; | 117 | let id = id.lookup(db).id; |
118 | let tree = db.item_tree(id.file_id); | 118 | let tree = id.item_tree(db); |
119 | let item = &tree[id.value]; | 119 | let item = &tree[id.value]; |
120 | tree[item.generic_params].clone() | 120 | tree[item.generic_params].clone() |
121 | } | 121 | } |
122 | GenericDefId::TraitId(id) => { | 122 | GenericDefId::TraitId(id) => { |
123 | let id = id.lookup(db).id; | 123 | let id = id.lookup(db).id; |
124 | let tree = db.item_tree(id.file_id); | 124 | let tree = id.item_tree(db); |
125 | let item = &tree[id.value]; | 125 | let item = &tree[id.value]; |
126 | tree[item.generic_params].clone() | 126 | tree[item.generic_params].clone() |
127 | } | 127 | } |
128 | GenericDefId::TypeAliasId(id) => { | 128 | GenericDefId::TypeAliasId(id) => { |
129 | let id = id.lookup(db).id; | 129 | let id = id.lookup(db).id; |
130 | let tree = db.item_tree(id.file_id); | 130 | let tree = id.item_tree(db); |
131 | let item = &tree[id.value]; | 131 | let item = &tree[id.value]; |
132 | tree[item.generic_params].clone() | 132 | tree[item.generic_params].clone() |
133 | } | 133 | } |
134 | GenericDefId::ImplId(id) => { | 134 | GenericDefId::ImplId(id) => { |
135 | let id = id.lookup(db).id; | 135 | let id = id.lookup(db).id; |
136 | let tree = db.item_tree(id.file_id); | 136 | let tree = id.item_tree(db); |
137 | let item = &tree[id.value]; | 137 | let item = &tree[id.value]; |
138 | tree[item.generic_params].clone() | 138 | tree[item.generic_params].clone() |
139 | } | 139 | } |
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 90df3d929..5f5b7151a 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -76,7 +76,7 @@ pub struct ItemTree { | |||
76 | } | 76 | } |
77 | 77 | ||
78 | impl ItemTree { | 78 | impl ItemTree { |
79 | pub(crate) fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> { | 79 | pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> { |
80 | let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id)); | 80 | let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id)); |
81 | let syntax = if let Some(node) = db.parse_or_expand(file_id) { | 81 | let syntax = if let Some(node) = db.parse_or_expand(file_id) { |
82 | if node.kind() == SyntaxKind::ERROR { | 82 | if node.kind() == SyntaxKind::ERROR { |
@@ -401,7 +401,47 @@ impl<N: ItemTreeNode> fmt::Debug for FileItemTreeId<N> { | |||
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | pub type ItemTreeId<N> = InFile<FileItemTreeId<N>>; | 404 | #[derive(Debug)] |
405 | pub struct ItemTreeId<N: ItemTreeNode> { | ||
406 | file: HirFileId, | ||
407 | pub value: FileItemTreeId<N>, | ||
408 | } | ||
409 | |||
410 | impl<N: ItemTreeNode> ItemTreeId<N> { | ||
411 | pub fn new(file: HirFileId, idx: FileItemTreeId<N>) -> Self { | ||
412 | Self { file, value: idx } | ||
413 | } | ||
414 | |||
415 | pub fn file_id(self) -> HirFileId { | ||
416 | self.file | ||
417 | } | ||
418 | |||
419 | pub fn item_tree(self, db: &dyn DefDatabase) -> Arc<ItemTree> { | ||
420 | db.file_item_tree(self.file) | ||
421 | } | ||
422 | } | ||
423 | |||
424 | impl<N: ItemTreeNode> Copy for ItemTreeId<N> {} | ||
425 | impl<N: ItemTreeNode> Clone for ItemTreeId<N> { | ||
426 | fn clone(&self) -> Self { | ||
427 | *self | ||
428 | } | ||
429 | } | ||
430 | |||
431 | impl<N: ItemTreeNode> PartialEq for ItemTreeId<N> { | ||
432 | fn eq(&self, other: &Self) -> bool { | ||
433 | self.file == other.file && self.value == other.value | ||
434 | } | ||
435 | } | ||
436 | |||
437 | impl<N: ItemTreeNode> Eq for ItemTreeId<N> {} | ||
438 | |||
439 | impl<N: ItemTreeNode> Hash for ItemTreeId<N> { | ||
440 | fn hash<H: Hasher>(&self, state: &mut H) { | ||
441 | self.file.hash(state); | ||
442 | self.value.hash(state); | ||
443 | } | ||
444 | } | ||
405 | 445 | ||
406 | macro_rules! mod_items { | 446 | macro_rules! mod_items { |
407 | ( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => { | 447 | ( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => { |
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 003d668ca..c97be584e 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -213,7 +213,7 @@ impl DefMap { | |||
213 | ) -> Option<Arc<DefMap>> { | 213 | ) -> Option<Arc<DefMap>> { |
214 | let block: BlockLoc = db.lookup_intern_block(block_id); | 214 | let block: BlockLoc = db.lookup_intern_block(block_id); |
215 | 215 | ||
216 | let item_tree = db.item_tree(block.ast_id.file_id); | 216 | let item_tree = db.file_item_tree(block.ast_id.file_id); |
217 | if item_tree.inner_items_of_block(block.ast_id.value).is_empty() { | 217 | if item_tree.inner_items_of_block(block.ast_id.value).is_empty() { |
218 | return None; | 218 | return None; |
219 | } | 219 | } |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index b5ae5a9e4..d0fefb5af 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -242,7 +242,7 @@ struct DefCollector<'a> { | |||
242 | impl DefCollector<'_> { | 242 | impl DefCollector<'_> { |
243 | fn seed_with_top_level(&mut self) { | 243 | fn seed_with_top_level(&mut self) { |
244 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; | 244 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; |
245 | let item_tree = self.db.item_tree(file_id.into()); | 245 | let item_tree = self.db.file_item_tree(file_id.into()); |
246 | let module_id = self.def_map.root; | 246 | let module_id = self.def_map.root; |
247 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; | 247 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; |
248 | if item_tree | 248 | if item_tree |
@@ -263,7 +263,7 @@ impl DefCollector<'_> { | |||
263 | } | 263 | } |
264 | 264 | ||
265 | fn seed_with_inner(&mut self, block: AstId<ast::BlockExpr>) { | 265 | fn seed_with_inner(&mut self, block: AstId<ast::BlockExpr>) { |
266 | let item_tree = self.db.item_tree(block.file_id); | 266 | let item_tree = self.db.file_item_tree(block.file_id); |
267 | let module_id = self.def_map.root; | 267 | let module_id = self.def_map.root; |
268 | self.def_map.modules[module_id].origin = ModuleOrigin::BlockExpr { block }; | 268 | self.def_map.modules[module_id].origin = ModuleOrigin::BlockExpr { block }; |
269 | if item_tree | 269 | if item_tree |
@@ -895,7 +895,7 @@ impl DefCollector<'_> { | |||
895 | } | 895 | } |
896 | 896 | ||
897 | // Then, fetch and process the item tree. This will reuse the expansion result from above. | 897 | // Then, fetch and process the item tree. This will reuse the expansion result from above. |
898 | let item_tree = self.db.item_tree(file_id); | 898 | let item_tree = self.db.file_item_tree(file_id); |
899 | let mod_dir = self.mod_dirs[&module_id].clone(); | 899 | let mod_dir = self.mod_dirs[&module_id].clone(); |
900 | ModCollector { | 900 | ModCollector { |
901 | def_collector: &mut *self, | 901 | def_collector: &mut *self, |
@@ -951,21 +951,21 @@ impl DefCollector<'_> { | |||
951 | let mut diagnosed_extern_crates = FxHashSet::default(); | 951 | let mut diagnosed_extern_crates = FxHashSet::default(); |
952 | for directive in &self.unresolved_imports { | 952 | for directive in &self.unresolved_imports { |
953 | if let ImportSource::ExternCrate(krate) = directive.import.source { | 953 | if let ImportSource::ExternCrate(krate) = directive.import.source { |
954 | let item_tree = self.db.item_tree(krate.file_id); | 954 | let item_tree = krate.item_tree(self.db); |
955 | let extern_crate = &item_tree[krate.value]; | 955 | let extern_crate = &item_tree[krate.value]; |
956 | 956 | ||
957 | diagnosed_extern_crates.insert(extern_crate.name.clone()); | 957 | diagnosed_extern_crates.insert(extern_crate.name.clone()); |
958 | 958 | ||
959 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_extern_crate( | 959 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_extern_crate( |
960 | directive.module_id, | 960 | directive.module_id, |
961 | InFile::new(krate.file_id, extern_crate.ast_id), | 961 | InFile::new(krate.file_id(), extern_crate.ast_id), |
962 | )); | 962 | )); |
963 | } | 963 | } |
964 | } | 964 | } |
965 | 965 | ||
966 | for directive in &self.unresolved_imports { | 966 | for directive in &self.unresolved_imports { |
967 | if let ImportSource::Import(import) = &directive.import.source { | 967 | if let ImportSource::Import(import) = &directive.import.source { |
968 | let item_tree = self.db.item_tree(import.file_id); | 968 | let item_tree = import.item_tree(self.db); |
969 | let import_data = &item_tree[import.value]; | 969 | let import_data = &item_tree[import.value]; |
970 | 970 | ||
971 | match (import_data.path.segments().first(), &import_data.path.kind) { | 971 | match (import_data.path.segments().first(), &import_data.path.kind) { |
@@ -979,7 +979,7 @@ impl DefCollector<'_> { | |||
979 | 979 | ||
980 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_import( | 980 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_import( |
981 | directive.module_id, | 981 | directive.module_id, |
982 | InFile::new(import.file_id, import_data.ast_id), | 982 | InFile::new(import.file_id(), import_data.ast_id), |
983 | import_data.index, | 983 | import_data.index, |
984 | )); | 984 | )); |
985 | } | 985 | } |
@@ -1055,7 +1055,7 @@ impl ModCollector<'_, '_> { | |||
1055 | self.def_collector.db, | 1055 | self.def_collector.db, |
1056 | krate, | 1056 | krate, |
1057 | &self.item_tree, | 1057 | &self.item_tree, |
1058 | InFile::new(self.file_id, import_id), | 1058 | ItemTreeId::new(self.file_id, import_id), |
1059 | ), | 1059 | ), |
1060 | status: PartialResolvedImport::Unresolved, | 1060 | status: PartialResolvedImport::Unresolved, |
1061 | }) | 1061 | }) |
@@ -1067,7 +1067,7 @@ impl ModCollector<'_, '_> { | |||
1067 | self.def_collector.db, | 1067 | self.def_collector.db, |
1068 | krate, | 1068 | krate, |
1069 | &self.item_tree, | 1069 | &self.item_tree, |
1070 | InFile::new(self.file_id, import_id), | 1070 | ItemTreeId::new(self.file_id, import_id), |
1071 | ), | 1071 | ), |
1072 | status: PartialResolvedImport::Unresolved, | 1072 | status: PartialResolvedImport::Unresolved, |
1073 | }) | 1073 | }) |
@@ -1299,7 +1299,7 @@ impl ModCollector<'_, '_> { | |||
1299 | Some((file_id, is_mod_rs)), | 1299 | Some((file_id, is_mod_rs)), |
1300 | &self.item_tree[module.visibility], | 1300 | &self.item_tree[module.visibility], |
1301 | ); | 1301 | ); |
1302 | let item_tree = db.item_tree(file_id.into()); | 1302 | let item_tree = db.file_item_tree(file_id.into()); |
1303 | ModCollector { | 1303 | ModCollector { |
1304 | def_collector: &mut *self.def_collector, | 1304 | def_collector: &mut *self.def_collector, |
1305 | macro_depth: self.macro_depth, | 1305 | macro_depth: self.macro_depth, |
diff --git a/crates/hir_def/src/src.rs b/crates/hir_def/src/src.rs index 751d4c052..24e57b469 100644 --- a/crates/hir_def/src/src.rs +++ b/crates/hir_def/src/src.rs | |||
@@ -14,12 +14,12 @@ impl<N: ItemTreeNode> HasSource for AssocItemLoc<N> { | |||
14 | type Value = N::Source; | 14 | type Value = N::Source; |
15 | 15 | ||
16 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { | 16 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { |
17 | let tree = db.item_tree(self.id.file_id); | 17 | let tree = self.id.item_tree(db); |
18 | let ast_id_map = db.ast_id_map(self.id.file_id); | 18 | let ast_id_map = db.ast_id_map(self.id.file_id()); |
19 | let root = db.parse_or_expand(self.id.file_id).unwrap(); | 19 | let root = db.parse_or_expand(self.id.file_id()).unwrap(); |
20 | let node = &tree[self.id.value]; | 20 | let node = &tree[self.id.value]; |
21 | 21 | ||
22 | InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) | 22 | InFile::new(self.id.file_id(), ast_id_map.get(node.ast_id()).to_node(&root)) |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
@@ -27,12 +27,12 @@ impl<N: ItemTreeNode> HasSource for ItemLoc<N> { | |||
27 | type Value = N::Source; | 27 | type Value = N::Source; |
28 | 28 | ||
29 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { | 29 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { |
30 | let tree = db.item_tree(self.id.file_id); | 30 | let tree = self.id.item_tree(db); |
31 | let ast_id_map = db.ast_id_map(self.id.file_id); | 31 | let ast_id_map = db.ast_id_map(self.id.file_id()); |
32 | let root = db.parse_or_expand(self.id.file_id).unwrap(); | 32 | let root = db.parse_or_expand(self.id.file_id()).unwrap(); |
33 | let node = &tree[self.id.value]; | 33 | let node = &tree[self.id.value]; |
34 | 34 | ||
35 | InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) | 35 | InFile::new(self.id.file_id(), ast_id_map.get(node.ast_id()).to_node(&root)) |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs index 104ee113f..9b590d919 100644 --- a/crates/ide_db/src/apply_change.rs +++ b/crates/ide_db/src/apply_change.rs | |||
@@ -148,7 +148,7 @@ impl RootDatabase { | |||
148 | hir::db::HygieneFrameQuery | 148 | hir::db::HygieneFrameQuery |
149 | 149 | ||
150 | // DefDatabase | 150 | // DefDatabase |
151 | hir::db::ItemTreeQuery | 151 | hir::db::FileItemTreeQuery |
152 | hir::db::BlockDefMapQuery | 152 | hir::db::BlockDefMapQuery |
153 | hir::db::CrateDefMapQueryQuery | 153 | hir::db::CrateDefMapQueryQuery |
154 | hir::db::StructDataQuery | 154 | hir::db::StructDataQuery |