-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Attempt to fix a potentially missing case in TypeComparer #5914
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
Attempt to fix a potentially missing case in TypeComparer #5914
Conversation
@smarter to clarify, this is the case I was talking about. To see why it's necessary, consider that if Since I'm not that familiar with type inference, I have no idea what kind of code would require this and cannot test it. |
@@ -451,7 +451,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] { | |||
// widening in `fourthTry` before adding to the constraint. | |||
if (frozenConstraint) isSubType(tp1, bounds(tp2).lo) | |||
else isSubTypeWhenFrozen(tp1, tp2) | |||
alwaysTrue || { | |||
alwaysTrue || | |||
frozenConstraint && (tp1 match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have a test case that fails if the case is missing! Failing that, one can try to instrument the code to see whether the new logic makes a difference anywhere in the existing code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky the following code fails without this case:
val a = newTypeVar(TypeBounds.empty)
val b = newTypeVar(TypeBounds.empty)
a <:< b
assert(a frozen_<:< b)
I think that seems potentially problematic. I believe I actually ran across this issue half a year ago, when I was trying to make my exhaustivity checker use Constraint
as a constraint solver. That being said, I have 0 idea on how to make TypeComparer enter this case w/o manually triggering it.
EDIT: for clarity, I meant to hand off this PR to @smarter. I think it's useful to know that a potential problem exists and that we already have a fix for it, even if it doesn't impact the codebase yet. It seems to me that if (a <:< b) then a frozen_<:< b
is a useful invariant to have.
46ab58b
to
f6d037a
Compare
@odersky can I get a re-review on this? I checked if this code actually impacts the codebase and the answer is it does: see all occurrences of "!!! result affected !!!" in http://dotty-ci.epfl.ch/lampepfl/dotty/11090/4. The problem is that all those occurences that I've checked (and there are 34) seemingly make comparing a type parameter with itself slightly quicker:
Note that if not for this change, the entire operation would still return To reiterate from our Monday meeting: I still think we should merge this PR - not having this case can result in very confusing results for someone trying to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting to the bottom of this. I agree it's better to add the code to avoid surprises.
This is the potentially missing case that I described in #5736 (comment).