From 6ed2fd233b569d01169fc888f30c358dd289d260 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sun, 18 Apr 2021 19:56:13 +0200 Subject: hir_ty: keep body::Expander in TyLoweringContext --- crates/hir_def/src/body.rs | 18 ++++++++---------- crates/hir_def/src/type_ref.rs | 38 +++----------------------------------- 2 files changed, 11 insertions(+), 45 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 8a9b936ea..131f424cc 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -37,13 +37,15 @@ use crate::{ /// A subset of Expander that only deals with cfg attributes. We only need it to /// avoid cyclic queries in crate def map during enum processing. +#[derive(Debug)] pub(crate) struct CfgExpander { cfg_options: CfgOptions, hygiene: Hygiene, krate: CrateId, } -pub(crate) struct Expander { +#[derive(Debug)] +pub struct Expander { cfg_expander: CfgExpander, def_map: Arc, current_file_id: HirFileId, @@ -80,11 +82,7 @@ impl CfgExpander { } impl Expander { - pub(crate) fn new( - db: &dyn DefDatabase, - current_file_id: HirFileId, - module: ModuleId, - ) -> Expander { + pub fn new(db: &dyn DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { let cfg_expander = CfgExpander::new(db, current_file_id, module.krate); let def_map = module.def_map(db); let ast_id_map = db.ast_id_map(current_file_id); @@ -98,7 +96,7 @@ impl Expander { } } - pub(crate) fn enter_expand( + pub fn enter_expand( &mut self, db: &dyn DefDatabase, macro_call: ast::MacroCall, @@ -170,7 +168,7 @@ impl Expander { Ok(ExpandResult { value: Some((mark, node)), err }) } - pub(crate) fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) { + pub fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) { self.cfg_expander.hygiene = Hygiene::new(db.upcast(), mark.file_id); self.current_file_id = mark.file_id; self.ast_id_map = mem::take(&mut mark.ast_id_map); @@ -190,7 +188,7 @@ impl Expander { &self.cfg_expander.cfg_options } - pub(crate) fn current_file_id(&self) -> HirFileId { + pub fn current_file_id(&self) -> HirFileId { self.current_file_id } @@ -210,7 +208,7 @@ impl Expander { } #[derive(Debug)] -pub(crate) struct Mark { +pub struct Mark { file_id: HirFileId, ast_id_map: Arc, bomb: DropBomb, diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs index e18712d24..ea29da5da 100644 --- a/crates/hir_def/src/type_ref.rs +++ b/crates/hir_def/src/type_ref.rs @@ -1,15 +1,10 @@ //! HIR for references to types. Paths in these are not yet resolved. They can //! be directly created from an ast::TypeRef, without further queries. -use hir_expand::{name::Name, AstId, ExpandResult, InFile}; +use hir_expand::{name::Name, AstId, InFile}; use syntax::ast; -use crate::{ - body::{Expander, LowerCtx}, - db::DefDatabase, - path::Path, - ModuleId, -}; +use crate::{body::LowerCtx, path::Path}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum Mutability { @@ -124,7 +119,7 @@ pub enum TypeBound { impl TypeRef { /// Converts an `ast::TypeRef` to a `hir::TypeRef`. - pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { + pub fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { match node { ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), ast::Type::TupleType(inner) => { @@ -303,30 +298,3 @@ impl TypeBound { } } } - -pub fn expand_macro_type( - db: &dyn DefDatabase, - module_id: ModuleId, - macro_type: &TypeRef, -) -> Option { - let macro_call = match macro_type { - TypeRef::Macro(macro_call) => macro_call, - _ => panic!("expected TypeRef::Macro"), - }; - - let file_id = macro_call.file_id; - let macro_call = macro_call.to_node(db.upcast()); - - let mut expander = Expander::new(db, file_id, module_id); - let (file_id, expanded) = match expander.enter_expand::(db, macro_call.clone()) { - Ok(ExpandResult { value: Some((mark, expanded)), .. }) => { - let file_id = expander.current_file_id(); - expander.exit(db, mark); - (file_id, expanded) - } - _ => return None, - }; - - let ctx = LowerCtx::new(db, file_id); - return Some(TypeRef::from_ast(&ctx, expanded)); -} -- cgit v1.2.3