[ty] Stop testing the (brittle) constraint set display implementation (#21743)
Some checks are pending
CI / test scripts (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (${{ github.repository == 'astral-sh/ruff' && 'depot-windows-2022-16' || 'windows-latest' }}) (push) Blocked by required conditions
CI / cargo test (macos-latest) (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / ty completion evaluation (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks walltime (medium|multithreaded) (push) Blocked by required conditions
CI / benchmarks walltime (small|large) (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

The `Display` implementation for constraint sets is brittle, and
deserves a rethink. But later! It's perfectly fine for printf debugging;
we just shouldn't be writing mdtests that depend on any particular
rendering details. Most of these tests can be replaced with an
equivalence check that actually validates that the _behavior_ of two
constraint sets are identical.
This commit is contained in:
Douglas Creager 2025-12-02 03:17:29 -05:00 committed by GitHub
parent 2182c750db
commit cf4196466c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 355 additions and 371 deletions

View file

@ -418,6 +418,7 @@ impl<'db> ConstraintSet<'db> {
Self::constrain_typevar(db, typevar, lower, upper, TypeRelation::Assignability)
}
#[expect(dead_code)] // Keep this around for debugging purposes
pub(crate) fn display(self, db: &'db dyn Db) -> impl Display {
self.node.simplify_for_display(db).display(db)
}

View file

@ -2213,10 +2213,8 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
}
Ok(())
}
KnownInstanceType::ConstraintSet(tracked_set) => {
let constraints = tracked_set.constraints(self.db);
f.with_type(ty).write_str("ty_extensions.ConstraintSet")?;
write!(f, "[{}]", constraints.display(self.db))
KnownInstanceType::ConstraintSet(_) => {
f.with_type(ty).write_str("ty_extensions.ConstraintSet")
}
KnownInstanceType::GenericContext(generic_context) => {
f.with_type(ty).write_str("ty_extensions.GenericContext")?;

View file

@ -10573,14 +10573,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
(
Type::KnownInstance(KnownInstanceType::ConstraintSet(left)),
Type::KnownInstance(KnownInstanceType::ConstraintSet(right)),
) => match op {
ast::CmpOp::Eq => Some(Ok(Type::BooleanLiteral(
left.constraints(self.db()) == right.constraints(self.db())
))),
ast::CmpOp::NotEq => Some(Ok(Type::BooleanLiteral(
left.constraints(self.db()) != right.constraints(self.db())
))),
_ => None,
) => {
let result = match op {
ast::CmpOp::Eq => Some(
left.constraints(self.db()).iff(self.db(), right.constraints(self.db()))
),
ast::CmpOp::NotEq => Some(
left.constraints(self.db()).iff(self.db(), right.constraints(self.db())).negate(self.db())
),
_ => None,
};
result.map(|constraints| Ok(Type::KnownInstance(KnownInstanceType::ConstraintSet(
TrackedConstraintSet::new(self.db(), constraints)
))))
}
(