MilesCranmer / DispatchDoctor.jl

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

Fix union limit edge-case within tuple #33

Closed MilesCranmer closed 3 weeks ago

MilesCranmer commented 3 weeks ago

Fixes an edgecase where a return type Tuple{Union{A,B,C}} would not respect the user-provided union_limit. This fixes it by adding special treatment for tuple types.

Note that this does not apply to any other struct. It just seems that tuples get special treatment by the compiler:

julia> struct A{T}
           a::T
       end

julia> Base.isconcretetype(Union{Float32,Float64})
false

julia> Base.isconcretetype(Tuple{Union{Float32,Float64}})
false

julia> Base.isconcretetype(A{Union{Float32,Float64}})
true
MilesCranmer commented 3 weeks ago

Even NamedTuple does not have this issue:

julia> Base.isconcretetype(@NamedTuple{a::Union{Float32,Float64}})
true

So it seems we truly only need a special branch for tuples.

coveralls commented 3 weeks ago

Coverage Status

coverage: 99.682% (+0.004%) from 99.678% when pulling 0a9d2db90353e9c8da15c88d46020bb91e5d4e7a on union-limit-within-tuple into 2a4631579793959b0668a741e6809d42a342ad58 on main.