From e60677178ed27254211958b1f54ff73b4588ab5b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 28 Sep 2019 18:49:00 +0300 Subject: correctly reset chalk state after a panic --- crates/ra_hir/src/ty/traits.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 90a11ac7d..b0f67ae50 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs @@ -1,9 +1,8 @@ //! Trait solving using Chalk. -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use chalk_ir::cast::Cast; use log::debug; -use parking_lot::Mutex; use ra_db::salsa; use ra_prof::profile; use rustc_hash::FxHashSet; @@ -30,9 +29,6 @@ impl PartialEq for TraitSolver { impl Eq for TraitSolver {} -// FIXME: this impl is WRONG, chalk is not RefUnwindSafe, and this causes #1927 -impl std::panic::RefUnwindSafe for TraitSolver {} - impl TraitSolver { fn solve( &self, @@ -41,7 +37,14 @@ impl TraitSolver { ) -> Option { let context = ChalkContext { db, krate: self.krate }; debug!("solve goal: {:?}", goal); - let solution = self.inner.lock().solve(&context, goal); + let mut solver = match self.inner.lock() { + Ok(it) => it, + // Our cancellation works via unwinding, but, as chalk is not + // panic-safe, we need to make sure to propagate the cancellation. + // Ideally, we should also make chalk panic-safe. + Err(_) => ra_db::Canceled::throw(), + }; + let solution = solver.solve(&context, goal); debug!("solve({:?}) => {:?}", goal, solution); solution } -- cgit v1.2.3