Skip to content

Commit

Permalink
Try to fix perf regression
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Nov 18, 2024
1 parent 1143efd commit 1f888e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/red_knot_python_semantic/src/types/narrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: _,
Expand All @@ -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 => {
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 1f888e2

Please sign in to comment.