Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
7555: Expander: store a LocalModuleId, not ModuleId r=jonas-schievink a=jonas-schievink

It already stores the DefMap containing the module, so having
a full ModuleId is unnecessary and makes it easier to mix things up

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
  • Loading branch information
bors[bot] and jonas-schievink committed Feb 4, 2021
2 parents 1bae550 + cacaebc commit 663d404
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 4 additions & 7 deletions crates/hir_def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,7 +49,7 @@ pub(crate) struct Expander {
def_map: Arc<DefMap>,
current_file_id: HirFileId,
ast_id_map: Arc<AstIdMap>,
module: ModuleId,
module: LocalModuleId,
recursion_limit: usize,
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -197,10 +197,7 @@ impl Expander {
}

fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> {
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<N: AstNode>(&self, item: &N) -> AstId<N> {
Expand Down
14 changes: 7 additions & 7 deletions crates/hir_def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
Expand Down

0 comments on commit 663d404

Please sign in to comment.