MilesCranmer / DispatchDoctor.jl

The dispatch doctor prescribes type stability
Apache License 2.0
128 stars 6 forks source link

Fix Julia special case types #3

Closed MilesCranmer closed 1 month ago

MilesCranmer commented 1 month ago

Right now the function

using DispatchDoctor
@stable f(a, t::Type{T}) where {T} = sum(a; init=zero(T))

is not classified as stable, even though it is. This is because of weird specialization rules: https://docs.julialang.org/en/v1.10/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing

To fix this, this PR moves back to a closure approach. This simplifies a lot of other things too and doesn't hurt performance.

This also makes it possible to use Vararg-args.