diff options
-rw-r--r-- | crates/ra_db/src/input.rs | 59 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/find_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lang_item.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 4 |
9 files changed, 37 insertions, 56 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 4069c0fed..b77640b2b 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | //! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how | 6 | //! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how |
7 | //! actual IO is done and lowered to input. | 7 | //! actual IO is done and lowered to input. |
8 | 8 | ||
9 | use std::{fmt, str::FromStr}; | 9 | use std::{fmt, ops, str::FromStr}; |
10 | 10 | ||
11 | use ra_cfg::CfgOptions; | 11 | use ra_cfg::CfgOptions; |
12 | use ra_syntax::SmolStr; | 12 | use ra_syntax::SmolStr; |
@@ -111,8 +111,8 @@ pub struct CrateData { | |||
111 | /// This actual crate name can be different in a particular dependent crate | 111 | /// This actual crate name can be different in a particular dependent crate |
112 | /// or may even be missing for some cases, such as a dummy crate for the code snippet. | 112 | /// or may even be missing for some cases, such as a dummy crate for the code snippet. |
113 | pub display_name: Option<String>, | 113 | pub display_name: Option<String>, |
114 | cfg_options: CfgOptions, | 114 | pub cfg_options: CfgOptions, |
115 | env: Env, | 115 | pub env: Env, |
116 | pub dependencies: Vec<Dependency>, | 116 | pub dependencies: Vec<Dependency>, |
117 | } | 117 | } |
118 | 118 | ||
@@ -142,17 +142,20 @@ impl CrateGraph { | |||
142 | cfg_options: CfgOptions, | 142 | cfg_options: CfgOptions, |
143 | env: Env, | 143 | env: Env, |
144 | ) -> CrateId { | 144 | ) -> CrateId { |
145 | let data = CrateData::new(file_id, edition, display_name, cfg_options, env); | 145 | let data = CrateData { |
146 | root_file_id: file_id, | ||
147 | edition, | ||
148 | display_name, | ||
149 | cfg_options, | ||
150 | env, | ||
151 | dependencies: Vec::new(), | ||
152 | }; | ||
146 | let crate_id = CrateId(self.arena.len() as u32); | 153 | let crate_id = CrateId(self.arena.len() as u32); |
147 | let prev = self.arena.insert(crate_id, data); | 154 | let prev = self.arena.insert(crate_id, data); |
148 | assert!(prev.is_none()); | 155 | assert!(prev.is_none()); |
149 | crate_id | 156 | crate_id |
150 | } | 157 | } |
151 | 158 | ||
152 | pub fn cfg_options(&self, crate_id: CrateId) -> &CfgOptions { | ||
153 | &self.arena[&crate_id].cfg_options | ||
154 | } | ||
155 | |||
156 | pub fn add_dep( | 159 | pub fn add_dep( |
157 | &mut self, | 160 | &mut self, |
158 | from: CrateId, | 161 | from: CrateId, |
@@ -174,10 +177,6 @@ impl CrateGraph { | |||
174 | self.arena.keys().copied() | 177 | self.arena.keys().copied() |
175 | } | 178 | } |
176 | 179 | ||
177 | pub fn crate_data(&self, crate_id: &CrateId) -> &CrateData { | ||
178 | &self.arena[crate_id] | ||
179 | } | ||
180 | |||
181 | // FIXME: this only finds one crate with the given root; we could have multiple | 180 | // FIXME: this only finds one crate with the given root; we could have multiple |
182 | pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { | 181 | pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { |
183 | let (&crate_id, _) = | 182 | let (&crate_id, _) = |
@@ -207,8 +206,8 @@ impl CrateGraph { | |||
207 | return false; | 206 | return false; |
208 | } | 207 | } |
209 | 208 | ||
210 | for dep in &self.crate_data(&from).dependencies { | 209 | for dep in &self[from].dependencies { |
211 | let crate_id = dep.crate_id(); | 210 | let crate_id = dep.crate_id; |
212 | if crate_id == target { | 211 | if crate_id == target { |
213 | return true; | 212 | return true; |
214 | } | 213 | } |
@@ -221,6 +220,13 @@ impl CrateGraph { | |||
221 | } | 220 | } |
222 | } | 221 | } |
223 | 222 | ||
223 | impl ops::Index<CrateId> for CrateGraph { | ||
224 | type Output = CrateData; | ||
225 | fn index(&self, crate_id: CrateId) -> &CrateData { | ||
226 | &self.arena[&crate_id] | ||
227 | } | ||
228 | } | ||
229 | |||
224 | impl CrateId { | 230 | impl CrateId { |
225 | pub fn shift(self, amount: u32) -> CrateId { | 231 | pub fn shift(self, amount: u32) -> CrateId { |
226 | CrateId(self.0 + amount) | 232 | CrateId(self.0 + amount) |
@@ -228,23 +234,6 @@ impl CrateId { | |||
228 | } | 234 | } |
229 | 235 | ||
230 | impl CrateData { | 236 | impl CrateData { |
231 | fn new( | ||
232 | root_file_id: FileId, | ||
233 | edition: Edition, | ||
234 | display_name: Option<String>, | ||
235 | cfg_options: CfgOptions, | ||
236 | env: Env, | ||
237 | ) -> CrateData { | ||
238 | CrateData { | ||
239 | root_file_id, | ||
240 | edition, | ||
241 | display_name, | ||
242 | dependencies: Vec::new(), | ||
243 | cfg_options, | ||
244 | env, | ||
245 | } | ||
246 | } | ||
247 | |||
248 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { | 237 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { |
249 | self.dependencies.push(Dependency { name, crate_id }) | 238 | self.dependencies.push(Dependency { name, crate_id }) |
250 | } | 239 | } |
@@ -272,12 +261,6 @@ impl fmt::Display for Edition { | |||
272 | } | 261 | } |
273 | } | 262 | } |
274 | 263 | ||
275 | impl Dependency { | ||
276 | pub fn crate_id(&self) -> CrateId { | ||
277 | self.crate_id | ||
278 | } | ||
279 | } | ||
280 | |||
281 | #[derive(Debug)] | 264 | #[derive(Debug)] |
282 | pub struct ParseEditionError { | 265 | pub struct ParseEditionError { |
283 | invalid_input: String, | 266 | invalid_input: String, |
@@ -376,7 +359,7 @@ mod tests { | |||
376 | .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) | 359 | .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) |
377 | .is_ok()); | 360 | .is_ok()); |
378 | assert_eq!( | 361 | assert_eq!( |
379 | graph.crate_data(&crate1).dependencies, | 362 | graph[crate1].dependencies, |
380 | vec![Dependency { crate_id: crate2, name: "crate_name_with_dashes".into() }] | 363 | vec![Dependency { crate_id: crate2, name: "crate_name_with_dashes".into() }] |
381 | ); | 364 | ); |
382 | } | 365 | } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 78c444037..41d4e2ed3 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -54,12 +54,11 @@ pub struct CrateDependency { | |||
54 | 54 | ||
55 | impl Crate { | 55 | impl Crate { |
56 | pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> { | 56 | pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> { |
57 | db.crate_graph() | 57 | db.crate_graph()[self.id] |
58 | .crate_data(&self.id) | ||
59 | .dependencies | 58 | .dependencies |
60 | .iter() | 59 | .iter() |
61 | .map(|dep| { | 60 | .map(|dep| { |
62 | let krate = Crate { id: dep.crate_id() }; | 61 | let krate = Crate { id: dep.crate_id }; |
63 | let name = dep.as_name(); | 62 | let name = dep.as_name(); |
64 | CrateDependency { krate, name } | 63 | CrateDependency { krate, name } |
65 | }) | 64 | }) |
@@ -72,7 +71,7 @@ impl Crate { | |||
72 | crate_graph | 71 | crate_graph |
73 | .iter() | 72 | .iter() |
74 | .filter(|&krate| { | 73 | .filter(|&krate| { |
75 | crate_graph.crate_data(&krate).dependencies.iter().any(|it| it.crate_id == self.id) | 74 | crate_graph[krate].dependencies.iter().any(|it| it.crate_id == self.id) |
76 | }) | 75 | }) |
77 | .map(|id| Crate { id }) | 76 | .map(|id| Crate { id }) |
78 | .collect() | 77 | .collect() |
@@ -84,11 +83,11 @@ impl Crate { | |||
84 | } | 83 | } |
85 | 84 | ||
86 | pub fn root_file(self, db: &impl DefDatabase) -> FileId { | 85 | pub fn root_file(self, db: &impl DefDatabase) -> FileId { |
87 | db.crate_graph().crate_data(&self.id).root_file_id | 86 | db.crate_graph()[self.id].root_file_id |
88 | } | 87 | } |
89 | 88 | ||
90 | pub fn edition(self, db: &impl DefDatabase) -> Edition { | 89 | pub fn edition(self, db: &impl DefDatabase) -> Edition { |
91 | db.crate_graph().crate_data(&self.id).edition | 90 | db.crate_graph()[self.id].edition |
92 | } | 91 | } |
93 | 92 | ||
94 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { | 93 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { |
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 217e19b01..07ca74ec3 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs | |||
@@ -176,7 +176,7 @@ fn find_importable_locations( | |||
176 | // directly (only through reexports in direct dependencies). | 176 | // directly (only through reexports in direct dependencies). |
177 | for krate in Some(from.krate) | 177 | for krate in Some(from.krate) |
178 | .into_iter() | 178 | .into_iter() |
179 | .chain(crate_graph.crate_data(&from.krate).dependencies.iter().map(|dep| dep.crate_id)) | 179 | .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id)) |
180 | { | 180 | { |
181 | result.extend( | 181 | result.extend( |
182 | importable_locations_in_crate(db, item, krate) | 182 | importable_locations_in_crate(db, item, krate) |
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index 79e8d8038..6de49730e 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs | |||
@@ -116,8 +116,7 @@ impl LangItems { | |||
116 | if let Some(target) = start_crate_target { | 116 | if let Some(target) = start_crate_target { |
117 | return Some(*target); | 117 | return Some(*target); |
118 | } | 118 | } |
119 | db.crate_graph() | 119 | db.crate_graph()[start_crate] |
120 | .crate_data(&start_crate) | ||
121 | .dependencies | 120 | .dependencies |
122 | .iter() | 121 | .iter() |
123 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) | 122 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 6af0f4a8e..066b43ef9 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -179,7 +179,7 @@ impl CrateDefMap { | |||
179 | pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { | 179 | pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { |
180 | let _p = profile("crate_def_map_query"); | 180 | let _p = profile("crate_def_map_query"); |
181 | let def_map = { | 181 | let def_map = { |
182 | let edition = db.crate_graph().crate_data(&krate).edition; | 182 | let edition = db.crate_graph()[krate].edition; |
183 | let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); | 183 | let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); |
184 | let root = modules.alloc(ModuleData::default()); | 184 | let root = modules.alloc(ModuleData::default()); |
185 | CrateDefMap { | 185 | CrateDefMap { |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index e69f89b80..d0459d9b0 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -34,7 +34,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C | |||
34 | let crate_graph = db.crate_graph(); | 34 | let crate_graph = db.crate_graph(); |
35 | 35 | ||
36 | // populate external prelude | 36 | // populate external prelude |
37 | for dep in &crate_graph.crate_data(&def_map.krate).dependencies { | 37 | for dep in &crate_graph[def_map.krate].dependencies { |
38 | let dep_def_map = db.crate_def_map(dep.crate_id); | 38 | let dep_def_map = db.crate_def_map(dep.crate_id); |
39 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 39 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
40 | def_map.extern_prelude.insert( | 40 | def_map.extern_prelude.insert( |
@@ -51,7 +51,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C | |||
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | let cfg_options = crate_graph.cfg_options(def_map.krate); | 54 | let cfg_options = &crate_graph[def_map.krate].cfg_options; |
55 | 55 | ||
56 | let mut collector = DefCollector { | 56 | let mut collector = DefCollector { |
57 | db, | 57 | db, |
@@ -128,7 +128,7 @@ where | |||
128 | DB: DefDatabase, | 128 | DB: DefDatabase, |
129 | { | 129 | { |
130 | fn collect(&mut self) { | 130 | fn collect(&mut self) { |
131 | let file_id = self.db.crate_graph().crate_data(&self.def_map.krate).root_file_id; | 131 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; |
132 | let raw_items = self.db.raw_items(file_id.into()); | 132 | let raw_items = self.db.raw_items(file_id.into()); |
133 | let module_id = self.def_map.root; | 133 | let module_id = self.def_map.root; |
134 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; | 134 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; |
@@ -954,7 +954,7 @@ mod tests { | |||
954 | let krate = db.test_crate(); | 954 | let krate = db.test_crate(); |
955 | 955 | ||
956 | let def_map = { | 956 | let def_map = { |
957 | let edition = db.crate_graph().crate_data(&krate).edition; | 957 | let edition = db.crate_graph()[krate].edition; |
958 | let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); | 958 | let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); |
959 | let root = modules.alloc(ModuleData::default()); | 959 | let root = modules.alloc(ModuleData::default()); |
960 | CrateDefMap { | 960 | CrateDefMap { |
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 6c653c4f5..6e1c8e42a 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -47,7 +47,7 @@ pub(crate) fn impls_for_trait_query( | |||
47 | // will only ever get called for a few crates near the root of the tree (the | 47 | // will only ever get called for a few crates near the root of the tree (the |
48 | // ones the user is editing), so this may actually be a waste of memory. I'm | 48 | // ones the user is editing), so this may actually be a waste of memory. I'm |
49 | // doing it like this mainly for simplicity for now. | 49 | // doing it like this mainly for simplicity for now. |
50 | for dep in &db.crate_graph().crate_data(&krate).dependencies { | 50 | for dep in &db.crate_graph()[krate].dependencies { |
51 | impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); | 51 | impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); |
52 | } | 52 | } |
53 | let crate_impl_defs = db.impls_in_crate(krate); | 53 | let crate_impl_defs = db.impls_in_crate(krate); |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 8b8af35fc..25e038a55 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -121,7 +121,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> | |||
121 | 121 | ||
122 | fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { | 122 | fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { |
123 | let mod_path = def.module(db).map(|module| { | 123 | let mod_path = def.module(db).map(|module| { |
124 | once(db.crate_graph().crate_data(&module.krate().into()).display_name.clone()) | 124 | once(db.crate_graph()[module.krate().into()].display_name.clone()) |
125 | .chain( | 125 | .chain( |
126 | module | 126 | module |
127 | .path_to_root(db) | 127 | .path_to_root(db) |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 903624381..c60e86aea 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -421,12 +421,12 @@ impl Analysis { | |||
421 | 421 | ||
422 | /// Returns the edition of the given crate. | 422 | /// Returns the edition of the given crate. |
423 | pub fn crate_edition(&self, crate_id: CrateId) -> Cancelable<Edition> { | 423 | pub fn crate_edition(&self, crate_id: CrateId) -> Cancelable<Edition> { |
424 | self.with_db(|db| db.crate_graph().crate_data(&crate_id).edition) | 424 | self.with_db(|db| db.crate_graph()[crate_id].edition) |
425 | } | 425 | } |
426 | 426 | ||
427 | /// Returns the root file of the given crate. | 427 | /// Returns the root file of the given crate. |
428 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 428 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
429 | self.with_db(|db| db.crate_graph().crate_data(&crate_id).root_file_id) | 429 | self.with_db(|db| db.crate_graph()[crate_id].root_file_id) |
430 | } | 430 | } |
431 | 431 | ||
432 | /// Returns the set of possible targets to run for the current file. | 432 | /// Returns the set of possible targets to run for the current file. |