RFC: experiments in diagonal constraints in jl_args_morespecific (ambiguity/method sorting) #16276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At the moment this is purely an experiment, as it doesn't even get as far as building inference. But I thought I'd post it as potentially thought-provoking. This is motivated by the assumption that #8974 is julia-0.6 at the earliest, and wondering if we can make some improvements in ambiguity-detection and method-sorting now.
This mostly explores TypeVars and "diagonal" constraints. Over in #11242 (comment) @yuyichao came up with some great examples of interesting cases for our current type-specificity computations. All of his examples are currently resolved using the rule that if any argument is more specific than any other, and no argument is less specific, then the method is more specific.
However, this leads to problems like #10174. I've wondered whether ambiguity should be defined along the lines of "two non-identical signatures, neither of which is consistently more specific than the other over the domain of their intersection." The italicized part is potentially a big change, for example:
Currently
f1(1,1) == 2
, becauseNumber
is broader thanInteger
. But if one adopts the "over the domain of their intersection" perspective, this doesn't make a lot of sense: both of these methods are candidates only when both args are integers, and when that's true definition 1 is actually more restrictive, since it additionally requires that both arguments are of the same type.This PR explores the possibility of using type-intersection to "nail down" TypeVars and plug them in before running
jl_args_morespecific
. It borks buildingint.jl
due to situations like this:which are judged as having the same priority, because in both cases
T
gets set toSigned
. So, this isn't right, and may not be a productive direction (esp. at this stage in the julia-0.5 release), but I thought it was worth a couple of hours.