From a2ca03d10b093ea20d7db8bfd78aa1e787482cc0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 17 Jan 2019 14:11:00 +0300 Subject: :arrow_up: salsa --- crates/ra_hir/Cargo.toml | 1 - crates/ra_hir/src/db.rs | 174 +++++++++++++++---------------------- crates/ra_hir/src/mock.rs | 10 ++- crates/ra_hir/src/nameres/tests.rs | 3 +- crates/ra_hir/src/ty/tests.rs | 4 +- 5 files changed, 78 insertions(+), 114 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 415848f09..87d2e98e9 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml @@ -8,7 +8,6 @@ authors = ["Aleksey Kladov "] arrayvec = "0.4.10" log = "0.4.5" relative-path = "0.4.0" -salsa = "0.9.2" rustc-hash = "1.0" parking_lot = "0.7.0" ena = "0.11" diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 0a0994f5f..b42f10071 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -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> + AsRef> { - fn hir_source_file(file_id: HirFileId) -> TreeArc { - type HirSourceFileQuery; - use fn HirFileId::hir_source_file; - } - - fn expand_macro_invocation(invoc: MacroCallId) -> Option> { - type ExpandMacroCallQuery; - use fn crate::macros::expand_macro_invocation; - } - - fn fn_scopes(def_id: DefId) -> Arc { - type FnScopesQuery; - use fn query_definitions::fn_scopes; - } - - fn struct_data(def_id: DefId) -> Arc { - type StructDataQuery; - use fn crate::adt::StructData::struct_data_query; - } - - fn enum_data(def_id: DefId) -> Arc { - type EnumDataQuery; - use fn crate::adt::EnumData::enum_data_query; - } - - fn enum_variant_data(def_id: DefId) -> Arc { - type EnumVariantDataQuery; - use fn crate::adt::EnumVariantData::enum_variant_data_query; - } - - fn infer(def_id: DefId) -> Arc { - type InferQuery; - use fn crate::ty::infer; - } - - fn type_for_def(def_id: DefId) -> Ty { - type TypeForDefQuery; - use fn crate::ty::type_for_def; - } - - fn type_for_field(def_id: DefId, field: Name) -> Option { - type TypeForFieldQuery; - use fn crate::ty::type_for_field; - } - - fn file_items(file_id: HirFileId) -> Arc { - type SourceFileItemsQuery; - use fn query_definitions::file_items; - } - - fn file_item(source_item_id: SourceItemId) -> TreeArc { - type FileItemQuery; - use fn query_definitions::file_item; - } - - fn submodules(source: SourceItemId) -> Arc> { - type SubmodulesQuery; - use fn crate::module_tree::Submodule::submodules_query; - } - - fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc { - type InputModuleItemsQuery; - use fn query_definitions::input_module_items; - } - - fn item_map(source_root_id: SourceRootId) -> Arc { - type ItemMapQuery; - use fn query_definitions::item_map; - } - - fn module_tree(source_root_id: SourceRootId) -> Arc { - type ModuleTreeQuery; - use fn crate::module_tree::ModuleTree::module_tree_query; - } - - fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc { - type ImplsInModuleQuery; - use fn crate::impl_block::impls_in_module; - } - - fn impls_in_crate(krate: Crate) -> Arc { - type ImplsInCrateQuery; - use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query; - } - - fn body_hir(def_id: DefId) -> Arc { - type BodyHirQuery; - use fn crate::expr::body_hir; - } - - fn body_syntax_mapping(def_id: DefId) -> Arc { - type BodySyntaxMappingQuery; - use fn crate::expr::body_syntax_mapping; - } - - fn fn_signature(def_id: DefId) -> Arc { - type FnSignatureQuery; - use fn crate::FnSignature::fn_signature_query; - } -} + #[salsa::invoke(HirFileId::hir_source_file)] + fn hir_source_file(&self, file_id: HirFileId) -> TreeArc; + + #[salsa::invoke(crate::macros::expand_macro_invocation)] + fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option>; + + #[salsa::invoke(query_definitions::fn_scopes)] + fn fn_scopes(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::adt::StructData::struct_data_query)] + fn struct_data(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::adt::EnumData::enum_data_query)] + fn enum_data(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::adt::EnumVariantData::enum_variant_data_query)] + fn enum_variant_data(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::ty::infer)] + fn infer(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::ty::type_for_def)] + fn type_for_def(&self, def_id: DefId) -> Ty; + + #[salsa::invoke(crate::ty::type_for_field)] + fn type_for_field(&self, def_id: DefId, field: Name) -> Option; + + #[salsa::invoke(query_definitions::file_items)] + fn file_items(&self, file_id: HirFileId) -> Arc; + + #[salsa::invoke(query_definitions::file_item)] + fn file_item(&self, source_item_id: SourceItemId) -> TreeArc; + + #[salsa::invoke(crate::module_tree::Submodule::submodules_query)] + fn submodules(&self, source: SourceItemId) -> Arc>; + + #[salsa::invoke(query_definitions::input_module_items)] + fn input_module_items( + &self, + source_root_id: SourceRootId, + module_id: ModuleId, + ) -> Arc; + + #[salsa::invoke(query_definitions::item_map)] + fn item_map(&self, source_root_id: SourceRootId) -> Arc; + + #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] + fn module_tree(&self, source_root_id: SourceRootId) -> Arc; + + #[salsa::invoke(crate::impl_block::impls_in_module)] + fn impls_in_module( + &self, + source_root_id: SourceRootId, + module_id: ModuleId, + ) -> Arc; + + #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] + fn impls_in_crate(&self, krate: Crate) -> Arc; + + #[salsa::invoke(crate::expr::body_hir)] + fn body_hir(&self, def_id: DefId) -> Arc; + + #[salsa::invoke(crate::expr::body_syntax_mapping)] + fn body_syntax_mapping(&self, def_id: DefId) -> Arc; + #[salsa::invoke(crate::FnSignature::fn_signature_query)] + fn fn_signature(&self, def_id: DefId) -> Arc; } diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 9371c5a0d..a83a5c6cc 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -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; diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 9a0474045..0ec11ec12 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -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; diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index affd63a85..a430cbe88 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -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}; -- cgit v1.2.3