Skip to content

Conversation

@dcreager
Copy link
Member

We were previously normalizing the upper and lower bounds of each constraint when constructing constraint sets. Like in #21463, this was for conflated reasons: It made constraint set displays nicer, since we wouldn't render multiple constraints with obviously equivalent bounds. (Think T ≤ A & B and T ≤ B & A) But it was also useful for correctness, since prior to #21463 we were (trying to) add the full transitive closure to a constraint set's BDD, and normalization gave a useful reduction in the number of nodes in a typical BDD.

Now that we don't store the transitive closure explicitly, that second reason is no longer relevant. Our sequent map can store that full transitive closure much more efficiently than the expanded BDD would have. This helps fix some false positives on #20933, where we're seeing some (incorrect, need to be fixed, but ideally not blocking this effort) assignability failures between a type and its normalization.

Normalization is still useful for display purposes, and so we do normalize the upper/lower bounds before building up our display representation of a constraint set BDD.

@dcreager dcreager added the internal An internal refactor or improvement label Nov 18, 2025
@dcreager dcreager added the ty Multi-file analysis & type inference label Nov 18, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 18, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 18, 2025

mypy_primer results

No ecosystem changes detected ✅

No memory usage changes detected ✅

Comment on lines +2312 to +2317
if left_constraint.implies(db, right_constraint) {
self.add_single_implication(left_constraint, right_constraint);
}
if right_constraint.implies(db, left_constraint) {
self.add_single_implication(right_constraint, left_constraint);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation above seems to imply that we could (should?) return early here? Because if a → b always implies a ∧ b = a, then the code below would otherwise add two additional a → b implications and one a → a implication, both of which seem unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other protections in place against both of those: The single_implications and pair_implications maps now have sets to store all of the consequents, so two copies of a → b will automatically get de-duped, no matter how they're created. And similarly, add_single_implication and add_pair_implication will skip any sequent of the form a → a, a ∧ b → a, or a ∧ b → b, since they are not useful.

@AlexWaygood AlexWaygood removed their request for review November 19, 2025 15:37
dcreager and others added 3 commits November 19, 2025 10:59
* origin/main:
  [ty] Fix flaky tests on macos (#21524)
  [ty] Add tests for generic implicit type aliases (#21522)
  [ty] Semantic tokens: consistently add the `DEFINITION` modifier (#21521)
  Only render hyperlinks for terminals known to support them (#21519)
  [ty] Keep colorizing `mypy_primer` output (#21515)
  [ty] Exit with `2` if there's any IO error (#21508)
  [`ruff`] Fix false positive for complex conversion specifiers in `logging-eager-conversion` (`RUF065`) (#21464)
  [ty] tighten up handling of subscripts in type expressions (#21503)
@dcreager dcreager merged commit 68ebd51 into main Nov 19, 2025
41 checks passed
@dcreager dcreager deleted the dcreager/abnormal branch November 19, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants