-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Constraint solver] Favor more-specialized overload among two generics. #14499
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
[Constraint solver] Favor more-specialized overload among two generics. #14499
Conversation
@swift-ci please test and merge |
And... it looks like this breaks when I put it on master:
The "enum cases" examples are changes in diagnostics that are mostly good; the "slow" test is now fast (which is also good); but the "optional" change is potentially a regression. |
@@ -1391,6 +1391,29 @@ void ConstraintSystem::addOverloadSet(Type boundType, | |||
return; | |||
} | |||
|
|||
// Performance hack: if there are two generic overloads, and one is | |||
// more specialized than the other, prefer the more-specialized one. | |||
if (!favoredChoice && choices.size() == 2 && |
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 idea is great! I'm trying to implement similar thing as well but instead of hard-coding this to 2 overloads only, maybe it would be better to try and group overload choices based on declaration context and rank them in groups so at the end there are N favored choices in the set?... Another idea might be to move from favoring to making it a ranking criteria since we erase worse intermediate solutions...
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.
You're absolutely right that we could generalize this. In general, if an one overload is more specialized than another, we should try it first. We could probably encode this information in an tree of disjunctions using favored constraints... but it would probably be better in the long run to compute the lattice describing the relationships and have the solver take an appropriate path through the lattice.
As for moving it to ranking criteria, that won't prune as efficiently, because we often still explore those other options. I'd rather
When we form an overload set containing two generic functions, where one is more specialized than the other, "favor" the more-specialized function in the constraint system so we won't explore any paths involving the less-specialized function when the more-specialized version applies. This should be a strict improvement, because previously we would have always gone down both paths. Fixes rdar://problem/37371815, taking this exponential example linear.
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
48f8501
to
a7239c7
Compare
@swift-ci please test source compatibility |
@swift-ci please smoke test |
@swift-ci please test source compatibility |
@swift-ci please smoke test compiler performance |
1 similar comment
@swift-ci please smoke test compiler performance |
@swift-ci please smoke test |
Build comment file:Compilation-performance test failed |
@swift-ci please smoke test compiler performance |
Build comment file:Compilation-performance test failed |
a7239c7
to
dee02c4
Compare
@swift-ci please clean test source compatibility |
1 similar comment
@swift-ci please clean test source compatibility |
…tlang#14497)" This reverts commit 43435af.
… serialize syntax trees. (swiftlang#14424)" (swiftlang#14465)" This reverts commit f8c77e1.
@swift-ci please smoke test |
@swift-ci please test source compatibility |
@swift-ci please smoke test |
@swift-ci please test source compatibility |
@swift-ci please smoke test compiler performance |
1 similar comment
@swift-ci please smoke test compiler performance |
Build comment file:Compilation-performance test failed |
@swift-ci please smoke test compiler performance |
Build comment file:Compilation-performance test failed |
@swift-ci please test compiler performance |
3 similar comments
@swift-ci please test compiler performance |
@swift-ci please test compiler performance |
@swift-ci please test compiler performance |
When we form an overload set containing two generic functions, where
one is more specialized than the other, "favor" the more-specialized
function in the constraint system so we won't explore any paths
involving the less-specialized function when the more-specialized
version applies. This should be a strict improvement, because
previously we would have always gone down both paths.
Fixes rdar://problem/37371815, taking this exponential example linear.