Thanks.
Btw, I found a weird case of Julia’s specialization rules interfering with this interface:
using DispatchDoctor
@stable f(a, t::Type{T}) where {T} = sum(a; init=zero(T))
f([1f0, 1f0], Float32)
Despite the normal function being type stable, this actually fails the type specialization test
ERROR: TypeInstabilityError: Instability detected in function `f`
with arguments `(Vector{Float32}, DataType)`. Inferred to be
`Any`, which is not a concrete type.
Stacktrace:
[1] #_stable_wrap#1
@ ~/PermaDocuments/DispatchDoctor.jl/src/DispatchDoctor.jl:25 [inlined]
because of Julia’s type specialization rules:
As a heuristic, Julia avoids automatically specializing on argument type parameters in three specific cases:
Type
,Function
, andVararg
.
Even if I modify _stable_wrap
to be
_stable_wrap(f::F, caller::G, args::Vararg{Any,N}; kwargs...) where {F,G,N}
it still fails, because now there are multiple non-specializing cases (Vararg
and Type
) – it seems like Julia lacks logic to deal with this situation.
I started a thread about this issue a while back:
but seems like that solution doesn’t work here.
Is there any way to force Julia to specialize no matter what?