From 343b0ccfb9e7dd341c1badbb9fb4583ceba85fd4 Mon Sep 17 00:00:00 2001 From: Jake Heinz Date: Fri, 14 Jan 2022 09:21:25 +0000 Subject: [PATCH] simplify --- crates/ide/src/prime_caches.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs index b873329e861..6464d599f08 100644 --- a/crates/ide/src/prime_caches.rs +++ b/crates/ide/src/prime_caches.rs @@ -79,7 +79,7 @@ pub(crate) fn parallel_prime_caches(db: &RootDatabase, num_worker_threads: u8 enum ParallelPrimeCacheWorkerProgress { BeginCrate { crate_id: CrateId, crate_name: String }, - EndCrate { crate_id: CrateId, cancelled: bool }, + EndCrate { crate_id: CrateId }, } let prime_caches_worker = move |db: Snapshot| { @@ -87,18 +87,10 @@ enum ParallelPrimeCacheWorkerProgress { progress_sender .send(ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name })?; - let cancelled = Cancelled::catch(|| { - // This also computes the DefMap - db.import_map(crate_id); - }) - .is_err(); + // This also computes the DefMap + db.import_map(crate_id); - progress_sender - .send(ParallelPrimeCacheWorkerProgress::EndCrate { crate_id, cancelled })?; - - if cancelled { - break; - } + progress_sender.send(ParallelPrimeCacheWorkerProgress::EndCrate { crate_id })?; } Ok::<_, crossbeam_channel::SendError<_>>(()) @@ -113,11 +105,12 @@ enum ParallelPrimeCacheWorkerProgress { let crates_total = crates_to_prime.len(); let mut crates_done = 0; - let mut is_cancelled = false; let mut crates_currently_indexing = FxHashMap::with_capacity_and_hasher(num_worker_threads as _, Default::default()); - while !crates_to_prime.is_empty() && !is_cancelled { + while !crates_to_prime.is_empty() { + db.unwind_if_cancelled(); + for crate_id in &mut crates_to_prime { work_sender .send(( @@ -129,17 +122,20 @@ enum ParallelPrimeCacheWorkerProgress { let worker_progress = match progress_receiver.recv() { Ok(p) => p, - Err(_) => break, + Err(_) => { + // our workers may have died from a cancelled task, so we'll check and re-raise here. + db.unwind_if_cancelled(); + break; + } }; match worker_progress { ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name } => { crates_currently_indexing.insert(crate_id, crate_name); } - ParallelPrimeCacheWorkerProgress::EndCrate { crate_id, cancelled } => { + ParallelPrimeCacheWorkerProgress::EndCrate { crate_id } => { crates_currently_indexing.remove(&crate_id); crates_to_prime.mark_done(crate_id); crates_done += 1; - is_cancelled = cancelled; } }; @@ -150,7 +146,6 @@ enum ParallelPrimeCacheWorkerProgress { }; cb(progress); - db.unwind_if_cancelled(); } }) .unwrap();