Store inner BlockIds in Body

This commit is contained in:
Jonas Schievink 2021-03-05 14:08:23 +01:00 committed by Jonas Schievink
parent 8da50c9077
commit 13f4356d2f
2 changed files with 6 additions and 1 deletions

View File

@ -32,7 +32,7 @@
nameres::DefMap,
path::{ModPath, Path},
src::HasSource,
AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId,
AsMacroCall, BlockId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId,
};
/// A subset of Expander that only deals with cfg attributes. We only need it to
@ -226,6 +226,8 @@ pub struct Body {
pub params: Vec<PatId>,
/// The `ExprId` of the actual body expression.
pub body_expr: ExprId,
/// Block expressions in this body that may contain inner items.
pub block_scopes: Vec<BlockId>,
pub item_scope: ItemScope,
_c: Count<Self>,
}

View File

@ -76,6 +76,7 @@ pub(super) fn lower(
labels: Arena::default(),
params: Vec::new(),
body_expr: dummy_expr_id(),
block_scopes: Vec::new(),
item_scope: Default::default(),
_c: Count::new(),
},
@ -700,6 +701,8 @@ fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId {
let block_loc =
BlockLoc { ast_id, module: self.expander.def_map.module_id(self.expander.module) };
let block_id = self.db.intern_block(block_loc);
self.body.block_scopes.push(block_id);
let opt_def_map = self.db.block_def_map(block_id);
let has_def_map = opt_def_map.is_some();
let def_map = opt_def_map.unwrap_or_else(|| self.expander.def_map.clone());