mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Auto merge of #14967 - rust-lang:revert-14965-panic-ctx, r=Veykril
Revert "Add mandatory panic contexts to all threadpool tasks" Reverts rust-lang/rust-analyzer#14965 This won't quite work actually given the use of `catch_unwind` in some of these
This commit is contained in:
commit
48f8799bf1
5 changed files with 138 additions and 174 deletions
|
@ -104,10 +104,13 @@ impl<'a> RequestDispatcher<'a> {
|
||||||
None => return self,
|
None => return self,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.global_state.task_pool.handle.spawn(ThreadIntent::Worker, panic_context, {
|
self.global_state.task_pool.handle.spawn(ThreadIntent::Worker, {
|
||||||
let world = self.global_state.snapshot();
|
let world = self.global_state.snapshot();
|
||||||
move || {
|
move || {
|
||||||
let result = panic::catch_unwind(move || f(world, params));
|
let result = panic::catch_unwind(move || {
|
||||||
|
let _pctx = stdx::panic_context::enter(panic_context);
|
||||||
|
f(world, params)
|
||||||
|
});
|
||||||
match thread_result_to_response::<R>(req.id.clone(), result) {
|
match thread_result_to_response::<R>(req.id.clone(), result) {
|
||||||
Ok(response) => Task::Response(response),
|
Ok(response) => Task::Response(response),
|
||||||
Err(_) => Task::Response(lsp_server::Response::new_err(
|
Err(_) => Task::Response(lsp_server::Response::new_err(
|
||||||
|
@ -175,10 +178,13 @@ impl<'a> RequestDispatcher<'a> {
|
||||||
None => return self,
|
None => return self,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.global_state.task_pool.handle.spawn(intent, panic_context, {
|
self.global_state.task_pool.handle.spawn(intent, {
|
||||||
let world = self.global_state.snapshot();
|
let world = self.global_state.snapshot();
|
||||||
move || {
|
move || {
|
||||||
let result = panic::catch_unwind(move || f(world, params));
|
let result = panic::catch_unwind(move || {
|
||||||
|
let _pctx = stdx::panic_context::enter(panic_context);
|
||||||
|
f(world, params)
|
||||||
|
});
|
||||||
match thread_result_to_response::<R>(req.id.clone(), result) {
|
match thread_result_to_response::<R>(req.id.clone(), result) {
|
||||||
Ok(response) => Task::Response(response),
|
Ok(response) => Task::Response(response),
|
||||||
Err(_) => Task::Retry(req),
|
Err(_) => Task::Retry(req),
|
||||||
|
|
|
@ -291,15 +291,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
state.task_pool.handle.spawn_with_sender(
|
state.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, move |_| {
|
||||||
stdx::thread::ThreadIntent::Worker,
|
|
||||||
"flycheck",
|
|
||||||
move |_| {
|
|
||||||
if let Err(e) = std::panic::catch_unwind(task) {
|
if let Err(e) = std::panic::catch_unwind(task) {
|
||||||
tracing::error!("flycheck task panicked: {e:?}")
|
tracing::error!("flycheck task panicked: {e:?}")
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -397,10 +397,7 @@ impl GlobalState {
|
||||||
tracing::debug!(%cause, "will prime caches");
|
tracing::debug!(%cause, "will prime caches");
|
||||||
let num_worker_threads = self.config.prime_caches_num_threads();
|
let num_worker_threads = self.config.prime_caches_num_threads();
|
||||||
|
|
||||||
self.task_pool.handle.spawn_with_sender(
|
self.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, {
|
||||||
stdx::thread::ThreadIntent::Worker,
|
|
||||||
"prime_caches",
|
|
||||||
{
|
|
||||||
let analysis = self.snapshot().analysis;
|
let analysis = self.snapshot().analysis;
|
||||||
move |sender| {
|
move |sender| {
|
||||||
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
|
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
|
||||||
|
@ -409,13 +406,10 @@ impl GlobalState {
|
||||||
sender.send(Task::PrimeCaches(report)).unwrap();
|
sender.send(Task::PrimeCaches(report)).unwrap();
|
||||||
});
|
});
|
||||||
sender
|
sender
|
||||||
.send(Task::PrimeCaches(PrimeCachesProgress::End {
|
.send(Task::PrimeCaches(PrimeCachesProgress::End { cancelled: res.is_err() }))
|
||||||
cancelled: res.is_err(),
|
|
||||||
}))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_status_or_notify(&mut self) {
|
fn update_status_or_notify(&mut self) {
|
||||||
|
@ -802,10 +796,7 @@ impl GlobalState {
|
||||||
|
|
||||||
// Diagnostics are triggered by the user typing
|
// Diagnostics are triggered by the user typing
|
||||||
// so we run them on a latency sensitive thread.
|
// so we run them on a latency sensitive thread.
|
||||||
self.task_pool.handle.spawn(
|
self.task_pool.handle.spawn(stdx::thread::ThreadIntent::LatencySensitive, move || {
|
||||||
stdx::thread::ThreadIntent::LatencySensitive,
|
|
||||||
"publish_diagnostics",
|
|
||||||
move || {
|
|
||||||
let _p = profile::span("publish_diagnostics");
|
let _p = profile::span("publish_diagnostics");
|
||||||
let diagnostics = subscriptions
|
let diagnostics = subscriptions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -830,9 +821,7 @@ impl GlobalState {
|
||||||
it.into_iter()
|
it.into_iter()
|
||||||
.map(move |d| lsp_types::Diagnostic {
|
.map(move |d| lsp_types::Diagnostic {
|
||||||
range: crate::to_proto::range(&line_index, d.range),
|
range: crate::to_proto::range(&line_index, d.range),
|
||||||
severity: Some(crate::to_proto::diagnostic_severity(
|
severity: Some(crate::to_proto::diagnostic_severity(d.severity)),
|
||||||
d.severity,
|
|
||||||
)),
|
|
||||||
code: Some(lsp_types::NumberOrString::String(
|
code: Some(lsp_types::NumberOrString::String(
|
||||||
d.code.as_str().to_string(),
|
d.code.as_str().to_string(),
|
||||||
)),
|
)),
|
||||||
|
@ -857,7 +846,6 @@ impl GlobalState {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
Task::Diagnostics(diagnostics.collect())
|
Task::Diagnostics(diagnostics.collect())
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ impl GlobalState {
|
||||||
pub(crate) fn fetch_workspaces(&mut self, cause: Cause) {
|
pub(crate) fn fetch_workspaces(&mut self, cause: Cause) {
|
||||||
tracing::info!(%cause, "will fetch workspaces");
|
tracing::info!(%cause, "will fetch workspaces");
|
||||||
|
|
||||||
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, "fetch_workspaces", {
|
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, {
|
||||||
let linked_projects = self.config.linked_projects();
|
let linked_projects = self.config.linked_projects();
|
||||||
let detached_files = self.config.detached_files().to_vec();
|
let detached_files = self.config.detached_files().to_vec();
|
||||||
let cargo_config = self.config.cargo();
|
let cargo_config = self.config.cargo();
|
||||||
|
@ -260,10 +260,7 @@ impl GlobalState {
|
||||||
tracing::info!(%cause, "will fetch build data");
|
tracing::info!(%cause, "will fetch build data");
|
||||||
let workspaces = Arc::clone(&self.workspaces);
|
let workspaces = Arc::clone(&self.workspaces);
|
||||||
let config = self.config.cargo();
|
let config = self.config.cargo();
|
||||||
self.task_pool.handle.spawn_with_sender(
|
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, move |sender| {
|
||||||
ThreadIntent::Worker,
|
|
||||||
"fetch_build_data",
|
|
||||||
move |sender| {
|
|
||||||
sender.send(Task::FetchBuildData(BuildDataProgress::Begin)).unwrap();
|
sender.send(Task::FetchBuildData(BuildDataProgress::Begin)).unwrap();
|
||||||
|
|
||||||
let progress = {
|
let progress = {
|
||||||
|
@ -274,11 +271,8 @@ impl GlobalState {
|
||||||
};
|
};
|
||||||
let res = ProjectWorkspace::run_all_build_scripts(&workspaces, &config, &progress);
|
let res = ProjectWorkspace::run_all_build_scripts(&workspaces, &config, &progress);
|
||||||
|
|
||||||
sender
|
sender.send(Task::FetchBuildData(BuildDataProgress::End((workspaces, res)))).unwrap();
|
||||||
.send(Task::FetchBuildData(BuildDataProgress::End((workspaces, res))))
|
});
|
||||||
.unwrap();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fetch_proc_macros(&mut self, cause: Cause, paths: Vec<ProcMacroPaths>) {
|
pub(crate) fn fetch_proc_macros(&mut self, cause: Cause, paths: Vec<ProcMacroPaths>) {
|
||||||
|
@ -286,10 +280,7 @@ impl GlobalState {
|
||||||
let dummy_replacements = self.config.dummy_replacements().clone();
|
let dummy_replacements = self.config.dummy_replacements().clone();
|
||||||
let proc_macro_clients = self.proc_macro_clients.clone();
|
let proc_macro_clients = self.proc_macro_clients.clone();
|
||||||
|
|
||||||
self.task_pool.handle.spawn_with_sender(
|
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, move |sender| {
|
||||||
ThreadIntent::Worker,
|
|
||||||
"fetch_proc_macros",
|
|
||||||
move |sender| {
|
|
||||||
sender.send(Task::LoadProcMacros(ProcMacroProgress::Begin)).unwrap();
|
sender.send(Task::LoadProcMacros(ProcMacroProgress::Begin)).unwrap();
|
||||||
|
|
||||||
let dummy_replacements = &dummy_replacements;
|
let dummy_replacements = &dummy_replacements;
|
||||||
|
@ -332,8 +323,7 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.send(Task::LoadProcMacros(ProcMacroProgress::End(res))).unwrap();
|
sender.send(Task::LoadProcMacros(ProcMacroProgress::End(res))).unwrap();
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_proc_macros(&mut self, proc_macros: ProcMacros) {
|
pub(crate) fn set_proc_macros(&mut self, proc_macros: ProcMacros) {
|
||||||
|
|
|
@ -14,41 +14,25 @@ impl<T> TaskPool<T> {
|
||||||
TaskPool { sender, pool: Pool::new(threads) }
|
TaskPool { sender, pool: Pool::new(threads) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn spawn<F>(
|
pub(crate) fn spawn<F>(&mut self, intent: ThreadIntent, task: F)
|
||||||
&mut self,
|
where
|
||||||
intent: ThreadIntent,
|
|
||||||
panic_context: impl Into<String>,
|
|
||||||
task: F,
|
|
||||||
) where
|
|
||||||
F: FnOnce() -> T + Send + 'static,
|
F: FnOnce() -> T + Send + 'static,
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
{
|
{
|
||||||
let panic_context = panic_context.into();
|
|
||||||
self.pool.spawn(intent, {
|
self.pool.spawn(intent, {
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
move || {
|
move || sender.send(task()).unwrap()
|
||||||
let _pctx = stdx::panic_context::enter(panic_context);
|
|
||||||
sender.send(task()).unwrap()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn spawn_with_sender<F>(
|
pub(crate) fn spawn_with_sender<F>(&mut self, intent: ThreadIntent, task: F)
|
||||||
&mut self,
|
where
|
||||||
intent: ThreadIntent,
|
|
||||||
panic_context: impl Into<String>,
|
|
||||||
task: F,
|
|
||||||
) where
|
|
||||||
F: FnOnce(Sender<T>) + Send + 'static,
|
F: FnOnce(Sender<T>) + Send + 'static,
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
{
|
{
|
||||||
let panic_context = panic_context.into();
|
|
||||||
self.pool.spawn(intent, {
|
self.pool.spawn(intent, {
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
move || {
|
move || task(sender)
|
||||||
let _pctx = stdx::panic_context::enter(panic_context);
|
|
||||||
task(sender)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue