internal: Rename AstDatabase to ExpandDatabase

This commit is contained in:
Lukas Wirth 2023-03-13 16:33:52 +01:00
parent 9fca0a4afe
commit 9fb9ee3b6a
30 changed files with 161 additions and 148 deletions

View file

@ -341,8 +341,8 @@ macro_rules! __ra_macro_fixture339 {($name : ident )=>{ impl Clone for $name
macro_rules! __ra_macro_fixture340 {([$($stack : tt )*])=>{$($stack )* }; ([$($stack : tt )*]{$($tail : tt )* })=>{$($stack )* { remove_sections_inner ! ([]$($tail )*); }}; ([$($stack : tt )*]$t : tt $($tail : tt )*)=>{ remove_sections ! ([$($stack )* $t ]$($tail )*); }; } macro_rules! __ra_macro_fixture340 {([$($stack : tt )*])=>{$($stack )* }; ([$($stack : tt )*]{$($tail : tt )* })=>{$($stack )* { remove_sections_inner ! ([]$($tail )*); }}; ([$($stack : tt )*]$t : tt $($tail : tt )*)=>{ remove_sections ! ([$($stack )* $t ]$($tail )*); }; }
macro_rules! __ra_macro_fixture341 {($t : ty ,$z : expr )=>{ impl Zero for $t { fn zero ()-> Self {$z as $t } fn is_zero (& self )-> bool { self == & Self :: zero ()}}}; } macro_rules! __ra_macro_fixture341 {($t : ty ,$z : expr )=>{ impl Zero for $t { fn zero ()-> Self {$z as $t } fn is_zero (& self )-> bool { self == & Self :: zero ()}}}; }
macro_rules! __ra_macro_fixture342 {($($ident : ident ),* $(,)?)=>{$(# [ allow ( bad_style )] pub const $ident : super :: Name = super :: Name :: new_inline ( stringify ! ($ident )); )* }; } macro_rules! __ra_macro_fixture342 {($($ident : ident ),* $(,)?)=>{$(# [ allow ( bad_style )] pub const $ident : super :: Name = super :: Name :: new_inline ( stringify ! ($ident )); )* }; }
macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; } macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; }
macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn AstDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; } macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn ExpandDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; }
macro_rules! __ra_macro_fixture345 {($($ty : ty =>$this : ident $im : block );*)=>{$(impl ToTokenTree for $ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . into (); leaf . into ()}} impl ToTokenTree for &$ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . clone (). into (); leaf . into ()}})* }} macro_rules! __ra_macro_fixture345 {($($ty : ty =>$this : ident $im : block );*)=>{$(impl ToTokenTree for $ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . into (); leaf . into ()}} impl ToTokenTree for &$ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . clone (). into (); leaf . into ()}})* }}
macro_rules! __ra_macro_fixture346 {($name : ident )=>{ impl $crate :: salsa :: InternKey for $name { fn from_intern_id ( v : $crate :: salsa :: InternId )-> Self {$name ( v )} fn as_intern_id (& self )-> $crate :: salsa :: InternId { self . 0 }}}; } macro_rules! __ra_macro_fixture346 {($name : ident )=>{ impl $crate :: salsa :: InternKey for $name { fn from_intern_id ( v : $crate :: salsa :: InternId )-> Self {$name ( v )} fn as_intern_id (& self )-> $crate :: salsa :: InternId { self . 0 }}}; }
macro_rules! __ra_macro_fixture347 {($($var : ident ($t : ty )),+ )=>{$(impl From <$t > for AttrOwner { fn from ( t : $t )-> AttrOwner { AttrOwner ::$var ( t )}})+ }; } macro_rules! __ra_macro_fixture347 {($($var : ident ($t : ty )),+ )=>{$(impl From <$t > for AttrOwner { fn from ( t : $t )-> AttrOwner { AttrOwner ::$var ( t )}})+ }; }

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use base_db::{salsa, CrateId, SourceDatabase, Upcast}; use base_db::{salsa, CrateId, SourceDatabase, Upcast};
use either::Either; use either::Either;
use hir_expand::{db::AstDatabase, HirFileId}; use hir_expand::{db::ExpandDatabase, HirFileId};
use intern::Interned; use intern::Interned;
use la_arena::ArenaMap; use la_arena::ArenaMap;
use syntax::{ast, AstPtr}; use syntax::{ast, AstPtr};
@ -64,7 +64,7 @@ pub trait InternDatabase: SourceDatabase {
} }
#[salsa::query_group(DefDatabaseStorage)] #[salsa::query_group(DefDatabaseStorage)]
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
#[salsa::input] #[salsa::input]
fn enable_proc_attr_macros(&self) -> bool; fn enable_proc_attr_macros(&self) -> bool;

View file

@ -20,7 +20,7 @@ use ::mbe::TokenMap;
use base_db::{fixture::WithFixture, ProcMacro, SourceDatabase}; use base_db::{fixture::WithFixture, ProcMacro, SourceDatabase};
use expect_test::Expect; use expect_test::Expect;
use hir_expand::{ use hir_expand::{
db::{AstDatabase, TokenExpander}, db::{ExpandDatabase, TokenExpander},
AstId, InFile, MacroDefId, MacroDefKind, MacroFile, AstId, InFile, MacroDefId, MacroDefKind, MacroFile,
}; };
use stdx::format_to; use stdx::format_to;

View file

@ -9,7 +9,7 @@ use base_db::{
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition, salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition,
SourceDatabase, Upcast, SourceDatabase, Upcast,
}; };
use hir_expand::{db::AstDatabase, InFile}; use hir_expand::{db::ExpandDatabase, InFile};
use stdx::hash::NoHashHashSet; use stdx::hash::NoHashHashSet;
use syntax::{algo, ast, AstNode}; use syntax::{algo, ast, AstNode};
@ -23,7 +23,7 @@ use crate::{
#[salsa::database( #[salsa::database(
base_db::SourceDatabaseExtStorage, base_db::SourceDatabaseExtStorage,
base_db::SourceDatabaseStorage, base_db::SourceDatabaseStorage,
hir_expand::db::AstDatabaseStorage, hir_expand::db::ExpandDatabaseStorage,
crate::db::InternDatabaseStorage, crate::db::InternDatabaseStorage,
crate::db::DefDatabaseStorage crate::db::DefDatabaseStorage
)] )]
@ -40,8 +40,8 @@ impl Default for TestDB {
} }
} }
impl Upcast<dyn AstDatabase> for TestDB { impl Upcast<dyn ExpandDatabase> for TestDB {
fn upcast(&self) -> &(dyn AstDatabase + 'static) { fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
&*self &*self
} }
} }

View file

