Julia inner type-inference working

Hi all,

I run over a very surprising type-inference difference. I always thought these two codes would be regarded identical to Julia’s compiler.

make_sigtype_without_bits(::Type{T}) where T<:Tuple = Tuple{_make_sigtype_without_bits.(tuple(T.parameters...))...}
make_sigtype_without_bits2(sigtype) = Tuple{_make_sigtype_without_bits.(tuple(sigtype.parameters...))...}
_make_sigtype_without_bits(element::Type) = element
_make_sigtype_without_bits(bits) = Core.Typeof(bits)

however the difference is huge:

julia> Base.promote_op(make_sigtype_without_bits, Type{Tuple{Int, 1}})
Type{Tuple{Int64, Int64}}

julia> Base.promote_op(make_sigtype_without_bits2, Type{Tuple{Int, 1}})
Type

Does someone know why I need to use explicit where syntax in order to get the compiler support? What is the semantic difference between the versions explicit-where and no-where-at-all which make for such drastic differences?

Using Julia 1.6.1

https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing

this is documented and explained here.

3 Likes

Impressive. I once read over the whole documentation. Either it is too long ago and I forgot or too long and documentation have been added meanwhile.

Really nice that this is already well documented and thank you so much for the fast and direct response!

2 Likes