Skip to content

Commit 6a98e96

Browse files
committed
Auto merge of rust-lang#14340 - Veykril:expand, r=lnicola
internal: Rename AstDatabase to ExpandDatabase
2 parents def4dbb + aaf08bd commit 6a98e96

31 files changed

+177
-168
lines changed

bench_data/numerous_macro_rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ macro_rules! __ra_macro_fixture339 {($name : ident )=>{ impl Clone for $name
341341
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 )*); }; }
342342
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 ()}}}; }
343343
macro_rules! __ra_macro_fixture342 {($($ident : ident ),* $(,)?)=>{$(# [ allow ( bad_style )] pub const $ident : super :: Name = super :: Name :: new_inline ( stringify ! ($ident )); )* }; }
344-
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 , }}}}; }
345-
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 , }}}; }
344+
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 , }}}}; }
345+
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 , }}}; }
346346
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 ()}})* }}
347347
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 }}}; }
348348
macro_rules! __ra_macro_fixture347 {($($var : ident ($t : ty )),+ )=>{$(impl From <$t > for AttrOwner { fn from ( t : $t )-> AttrOwner { AttrOwner ::$var ( t )}})+ }; }

crates/hir-def/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
55
use either::Either;
6-
use hir_expand::{db::AstDatabase, HirFileId};
6+
use hir_expand::{db::ExpandDatabase, HirFileId};
77
use intern::Interned;
88
use la_arena::ArenaMap;
99
use syntax::{ast, AstPtr};
@@ -64,7 +64,7 @@ pub trait InternDatabase: SourceDatabase {
6464
}
6565

6666
#[salsa::query_group(DefDatabaseStorage)]
67-
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
67+
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
6868
#[salsa::input]
6969
fn enable_proc_attr_macros(&self) -> bool;
7070

crates/hir-def/src/macro_expansion_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ::mbe::TokenMap;
2020
use base_db::{fixture::WithFixture, ProcMacro, SourceDatabase};
2121
use expect_test::Expect;
2222
use hir_expand::{
23-
db::{AstDatabase, TokenExpander},
23+
db::{ExpandDatabase, TokenExpander},
2424
AstId, InFile, MacroDefId, MacroDefKind, MacroFile,
2525
};
2626
use stdx::format_to;

crates/hir-def/src/nameres/collector.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
8787
// FIXME: a hacky way to create a Name from string.
8888
let name =
8989
tt::Ident { text: it.name.clone(), span: tt::TokenId::unspecified() };
90-
(
91-
name.as_name(),
92-
ProcMacroExpander::new(def_map.krate, base_db::ProcMacroId(idx as u32)),
93-
)
90+
(name.as_name(), ProcMacroExpander::new(base_db::ProcMacroId(idx as u32)))
9491
})
9592
.collect()
9693
}
@@ -581,7 +578,7 @@ impl DefCollector<'_> {
581578
let kind = def.kind.to_basedb_kind();
582579
let (expander, kind) = match self.proc_macros.iter().find(|(n, _)| n == &def.name) {
583580
Some(&(_, expander)) => (expander, kind),
584-
None => (ProcMacroExpander::dummy(self.def_map.krate), kind),
581+
None => (ProcMacroExpander::dummy(), kind),
585582
};
586583

587584
let proc_macro_id =

crates/hir-def/src/test_db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use base_db::{
99
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition,
1010
SourceDatabase, Upcast,
1111
};
12-
use hir_expand::{db::AstDatabase, InFile};
12+
use hir_expand::{db::ExpandDatabase, InFile};
1313
use stdx::hash::NoHashHashSet;
1414
use syntax::{algo, ast, AstNode};
1515

@@ -23,7 +23,7 @@ use crate::{
2323
#[salsa::database(
2424
base_db::SourceDatabaseExtStorage,
2525
base_db::SourceDatabaseStorage,
26-
hir_expand::db::AstDatabaseStorage,
26+
hir_expand::db::ExpandDatabaseStorage,
2727
crate::db::InternDatabaseStorage,
2828
crate::db::DefDatabaseStorage
2929
)]
@@ -40,8 +40,8 @@ impl Default for TestDB {
4040
}
4141
}
4242

