Skip to content

Commit a2ca03d

Browse files
committed
⬆️ salsa
1 parent 454cc31 commit a2ca03d

File tree

14 files changed

+190
-234
lines changed

14 files changed

+190
-234
lines changed

Cargo.lock

Lines changed: 55 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
66

77
[dependencies]
88
relative-path = "0.4.0"
9-
salsa = "0.9.2"
9+
salsa = "0.10.0-alpha1"
1010
rustc-hash = "1.0"
1111
parking_lot = "0.7.0"
1212
ra_arena = { path = "../ra_arena" }

crates/ra_db/src/input.rs

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -146,46 +146,31 @@ impl CrateGraph {
146146
}
147147
}
148148

149-
salsa::query_group! {
150-
pub trait FilesDatabase: salsa::Database {
151-
/// Text of the file.
152-
fn file_text(file_id: FileId) -> Arc<String> {
153-
type FileTextQuery;
154-
storage input;
155-
}
156-
/// Path to a file, relative to the root of its source root.
157-
fn file_relative_path(file_id: FileId) -> RelativePathBuf {
158-
type FileRelativePathQuery;
159-
storage input;
160-
}
161-
/// Source root of the file.
162-
fn file_source_root(file_id: FileId) -> SourceRootId {
163-
type FileSourceRootQuery;
164-
storage input;
165-
}
166-
/// Contents of the source root.
167-
fn source_root(id: SourceRootId) -> Arc<SourceRoot> {
168-
type SourceRootQuery;
169-
storage input;
170-
}
171-
/// The set of "local" (that is, from the current workspace) roots.
172-
/// Files in local roots are assumed to change frequently.
173-
fn local_roots() -> Arc<Vec<SourceRootId>> {
174-
type LocalRootsQuery;
175-
storage input;
176-
}
177-
/// The set of roots for crates.io libraries.
178-
/// Files in libraries are assumed to never change.
179-
fn library_roots() -> Arc<Vec<SourceRootId>> {
180-
type LibraryRootsQuery;
181-
storage input;
182-
}
183-
/// The crate graph.
184-
fn crate_graph() -> Arc<CrateGraph> {
185-
type CrateGraphQuery;
186-
storage input;
187-
}
188-
}
149+
#[salsa::query_group]
150+
pub trait FilesDatabase: salsa::Database {
151+
/// Text of the file.
152+
#[salsa::input]
153+
fn file_text(&self, file_id: FileId) -> Arc<String>;
154+
/// Path to a file, relative to the root of its source root.
155+
#[salsa::input]
156+
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
157+
/// Source root of the file.
158+
#[salsa::input]
159+
fn file_source_root(&self, file_id: FileId) -> SourceRootId;
160+
/// Contents of the source root.
161+
#[salsa::input]
162+
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
163+
/// The set of "local" (that is, from the current workspace) roots.
164+
/// Files in local roots are assumed to change frequently.
165+
#[salsa::input]
166+
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
167+
/// The set of roots for crates.io libraries.
168+
/// Files in libraries are assumed to never change.
169+
#[salsa::input]
170+
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
171+
/// The crate graph.
172+
#[salsa::input]
173+
fn crate_graph(&self) -> Arc<CrateGraph>;
189174
}
190175

191176
#[cfg(test)]

crates/ra_db/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::panic;
99

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

12+
pub use ::salsa as salsa;
1213
pub use crate::{
1314
cancellation::Canceled,
1415
syntax_ptr::LocalSyntaxPtr,
@@ -51,12 +52,9 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
5152
}
5253
}
5354

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

6260
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {

crates/ra_hir/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ authors = ["Aleksey Kladov <[email protected]>"]
88
arrayvec = "0.4.10"
99
log = "0.4.5"
1010
relative-path = "0.4.0"
11-
salsa = "0.9.2"
1211
rustc-hash = "1.0"
1312
parking_lot = "0.7.0"
1413
ena = "0.11"

crates/ra_hir/src/db.rs

Lines changed: 70 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
4-
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase};
4+
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, salsa};
55

