Skip to content

Commit 474b036

Browse files
committed
XXX debug messages
1 parent 8b48ddd commit 474b036

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,9 @@ impl<'db> Type<'db> {
731731
}
732732

733733
pub(crate) fn object(db: &'db dyn Db) -> Self {
734-
KnownClass::Object.to_instance(db)
734+
let x = KnownClass::Object.to_instance(db);
735+
eprintln!("==> Type::object is {} {:?}", x.display(db), db as *const _);
736+
x
735737
}
736738

737739
pub const fn is_unknown(&self) -> bool {
@@ -1316,9 +1318,11 @@ impl<'db> Type<'db> {
13161318
}
13171319

13181320
fn when_subtype_of<C: Constraints<'db>>(self, db: &'db dyn Db, target: Type<'db>) -> C {
1319-
self.has_relation_to::<C>(db, target, TypeRelation::Subtyping)
1320-
.and(db, || self.premises(db))
1321-
.and(db, || target.premises(db))
1321+
let premises = self.premises::<C>(db).and(db, || target.premises(db));
1322+
premises.equivalent_to(
1323+
db,
1324+
self.has_relation_to::<C>(db, target, TypeRelation::Subtyping),
1325+
)
13221326
}
13231327

13241328
/// Return true if this type is [assignable to] type `target`.
@@ -1331,9 +1335,10 @@ impl<'db> Type<'db> {
13311335

13321336
fn when_assignable_to<C: Constraints<'db>>(self, db: &'db dyn Db, target: Type<'db>) -> C {
13331337
let premises = self.premises::<C>(db).and(db, || target.premises(db));
1334-
premises.implies(db, || {
1335-
self.has_relation_to::<C>(db, target, TypeRelation::Assignability)
1336-
})
1338+
premises.equivalent_to(
1339+
db,
1340+
self.has_relation_to::<C>(db, target, TypeRelation::Assignability),
1341+
)
13371342
}
13381343

13391344
fn has_relation_to<C: Constraints<'db>>(

crates/ty_python_semantic/src/types/class.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,6 +4335,7 @@ impl KnownClass {
43354335
pub(crate) fn to_class_literal(self, db: &dyn Db) -> Type<'_> {
43364336
self.try_to_class_literal(db)
43374337
.map(Type::ClassLiteral)
4338+
.inspect(|_| eprintln!("==> a {:?}", self))
43384339
.unwrap_or_else(Type::unknown)
43394340
}
43404341

crates/ty_python_semantic/src/types/constraints.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ pub(crate) trait Constraints<'db>: Clone + Sized {
150150
self.clone().negate(db).or(db, || self.and(db, other))
151151
}
152152

153+
fn equivalent_to(self, db: &'db dyn Db, other: Self) -> Self {
154+
self.clone()
155+
.and(db, || other.clone())
156+
.or(db, || self.negate(db).and(db, || other.negate(db)))
157+
}
158+
153159
/// Returns the intersection of this constraint set and another. The other constraint set is
154160
/// provided as a thunk, to implement short-circuiting: the thunk is not forced if the
155161
/// constraint set is already saturated.
@@ -398,12 +404,6 @@ impl<'db> Constraints<'db> for ConstraintSet<'db> {
398404
) -> Self {
399405
let lower = lower.bottom_materialization(db);
400406
let upper = upper.top_materialization(db);
401-
eprintln!(
402-
"==> constraint {} <: {} <: {}",
403-
lower.display(db),
404-
typevar.display(db),
405-
upper.display(db)
406-
);
407407
match Constraint::range(db, lower, upper) {
408408
Satisfiable::Never => Self::never(),
409409
Satisfiable::Always => Self::always(),
@@ -1039,6 +1039,23 @@ impl<'db> Constraint<'db> {
10391039
///
10401040
/// Panics if `lower` and `upper` are not both fully static.
10411041
fn range(db: &'db dyn Db, lower: Type<'db>, upper: Type<'db>) -> Satisfiable<Constraint<'db>> {
1042+
eprintln!(
1043+
"==> range {}/{} .. {}/{}",
1044+
lower.display(db),
1045+
lower.bottom_materialization(db).display(db),
1046+
upper.display(db),
1047+
upper.top_materialization(db).display(db),
1048+
);
1049+
debug_assert!(
1050+
!matches!(lower, Type::Dynamic(_)),
1051+
"{} is not fully static",
1052+
lower.display(db)
1053+
);
1054+
debug_assert!(
1055+
!matches!(upper, Type::Dynamic(_)),
1056+
"{} is not fully static",
1057+
upper.display(db)
1058+
);
10421059
debug_assert_eq!(
10431060
lower,
10441061
lower.bottom_materialization(db),
@@ -1177,6 +1194,15 @@ impl<'db> RangeConstraint<'db> {
11771194
typevar: BoundTypeVarInstance<'db>,
11781195
set: &mut ConstraintSet<'db>,
11791196
) {
1197+
/*
1198+
eprintln!(
1199+
"==> ¬({} ≤ {} ≤ {})",
1200+
self.lower.display(db),
1201+
typevar.display(db),
1202+
self.upper.display(db)
1203+
);
1204+
*/
1205+
11801206
// Lower bound:
11811207
// ¬(s ≤ α) = ((α ≤ s) ∧ α ≠ s) ∨ (a ≁ s)
11821208
set.union_clause(
@@ -1196,6 +1222,8 @@ impl<'db> RangeConstraint<'db> {
11961222

11971223
// Upper bound:
11981224
// ¬(α ≤ t) = ((t ≤ α) ∧ α ≠ t) ∨ (a ≁ t)
1225+
eprintln!("==> what {}", self.upper.display(db));
1226+
eprintln!("==> what {}", Type::object(db).display(db));
11991227
set.union_clause(
12001228
db,
12011229
ConstraintClause::from_constraints(

0 commit comments

Comments
 (0)