diff options
-rw-r--r-- | Cargo.lock | 27 | ||||
-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 |
4 files changed, 36 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock index f93f11a82..7f329c4db 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -485,6 +485,16 @@ dependencies = [ | |||
485 | ] | 485 | ] |
486 | 486 | ||
487 | [[package]] | 487 | [[package]] |
488 | name = "im" | ||
489 | version = "13.0.0" | ||
490 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
491 | dependencies = [ | ||
492 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", | ||
493 | "sized-chunks 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
494 | "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
495 | ] | ||
496 | |||
497 | [[package]] | ||
488 | name = "indexmap" | 498 | name = "indexmap" |
489 | version = "1.1.0" | 499 | version = "1.1.0" |
490 | source = "registry+https://github.com/rust-lang/crates.io-index" | 500 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1006,6 +1016,7 @@ dependencies = [ | |||
1006 | "chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git)", | 1016 | "chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git)", |
1007 | "chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git)", | 1017 | "chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git)", |
1008 | "ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1018 | "ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1019 | "im 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1009 | "insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1020 | "insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1010 | "lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1021 | "lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1011 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", | 1022 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1551,6 +1562,14 @@ dependencies = [ | |||
1551 | ] | 1562 | ] |
1552 | 1563 | ||
1553 | [[package]] | 1564 | [[package]] |
1565 | name = "sized-chunks" | ||
1566 | version = "0.3.1" | ||
1567 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1568 | dependencies = [ | ||
1569 | "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1570 | ] | ||
1571 | |||
1572 | [[package]] | ||
1554 | name = "slab" | 1573 | name = "slab" |
1555 | version = "0.4.2" | 1574 | version = "0.4.2" |
1556 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1575 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1685,6 +1704,11 @@ dependencies = [ | |||
1685 | ] | 1704 | ] |
1686 | 1705 | ||
1687 | [[package]] | 1706 | [[package]] |
1707 | name = "typenum" | ||
1708 | version = "1.11.2" | ||
1709 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1710 | |||
1711 | [[package]] | ||
1688 | name = "unicase" | 1712 | name = "unicase" |
1689 | version = "2.5.1" | 1713 | version = "2.5.1" |
1690 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1714 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1893,6 +1917,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1893 | "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" | 1917 | "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" |
1894 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" | 1918 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" |
1895 | "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" | 1919 | "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" |
1920 | "checksum im 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8db49f8bc08d5cc4e2bb0f7d25a6d1db2c79bc6f7d7c86c96c657eb3d214125f" | ||
1896 | "checksum indexmap 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4d6d89e0948bf10c08b9ecc8ac5b83f07f857ebe2c0cbe38de15b4e4f510356" | 1921 | "checksum indexmap 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4d6d89e0948bf10c08b9ecc8ac5b83f07f857ebe2c0cbe38de15b4e4f510356" |
1897 | "checksum indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c60da1c9abea75996b70a931bba6c750730399005b61ccd853cee50ef3d0d0c" | 1922 | "checksum indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c60da1c9abea75996b70a931bba6c750730399005b61ccd853cee50ef3d0d0c" |
1898 | "checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" | 1923 | "checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" |
@@ -1987,6 +2012,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1987 | "checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" | 2012 | "checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" |
1988 | "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" | 2013 | "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" |
1989 | "checksum serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "38b08a9a90e5260fe01c6480ec7c811606df6d3a660415808c3c3fa8ed95b582" | 2014 | "checksum serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "38b08a9a90e5260fe01c6480ec7c811606df6d3a660415808c3c3fa8ed95b582" |
2015 | "checksum sized-chunks 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f01db57d7ee89c8e053245deb77040a6cc8508311f381c88749c33d4b9b78785" | ||
1990 | "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" | 2016 | "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" |
1991 | "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" | 2017 | "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" |
1992 | "checksum smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "590700be3630457c56f8c73c0ea39881476ad7076cd84057d44f4f38f79914fb" | 2018 | "checksum smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "590700be3630457c56f8c73c0ea39881476ad7076cd84057d44f4f38f79914fb" |
@@ -2002,6 +2028,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2002 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" | 2028 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" |
2003 | "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" | 2029 | "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" |
2004 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" | 2030 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" |
2031 | "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" | ||
2005 | "checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" | 2032 | "checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" |
2006 | "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" | 2033 | "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" |
2007 | "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" | 2034 | "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" |
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); |