From b8cae2cf8f7d2a0162d614e25ef95d7e4a5d3677 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Jun 2019 18:05:02 +0300 Subject: check for cancellation when executing queries Note that we can't just remove CheckCanceled trait altogether: sometimes it's useful to check for cancellation while the query is running! We do this, for example, in the name resolution fixed-point loop. --- crates/ra_hir/src/ids.rs | 1 - crates/ra_hir/src/nameres.rs | 1 - crates/ra_hir/src/ty/infer.rs | 1 - crates/ra_hir/src/ty/traits.rs | 1 - crates/ra_ide_api/src/db.rs | 8 ++++++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 352f9ffd9..033af1632 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -61,7 +61,6 @@ impl HirFileId { db: &impl AstDatabase, file_id: HirFileId, ) -> Option> { - db.check_canceled(); match file_id.0 { HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()), HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file), diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index d84134877..3532faf01 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -234,7 +234,6 @@ impl CrateDefMap { db: &(impl DefDatabase + AstDatabase), krate: Crate, ) -> Arc { - db.check_canceled(); let _p = profile("crate_def_map_query"); let def_map = { let edition = krate.edition(db); diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index fef0f1d24..e150d7fd8 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -54,7 +54,6 @@ mod unify; /// The entry point of type inference. pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc { let _p = profile("infer_query"); - db.check_canceled(); let body = def.body(db); let resolver = def.resolver(db); let mut ctx = InferenceContext::new(db, body, resolver); diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index db78f25ca..fda7f9c04 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs @@ -83,7 +83,6 @@ pub(crate) fn implements_query( krate: Crate, trait_ref: Canonical, ) -> Option { - db.check_canceled(); let _p = profile("implements_query"); let goal: chalk_ir::Goal = trait_ref.value.to_chalk(db).cast(); debug!("goal: {:?}", goal); diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index b3f395502..82b061419 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -33,8 +33,12 @@ impl salsa::Database for RootDatabase { Canceled::throw() } fn salsa_event(&self, event: impl Fn() -> salsa::Event) { - if let salsa::EventKind::DidValidateMemoizedValue { .. } = event().kind { - self.check_canceled(); + match event().kind { + salsa::EventKind::DidValidateMemoizedValue { .. } + | salsa::EventKind::WillExecute { .. } => { + self.check_canceled(); + } + _ => (), } } } -- cgit v1.2.3