-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ConstraintSolver] Forbid forming solutions with free generic type parameters #10021
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
Conversation
@swift-ci please smoke test |
This looks good, but what's with the operator+ showing up in completion results everywhere? Is it bogus? |
@nkcsgexi Should take a look at this |
@slavapestov I think this is correct actually because we allow unresolved types now which means if there is anything like |
Right, but when the left hand side is a tuple type, none of those overloads should apply, since there is a conformance constraint on Self. |
True, I somehow only noticed that happening for objects, but I see that there is a tuple in there too, so don't know, maybe this exposed a bug somewhere in |
Even for objects this operator should only show up if it conforms to the relevant protocols. It's worth investigating... |
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.
The actual changes look good, but I agree we need to understand why the completion results change here.
@xedin I'm a little confused why does this change leads to showing |
@@ -2058,7 +2058,7 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) { | |||
|
|||
// Attempt to solve the constraint system. | |||
SmallVector<Solution, 4> viable; | |||
if (CS.solve(viable, FreeTypeVariableBinding::GenericParameters)) | |||
if (CS.solve(viable, FreeTypeVariableBinding::UnresolvedType)) |
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.
Looking into this a little bit, code completion calls typeCheckCompletionSequence
for each potential operators to decide whether they should be included into the code completion list. It seems this line change caused a solution that used to be unviable for "+" now becomes viable, thus +
is considered as a viable code completion item. Any idea why this line change is less strict than before?
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.
Ok, the reason why + is returned in here is because + has multiple generic overloads and UnresolvedType is more permissive than GenericParameter, so what it's matching is -
Swift.(file).Strideable.+ : <Self where Self : Strideable> (Self.Type) -> (Self.Stride, Self) -> Self
. I think I can tweak typeCheckCompletionSequence
so if CCE
is unresolved don't return it the solution.
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.
Great, Thank you!
172c09b
to
52d44d0
Compare
@slavapestov @rudkx @nkcsgexi Alright, all of the + overloads are gone from the results. |
@swift-ci please smoke test |
@nkcsgexi looks like it can't find
It looks like that list has only operators with a single argument, do you think that is correct? |
Since this test is on SourceKit side where it is not the main channel for us to test code completion correctness, updating the test accordingly and file a rdar to log such update makes sense. |
Thanks, @nkcsgexi ! I've filed rdar://problem/32519796 |
…rameters `FreeTypeVariableBinding::GenericParameters` mode allowed to bind all free type variables with fresh generic parameter types, which is incorrect (at least) if there are multiple generic solutions present, because such parameters couldn't be compared. This mode was used for code completion, which is now switched to use `FreeTypeVariableBinding::UnresolvedType` instead.
52d44d0
to
f09d2ad
Compare
@swift-ci please smoke test |
FreeTypeVariableBinding::GenericParameters
mode allowed to bindall free type variables with fresh generic parameter types, which
is incorrect (at least) if there are multiple generic solutions
present, because such parameters couldn't be compared.
This mode was used for code completion, which is now switched to use
FreeTypeVariableBinding::UnresolvedType
instead.