Skip to content

Commit c15f58c

Browse files
committed
debug
1 parent 8922174 commit c15f58c

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

crates/ty_python_semantic/src/types/constraints.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ impl<'db> ConstrainedTypeVar<'db> {
335335
) -> Node<'db> {
336336
debug_assert_eq!(lower, lower.bottom_materialization(db));
337337
debug_assert_eq!(upper, upper.top_materialization(db));
338+
eprintln!(
339+
"==> new constraint {} ≤ {} ≤ {}",
340+
lower.display(db),
341+
typevar.identity(db).display(db),
342+
upper.display(db),
343+
);
338344

339345
// If `lower ≰ upper`, then the constraint cannot be satisfied, since there is no type that
340346
// is both greater than `lower`, and less than `upper`.
@@ -350,6 +356,12 @@ impl<'db> ConstrainedTypeVar<'db> {
350356

351357
let lower = lower.normalized(db);
352358
let upper = upper.normalized(db);
359+
eprintln!(
360+
" -> normalized {} ≤ {} ≤ {}",
361+
lower.display(db),
362+
typevar.identity(db).display(db),
363+
upper.display(db),
364+
);
353365

354366
// We have an (arbitrary) ordering for typevars. If the upper and/or lower bounds are
355367
// typevars, we have to ensure that the bounds are "later" according to that order than the
@@ -360,6 +372,13 @@ impl<'db> ConstrainedTypeVar<'db> {
360372
match (lower, upper) {
361373
// L ≤ T ≤ L == (T ≤ [L] ≤ T)
362374
(Type::TypeVar(lower), Type::TypeVar(upper)) if lower == upper => {
375+
eprintln!(
376+
" -> new constraint {} {} {:?} NOT {:?}",
377+
lower.identity(db).display(db),
378+
typevar.identity(db).display(db),
379+
lower.identity(db).cmp(&typevar.identity(db)),
380+
lower.cmp(&typevar),
381+
);
363382
let (bound, typevar) = if lower.can_be_bound_for(db, typevar) {
364383
(lower, typevar)
365384
} else {
@@ -771,11 +790,30 @@ impl<'db> Node<'db> {
771790
Type::TypeVar(rhs) if bound_typevar.can_be_bound_for(db, rhs) => rhs,
772791
_ => bound_typevar,
773792
};
793+
eprintln!(
794+
"==> wstog {} {} {}",
795+
self.display(db),
796+
lhs.display(db),
797+
rhs.display(db)
798+
);
799+
eprintln!(
800+
" -> constrained {}",
801+
constrained_typevar.identity(db).display(db)
802+
);
774803
let projected = self
775804
.project_typevar(db, constrained_typevar.identity(db))
776805
.simplify(db, self);
777806
let constraint = ConstrainedTypeVar::new_node(db, bound_typevar, Type::Never, rhs);
778-
projected.and(db, constraint).iff(db, projected)
807+
let combined = projected.and(db, constraint);
808+
eprintln!(" -> self {}", self.display(db));
809+
eprintln!(" {}", self.display_graph(db, &" "));
810+
eprintln!(" -> projected {}", projected.display(db));
811+
eprintln!(" {}", projected.display_graph(db, &" "));
812+
eprintln!(" -> constraint {}", constraint.display(db));
813+
eprintln!(" {}", constraint.display_graph(db, &" "));
814+
eprintln!(" -> combined {}", combined.display(db));
815+
eprintln!(" {}", combined.display_graph(db, &" "));
816+
combined.iff(db, projected)
779817
}
780818

781819
(_, Type::TypeVar(bound_typevar)) => {
@@ -1222,11 +1260,23 @@ impl<'db> InteriorNode<'db> {
12221260
let self_constraint = self.constraint(db);
12231261
let if_true = self.if_true(db).project_typevar(db, typevar);
12241262
let if_false = self.if_false(db).project_typevar(db, typevar);
1225-
if self_constraint.typevar(db).identity(db) > typevar {
1263+
eprintln!(
1264+
"==> project {} {} {}",
1265+
Node::Interior(self).display(db),
1266+
self_constraint.typevar(db).identity(db).display(db),
1267+
typevar.display(db)
1268+
);
1269+
eprintln!(" -> true {}", if_true.display(db));
1270+
eprintln!(" -> false {}", if_false.display(db));
1271+
let result = if self_constraint.typevar(db).identity(db) > typevar {
1272+
eprintln!(" -> done");
12261273
if_true.or(db, if_false)
12271274
} else {
1275+
eprintln!(" -> replace");
12281276
Node::new(db, self_constraint, if_true, if_false)
1229-
}
1277+
};
1278+
eprintln!(" -> result {}", result.display(db));
1279+
result
12301280
}
12311281

12321282
#[salsa::tracked(heap_size=ruff_memory_usage::heap_size)]

0 commit comments

Comments
 (0)