@ -10,7 +10,7 @@ use smallvec::{smallvec, SmallVec};
use syntax::{ast, match_ast, AstNode, SmolStr, SyntaxNode}; use syntax::{ast, match_ast, AstNode, SmolStr, SyntaxNode};
use crate::{ use crate::{
db::AstDatabase, db::ExpandDatabase,
hygiene::Hygiene, hygiene::Hygiene,
mod_path::{ModPath, PathKind}, mod_path::{ModPath, PathKind},
name::AsName, name::AsName,
@ -38,7 +38,7 @@ impl ops::Deref for RawAttrs {
impl RawAttrs { impl RawAttrs {
pub const EMPTY: Self = Self { entries: None }; pub const EMPTY: Self = Self { entries: None };
pub fn new(db: &dyn AstDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self { pub fn new(db: &dyn ExpandDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
let entries = collect_attrs(owner) let entries = collect_attrs(owner)
.filter_map(|(id, attr)| match attr { .filter_map(|(id, attr)| match attr {
Either::Left(attr) => { Either::Left(attr) => {
@ -55,7 +55,7 @@ impl RawAttrs {
Self { entries: if entries.is_empty() { None } else { Some(entries) } } Self { entries: if entries.is_empty() { None } else { Some(entries) } }
} }
pub fn from_attrs_owner(db: &dyn AstDatabase, owner: InFile<&dyn ast::HasAttrs>) -> Self { pub fn from_attrs_owner(db: &dyn ExpandDatabase, owner: InFile<&dyn ast::HasAttrs>) -> Self {
let hygiene = Hygiene::new(db, owner.file_id); let hygiene = Hygiene::new(db, owner.file_id);
Self::new(db, owner.value, &hygiene) Self::new(db, owner.value, &hygiene)
} }
@ -87,7 +87,7 @@ impl RawAttrs {
/// Processes `cfg_attr`s, returning the resulting semantic `Attrs`. /// Processes `cfg_attr`s, returning the resulting semantic `Attrs`.
// FIXME: This should return a different type // FIXME: This should return a different type
pub fn filter(self, db: &dyn AstDatabase, krate: CrateId) -> RawAttrs { pub fn filter(self, db: &dyn ExpandDatabase, krate: CrateId) -> RawAttrs {
let has_cfg_attrs = self let has_cfg_attrs = self
.iter() .iter()
.any(|attr| attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr])); .any(|attr| attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]));
@ -199,7 +199,7 @@ impl fmt::Display for AttrInput {
impl Attr { impl Attr {
fn from_src( fn from_src(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
ast: ast::Meta, ast: ast::Meta,
hygiene: &Hygiene, hygiene: &Hygiene,
id: AttrId, id: AttrId,
@ -221,7 +221,7 @@ impl Attr {
} }
fn from_tt( fn from_tt(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
tt: &tt::Subtree, tt: &tt::Subtree,
hygiene: &Hygiene, hygiene: &Hygiene,
id: AttrId, id: AttrId,

View file

@ -1,6 +1,6 @@
//! Builtin attributes. //! Builtin attributes.
use crate::{db::AstDatabase, name, tt, ExpandResult, MacroCallId, MacroCallKind}; use crate::{db::ExpandDatabase, name, tt, ExpandResult, MacroCallId, MacroCallKind};
macro_rules! register_builtin { macro_rules! register_builtin {
( $(($name:ident, $variant:ident) => $expand:ident),* ) => { ( $(($name:ident, $variant:ident) => $expand:ident),* ) => {
@ -12,7 +12,7 @@ macro_rules! register_builtin {
impl BuiltinAttrExpander { impl BuiltinAttrExpander {
pub fn expand( pub fn expand(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -60,7 +60,7 @@ pub fn find_builtin_attr(ident: &name::Name) -> Option<BuiltinAttrExpander> {
} }
fn dummy_attr_expand( fn dummy_attr_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -90,7 +90,7 @@ fn dummy_attr_expand(
/// So this hacky approach is a lot more friendly for us, though it does require a bit of support in /// So this hacky approach is a lot more friendly for us, though it does require a bit of support in
/// [`hir::Semantics`] to make this work. /// [`hir::Semantics`] to make this work.
fn derive_attr_expand( fn derive_attr_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {

View file

@ -9,7 +9,7 @@ use syntax::{
match_ast, match_ast,
}; };
use crate::{db::AstDatabase, name, quote, ExpandError, ExpandResult, MacroCallId}; use crate::{db::ExpandDatabase, name, quote, ExpandError, ExpandResult, MacroCallId};
macro_rules! register_builtin { macro_rules! register_builtin {
( $($trait:ident => $expand:ident),* ) => { ( $($trait:ident => $expand:ident),* ) => {
@ -21,7 +21,7 @@ macro_rules! register_builtin {
impl BuiltinDeriveExpander { impl BuiltinDeriveExpander {
pub fn expand( pub fn expand(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -141,7 +141,7 @@ fn expand_simple_derive(tt: &tt::Subtree, trait_path: tt::Subtree) -> ExpandResu
ExpandResult::ok(expanded) ExpandResult::ok(expanded)
} }
fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree { fn find_builtin_crate(db: &dyn ExpandDatabase, id: MacroCallId) -> tt::TokenTree {
// FIXME: make hygiene works for builtin derive macro // FIXME: make hygiene works for builtin derive macro
// such that $crate can be used here. // such that $crate can be used here.
let cg = db.crate_graph(); let cg = db.crate_graph();
@ -158,7 +158,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree {
} }
fn copy_expand( fn copy_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -167,7 +167,7 @@ fn copy_expand(
} }
fn clone_expand( fn clone_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -176,7 +176,7 @@ fn clone_expand(
} }
fn default_expand( fn default_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -185,7 +185,7 @@ fn default_expand(
} }
fn debug_expand( fn debug_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -194,7 +194,7 @@ fn debug_expand(
} }
fn hash_expand( fn hash_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -202,13 +202,17 @@ fn hash_expand(
expand_simple_derive(tt, quote! { #krate::hash::Hash }) expand_simple_derive(tt, quote! { #krate::hash::Hash })
} }
fn eq_expand(db: &dyn AstDatabase, id: MacroCallId, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> { fn eq_expand(
db: &dyn ExpandDatabase,
id: MacroCallId,
tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> {
let krate = find_builtin_crate(db, id); let krate = find_builtin_crate(db, id);
expand_simple_derive(tt, quote! { #krate::cmp::Eq }) expand_simple_derive(tt, quote! { #krate::cmp::Eq })
} }
fn partial_eq_expand( fn partial_eq_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -217,7 +221,7 @@ fn partial_eq_expand(
} }
fn ord_expand( fn ord_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -226,7 +230,7 @@ fn ord_expand(
} }
fn partial_ord_expand( fn partial_ord_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {

View file

@ -10,7 +10,7 @@ use syntax::{
}; };
use crate::{ use crate::{
db::AstDatabase, name, quote, tt, ExpandError, ExpandResult, MacroCallId, MacroCallLoc, db::ExpandDatabase, name, quote, tt, ExpandError, ExpandResult, MacroCallId, MacroCallLoc,
}; };
macro_rules! register_builtin { macro_rules! register_builtin {
@ -28,7 +28,7 @@ macro_rules! register_builtin {
impl BuiltinFnLikeExpander { impl BuiltinFnLikeExpander {
pub fn expand( pub fn expand(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -42,7 +42,7 @@ macro_rules! register_builtin {
impl EagerExpander { impl EagerExpander {
pub fn expand( pub fn expand(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
arg_id: MacroCallId, arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -121,7 +121,7 @@ const DOLLAR_CRATE: tt::Ident =
tt::Ident { text: SmolStr::new_inline("$crate"), span: tt::TokenId::unspecified() }; tt::Ident { text: SmolStr::new_inline("$crate"), span: tt::TokenId::unspecified() };
fn module_path_expand( fn module_path_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -130,7 +130,7 @@ fn module_path_expand(
} }
fn line_expand( fn line_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -144,7 +144,7 @@ fn line_expand(
} }
fn log_syntax_expand( fn log_syntax_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -152,7 +152,7 @@ fn log_syntax_expand(
} }
fn trace_macros_expand( fn trace_macros_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -160,7 +160,7 @@ fn trace_macros_expand(
} }
fn stringify_expand( fn stringify_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -174,7 +174,7 @@ fn stringify_expand(
} }
fn column_expand( fn column_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -188,7 +188,7 @@ fn column_expand(
} }
fn assert_expand( fn assert_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -218,7 +218,7 @@ fn assert_expand(
} }
fn file_expand( fn file_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -234,7 +234,7 @@ fn file_expand(
} }
fn format_args_expand( fn format_args_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -276,7 +276,7 @@ fn format_args_expand(
} }
fn asm_expand( fn asm_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -304,7 +304,7 @@ fn asm_expand(
} }
fn global_asm_expand( fn global_asm_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
_tt: &tt::Subtree, _tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -313,7 +313,7 @@ fn global_asm_expand(
} }
fn cfg_expand( fn cfg_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -325,7 +325,7 @@ fn cfg_expand(
} }
fn panic_expand( fn panic_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -343,7 +343,7 @@ fn panic_expand(
} }
fn unreachable_expand( fn unreachable_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -379,7 +379,7 @@ fn unquote_byte_string(lit: &tt::Literal) -> Option<Vec<u8>> {
} }
fn compile_error_expand( fn compile_error_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_id: MacroCallId, _id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -395,7 +395,7 @@ fn compile_error_expand(
} }
fn concat_expand( fn concat_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_arg_id: MacroCallId, _arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -441,7 +441,7 @@ fn concat_expand(
} }
fn concat_bytes_expand( fn concat_bytes_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_arg_id: MacroCallId, _arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -507,7 +507,7 @@ fn concat_bytes_expand_subtree(
} }
fn concat_idents_expand( fn concat_idents_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_arg_id: MacroCallId, _arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -529,7 +529,7 @@ fn concat_idents_expand(
} }
fn relative_file( fn relative_file(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
call_id: MacroCallId, call_id: MacroCallId,
path_str: &str, path_str: &str,
allow_recursion: bool, allow_recursion: bool,
@ -558,7 +558,7 @@ fn parse_string(tt: &tt::Subtree) -> Result<String, ExpandError> {
} }
fn include_expand( fn include_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
arg_id: MacroCallId, arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -583,7 +583,7 @@ fn include_expand(
} }
fn include_bytes_expand( fn include_bytes_expand(
_db: &dyn AstDatabase, _db: &dyn ExpandDatabase,
_arg_id: MacroCallId, _arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -606,7 +606,7 @@ fn include_bytes_expand(
} }
fn include_str_expand( fn include_str_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
arg_id: MacroCallId, arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -637,13 +637,13 @@ fn include_str_expand(
ExpandResult::ok(ExpandedEager::new(quote!(#text))) ExpandResult::ok(ExpandedEager::new(quote!(#text)))
} }
fn get_env_inner(db: &dyn AstDatabase, arg_id: MacroCallId, key: &str) -> Option<String> { fn get_env_inner(db: &dyn ExpandDatabase, arg_id: MacroCallId, key: &str) -> Option<String> {
let krate = db.lookup_intern_macro_call(arg_id).krate; let krate = db.lookup_intern_macro_call(arg_id).krate;
db.crate_graph()[krate].env.get(key) db.crate_graph()[krate].env.get(key)
} }
fn env_expand( fn env_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
arg_id: MacroCallId, arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {
@ -679,7 +679,7 @@ fn env_expand(
} }
fn option_env_expand( fn option_env_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
arg_id: MacroCallId, arg_id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<ExpandedEager> { ) -> ExpandResult<ExpandedEager> {

View file

@ -44,7 +44,7 @@ pub enum TokenExpander {
impl TokenExpander { impl TokenExpander {
fn expand( fn expand(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
tt: &tt::Subtree, tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> { ) -> ExpandResult<tt::Subtree> {
@ -83,9 +83,8 @@ impl TokenExpander {
} }
} }
// FIXME: rename to ExpandDatabase #[salsa::query_group(ExpandDatabaseStorage)]
#[salsa::query_group(AstDatabaseStorage)] pub trait ExpandDatabase: SourceDatabase {
pub trait AstDatabase: SourceDatabase {
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
/// Main public API -- parses a hir file, not caring whether it's a real /// Main public API -- parses a hir file, not caring whether it's a real
@ -138,7 +137,7 @@ pub trait AstDatabase: SourceDatabase {
/// token. The `token_to_map` mapped down into the expansion, with the mapped /// token. The `token_to_map` mapped down into the expansion, with the mapped
/// token returned. /// token returned.
pub fn expand_speculative( pub fn expand_speculative(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
actual_macro_call: MacroCallId, actual_macro_call: MacroCallId,
speculative_args: &SyntaxNode, speculative_args: &SyntaxNode,
token_to_map: SyntaxToken, token_to_map: SyntaxToken,
@ -236,12 +235,12 @@ pub fn expand_speculative(
Some((node.syntax_node(), token)) Some((node.syntax_node(), token))
} }
fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> { fn ast_id_map(db: &dyn ExpandDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
let map = db.parse_or_expand(file_id).map(|it| AstIdMap::from_source(&it)).unwrap_or_default(); let map = db.parse_or_expand(file_id).map(|it| AstIdMap::from_source(&it)).unwrap_or_default();
Arc::new(map) Arc::new(map)
} }
fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> { fn parse_or_expand(db: &dyn ExpandDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
match file_id.repr() { match file_id.repr() {
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
HirFileIdRepr::MacroFile(macro_file) => { HirFileIdRepr::MacroFile(macro_file) => {
@ -253,7 +252,7 @@ fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNod
} }
fn parse_macro_expansion( fn parse_macro_expansion(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
macro_file: MacroFile, macro_file: MacroFile,
) -> ExpandResult<Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>> { ) -> ExpandResult<Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>> {
let _p = profile::span("parse_macro_expansion"); let _p = profile::span("parse_macro_expansion");
@ -296,7 +295,7 @@ fn parse_macro_expansion(
} }
fn macro_arg( fn macro_arg(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
id: MacroCallId, id: MacroCallId,
) -> Option<Arc<(tt::Subtree, mbe::TokenMap, fixup::SyntaxFixupUndoInfo)>> { ) -> Option<Arc<(tt::Subtree, mbe::TokenMap, fixup::SyntaxFixupUndoInfo)>> {
let arg = db.macro_arg_text(id)?; let arg = db.macro_arg_text(id)?;
@ -357,7 +356,7 @@ fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<Sy
.unwrap_or_default() .unwrap_or_default()
} }
fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> { fn macro_arg_text(db: &dyn ExpandDatabase, id: MacroCallId) -> Option<GreenNode> {
let loc = db.lookup_intern_macro_call(id); let loc = db.lookup_intern_macro_call(id);
let arg = loc.kind.arg(db)?; let arg = loc.kind.arg(db)?;
if matches!(loc.kind, MacroCallKind::FnLike { .. }) { if matches!(loc.kind, MacroCallKind::FnLike { .. }) {
@ -380,7 +379,10 @@ fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
Some(arg.green().into()) Some(arg.green().into())
} }
fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Result<Arc<TokenExpander>, mbe::ParseError> { fn macro_def(
db: &dyn ExpandDatabase,
id: MacroDefId,
) -> Result<Arc<TokenExpander>, mbe::ParseError> {
match id.kind { match id.kind {
MacroDefKind::Declarative(ast_id) => { MacroDefKind::Declarative(ast_id) => {
let (mac, def_site_token_map) = match ast_id.to_node(db) { let (mac, def_site_token_map) = match ast_id.to_node(db) {
@ -419,7 +421,10 @@ fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Result<Arc<TokenExpander>,
} }
} }
fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Arc<tt::Subtree>>> { fn macro_expand(
db: &dyn ExpandDatabase,
id: MacroCallId,
) -> ExpandResult<Option<Arc<tt::Subtree>>> {
let _p = profile::span("macro_expand"); let _p = profile::span("macro_expand");
let loc: MacroCallLoc = db.lookup_intern_macro_call(id); let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
if let Some(eager) = &loc.eager { if let Some(eager) = &loc.eager {
@ -469,11 +474,11 @@ fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Ar
ExpandResult { value: Some(Arc::new(tt)), err } ExpandResult { value: Some(Arc::new(tt)), err }
} }
fn macro_expand_error(db: &dyn AstDatabase, macro_call: MacroCallId) -> Option<ExpandError> { fn macro_expand_error(db: &dyn ExpandDatabase, macro_call: MacroCallId) -> Option<ExpandError> {
db.macro_expand(macro_call).err db.macro_expand(macro_call).err
} }
fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::Subtree> { fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<tt::Subtree> {
let loc: MacroCallLoc = db.lookup_intern_macro_call(id); let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
let macro_arg = match db.macro_arg(id) { let macro_arg = match db.macro_arg(id) {
Some(it) => it, Some(it) => it,
@ -502,11 +507,11 @@ fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::
expander.expand(db, loc.krate, &macro_arg.0, attr_arg.as_ref()) expander.expand(db, loc.krate, &macro_arg.0, attr_arg.as_ref())
} }
fn hygiene_frame(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<HygieneFrame> { fn hygiene_frame(db: &dyn ExpandDatabase, file_id: HirFileId) -> Arc<HygieneFrame> {
Arc::new(HygieneFrame::new(db, file_id)) Arc::new(HygieneFrame::new(db, file_id))
} }
fn macro_expand_to(db: &dyn AstDatabase, id: MacroCallId) -> ExpandTo { fn macro_expand_to(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandTo {
let loc: MacroCallLoc = db.lookup_intern_macro_call(id); let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
loc.kind.expand_to() loc.kind.expand_to()
} }

View file

@ -25,7 +25,7 @@ use syntax::{ted, SyntaxNode};
use crate::{ use crate::{
ast::{self, AstNode}, ast::{self, AstNode},
db::AstDatabase, db::ExpandDatabase,
hygiene::Hygiene, hygiene::Hygiene,
mod_path::ModPath, mod_path::ModPath,
EagerCallInfo, ExpandError, ExpandResult, ExpandTo, InFile, MacroCallId, MacroCallKind, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, InFile, MacroCallId, MacroCallKind,
@ -96,7 +96,7 @@ impl ErrorSink for &'_ mut dyn FnMut(ExpandError) {
} }
pub fn expand_eager_macro( pub fn expand_eager_macro(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
krate: CrateId, krate: CrateId,
macro_call: InFile<ast::MacroCall>, macro_call: InFile<ast::MacroCall>,
def: MacroDefId, def: MacroDefId,
@ -172,7 +172,7 @@ fn to_subtree(node: &SyntaxNode) -> crate::tt::Subtree {
} }
fn lazy_expand( fn lazy_expand(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
def: &MacroDefId, def: &MacroDefId,
macro_call: InFile<ast::MacroCall>, macro_call: InFile<ast::MacroCall>,
krate: CrateId, krate: CrateId,
@ -193,7 +193,7 @@ fn lazy_expand(
} }
fn eager_macro_recur( fn eager_macro_recur(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
hygiene: &Hygiene, hygiene: &Hygiene,
curr: InFile<SyntaxNode>, curr: InFile<SyntaxNode>,
krate: CrateId, krate: CrateId,

View file

@ -14,7 +14,7 @@ use syntax::{
}; };
use crate::{ use crate::{
db::{self, AstDatabase}, db::{self, ExpandDatabase},
fixup, fixup,
name::{AsName, Name}, name::{AsName, Name},
HirFileId, InFile, MacroCallKind, MacroCallLoc, MacroDefKind, MacroFile, HirFileId, InFile, MacroCallKind, MacroCallLoc, MacroDefKind, MacroFile,
@ -26,7 +26,7 @@ pub struct Hygiene {
} }
impl Hygiene { impl Hygiene {
pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene { pub fn new(db: &dyn ExpandDatabase, file_id: HirFileId) -> Hygiene {
Hygiene { frames: Some(HygieneFrames::new(db, file_id)) } Hygiene { frames: Some(HygieneFrames::new(db, file_id)) }
} }
@ -37,7 +37,7 @@ impl Hygiene {
// FIXME: this should just return name // FIXME: this should just return name
pub fn name_ref_to_name( pub fn name_ref_to_name(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
name_ref: ast::NameRef, name_ref: ast::NameRef,
) -> Either<Name, CrateId> { ) -> Either<Name, CrateId> {
if let Some(frames) = &self.frames { if let Some(frames) = &self.frames {
@ -51,7 +51,7 @@ impl Hygiene {
Either::Left(name_ref.as_name()) Either::Left(name_ref.as_name())
} }
pub fn local_inner_macros(&self, db: &dyn AstDatabase, path: ast::Path) -> Option<CrateId> { pub fn local_inner_macros(&self, db: &dyn ExpandDatabase, path: ast::Path) -> Option<CrateId> {
let mut token = path.syntax().first_token()?.text_range(); let mut token = path.syntax().first_token()?.text_range();
let frames = self.frames.as_ref()?; let frames = self.frames.as_ref()?;
let mut current = &frames.0; let mut current = &frames.0;
@ -87,13 +87,13 @@ pub struct HygieneFrame {
} }
impl HygieneFrames { impl HygieneFrames {
fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Self { fn new(db: &dyn ExpandDatabase, file_id: HirFileId) -> Self {
// Note that this intentionally avoids the `hygiene_frame` query to avoid blowing up memory // Note that this intentionally avoids the `hygiene_frame` query to avoid blowing up memory
// usage. The query is only helpful for nested `HygieneFrame`s as it avoids redundant work. // usage. The query is only helpful for nested `HygieneFrame`s as it avoids redundant work.
HygieneFrames(Arc::new(HygieneFrame::new(db, file_id))) HygieneFrames(Arc::new(HygieneFrame::new(db, file_id)))
} }
fn root_crate(&self, db: &dyn AstDatabase, node: &SyntaxNode) -> Option<CrateId> { fn root_crate(&self, db: &dyn ExpandDatabase, node: &SyntaxNode) -> Option<CrateId> {
let mut token = node.first_token()?.text_range(); let mut token = node.first_token()?.text_range();
let mut result = self.0.krate; let mut result = self.0.krate;
let mut current = self.0.clone(); let mut current = self.0.clone();
@ -136,7 +136,7 @@ struct HygieneInfo {
impl HygieneInfo { impl HygieneInfo {
fn map_ident_up( fn map_ident_up(
&self, &self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
token: TextRange, token: TextRange,
) -> Option<(InFile<TextRange>, Origin)> { ) -> Option<(InFile<TextRange>, Origin)> {
let token_id = self.exp_map.token_by_range(token)?; let token_id = self.exp_map.token_by_range(token)?;
@ -175,7 +175,7 @@ impl HygieneInfo {
} }
fn make_hygiene_info( fn make_hygiene_info(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
macro_file: MacroFile, macro_file: MacroFile,
loc: &MacroCallLoc, loc: &MacroCallLoc,
) -> Option<HygieneInfo> { ) -> Option<HygieneInfo> {
@ -215,7 +215,7 @@ fn make_hygiene_info(
} }
impl HygieneFrame { impl HygieneFrame {
pub(crate) fn new(db: &dyn AstDatabase, file_id: HirFileId) -> HygieneFrame { pub(crate) fn new(db: &dyn ExpandDatabase, file_id: HirFileId) -> HygieneFrame {
let (info, krate, local_inner) = match file_id.macro_file() { let (info, krate, local_inner) = match file_id.macro_file() {
None => (None, None, false), None => (None, None, false),
Some(macro_file) => { Some(macro_file) => {

View file

@ -198,7 +198,7 @@ impl HirFileId {
/// For macro-expansion files, returns the file original source file the /// For macro-expansion files, returns the file original source file the
/// expansion originated from. /// expansion originated from.
pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId { pub fn original_file(self, db: &dyn db::ExpandDatabase) -> FileId {
let mut file_id = self; let mut file_id = self;
loop { loop {
match file_id.repr() { match file_id.repr() {
@ -214,7 +214,7 @@ impl HirFileId {
} }
} }
pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 { pub fn expansion_level(self, db: &dyn db::ExpandDatabase) -> u32 {
let mut level = 0; let mut level = 0;
let mut curr = self; let mut curr = self;
while let Some(macro_file) = curr.macro_file() { while let Some(macro_file) = curr.macro_file() {
@ -227,14 +227,14 @@ impl HirFileId {
} }
/// If this is a macro call, returns the syntax node of the call. /// If this is a macro call, returns the syntax node of the call.
pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { pub fn call_node(self, db: &dyn db::ExpandDatabase) -> Option<InFile<SyntaxNode>> {
let macro_file = self.macro_file()?; let macro_file = self.macro_file()?;
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
Some(loc.kind.to_node(db)) Some(loc.kind.to_node(db))
} }
/// If this is a macro call, returns the syntax node of the very first macro call this file resides in. /// If this is a macro call, returns the syntax node of the very first macro call this file resides in.
pub fn original_call_node(self, db: &dyn db::AstDatabase) -> Option<(FileId, SyntaxNode)> { pub fn original_call_node(self, db: &dyn db::ExpandDatabase) -> Option<(FileId, SyntaxNode)> {
let mut call = let mut call =
db.lookup_intern_macro_call(self.macro_file()?.macro_call_id).kind.to_node(db); db.lookup_intern_macro_call(self.macro_file()?.macro_call_id).kind.to_node(db);
loop { loop {
@ -248,7 +248,7 @@ impl HirFileId {
} }
/// Return expansion information if it is a macro-expansion file /// Return expansion information if it is a macro-expansion file
pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> { pub fn expansion_info(self, db: &dyn db::ExpandDatabase) -> Option<ExpansionInfo> {
let macro_file = self.macro_file()?; let macro_file = self.macro_file()?;
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
@ -294,7 +294,7 @@ impl HirFileId {
} }
/// Indicate it is macro file generated for builtin derive /// Indicate it is macro file generated for builtin derive
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Attr>> { pub fn is_builtin_derive(&self, db: &dyn db::ExpandDatabase) -> Option<InFile<ast::Attr>> {
let macro_file = self.macro_file()?; let macro_file = self.macro_file()?;
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let attr = match loc.def.kind { let attr = match loc.def.kind {
@ -304,7 +304,7 @@ impl HirFileId {
Some(attr.with_value(ast::Attr::cast(attr.value.clone())?)) Some(attr.with_value(ast::Attr::cast(attr.value.clone())?))
} }
pub fn is_custom_derive(&self, db: &dyn db::AstDatabase) -> bool { pub fn is_custom_derive(&self, db: &dyn db::ExpandDatabase) -> bool {
match self.macro_file() { match self.macro_file() {
Some(macro_file) => { Some(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
@ -315,7 +315,7 @@ impl HirFileId {
} }
/// Return whether this file is an include macro /// Return whether this file is an include macro
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool { pub fn is_include_macro(&self, db: &dyn db::ExpandDatabase) -> bool {
match self.macro_file() { match self.macro_file() {
Some(macro_file) => { Some(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
@ -326,7 +326,7 @@ impl HirFileId {
} }
/// Return whether this file is an attr macro /// Return whether this file is an attr macro
pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool { pub fn is_attr_macro(&self, db: &dyn db::ExpandDatabase) -> bool {
match self.macro_file() { match self.macro_file() {
Some(macro_file) => { Some(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
@ -338,7 +338,7 @@ impl HirFileId {
/// Return whether this file is the pseudo expansion of the derive attribute. /// Return whether this file is the pseudo expansion of the derive attribute.
/// See [`crate::builtin_attr_macro::derive_attr_expand`]. /// See [`crate::builtin_attr_macro::derive_attr_expand`].
pub fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::AstDatabase) -> bool { pub fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::ExpandDatabase) -> bool {
match self.macro_file() { match self.macro_file() {
Some(macro_file) => { Some(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id); let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
@ -384,7 +384,7 @@ impl HirFileId {
impl MacroDefId { impl MacroDefId {
pub fn as_lazy_macro( pub fn as_lazy_macro(
self, self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
krate: CrateId, krate: CrateId,
kind: MacroCallKind, kind: MacroCallKind,
) -> MacroCallId { ) -> MacroCallId {
@ -427,7 +427,7 @@ impl MacroCallKind {
} }
} }
pub fn to_node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> InFile<SyntaxNode> {
match self { match self {
MacroCallKind::FnLike { ast_id, .. } => { MacroCallKind::FnLike { ast_id, .. } => {
ast_id.with_value(ast_id.to_node(db).syntax().clone()) ast_id.with_value(ast_id.to_node(db).syntax().clone())
@ -465,7 +465,7 @@ impl MacroCallKind {
/// Returns the original file range that best describes the location of this macro call. /// Returns the original file range that best describes the location of this macro call.
/// ///
/// Unlike `MacroCallKind::original_call_range`, this also spans the item of attributes and derives. /// Unlike `MacroCallKind::original_call_range`, this also spans the item of attributes and derives.
pub fn original_call_range_with_body(self, db: &dyn db::AstDatabase) -> FileRange { pub fn original_call_range_with_body(self, db: &dyn db::ExpandDatabase) -> FileRange {
let mut kind = self; let mut kind = self;
let file_id = loop { let file_id = loop {
match kind.file_id().repr() { match kind.file_id().repr() {
@ -490,7 +490,7 @@ impl MacroCallKind {
/// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros /// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros
/// get the whole `ast::MacroCall`, attribute macros get the attribute's range, and derives /// get the whole `ast::MacroCall`, attribute macros get the attribute's range, and derives
/// get only the specific derive that is being referred to. /// get only the specific derive that is being referred to.
pub fn original_call_range(self, db: &dyn db::AstDatabase) -> FileRange { pub fn original_call_range(self, db: &dyn db::ExpandDatabase) -> FileRange {
let mut kind = self; let mut kind = self;
let file_id = loop { let file_id = loop {
match kind.file_id().repr() { match kind.file_id().repr() {
@ -529,7 +529,7 @@ impl MacroCallKind {
FileRange { range, file_id } FileRange { range, file_id }
} }
fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { fn arg(&self, db: &dyn db::ExpandDatabase) -> Option<SyntaxNode> {
match self { match self {
MacroCallKind::FnLike { ast_id, .. } => { MacroCallKind::FnLike { ast_id, .. } => {
Some(ast_id.to_node(db).token_tree()?.syntax().clone()) Some(ast_id.to_node(db).token_tree()?.syntax().clone())
@ -597,7 +597,7 @@ impl ExpansionInfo {
/// Both of these only have one simple call site input so no special handling is required here. /// Both of these only have one simple call site input so no special handling is required here.
pub fn map_token_down( pub fn map_token_down(
&self, &self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
item: Option<ast::Item>, item: Option<ast::Item>,
token: InFile<&SyntaxToken>, token: InFile<&SyntaxToken>,
) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + '_> { ) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + '_> {
@ -666,7 +666,7 @@ impl ExpansionInfo {
/// Map a token up out of the expansion it resides in into the arguments of the macro call of the expansion. /// Map a token up out of the expansion it resides in into the arguments of the macro call of the expansion.
pub fn map_token_up( pub fn map_token_up(
&self, &self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
token: InFile<&SyntaxToken>, token: InFile<&SyntaxToken>,
) -> Option<(InFile<SyntaxToken>, Origin)> { ) -> Option<(InFile<SyntaxToken>, Origin)> {
// Fetch the id through its text range, // Fetch the id through its text range,
@ -717,7 +717,7 @@ impl ExpansionInfo {
pub type AstId<N> = InFile<FileAstId<N>>; pub type AstId<N> = InFile<FileAstId<N>>;
impl<N: AstNode> AstId<N> { impl<N: AstNode> AstId<N> {
pub fn to_node(&self, db: &dyn db::AstDatabase) -> N { pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> N {
let root = db.parse_or_expand(self.file_id).unwrap(); let root = db.parse_or_expand(self.file_id).unwrap();
db.ast_id_map(self.file_id).get(self.value).to_node(&root) db.ast_id_map(self.file_id).get(self.value).to_node(&root)
} }
@ -753,7 +753,7 @@ impl<T> InFile<T> {
self.with_value(&self.value) self.with_value(&self.value)
} }
pub fn file_syntax(&self, db: &dyn db::AstDatabase) -> SyntaxNode { pub fn file_syntax(&self, db: &dyn db::ExpandDatabase) -> SyntaxNode {
db.parse_or_expand(self.file_id).expect("source created from invalid file") db.parse_or_expand(self.file_id).expect("source created from invalid file")
} }
} }
@ -783,7 +783,7 @@ impl<L, R> InFile<Either<L, R>> {
impl<'a> InFile<&'a SyntaxNode> { impl<'a> InFile<&'a SyntaxNode> {
pub fn ancestors_with_macros( pub fn ancestors_with_macros(
self, self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ { ) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
iter::successors(Some(self.cloned()), move |node| match node.value.parent() { iter::successors(Some(self.cloned()), move |node| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)), Some(parent) => Some(node.with_value(parent)),
@ -794,7 +794,7 @@ impl<'a> InFile<&'a SyntaxNode> {
/// Skips the attributed item that caused the macro invocation we are climbing up /// Skips the attributed item that caused the macro invocation we are climbing up
pub fn ancestors_with_macros_skip_attr_item( pub fn ancestors_with_macros_skip_attr_item(
self, self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ { ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() { let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)), Some(parent) => Some(node.with_value(parent)),
@ -816,7 +816,7 @@ impl<'a> InFile<&'a SyntaxNode> {
/// ///
/// For attributes and derives, this will point back to the attribute only. /// For attributes and derives, this will point back to the attribute only.
/// For the entire item use [`InFile::original_file_range_full`]. /// For the entire item use [`InFile::original_file_range_full`].
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange { pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> FileRange {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
HirFileIdRepr::MacroFile(mac_file) => { HirFileIdRepr::MacroFile(mac_file) => {
@ -831,7 +831,7 @@ impl<'a> InFile<&'a SyntaxNode> {
} }
/// Falls back to the macro call range if the node cannot be mapped up fully. /// Falls back to the macro call range if the node cannot be mapped up fully.
pub fn original_file_range_full(self, db: &dyn db::AstDatabase) -> FileRange { pub fn original_file_range_full(self, db: &dyn db::ExpandDatabase) -> FileRange {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
HirFileIdRepr::MacroFile(mac_file) => { HirFileIdRepr::MacroFile(mac_file) => {
@ -846,7 +846,7 @@ impl<'a> InFile<&'a SyntaxNode> {
} }
/// Attempts to map the syntax node back up its macro calls. /// Attempts to map the syntax node back up its macro calls.
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> { pub fn original_file_range_opt(self, db: &dyn db::ExpandDatabase) -> Option<FileRange> {
match ascend_node_border_tokens(db, self) { match ascend_node_border_tokens(db, self) {
Some(InFile { file_id, value: (first, last) }) => { Some(InFile { file_id, value: (first, last) }) => {
let original_file = file_id.original_file(db); let original_file = file_id.original_file(db);
@ -865,7 +865,7 @@ impl<'a> InFile<&'a SyntaxNode> {
} }
} }
pub fn original_syntax_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { pub fn original_syntax_node(self, db: &dyn db::ExpandDatabase) -> Option<InFile<SyntaxNode>> {
// This kind of upmapping can only be achieved in attribute expanded files, // This kind of upmapping can only be achieved in attribute expanded files,
// as we don't have node inputs otherwise and therefore can't find an `N` node in the input // as we don't have node inputs otherwise and therefore can't find an `N` node in the input
if !self.file_id.is_macro() { if !self.file_id.is_macro() {
@ -892,13 +892,13 @@ impl<'a> InFile<&'a SyntaxNode> {
} }
impl InFile<SyntaxToken> { impl InFile<SyntaxToken> {
pub fn upmap(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxToken>> { pub fn upmap(self, db: &dyn db::ExpandDatabase) -> Option<InFile<SyntaxToken>> {
let expansion = self.file_id.expansion_info(db)?; let expansion = self.file_id.expansion_info(db)?;
expansion.map_token_up(db, self.as_ref()).map(|(it, _)| it) expansion.map_token_up(db, self.as_ref()).map(|(it, _)| it)
} }
/// Falls back to the macro call range if the node cannot be mapped up fully. /// Falls back to the macro call range if the node cannot be mapped up fully.
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange { pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> FileRange {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
HirFileIdRepr::MacroFile(mac_file) => { HirFileIdRepr::MacroFile(mac_file) => {
@ -913,7 +913,7 @@ impl InFile<SyntaxToken> {
} }
/// Attempts to map the syntax node back up its macro calls. /// Attempts to map the syntax node back up its macro calls.
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> { pub fn original_file_range_opt(self, db: &dyn db::ExpandDatabase) -> Option<FileRange> {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => { HirFileIdRepr::FileId(file_id) => {
Some(FileRange { file_id, range: self.value.text_range() }) Some(FileRange { file_id, range: self.value.text_range() })
@ -932,7 +932,7 @@ impl InFile<SyntaxToken> {
pub fn ancestors_with_macros( pub fn ancestors_with_macros(
self, self,
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ { ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
self.value.parent().into_iter().flat_map({ self.value.parent().into_iter().flat_map({
let file_id = self.file_id; let file_id = self.file_id;
@ -942,7 +942,7 @@ impl InFile<SyntaxToken> {
} }
fn ascend_node_border_tokens( fn ascend_node_border_tokens(
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
InFile { file_id, value: node }: InFile<&SyntaxNode>, InFile { file_id, value: node }: InFile<&SyntaxNode>,
) -> Option<InFile<(SyntaxToken, SyntaxToken)>> { ) -> Option<InFile<(SyntaxToken, SyntaxToken)>> {
let expansion = file_id.expansion_info(db)?; let expansion = file_id.expansion_info(db)?;
@ -958,7 +958,7 @@ fn ascend_node_border_tokens(
} }
fn ascend_call_token( fn ascend_call_token(
db: &dyn db::AstDatabase, db: &dyn db::ExpandDatabase,
expansion: &ExpansionInfo, expansion: &ExpansionInfo,
token: InFile<SyntaxToken>, token: InFile<SyntaxToken>,
) -> Option<InFile<SyntaxToken>> { ) -> Option<InFile<SyntaxToken>> {
@ -977,7 +977,7 @@ impl<N: AstNode> InFile<N> {
self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n)) self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))
} }
pub fn original_ast_node(self, db: &dyn db::AstDatabase) -> Option<InFile<N>> { pub fn original_ast_node(self, db: &dyn db::ExpandDatabase) -> Option<InFile<N>> {
// This kind of upmapping can only be achieved in attribute expanded files, // This kind of upmapping can only be achieved in attribute expanded files,
// as we don't have node inputs otherwise and therefore can't find an `N` node in the input // as we don't have node inputs otherwise and therefore can't find an `N` node in the input
if !self.file_id.is_macro() { if !self.file_id.is_macro() {

View file

@ -6,7 +6,7 @@ use std::{
}; };
use crate::{ use crate::{
db::AstDatabase, db::ExpandDatabase,
hygiene::Hygiene, hygiene::Hygiene,
name::{known, Name}, name::{known, Name},
}; };
@ -37,7 +37,11 @@ pub enum PathKind {
} }
impl ModPath { impl ModPath {
pub fn from_src(db: &dyn AstDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { pub fn from_src(
db: &dyn ExpandDatabase,
path: ast::Path,
hygiene: &Hygiene,
) -> Option<ModPath> {
convert_path(db, None, path, hygiene) convert_path(db, None, path, hygiene)
} }
@ -162,7 +166,7 @@ impl From<Name> for ModPath {
} }
fn convert_path( fn convert_path(
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
prefix: Option<ModPath>, prefix: Option<ModPath>,
path: ast::Path, path: ast::Path,
hygiene: &Hygiene, hygiene: &Hygiene,

View file

@ -3,7 +3,7 @@
use base_db::{CrateId, ProcMacroExpansionError, ProcMacroId, ProcMacroKind}; use base_db::{CrateId, ProcMacroExpansionError, ProcMacroId, ProcMacroKind};
use stdx::never; use stdx::never;
use crate::{db::AstDatabase, tt, ExpandError, ExpandResult}; use crate::{db::ExpandDatabase, tt, ExpandError, ExpandResult};
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct ProcMacroExpander { pub struct ProcMacroExpander {
@ -27,7 +27,7 @@ impl ProcMacroExpander {
pub fn expand( pub fn expand(
self, self,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
calling_crate: CrateId, calling_crate: CrateId,
tt: &tt::Subtree, tt: &tt::Subtree,
attr_arg: Option<&tt::Subtree>, attr_arg: Option<&tt::Subtree>,

View file

@ -9,7 +9,7 @@ use base_db::{
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
}; };
use hir_def::{db::DefDatabase, ModuleId}; use hir_def::{db::DefDatabase, ModuleId};
use hir_expand::db::AstDatabase; use hir_expand::db::ExpandDatabase;
use stdx::hash::{NoHashHashMap, NoHashHashSet}; use stdx::hash::{NoHashHashMap, NoHashHashSet};
use syntax::TextRange; use syntax::TextRange;
use test_utils::extract_annotations; use test_utils::extract_annotations;
@ -17,7 +17,7 @@ use test_utils::extract_annotations;
#[salsa::database( #[salsa::database(
base_db::SourceDatabaseExtStorage, base_db::SourceDatabaseExtStorage,
base_db::SourceDatabaseStorage, base_db::SourceDatabaseStorage,
hir_expand::db::AstDatabaseStorage, hir_expand::db::ExpandDatabaseStorage,
hir_def::db::InternDatabaseStorage, hir_def::db::InternDatabaseStorage,
hir_def::db::DefDatabaseStorage, hir_def::db::DefDatabaseStorage,
crate::db::HirDatabaseStorage crate::db::HirDatabaseStorage
@ -41,8 +41,8 @@ impl fmt::Debug for TestDB {
} }
} }
impl Upcast<dyn AstDatabase> for TestDB { impl Upcast<dyn ExpandDatabase> for TestDB {
fn upcast(&self) -> &(dyn AstDatabase + 'static) { fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
&*self &*self
} }
} }

View file

@ -23,7 +23,7 @@ use hir_def::{
src::HasSource, src::HasSource,
AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId, AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId,
}; };
use hir_expand::{db::AstDatabase, InFile}; use hir_expand::{db::ExpandDatabase, InFile};
use once_cell::race::OnceBool; use once_cell::race::OnceBool;
use stdx::format_to; use stdx::format_to;
use syntax::{ use syntax::{

View file

@ -5,7 +5,7 @@
//! But we need this for at least LRU caching at the query level. //! But we need this for at least LRU caching at the query level.
pub use hir_def::db::*; pub use hir_def::db::*;
pub use hir_expand::db::{ pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, ExpandProcMacroQuery, HygieneFrameQuery, AstIdMapQuery, ExpandDatabase, ExpandDatabaseStorage, ExpandProcMacroQuery, HygieneFrameQuery,
InternMacroCallQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandErrorQuery, InternMacroCallQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandErrorQuery,
MacroExpandQuery, ParseMacroExpansionQuery, MacroExpandQuery, ParseMacroExpansionQuery,
}; };

View file

@ -15,7 +15,7 @@ use hir_def::{
AsMacroCall, DefWithBodyId, FieldId, FunctionId, MacroId, TraitId, VariantId, AsMacroCall, DefWithBodyId, FieldId, FunctionId, MacroId, TraitId, VariantId,
}; };
use hir_expand::{ use hir_expand::{
db::AstDatabase, db::ExpandDatabase,
name::{known, AsName}, name::{known, AsName},
ExpansionInfo, MacroCallId, ExpansionInfo, MacroCallId,
}; };
@ -1536,7 +1536,7 @@ impl<'db> SemanticsImpl<'db> {
fn macro_call_to_macro_id( fn macro_call_to_macro_id(
ctx: &mut SourceToDefCtx<'_, '_>, ctx: &mut SourceToDefCtx<'_, '_>,
db: &dyn AstDatabase, db: &dyn ExpandDatabase,
macro_call_id: MacroCallId, macro_call_id: MacroCallId,
) -> Option<MacroId> { ) -> Option<MacroId> {
let loc = db.lookup_intern_macro_call(macro_call_id); let loc = db.lookup_intern_macro_call(macro_call_id);

View file

@ -1027,7 +1027,7 @@ fn next_space_for_fn_after_call_site(expr: ast::CallableExpr) -> Option<Generate
} }
fn next_space_for_fn_in_module( fn next_space_for_fn_in_module(
db: &dyn hir::db::AstDatabase, db: &dyn hir::db::ExpandDatabase,
module_source: &hir::InFile<hir::ModuleSource>, module_source: &hir::InFile<hir::ModuleSource>,
) -> Option<(FileId, GeneratedFunctionTarget)> { ) -> Option<(FileId, GeneratedFunctionTarget)> {
let file = module_source.file_id.original_file(db); let file = module_source.file_id.original_file(db);

View file

@ -71,7 +71,7 @@ impl RootDatabase {
base_db::SourceRootQuery base_db::SourceRootQuery
base_db::SourceRootCratesQuery base_db::SourceRootCratesQuery
// AstDatabase // ExpandDatabase
hir::db::AstIdMapQuery hir::db::AstIdMapQuery
hir::db::ParseMacroExpansionQuery hir::db::ParseMacroExpansionQuery
hir::db::InternMacroCallQuery hir::db::InternMacroCallQuery

View file

@ -50,7 +50,7 @@ use base_db::{
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
}; };
use hir::{ use hir::{
db::{AstDatabase, DefDatabase, HirDatabase}, db::{DefDatabase, ExpandDatabase, HirDatabase},
symbols::FileSymbolKind, symbols::FileSymbolKind,
}; };
use stdx::hash::NoHashHashSet; use stdx::hash::NoHashHashSet;
@ -68,7 +68,7 @@ pub type FxIndexMap<K, V> =
#[salsa::database( #[salsa::database(
base_db::SourceDatabaseExtStorage, base_db::SourceDatabaseExtStorage,
base_db::SourceDatabaseStorage, base_db::SourceDatabaseStorage,
hir::db::AstDatabaseStorage, hir::db::ExpandDatabaseStorage,
hir::db::DefDatabaseStorage, hir::db::DefDatabaseStorage,
hir::db::HirDatabaseStorage, hir::db::HirDatabaseStorage,
hir::db::InternDatabaseStorage, hir::db::InternDatabaseStorage,
@ -95,8 +95,8 @@ impl fmt::Debug for RootDatabase {
} }
} }
impl Upcast<dyn AstDatabase> for RootDatabase { impl Upcast<dyn ExpandDatabase> for RootDatabase {
fn upcast(&self) -> &(dyn AstDatabase + 'static) { fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
&*self &*self
} }
} }

View file

@ -1,4 +1,4 @@
use hir::{db::AstDatabase, InFile}; use hir::{db::ExpandDatabase, InFile};
use ide_db::{assists::Assist, defs::NameClass}; use ide_db::{assists::Assist, defs::NameClass};
use syntax::AstNode; use syntax::AstNode;

View file

@ -1,6 +1,6 @@
use either::Either; use either::Either;
use hir::{ use hir::{
db::{AstDatabase, HirDatabase}, db::{ExpandDatabase, HirDatabase},
known, AssocItem, HirDisplay, InFile, Type, known, AssocItem, HirDisplay, InFile, Type,
}; };
use ide_db::{ use ide_db::{

View file

@ -1,4 +1,4 @@
use hir::{db::AstDatabase, HasSource, HirDisplay, Semantics}; use hir::{db::ExpandDatabase, HasSource, HirDisplay, Semantics};
use ide_db::{base_db::FileId, source_change::SourceChange, RootDatabase}; use ide_db::{base_db::FileId, source_change::SourceChange, RootDatabase};
use syntax::{ use syntax::{
ast::{self, edit::IndentLevel, make}, ast::{self, edit::IndentLevel, make},

View file

@ -1,4 +1,4 @@
use hir::{db::AstDatabase, InFile}; use hir::{db::ExpandDatabase, InFile};
use ide_db::source_change::SourceChange; use ide_db::source_change::SourceChange;
use syntax::{ use syntax::{
ast::{self, HasArgList}, ast::{self, HasArgList},

View file

@ -1,5 +1,5 @@
use either::Either; use either::Either;
use hir::{db::AstDatabase, HirDisplay, InFile, Type}; use hir::{db::ExpandDatabase, HirDisplay, InFile, Type};
use ide_db::{famous_defs::FamousDefs, source_change::SourceChange}; use ide_db::{famous_defs::FamousDefs, source_change::SourceChange};
use syntax::{ use syntax::{
ast::{self, BlockExpr, ExprStmt}, ast::{self, BlockExpr, ExprStmt},

View file

@ -1,4 +1,4 @@
use hir::{db::AstDatabase, HirDisplay, InFile}; use hir::{db::ExpandDatabase, HirDisplay, InFile};
use ide_db::{ use ide_db::{
assists::{Assist, AssistId, AssistKind}, assists::{Assist, AssistId, AssistKind},
base_db::FileRange, base_db::FileRange,

View file

@ -1,4 +1,4 @@
use hir::{db::AstDatabase, HirDisplay}; use hir::{db::ExpandDatabase, HirDisplay};
use ide_db::{ use ide_db::{
assists::{Assist, AssistId, AssistKind}, assists::{Assist, AssistId, AssistKind},
base_db::FileRange, base_db::FileRange,

View file

@ -1,4 +1,4 @@
use hir::db::AstDatabase; use hir::db::ExpandDatabase;
use ide_db::{assists::Assist, base_db::AnchoredPathBuf, source_change::FileSystemEdit}; use ide_db::{assists::Assist, base_db::AnchoredPathBuf, source_change::FileSystemEdit};
use itertools::Itertools; use itertools::Itertools;
use syntax::AstNode; use syntax::AstNode;

View file

@ -7,7 +7,7 @@ use std::{
}; };
use hir::{ use hir::{
db::{AstDatabase, DefDatabase, HirDatabase}, db::{DefDatabase, ExpandDatabase, HirDatabase},
AssocItem, Crate, Function, HasSource, HirDisplay, ModuleDef, AssocItem, Crate, Function, HasSource, HirDisplay, ModuleDef,
}; };
use hir_def::{ use hir_def::{