mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-24 12:03:31 +00:00
:arrow_up salsa
This commit is contained in:
parent
ae97cd59ff
commit
8cf092d5de
9 changed files with 79 additions and 158 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -726,7 +726,7 @@ dependencies = [
|
|||
"ra_syntax 0.1.0",
|
||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
]
|
||||
|
||||
|
@ -746,6 +746,7 @@ dependencies = [
|
|||
"ra_syntax 0.1.0",
|
||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
]
|
||||
|
||||
|
@ -766,6 +767,7 @@ dependencies = [
|
|||
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
"unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -1088,7 +1090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "salsa"
|
||||
version = "0.10.0-alpha1"
|
||||
version = "0.10.0-alpha3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1097,13 +1099,13 @@ dependencies = [
|
|||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa-macros 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa-macros 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "salsa-macros"
|
||||
version = "0.10.0-alpha1"
|
||||
version = "0.10.0-alpha3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1694,8 +1696,8 @@ dependencies = [
|
|||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
|
||||
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
|
||||
"checksum salsa 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)" = "4cc048429df53bf0720b93cfa5fa8c3fc3dc7dd65ab41b3f754a8870e7b5c834"
|
||||
"checksum salsa-macros 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d5a1aeb618da4b1a00d2885d045154ac30deb04109f3ce73c1fd789caba4fb1"
|
||||
"checksum salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)" = "135c0977b23f8a9dc16744dd5495989110e3763ba5ea41e386741c7f8901e285"
|
||||
"checksum salsa-macros 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)" = "c9c93b5efed7281334c4bed8470b278076d1ccd6a60da59a15cd0d57792afff8"
|
||||
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
|
|
|
@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
|||
|
||||
[dependencies]
|
||||
relative-path = "0.4.0"
|
||||
salsa = "0.10.0-alpha1"
|
||||
salsa = "0.10.0-alpha3"
|
||||
rustc-hash = "1.0"
|
||||
parking_lot = "0.7.0"
|
||||
ra_arena = { path = "../ra_arena" }
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
/// Note that neither this module, nor any other part of the analyzer's core do
|
||||
/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how
|
||||
/// actual IO is done and lowered to input.
|
||||
use std::sync::Arc;
|
||||
|
||||
use relative_path::RelativePathBuf;
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa;
|
||||
|
||||
use ra_syntax::SmolStr;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
@ -146,45 +143,6 @@ impl CrateGraph {
|
|||
}
|
||||
}
|
||||
|
||||
#[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>;
|
||||
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
|
||||
let root = db.source_root(id);
|
||||
let graph = db.crate_graph();
|
||||
let res = root
|
||||
.files
|
||||
.values()
|
||||
.filter_map(|&it| graph.crate_id_for_crate_root(it))
|
||||
.collect::<Vec<_>>();
|
||||
Arc::new(res)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{CrateGraph, FileId, SmolStr};
|
||||
|
|
|
@ -4,17 +4,18 @@ mod input;
|
|||
mod loc2id;
|
||||
pub mod mock;
|
||||
|
||||
use std::panic;
|
||||
use std::{
|
||||
panic, sync::Arc,
|
||||
};
|
||||
|
||||
use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc};
|
||||
use relative_path::RelativePathBuf;
|
||||
|
||||
pub use ::salsa as salsa;
|
||||
pub use crate::{
|
||||
cancellation::Canceled,
|
||||
input::{
|
||||
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,
|
||||
FileTextQuery, FileSourceRootQuery, SourceRootQuery, SourceRootCratesQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery,
|
||||
FileRelativePathQuery
|
||||
FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,
|
||||
},
|
||||
loc2id::LocationIntener,
|
||||
};
|
||||
|
@ -50,16 +51,6 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
|
|||
}
|
||||
}
|
||||
|
||||
#[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> {
|
||||
let text = db.file_text(file_id);
|
||||
SourceFile::parse(&*text)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FilePosition {
|
||||
pub file_id: FileId,
|
||||
|
@ -71,3 +62,52 @@ pub struct FileRange {
|
|||
pub file_id: FileId,
|
||||
pub range: TextRange,
|
||||
}
|
||||
|
||||
#[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>;
|
||||
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
|
||||
let root = db.source_root(id);
|
||||
let graph = db.crate_graph();
|
||||
let res = root
|
||||
.files
|
||||
.values()
|
||||
.filter_map(|&it| graph.crate_id_for_crate_root(it))
|
||||
.collect::<Vec<_>>();
|
||||
Arc::new(res)
|
||||
}
|
||||
|
||||
#[salsa::query_group]
|
||||
pub trait SyntaxDatabase: FilesDatabase + BaseDatabase {
|
||||
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
|
||||
}
|
||||
|
||||
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
|
||||
let text = db.file_text(file_id);
|
||||
SourceFile::parse(&*text)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ rustc-hash = "1.0"
|
|||
parking_lot = "0.7.0"
|
||||
ena = "0.11"
|
||||
join_to_string = "0.1.3"
|
||||
salsa = "0.10.0-alpha3"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_arena = { path = "../ra_arena" }
|
||||
ra_db = { path = "../ra_db" }
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::{db, HirInterner};
|
|||
|
||||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
||||
|
||||
#[salsa::database(ra_db::FilesDatabase, ra_db::SyntaxDatabase, db::HirDatabase)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct MockDatabase {
|
||||
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
|
||||
|
@ -181,8 +182,7 @@ impl MockDatabase {
|
|||
pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> {
|
||||
*self.events.lock() = Some(Vec::new());
|
||||
f();
|
||||
let events = self.events.lock().take().unwrap();
|
||||
events
|
||||
self.events.lock().take().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> {
|
||||
|
@ -192,51 +192,11 @@ impl MockDatabase {
|
|||
.filter_map(|e| match e.kind {
|
||||
// This pretty horrible, but `Debug` is the only way to inspect
|
||||
// QueryDescriptor at the moment.
|
||||
salsa::EventKind::WillExecute { descriptor } => Some(format!("{:?}", descriptor)),
|
||||
salsa::EventKind::WillExecute { database_key } => {
|
||||
Some(format!("{:?}", database_key))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
salsa::database_storage! {
|
||||
pub(crate) struct MockDatabaseStorage for MockDatabase {
|
||||
impl ra_db::FilesDatabase {
|
||||
fn file_text() for ra_db::FileTextQuery;
|
||||
fn file_relative_path() for ra_db::FileRelativePathQuery;
|
||||
fn file_source_root() for ra_db::FileSourceRootQuery;
|
||||
fn source_root() for ra_db::SourceRootQuery;
|
||||
fn source_root_crates() for ra_db::SourceRootCratesQuery;
|
||||
fn local_roots() for ra_db::LocalRootsQuery;
|
||||
fn library_roots() for ra_db::LibraryRootsQuery;
|
||||
fn crate_graph() for ra_db::CrateGraphQuery;
|
||||
}
|
||||
impl ra_db::SyntaxDatabase {
|
||||
fn source_file() for ra_db::SourceFileQuery;
|
||||
}
|
||||
impl db::HirDatabase {
|
||||
fn hir_source_file() for db::HirSourceFileQuery;
|
||||
fn expand_macro_invocation() for db::ExpandMacroInvocationQuery;
|
||||
fn module_tree() for db::ModuleTreeQuery;
|
||||
fn fn_scopes() for db::FnScopesQuery;
|
||||
fn file_items() for db::FileItemsQuery;
|
||||
fn file_item() for db::FileItemQuery;
|
||||
fn lower_module() for db::LowerModuleQuery;
|
||||
fn lower_module_module() for db::LowerModuleModuleQuery;
|
||||
fn lower_module_source_map() for db::LowerModuleSourceMapQuery;
|
||||
fn item_map() for db::ItemMapQuery;
|
||||
fn submodules() for db::SubmodulesQuery;
|
||||
fn infer() for db::InferQuery;
|
||||
fn type_for_def() for db::TypeForDefQuery;
|
||||
fn type_for_field() for db::TypeForFieldQuery;
|
||||
fn struct_data() for db::StructDataQuery;
|
||||
fn enum_data() for db::EnumDataQuery;
|
||||
fn impls_in_module() for db::ImplsInModuleQuery;
|
||||
fn impls_in_crate() for db::ImplsInCrateQuery;
|
||||
fn body_hir() for db::BodyHirQuery;
|
||||
fn body_syntax_mapping() for db::BodySyntaxMappingQuery;
|
||||
fn fn_signature() for db::FnSignatureQuery;
|
||||
fn generic_params() for db::GenericParamsQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ fst = "0.3.1"
|
|||
rustc-hash = "1.0"
|
||||
parking_lot = "0.7.0"
|
||||
unicase = "2.2.0"
|
||||
salsa = "0.10.0-alpha3"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_ide_api_light = { path = "../ra_ide_api_light" }
|
||||
|
|
|
@ -7,6 +7,13 @@ use ra_db::{
|
|||
|
||||
use crate::{symbol_index, LineIndex};
|
||||
|
||||
#[salsa::database(
|
||||
ra_db::FilesDatabase,
|
||||
ra_db::SyntaxDatabase,
|
||||
LineIndexDatabase,
|
||||
symbol_index::SymbolsDatabase,
|
||||
hir::db::HirDatabase
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct RootDatabase {
|
||||
runtime: salsa::Runtime<RootDatabase>,
|
||||
|
@ -64,52 +71,3 @@ fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex>
|
|||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
|
||||
salsa::database_storage! {
|
||||
pub(crate) struct RootDatabaseStorage for RootDatabase {
|
||||
impl ra_db::FilesDatabase {
|
||||
fn file_text() for ra_db::FileTextQuery;
|
||||
fn file_relative_path() for ra_db::FileRelativePathQuery;
|
||||
fn file_source_root() for ra_db::FileSourceRootQuery;
|
||||
fn source_root() for ra_db::SourceRootQuery;
|
||||
fn source_root_crates() for ra_db::SourceRootCratesQuery;
|
||||
fn local_roots() for ra_db::LocalRootsQuery;
|
||||
fn library_roots() for ra_db::LibraryRootsQuery;
|
||||
fn crate_graph() for ra_db::CrateGraphQuery;
|
||||
}
|
||||
impl ra_db::SyntaxDatabase {
|
||||
fn source_file() for ra_db::SourceFileQuery;
|
||||
}
|
||||
impl LineIndexDatabase {
|
||||
fn line_index() for LineIndexQuery;
|
||||
}
|
||||
impl symbol_index::SymbolsDatabase {
|
||||
fn file_symbols() for symbol_index::FileSymbolsQuery;
|
||||
fn library_symbols() for symbol_index::LibrarySymbolsQuery;
|
||||
}
|
||||
impl hir::db::HirDatabase {
|
||||
fn hir_source_file() for hir::db::HirSourceFileQuery;
|
||||
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::FileItemsQuery;
|
||||
fn file_item() for hir::db::FileItemQuery;
|
||||
fn lower_module() for hir::db::LowerModuleQuery;
|
||||
fn lower_module_module() for hir::db::LowerModuleModuleQuery;
|
||||
fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery;
|
||||
fn item_map() for hir::db::ItemMapQuery;
|
||||
fn submodules() for hir::db::SubmodulesQuery;
|
||||
fn infer() for hir::db::InferQuery;
|
||||
fn type_for_def() for hir::db::TypeForDefQuery;
|
||||
fn type_for_field() for hir::db::TypeForFieldQuery;
|
||||
fn struct_data() for hir::db::StructDataQuery;
|
||||
fn enum_data() for hir::db::EnumDataQuery;
|
||||
fn impls_in_module() for hir::db::ImplsInModuleQuery;
|
||||
fn impls_in_crate() for hir::db::ImplsInCrateQuery;
|
||||
fn body_hir() for hir::db::BodyHirQuery;
|
||||
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
|
||||
fn fn_signature() for hir::db::FnSignatureQuery;
|
||||
fn generic_params() for hir::db::GenericParamsQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use ra_db::{
|
|||
use crate::db::RootDatabase;
|
||||
|
||||
pub(crate) fn status(db: &RootDatabase) -> String {
|
||||
let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len();
|
||||
let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len();
|
||||
let n_defs = {
|
||||
let interner: &hir::HirInterner = db.as_ref();
|
||||
interner.len()
|
||||
|
|
Loading…
Reference in a new issue