From cacaebcb33f1b712fbece87c69fa0ad843648f78 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 4 Feb 2021 15:04:21 +0100 Subject: Expander: store a LocalModuleId, not ModuleId It already stores the DefMap containing the module, so having a full ModuleId is unnecessary and makes it easier to mix things up --- crates/hir_def/src/body.rs | 11 ++++------- crates/hir_def/src/body/lower.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 41abd8f83..9a432f7d1 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -33,7 +33,7 @@ use crate::{ nameres::DefMap, path::{ModPath, Path}, src::HasSource, - AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, + AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId, }; /// A subset of Expander that only deals with cfg attributes. We only need it to @@ -49,7 +49,7 @@ pub(crate) struct Expander { def_map: Arc, current_file_id: HirFileId, ast_id_map: Arc, - module: ModuleId, + module: LocalModuleId, recursion_limit: usize, } @@ -94,7 +94,7 @@ impl Expander { def_map: crate_def_map, current_file_id, ast_id_map, - module, + module: module.local_id, recursion_limit: 0, } } @@ -197,10 +197,7 @@ impl Expander { } fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option { - self.def_map - .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) - .0 - .take_macros() + self.def_map.resolve_path(db, self.module, path, BuiltinShadowMode::Other).0.take_macros() } fn ast_id(&self, item: &N) -> AstId { diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 540c6c9ad..28b11cdde 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -698,15 +698,15 @@ impl ExprCollector<'_> { fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId { let ast_id = self.expander.ast_id(&block); - let block_loc = BlockLoc { ast_id, module: self.expander.module }; + 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); 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()); - let module = - if has_def_map { def_map.module_id(def_map.root()) } else { self.expander.module }; + let module = if has_def_map { def_map.root() } else { self.expander.module }; let prev_def_map = mem::replace(&mut self.expander.def_map, def_map); - let prev_module = mem::replace(&mut self.expander.module, module); + let prev_local_module = mem::replace(&mut self.expander.module, module); self.collect_stmts_items(block.statements()); let statements = @@ -719,7 +719,7 @@ impl ExprCollector<'_> { ); self.expander.def_map = prev_def_map; - self.expander.module = prev_module; + self.expander.module = prev_local_module; expr_id } @@ -812,7 +812,7 @@ impl ExprCollector<'_> { } Either::Right(e) => { let mac = MacroDefId { - krate: self.expander.module.krate, + krate: self.expander.def_map.krate(), ast_id: Some(self.expander.ast_id(&e)), kind: MacroDefKind::Declarative, local_inner: false, @@ -852,7 +852,7 @@ impl ExprCollector<'_> { // decide that, we need to try resolving the name. let (resolved, _) = self.expander.def_map.resolve_path( self.db, - self.expander.module.local_id, + self.expander.module, &name.clone().into(), BuiltinShadowMode::Other, ); -- cgit v1.2.3