diff options
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index bbdc606cd..fe90879b6 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -1,55 +1,56 @@ | |||
1 | /// This module implements import-resolution/macro expansion algorithm. | 1 | //! This module implements import-resolution/macro expansion algorithm. |
2 | /// | 2 | //! |
3 | /// The result of this module is `CrateDefMap`: a data structure which contains: | 3 | //! The result of this module is `CrateDefMap`: a data structure which contains: |
4 | /// | 4 | //! |
5 | /// * a tree of modules for the crate | 5 | //! * a tree of modules for the crate |
6 | /// * for each module, a set of items visible in the module (directly declared | 6 | //! * for each module, a set of items visible in the module (directly declared |
7 | /// or imported) | 7 | //! or imported) |
8 | /// | 8 | //! |
9 | /// Note that `CrateDefMap` contains fully macro expanded code. | 9 | //! Note that `CrateDefMap` contains fully macro expanded code. |
10 | /// | 10 | //! |
11 | /// Computing `CrateDefMap` can be partitioned into several logically | 11 | //! Computing `CrateDefMap` can be partitioned into several logically |
12 | /// independent "phases". The phases are mutually recursive though, there's no | 12 | //! independent "phases". The phases are mutually recursive though, there's no |
13 | /// strict ordering. | 13 | //! strict ordering. |
14 | /// | 14 | //! |
15 | /// ## Collecting RawItems | 15 | //! ## Collecting RawItems |
16 | /// | 16 | //! |
17 | /// This happens in the `raw` module, which parses a single source file into a | 17 | //! This happens in the `raw` module, which parses a single source file into a |
18 | /// set of top-level items. Nested imports are desugared to flat imports in | 18 | //! set of top-level items. Nested imports are desugared to flat imports in |
19 | /// this phase. Macro calls are represented as a triple of (Path, Option<Name>, | 19 | //! this phase. Macro calls are represented as a triple of (Path, Option<Name>, |
20 | /// TokenTree). | 20 | //! TokenTree). |
21 | /// | 21 | //! |
22 | /// ## Collecting Modules | 22 | //! ## Collecting Modules |
23 | /// | 23 | //! |
24 | /// This happens in the `collector` module. In this phase, we recursively walk | 24 | //! This happens in the `collector` module. In this phase, we recursively walk |
25 | /// tree of modules, collect raw items from submodules, populate module scopes | 25 | //! tree of modules, collect raw items from submodules, populate module scopes |
26 | /// with defined items (so, we assign item ids in this phase) and record the set | 26 | //! with defined items (so, we assign item ids in this phase) and record the set |
27 | /// of unresolved imports and macros. | 27 | //! of unresolved imports and macros. |
28 | /// | 28 | //! |
29 | /// While we walk tree of modules, we also record macro_rules definitions and | 29 | //! While we walk tree of modules, we also record macro_rules definitions and |
30 | /// expand calls to macro_rules defined macros. | 30 | //! expand calls to macro_rules defined macros. |
31 | /// | 31 | //! |
32 | /// ## Resolving Imports | 32 | //! ## Resolving Imports |
33 | /// | 33 | //! |
34 | /// We maintain a list of currently unresolved imports. On every iteration, we | 34 | //! We maintain a list of currently unresolved imports. On every iteration, we |
35 | /// try to resolve some imports from this list. If the import is resolved, we | 35 | //! try to resolve some imports from this list. If the import is resolved, we |
36 | /// record it, by adding an item to current module scope and, if necessary, by | 36 | //! record it, by adding an item to current module scope and, if necessary, by |
37 | /// recursively populating glob imports. | 37 | //! recursively populating glob imports. |
38 | /// | 38 | //! |
39 | /// ## Resolving Macros | 39 | //! ## Resolving Macros |
40 | /// | 40 | //! |
41 | /// macro_rules from the same crate use a global mutable namespace. We expand | 41 | //! macro_rules from the same crate use a global mutable namespace. We expand |
42 | /// them immediately, when we collect modules. | 42 | //! them immediately, when we collect modules. |
43 | /// | 43 | //! |
44 | /// Macros from other crates (including proc-macros) can be used with | 44 | //! Macros from other crates (including proc-macros) can be used with |
45 | /// `foo::bar!` syntax. We handle them similarly to imports. There's a list of | 45 | //! `foo::bar!` syntax. We handle them similarly to imports. There's a list of |
46 | /// unexpanded macros. On every iteration, we try to resolve each macro call | 46 | //! unexpanded macros. On every iteration, we try to resolve each macro call |
47 | /// path and, upon success, we run macro expansion and "collect module" phase | 47 | //! path and, upon success, we run macro expansion and "collect module" phase |
48 | /// on the result | 48 | //! on the result |
49 | 49 | ||
50 | mod per_ns; | 50 | mod per_ns; |
51 | mod raw; | 51 | mod raw; |
52 | mod collector; | 52 | mod collector; |
53 | mod mod_resolution; | ||
53 | #[cfg(test)] | 54 | #[cfg(test)] |
54 | mod tests; | 55 | mod tests; |
55 | 56 | ||
@@ -101,6 +102,8 @@ pub struct CrateDefMap { | |||
101 | /// However, do we want to put it as a global variable? | 102 | /// However, do we want to put it as a global variable? |
102 | poison_macros: FxHashSet<MacroDefId>, | 103 | poison_macros: FxHashSet<MacroDefId>, |
103 | 104 | ||
105 | exported_macros: FxHashMap<Name, MacroDefId>, | ||
106 | |||
104 | diagnostics: Vec<DefDiagnostic>, | 107 | diagnostics: Vec<DefDiagnostic>, |
105 | } | 108 | } |
106 | 109 | ||
@@ -245,6 +248,7 @@ impl CrateDefMap { | |||
245 | root, | 248 | root, |
246 | modules, | 249 | modules, |
247 | poison_macros: FxHashSet::default(), | 250 | poison_macros: FxHashSet::default(), |
251 | exported_macros: FxHashMap::default(), | ||
248 | diagnostics: Vec::new(), | 252 | diagnostics: Vec::new(), |
249 | } | 253 | } |
250 | }; | 254 | }; |