7359: ItemTree: store a mapping from blocks to inner items r=jonas-schievink a=jonas-schievink

To do name resolution within block expressions, we need to know which inner items are located inside each block expression. This adds such a mapping to `ItemTree`, replacing the previous one, which was seemingly unused other than to access all the inner items.

This also assigns `AstId`s to block expressions, which is needed to store the mapping in salsa.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-01-20 16:09:22 +00:00 committed by GitHub
commit e62533c3ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 32 deletions

View file

@ -13,7 +13,7 @@ use std::{
};
use la_arena::{Arena, Idx};
use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
/// `AstId` points to an AST node in a specific file.
pub struct FileAstId<N: AstNode> {
@ -72,12 +72,20 @@ impl AstIdMap {
// get lower ids then children. That is, adding a new child does not
// change parent's id. This means that, say, adding a new function to a
// trait does not change ids of top-level items, which helps caching.
bdfs(node, |it| match ast::Item::cast(it) {
Some(module_item) => {
res.alloc(module_item.syntax());
true
bdfs(node, |it| {
match_ast! {
match it {
ast::Item(module_item) => {
res.alloc(module_item.syntax());
true
},
ast::BlockExpr(block) => {
res.alloc(block.syntax());
true
},
_ => false,
}
}
None => false,
});
res
}