Merge #1362
1362: Introduce AST database r=matklad a=matklad The idea here is to separate fragile bits which look into the syntax directly from robust bits which are safe across reparses. This uses the new `salsa::requires` featue Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
82cf27b5fc
@ -16,7 +16,12 @@ use vfs_filter::IncludeRustFiles;
|
||||
|
||||
type Result<T> = std::result::Result<T, failure::Error>;
|
||||
|
||||
#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)]
|
||||
#[salsa::database(
|
||||
ra_db::SourceDatabaseStorage,
|
||||
db::AstDatabaseStorage,
|
||||
db::DefDatabaseStorage,
|
||||
db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub struct BatchDatabase {
|
||||
runtime: salsa::Runtime<BatchDatabase>,
|
||||
|
@ -10,7 +10,7 @@ use ra_syntax::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Name, AsName, Struct, Union, Enum, EnumVariant, Crate,
|
||||
Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
|
||||
HirDatabase, HirFileId, StructField, FieldSource,
|
||||
type_ref::TypeRef, DefDatabase,
|
||||
};
|
||||
@ -55,7 +55,10 @@ impl StructData {
|
||||
StructData { name, variant_data }
|
||||
}
|
||||
|
||||
pub(crate) fn struct_data_query(db: &impl DefDatabase, struct_: Struct) -> Arc<StructData> {
|
||||
pub(crate) fn struct_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
struct_: Struct,
|
||||
) -> Arc<StructData> {
|
||||
let (_, struct_def) = struct_.source(db);
|
||||
Arc::new(StructData::new(&*struct_def))
|
||||
}
|
||||
@ -68,7 +71,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant>
|
||||
impl EnumVariant {
|
||||
pub(crate) fn source_impl(
|
||||
&self,
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
let (file_id, enum_def) = self.parent.source(db);
|
||||
let var = variants(&*enum_def)
|
||||
@ -91,7 +94,7 @@ pub struct EnumData {
|
||||
}
|
||||
|
||||
impl EnumData {
|
||||
pub(crate) fn enum_data_query(db: &impl DefDatabase, e: Enum) -> Arc<EnumData> {
|
||||
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
||||
let (_file_id, enum_def) = e.source(db);
|
||||
let name = enum_def.name().map(|n| n.as_name());
|
||||
let variants = variants(&*enum_def)
|
||||
@ -198,7 +201,10 @@ impl VariantDef {
|
||||
}
|
||||
|
||||
impl StructField {
|
||||
pub(crate) fn source_impl(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
|
||||
pub(crate) fn source_impl(
|
||||
&self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, FieldSource) {
|
||||
let var_data = self.parent.variant_data(db);
|
||||
let fields = var_data.fields().unwrap();
|
||||
let ss;
|
||||
|
@ -5,7 +5,7 @@ use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc};
|
||||
|
||||
use crate::{
|
||||
Name, AsName, AstId, Ty, HirFileId, Either, KnownName,
|
||||
HirDatabase, DefDatabase,
|
||||
HirDatabase, DefDatabase, AstDatabase,
|
||||
type_ref::TypeRef,
|
||||
nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
|
||||
expr::{Body, BodySourceMap, validation::ExprValidator},
|
||||
@ -147,7 +147,7 @@ pub enum ModuleSource {
|
||||
|
||||
impl ModuleSource {
|
||||
pub(crate) fn new(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: Option<FileId>,
|
||||
decl_id: Option<AstId<ast::Module>>,
|
||||
) -> ModuleSource {
|
||||
@ -168,7 +168,7 @@ impl ModuleSource {
|
||||
|
||||
impl Module {
|
||||
/// Name of this module.
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
let def_map = db.crate_def_map(self.krate);
|
||||
let parent = def_map[self.module_id].parent?;
|
||||
def_map[parent].children.iter().find_map(|(name, module_id)| {
|
||||
@ -181,7 +181,10 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
|
||||
pub fn definition_source(self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) {
|
||||
pub fn definition_source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, ModuleSource) {
|
||||
let def_map = db.crate_def_map(self.krate);
|
||||
let decl_id = def_map[self.module_id].declaration;
|
||||
let file_id = def_map[self.module_id].definition;
|
||||
@ -340,7 +343,7 @@ impl StructField {
|
||||
self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
|
||||
}
|
||||
|
||||
pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
|
||||
pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, FieldSource) {
|
||||
self.source_impl(db)
|
||||
}
|
||||
|
||||
@ -368,7 +371,10 @@ pub struct Struct {
|
||||
}
|
||||
|
||||
impl Struct {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -376,7 +382,7 @@ impl Struct {
|
||||
self.id.module(db)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
db.struct_data(self).name.clone()
|
||||
}
|
||||
|
||||
@ -432,11 +438,14 @@ pub struct Union {
|
||||
}
|
||||
|
||||
impl Union {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::StructDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
db.struct_data(Struct { id: self.id }).name.clone()
|
||||
}
|
||||
|
||||
@ -468,7 +477,10 @@ pub struct Enum {
|
||||
}
|
||||
|
||||
impl Enum {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -476,7 +488,7 @@ impl Enum {
|
||||
self.id.module(db)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
db.enum_data(self).name.clone()
|
||||
}
|
||||
|
||||
@ -521,7 +533,10 @@ pub struct EnumVariant {
|
||||
}
|
||||
|
||||
impl EnumVariant {
|
||||
pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
pub fn source(
|
||||
&self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
self.source_impl(db)
|
||||
}
|
||||
pub fn module(&self, db: &impl HirDatabase) -> Module {
|
||||
@ -610,7 +625,10 @@ pub struct FnSignature {
|
||||
}
|
||||
|
||||
impl FnSignature {
|
||||
pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
|
||||
pub(crate) fn fn_signature_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
func: Function,
|
||||
) -> Arc<FnSignature> {
|
||||
let (_, node) = func.source(db);
|
||||
let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
|
||||
let mut params = Vec::new();
|
||||
@ -668,7 +686,7 @@ impl FnSignature {
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, TreeArc<ast::FnDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -752,7 +770,10 @@ pub struct Const {
|
||||
}
|
||||
|
||||
impl Const {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::ConstDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -809,7 +830,7 @@ impl ConstSignature {
|
||||
}
|
||||
|
||||
pub(crate) fn const_signature_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Const,
|
||||
) -> Arc<ConstSignature> {
|
||||
let (_, node) = konst.source(db);
|
||||
@ -817,7 +838,7 @@ impl ConstSignature {
|
||||
}
|
||||
|
||||
pub(crate) fn static_signature_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Static,
|
||||
) -> Arc<ConstSignature> {
|
||||
let (_, node) = konst.source(db);
|
||||
@ -838,7 +859,10 @@ pub struct Static {
|
||||
}
|
||||
|
||||
impl Static {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::StaticDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -873,7 +897,10 @@ pub struct Trait {
|
||||
}
|
||||
|
||||
impl Trait {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
@ -922,7 +949,10 @@ pub struct TypeAlias {
|
||||
}
|
||||
|
||||
impl TypeAlias {
|
||||
pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
|
||||
self.id.source(db)
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,35 @@ use crate::{
|
||||
lang_item::{LangItems, LangItemTarget},
|
||||
};
|
||||
|
||||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
pub trait DefDatabase: SourceDatabase {
|
||||
// This database has access to source code, so queries here are not really
|
||||
// incremental.
|
||||
#[salsa::query_group(AstDatabaseStorage)]
|
||||
pub trait AstDatabase: SourceDatabase {
|
||||
#[salsa::interned]
|
||||
fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
|
||||
|
||||
#[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
|
||||
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
|
||||
#[salsa::transparent]
|
||||
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
|
||||
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
|
||||
#[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
|
||||
fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_def_query)]
|
||||
fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_arg_query)]
|
||||
fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_expand_query)]
|
||||
fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
|
||||
}
|
||||
|
||||
// This database uses `AstDatabase` internally,
|
||||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
#[salsa::requires(AstDatabase)]
|
||||
pub trait DefDatabase: SourceDatabase {
|
||||
#[salsa::interned]
|
||||
fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
|
||||
#[salsa::interned]
|
||||
@ -46,18 +71,6 @@ pub trait DefDatabase: SourceDatabase {
|
||||
#[salsa::interned]
|
||||
fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_def_query)]
|
||||
fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_arg_query)]
|
||||
fn macro_arg(&self, macro_call: ids::MacroCallId) -> Option<Arc<tt::Subtree>>;
|
||||
|
||||
#[salsa::invoke(crate::ids::macro_expand_query)]
|
||||
fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
|
||||
|
||||
#[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
|
||||
fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
|
||||
|
||||
#[salsa::invoke(crate::adt::StructData::struct_data_query)]
|
||||
fn struct_data(&self, s: Struct) -> Arc<StructData>;
|
||||
|
||||
@ -70,13 +83,6 @@ pub trait DefDatabase: SourceDatabase {
|
||||
#[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
|
||||
fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
|
||||
|
||||
#[salsa::invoke(crate::source_id::AstIdMap::ast_id_map_query)]
|
||||
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
|
||||
|
||||
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
|
||||
#[salsa::transparent]
|
||||
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
|
||||
|
||||
#[salsa::invoke(RawItems::raw_items_query)]
|
||||
fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
|
||||
|
||||
@ -121,7 +127,7 @@ pub trait DefDatabase: SourceDatabase {
|
||||
}
|
||||
|
||||
#[salsa::query_group(HirDatabaseStorage)]
|
||||
pub trait HirDatabase: DefDatabase {
|
||||
pub trait HirDatabase: DefDatabase + AstDatabase {
|
||||
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
||||
fn expr_scopes(&self, def: DefWithBody) -> Arc<ExprScopes>;
|
||||
|
||||
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner};
|
||||
|
||||
use crate::{
|
||||
db::{ HirDatabase, DefDatabase},
|
||||
db::{HirDatabase, DefDatabase, AstDatabase},
|
||||
Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef
|
||||
};
|
||||
|
||||
@ -52,7 +52,7 @@ impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlo
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
def: GenericDef,
|
||||
) -> Arc<GenericParams> {
|
||||
let mut generics = GenericParams::default();
|
||||
|
@ -9,7 +9,7 @@ use ra_prof::profile;
|
||||
use mbe::MacroRules;
|
||||
|
||||
use crate::{
|
||||
Module, DefDatabase, AstId, FileAstId,
|
||||
Module, DefDatabase, AstId, FileAstId, AstDatabase,
|
||||
};
|
||||
|
||||
/// hir makes heavy use of ids: integer (u32) handlers to various things. You
|
||||
@ -37,7 +37,7 @@ pub struct HirFileId(HirFileIdRepr);
|
||||
impl HirFileId {
|
||||
/// For macro-expansion files, returns the file original source file the
|
||||
/// expansion originated from.
|
||||
pub fn original_file(self, db: &impl DefDatabase) -> FileId {
|
||||
pub fn original_file(self, db: &impl AstDatabase) -> FileId {
|
||||
match self.0 {
|
||||
HirFileIdRepr::File(file_id) => file_id,
|
||||
HirFileIdRepr::Macro(macro_file) => {
|
||||
@ -58,7 +58,7 @@ impl HirFileId {
|
||||
}
|
||||
|
||||
pub(crate) fn parse_or_expand_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &impl AstDatabase,
|
||||
file_id: HirFileId,
|
||||
) -> Option<TreeArc<SyntaxNode>> {
|
||||
db.check_canceled();
|
||||
@ -120,7 +120,7 @@ impl From<FileId> for HirFileId {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>);
|
||||
|
||||
pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
||||
pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
||||
let macro_call = id.0.to_node(db);
|
||||
let arg = macro_call.token_tree()?;
|
||||
let (tt, _) = mbe::ast_to_token_tree(arg).or_else(|| {
|
||||
@ -134,7 +134,7 @@ pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<A
|
||||
Some(Arc::new(rules))
|
||||
}
|
||||
|
||||
pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> {
|
||||
pub(crate) fn macro_arg_query(db: &impl AstDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> {
|
||||
let loc = id.loc(db);
|
||||
let macro_call = loc.ast_id.to_node(db);
|
||||
let arg = macro_call.token_tree()?;
|
||||
@ -143,7 +143,7 @@ pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<
|
||||
}
|
||||
|
||||
pub(crate) fn macro_expand_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &impl AstDatabase,
|
||||
id: MacroCallId,
|
||||
) -> Result<Arc<tt::Subtree>, String> {
|
||||
let loc = id.loc(db);
|
||||
@ -185,7 +185,7 @@ pub struct MacroCallLoc {
|
||||
}
|
||||
|
||||
impl MacroCallId {
|
||||
pub(crate) fn loc(self, db: &impl DefDatabase) -> MacroCallLoc {
|
||||
pub(crate) fn loc(self, db: &impl AstDatabase) -> MacroCallLoc {
|
||||
db.lookup_intern_macro(self)
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ impl MacroCallId {
|
||||
}
|
||||
|
||||
impl MacroCallLoc {
|
||||
pub(crate) fn id(self, db: &impl DefDatabase) -> MacroCallId {
|
||||
pub(crate) fn id(self, db: &impl AstDatabase) -> MacroCallId {
|
||||
db.intern_macro(self)
|
||||
}
|
||||
}
|
||||
@ -233,7 +233,7 @@ pub(crate) struct LocationCtx<DB> {
|
||||
file_id: HirFileId,
|
||||
}
|
||||
|
||||
impl<'a, DB: DefDatabase> LocationCtx<&'a DB> {
|
||||
impl<'a, DB: DefDatabase + AstDatabase> LocationCtx<&'a DB> {
|
||||
pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
|
||||
LocationCtx { db, module, file_id }
|
||||
}
|
||||
@ -250,16 +250,19 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
||||
fn intern(db: &impl DefDatabase, loc: ItemLoc<N>) -> Self;
|
||||
fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<N>;
|
||||
|
||||
fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self {
|
||||
fn from_ast(ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>, ast: &N) -> Self {
|
||||
let items = ctx.db.ast_id_map(ctx.file_id);
|
||||
let item_id = items.ast_id(ast);
|
||||
Self::from_ast_id(ctx, item_id)
|
||||
}
|
||||
fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self {
|
||||
fn from_ast_id(
|
||||
ctx: LocationCtx<&(impl AstDatabase + DefDatabase)>,
|
||||
ast_id: FileAstId<N>,
|
||||
) -> Self {
|
||||
let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
|
||||
Self::intern(ctx.db, loc)
|
||||
}
|
||||
fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) {
|
||||
fn source(self, db: &(impl AstDatabase + DefDatabase)) -> (HirFileId, TreeArc<N>) {
|
||||
let loc = self.lookup_intern(db);
|
||||
let ast = loc.ast_id.to_node(db);
|
||||
(loc.ast_id.file_id(), ast)
|
||||
@ -356,7 +359,7 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
|
||||
}
|
||||
|
||||
impl MacroCallId {
|
||||
pub fn debug_dump(&self, db: &impl DefDatabase) -> String {
|
||||
pub fn debug_dump(&self, db: &impl AstDatabase) -> String {
|
||||
let loc = self.clone().loc(db);
|
||||
let node = loc.ast_id.to_node(db);
|
||||
let syntax_str = node.syntax().text().chunks().collect::<Vec<_>>().join(" ");
|
||||
@ -367,7 +370,7 @@ impl MacroCallId {
|
||||
let macro_rules = db.macro_def(loc.def);
|
||||
|
||||
format!(
|
||||
"macro call [file: {:#?}] : {}\nhas rules: {}",
|
||||
"macro call [file: {:?}] : {}\nhas rules: {}",
|
||||
db.file_relative_path(original),
|
||||
syntax_str,
|
||||
macro_rules.is_some()
|
||||
|
@ -8,7 +8,7 @@ use ra_syntax::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Const, TypeAlias, Function, HirFileId,
|
||||
Const, TypeAlias, Function, HirFileId, AstDatabase,
|
||||
HirDatabase, DefDatabase, TraitRef,
|
||||
type_ref::TypeRef,
|
||||
ids::LocationCtx,
|
||||
@ -58,7 +58,10 @@ impl ImplBlock {
|
||||
}
|
||||
|
||||
/// Returns the syntax of the impl block
|
||||
pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
pub fn source(
|
||||
&self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
||||
let (file_id, source) = self.module.definition_source(db);
|
||||
(file_id, source_map.get(&source, self.impl_id))
|
||||
@ -117,7 +120,7 @@ pub struct ImplData {
|
||||
|
||||
impl ImplData {
|
||||
pub(crate) fn from_ast(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
module: Module,
|
||||
node: &ast::ImplBlock,
|
||||
@ -187,7 +190,11 @@ pub struct ModuleImplBlocks {
|
||||
}
|
||||
|
||||
impl ModuleImplBlocks {
|
||||
fn collect(db: &impl DefDatabase, module: Module, source_map: &mut ImplSourceMap) -> Self {
|
||||
fn collect(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
module: Module,
|
||||
source_map: &mut ImplSourceMap,
|
||||
) -> Self {
|
||||
let mut m = ModuleImplBlocks {
|
||||
module,
|
||||
impls: Arena::default(),
|
||||
@ -218,7 +225,7 @@ impl ModuleImplBlocks {
|
||||
}
|
||||
|
||||
pub(crate) fn impls_in_module_with_source_map_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
module: Module,
|
||||
) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) {
|
||||
let mut source_map = ImplSourceMap::default();
|
||||
|
@ -4,7 +4,7 @@ use rustc_hash::FxHashMap;
|
||||
use ra_syntax::{SmolStr, ast::AttrsOwner};
|
||||
|
||||
use crate::{
|
||||
Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, Static, Struct, Trait
|
||||
Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, Static, Struct, Trait, AstDatabase,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
@ -41,7 +41,10 @@ impl LangItems {
|
||||
}
|
||||
|
||||
/// Salsa query. This will look for lang items in a specific crate.
|
||||
pub(crate) fn lang_items_query(db: &impl DefDatabase, krate: Crate) -> Arc<LangItems> {
|
||||
pub(crate) fn lang_items_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
krate: Crate,
|
||||
) -> Arc<LangItems> {
|
||||
let mut lang_items = LangItems { items: FxHashMap::default() };
|
||||
|
||||
if let Some(module) = krate.root_module(db) {
|
||||
@ -74,7 +77,11 @@ impl LangItems {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_lang_items_recursive(&mut self, db: &impl DefDatabase, module: &Module) {
|
||||
fn collect_lang_items_recursive(
|
||||
&mut self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
module: &Module,
|
||||
) {
|
||||
// Look for impl targets
|
||||
let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone());
|
||||
let source = module.definition_source(db).1;
|
||||
|
@ -48,7 +48,7 @@ mod code_model;
|
||||
mod marks;
|
||||
|
||||
use crate::{
|
||||
db::{HirDatabase, DefDatabase},
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
name::{AsName, KnownName},
|
||||
source_id::{FileAstId, AstId},
|
||||
resolve::Resolver,
|
||||
|
@ -13,7 +13,12 @@ use crate::{db, diagnostics::DiagnosticSink};
|
||||
|
||||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
||||
|
||||
#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)]
|
||||
#[salsa::database(
|
||||
ra_db::SourceDatabaseStorage,
|
||||
db::AstDatabaseStorage,
|
||||
db::DefDatabaseStorage,
|
||||
db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub struct MockDatabase {
|
||||
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
|
||||
|
@ -65,7 +65,7 @@ use ra_prof::profile;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{
|
||||
ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType,
|
||||
ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType, AstDatabase,
|
||||
DefDatabase, Path, PathKind, HirFileId, Trait,
|
||||
ids::MacroDefId,
|
||||
diagnostics::DiagnosticSink,
|
||||
@ -232,7 +232,10 @@ fn or(left: ItemOrMacro, right: ItemOrMacro) -> ItemOrMacro {
|
||||
}
|
||||
|
||||
impl CrateDefMap {
|
||||
pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> {
|
||||
pub(crate) fn crate_def_map_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
krate: Crate,
|
||||
) -> Arc<CrateDefMap> {
|
||||
db.check_canceled();
|
||||
let _p = profile("crate_def_map_query");
|
||||
let def_map = {
|
||||
@ -278,7 +281,7 @@ impl CrateDefMap {
|
||||
|
||||
pub(crate) fn add_diagnostics(
|
||||
&self,
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
module: CrateModuleId,
|
||||
sink: &mut DiagnosticSink,
|
||||
) {
|
||||
@ -534,7 +537,7 @@ mod diagnostics {
|
||||
use ra_syntax::{AstPtr, ast};
|
||||
|
||||
use crate::{
|
||||
AstId, DefDatabase,
|
||||
AstId, DefDatabase, AstDatabase,
|
||||
nameres::CrateModuleId,
|
||||
diagnostics::{DiagnosticSink, UnresolvedModule}
|
||||
};
|
||||
@ -551,7 +554,7 @@ mod diagnostics {
|
||||
impl DefDiagnostic {
|
||||
pub(super) fn add_to(
|
||||
&self,
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
target_module: CrateModuleId,
|
||||
sink: &mut DiagnosticSink,
|
||||
) {
|
||||
|
@ -8,7 +8,7 @@ use ra_syntax::ast;
|
||||
|
||||
use crate::{
|
||||
Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef,
|
||||
DefDatabase, HirFileId, Name, Path,
|
||||
DefDatabase, HirFileId, Name, Path, AstDatabase,
|
||||
KnownName,
|
||||
nameres::{
|
||||
Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode,
|
||||
@ -20,7 +20,10 @@ use crate::{
|
||||
AstId,
|
||||
};
|
||||
|
||||
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||
pub(super) fn collect_defs(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
mut def_map: CrateDefMap,
|
||||
) -> CrateDefMap {
|
||||
// populate external prelude
|
||||
for dep in def_map.krate.dependencies(db) {
|
||||
log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate);
|
||||
@ -93,7 +96,7 @@ struct DefCollector<DB> {
|
||||
|
||||
impl<'a, DB> DefCollector<&'a DB>
|
||||
where
|
||||
DB: DefDatabase,
|
||||
DB: DefDatabase + AstDatabase,
|
||||
{
|
||||
fn collect(&mut self) {
|
||||
let crate_graph = self.db.crate_graph();
|
||||
@ -470,7 +473,7 @@ struct ModCollector<'a, D> {
|
||||
|
||||
impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
|
||||
where
|
||||
DB: DefDatabase,
|
||||
DB: DefDatabase + AstDatabase,
|
||||
{
|
||||
fn collect(&mut self, items: &[raw::RawItem]) {
|
||||
for item in items {
|
||||
@ -615,7 +618,7 @@ fn is_macro_rules(path: &Path) -> bool {
|
||||
}
|
||||
|
||||
fn resolve_submodule(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
name: &Name,
|
||||
is_root: bool,
|
||||
@ -658,7 +661,7 @@ mod tests {
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
fn do_collect_defs(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
def_map: CrateDefMap,
|
||||
monitor: MacroStackMonitor,
|
||||
) -> CrateDefMap {
|
||||
|
@ -7,7 +7,7 @@ use ra_syntax::{
|
||||
ast::{self, NameOwner, AttrsOwner},
|
||||
};
|
||||
|
||||
use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either};
|
||||
use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either, AstDatabase};
|
||||
|
||||
/// `RawItems` is a set of top-level items in a file (except for impls).
|
||||
///
|
||||
@ -56,12 +56,15 @@ impl ImportSourceMap {
|
||||
}
|
||||
|
||||
impl RawItems {
|
||||
pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<RawItems> {
|
||||
pub(crate) fn raw_items_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
) -> Arc<RawItems> {
|
||||
db.raw_items_with_source_map(file_id).0
|
||||
}
|
||||
|
||||
pub(crate) fn raw_items_with_source_map_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
|
||||
let mut collector = RawItemsCollector {
|
||||
|
@ -3,7 +3,7 @@ use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}};
|
||||
use ra_arena::{Arena, RawId, impl_arena_id};
|
||||
use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast};
|
||||
|
||||
use crate::{HirFileId, DefDatabase};
|
||||
use crate::{HirFileId, AstDatabase};
|
||||
|
||||
/// `AstId` points to an AST node in any file.
|
||||
///
|
||||
@ -38,7 +38,7 @@ impl<N: AstNode> AstId<N> {
|
||||
self.file_id
|
||||
}
|
||||
|
||||
pub(crate) fn to_node(&self, db: &impl DefDatabase) -> TreeArc<N> {
|
||||
pub(crate) fn to_node(&self, db: &impl AstDatabase) -> TreeArc<N> {
|
||||
let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw);
|
||||
N::cast(&syntax_node).unwrap().to_owned()
|
||||
}
|
||||
@ -87,7 +87,7 @@ pub struct AstIdMap {
|
||||
}
|
||||
|
||||
impl AstIdMap {
|
||||
pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||
pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||
let map = if let Some(node) = db.parse_or_expand(file_id) {
|
||||
AstIdMap::from_source(&*node)
|
||||
} else {
|
||||
@ -97,7 +97,7 @@ impl AstIdMap {
|
||||
}
|
||||
|
||||
pub(crate) fn file_item_query(
|
||||
db: &impl DefDatabase,
|
||||
db: &impl AstDatabase,
|
||||
file_id: HirFileId,
|
||||
ast_id: ErasedFileAstId,
|
||||
) -> TreeArc<SyntaxNode> {
|
||||
|
@ -5,7 +5,10 @@ use rustc_hash::FxHashMap;
|
||||
|
||||
use ra_syntax::ast::{self, NameOwner};
|
||||
|
||||
use crate::{Function, Const, TypeAlias, Name, DefDatabase, Trait, ids::LocationCtx, name::AsName, Module};
|
||||
use crate::{
|
||||
Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module,
|
||||
ids::LocationCtx, name::AsName,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TraitData {
|
||||
@ -15,7 +18,10 @@ pub struct TraitData {
|
||||
}
|
||||
|
||||
impl TraitData {
|
||||
pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: Trait) -> Arc<TraitData> {
|
||||
pub(crate) fn trait_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
tr: Trait,
|
||||
) -> Arc<TraitData> {
|
||||
let (file_id, node) = tr.source(db);
|
||||
let name = node.name().map(|n| n.as_name());
|
||||
let module = tr.module(db);
|
||||
|
@ -2,9 +2,12 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef};
|
||||
use crate::{TypeAlias, DefDatabase, AstDatabase, type_ref::TypeRef};
|
||||
|
||||
pub(crate) fn type_alias_ref_query(db: &impl DefDatabase, typ: TypeAlias) -> Arc<TypeRef> {
|
||||
pub(crate) fn type_alias_ref_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
typ: TypeAlias,
|
||||
) -> Arc<TypeRef> {
|
||||
let (_, node) = typ.source(db);
|
||||
Arc::new(TypeRef::from_ast_opt(node.type_ref()))
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
|
||||
ra_db::SourceDatabaseStorage,
|
||||
LineIndexDatabaseStorage,
|
||||
symbol_index::SymbolsDatabaseStorage,
|
||||
hir::db::HirDatabaseStorage,
|
||||
hir::db::DefDatabaseStorage
|
||||
hir::db::AstDatabaseStorage,
|
||||
hir::db::DefDatabaseStorage,
|
||||
hir::db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct RootDatabase {
|
||||
|
Loading…
x
Reference in New Issue
Block a user