Skip to content

Commit 473413f

Browse files
committed
XXX debug
1 parent 5ab3053 commit 473413f

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,14 +1475,31 @@ impl<'db> Type<'db> {
14751475
})
14761476
}
14771477
Some(TypeVarBoundOrConstraints::Constraints(constraints)) => {
1478-
constraints.elements(db).iter().when_all(db, |constraint| {
1478+
let x = constraints.elements(db).iter().when_all(db, |constraint| {
14791479
// Note that constrained typevars must specialize to _exactly_ one of the
14801480
// constraints, not to a _subtype_ of one.
1481-
C::constrain_typevar(db, bound_typevar, *constraint, *constraint)
1482-
.implies(db, || {
1483-
constraint.has_relation_to_impl(db, target, relation, visitor)
1484-
})
1485-
})
1481+
let x =
1482+
C::constrain_typevar(db, bound_typevar, *constraint, *constraint)
1483+
.implies(db, || {
1484+
constraint
1485+
.has_relation_to_impl(db, target, relation, visitor)
1486+
});
1487+
eprintln!(
1488+
"==> constraint {}[{}] {} => {}",
1489+
self.display(db),
1490+
constraint.display(db),
1491+
target.display(db),
1492+
x.display(db)
1493+
);
1494+
x
1495+
});
1496+
eprintln!(
1497+
"==> constraint {}[OVERALL] {} => {}",
1498+
self.display(db),
1499+
target.display(db),
1500+
x.display(db),
1501+
);
1502+
x
14861503
}
14871504
}
14881505
}
@@ -1495,12 +1512,33 @@ impl<'db> Type<'db> {
14951512
.typevar(db)
14961513
.constraints(db)
14971514
.when_some_and(db, |constraints| {
1498-
constraints.iter().when_all(db, |constraint| {
1499-
C::constrain_typevar(db, bound_typevar, *constraint, *constraint)
1500-
.implies(db, || {
1501-
self.has_relation_to_impl(db, *constraint, relation, visitor)
1502-
})
1503-
})
1515+
let x = constraints.iter().when_all(db, |constraint| {
1516+
let x =
1517+
C::constrain_typevar(db, bound_typevar, *constraint, *constraint)
1518+
.implies(db, || {
1519+
self.has_relation_to_impl(
1520+
db,
1521+
*constraint,
1522+
relation,
1523+
visitor,
1524+
)
1525+
});
1526+
eprintln!(
1527+
"==> constraint {} {}[{}] => {}",
1528+
self.display(db),
1529+
target.display(db),
1530+
constraint.display(db),
1531+
x.display(db)
1532+
);
1533+
x
1534+
});
1535+
eprintln!(
1536+
"==> constraint {} {}[OVERALL] => {}",
1537+
self.display(db),
1538+
target.display(db),
1539+
x.display(db)
1540+
);
1541+
x
15041542
})
15051543
.is_never_satisfied(db) =>
15061544
{

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ impl<'db> Bindings<'db> {
589589

590590
Some(KnownFunction::IsSubtypeOf) => {
591591
if let [Some(ty_a), Some(ty_b)] = overload.parameter_types() {
592+
let x = ty_a.when_subtype_of::<ConstraintSet>(db, *ty_b);
593+
eprintln!("==> {}", x.display(db));
592594
overload.set_return_type(Type::BooleanLiteral(
593595
ty_a.is_subtype_of(db, *ty_b),
594596
));

crates/ty_python_semantic/src/types/constraints.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ impl<'db> Constraints<'db> for ConstraintSet<'db> {
366366
result
367367
}
368368

369+
// XXX
370+
fn implies(self, db: &'db dyn Db, other: impl FnOnce() -> Self) -> Self {
371+
let p = self.clone();
372+
let q = other();
373+
let result = self
374+
.clone()
375+
.negate(db)
376+
.or(db, || self.and(db, || q.clone()));
377+
eprintln!(
378+
"==> {} → {} = {}",
379+
p.display(db),
380+
q.display(db),
381+
result.display(db)
382+
);
383+
result
384+
}
385+
369386
fn display(&self, db: &'db dyn Db) -> impl Display {
370387
self.display(db)
371388
}
@@ -491,6 +508,13 @@ impl<'db> ConstraintClause<'db> {
491508

492509
/// Returns the union of this clause and another.
493510
fn union_clause(self, db: &'db dyn Db, other: Self) -> Simplified<Self> {
511+
if false {
512+
eprintln!(
513+
"==> union_clause {} {}",
514+
self.display(db),
515+
other.display(db)
516+
);
517+
}
494518
if self.is_always() || other.is_always() {
495519
return Simplified::One(Self::always());
496520
}
@@ -501,6 +525,9 @@ impl<'db> ConstraintClause<'db> {
501525
return Simplified::One(self);
502526
}
503527
if let Some(simplified) = self.simplifies_via_union(db, &other) {
528+
if false {
529+
eprintln!(" -> simplified {}", simplified.display(db));
530+
}
504531
if simplified.is_always() {
505532
return Simplified::Always;
506533
}

0 commit comments

Comments
 (0)