From b35312d4af305e86e360235150cddc263d4adc4a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 29 Mar 2021 23:15:12 +0300 Subject: [PATCH] internal: ensure that runaway type-inference doesn't block the main loop We have a bug where type-checking `per_query_memory_usage` takes a couple of seconds. It also reveals another bug: our type inference is not cancellable. --- crates/hir_ty/src/infer/expr.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index e6ede05ca14..6279aa572c5 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -119,6 +119,8 @@ impl<'a> InferenceContext<'a> { } fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { + self.db.check_canceled(); + let body = Arc::clone(&self.body); // avoid borrow checker problem let ty = match &body[tgt_expr] { Expr::Missing => self.err_ty(),