Skip to content

[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

Merged
merged 1 commit into from
Jun 1, 2017

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 1, 2017

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.

@xedin xedin requested review from slavapestov and rudkx June 1, 2017 02:27
@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

This looks good, but what's with the operator+ showing up in completion results everywhere? Is it bogus?

@slavapestov
Copy link
Contributor

@nkcsgexi Should take a look at this

@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@slavapestov I think this is correct actually because we allow unresolved types now which means if there is anything like +(Self, Self) -> Self it would be included, and there is a bunch of overloads like that.

@slavapestov
Copy link
Contributor

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.

@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

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 CompletionLookup. Any ideas, @nkcsgexi ?

@slavapestov
Copy link
Contributor

Even for objects this operator should only show up if it conforms to the relevant protocols. It's worth investigating...

Copy link
Contributor

@rudkx rudkx left a 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.

@nkcsgexi
Copy link
Contributor

nkcsgexi commented Jun 1, 2017

@xedin I'm a little confused why does this change leads to showing + operator in the code completion list?

@@ -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))
Copy link
Contributor

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?

Copy link
Contributor Author

@xedin xedin Jun 1, 2017

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, Thank you!

@xedin xedin force-pushed the no-free-generic-params branch from 172c09b to 52d44d0 Compare June 1, 2017 19:26
@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@slavapestov @rudkx @nkcsgexi Alright, all of the + overloads are gone from the results.

@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@nkcsgexi looks like it can't find x<< anymore, if I look at results I can see following list:

Results for filterText: x [
    {name:x}
    {name:x.}
    {name:x=}
    {name:x==}
    {name:x!=}
    {name:x<}
    {name:x>}
    {name:x<=}
    {name:x>=}
    {name:x+}
    {name:x-}
    {name:x*}
    {name:x/}
    {name:x%}
    {name:x+=}
    {name:x-=}
    {name:x*=}
    {name:x/=}
    {name:x%=}
    {name:x&<<}
    {name:x&>>}
    {name:x&<<=}
    {name:x&>>=}
    {name:x&}
    {name:x|}
    {name:x^}
    {name:x&=}
    {name:x|=}
    {name:x^=}
    {name:x...}
    {name:x...}
    {name:x..<}
    {name:x&*}
    {name:x&+}
    {name:x&-}
    {name:x~=}
]

It looks like that list has only operators with a single argument, do you think that is correct?

@nkcsgexi
Copy link
Contributor

nkcsgexi commented Jun 1, 2017

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.

@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

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.
@xedin xedin force-pushed the no-free-generic-params branch from 52d44d0 to f09d2ad Compare June 1, 2017 21:05
@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2017

@swift-ci please smoke test

@xedin xedin merged commit 0a0585c into swiftlang:master Jun 1, 2017
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.

4 participants