Skip to content

Commit

Permalink
⬆️ salsa
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jan 17, 2019
1 parent 454cc31 commit a2ca03d
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 234 deletions.
99 changes: 55 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/ra_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]

[dependencies]
relative-path = "0.4.0"
salsa = "0.9.2"
salsa = "0.10.0-alpha1"
rustc-hash = "1.0"
parking_lot = "0.7.0"
ra_arena = { path = "../ra_arena" }
Expand Down
65 changes: 25 additions & 40 deletions crates/ra_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,46 +146,31 @@ impl CrateGraph {
}
}

salsa::query_group! {
pub trait FilesDatabase: salsa::Database {
/// Text of the file.
fn file_text(file_id: FileId) -> Arc<String> {
type FileTextQuery;
storage input;
}
/// Path to a file, relative to the root of its source root.
fn file_relative_path(file_id: FileId) -> RelativePathBuf {
type FileRelativePathQuery;
storage input;
}
/// Source root of the file.
fn file_source_root(file_id: FileId) -> SourceRootId {
type FileSourceRootQuery;
storage input;
}
/// Contents of the source root.
fn source_root(id: SourceRootId) -> Arc<SourceRoot> {
type SourceRootQuery;
storage input;
}
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
fn local_roots() -> Arc<Vec<SourceRootId>> {
type LocalRootsQuery;
storage input;
}
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
fn library_roots() -> Arc<Vec<SourceRootId>> {
type LibraryRootsQuery;
storage input;
}
/// The crate graph.
fn crate_graph() -> Arc<CrateGraph> {
type CrateGraphQuery;
storage input;
}
}
#[salsa::query_group]
pub trait FilesDatabase: salsa::Database {
/// Text of the file.
#[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>;
/// Path to a file, relative to the root of its source root.
#[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
/// Source root of the file.
#[salsa::input]
fn file_source_root(&self, file_id: FileId) -> SourceRootId;
/// Contents of the source root.
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
}

#[cfg(test)]
Expand Down
10 changes: 4 additions & 6 deletions crates/ra_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::panic;

use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc};

pub use ::salsa as salsa;
pub use crate::{
cancellation::Canceled,
syntax_ptr::LocalSyntaxPtr,
Expand Down Expand Up @@ -51,12 +52,9 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
}
}

salsa::query_group! {
pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase {
fn source_file(file_id: FileId) -> TreeArc<SourceFile> {
type SourceFileQuery;
}
}
#[salsa::query_group]
pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase {
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
}

fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
Expand Down
1 change: 0 additions & 1 deletion crates/ra_hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
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"
Expand Down
174 changes: 70 additions & 104 deletions crates/ra_hir/src/db.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}

fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> {
type ExpandMacroCallQuery;
use fn crate::macros::expand_macro_invocation;
}

fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
type FnScopesQuery;
use fn query_definitions::fn_scopes;
}

fn struct_data(def_id: DefId) -> Arc<StructData> {
type StructDataQuery;
use fn crate::adt::StructData::struct_data_query;
}

fn enum_data(def_id: DefId) -> Arc<EnumData> {
type EnumDataQuery;
use fn crate::adt::EnumData::enum_data_query;
}

fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> {
type EnumVariantDataQuery;
use fn crate::adt::EnumVariantData::enum_variant_data_query;
}

fn infer(def_id: DefId) -> Arc<InferenceResult> {
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<Ty> {
type TypeForFieldQuery;
use fn crate::ty::type_for_field;
}

fn file_items(file_id: HirFileId) -> Arc<SourceFileItems> {
type SourceFileItemsQuery;
use fn query_definitions::file_items;
}

fn file_item(source_item_id: SourceItemId) -> TreeArc<SyntaxNode> {
type FileItemQuery;
use fn query_definitions::file_item;
}

fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> {
type SubmodulesQuery;
use fn crate::module_tree::Submodule::submodules_query;
}

fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> {
type InputModuleItemsQuery;
use fn query_definitions::input_module_items;
}

fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> {
type ItemMapQuery;
use fn query_definitions::item_map;
}

fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> {
type ModuleTreeQuery;
use fn crate::module_tree::ModuleTree::module_tree_query;
}

fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> {
type ImplsInModuleQuery;
use fn crate::impl_block::impls_in_module;
}

fn impls_in_crate(krate: Crate) -> Arc<CrateImplBlocks> {
type ImplsInCrateQuery;
use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
}

fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
type BodyHirQuery;
use fn crate::expr::body_hir;
}

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(HirFileId::hir_source_file)]
fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>;

