Closed
Description
openedon Mar 16, 2020
Using nspecializations
from here, I find the following behavior strange:
julia> function abstractparameters(T::Type, AT::Type)
@nospecialize T AT
@assert T <: AT
Tst = supertype(T)
while Tst <: AT
T = Tst
Tst = supertype(T)
end
return T.parameters
end
abstractparameters (generic function with 1 method)
julia> abstractparameters(typeof(rand(3)), AbstractArray)
svec(Float64, 1)
julia> abstractparameters(typeof(rand(Float32, 3)), AbstractArray)
svec(Float32, 1)
julia> abstractparameters(typeof(rand(Int, 3)), AbstractArray)
svec(Int64, 1)
julia> m = first(methods(abstractparameters))
abstractparameters(T::Type, AT::Type) in Main at REPL[3]:2
julia> nspecializations(m) # this is what I expect
1
julia> @generated function f(a::AbstractArray)
T, N = abstractparameters(a, AbstractArray) # call it from a @generated method
:($T(1))
end
f (generic function with 1 method)
julia> f(rand(3))
1.0
julia> f(rand(Float32, 3))
1.0f0
julia> nspecializations(m) # this is what I don't want
2
julia> m.specializations
Core.TypeMapEntry(Core.TypeMapEntry(nothing, Tuple{typeof(abstractparameters),Type,Type}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type, ::Type), false, false, false), Tuple{typeof(abstractparameters),Type,Type{AbstractArray}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type, ::Type{AbstractArray}), false, false, false)
This is a MWE of a bigger problem: in LoopVectorization, I've measured at least 33 specializations of abstractparameters
despite the fact that both arguments are marked as not being specialiizable. In that case there are specializations on both parameters. Here's 30 of them:
julia> m.specializations.arg1[1].targ
30-element Array{Any,1}:
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{1,3}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{1,3}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float64,Tuple{1,3}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float64,Tuple{1,3}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{1,73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{1,73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{1,75}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{1,75}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{69,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{69,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{73,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{73,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float32,Tuple{75,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float32,Tuple{75,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Float64,Tuple{1,73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Float64,Tuple{1,73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
⋮
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int32,Tuple{73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int32,Tuple{73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int32,Tuple{75,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int32,Tuple{75,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{1,73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{1,73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{1,75}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{1,75}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{69,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{69,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{73,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{73,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{73}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{73}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Core.TypeMapEntry(nothing, Tuple{typeof(LoopVectorization.abstractparameters),Type{StaticStridedPointer{Int64,Tuple{75,1}}},Type{VectorizationBase.AbstractStaticStridedPointer}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for abstractparameters(::Type{StaticStridedPointer{Int64,Tuple{75,1}}}, ::Type{VectorizationBase.AbstractStaticStridedPointer}), false, true, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels