-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ConstraintSolver] When ranking bindings prefer type vars with literal bindings #11966
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
[ConstraintSolver] When ranking bindings prefer type vars with literal bindings #11966
Conversation
What does this give us? |
@slavapestov Sometimes we pick something for "best" bindings which isn't really that, e.g. when I remove contraction of |
b8ece38
to
603d28d
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Linux platform |
@rudkx Looks like it improved one of the slow perf tests too by applying literals earlier \o/ |
@swift-ci please test source compatibility |
…l bindings Change the potential binding ranking logic to prefer type variables which don't have other type variables related to them, but have literal bindings, over the ones that do have other type variables.
603d28d
to
7d80daf
Compare
@rudkx I've added couple more steps to the test which is now much faster and moved it to perf/fast. |
@swift-ci please smoke test |
@swift-ci please test source compatibility |
Awesome! Although that test case should be diagnosed as invalid :( We don't allow single-element tuples as values anymore. |
@slavapestov This is intentional, some of the code exhibits exponential behavior when we can't easily find a solution or there is no solution e.g. let a = "a"
let b = "b"
let c = 42
_ = "a=" + a + ";b=" + b + ";c=" + c Is currently "too complex" because it can't find a solution with favorite types and solver goes on exploring generics forever... |
If the best bindings we could get on the current step are bindings to literal type without any other type variable involved, let's try to attempt them right away, that should help to prune search space.
…pe variable they belong to
@rudkx I've added commit which removes restrictions for early attempting of literal bindings and refactored |
@swift-ci please smoke test |
@swift-ci please test source compatibility |
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.
LGTM. I had tried the same change to CSSolver.cpp not that long ago but I think something failed. Maybe it also requires the other change to type check one of the expressions or perhaps something else has changed in the meantime.
@swift-ci please smoke test and merge |
Change the potential binding ranking logic to prefer type variables
which don't have other type variables related to them, but have literal
bindings, over the ones that do have other type variables.