Unnamed repository; edit this file 'description' to name the repository.
rm `ExpandDatabase`
30 files changed, 235 insertions, 281 deletions
diff --git a/Cargo.lock b/Cargo.lock index 2a45b6ea4f..75e531e5bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,7 +891,6 @@ dependencies = [ "itertools 0.15.0", "mbe", "parser", - "query-group-macro", "rustc-hash 2.1.2", "salsa", "salsa-macros", diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index d1190686fc..9cfb3621a8 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -2,7 +2,6 @@ use base_db::{Crate, SourceDatabase}; use hir_expand::{ EditionedFileId, HirFileId, InFile, Lookup, MacroCallId, MacroDefId, MacroDefKind, - db::ExpandDatabase, }; use salsa::{Durability, Setter}; use triomphe::Arc; @@ -16,7 +15,7 @@ use crate::{ }; #[query_group::query_group] -pub trait DefDatabase: ExpandDatabase + SourceDatabase { +pub trait DefDatabase: SourceDatabase { /// Computes an [`ItemTree`] for the given file or macro expansion. #[salsa::invoke(file_item_tree)] #[salsa::transparent] diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs index 2172e2412b..1d24a4604d 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -61,13 +61,12 @@ mod test_db; use std::hash::{Hash, Hasher}; -use base_db::{Crate, impl_intern_key}; +use base_db::{Crate, SourceDatabase, impl_intern_key}; use hir_expand::{ AstId, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroCallStyles, MacroDefId, MacroDefKind, attrs::AttrId, builtin::{BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander}, - db::ExpandDatabase, eager::expand_eager_macro_input, impl_intern_lookup, mod_path::ModPath, @@ -1312,7 +1311,7 @@ impl<T: AstIdNode> AstIdWithPath<T> { } pub fn macro_call_as_call_id( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ast_id: AstId<ast::MacroCall>, path: &ModPath, call_site: SyntaxContext, diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index 5cca220967..a4f7d9c678 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -16,11 +16,11 @@ mod proc_macros; use std::{any::TypeId, iter, ops::Range, sync}; +use base_db::SourceDatabase; use expect_test::Expect; use hir_expand::{ AstId, ExpansionInfo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroKind, builtin::quote::quote, - db::ExpandDatabase, proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind}, span_map::SpanMap, }; @@ -387,7 +387,7 @@ struct IdentityWhenValidProcMacroExpander; impl ProcMacroExpander for IdentityWhenValidProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &base_db::Env, diff --git a/crates/hir-expand/Cargo.toml b/crates/hir-expand/Cargo.toml index 43b0bea891..9af75a0d8a 100644 --- a/crates/hir-expand/Cargo.toml +++ b/crates/hir-expand/Cargo.toml @@ -20,7 +20,6 @@ rustc-hash.workspace = true itertools.workspace = true smallvec.workspace = true triomphe.workspace = true -query-group.workspace = true salsa.workspace = true salsa-macros.workspace = true thin-vec.workspace = true diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs index 896baacf04..f5e581e8cf 100644 --- a/crates/hir-expand/src/attrs.rs +++ b/crates/hir-expand/src/attrs.rs @@ -17,7 +17,7 @@ use std::{borrow::Cow, cell::OnceCell, convert::Infallible, fmt, ops::ControlFlow}; use ::tt::TextRange; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use cfg::{CfgExpr, CfgOptions}; use either::Either; use intern::Interned; @@ -30,7 +30,6 @@ use syntax_bridge::DocCommentDesugarMode; use crate::{ AstId, - db::ExpandDatabase, mod_path::ModPath, span_map::SpanMap, tt::{self, TopSubtree}, @@ -293,7 +292,7 @@ impl Attr { /// Parses this attribute as a token tree consisting of comma separated paths. pub fn parse_path_comma_token_tree<'a>( &'a self, - db: &'a dyn ExpandDatabase, + db: &'a dyn SourceDatabase, ) -> Option<impl Iterator<Item = (ModPath, Span, tt::TokenTreesView<'a>)> + 'a> { let args = self.token_tree_value()?; @@ -305,7 +304,7 @@ impl Attr { } fn parse_path_comma_token_tree<'a>( - db: &'a dyn ExpandDatabase, + db: &'a dyn SourceDatabase, args: &'a tt::TopSubtree, ) -> impl Iterator<Item = (ModPath, Span, tt::TokenTreesView<'a>)> { args.token_trees() @@ -366,7 +365,7 @@ impl AttrId { /// to `cfg_attr`) and its [`ast::Meta`]. pub fn find_attr_range<N: ast::HasAttrs>( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, owner: AstId<N>, ) -> (ast::Attr, ast::Meta) { @@ -380,7 +379,7 @@ impl AttrId { /// original file (not speculatively expanded macro output). pub fn find_attr_range_with_source( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, owner: &dyn ast::HasAttrs, ) -> (ast::Attr, ast::Meta) { @@ -393,7 +392,7 @@ impl AttrId { /// to `cfg_attr`) and its [`ast::Meta`]. pub(crate) fn find_attr_range_with_source_opt( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, owner: &dyn ast::HasAttrs, ) -> Option<(ast::Attr, ast::Meta)> { @@ -418,7 +417,7 @@ impl AttrId { pub fn find_derive_range( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, owner: AstId<ast::Adt>, derive_index: u32, diff --git a/crates/hir-expand/src/builtin/attr_macro.rs b/crates/hir-expand/src/builtin/attr_macro.rs index 9b13f9fb00..540b3e66ce 100644 --- a/crates/hir-expand/src/builtin/attr_macro.rs +++ b/crates/hir-expand/src/builtin/attr_macro.rs @@ -1,8 +1,9 @@ //! Builtin attributes. +use base_db::SourceDatabase; use intern::sym; use span::Span; -use crate::{ExpandResult, MacroCallId, MacroCallKind, db::ExpandDatabase, name, tt}; +use crate::{ExpandResult, MacroCallId, MacroCallKind, name, tt}; use super::quote; @@ -14,7 +15,7 @@ macro_rules! register_builtin { } impl BuiltinAttrExpander { - pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { + pub fn expander(&self) -> fn (&dyn SourceDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { match *self { $( BuiltinAttrExpander::$variant => $expand, )* } @@ -34,7 +35,7 @@ macro_rules! register_builtin { impl BuiltinAttrExpander { pub fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -74,7 +75,7 @@ pub fn find_builtin_attr(ident: &name::Name) -> Option<BuiltinAttrExpander> { } fn dummy_attr_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, _span: Span, @@ -83,7 +84,7 @@ fn dummy_attr_expand( } fn dummy_gate_test_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -117,7 +118,7 @@ fn dummy_gate_test_expand( /// 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. fn derive_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, diff --git a/crates/hir-expand/src/builtin/derive_macro.rs b/crates/hir-expand/src/builtin/derive_macro.rs index 86ee3f153b..5e85a710e0 100644 --- a/crates/hir-expand/src/builtin/derive_macro.rs +++ b/crates/hir-expand/src/builtin/derive_macro.rs @@ -1,5 +1,6 @@ //! Builtin derives. +use base_db::SourceDatabase; use either::Either; use intern::sym; use itertools::{Itertools, izip}; @@ -13,7 +14,6 @@ use tracing::debug; use crate::{ ExpandError, ExpandResult, MacroCallId, builtin::quote::dollar_crate, - db::ExpandDatabase, hygiene::span_with_def_site_ctxt, name::{self, AsName, Name}, span_map::ExpansionSpanMap, @@ -35,7 +35,7 @@ macro_rules! register_builtin { } impl BuiltinDeriveExpander { - pub fn expander(&self) -> fn(&dyn ExpandDatabase, Span, &tt::TopSubtree) -> ExpandResult<tt::TopSubtree> { + pub fn expander(&self) -> fn(&dyn SourceDatabase, Span, &tt::TopSubtree) -> ExpandResult<tt::TopSubtree> { match *self { $( BuiltinDeriveExpander::$trait => $expand, )* } @@ -54,7 +54,7 @@ macro_rules! register_builtin { impl BuiltinDeriveExpander { pub fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -228,7 +228,7 @@ struct AdtParam { // FIXME: This whole thing needs a refactor. Each derive requires its special values, and the result is a mess. fn parse_adt( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, tt: &tt::TopSubtree, call_site: Span, ) -> Result<BasicAdtInfo, ExpandError> { @@ -387,7 +387,7 @@ fn parse_adt_from_syntax( } fn to_adt_syntax( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, tt: &tt::TopSubtree, call_site: Span, ) -> Result<(ast::Adt, span::SpanMap), ExpandError> { @@ -448,7 +448,7 @@ fn name_to_token( /// where B1, ..., BN are the bounds given by `bounds_paths`. Z is a phantom type, and /// therefore does not get bound by the derived trait. fn expand_simple_derive( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, invoc_span: Span, tt: &tt::TopSubtree, trait_path: tt::TopSubtree, @@ -531,7 +531,7 @@ fn expand_simple_derive_with_parsed( } fn copy_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -547,7 +547,7 @@ fn copy_expand( } fn clone_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -602,7 +602,7 @@ fn and_and(span: Span) -> tt::TopSubtree { } fn default_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -667,7 +667,7 @@ fn default_expand( } fn debug_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -740,7 +740,7 @@ fn debug_expand( } fn hash_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -787,7 +787,7 @@ fn hash_expand( } fn eq_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -803,7 +803,7 @@ fn eq_expand( } fn partial_eq_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -875,7 +875,7 @@ fn self_and_other_patterns( } fn ord_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -933,7 +933,7 @@ fn ord_expand( } fn partial_ord_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { @@ -996,7 +996,7 @@ fn partial_ord_expand( } fn coerce_pointee_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, tt: &tt::TopSubtree, ) -> ExpandResult<tt::TopSubtree> { diff --git a/crates/hir-expand/src/builtin/fn_macro.rs b/crates/hir-expand/src/builtin/fn_macro.rs index 68c9fc4a37..5b9fe09077 100644 --- a/crates/hir-expand/src/builtin/fn_macro.rs +++ b/crates/hir-expand/src/builtin/fn_macro.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; -use base_db::AnchoredPath; +use base_db::{AnchoredPath, SourceDatabase}; use cfg::CfgExpr; use either::Either; use intern::{Symbol, sym}; @@ -19,7 +19,6 @@ use syntax_bridge::syntax_node_to_token_tree; use crate::{ EditionedFileId, ExpandError, ExpandResult, MacroCallId, builtin::quote::{WithDelimiter, dollar_crate}, - db::ExpandDatabase, hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt}, name, tt::{self, DelimSpan, TtElement, TtIter}, @@ -38,7 +37,7 @@ macro_rules! register_builtin { } impl BuiltinFnLikeExpander { - fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { + fn expander(&self) -> fn (&dyn SourceDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { match *self { $( BuiltinFnLikeExpander::$kind => $expand, )* } @@ -46,7 +45,7 @@ macro_rules! register_builtin { } impl EagerExpander { - fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { + fn expander(&self) -> fn (&dyn SourceDatabase, MacroCallId, &tt::TopSubtree, Span) -> ExpandResult<tt::TopSubtree> { match *self { $( EagerExpander::$e_kind => $e_expand, )* } @@ -66,7 +65,7 @@ macro_rules! register_builtin { impl BuiltinFnLikeExpander { pub fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -83,7 +82,7 @@ impl BuiltinFnLikeExpander { impl EagerExpander { pub fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -154,7 +153,7 @@ fn mk_pound(span: Span) -> tt::Leaf { } fn module_path_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -166,7 +165,7 @@ fn module_path_expand( } fn line_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -181,7 +180,7 @@ fn line_expand( } fn log_syntax_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -190,7 +189,7 @@ fn log_syntax_expand( } fn trace_macros_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -199,7 +198,7 @@ fn trace_macros_expand( } fn stringify_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -214,7 +213,7 @@ fn stringify_expand( } fn assert_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -253,7 +252,7 @@ fn assert_expand( } fn file_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -270,7 +269,7 @@ fn file_expand( } fn format_args_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -284,7 +283,7 @@ fn format_args_expand( } fn format_args_nl_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -307,7 +306,7 @@ fn format_args_nl_expand( } fn asm_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -322,7 +321,7 @@ fn asm_expand( } fn global_asm_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -337,7 +336,7 @@ fn global_asm_expand( } fn naked_asm_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -352,7 +351,7 @@ fn naked_asm_expand( } fn cfg_select_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -441,7 +440,7 @@ fn cfg_select_expand( } fn cfg_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -454,7 +453,7 @@ fn cfg_expand( } fn panic_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -481,7 +480,7 @@ fn panic_expand( } fn unreachable_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -510,7 +509,7 @@ fn unreachable_expand( } #[allow(clippy::never_loop)] -fn use_panic_2021(db: &dyn ExpandDatabase, span: Span) -> bool { +fn use_panic_2021(db: &dyn SourceDatabase, span: Span) -> bool { // To determine the edition, we check the first span up the expansion // stack that does not have #[allow_internal_unstable(edition_panic)]. // (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.) @@ -532,7 +531,7 @@ fn use_panic_2021(db: &dyn ExpandDatabase, span: Span) -> bool { } fn compile_error_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -552,7 +551,7 @@ fn compile_error_expand( } fn concat_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _arg_id: MacroCallId, tt: &tt::TopSubtree, call_site: Span, @@ -659,7 +658,7 @@ fn concat_expand( } fn concat_bytes_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _arg_id: MacroCallId, tt: &tt::TopSubtree, call_site: Span, @@ -758,7 +757,7 @@ fn concat_bytes_expand_subtree( } fn relative_file( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, call_id: MacroCallId, path_str: &str, allow_recursion: bool, @@ -811,7 +810,7 @@ fn parse_string(tt: &tt::TopSubtree) -> Result<(Symbol, Span), ExpandError> { } fn include_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, arg_id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -835,7 +834,7 @@ fn include_expand( } pub fn include_input_to_file_id( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, arg_id: MacroCallId, arg: &tt::TopSubtree, ) -> Result<EditionedFileId, ExpandError> { @@ -844,7 +843,7 @@ pub fn include_input_to_file_id( } fn include_bytes_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _arg_id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -858,7 +857,7 @@ fn include_bytes_expand( } fn include_str_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, arg_id: MacroCallId, tt: &tt::TopSubtree, call_site: Span, @@ -890,13 +889,13 @@ fn include_str_expand( ExpandResult::ok(quote!(call_site =>#text)) } -fn get_env_inner(db: &dyn ExpandDatabase, arg_id: MacroCallId, key: &Symbol) -> Option<String> { +fn get_env_inner(db: &dyn SourceDatabase, arg_id: MacroCallId, key: &Symbol) -> Option<String> { let krate = arg_id.loc(db).krate; krate.env(db).get(key.as_str()) } fn env_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, arg_id: MacroCallId, tt: &tt::TopSubtree, span: Span, @@ -934,7 +933,7 @@ fn env_expand( } fn option_env_expand( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, arg_id: MacroCallId, tt: &tt::TopSubtree, call_site: Span, @@ -961,7 +960,7 @@ fn option_env_expand( } fn quote_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _arg_id: MacroCallId, _tt: &tt::TopSubtree, span: Span, @@ -987,7 +986,7 @@ fn unescape_str(s: &str) -> Cow<'_, str> { } fn pattern_type_expand( - _db: &dyn ExpandDatabase, + _db: &dyn SourceDatabase, _arg_id: MacroCallId, tt: &tt::TopSubtree, call_site: Span, diff --git a/crates/hir-expand/src/cfg_process.rs b/crates/hir-expand/src/cfg_process.rs index 81edc9f2cf..45a81d3b36 100644 --- a/crates/hir-expand/src/cfg_process.rs +++ b/crates/hir-expand/src/cfg_process.rs @@ -2,7 +2,7 @@ use std::{cell::OnceCell, ops::ControlFlow}; use ::tt::TextRange; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use cfg::CfgExpr; use parser::T; use smallvec::SmallVec; @@ -14,7 +14,6 @@ use syntax_bridge::DocCommentDesugarMode; use crate::{ attrs::{AstPathExt, AttrId, expand_cfg_attr, is_item_tree_filtered_attr}, - db::ExpandDatabase, fixup::{self, SyntaxFixupUndoInfo}, span_map::SpanMap, tt::{self, DelimSpan, Span}, @@ -46,7 +45,7 @@ struct AstAttrToProcess { } fn macro_input_callback( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, is_derive: bool, censor_item_tree_attr_ids: &[AttrId], krate: Crate, @@ -293,7 +292,7 @@ fn macro_input_callback( } pub(crate) fn attr_macro_input_to_token_tree( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, node: &SyntaxNode, span_map: SpanMap<'_>, span: Span, diff --git a/crates/hir-expand/src/change.rs b/crates/hir-expand/src/change.rs index f75f45983c..58808bc6c8 100644 --- a/crates/hir-expand/src/change.rs +++ b/crates/hir-expand/src/change.rs @@ -1,9 +1,9 @@ //! Defines a unit of change that can applied to the database to get the next //! state. Changes are transactional. -use base_db::{CrateGraphBuilder, FileChange, SourceRoot}; +use base_db::{CrateGraphBuilder, FileChange, SourceDatabase, SourceRoot}; use span::FileId; -use crate::{db::ExpandDatabase, proc_macro::ProcMacrosBuilder}; +use crate::proc_macro::ProcMacrosBuilder; #[derive(Debug, Default)] pub struct ChangeWithProcMacros { @@ -12,7 +12,7 @@ pub struct ChangeWithProcMacros { } impl ChangeWithProcMacros { - pub fn apply(self, db: &mut impl ExpandDatabase) { + pub fn apply(self, db: &mut impl SourceDatabase) { let crates_id_map = self.source_change.apply(db); if let Some(proc_macros) = self.proc_macros { proc_macros.build_in( diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs deleted file mode 100644 index d9e17cfb2d..0000000000 --- a/crates/hir-expand/src/db.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Defines database & queries for macro expansion. - -use base_db::SourceDatabase; - -#[query_group::query_group] -pub trait ExpandDatabase: SourceDatabase {} diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs index c250bc5270..a3c9047d76 100644 --- a/crates/hir-expand/src/declarative.rs +++ b/crates/hir-expand/src/declarative.rs @@ -2,7 +2,7 @@ use std::ops::ControlFlow; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use span::{Edition, Span, SyntaxContext}; use stdx::TupleExt; use syntax::{ @@ -15,7 +15,6 @@ use crate::{ AstId, ExpandError, ExpandErrorKind, ExpandResult, HirFileId, Lookup, MacroCallId, MacroCallStyle, attrs::{AstKeyValueMetaExt, AstPathExt, expand_cfg_attr}, - db::ExpandDatabase, hygiene::{Transparency, apply_mark}, tt, }; @@ -31,7 +30,7 @@ pub struct DeclarativeMacroExpander { impl DeclarativeMacroExpander { pub fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, tt: &tt::TopSubtree, call_id: MacroCallId, span: Span, @@ -60,7 +59,7 @@ impl DeclarativeMacroExpander { pub fn expand_unhygienic( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, tt: &tt::TopSubtree, call_style: MacroCallStyle, call_site: Span, @@ -85,7 +84,7 @@ impl AstId<ast::Macro> { #[salsa::tracked(returns(ref))] pub fn decl_macro_expander( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, def_crate: Crate, ) -> DeclarativeMacroExpander { let id = self; diff --git a/crates/hir-expand/src/eager.rs b/crates/hir-expand/src/eager.rs index 16053840b7..00457ad44b 100644 --- a/crates/hir-expand/src/eager.rs +++ b/crates/hir-expand/src/eager.rs @@ -18,7 +18,7 @@ //! //! //! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros> -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use span::SyntaxContext; use syntax::{ AstPtr, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent, syntax_editor::SyntaxEditor, @@ -29,7 +29,6 @@ use crate::{ AstId, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind, ast::{self, AstNode}, - db::ExpandDatabase, mod_path::ModPath, }; @@ -39,7 +38,7 @@ pub type EagerCallBackFn<'a> = &'a mut dyn FnMut( ); pub fn expand_eager_macro_input( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, macro_call: &ast::MacroCall, ast_id: AstId<ast::MacroCall>, @@ -119,7 +118,7 @@ pub fn expand_eager_macro_input( } fn lazy_expand<'db>( - db: &'db dyn ExpandDatabase, + db: &'db dyn SourceDatabase, def: &MacroDefId, macro_call: &ast::MacroCall, ast_id: AstId<ast::MacroCall>, @@ -142,7 +141,7 @@ fn lazy_expand<'db>( } fn eager_macro_recur( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span_map: &ExpansionSpanMap, expanded_map: &mut ExpansionSpanMap, mut offset: TextSize, diff --git a/crates/hir-expand/src/files.rs b/crates/hir-expand/src/files.rs index a6ae901973..3524e0cb09 100644 --- a/crates/hir-expand/src/files.rs +++ b/crates/hir-expand/src/files.rs @@ -1,14 +1,14 @@ //! Things to wrap other things in file ids. use std::borrow::Borrow; +use base_db::SourceDatabase; use either::Either; use span::{AstIdNode, ErasedFileAstId, FileAstId, FileId, SyntaxContext}; use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize}; use crate::{ - EditionedFileId, HirFileId, MacroCallId, MacroKind, - db::{self, ExpandDatabase}, - map_node_range_up, map_node_range_up_rooted, span_for_offset, + EditionedFileId, HirFileId, MacroCallId, MacroKind, map_node_range_up, + map_node_range_up_rooted, span_for_offset, }; /// `InFile<T>` stores a value of `T` inside a particular file/syntax tree. @@ -38,7 +38,7 @@ pub type FilePosition = FilePositionWrapper<EditionedFileId>; impl FilePosition { #[inline] - pub fn into_file_id(self, db: &dyn ExpandDatabase) -> FilePositionWrapper<FileId> { + pub fn into_file_id(self, db: &dyn SourceDatabase) -> FilePositionWrapper<FileId> { FilePositionWrapper { file_id: self.file_id.file_id(db), offset: self.offset } } } @@ -72,17 +72,17 @@ pub type FileRange = FileRangeWrapper<EditionedFileId>; impl FileRange { #[inline] - pub fn into_file_id(self, db: &dyn ExpandDatabase) -> FileRangeWrapper<FileId> { + pub fn into_file_id(self, db: &dyn SourceDatabase) -> FileRangeWrapper<FileId> { FileRangeWrapper { file_id: self.file_id.file_id(db), range: self.range } } #[inline] - pub fn file_text(self, db: &dyn ExpandDatabase) -> &triomphe::Arc<str> { + pub fn file_text(self, db: &dyn SourceDatabase) -> &triomphe::Arc<str> { db.file_text(self.file_id.file_id(db)).text(db) } #[inline] - pub fn text(self, db: &dyn ExpandDatabase) -> &str { + pub fn text(self, db: &dyn SourceDatabase) -> &str { &self.file_text(db)[self.range] } } @@ -93,16 +93,16 @@ impl FileRange { pub type AstId<N> = crate::InFile<FileAstId<N>>; impl<N: AstNode> AstId<N> { - pub fn to_node(&self, db: &dyn ExpandDatabase) -> N { + pub fn to_node(&self, db: &dyn SourceDatabase) -> N { self.to_ptr(db).to_node(&self.file_id.parse_or_expand(db)) } - pub fn to_range(&self, db: &dyn ExpandDatabase) -> TextRange { + pub fn to_range(&self, db: &dyn SourceDatabase) -> TextRange { self.to_ptr(db).text_range() } - pub fn to_in_file_node(&self, db: &dyn ExpandDatabase) -> crate::InFile<N> { + pub fn to_in_file_node(&self, db: &dyn SourceDatabase) -> crate::InFile<N> { crate::InFile::new(self.file_id, self.to_ptr(db).to_node(&self.file_id.parse_or_expand(db))) } - pub fn to_ptr(&self, db: &dyn ExpandDatabase) -> AstPtr<N> { + pub fn to_ptr(&self, db: &dyn SourceDatabase) -> AstPtr<N> { self.file_id.ast_id_map(db).get(self.value) } pub fn erase(&self) -> ErasedAstId { @@ -120,10 +120,10 @@ impl<N: AstNode> AstId<N> { pub type ErasedAstId = crate::InFile<ErasedFileAstId>; impl ErasedAstId { - pub fn to_range(&self, db: &dyn ExpandDatabase) -> TextRange { + pub fn to_range(&self, db: &dyn SourceDatabase) -> TextRange { self.to_ptr(db).text_range() } - pub fn to_ptr(&self, db: &dyn ExpandDatabase) -> SyntaxNodePtr { + pub fn to_ptr(&self, db: &dyn SourceDatabase) -> SyntaxNodePtr { self.file_id.ast_id_map(db).get_erased(self.value) } } @@ -203,35 +203,35 @@ impl<FileKind, L, R> InFileWrapper<FileKind, Either<L, R>> { // endregion:transpose impls trait FileIdToSyntax: Copy { - fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode; + fn file_syntax(self, db: &dyn SourceDatabase) -> SyntaxNode; } impl FileIdToSyntax for EditionedFileId { - fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode { + fn file_syntax(self, db: &dyn SourceDatabase) -> SyntaxNode { self.parse(db).syntax_node() } } impl FileIdToSyntax for MacroCallId { - fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode { + fn file_syntax(self, db: &dyn SourceDatabase) -> SyntaxNode { self.parse_macro_expansion(db).value.0.syntax_node() } } impl FileIdToSyntax for HirFileId { - fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode { + fn file_syntax(self, db: &dyn SourceDatabase) -> SyntaxNode { self.parse_or_expand(db) } } #[allow(private_bounds)] impl<FileId: FileIdToSyntax, T> InFileWrapper<FileId, T> { - pub fn file_syntax(&self, db: &dyn db::ExpandDatabase) -> SyntaxNode { + pub fn file_syntax(&self, db: &dyn SourceDatabase) -> SyntaxNode { FileIdToSyntax::file_syntax(self.file_id, db) } } #[allow(private_bounds)] impl<FileId: FileIdToSyntax, N: AstNode> InFileWrapper<FileId, AstPtr<N>> { - pub fn to_node(&self, db: &dyn ExpandDatabase) -> N { + pub fn to_node(&self, db: &dyn SourceDatabase) -> N { self.value.to_node(&self.file_syntax(db)) } } @@ -262,7 +262,7 @@ impl<FileId: Copy, SN: Borrow<SyntaxNode>> InFileWrapper<FileId, SN> { impl<SN: Borrow<SyntaxNode>> InFile<SN> { pub fn parent_ancestors_with_macros( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ { let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() { Some(parent) => Some(node.with_value(parent)), @@ -281,7 +281,7 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> { pub fn ancestors_with_macros( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ { let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() { Some(parent) => Some(node.with_value(parent)), @@ -310,21 +310,18 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> { /// /// For attributes and derives, this will point back to the attribute only. /// For the entire item use `InFile::original_file_range_full`. - pub fn original_file_range_rooted(self, db: &dyn db::ExpandDatabase) -> FileRange { + pub fn original_file_range_rooted(self, db: &dyn SourceDatabase) -> FileRange { self.borrow().map(SyntaxNode::text_range).original_node_file_range_rooted(db) } /// Falls back to the macro call range if the node cannot be mapped up fully. - pub fn original_file_range_with_macro_call_input( - self, - db: &dyn db::ExpandDatabase, - ) -> FileRange { + pub fn original_file_range_with_macro_call_input(self, db: &dyn SourceDatabase) -> FileRange { self.borrow().map(SyntaxNode::text_range).original_node_file_range_with_macro_call_input(db) } pub fn original_syntax_node_rooted( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> Option<InRealFile<SyntaxNode>> { // 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 @@ -362,24 +359,21 @@ impl InFile<&SyntaxNode> { /// Attempts to map the syntax node back up its macro calls. pub fn original_file_range_opt( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> Option<(FileRange, SyntaxContext)> { self.borrow().map(SyntaxNode::text_range).original_node_file_range_opt(db) } } impl InMacroFile<SyntaxToken> { - pub fn upmap_once( - self, - db: &dyn db::ExpandDatabase, - ) -> InFile<smallvec::SmallVec<[TextRange; 1]>> { + pub fn upmap_once(self, db: &dyn SourceDatabase) -> InFile<smallvec::SmallVec<[TextRange; 1]>> { self.file_id.expansion_info(db).map_range_up_once(db, self.value.text_range()) } } impl InFile<SyntaxToken> { /// Falls back to the macro call range if the node cannot be mapped up fully. - pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> FileRange { + pub fn original_file_range(self, db: &dyn SourceDatabase) -> FileRange { match self.file_id { HirFileId::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, HirFileId::MacroFile(mac_file) => { @@ -403,7 +397,7 @@ impl InFile<SyntaxToken> { } /// Attempts to map the syntax node back up its macro calls. - pub fn original_file_range_opt(self, db: &dyn db::ExpandDatabase) -> Option<FileRange> { + pub fn original_file_range_opt(self, db: &dyn SourceDatabase) -> Option<FileRange> { match self.file_id { HirFileId::FileId(file_id) => { Some(FileRange { file_id, range: self.value.text_range() }) @@ -424,16 +418,13 @@ impl InFile<SyntaxToken> { } impl InMacroFile<TextSize> { - pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> (FileRange, SyntaxContext) { + pub fn original_file_range(self, db: &dyn SourceDatabase) -> (FileRange, SyntaxContext) { span_for_offset(db, self.file_id.expansion_span_map(db), self.value) } } impl InFile<TextRange> { - pub fn original_node_file_range( - self, - db: &dyn db::ExpandDatabase, - ) -> (FileRange, SyntaxContext) { + pub fn original_node_file_range(self, db: &dyn SourceDatabase) -> (FileRange, SyntaxContext) { match self.file_id { HirFileId::FileId(file_id) => { (FileRange { file_id, range: self.value }, SyntaxContext::root(file_id.edition(db))) @@ -453,7 +444,7 @@ impl InFile<TextRange> { } } - pub fn original_node_file_range_rooted(self, db: &dyn db::ExpandDatabase) -> FileRange { + pub fn original_node_file_range_rooted(self, db: &dyn SourceDatabase) -> FileRange { match self.file_id { HirFileId::FileId(file_id) => FileRange { file_id, range: self.value }, HirFileId::MacroFile(mac_file) => { @@ -470,7 +461,7 @@ impl InFile<TextRange> { pub fn original_node_file_range_with_macro_call_input( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> FileRange { match self.file_id { HirFileId::FileId(file_id) => FileRange { file_id, range: self.value }, @@ -488,7 +479,7 @@ impl InFile<TextRange> { pub fn original_node_file_range_opt( self, - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, ) -> Option<(FileRange, SyntaxContext)> { match self.file_id { HirFileId::FileId(file_id) => Some(( @@ -501,10 +492,7 @@ impl InFile<TextRange> { } } - pub fn original_node_file_range_rooted_opt( - self, - db: &dyn db::ExpandDatabase, - ) -> Option<FileRange> { + pub fn original_node_file_range_rooted_opt(self, db: &dyn SourceDatabase) -> Option<FileRange> { match self.file_id { HirFileId::FileId(file_id) => Some(FileRange { file_id, range: self.value }), HirFileId::MacroFile(mac_file) => { @@ -515,7 +503,7 @@ impl InFile<TextRange> { } impl<N: AstNode> InFile<N> { - pub fn original_ast_node_rooted(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<N>> { + pub fn original_ast_node_rooted(self, db: &dyn SourceDatabase) -> Option<InRealFile<N>> { // 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 let file_id = match self.file_id { diff --git a/crates/hir-expand/src/hygiene.rs b/crates/hir-expand/src/hygiene.rs index 1cf8ce2a57..e471c6d2bd 100644 --- a/crates/hir-expand/src/hygiene.rs +++ b/crates/hir-expand/src/hygiene.rs @@ -26,12 +26,12 @@ use std::convert::identity; use span::{Edition, MacroCallId, Span, SyntaxContext}; -use crate::db::ExpandDatabase; +use base_db::SourceDatabase; pub use span::Transparency; pub fn span_with_def_site_ctxt( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, expn_id: MacroCallId, edition: Edition, @@ -40,7 +40,7 @@ pub fn span_with_def_site_ctxt( } pub fn span_with_call_site_ctxt( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, expn_id: MacroCallId, edition: Edition, @@ -49,7 +49,7 @@ pub fn span_with_call_site_ctxt( } pub fn span_with_mixed_site_ctxt( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, expn_id: MacroCallId, edition: Edition, @@ -58,7 +58,7 @@ pub fn span_with_mixed_site_ctxt( } fn span_with_ctxt_from_mark( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span: Span, expn_id: MacroCallId, transparency: Transparency, @@ -71,7 +71,7 @@ fn span_with_ctxt_from_mark( } pub(super) fn apply_mark( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ctxt: span::SyntaxContext, call_id: span::MacroCallId, transparency: Transparency, @@ -108,7 +108,7 @@ pub(super) fn apply_mark( } fn apply_mark_internal( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ctxt: SyntaxContext, call_id: MacroCallId, transparency: Transparency, diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 293d73fb2d..9ebb346a37 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -12,7 +12,6 @@ pub use intern; pub mod attrs; pub mod builtin; pub mod change; -pub mod db; pub mod declarative; pub mod eager; pub mod files; @@ -34,7 +33,7 @@ use triomphe::Arc; use core::fmt; use std::{borrow::Cow, ops}; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use either::Either; use mbe::MatchedArmIndex; use span::{ @@ -54,7 +53,6 @@ use crate::{ include_input_to_file_id, pseudo_derive_attr_expansion, }, cfg_process::attr_macro_input_to_token_tree, - db::ExpandDatabase, fixup::SyntaxFixupUndoInfo, hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt}, proc_macro::{CustomProcMacroExpander, ProcMacroKind, ProcMacros}, @@ -117,7 +115,7 @@ pub trait Lookup { fn lookup<'db>(&self, db: &'db Self::Database) -> &'db Self::Data; } -impl_intern_lookup!(ExpandDatabase, MacroCallId, MacroCallLoc); +impl_intern_lookup!(SourceDatabase, MacroCallId, MacroCallLoc); pub type ExpandResult<T> = ValueResult<T, ExpandError>; @@ -140,7 +138,7 @@ impl ExpandError { self.inner.1 } - pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError { + pub fn render_to_string(&self, db: &dyn SourceDatabase) -> RenderedExpandError { self.inner.0.render_to_string(db) } } @@ -179,7 +177,7 @@ impl RenderedExpandError { } impl ExpandErrorKind { - pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError { + pub fn render_to_string(&self, db: &dyn SourceDatabase) -> RenderedExpandError { match self { ExpandErrorKind::ProcMacroAttrExpansionDisabled => RenderedExpandError { message: "procedural attribute macro expansion is disabled".to_owned(), @@ -413,10 +411,10 @@ pub enum MacroKind { } impl MacroCallId { - pub fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode> { + pub fn call_node(self, db: &dyn SourceDatabase) -> InFile<SyntaxNode> { self.loc(db).to_node(db) } - pub fn expansion_level(self, db: &dyn ExpandDatabase) -> u32 { + pub fn expansion_level(self, db: &dyn SourceDatabase) -> u32 { let mut level = 0; let mut macro_file = self; loop { @@ -429,16 +427,16 @@ impl MacroCallId { }; } } - pub fn parent(self, db: &dyn ExpandDatabase) -> HirFileId { + pub fn parent(self, db: &dyn SourceDatabase) -> HirFileId { self.loc(db).kind.file_id() } /// Return expansion information if it is a macro-expansion file - pub fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo<'_> { + pub fn expansion_info(self, db: &dyn SourceDatabase) -> ExpansionInfo<'_> { ExpansionInfo::new(db, self) } - pub fn kind(self, db: &dyn ExpandDatabase) -> MacroKind { + pub fn kind(self, db: &dyn SourceDatabase) -> MacroKind { match self.loc(db).def.kind { MacroDefKind::Declarative(..) => MacroKind::Declarative, MacroDefKind::BuiltIn(..) | MacroDefKind::BuiltInEager(..) => { @@ -453,24 +451,24 @@ impl MacroCallId { } } - pub fn is_include_macro(self, db: &dyn ExpandDatabase) -> bool { + pub fn is_include_macro(self, db: &dyn SourceDatabase) -> bool { self.loc(db).def.is_include() } - pub fn is_include_like_macro(self, db: &dyn ExpandDatabase) -> bool { + pub fn is_include_like_macro(self, db: &dyn SourceDatabase) -> bool { self.loc(db).def.is_include_like() } - pub fn is_env_or_option_env(self, db: &dyn ExpandDatabase) -> bool { + pub fn is_env_or_option_env(self, db: &dyn SourceDatabase) -> bool { self.loc(db).def.is_env_or_option_env() } - pub fn is_eager(self, db: &dyn ExpandDatabase) -> bool { + pub fn is_eager(self, db: &dyn SourceDatabase) -> bool { let loc = self.loc(db); matches!(loc.def.kind, MacroDefKind::BuiltInEager(..)) } - pub fn eager_arg(self, db: &dyn ExpandDatabase) -> Option<MacroCallId> { + pub fn eager_arg(self, db: &dyn SourceDatabase) -> Option<MacroCallId> { let loc = self.loc(db); match &loc.kind { MacroCallKind::FnLike { eager, .. } => eager.as_ref().map(|it| it.arg_id), @@ -478,7 +476,7 @@ impl MacroCallId { } } - pub fn is_derive_attr_pseudo_expansion(self, db: &dyn ExpandDatabase) -> bool { + pub fn is_derive_attr_pseudo_expansion(self, db: &dyn SourceDatabase) -> bool { let loc = self.loc(db); loc.def.is_attribute_derive() } @@ -492,7 +490,7 @@ impl MacroCallId { #[salsa::tracked(returns(ref), lru = 512)] pub fn parse_macro_expansion( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ) -> ExpandResult<(Parse<SyntaxNode>, ExpansionSpanMap)> { let _p = tracing::info_span!("parse_macro_expansion").entered(); let loc = self.loc(db); @@ -507,7 +505,7 @@ impl MacroCallId { pub fn parse_macro_expansion_error( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ) -> Option<ExpandResult<Arc<[SyntaxError]>>> { let e: ExpandResult<Arc<[SyntaxError]>> = self.parse_macro_expansion(db).as_ref().map(|it| Arc::from(it.0.errors())); @@ -523,7 +521,7 @@ impl MacroCallId { #[allow(deprecated)] // we are macro_arg_considering_derives pub fn macro_arg_considering_derives<'db>( self, - db: &'db dyn ExpandDatabase, + db: &'db dyn SourceDatabase, kind: &MacroCallKind, ) -> &'db MacroArgResult { match kind { @@ -538,7 +536,7 @@ impl MacroCallId { /// query, only typing in the macro call itself changes the returned /// subtree. #[salsa::tracked(returns(ref))] - fn macro_arg(self, db: &dyn ExpandDatabase) -> MacroArgResult { + fn macro_arg(self, db: &dyn SourceDatabase) -> MacroArgResult { let loc = self.loc(db); if let MacroCallLoc { @@ -619,7 +617,7 @@ impl MacroCallId { } // MacroCallKind::Derive should not be here. As we are getting the argument for the derive macro MacroCallKind::Derive { .. } => { - unreachable!("`ExpandDatabase::macro_arg` called with `MacroCallKind::Derive`") + unreachable!("`MacroCallId::macro_arg` called with `MacroCallKind::Derive`") } MacroCallKind::Attr { ast_id, censored_attr_ids: attr_ids, .. } => { let node = ast_id.to_ptr(db).to_node(&root); @@ -656,7 +654,7 @@ impl MacroCallId { fn macro_expand<'db>( self, - db: &'db dyn ExpandDatabase, + db: &'db dyn SourceDatabase, loc: &MacroCallLoc, ) -> ExpandResult<(Cow<'db, tt::TopSubtree>, MatchedArmIndex)> { let _p = tracing::info_span!("macro_expand").entered(); @@ -736,7 +734,7 @@ impl MacroCallId { /// non-determinism breaks salsa in a very, very, very bad way. /// @edwin0cheng heroically debugged this once! See #4315 for details #[salsa::tracked(returns(ref))] - fn expand_proc_macro(self, db: &dyn ExpandDatabase) -> ExpandResult<tt::TopSubtree> { + fn expand_proc_macro(self, db: &dyn SourceDatabase) -> ExpandResult<tt::TopSubtree> { let loc = self.loc(db); let (macro_arg, undo_info, span) = self.macro_arg_considering_derives(db, &loc.kind); @@ -782,7 +780,7 @@ impl MacroCallId { /// token(s) returned with their priority. pub fn expand_speculative( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, speculative_args: &SyntaxNode, token_to_map: SyntaxToken, ) -> Option<(SyntaxNode, Vec<(SyntaxToken, u8)>)> { @@ -965,9 +963,9 @@ fn expand_unimplemented_builtin_macro(span: Span) -> ExpandResult<tt::TopSubtree /// directly depend on as that would cause to frequent invalidations, mainly because of the /// parse queries being LRU cached. If they weren't the invalidations would only happen if the /// user wrote in the file that defines the proc-macro. -fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span { +fn proc_macro_span(db: &dyn SourceDatabase, ast: AstId<ast::Fn>) -> Span { #[salsa::tracked] - fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>, _: ()) -> Span { + fn proc_macro_span(db: &dyn SourceDatabase, ast: AstId<ast::Fn>, _: ()) -> Span { let (parse, span_map) = ast.file_id.parse_with_map(db); let root = parse.syntax_node(); let ast_id_map = ast.file_id.ast_id_map(db); @@ -981,7 +979,7 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span { } pub(crate) fn token_tree_to_syntax_node( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, tt: &tt::TopSubtree, expand_to: ExpandTo, ) -> (Parse<SyntaxNode>, ExpansionSpanMap) { @@ -1016,7 +1014,7 @@ fn check_tt_count(tt: &tt::TopSubtree) -> Result<(), ExpandResult<()>> { impl MacroDefId { pub fn make_call( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, krate: Crate, kind: MacroCallKind, ctxt: SyntaxContext, @@ -1024,7 +1022,7 @@ impl MacroDefId { MacroCallId::new(db, MacroCallLoc { def: self, krate, kind, ctxt }) } - pub fn definition_range(&self, db: &dyn ExpandDatabase) -> InFile<TextRange> { + pub fn definition_range(&self, db: &dyn SourceDatabase) -> InFile<TextRange> { match self.kind { MacroDefKind::Declarative(id, _) | MacroDefKind::BuiltIn(id, _) @@ -1105,7 +1103,7 @@ impl MacroDefId { } impl MacroCallLoc { - pub fn to_node(&self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode> { + pub fn to_node(&self, db: &dyn SourceDatabase) -> InFile<SyntaxNode> { match &self.kind { MacroCallKind::FnLike { ast_id, .. } => { ast_id.with_value(ast_id.to_node(db).syntax().clone()) @@ -1125,7 +1123,7 @@ impl MacroCallLoc { } } - pub fn to_node_item(&self, db: &dyn ExpandDatabase) -> InFile<ast::Item> { + pub fn to_node_item(&self, db: &dyn SourceDatabase) -> InFile<ast::Item> { match self.kind { MacroCallKind::FnLike { ast_id, .. } => { InFile::new(ast_id.file_id, ast_id.map(FileAstId::upcast).to_node(db)) @@ -1151,7 +1149,7 @@ impl MacroCallLoc { pub fn include_file_id( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, macro_call_id: MacroCallId, ) -> Option<EditionedFileId> { if self.def.is_include() @@ -1197,7 +1195,7 @@ impl MacroCallKind { /// - fn_like! {}, it spans the path and token tree /// - #\[derive], it spans the `#[derive(...)]` attribute and the annotated item /// - #\[attr], it spans the `#[attr(...)]` attribute and the annotated item - pub fn original_call_range_with_input(&self, db: &dyn ExpandDatabase) -> FileRange { + pub fn original_call_range_with_input(&self, db: &dyn SourceDatabase) -> FileRange { let get_range = |kind: &_| match kind { MacroCallKind::FnLike { ast_id, .. } => ast_id.erase(), MacroCallKind::Derive { ast_id, .. } => ast_id.erase(), @@ -1225,7 +1223,7 @@ impl MacroCallKind { /// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros /// get the macro path (rustc shows the whole `ast::MacroCall`), attribute macros get the /// attribute's range, and derives get only the specific derive that is being referred to. - pub fn original_call_range(&self, db: &dyn ExpandDatabase, krate: Crate) -> FileRange { + pub fn original_call_range(&self, db: &dyn SourceDatabase, krate: Crate) -> FileRange { let get_range = |kind: &_| match kind { MacroCallKind::FnLike { ast_id, .. } => { let node = ast_id.to_node(db); @@ -1261,7 +1259,7 @@ impl MacroCallKind { FileRange { range, file_id } } - fn arg(&self, db: &dyn ExpandDatabase) -> InFile<Option<SyntaxNode>> { + fn arg(&self, db: &dyn SourceDatabase) -> InFile<Option<SyntaxNode>> { match self { MacroCallKind::FnLike { ast_id, .. } => { ast_id.to_in_file_node(db).map(|it| Some(it.token_tree()?.syntax().clone())) @@ -1351,7 +1349,7 @@ impl<'db> ExpansionInfo<'db> { /// Looks up the span at the given offset. pub fn span_for_offset( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, offset: TextSize, ) -> (FileRange, SyntaxContext) { debug_assert!(self.expanded.value.text_range().contains(offset)); @@ -1361,7 +1359,7 @@ impl<'db> ExpansionInfo<'db> { /// Maps up the text range out of the expansion hierarchy back into the original file its from. pub fn map_node_range_up( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, range: TextRange, ) -> Option<(FileRange, SyntaxContext)> { debug_assert!(self.expanded.value.text_range().contains_range(range)); @@ -1374,7 +1372,7 @@ impl<'db> ExpansionInfo<'db> { /// and as such we may consider inputs that are unrelated. pub fn map_range_up_once( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, token: TextRange, ) -> InFile<smallvec::SmallVec<[TextRange; 1]>> { debug_assert!(self.expanded.value.text_range().contains_range(token)); @@ -1401,7 +1399,7 @@ impl<'db> ExpansionInfo<'db> { } } - pub fn new(db: &'db dyn ExpandDatabase, macro_file: MacroCallId) -> ExpansionInfo<'db> { + pub fn new(db: &'db dyn SourceDatabase, macro_file: MacroCallId) -> ExpansionInfo<'db> { let _p = tracing::info_span!("ExpansionInfo::new").entered(); let loc = macro_file.loc(db); @@ -1419,7 +1417,7 @@ impl<'db> ExpansionInfo<'db> { /// considering the root spans contained. /// Unlike [`map_node_range_up`], this will not return `None` if any anchors or syntax contexts differ. pub fn map_node_range_up_rooted( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, exp_map: &ExpansionSpanMap, range: TextRange, ) -> Option<FileRange> { @@ -1442,7 +1440,7 @@ pub fn map_node_range_up_rooted( /// /// this will return `None` if any anchors or syntax contexts differ. pub fn map_node_range_up( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, exp_map: &ExpansionSpanMap, range: TextRange, ) -> Option<(FileRange, SyntaxContext)> { @@ -1463,7 +1461,7 @@ pub fn map_node_range_up( /// Looks up the span at the given offset. pub fn span_for_offset( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, exp_map: &ExpansionSpanMap, offset: TextSize, ) -> (FileRange, SyntaxContext) { @@ -1474,7 +1472,7 @@ pub fn span_for_offset( // FIXME: This is only public because of its use in `load_cargo` (which we should consider removing // by moving the implementations of the subrequests to `hir_expand`, and calling within `load-cargo`). // Avoid adding any more outside uses. -pub fn resolve_span(db: &dyn ExpandDatabase, Span { range, anchor, ctx: _ }: Span) -> FileRange { +pub fn resolve_span(db: &dyn SourceDatabase, Span { range, anchor, ctx: _ }: Span) -> FileRange { let file_id = EditionedFileId::from_span_file_id(db, anchor.file_id); let anchor_offset = HirFileId::from(file_id).ast_id_map(db).get_erased(anchor.ast_id).text_range().start(); @@ -1624,7 +1622,7 @@ impl HirFileId { } } - pub fn syntax_context(self, db: &dyn ExpandDatabase, edition: Edition) -> SyntaxContext { + pub fn syntax_context(self, db: &dyn SourceDatabase, edition: Edition) -> SyntaxContext { match self { HirFileId::FileId(_) => SyntaxContext::root(edition), HirFileId::MacroFile(m) => { @@ -1634,14 +1632,14 @@ impl HirFileId { } } - pub fn edition(self, db: &dyn ExpandDatabase) -> Edition { + pub fn edition(self, db: &dyn SourceDatabase) -> Edition { match self { HirFileId::FileId(file_id) => file_id.edition(db), HirFileId::MacroFile(m) => m.loc(db).def.edition, } } - pub fn original_file(self, db: &dyn ExpandDatabase) -> EditionedFileId { + pub fn original_file(self, db: &dyn SourceDatabase) -> EditionedFileId { let mut file_id = self; loop { match file_id { @@ -1653,7 +1651,7 @@ impl HirFileId { } } - pub fn original_file_respecting_includes(mut self, db: &dyn ExpandDatabase) -> EditionedFileId { + pub fn original_file_respecting_includes(mut self, db: &dyn SourceDatabase) -> EditionedFileId { loop { match self { HirFileId::FileId(id) => break id, @@ -1671,7 +1669,7 @@ impl HirFileId { } } - pub fn original_call_node(self, db: &dyn ExpandDatabase) -> Option<InRealFile<SyntaxNode>> { + pub fn original_call_node(self, db: &dyn SourceDatabase) -> Option<InRealFile<SyntaxNode>> { let mut call = self.macro_file()?.loc(db).to_node(db); loop { match call.file_id { @@ -1685,13 +1683,13 @@ impl HirFileId { } } - pub fn call_node(self, db: &dyn ExpandDatabase) -> Option<InFile<SyntaxNode>> { + pub fn call_node(self, db: &dyn SourceDatabase) -> Option<InFile<SyntaxNode>> { Some(self.macro_file()?.loc(db).to_node(db)) } pub fn as_builtin_derive_attr_node( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ) -> Option<InFile<ast::Attr>> { let macro_file = self.macro_file()?; let loc = macro_file.loc(db); @@ -1704,7 +1702,7 @@ impl HirFileId { /// Main public API -- parses a hir file, not caring whether it's a real /// file or a macro expansion. - pub fn parse_or_expand(self, db: &dyn ExpandDatabase) -> SyntaxNode { + pub fn parse_or_expand(self, db: &dyn SourceDatabase) -> SyntaxNode { match self { HirFileId::FileId(file_id) => file_id.parse(db).syntax_node(), HirFileId::MacroFile(macro_file) => { @@ -1715,7 +1713,7 @@ impl HirFileId { pub(crate) fn parse_with_map( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, ) -> (Parse<SyntaxNode>, SpanMap<'_>) { match self { HirFileId::FileId(file_id) => ( @@ -1733,7 +1731,7 @@ impl HirFileId { #[salsa::tracked] impl HirFileId { #[salsa::tracked(lru = 1024, returns(ref))] - pub fn ast_id_map(self, db: &dyn ExpandDatabase) -> AstIdMap { + pub fn ast_id_map(self, db: &dyn SourceDatabase) -> AstIdMap { AstIdMap::from_source(&self.parse_or_expand(db)) } } diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index b90bfac483..59578bae89 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -6,12 +6,11 @@ use std::{ }; use crate::{ - db::ExpandDatabase, hygiene::Transparency, name::{AsName, Name}, tt, }; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use intern::{Symbol, sym}; use parser::T; use smallvec::SmallVec; @@ -45,14 +44,14 @@ impl PathKind { impl ModPath { pub fn from_src( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, path: ast::Path, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext, ) -> Option<ModPath> { convert_path(db, path, span_for_range) } - pub fn from_tt(db: &dyn ExpandDatabase, tt: tt::TokenTreesView<'_>) -> Option<ModPath> { + pub fn from_tt(db: &dyn SourceDatabase, tt: tt::TokenTreesView<'_>) -> Option<ModPath> { convert_path_tt(db, tt) } @@ -68,7 +67,7 @@ impl ModPath { } pub fn from_tokens( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext, is_abs: bool, segments: impl Iterator<Item = SyntaxToken>, @@ -180,16 +179,13 @@ impl ModPath { _ => None, } } - pub fn display_verbatim<'a>( - &'a self, - db: &'a dyn crate::db::ExpandDatabase, - ) -> impl fmt::Display + 'a { + pub fn display_verbatim<'a>(&'a self, db: &'a dyn SourceDatabase) -> impl fmt::Display + 'a { Display { db, path: self, edition: None } } pub fn display<'a>( &'a self, - db: &'a dyn crate::db::ExpandDatabase, + db: &'a dyn SourceDatabase, edition: Edition, ) -> impl fmt::Display + 'a { Display { db, path: self, edition: Some(edition) } @@ -203,7 +199,7 @@ impl Extend<Name> for ModPath { } struct Display<'a> { - db: &'a dyn ExpandDatabase, + db: &'a dyn SourceDatabase, path: &'a ModPath, edition: Option<Edition>, } @@ -221,7 +217,7 @@ impl From<Name> for ModPath { } fn display_fmt_path( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, path: &ModPath, f: &mut fmt::Formatter<'_>, edition: Option<Edition>, @@ -261,7 +257,7 @@ fn display_fmt_path( } fn convert_path( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, path: ast::Path, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext, ) -> Option<ModPath> { @@ -346,7 +342,7 @@ fn convert_path( Some(mod_path) } -fn convert_path_tt(db: &dyn ExpandDatabase, tt: tt::TokenTreesView<'_>) -> Option<ModPath> { +fn convert_path_tt(db: &dyn SourceDatabase, tt: tt::TokenTreesView<'_>) -> Option<ModPath> { let mut leaves = tt.iter().filter_map(|tt| match tt { tt::TtElement::Leaf(leaf) => Some(leaf), tt::TtElement::Subtree(..) => None, @@ -388,7 +384,7 @@ fn convert_path_tt(db: &dyn ExpandDatabase, tt: tt::TokenTreesView<'_>) -> Optio Some(ModPath { kind, segments }) } -pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> Option<Crate> { +pub fn resolve_crate_root(db: &dyn SourceDatabase, mut ctxt: SyntaxContext) -> Option<Crate> { // When resolving `$crate` from a `macro_rules!` invoked in a `macro`, // we don't want to pretend that the `macro_rules!` definition is in the `macro` // as described in `SyntaxContextId::apply_mark`, so we ignore prepended opaque marks. diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs index b511bc3c15..d91b0f378e 100644 --- a/crates/hir-expand/src/name.rs +++ b/crates/hir-expand/src/name.rs @@ -2,6 +2,7 @@ use std::fmt; +use base_db::SourceDatabase; use intern::{Symbol, sym}; use span::{Edition, SyntaxContext}; use syntax::utils::is_raw_identifier; @@ -180,7 +181,7 @@ impl Name { #[inline] pub fn display<'a>( &'a self, - db: &dyn crate::db::ExpandDatabase, + db: &dyn SourceDatabase, edition: Edition, ) -> impl fmt::Display + 'a { _ = db; diff --git a/crates/hir-expand/src/prettify_macro_expansion_.rs b/crates/hir-expand/src/prettify_macro_expansion_.rs index 687bd1a714..d088b0d1a9 100644 --- a/crates/hir-expand/src/prettify_macro_expansion_.rs +++ b/crates/hir-expand/src/prettify_macro_expansion_.rs @@ -1,15 +1,15 @@ //! Pretty printing of macros output. -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use rustc_hash::FxHashMap; use syntax::SyntaxNode; -use crate::{db::ExpandDatabase, span_map::ExpansionSpanMap}; +use crate::span_map::ExpansionSpanMap; /// Inserts whitespace and replaces `$crate` in macro expansions. #[expect(deprecated)] pub fn prettify_macro_expansion( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, syn: SyntaxNode, span_map: &ExpansionSpanMap, target_crate_id: Crate, diff --git a/crates/hir-expand/src/proc_macro.rs b/crates/hir-expand/src/proc_macro.rs index 94c105761d..f4a259dcc1 100644 --- a/crates/hir-expand/src/proc_macro.rs +++ b/crates/hir-expand/src/proc_macro.rs @@ -4,14 +4,14 @@ use core::fmt; use std::any::Any; use std::{panic::RefUnwindSafe, sync}; -use base_db::{Crate, CrateBuilderId, CratesIdMap, Env, ProcMacroLoadingError}; +use base_db::{Crate, CrateBuilderId, CratesIdMap, Env, ProcMacroLoadingError, SourceDatabase}; use intern::Symbol; use rustc_hash::FxHashMap; use salsa::{Durability, Setter}; use span::Span; use triomphe::Arc; -use crate::{ExpandError, ExpandErrorKind, ExpandResult, db::ExpandDatabase, tt}; +use crate::{ExpandError, ExpandErrorKind, ExpandResult, tt}; #[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Hash)] pub enum ProcMacroKind { @@ -26,7 +26,7 @@ pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + Any { /// [`ProcMacroKind::Attr`]), environment variables, and span information. fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, subtree: &tt::TopSubtree, attrs: Option<&tt::TopSubtree>, env: &Env, @@ -85,7 +85,7 @@ impl ProcMacrosBuilder { } /// Builds [`ProcMacros`] and adds id to `db` - pub(crate) fn build_in(self, db: &mut dyn ExpandDatabase, crates_id_map: &CratesIdMap) { + pub(crate) fn build_in(self, db: &mut dyn SourceDatabase, crates_id_map: &CratesIdMap) { let mut map = self .0 .into_iter() @@ -121,7 +121,7 @@ pub struct ProcMacros { } impl ProcMacros { - pub fn init_default(db: &dyn ExpandDatabase, durability: Durability) { + pub fn init_default(db: &dyn SourceDatabase, durability: Durability) { _ = Self::builder(Default::default()).durability(durability).new(db); } } @@ -130,7 +130,7 @@ impl ProcMacros { impl ProcMacros { /// Incrementality query to prevent queries from directly depending on [`Self::get`]. #[salsa::tracked(returns(as_ref))] - pub fn get_for_crate(db: &dyn ExpandDatabase, krate: Crate) -> Option<Arc<CrateProcMacros>> { + pub fn get_for_crate(db: &dyn SourceDatabase, krate: Crate) -> Option<Arc<CrateProcMacros>> { Self::get(db).by_crate(db).get(&krate).cloned() } } @@ -273,7 +273,7 @@ impl CustomProcMacroExpander { pub fn expand( self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, def_crate: Crate, calling_crate: Crate, tt: &tt::TopSubtree, diff --git a/crates/hir-expand/src/span_map.rs b/crates/hir-expand/src/span_map.rs index 8f2b74091f..7b1a04de73 100644 --- a/crates/hir-expand/src/span_map.rs +++ b/crates/hir-expand/src/span_map.rs @@ -1,11 +1,12 @@ //! Span maps for real files and macro expansions. +use base_db::SourceDatabase; use span::Span; use syntax::{AstNode, TextRange, ast}; pub use span::RealSpanMap; -use crate::{HirFileId, MacroCallId, db::ExpandDatabase}; +use crate::{HirFileId, MacroCallId}; pub type ExpansionSpanMap = span::SpanMap; @@ -39,7 +40,7 @@ impl<'db> SpanMap<'db> { impl HirFileId { #[inline] - pub fn span_map<'db>(self, db: &'db dyn ExpandDatabase) -> SpanMap<'db> { + pub fn span_map<'db>(self, db: &'db dyn SourceDatabase) -> SpanMap<'db> { match self { HirFileId::FileId(file_id) => SpanMap::RealSpanMap(real_span_map(db, file_id)), HirFileId::MacroFile(m) => SpanMap::ExpansionSpanMap(m.expansion_span_map(db)), @@ -51,7 +52,7 @@ impl HirFileId { /// `HirFileId::from(file_id).span_map(db)` instead of `real_span_map(db, file_id)`. #[salsa_macros::tracked(returns(ref))] pub(crate) fn real_span_map( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, editioned_file_id: base_db::EditionedFileId, ) -> RealSpanMap { use syntax::ast::HasModuleItem; @@ -114,7 +115,7 @@ pub(crate) fn real_span_map( } impl MacroCallId { - pub fn expansion_span_map(self, db: &dyn ExpandDatabase) -> &ExpansionSpanMap { + pub fn expansion_span_map(self, db: &dyn SourceDatabase) -> &ExpansionSpanMap { &self.parse_macro_expansion(db).value.1 } } diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs index b8f271108e..8ae3a024f0 100644 --- a/crates/hir/src/db.rs +++ b/crates/hir/src/db.rs @@ -4,5 +4,4 @@ //! //! But we need this for at least LRU caching at the query level. pub use hir_def::db::{DefDatabase, set_expand_proc_attr_macros}; -pub use hir_expand::db::ExpandDatabase; pub use hir_ty::db::HirDatabase; diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 8023d239af..ba488b8af3 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -26,7 +26,6 @@ use hir_expand::{ EditionedFileId, ExpandResult, FileRange, HirFileId, InMacroFile, MacroCallId, attrs::AstPathExt, builtin::{BuiltinFnLikeExpander, EagerExpander}, - db::ExpandDatabase, files::{FileRangeWrapper, HirFileRange, InRealFile}, mod_path::{ModPath, PathKind}, name::AsName, @@ -2604,7 +2603,7 @@ fn macro_call_to_macro_id( ctx: &mut SourceToDefCtx<'_, '_>, macro_call_id: MacroCallId, ) -> Option<MacroId> { - let db: &dyn ExpandDatabase = ctx.db; + let db = ctx.db; let loc = macro_call_id.loc(db); match loc.def.ast_id() { diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs index 7a3c466daa..93cfee8135 100644 --- a/crates/ide-db/src/apply_change.rs +++ b/crates/ide-db/src/apply_change.rs @@ -195,19 +195,6 @@ impl RootDatabase { // hir::db::InternProcMacroQuery // hir::db::InternMacroRulesQuery - // // ExpandDatabase - // hir::db::AstIdMapQuery - // hir::db::DeclMacroExpanderQuery - // hir::db::ExpandProcMacroQuery - // hir::db::InternMacroCallQuery - // hir::db::InternSyntaxContextQuery - // hir::db::MacroArgQuery - // hir::db::ParseMacroExpansionErrorQuery - // hir::db::ParseMacroExpansionQuery - // hir::db::ProcMacroSpanQuery - // hir::db::ProcMacrosQuery - // hir::db::RealSpanMapQuery - // // LineIndexDatabase // crate::LineIndexQuery diff --git a/crates/ide-ssr/src/replacing.rs b/crates/ide-ssr/src/replacing.rs index 16287a439c..6bf4e72f20 100644 --- a/crates/ide-ssr/src/replacing.rs +++ b/crates/ide-ssr/src/replacing.rs @@ -15,7 +15,7 @@ use crate::{Match, SsrMatches, fragments, resolving::ResolvedRule}; /// template. Placeholders in the template will have been substituted with whatever they matched to /// in the original code. pub(crate) fn matches_to_edit<'db>( - db: &'db dyn hir::db::ExpandDatabase, + db: &'db dyn ide_db::base_db::SourceDatabase, matches: &SsrMatches, file_src: &str, rules: &[ResolvedRule<'db>], @@ -24,7 +24,7 @@ pub(crate) fn matches_to_edit<'db>( } fn matches_to_edit_at_offset<'db>( - db: &'db dyn hir::db::ExpandDatabase, + db: &'db dyn ide_db::base_db::SourceDatabase, matches: &SsrMatches, file_src: &str, relative_start: TextSize, @@ -41,7 +41,7 @@ fn matches_to_edit_at_offset<'db>( } struct ReplacementRenderer<'a, 'db> { - db: &'db dyn hir::db::ExpandDatabase, + db: &'db dyn ide_db::base_db::SourceDatabase, match_info: &'a Match, file_src: &'a str, rules: &'a [ResolvedRule<'db>], @@ -59,7 +59,7 @@ struct ReplacementRenderer<'a, 'db> { } fn render_replace<'db>( - db: &'db dyn hir::db::ExpandDatabase, + db: &'db dyn ide_db::base_db::SourceDatabase, match_info: &Match, file_src: &str, rules: &[ResolvedRule<'db>], diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 9fc89e90f2..db5464a1fe 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -1,8 +1,9 @@ use std::iter; -use hir::{EditionedFileId, FilePosition, FileRange, HirFileId, InFile, Semantics, db}; +use hir::{EditionedFileId, FilePosition, FileRange, HirFileId, InFile, Semantics}; use ide_db::{ FxHashMap, FxHashSet, RootDatabase, + base_db::SourceDatabase, defs::{Definition, IdentClass}, helpers::pick_best_token, search::{FileReference, ReferenceCategory, SearchScope}, @@ -676,7 +677,7 @@ fn find_defs(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> FxHashSe } fn original_frange( - db: &dyn db::ExpandDatabase, + db: &dyn SourceDatabase, file_id: HirFileId, text_range: Option<TextRange>, ) -> Option<FileRange> { diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index b5860cb0ca..fb082d3209 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -11,16 +11,15 @@ extern crate rustc_driver as _; use std::{any::Any, collections::hash_map::Entry, mem, path::Path, sync}; use crossbeam_channel::{Receiver, unbounded}; -use hir_expand::{ - db::ExpandDatabase, - proc_macro::{ - ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacroLoadResult, - ProcMacrosBuilder, - }, +use hir_expand::proc_macro::{ + ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacroLoadResult, + ProcMacrosBuilder, }; use ide_db::{ ChangeWithProcMacros, FxHashMap, RootDatabase, - base_db::{CrateGraphBuilder, Env, ProcMacroLoadingError, SourceRoot, SourceRootId}, + base_db::{ + CrateGraphBuilder, Env, ProcMacroLoadingError, SourceDatabase, SourceRoot, SourceRootId, + }, prime_caches, }; use itertools::Itertools; @@ -569,7 +568,7 @@ struct Expander(proc_macro_api::ProcMacro); impl ProcMacroExpander for Expander { fn expand( &self, - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, subtree: &tt::TopSubtree, attrs: Option<&tt::TopSubtree>, env: &Env, @@ -749,7 +748,7 @@ impl ProcMacroExpander for Expander { } fn resolve_sub_span( - db: &dyn ExpandDatabase, + db: &dyn SourceDatabase, file_id: u32, ast_id: u32, range: TextRange, diff --git a/crates/proc-macro-api/src/bidirectional_protocol.rs b/crates/proc-macro-api/src/bidirectional_protocol.rs index 75c3bf8d35..f070b1c9a3 100644 --- a/crates/proc-macro-api/src/bidirectional_protocol.rs +++ b/crates/proc-macro-api/src/bidirectional_protocol.rs @@ -56,7 +56,7 @@ pub fn run_conversation( return Ok(BidirectionalMessage::Response(response)); } BidirectionalMessage::SubRequest(sr) => { - // TODO: Avoid `AssertUnwindSafe` by making the callback `UnwindSafe` once `ExpandDatabase` + // TODO: Avoid `AssertUnwindSafe` by making the callback `UnwindSafe` once `SourceDatabase` // becomes unwind-safe (currently blocked by `parking_lot::RwLock` in the VFS). let resp = match catch_unwind(AssertUnwindSafe(|| callback(sr))) { Ok(Ok(resp)) => BidirectionalMessage::SubResponse(resp), diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs index f346535ca1..63e76d049b 100644 --- a/crates/test-fixture/src/lib.rs +++ b/crates/test-fixture/src/lib.rs @@ -17,7 +17,6 @@ use cfg::CfgOptions; use hir_expand::{ EditionedFileId, FileRange, change::ChangeWithProcMacros, - db::ExpandDatabase, files::FilePosition, proc_macro::{ ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacrosBuilder, @@ -139,7 +138,7 @@ pub const WORKSPACE: base_db::SourceRootId = base_db::SourceRootId(0); /// /// Available proc macros: `identity` (attr), `DeriveIdentity` (derive), `input_replace` (attr), /// `mirror` (bang), `shorten` (bang) -pub trait WithFixture: Default + ExpandDatabase + SourceDatabase + 'static { +pub trait WithFixture: Default + SourceDatabase + 'static { /// See the trait documentation for more information on fixtures. #[track_caller] fn with_single_file( @@ -231,7 +230,7 @@ pub trait WithFixture: Default + ExpandDatabase + SourceDatabase + 'static { } } -impl<DB: ExpandDatabase + SourceDatabase + Default + 'static> WithFixture for DB {} +impl<DB: SourceDatabase + Default + 'static> WithFixture for DB {} pub struct ChangeFixture { pub file_position: Option<(span::EditionedFileId, RangeOrOffset)>, @@ -847,7 +846,7 @@ struct IdentityProcMacroExpander; impl ProcMacroExpander for IdentityProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -870,7 +869,7 @@ struct Issue18089ProcMacroExpander; impl ProcMacroExpander for Issue18089ProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -906,7 +905,7 @@ struct AttributeInputReplaceProcMacroExpander; impl ProcMacroExpander for AttributeInputReplaceProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, _: &TopSubtree, attrs: Option<&TopSubtree>, _: &Env, @@ -930,7 +929,7 @@ struct Issue18840ProcMacroExpander; impl ProcMacroExpander for Issue18840ProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, fn_: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -967,7 +966,7 @@ struct MirrorProcMacroExpander; impl ProcMacroExpander for MirrorProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, input: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -1006,7 +1005,7 @@ struct ShortenProcMacroExpander; impl ProcMacroExpander for ShortenProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, input: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -1051,7 +1050,7 @@ struct Issue17479ProcMacroExpander; impl ProcMacroExpander for Issue17479ProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -1082,7 +1081,7 @@ struct Issue18898ProcMacroExpander; impl ProcMacroExpander for Issue18898ProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -1136,7 +1135,7 @@ struct DisallowCfgProcMacroExpander; impl ProcMacroExpander for DisallowCfgProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _: Option<&TopSubtree>, _: &Env, @@ -1168,7 +1167,7 @@ struct GenerateSuffixedTypeProcMacroExpander; impl ProcMacroExpander for GenerateSuffixedTypeProcMacroExpander { fn expand( &self, - _: &dyn ExpandDatabase, + _: &dyn SourceDatabase, subtree: &TopSubtree, _attrs: Option<&TopSubtree>, _env: &Env, |