66
use crate::{
77
DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId,
@@ -16,111 +16,77 @@ use crate::{
1616
impl_block::ModuleImplBlocks,
1717
};
1818

19-
salsa::query_group! {
20-
21-
pub trait HirDatabase: SyntaxDatabase
19+
#[salsa::query_group]
20+
pub trait HirDatabase:
21+
SyntaxDatabase
2222
+ AsRef<LocationIntener<DefLoc, DefId>>
2323
+ AsRef<LocationIntener<MacroCallLoc, MacroCallId>>
2424
{
25-
fn hir_source_file(file_id: HirFileId) -> TreeArc<SourceFile> {
26-
type HirSourceFileQuery;
27-
use fn HirFileId::hir_source_file;
28-
}
29-
30-
fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> {
31-
type ExpandMacroCallQuery;
32-
use fn crate::macros::expand_macro_invocation;
33-
}
34-
35-
fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
36-
type FnScopesQuery;
37-
use fn query_definitions::fn_scopes;
38-
}
39-
40-
fn struct_data(def_id: DefId) -> Arc<StructData> {
41-
type StructDataQuery;
42-
use fn crate::adt::StructData::struct_data_query;
43-
}
44-
45-
fn enum_data(def_id: DefId) -> Arc<EnumData> {
46-
type EnumDataQuery;
47-
use fn crate::adt::EnumData::enum_data_query;
48-
}
49-
50-
fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> {
51-
type EnumVariantDataQuery;
52-
use fn crate::adt::EnumVariantData::enum_variant_data_query;
53-
}
54-
55-
fn infer(def_id: DefId) -> Arc<InferenceResult> {
56-
type InferQuery;
57-
use fn crate::ty::infer;
58-
}
59-
60-
fn type_for_def(def_id: DefId) -> Ty {
61-
type TypeForDefQuery;
62-
use fn crate::ty::type_for_def;
63-
}
64-
65-
fn type_for_field(def_id: DefId, field: Name) -> Option<Ty> {
66-
type TypeForFieldQuery;
67-
use fn crate::ty::type_for_field;
68-
}
69-
70-
fn file_items(file_id: HirFileId) -> Arc<SourceFileItems> {
71-
type SourceFileItemsQuery;
72-
use fn query_definitions::file_items;
73-
}
74-
75-
fn file_item(source_item_id: SourceItemId) -> TreeArc<SyntaxNode> {
76-
type FileItemQuery;
77-
use fn query_definitions::file_item;
78-
}
79-
80-
fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> {
81-
type SubmodulesQuery;
82-
use fn crate::module_tree::Submodule::submodules_query;
83-
}
84-
85-
fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> {
86-
type InputModuleItemsQuery;
87-
use fn query_definitions::input_module_items;
88-
}
89-
90-
fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> {
91-
type ItemMapQuery;
92-
use fn query_definitions::item_map;
93-
}
94-
95-
fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> {
96-
type ModuleTreeQuery;
97-
use fn crate::module_tree::ModuleTree::module_tree_query;
98-
}
99-
100-
fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> {
101-
type ImplsInModuleQuery;
102-
use fn crate::impl_block::impls_in_module;
103-
}
104-
105-
fn impls_in_crate(krate: Crate) -> Arc<CrateImplBlocks> {
106-
type ImplsInCrateQuery;
107-
use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
108-
}
109-
110-
fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
111-
type BodyHirQuery;
112-
use fn crate::expr::body_hir;
113-
}
114-
115-
fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> {
116-
type BodySyntaxMappingQuery;
117-
use fn crate::expr::body_syntax_mapping;
118-
}
119-
120-
fn fn_signature(def_id: DefId) -> Arc<FnSignature> {
121-
type FnSignatureQuery;
122-
use fn crate::FnSignature::fn_signature_query;
123-
}
124-
}
25+
#[salsa::invoke(HirFileId::hir_source_file)]
26+
fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
27+
28+
#[salsa::invoke(crate::macros::expand_macro_invocation)]
29+
fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>;
30+
31+
#[salsa::invoke(query_definitions::fn_scopes)]
32+
fn fn_scopes(&self, def_id: DefId) -> Arc<FnScopes>;
33+
34+
#[salsa::invoke(crate::adt::StructData::struct_data_query)]
35+
fn struct_data(&self, def_id: DefId) -> Arc<StructData>;
36+
37+
#[salsa::invoke(crate::adt::EnumData::enum_data_query)]
38+
fn enum_data(&self, def_id: DefId) -> Arc<EnumData>;
39+
40+
#[salsa::invoke(crate::adt::EnumVariantData::enum_variant_data_query)]
41+
fn enum_variant_data(&self, def_id: DefId) -> Arc<EnumVariantData>;
42+
43+
#[salsa::invoke(crate::ty::infer)]
44+
fn infer(&self, def_id: DefId) -> Arc<InferenceResult>;
45+
46+
#[salsa::invoke(crate::ty::type_for_def)]
47+
fn type_for_def(&self, def_id: DefId) -> Ty;
48+
49+
#[salsa::invoke(crate::ty::type_for_field)]
50+
fn type_for_field(&self, def_id: DefId, field: Name) -> Option<Ty>;
51+
52+
#[salsa::invoke(query_definitions::file_items)]
53+
fn file_items(&self, file_id: HirFileId) -> Arc<SourceFileItems>;
54+
55+
#[salsa::invoke(query_definitions::file_item)]
56+
fn file_item(&self, source_item_id: SourceItemId) -> TreeArc<SyntaxNode>;
57+
58+
#[salsa::invoke(crate::module_tree::Submodule::submodules_query)]
59+
fn submodules(&self, source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>>;
60+
61+
#[salsa::invoke(query_definitions::input_module_items)]
62+
fn input_module_items(
63+
&self,
64+
source_root_id: SourceRootId,
65+
module_id: ModuleId,
66+
) -> Arc<InputModuleItems>;
67+
68+
#[salsa::invoke(query_definitions::item_map)]
69+
fn item_map(&self, source_root_id: SourceRootId) -> Arc<ItemMap>;
70+
71+
#[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)]
72+
fn module_tree(&self, source_root_id: SourceRootId) -> Arc<ModuleTree>;
73+
74+
#[salsa::invoke(crate::impl_block::impls_in_module)]
75+
fn impls_in_module(
76+
&self,
77+
source_root_id: SourceRootId,
78+
module_id: ModuleId,
79+
) -> Arc<ModuleImplBlocks>;
80+
81+
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
82+
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
83+
84+
#[salsa::invoke(crate::expr::body_hir)]
85+
fn body_hir(&self, def_id: DefId) -> Arc<crate::expr::Body>;
86+
87+
#[salsa::invoke(crate::expr::body_syntax_mapping)]
88+
fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>;
12589

90+
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
91+
fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>;
12692
}

