From 1f888e277b6fdb2e755828d7ea3167a0f1bf26bd Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 18 Nov 2024 13:38:40 +0100 Subject: [PATCH] Try to fix perf regression --- crates/red_knot_python_semantic/src/types/narrow.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/narrow.rs b/crates/red_knot_python_semantic/src/types/narrow.rs index e62f566d260acd..fb56a9e2c0b55e 100644 --- a/crates/red_knot_python_semantic/src/types/narrow.rs +++ b/crates/red_knot_python_semantic/src/types/narrow.rs @@ -278,8 +278,6 @@ impl<'db> NarrowingConstraintsBuilder<'db> { .tuple_windows::<(&ruff_python_ast::Expr, &ruff_python_ast::Expr)>(); let mut constraints = NarrowingConstraints::default(); for (op, (left, right)) in std::iter::zip(&**ops, comparator_tuples) { - let rhs_ty = inference.expression_ty(right.scoped_expression_id(self.db, scope)); - match left { ast::Expr::Name(ast::ExprName { range: _, @@ -288,6 +286,8 @@ impl<'db> NarrowingConstraintsBuilder<'db> { }) => { // SAFETY: we should always have a symbol for every Name node. let symbol = self.symbols().symbol_id_by_name(id).unwrap(); + let rhs_ty = + inference.expression_ty(right.scoped_expression_id(self.db, scope)); match if is_positive { *op } else { op.negate() } { ast::CmpOp::IsNot => { @@ -333,6 +333,8 @@ impl<'db> NarrowingConstraintsBuilder<'db> { if let Some(id) = arguments.args[0].as_name_expr().map(|name| &name.id) { let symbol = self.symbols().symbol_id_by_name(id).unwrap(); if ast::CmpOp::Is == if is_positive { *op } else { op.negate() } { + let rhs_ty = inference + .expression_ty(right.scoped_expression_id(self.db, scope)); if rhs_ty.is_class_literal() { constraints.insert(symbol, rhs_ty.to_instance(self.db)); }