Skip to content

Conversation

mtshiba
Copy link
Contributor

@mtshiba mtshiba commented Mar 15, 2025

Summary

From #16641

As stated in this comment (#16641 (comment)), the current ordering implementation for intersection types is incorrect. So, I will introduce lexicographic ordering for intersection types.

Test Plan

As can be seen here, it appears that the execution time of red_knot_check_file will slow down by about 3% when this change is merged. The slow-down itself is unavoidable given that we have been skipping processes that should have been done, but please let me know if there is a better ordering algorithm or some sort of salsa query technique.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 15, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great! It looks like this change means that the negation_reverses_subtype_order property test now passes consistently; could you move it from the flaky submodule in property_tests.rs to the stable submodule?

I verified that it now passes consistently by running QUICKCHECK_TESTS=2000000 cargo test --release -p red_knot_python_semantic -- --ignored types::property_tests::flaky::negation_reverses_subtype_order, which quickly fails on main but not on this PR branch.

@AlexWaygood AlexWaygood reopened this Mar 17, 2025
Copy link
Contributor

github-actions bot commented Mar 17, 2025

mypy_primer results

No ecosystem changes detected ✅

This comment was marked as off-topic.

@AlexWaygood
Copy link
Member

As can be seen here, it appears that the execution time of red_knot_check_file will slow down by about 3% when this change is merged. The slow-down itself is unavoidable given that we have been skipping processes that should have been done, but please let me know if there is a better ordering algorithm or some sort of salsa query technique.

For this change on its own, the benchmarks are in fact entirely neutral. I think the slowdown observed on that earlier PR must come from somewhere else.

Thanks for the PR, this is great!

@AlexWaygood AlexWaygood changed the title fix incorrect ordering of intersection [red-knot] Stabilize negation_reverses_subtype_order property test Mar 17, 2025
@AlexWaygood
Copy link
Member

I'm so sorry -- I closed this meaning to close and reopen it, but now GitHub isn't letting me reopen it. I'll try to open a fresh PR from this branch.

@AlexWaygood
Copy link
Member

#16801. Sorry again; don't know why this happened :-(

AlexWaygood added a commit that referenced this pull request Mar 17, 2025
…16801)

## Summary

This is a re-creation of #16764 by
@mtshiba, which I closed meaning to immediately reopen (GitHub wasn't
updating the PR with the latest pushed changes), and which GitHub will
not allow me to reopen for some reason. Pasting the summary from that PR
below:

> From #16641
> 
> As stated in this comment
(#16641 (comment)),
the current ordering implementation for intersection types is incorrect.
So, I will introduce lexicographic ordering for intersection types.

## Test Plan

One property test stabilised (tested locally with
`QUICKCHECK_TESTS=2000000 cargo test --release -p
red_knot_python_semantic -- --ignored
types::property_tests::stable::negation_reverses_subtype_order`), and
existing mdtests that previously failed now pass.

Primarily-authored-by:
[mtshiba](https://github.com/astral-sh/ruff/commits?author=mtshiba)

---------

Co-authored-by: Shunsuke Shibayama <sbym1346@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants