diff options
Diffstat (limited to 'crates/hir_expand/src/ast_id_map.rs')
-rw-r--r-- | crates/hir_expand/src/ast_id_map.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/hir_expand/src/ast_id_map.rs b/crates/hir_expand/src/ast_id_map.rs index 2401b0cc5..16cf29907 100644 --- a/crates/hir_expand/src/ast_id_map.rs +++ b/crates/hir_expand/src/ast_id_map.rs | |||
@@ -13,7 +13,8 @@ use std::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use la_arena::{Arena, Idx}; | 15 | use la_arena::{Arena, Idx}; |
16 | use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; | 16 | use profile::Count; |
17 | use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; | ||
17 | 18 | ||
18 | /// `AstId` points to an AST node in a specific file. | 19 | /// `AstId` points to an AST node in a specific file. |
19 | pub struct FileAstId<N: AstNode> { | 20 | pub struct FileAstId<N: AstNode> { |
@@ -62,22 +63,31 @@ type ErasedFileAstId = Idx<SyntaxNodePtr>; | |||
62 | #[derive(Debug, PartialEq, Eq, Default)] | 63 | #[derive(Debug, PartialEq, Eq, Default)] |
63 | pub struct AstIdMap { | 64 | pub struct AstIdMap { |
64 | arena: Arena<SyntaxNodePtr>, | 65 | arena: Arena<SyntaxNodePtr>, |
66 | _c: Count<Self>, | ||
65 | } | 67 | } |
66 | 68 | ||
67 | impl AstIdMap { | 69 | impl AstIdMap { |
68 | pub(crate) fn from_source(node: &SyntaxNode) -> AstIdMap { | 70 | pub(crate) fn from_source(node: &SyntaxNode) -> AstIdMap { |
69 | assert!(node.parent().is_none()); | 71 | assert!(node.parent().is_none()); |
70 | let mut res = AstIdMap { arena: Arena::default() }; | 72 | let mut res = AstIdMap::default(); |
71 | // By walking the tree in breadth-first order we make sure that parents | 73 | // By walking the tree in breadth-first order we make sure that parents |
72 | // get lower ids then children. That is, adding a new child does not | 74 | // get lower ids then children. That is, adding a new child does not |
73 | // change parent's id. This means that, say, adding a new function to a | 75 | // change parent's id. This means that, say, adding a new function to a |
74 | // trait does not change ids of top-level items, which helps caching. | 76 | // trait does not change ids of top-level items, which helps caching. |
75 | bdfs(node, |it| match ast::Item::cast(it) { | 77 | bdfs(node, |it| { |
76 | Some(module_item) => { | 78 | match_ast! { |
77 | res.alloc(module_item.syntax()); | 79 | match it { |
78 | true | 80 | ast::Item(module_item) => { |
81 | res.alloc(module_item.syntax()); | ||
82 | true | ||
83 | }, | ||
84 | ast::BlockExpr(block) => { | ||
85 | res.alloc(block.syntax()); | ||
86 | true | ||
87 | }, | ||
88 | _ => false, | ||
89 | } | ||
79 | } | 90 | } |
80 | None => false, | ||
81 | }); | 91 | }); |
82 | res | 92 | res |
83 | } | 93 | } |