Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay hard argument comparisons #20007

Merged
merged 3 commits into from
Mar 26, 2024
Merged

Delay hard argument comparisons #20007

merged 3 commits into from
Mar 26, 2024

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 23, 2024

When comparing arguments of two applied types, perform hard comparisons after easy ones. A comparison is hard if it entails a subtype test A <: B where A is an AndType or B is an OrType. Such comparisons need to perform an either, which might lose solutions.

Fixes #19999

When comparing arguments of two applied types, perform hard comparisons
after easy ones. A comparison if hard if it entails a subtype test A <: B
where A is an AndType or B is an OrType. Such comparisons need to perform an either,
which might lose solutions.

Fixes scala#19999
@odersky
Copy link
Contributor Author

odersky commented Mar 23, 2024

We could possibly generalize this, delaying hard comparisons in more conjunctive tests, not just type in arguments. But it is hard in general to identify a conjunctive subsequence of tests when doing a subtype traversal.

@dwijnand
Copy link
Member

Interesting! I've had a case that required this defer too.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

* So we defer such tests to run last, on the chance that some other argument
* comparison will instantiate or constrain type variables first.
*/
def isHard(arg1: Type, arg2: Type): Boolean =
Copy link
Member

Choose a reason for hiding this comment

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

Using the word hard here might lead to confuse with hard unions since OrTypes are also involved. Maybe we could call this isIncomplete instead?

compiler/src/dotty/tools/dotc/core/TypeComparer.scala Outdated Show resolved Hide resolved
@smarter smarter assigned odersky and unassigned smarter Mar 25, 2024
Co-authored-by: Guillaume Martres <[email protected]>
@smarter smarter merged commit 5c6524a into scala:main Mar 26, 2024
19 checks passed
@smarter smarter deleted the fix-19999 branch March 26, 2024 14:43
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
WojciechMazur added a commit that referenced this pull request Jul 5, 2024
Backports #20007 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No longer able to extract a type from an intersection
4 participants