type system revision and new subtype algorithm#18457
Conversation
src/typemap.c
Outdated
| return jl_types_equal_generic(a, b, useenv); | ||
| } | ||
| return jl_subtype(a, b, 0) && jl_subtype(b, a, 0); | ||
| return jl_types_equal(a, b); |
There was a problem hiding this comment.
❤️
(can now get rid of this function, those comments, and rip out useenv entirely :)
|
Theoretically, any tuple is Nevertheless, this is incredible. 👍 |
|
I'm a bit confused by |
|
I thought |
|
Ah, yes. I was forgetting how the new Tuple type syntax works. Thanks, @johnmyleswhite. |
|
(I was thinking of |
Oh snap! Flashback to my giddy excitement during your JuliaCon 2015 talk :) |
|
@TotalVerb Good point. From there, we have two choices:
We currently pick (2). While |
|
Ah. So the current rule for function dispatch, that typevars in covariant position only range over concrete types, will be applied to type calculations too? It is certainly nice that this will be made more consistent than it is presently: julia> test{T}(::Vararg{T,2}) = T
test (generic function with 1 method)
julia> test(1,1.0)
ERROR: MethodError: no method matching test(::Int64, ::Float64)
Closest candidates are:
test{T}(::T...) at REPL[128]:1
julia> typeof(test).name.mt.defs.sig
Tuple{#test,Vararg{T,2}}
julia> isa((test,1,1.0), ans)
true
|
Yes. That certain typevars range over concrete types is now just a structural property of types, to be followed by all type operations. |
cb4ee8e to
aa2e093
Compare
| unionlen(x::Union) = unionlen(x.a) + unionlen(x.b) | ||
| unionlen(x::ANY) = 1 | ||
|
|
||
| _uniontypes(x::Union, ts) = (_uniontypes(x.a,ts); _uniontypes(x.b,ts); ts) |
There was a problem hiding this comment.
The underscore means you're not allowed to complain about it :)
|
There's some performance we need to claw back, looks like this added about 10 minutes to the test time on appveyor. Probably comparable on Travis. |
This implements the plan in #8974. It is now working well enough to build a system image and get a REPL, albeit with inference disabled. I have some demos.
In the internals there are "only" three changes:
UnionAlltypes, which have two fields: a TypeVar and a type body:Uniontypes now have two fields, pointing to two types to union together (instead of an svec of types). This is just a representation change.The second one is issue #18450.
UnionAll types nest arbitrarily, and the signatures of methods with static parameters are UnionAll types, so we now have "triangular" dispatch:
(Clearly showing the method error isn't working, but that should just be a matter of updating the showing and reflection code in Base.)
The next steps are to get inference working and then fully replace intersection and morespecific with implementations based on the new algorithm.
Edit: Fixes #19159 #18892 #18450 #18348 #17943 #16922 #13165 #12596 #11803 #8915 #8625 #6721 #2552