43-
impl Upcast<dyn AstDatabase> for TestDB {
44-
fn upcast(&self) -> &(dyn AstDatabase + 'static) {
43+
impl Upcast<dyn ExpandDatabase> for TestDB {
44+
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
4545
&*self
4646
}
4747
}

crates/hir-expand/src/attrs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use smallvec::{smallvec, SmallVec};
1010
use syntax::{ast, match_ast, AstNode, SmolStr, SyntaxNode};
1111

1212
use crate::{
13-
db::AstDatabase,
13+
db::ExpandDatabase,
1414
hygiene::Hygiene,
1515
mod_path::{ModPath, PathKind},
1616
name::AsName,
@@ -38,7 +38,7 @@ impl ops::Deref for RawAttrs {
3838
impl RawAttrs {
3939
pub const EMPTY: Self = Self { entries: None };
4040

41-
pub fn new(db: &dyn AstDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
41+
pub fn new(db: &dyn ExpandDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
4242
let entries = collect_attrs(owner)
4343
.filter_map(|(id, attr)| match attr {
4444
Either::Left(attr) => {
@@ -55,7 +55,7 @@ impl RawAttrs {
5555
Self { entries: if entries.is_empty() { None } else { Some(entries) } }
5656
}
5757

58-
pub fn from_attrs_owner(db: &dyn AstDatabase, owner: InFile<&dyn ast::HasAttrs>) -> Self {
58+
pub fn from_attrs_owner(db: &dyn ExpandDatabase, owner: InFile<&dyn ast::HasAttrs>) -> Self {
5959
let hygiene = Hygiene::new(db, owner.file_id);
6060
Self::new(db, owner.value, &hygiene)
6161
}
@@ -87,7 +87,7 @@ impl RawAttrs {
8787

8888
/// Processes `cfg_attr`s, returning the resulting semantic `Attrs`.
8989
// FIXME: This should return a different type
90-
pub fn filter(self, db: &dyn AstDatabase, krate: CrateId) -> RawAttrs {
90+
pub fn filter(self, db: &dyn ExpandDatabase, krate: CrateId) -> RawAttrs {
9191
let has_cfg_attrs = self
9292
.iter()
9393
.any(|attr| attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]));
@@ -199,7 +199,7 @@ impl fmt::Display for AttrInput {
199199

200200
impl Attr {
201201
fn from_src(
202-
db: &dyn AstDatabase,
202+
db: &dyn ExpandDatabase,
203203
ast: ast::Meta,
204204
hygiene: &Hygiene,
205205
id: AttrId,
@@ -221,7 +221,7 @@ impl Attr {
221221
}
222222

223223
fn from_tt(
224-
db: &dyn AstDatabase,
224+
db: &dyn ExpandDatabase,
225225
tt: &tt::Subtree,
226226
hygiene: &Hygiene,
227227
id: AttrId,

crates/hir-expand/src/builtin_attr_macro.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Builtin attributes.
22
3-
use crate::{db::AstDatabase, name, tt, ExpandResult, MacroCallId, MacroCallKind};
3+
use crate::{db::ExpandDatabase, name, tt, ExpandResult, MacroCallId, MacroCallKind};
44

55
macro_rules! register_builtin {
66
( $(($name:ident, $variant:ident) => $expand:ident),* ) => {
@@ -12,7 +12,7 @@ macro_rules! register_builtin {
1212
impl BuiltinAttrExpander {
1313
pub fn expand(
1414
&self,
15-
db: &dyn AstDatabase,
15+
db: &dyn ExpandDatabase,
1616
id: MacroCallId,
1717
tt: &tt::Subtree,
1818
) -> ExpandResult<tt::Subtree> {
@@ -60,7 +60,7 @@ pub fn find_builtin_attr(ident: &name::Name) -> Option<BuiltinAttrExpander> {
6060
}
6161

6262
fn dummy_attr_expand(
63-
_db: &dyn AstDatabase,
63+
_db: &dyn ExpandDatabase,
6464
_id: MacroCallId,
6565
tt: &tt::Subtree,
6666
) -> ExpandResult<tt::Subtree> {
@@ -90,7 +90,7 @@ fn dummy_attr_expand(
9090
/// So this hacky approach is a lot more friendly for us, though it does require a bit of support in
9191
/// [`hir::Semantics`] to make this work.
9292
fn derive_attr_expand(
93-
db: &dyn AstDatabase,
93+
db: &dyn ExpandDatabase,
9494
id: MacroCallId,
9595
tt: &tt::Subtree,
9696
) -> ExpandResult<tt::Subtree> {

crates/hir-expand/src/builtin_derive_macro.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use syntax::{
99
match_ast,
1010
};
1111

12-
use crate::{db::AstDatabase, name, quote, ExpandError, ExpandResult, MacroCallId};
12+
use crate::{db::ExpandDatabase, name, quote, ExpandError, ExpandResult, MacroCallId};
1313

1414
macro_rules! register_builtin {
1515
( $($trait:ident => $expand:ident),* ) => {
@@ -21,7 +21,7 @@ macro_rules! register_builtin {
2121
impl BuiltinDeriveExpander {
2222
pub fn expand(
2323
&self,
24-
db: &dyn AstDatabase,
24+
db: &dyn ExpandDatabase,
2525
id: MacroCallId,
2626
tt: &tt::Subtree,
2727
) -> ExpandResult<tt::Subtree> {
@@ -141,7 +141,7 @@ fn expand_simple_derive(tt: &tt::Subtree, trait_path: tt::Subtree) -> ExpandResu
141141
ExpandResult::ok(expanded)
142142
}
143143

144-
fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree {
144+
fn find_builtin_crate(db: &dyn ExpandDatabase, id: MacroCallId) -> tt::TokenTree {
145145
// FIXME: make hygiene works for builtin derive macro
146146
// such that $crate can be used here.
147147
let cg = db.crate_graph();
@@ -158,7 +158,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree {
158158
}
159159

160160
fn copy_expand(
161-
db: &dyn AstDatabase,
161+
db: &dyn ExpandDatabase,
162162
id: MacroCallId,
163163
tt: &tt::Subtree,
164164
) -> ExpandResult<tt::Subtree> {
@@ -167,7 +167,7 @@ fn copy_expand(
167167
}
168168

169169
fn clone_expand(
170-
db: &dyn AstDatabase,
170+
db: &dyn ExpandDatabase,
171171
id: MacroCallId,
172172
tt: &tt::Subtree,
173173
) -> ExpandResult<tt::Subtree> {
@@ -176,7 +176,7 @@ fn clone_expand(
176176
}
177177

178178
fn default_expand(
179-
db: &dyn AstDatabase,
179+
db: &dyn ExpandDatabase,
180180
id: MacroCallId,
181181
tt: &tt::Subtree,
182182
) -> ExpandResult<tt::Subtree> {
@@ -185,7 +185,7 @@ fn default_expand(
185185
}
186186

187187
fn debug_expand(
188-
db: &dyn AstDatabase,
188+
db: &dyn ExpandDatabase,
189189
id: MacroCallId,
190190
tt: &tt::Subtree,
191191
) -> ExpandResult<tt::Subtree> {
@@ -194,21 +194,25 @@ fn debug_expand(
194194
}
195195

196196
fn hash_expand(
197-
db: &dyn AstDatabase,
197+
db: &dyn ExpandDatabase,
198198
id: MacroCallId,
199199
tt: &tt::Subtree,
200200
) -> ExpandResult<tt::Subtree> {
201201
let krate = find_builtin_crate(db, id);
202202
expand_simple_derive(tt, quote! { #krate::hash::Hash })
203203
}
204204

205-
fn eq_expand(db: &dyn AstDatabase, id: MacroCallId, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> {
205+
fn eq_expand(
206+
db: &dyn ExpandDatabase,
207+
id: MacroCallId,
208+
tt: &tt::Subtree,
209+
) -> ExpandResult<tt::Subtree> {
206210
let krate = find_builtin_crate(db, id);
207211
expand_simple_derive(tt, quote! { #krate::cmp::Eq })
208212
}
209213

210214
fn partial_eq_expand(
211-
db: &dyn AstDatabase,
215+
db: &dyn ExpandDatabase,
212216
id: MacroCallId,
213217
tt: &tt::Subtree,
214218
) -> ExpandResult<tt::Subtree> {
@@ -217,7 +221,7 @@ fn partial_eq_expand(
217221
}
218222

219223
fn ord_expand(
220-
db: &dyn AstDatabase,
224+
db: &dyn ExpandDatabase,
221225
id: MacroCallId,
222226
tt: &tt::Subtree,
223227
) -> ExpandResult<tt::Subtree> {
@@ -226,7 +230,7 @@ fn ord_expand(
226230
}
227231

228232
fn partial_ord_expand(
229-
db: &dyn AstDatabase,
233+
db: &dyn ExpandDatabase,
230234
id: MacroCallId,
231235
tt: &tt::Subtree,
232236
) -> ExpandResult<tt::Subtree> {

0 commit comments

Comments
 (0)