diff options
author | Aleksey Kladov <[email protected]> | 2019-01-23 20:14:13 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-24 10:29:19 +0000 |
commit | 3ab1519cb27b927074ed7fbbb18a856e6e7fabb8 (patch) | |
tree | 692c7a256604e188d38890966290bd1637d7dd60 /crates/ra_hir/src/impl_block.rs | |
parent | cfb085ded8d61d7b744d0a83ecbb3da254f6ab9f (diff) |
Change ids strategy
this is a part of larghish hir refactoring which aims to
* replace per-source-root module trees with per crate trees
* switch from a monotyped DedId to type-specific ids
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 551d0d149..ba8b84da2 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -3,14 +3,12 @@ use rustc_hash::FxHashMap; | |||
3 | 3 | ||
4 | use ra_arena::{Arena, RawId, impl_arena_id}; | 4 | use ra_arena::{Arena, RawId, impl_arena_id}; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast::{self, AstNode}; |
6 | use ra_db::{SourceRootId}; | ||
7 | 6 | ||
8 | use crate::{ | 7 | use crate::{ |
9 | DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, | 8 | DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, |
10 | Function, HirInterner, | 9 | Function, HirFileId, HirInterner, |
11 | db::HirDatabase, | 10 | db::HirDatabase, |
12 | type_ref::TypeRef, | 11 | type_ref::TypeRef, |
13 | module_tree::ModuleId, | ||
14 | }; | 12 | }; |
15 | 13 | ||
16 | use crate::code_model_api::{Module, ModuleSource}; | 14 | use crate::code_model_api::{Module, ModuleSource}; |
@@ -67,13 +65,13 @@ pub struct ImplData { | |||
67 | impl ImplData { | 65 | impl ImplData { |
68 | pub(crate) fn from_ast( | 66 | pub(crate) fn from_ast( |
69 | db: &impl AsRef<HirInterner>, | 67 | db: &impl AsRef<HirInterner>, |
68 | file_id: HirFileId, | ||
70 | file_items: &SourceFileItems, | 69 | file_items: &SourceFileItems, |
71 | module: &Module, | 70 | module: Module, |
72 | node: &ast::ImplBlock, | 71 | node: &ast::ImplBlock, |
73 | ) -> Self { | 72 | ) -> Self { |
74 | let target_trait = node.target_trait().map(TypeRef::from_ast); | 73 | let target_trait = node.target_trait().map(TypeRef::from_ast); |
75 | let target_type = TypeRef::from_ast_opt(node.target_type()); | 74 | let target_type = TypeRef::from_ast_opt(node.target_type()); |
76 | let module_loc = module.def_id.loc(db); | ||
77 | let items = if let Some(item_list) = node.item_list() { | 75 | let items = if let Some(item_list) = node.item_list() { |
78 | item_list | 76 | item_list |
79 | .impl_items() | 77 | .impl_items() |
@@ -85,13 +83,13 @@ impl ImplData { | |||
85 | }; | 83 | }; |
86 | let item_id = file_items.id_of_unchecked(item_node.syntax()); | 84 | let item_id = file_items.id_of_unchecked(item_node.syntax()); |
87 | let source_item_id = SourceItemId { | 85 | let source_item_id = SourceItemId { |
88 | file_id: module_loc.source_item_id.file_id, | 86 | file_id, |
89 | item_id: Some(item_id), | 87 | item_id: Some(item_id), |
90 | }; | 88 | }; |
91 | let def_loc = DefLoc { | 89 | let def_loc = DefLoc { |
90 | module, | ||
92 | kind, | 91 | kind, |
93 | source_item_id, | 92 | source_item_id, |
94 | ..module_loc | ||
95 | }; | 93 | }; |
96 | let def_id = def_loc.id(db); | 94 | let def_id = def_loc.id(db); |
97 | match item_node.kind() { | 95 | match item_node.kind() { |
@@ -168,6 +166,7 @@ impl ModuleImplBlocks { | |||
168 | 166 | ||
169 | fn collect(&mut self, db: &impl HirDatabase, module: Module) { | 167 | fn collect(&mut self, db: &impl HirDatabase, module: Module) { |
170 | let (file_id, module_source) = module.definition_source(db); | 168 | let (file_id, module_source) = module.definition_source(db); |
169 | let file_id: HirFileId = file_id.into(); | ||
171 | let node = match &module_source { | 170 | let node = match &module_source { |
172 | ModuleSource::SourceFile(node) => node.syntax(), | 171 | ModuleSource::SourceFile(node) => node.syntax(), |
173 | ModuleSource::Module(node) => node | 172 | ModuleSource::Module(node) => node |
@@ -176,10 +175,11 @@ impl ModuleImplBlocks { | |||
176 | .syntax(), | 175 | .syntax(), |
177 | }; | 176 | }; |
178 | 177 | ||
179 | let source_file_items = db.file_items(file_id.into()); | 178 | let source_file_items = db.file_items(file_id); |
180 | 179 | ||
181 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { | 180 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { |
182 | let impl_block = ImplData::from_ast(db, &source_file_items, &module, impl_block_ast); | 181 | let impl_block = |
182 | ImplData::from_ast(db, file_id, &source_file_items, module, impl_block_ast); | ||
183 | let id = self.impls.alloc(impl_block); | 183 | let id = self.impls.alloc(impl_block); |
184 | for impl_item in &self.impls[id].items { | 184 | for impl_item in &self.impls[id].items { |
185 | self.impls_by_def.insert(impl_item.def_id(), id); | 185 | self.impls_by_def.insert(impl_item.def_id(), id); |
@@ -188,13 +188,8 @@ impl ModuleImplBlocks { | |||
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | pub(crate) fn impls_in_module( | 191 | pub(crate) fn impls_in_module(db: &impl HirDatabase, module: Module) -> Arc<ModuleImplBlocks> { |
192 | db: &impl HirDatabase, | ||
193 | source_root_id: SourceRootId, | ||
194 | module_id: ModuleId, | ||
195 | ) -> Arc<ModuleImplBlocks> { | ||
196 | let mut result = ModuleImplBlocks::new(); | 192 | let mut result = ModuleImplBlocks::new(); |
197 | let module = Module::from_module_id(db, source_root_id, module_id); | ||
198 | result.collect(db, module); | 193 | result.collect(db, module); |
199 | Arc::new(result) | 194 | Arc::new(result) |
200 | } | 195 | } |