Skip to content

[5.1][ConstraintSystem] Consolidate logic forming locators to callees #25782

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 26, 2019

This PR adds ConstraintSystem::getCalleeLocator, which forms a locator that describes the callee of a given expression. This function is then used to replace various places where this logic is duplicated, and in doing so improves a couple of diagnostics due to catching cases that were previously missed. Most notably, it's now more lenient when forming a ConstructorMember locator for an apply. Previously such a locator was only formed for an apply of a TypeExpr, however now it's formed for an apply of an expr of AnyMetatypeType. This better matches the logic in simplifyApplicableFnConstraint and allows us to better diagnose things like type(of: x)(...).

getCalleeLocator is then used when checking if we can diagnose an ambiguity with fixes, which allows us to have fixes anchored to both the apply and to its function expr (where the former could be looking at an argument of the apply, and the latter could be looking at a requirement of the callee).

Finally, this PR adds a convenience getDeclOrNull function to OverloadChoice, and fixes a simple compiler crasher. Given how straightforward these changes were, I didn't feel it was worth splitting them into a separate PR.

Resolves SR-10694 and SR-10696.

This commit adds `ConstraintSystem::getCalleeLocator`, which forms a
locator that describes the callee of a given expression. This function
is then used to replace various places where this logic is duplicated.

This commit also changes the conditions under which a ConstructorMember
callee locator is formed. Previously it was formed for a CallExpr with a
TypeExpr function expr. However, now such a locator is formed if the
function expr is of AnyMetatypeType. This allows it to be more lenient
with invalid code, as well as work with DotSelfExpr.

Resolves SR-10694.

(cherry picked from commit 894a1e5)
Currently we check that the fixes share the same anchor, however this
doesn't account for the case where, given an ApplyExpr, one fix is
anchored on its function expr, and another is anchored on the apply
itself (because the former fix might be looking at the callee's
requirements, and the latter fix might be looking at an argument of
the call).

This commit changes the logic such that we check that fixes share the
same callee locator, which covers the above case. In addition, now
that we have the callee locator, we can use this to find the overload
directly.

(cherry picked from commit 63df26a)
This helps clean up a bunch of call sites.

(cherry picked from commit 8aa7401)
@xedin
Copy link
Contributor Author

xedin commented Jun 26, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8da7501

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8da7501

@hamishknight
Copy link
Contributor

If we're cherry-picking this, could we also cherry-pick 40d2f51 to make sure we don't start resolving callee overloads for x[](y) expressions?

@xedin
Copy link
Contributor Author

xedin commented Jun 26, 2019

@hamishknight Absolutely!

@xedin
Copy link
Contributor Author

xedin commented Jun 26, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8da7501

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8da7501

Previously we returned a subscript member locator for an apply of a
subscript expr, which is incorrect because the callee is the function
returned from the subscript rather than the subscript itself.

(cherry picked from commit 40d2f51)
@xedin xedin force-pushed the callee-locator-logic-consolidation-5.1 branch from 7fe1bd2 to a0a4a5b Compare June 26, 2019 18:21
@xedin
Copy link
Contributor Author

xedin commented Jun 26, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7fe1bd22b66fdef132899cc399f6ee79ef49e26d

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7fe1bd22b66fdef132899cc399f6ee79ef49e26d

@theblixguy
Copy link
Collaborator

Seems like this is good to merge! I hope this fixes my other PR 🤞

@xedin xedin merged commit bf61952 into swiftlang:swift-5.1-branch Jun 26, 2019
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