mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
⬆️ salsa
This commit is contained in:
parent
454cc31358
commit
a2ca03d10b
14 changed files with 172 additions and 216 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
|
||||
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase};
|
||||
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, salsa};
|
||||
|
||||
use crate::{
|
||||
DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId,
|
||||
|
@ -16,111 +16,77 @@ use crate::{
|
|||
impl_block::ModuleImplBlocks,
|
||||
};
|
||||
|
||||
salsa::query_group! {
|
||||
|
||||
pub trait HirDatabase: SyntaxDatabase
|
||||
#[salsa::query_group]
|
||||
pub trait HirDatabase:
|
||||
SyntaxDatabase
|
||||
+ AsRef<LocationIntener<DefLoc, DefId>>
|
||||
+ AsRef<LocationIntener<MacroCallLoc, MacroCallId>>
|
||||
{
|
||||
fn hir_source_file(file_id: HirFileId) -> TreeArc<SourceFile> {
|
||||
type HirSourceFileQuery;
|
||||
use fn HirFileId::hir_source_file;
|
||||
}
|
||||
#[salsa::invoke(HirFileId::hir_source_file)]
|
||||
fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
|
||||
|
||||
fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> {
|
||||
type ExpandMacroCallQuery;
|
||||
use fn crate::macros::expand_macro_invocation;
|
||||
}
|
||||
#[salsa::invoke(crate::macros::expand_macro_invocation)]
|
||||
fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>;
|
||||
|
||||
fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
|
||||
type FnScopesQuery;
|
||||
use fn query_definitions::fn_scopes;
|
||||
}
|
||||
#[salsa::invoke(query_definitions::fn_scopes)]
|
||||
fn fn_scopes(&self, def_id: DefId) -> Arc<FnScopes>;
|
||||
|
||||
fn struct_data(def_id: DefId) -> Arc<StructData> {
|
||||
type StructDataQuery;
|
||||
use fn crate::adt::StructData::struct_data_query;
|
||||
}
|
||||
#[salsa::invoke(crate::adt::StructData::struct_data_query)]
|
||||
fn struct_data(&self, def_id: DefId) -> Arc<StructData>;
|
||||
|
||||
fn enum_data(def_id: DefId) -> Arc<EnumData> {
|
||||
type EnumDataQuery;
|
||||
use fn crate::adt::EnumData::enum_data_query;
|
||||
}
|
||||
#[salsa::invoke(crate::adt::EnumData::enum_data_query)]
|
||||
fn enum_data(&self, def_id: DefId) -> Arc<EnumData>;
|
||||
|
||||
fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> {
|
||||
type EnumVariantDataQuery;
|
||||
use fn crate::adt::EnumVariantData::enum_variant_data_query;
|
||||
}
|
||||
#[salsa::invoke(crate::adt::EnumVariantData::enum_variant_data_query)]
|
||||
fn enum_variant_data(&self, def_id: DefId) -> Arc<EnumVariantData>;
|
||||
|
||||
fn infer(def_id: DefId) -> Arc<InferenceResult> {
|
||||
type InferQuery;
|
||||
use fn crate::ty::infer;
|
||||
}
|
||||
#[salsa::invoke(crate::ty::infer)]
|
||||
fn infer(&self, def_id: DefId) -> Arc<InferenceResult>;
|
||||
|
||||
fn type_for_def(def_id: DefId) -> Ty {
|
||||
type TypeForDefQuery;
|
||||
use fn crate::ty::type_for_def;
|
||||
}
|
||||
#[salsa::invoke(crate::ty::type_for_def)]
|
||||
fn type_for_def(&self, def_id: DefId) -> Ty;
|
||||
|
||||
fn type_for_field(def_id: DefId, field: Name) -> Option<Ty> {
|
||||
type TypeForFieldQuery;
|
||||
use fn crate::ty::type_for_field;
|
||||
}
|
||||
#[salsa::invoke(crate::ty::type_for_field)]
|
||||
fn type_for_field(&self, def_id: DefId, field: Name) -> Option<Ty>;
|
||||
|
||||
fn file_items(file_id: HirFileId) -> Arc<SourceFileItems> {
|
||||
type SourceFileItemsQuery;
|
||||
use fn query_definitions::file_items;
|
||||
}
|
||||
#[salsa::invoke(query_definitions::file_items)]
|
||||
fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>;
|
||||
|
||||
fn file_item(source_item_id: SourceItemId) -> TreeArc<SyntaxNode> {
|
||||
type FileItemQuery;
|
||||
use fn query_definitions::file_item;
|
||||
}
|
||||
#[salsa::invoke(query_definitions::file_item)]
|
||||
fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>;
|
||||
|
||||
fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> {
|
||||
type SubmodulesQuery;
|
||||
use fn crate::module_tree::Submodule::submodules_query;
|
||||
}
|
||||
#[salsa::invoke(crate::module_tree::Submodule::submodules_query)]
|
||||
fn submodules(&self, source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>>;
|
||||
|
||||
fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> {
|
||||
type InputModuleItemsQuery;
|
||||
use fn query_definitions::input_module_items;
|
||||
}
|
||||
#[salsa::invoke(query_definitions::input_module_items)]
|
||||
fn input_module_items(
|
||||
&self,
|
||||
source_root_id: SourceRootId,
|
||||
module_id: ModuleId,
|
||||
) -> Arc<InputModuleItems>;
|
||||
|
||||
fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> {
|
||||
type ItemMapQuery;
|
||||
use fn query_definitions::item_map;
|
||||
}
|
||||
#[salsa::invoke(query_definitions::item_map)]
|
||||
fn item_map(&self, source_root_id: SourceRootId) -> Arc<ItemMap>;
|
||||
|
||||
fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> {
|
||||
type ModuleTreeQuery;
|
||||
use fn crate::module_tree::ModuleTree::module_tree_query;
|
||||
}
|
||||
#[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]
|
||||
fn module_tree(&self, source_root_id: SourceRootId) -> Arc<ModuleTree>;
|
||||
|
||||
fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> {
|
||||
type ImplsInModuleQuery;
|
||||
use fn crate::impl_block::impls_in_module;
|
||||
}
|
||||
#[salsa::invoke(crate::impl_block::impls_in_module)]
|
||||
fn impls_in_module(
|
||||
&self,
|
||||
source_root_id: SourceRootId,
|
||||
module_id: ModuleId,
|
||||
) -> Arc<ModuleImplBlocks>;
|
||||
|
||||
fn impls_in_crate(krate: Crate) -> Arc<CrateImplBlocks> {
|
||||
type ImplsInCrateQuery;
|
||||
use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
|
||||
}
|
||||
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
||||
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
||||
|
||||
fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
|
||||
type BodyHirQuery;
|
||||
use fn crate::expr::body_hir;
|
||||
}
|
||||
#[salsa::invoke(crate::expr::body_hir)]
|
||||
fn body_hir(&self, def_id: DefId) -> Arc<crate::expr::Body>;
|
||||
|
||||
fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> {
|
||||
type BodySyntaxMappingQuery;
|
||||
use fn crate::expr::body_syntax_mapping;
|
||||
}
|
||||
|
||||
fn fn_signature(def_id: DefId) -> Arc<FnSignature> {
|
||||
type FnSignatureQuery;
|
||||
use fn crate::FnSignature::fn_signature_query;
|
||||
}
|
||||
}
|
||||
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
||||
fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>;
|
||||
|
||||
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
|
||||
fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use std::{sync::Arc, panic};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use salsa::{self, Database};
|
||||
use ra_db::{LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId};
|
||||
use ra_db::{
|
||||
LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId,
|
||||
salsa::{self, Database},
|
||||
};
|
||||
use relative_path::RelativePathBuf;
|
||||
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
|
||||
|
||||
|
@ -220,10 +222,10 @@ salsa::database_storage! {
|
|||
}
|
||||
impl db::HirDatabase {
|
||||
fn hir_source_file() for db::HirSourceFileQuery;
|
||||
fn expand_macro_invocation() for db::ExpandMacroCallQuery;
|
||||
fn expand_macro_invocation() for db::ExpandMacroInvocationQuery;
|
||||
fn module_tree() for db::ModuleTreeQuery;
|
||||
fn fn_scopes() for db::FnScopesQuery;
|
||||
fn file_items() for db::SourceFileItemsQuery;
|
||||
fn file_items() for db::FileItemsQuery;
|
||||
fn file_item() for db::FileItemQuery;
|
||||
fn input_module_items() for db::InputModuleItemsQuery;
|
||||
fn item_map() for db::ItemMapQuery;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use salsa::Database;
|
||||
use ra_db::{FilesDatabase, CrateGraph, SourceRootId};
|
||||
use ra_db::{FilesDatabase, CrateGraph, SourceRootId, salsa::Database};
|
||||
use relative_path::RelativePath;
|
||||
use test_utils::assert_eq_text;
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@ use std::fmt::Write;
|
|||
use std::path::{PathBuf, Path};
|
||||
use std::fs;
|
||||
|
||||
use salsa::Database;
|
||||
|
||||
use ra_db::SyntaxDatabase;
|
||||
use ra_db::{SyntaxDatabase, salsa::Database};
|
||||
use ra_syntax::ast::{self, AstNode};
|
||||
use test_utils::{project_dir, assert_eq_text, read_text};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue