diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 3 |
3 files changed, 9 insertions, 2 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index d9bed4dda..f955dc3e6 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -6,6 +6,7 @@ authors = ["rust-analyzer developers"] | |||
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | arrayvec = "0.4.10" | 8 | arrayvec = "0.4.10" |
9 | im = "13.0.0" | ||
9 | log = "0.4.5" | 10 | log = "0.4.5" |
10 | relative-path = "0.4.0" | 11 | relative-path = "0.4.0" |
11 | rustc-hash = "1.0" | 12 | rustc-hash = "1.0" |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index befbb2a9b..7e5138d05 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -54,6 +54,7 @@ mod mod_resolution; | |||
54 | #[cfg(test)] | 54 | #[cfg(test)] |
55 | mod tests; | 55 | mod tests; |
56 | 56 | ||
57 | use std::hash::BuildHasherDefault; | ||
57 | use std::sync::Arc; | 58 | use std::sync::Arc; |
58 | 59 | ||
59 | use once_cell::sync::Lazy; | 60 | use once_cell::sync::Lazy; |
@@ -61,7 +62,7 @@ use ra_arena::{impl_arena_id, Arena, RawId}; | |||
61 | use ra_db::{Edition, FileId}; | 62 | use ra_db::{Edition, FileId}; |
62 | use ra_prof::profile; | 63 | use ra_prof::profile; |
63 | use ra_syntax::ast; | 64 | use ra_syntax::ast; |
64 | use rustc_hash::{FxHashMap, FxHashSet}; | 65 | use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; |
65 | use test_utils::tested_by; | 66 | use test_utils::tested_by; |
66 | 67 | ||
67 | use crate::{ | 68 | use crate::{ |
@@ -73,6 +74,8 @@ use crate::{ | |||
73 | AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, | 74 | AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, |
74 | }; | 75 | }; |
75 | 76 | ||
77 | pub(crate) type ImmFxHashMap<K, V> = im::HashMap<K, V, BuildHasherDefault<FxHasher>>; | ||
78 | |||
76 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; | 79 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; |
77 | 80 | ||
78 | pub use self::{ | 81 | pub use self::{ |
@@ -139,7 +142,7 @@ pub(crate) struct ModuleData { | |||
139 | pub struct ModuleScope { | 142 | pub struct ModuleScope { |
140 | items: FxHashMap<Name, Resolution>, | 143 | items: FxHashMap<Name, Resolution>, |
141 | macros: FxHashMap<Name, MacroDef>, | 144 | macros: FxHashMap<Name, MacroDef>, |
142 | textual_macros: FxHashMap<Name, MacroDef>, | 145 | textual_macros: ImmFxHashMap<Name, MacroDef>, |
143 | } | 146 | } |
144 | 147 | ||
145 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | 148 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { |
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 10c32ffa1..3803c7185 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -631,6 +631,7 @@ where | |||
631 | modules[res].parent = Some(self.module_id); | 631 | modules[res].parent = Some(self.module_id); |
632 | modules[res].declaration = Some(declaration); | 632 | modules[res].declaration = Some(declaration); |
633 | modules[res].definition = definition; | 633 | modules[res].definition = definition; |
634 | // Cloning immutable map is lazy and fast | ||
634 | modules[res].scope.textual_macros = modules[self.module_id].scope.textual_macros.clone(); | 635 | modules[res].scope.textual_macros = modules[self.module_id].scope.textual_macros.clone(); |
635 | modules[self.module_id].children.insert(name.clone(), res); | 636 | modules[self.module_id].children.insert(name.clone(), res); |
636 | let resolution = Resolution { | 637 | let resolution = Resolution { |
@@ -707,6 +708,8 @@ where | |||
707 | } | 708 | } |
708 | 709 | ||
709 | fn import_all_textual_macros(&mut self, module_id: CrateModuleId) { | 710 | fn import_all_textual_macros(&mut self, module_id: CrateModuleId) { |
711 | // `clone()` is needed here to avoid mutable borrow `self.def_collector` when first borrow is alive | ||
712 | // Cloning immutable map is lazy and fast | ||
710 | let macros = self.def_collector.def_map[module_id].scope.textual_macros.clone(); | 713 | let macros = self.def_collector.def_map[module_id].scope.textual_macros.clone(); |
711 | for (name, macro_) in macros { | 714 | for (name, macro_) in macros { |
712 | self.def_collector.define_textual_macro(self.module_id, name.clone(), macro_.id); | 715 | self.def_collector.define_textual_macro(self.module_id, name.clone(), macro_.id); |