Skip to content

Commit 83fe206

Browse files
committed
chore: use more AssertUnwindSafe (unwound accumulators can't hurt us)
1 parent 1ddbf1e commit 83fe206

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

crates/ide-db/src/prime_caches.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@ pub fn parallel_prime_caches(
7474
let (work_sender, progress_receiver) = {
7575
let (progress_sender, progress_receiver) = crossbeam_channel::unbounded();
7676
let (work_sender, work_receiver) = crossbeam_channel::unbounded();
77-
let graph = graph.clone();
78-
let local_roots = db.local_roots();
79-
let prime_caches_worker = move |db: Snapshot<RootDatabase>| {
80-
while let Ok((crate_id, crate_name)) = work_receiver.recv() {
81-
progress_sender.send(ParallelPrimeCacheWorkerProgress::BeginCrate {
82-
crate_id,
83-
crate_name,
84-
})?;
77+
let prime_caches_worker = move |db: RootDatabase| {
78+
while let Ok((crate_id, crate_name, kind)) = work_receiver.recv() {
79+
progress_sender
80+
.send(ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name })?;
8581

8682
match kind {
8783
PrimingPhase::DefMap => _ = db.crate_def_map(crate_id),
@@ -197,7 +193,7 @@ pub fn parallel_prime_caches(
197193
}
198194

199195
while crates_done < crates_total {
200-
db.unwind_if_cancelled();
196+
db.unwind_if_revision_cancelled();
201197

202198
// recv_timeout is somewhat a hack, we need a way to from this thread check to see if the current salsa revision
203199
// is cancelled on a regular basis. workers will only exit if they are processing a task that is cancelled, or
@@ -209,7 +205,7 @@ pub fn parallel_prime_caches(
209205
}
210206
Err(crossbeam_channel::RecvTimeoutError::Disconnected) => {
211207
// our workers may have died from a cancelled task, so we'll check and re-raise here.
212-
db.unwind_if_cancelled();
208+
db.unwind_if_revision_cancelled();
213209
break;
214210
}
215211
};

crates/rust-analyzer/src/cli/rustc_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ impl Tester {
160160
let analysis = self.host.analysis();
161161
let root_file = self.root_file;
162162
move || {
163-
let res = std::panic::catch_unwind(move || {
163+
let res = std::panic::catch_unwind(AssertUnwindSafe(move || {
164164
analysis.full_diagnostics(
165165
diagnostic_config,
166166
ide::AssistResolveStrategy::None,
167167
root_file,
168168
)
169-
});
169+
}));
170170
main.unpark();
171171
res
172172
}

crates/rust-analyzer/src/main_loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl GlobalState {
526526
let num_worker_threads = self.config.prime_caches_num_threads();
527527

528528
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, {
529-
let analysis = self.snapshot().analysis;
529+
let analysis = AssertUnwindSafe(self.snapshot().analysis);
530530
move |sender| {
531531
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
532532
let res = analysis.parallel_prime_caches(num_worker_threads, |progress| {
@@ -898,12 +898,12 @@ impl GlobalState {
898898
}
899899
QueuedTask::CheckProcMacroSources(modified_rust_files) => {
900900
let crate_graph = self.analysis_host.raw_database().crate_graph();
901-
let snap = self.snapshot();
901+
let analysis = AssertUnwindSafe(self.snapshot().analysis);
902902
self.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, {
903903
move |sender| {
904904
if modified_rust_files.into_iter().any(|file_id| {
905905
// FIXME: Check whether these files could be build script related
906-
match snap.analysis.crates_for(file_id) {
906+
match analysis.crates_for(file_id) {
907907
Ok(crates) => {
908908
crates.iter().any(|&krate| crate_graph[krate].is_proc_macro)
909909
}

0 commit comments

Comments
 (0)