crates/ra_hir/src/mock.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::{sync::Arc, panic};
22

33
use parking_lot::Mutex;
4-
use salsa::{self, Database};
5-
use ra_db::{LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId};
4+
use ra_db::{
5+
LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId,
6+
salsa::{self, Database},
7+
};
68
use relative_path::RelativePathBuf;
79
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
810

@@ -220,10 +222,10 @@ salsa::database_storage! {
220222
}
221223
impl db::HirDatabase {
222224
fn hir_source_file() for db::HirSourceFileQuery;
223-
fn expand_macro_invocation() for db::ExpandMacroCallQuery;
225+
fn expand_macro_invocation() for db::ExpandMacroInvocationQuery;
224226
fn module_tree() for db::ModuleTreeQuery;
225227
fn fn_scopes() for db::FnScopesQuery;
226-
fn file_items() for db::SourceFileItemsQuery;
228+
fn file_items() for db::FileItemsQuery;
227229
fn file_item() for db::FileItemQuery;
228230
fn input_module_items() for db::InputModuleItemsQuery;
229231
fn item_map() for db::ItemMapQuery;

crates/ra_hir/src/nameres/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::sync::Arc;
22

3-
use salsa::Database;
4-
use ra_db::{FilesDatabase, CrateGraph, SourceRootId};
3+
use ra_db::{FilesDatabase, CrateGraph, SourceRootId, salsa::Database};
54
use relative_path::RelativePath;
65
use test_utils::assert_eq_text;
76

crates/ra_hir/src/ty/tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::fmt::Write;
33
use std::path::{PathBuf, Path};
44
use std::fs;
55

6-
use salsa::Database;
7-
8-
use ra_db::SyntaxDatabase;
6+
use ra_db::{SyntaxDatabase, salsa::Database};
97
use ra_syntax::ast::{self, AstNode};
108
use test_utils::{project_dir, assert_eq_text, read_text};
119

crates/ra_ide_api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ log = "0.4.5"
1010
relative-path = "0.4.0"
1111
rayon = "1.0.2"
1212
fst = "0.3.1"
13-
salsa = "0.9.2"
1413
rustc-hash = "1.0"
1514
parking_lot = "0.7.0"
1615
unicase = "2.2.0"

crates/ra_ide_api/src/db.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::{fmt, sync::Arc};
22

3-
use salsa::{self, Database};
4-
use ra_db::{LocationIntener, BaseDatabase, FileId, Canceled};
3+
use ra_db::{
4+
LocationIntener, BaseDatabase, FileId, Canceled,
5+
salsa::{self, Database},
6+
};
57

68
use crate::{symbol_index, LineIndex};
79

@@ -73,12 +75,9 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas
7375
}
7476
}
7577

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

8483
fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
@@ -109,10 +108,10 @@ salsa::database_storage! {
109108
}
110109
impl hir::db::HirDatabase {
111110
fn hir_source_file() for hir::db::HirSourceFileQuery;
112-
fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery;
111+
fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery;
113112
fn module_tree() for hir::db::ModuleTreeQuery;
114113
fn fn_scopes() for hir::db::FnScopesQuery;
115-
fn file_items() for hir::db::SourceFileItemsQuery;
114+
fn file_items() for hir::db::FileItemsQuery;
116115
fn file_item() for hir::db::FileItemQuery;
117116
fn input_module_items() for hir::db::InputModuleItemsQuery;
118117
fn item_map() for hir::db::ItemMapQuery;

0 commit comments

Comments
 (0)