aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-09 10:13:36 +0000
committerAleksey Kladov <[email protected]>2018-12-09 10:13:36 +0000
commit13100da7a2aa97cdbda9ed4bd99896e2ff6d5cf6 (patch)
treef633d0ff9cef84fb5b94d68a2ef96707e28f05dc
parent904438e993b4cc3c1d9269a44436c1b112de16c0 (diff)
switch threadpool back from rayon to threadpool
rayon does not replenish the pool when the thread panics, but we must be reselient to bugs.
-rw-r--r--Cargo.lock10
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs15
3 files changed, 17 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4f46e26fb..1f69a91b2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -697,6 +697,7 @@ dependencies = [
697 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 697 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
698 "test_utils 0.1.0", 698 "test_utils 0.1.0",
699 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 699 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
700 "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
700 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 701 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
701 "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 702 "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
702] 703]
@@ -1104,6 +1105,14 @@ dependencies = [
1104] 1105]
1105 1106
1106[[package]] 1107[[package]]
1108name = "threadpool"
1109version = "1.7.1"
1110source = "registry+https://github.com/rust-lang/crates.io-index"
1111dependencies = [
1112 "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
1113]
1114
1115[[package]]
1107name = "time" 1116name = "time"
1108version = "0.1.40" 1117version = "0.1.40"
1109source = "registry+https://github.com/rust-lang/crates.io-index" 1118source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1414,6 +1423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1414"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f" 1423"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f"
1415"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" 1424"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
1416"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 1425"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
1426"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
1417"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" 1427"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
1418"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" 1428"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
1419"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77" 1429"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77"
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 79d86f9b2..5ee218b6b 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8rayon = "1.0.2" 8rayon = "1.0.2"
9threadpool = "1.7.1"
9relative-path = "0.4.0" 10relative-path = "0.4.0"
10failure = "0.1.2" 11failure = "0.1.2"
11failure_derive = "0.1.2" 12failure_derive = "0.1.2"
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 0e1878906..a01eeff88 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -9,7 +9,8 @@ use gen_lsp_server::{
9}; 9};
10use languageserver_types::NumberOrString; 10use languageserver_types::NumberOrString;
11use ra_analysis::{Canceled, FileId, LibraryData}; 11use ra_analysis::{Canceled, FileId, LibraryData};
12use rayon::{self, ThreadPool}; 12use rayon;
13use threadpool::ThreadPool;
13use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
14use serde::{de::DeserializeOwned, Serialize}; 15use serde::{de::DeserializeOwned, Serialize};
15use failure::{format_err, bail}; 16use failure::{format_err, bail};
@@ -54,11 +55,7 @@ pub fn main_loop(
54 msg_receiver: &Receiver<RawMessage>, 55 msg_receiver: &Receiver<RawMessage>,
55 msg_sender: &Sender<RawMessage>, 56 msg_sender: &Sender<RawMessage>,
56) -> Result<()> { 57) -> Result<()> {
57 let pool = rayon::ThreadPoolBuilder::new() 58 let pool = ThreadPool::new(8);
58 .num_threads(4)
59 .panic_handler(|_| log::error!("thread panicked :("))
60 .build()
61 .unwrap();
62 let (task_sender, task_receiver) = unbounded::<Task>(); 59 let (task_sender, task_receiver) = unbounded::<Task>();
63 let (fs_worker, fs_watcher) = vfs::roots_loader(); 60 let (fs_worker, fs_watcher) = vfs::roots_loader();
64 let (ws_worker, ws_watcher) = workspace_loader(); 61 let (ws_worker, ws_watcher) = workspace_loader();
@@ -155,7 +152,7 @@ fn main_loop_inner(
155 } else { 152 } else {
156 let (files, resolver) = state.events_to_files(events); 153 let (files, resolver) = state.events_to_files(events);
157 let sender = libdata_sender.clone(); 154 let sender = libdata_sender.clone();
158 pool.spawn(move || { 155 pool.execute(move || {
159 let start = ::std::time::Instant::now(); 156 let start = ::std::time::Instant::now();
160 log::info!("indexing {} ... ", root.display()); 157 log::info!("indexing {} ... ", root.display());
161 let data = LibraryData::prepare(files, resolver); 158 let data = LibraryData::prepare(files, resolver);
@@ -402,7 +399,7 @@ impl<'a> PoolDispatcher<'a> {
402 Ok((id, params)) => { 399 Ok((id, params)) => {
403 let world = self.world.snapshot(); 400 let world = self.world.snapshot();
404 let sender = self.sender.clone(); 401 let sender = self.sender.clone();
405 self.pool.spawn(move || { 402 self.pool.execute(move || {
406 let resp = match f(world, params) { 403 let resp = match f(world, params) {
407 Ok(resp) => RawResponse::ok::<R>(id, &resp), 404 Ok(resp) => RawResponse::ok::<R>(id, &resp),
408 Err(e) => match e.downcast::<LspError>() { 405 Err(e) => match e.downcast::<LspError>() {
@@ -452,7 +449,7 @@ fn update_file_notifications_on_threadpool(
452 sender: Sender<Task>, 449 sender: Sender<Task>,
453 subscriptions: Vec<FileId>, 450 subscriptions: Vec<FileId>,
454) { 451) {
455 pool.spawn(move || { 452 pool.execute(move || {
456 for file_id in subscriptions { 453 for file_id in subscriptions {
457 match handlers::publish_diagnostics(&world, file_id) { 454 match handlers::publish_diagnostics(&world, file_id) {
458 Err(e) => { 455 Err(e) => {