#[salsa::invoke(crate::macros::expand_macro_invocation)]
fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>;

#[salsa::invoke(query_definitions::fn_scopes)]
fn fn_scopes(&self, def_id: DefId) -> Arc<FnScopes>;

#[salsa::invoke(crate::adt::StructData::struct_data_query)]
fn struct_data(&self, def_id: DefId) -> Arc<StructData>;

#[salsa::invoke(crate::adt::EnumData::enum_data_query)]
fn enum_data(&self, def_id: DefId) -> Arc<EnumData>;

#[salsa::invoke(crate::adt::EnumVariantData::enum_variant_data_query)]
fn enum_variant_data(&self, def_id: DefId) -> Arc<EnumVariantData>;

#[salsa::invoke(crate::ty::infer)]
fn infer(&self, def_id: DefId) -> Arc<InferenceResult>;

#[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<Ty>;

#[salsa::invoke(query_definitions::file_items)]
fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>;

#[salsa::invoke(query_definitions::file_item)]
fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>;

#[salsa::invoke(crate::module_tree::Submodule::submodules_query)]
fn submodules(&self, source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>>;

#[salsa::invoke(query_definitions::input_module_items)]
fn input_module_items(
&self,
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Arc<InputModuleItems>;

#[salsa::invoke(query_definitions::item_map)]
fn item_map(&self, source_root_id: SourceRootId) -> Arc<ItemMap>;

#[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]
fn module_tree(&self, source_root_id: SourceRootId) -> Arc<ModuleTree>;

#[salsa::invoke(crate::impl_block::impls_in_module)]
fn impls_in_module(
&self,
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Arc<ModuleImplBlocks>;

#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;

#[salsa::invoke(crate::expr::body_hir)]
fn body_hir(&self, def_id: DefId) -> Arc<crate::expr::Body>;

#[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>;
}
10 changes: 6 additions & 4 deletions crates/ra_hir/src/mock.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/ra_hir/src/nameres/tests.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 1 addition & 3 deletions crates/ra_hir/src/ty/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
1 change: 0 additions & 1 deletion crates/ra_ide_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ log = "0.4.5"
relative-path = "0.4.0"
rayon = "1.0.2"
fst = "0.3.1"
salsa = "0.9.2"
rustc-hash = "1.0"
parking_lot = "0.7.0"
unicase = "2.2.0"
Expand Down
19 changes: 9 additions & 10 deletions crates/ra_ide_api/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{fmt, sync::Arc};

use salsa::{self, Database};
use ra_db::{LocationIntener, BaseDatabase, FileId, Canceled};
use ra_db::{
LocationIntener, BaseDatabase, FileId, Canceled,
salsa::{self, Database},
};

use crate::{symbol_index, LineIndex};

Expand Down Expand Up @@ -73,12 +75,9 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas
}
}

salsa::query_group! {
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
fn line_index(file_id: FileId) -> Arc<LineIndex> {
type LineIndexQuery;
}
}
#[salsa::query_group]
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
}

fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
Expand Down Expand Up @@ -109,10 +108,10 @@ salsa::database_storage! {
}
impl hir::db::HirDatabase {
fn hir_source_file() for hir::db::HirSourceFileQuery;
fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery;
fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery;
fn module_tree() for hir::db::ModuleTreeQuery;
fn fn_scopes() for hir::db::FnScopesQuery;
fn file_items() for hir::db::SourceFileItemsQuery;
fn file_items() for hir::db::FileItemsQuery;
fn file_item() for hir::db::FileItemQuery;
fn input_module_items() for hir::db::InputModuleItemsQuery;
fn item_map() for hir::db::ItemMapQuery;
Expand Down
Loading

0 comments on commit a2ca03d

Please sign in to comment.