diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-12 11:36:47 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-12 11:36:47 +0100 |
commit | 03645c55761f8c9345ee3837a6010e65e7a80179 (patch) | |
tree | 9c24cb112429b0334762063e71a65a1907386e59 | |
parent | 6296f51678843c96a4ab1f1e6784b6d69222e072 (diff) | |
parent | fed52706def9a9f5d33edc7dd9848a02ae475ba5 (diff) |
Merge #1382
1382: use salsa's LRU for syntax trees r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/init.rs | 14 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 8 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 4 | ||||
-rw-r--r-- | editors/code/src/server.ts | 3 |
13 files changed, 63 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock index 579daecf1..2c1c7099e 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1058,7 +1058,7 @@ dependencies = [ | |||
1058 | "ra_syntax 0.1.0", | 1058 | "ra_syntax 0.1.0", |
1059 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1059 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1060 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1060 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1061 | "salsa 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1061 | "salsa 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", |
1062 | "test_utils 0.1.0", | 1062 | "test_utils 0.1.0", |
1063 | ] | 1063 | ] |
1064 | 1064 | ||
@@ -1478,11 +1478,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1478 | 1478 | ||
1479 | [[package]] | 1479 | [[package]] |
1480 | name = "salsa" | 1480 | name = "salsa" |
1481 | version = "0.12.2" | 1481 | version = "0.12.3" |
1482 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1482 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1483 | dependencies = [ | 1483 | dependencies = [ |
1484 | "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1484 | "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1485 | "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1485 | "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1486 | "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1486 | "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1487 | "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1487 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1488 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1488 | "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1489 | "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -2125,7 +2126,7 @@ dependencies = [ | |||
2125 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 2126 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" |
2126 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" | 2127 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" |
2127 | "checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" | 2128 | "checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" |
2128 | "checksum salsa 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2208fabe493ad352dc4f544c482b39e9b9a2c1719d9aa4a0f5e828a61210956" | 2129 | "checksum salsa 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2891cd628406e8a0ca714b827511de1bff76f796e3382cc72a3de732ccad5aea" |
2129 | "checksum salsa-macros 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7f1e25ca2b995bdf032946174929d62156ffd57abd7ff88dc6f9bdeb5ac0c59" | 2130 | "checksum salsa-macros 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7f1e25ca2b995bdf032946174929d62156ffd57abd7ff88dc6f9bdeb5ac0c59" |
2130 | "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" | 2131 | "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" |
2131 | "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" | 2132 | "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index a445dcb4d..c59821f44 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -7,7 +7,7 @@ use std::collections::HashSet; | |||
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | 8 | ||
9 | use ra_db::{ | 9 | use ra_db::{ |
10 | CrateGraph, FileId, SourceRoot, SourceRootId, SourceDatabase, salsa, | 10 | CrateGraph, FileId, SourceRoot, SourceRootId, SourceDatabase, salsa::{self, Database}, |
11 | }; | 11 | }; |
12 | use ra_hir::db; | 12 | use ra_hir::db; |
13 | use ra_project_model::ProjectWorkspace; | 13 | use ra_project_model::ProjectWorkspace; |
@@ -43,6 +43,12 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { | |||
43 | impl BatchDatabase { | 43 | impl BatchDatabase { |
44 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { | 44 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { |
45 | let mut db = BatchDatabase { runtime: salsa::Runtime::default() }; | 45 | let mut db = BatchDatabase { runtime: salsa::Runtime::default() }; |
46 | let lru_cap = std::env::var("RA_LRU_CAP") | ||
47 | .ok() | ||
48 | .and_then(|it| it.parse::<usize>().ok()) | ||
49 | .unwrap_or(ra_db::DEFAULT_LRU_CAP); | ||
50 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_cap); | ||
51 | db.query_mut(ra_hir::db::ParseMacroQuery).set_lru_capacity(lru_cap); | ||
46 | db.set_crate_graph(Arc::new(crate_graph)); | 52 | db.set_crate_graph(Arc::new(crate_graph)); |
47 | 53 | ||
48 | // wait until Vfs has loaded all roots | 54 | // wait until Vfs has loaded all roots |
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index 827855b2f..f73dd739a 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -5,7 +5,7 @@ version = "0.1.0" | |||
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | salsa = "0.12.1" | 8 | salsa = "0.12.3" |
9 | relative-path = "0.4.0" | 9 | relative-path = "0.4.0" |
10 | rustc-hash = "1.0" | 10 | rustc-hash = "1.0" |
11 | 11 | ||
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 7c49c585b..f08616100 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -65,6 +65,8 @@ pub struct FileRange { | |||
65 | pub range: TextRange, | 65 | pub range: TextRange, |
66 | } | 66 | } |
67 | 67 | ||
68 | pub const DEFAULT_LRU_CAP: usize = 128; | ||
69 | |||
68 | /// Database which stores all significant input facts: source code and project | 70 | /// Database which stores all significant input facts: source code and project |
69 | /// model. Everything else in rust-analyzer is derived from these queries. | 71 | /// model. Everything else in rust-analyzer is derived from these queries. |
70 | #[salsa::query_group(SourceDatabaseStorage)] | 72 | #[salsa::query_group(SourceDatabaseStorage)] |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 247dc0fee..ce03a0f95 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -225,7 +225,6 @@ impl RootDatabase { | |||
225 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); | 225 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); |
226 | 226 | ||
227 | self.query(ra_db::ParseQuery).sweep(sweep); | 227 | self.query(ra_db::ParseQuery).sweep(sweep); |
228 | |||
229 | self.query(hir::db::ParseMacroQuery).sweep(sweep); | 228 | self.query(hir::db::ParseMacroQuery).sweep(sweep); |
230 | self.query(hir::db::MacroDefQuery).sweep(sweep); | 229 | self.query(hir::db::MacroDefQuery).sweep(sweep); |
231 | self.query(hir::db::MacroArgQuery).sweep(sweep); | 230 | self.query(hir::db::MacroArgQuery).sweep(sweep); |
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index d1a452ecb..b3f395502 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | 5 | ||
6 | use ra_db::{ | 6 | use ra_db::{ |
7 | CheckCanceled, FileId, Canceled, SourceDatabase, | 7 | CheckCanceled, FileId, Canceled, SourceDatabase, |
8 | salsa, | 8 | salsa::{self, Database}, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; | 11 | use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; |
@@ -41,6 +41,12 @@ impl salsa::Database for RootDatabase { | |||
41 | 41 | ||
42 | impl Default for RootDatabase { | 42 | impl Default for RootDatabase { |
43 | fn default() -> RootDatabase { | 43 | fn default() -> RootDatabase { |
44 | RootDatabase::new(None) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl RootDatabase { | ||
49 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { | ||
44 | let mut db = RootDatabase { | 50 | let mut db = RootDatabase { |
45 | runtime: salsa::Runtime::default(), | 51 | runtime: salsa::Runtime::default(), |
46 | last_gc: time::Instant::now(), | 52 | last_gc: time::Instant::now(), |
@@ -49,6 +55,9 @@ impl Default for RootDatabase { | |||
49 | db.set_crate_graph(Default::default()); | 55 | db.set_crate_graph(Default::default()); |
50 | db.set_local_roots(Default::default()); | 56 | db.set_local_roots(Default::default()); |
51 | db.set_library_roots(Default::default()); | 57 | db.set_library_roots(Default::default()); |
58 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | ||
59 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | ||
60 | db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | ||
52 | db | 61 | db |
53 | } | 62 | } |
54 | } | 63 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index dbebf50a6..8741e736f 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -242,12 +242,21 @@ pub struct CallInfo { | |||
242 | } | 242 | } |
243 | 243 | ||
244 | /// `AnalysisHost` stores the current state of the world. | 244 | /// `AnalysisHost` stores the current state of the world. |
245 | #[derive(Debug, Default)] | 245 | #[derive(Debug)] |
246 | pub struct AnalysisHost { | 246 | pub struct AnalysisHost { |
247 | db: db::RootDatabase, | 247 | db: db::RootDatabase, |
248 | } | 248 | } |
249 | 249 | ||
250 | impl Default for AnalysisHost { | ||
251 | fn default() -> AnalysisHost { | ||
252 | AnalysisHost::new(None) | ||
253 | } | ||
254 | } | ||
255 | |||
250 | impl AnalysisHost { | 256 | impl AnalysisHost { |
257 | pub fn new(lru_capcity: Option<usize>) -> AnalysisHost { | ||
258 | AnalysisHost { db: db::RootDatabase::new(lru_capcity) } | ||
259 | } | ||
251 | /// Returns a snapshot of the current state, which you can query for | 260 | /// Returns a snapshot of the current state, which you can query for |
252 | /// semantic information. | 261 | /// semantic information. |
253 | pub fn analysis(&self) -> Analysis { | 262 | pub fn analysis(&self) -> Analysis { |
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs index 1b77e0312..b894b449d 100644 --- a/crates/ra_lsp_server/src/init.rs +++ b/crates/ra_lsp_server/src/init.rs | |||
@@ -17,11 +17,17 @@ pub struct InitializationOptions { | |||
17 | /// Defaults to `true` | 17 | /// Defaults to `true` |
18 | #[serde(deserialize_with = "nullable_bool_true")] | 18 | #[serde(deserialize_with = "nullable_bool_true")] |
19 | pub show_workspace_loaded: bool, | 19 | pub show_workspace_loaded: bool, |
20 | |||
21 | pub lru_capacity: Option<usize>, | ||
20 | } | 22 | } |
21 | 23 | ||
22 | impl Default for InitializationOptions { | 24 | impl Default for InitializationOptions { |
23 | fn default() -> InitializationOptions { | 25 | fn default() -> InitializationOptions { |
24 | InitializationOptions { publish_decorations: false, show_workspace_loaded: true } | 26 | InitializationOptions { |
27 | publish_decorations: false, | ||
28 | show_workspace_loaded: true, | ||
29 | lru_capacity: None, | ||
30 | } | ||
25 | } | 31 | } |
26 | } | 32 | } |
27 | 33 | ||
@@ -54,8 +60,10 @@ mod test { | |||
54 | assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); | 60 | assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); |
55 | assert_eq!( | 61 | assert_eq!( |
56 | default, | 62 | default, |
57 | serde_json::from_str(r#"{"publishDecorations":null, "showWorkspaceLoaded":null}"#) | 63 | serde_json::from_str( |
58 | .unwrap() | 64 | r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"# |
65 | ) | ||
66 | .unwrap() | ||
59 | ); | 67 | ); |
60 | } | 68 | } |
61 | } | 69 | } |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 090fb9b1b..0790ea472 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -73,7 +73,7 @@ pub fn main_loop( | |||
73 | loaded_workspaces | 73 | loaded_workspaces |
74 | }; | 74 | }; |
75 | 75 | ||
76 | let mut state = WorldState::new(ws_roots, workspaces); | 76 | let mut state = WorldState::new(ws_roots, workspaces, options.lru_capacity); |
77 | 77 | ||
78 | let pool = ThreadPool::new(THREADPOOL_SIZE); | 78 | let pool = ThreadPool::new(THREADPOOL_SIZE); |
79 | let (task_sender, task_receiver) = unbounded::<Task>(); | 79 | let (task_sender, task_receiver) = unbounded::<Task>(); |
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index cd8df4fdb..f9ce570ca 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -46,7 +46,11 @@ pub struct WorldSnapshot { | |||
46 | } | 46 | } |
47 | 47 | ||
48 | impl WorldState { | 48 | impl WorldState { |
49 | pub fn new(folder_roots: Vec<PathBuf>, workspaces: Vec<ProjectWorkspace>) -> WorldState { | 49 | pub fn new( |
50 | folder_roots: Vec<PathBuf>, | ||
51 | workspaces: Vec<ProjectWorkspace>, | ||
52 | lru_capacity: Option<usize>, | ||
53 | ) -> WorldState { | ||
50 | let mut change = AnalysisChange::new(); | 54 | let mut change = AnalysisChange::new(); |
51 | 55 | ||
52 | let mut roots = Vec::new(); | 56 | let mut roots = Vec::new(); |
@@ -74,7 +78,7 @@ impl WorldState { | |||
74 | } | 78 | } |
75 | change.set_crate_graph(crate_graph); | 79 | change.set_crate_graph(crate_graph); |
76 | 80 | ||
77 | let mut analysis_host = AnalysisHost::default(); | 81 | let mut analysis_host = AnalysisHost::new(lru_capacity); |
78 | analysis_host.apply_change(change); | 82 | analysis_host.apply_change(change); |
79 | WorldState { | 83 | WorldState { |
80 | roots_to_scan, | 84 | roots_to_scan, |
diff --git a/editors/code/package.json b/editors/code/package.json index 05c808394..c2ed8d126 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -232,6 +232,11 @@ | |||
232 | ], | 232 | ], |
233 | "default": "off", | 233 | "default": "off", |
234 | "description": "Trace output of cargo-watch" | 234 | "description": "Trace output of cargo-watch" |
235 | }, | ||
236 | "rust-analyzer.lruCapacity": { | ||
237 | "type": "number", | ||
238 | "default": null, | ||
239 | "description": "Number of syntax trees rust-analyzer keeps in memory" | ||
235 | } | 240 | } |
236 | } | 241 | } |
237 | }, | 242 | }, |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 8d73a6b34..3024546d2 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -19,6 +19,7 @@ export class Config { | |||
19 | public enableEnhancedTyping = true; | 19 | public enableEnhancedTyping = true; |
20 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | 20 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; |
21 | public showWorkspaceLoadedNotification = true; | 21 | public showWorkspaceLoadedNotification = true; |
22 | public lruCapacity: null | number = null; | ||
22 | public cargoWatchOptions: CargoWatchOptions = { | 23 | public cargoWatchOptions: CargoWatchOptions = { |
23 | enableOnStartup: 'ask', | 24 | enableOnStartup: 'ask', |
24 | trace: 'off', | 25 | trace: 'off', |
@@ -109,5 +110,8 @@ export class Config { | |||
109 | '' | 110 | '' |
110 | ); | 111 | ); |
111 | } | 112 | } |
113 | if (config.has('lruCapacity')) { | ||
114 | this.lruCapacity = config.get('lruCapacity') as number; | ||
115 | } | ||
112 | } | 116 | } |
113 | } | 117 | } |
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 81c2b3fff..7029142fd 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts | |||
@@ -35,7 +35,8 @@ export class Server { | |||
35 | initializationOptions: { | 35 | initializationOptions: { |
36 | publishDecorations: true, | 36 | publishDecorations: true, |
37 | showWorkspaceLoaded: | 37 | showWorkspaceLoaded: |
38 | Server.config.showWorkspaceLoadedNotification | 38 | Server.config.showWorkspaceLoadedNotification, |
39 | lruCapacity: Server.config.lruCapacity | ||
39 | }, | 40 | }, |
40 | traceOutputChannel | 41 | traceOutputChannel |
41 | }; | 42 | }; |