Skip to content

Commit

Permalink
dict value fix (#688)
Browse files Browse the repository at this point in the history
* dict value fix

* Update test/tracing.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
wsmoses and github-actions[bot] authored Feb 4, 2025
1 parent 234d168 commit 21f7660
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Tracing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,19 @@ end
Base.@nospecializeinfer @inline dict_key(::Type{<:AbstractDict}) = nothing
Base.@nospecializeinfer @inline dict_key(::Type{<:AbstractDict{K}}) where {K} = K
Base.@nospecializeinfer @inline dict_value(::Type{<:AbstractDict}) = nothing
Base.@nospecializeinfer @inline dict_value(
::Type{<:(AbstractDict{K,V} where {K})}
) where {V} = V
Base.@nospecializeinfer @inline function dict_value(
T::Type{<:(AbstractDict{K,V} where {K})}
) where {V}
if @isdefined(V)
V
elseif T <: UnionAll
dict_value(T.body)
elseif T <: Dict && length(T.parameters) >= 2
T.parameters[2]
else
error("Could not get element type of $T")
end
end

Base.@nospecializeinfer function traced_type_inner(
@nospecialize(T::Type{<:AbstractDict}),
Expand Down
17 changes: 17 additions & 0 deletions test/tracing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ end
(Dict{A,TracedRArray{Float64,0}} where {A}),
(Dict{A,TracedRArray{Float64,0}} where {A}),
),
(
(
Dict{
Symbol,NTuple{nsteps,SpectralVariable3D}
} where {nsteps} where {SpectralVariable3D}
),
(
Dict{
Symbol,NTuple{nsteps,SpectralVariable3D}
} where {nsteps} where {SpectralVariable3D}
),
(
Dict{
Symbol,NTuple{nsteps,SpectralVariable3D}
} where {nsteps} where {SpectralVariable3D}
),
),
(
Base.Pairs{Symbol,Union{}},
Base.Pairs{Symbol,Union{}},
Expand Down

0 comments on commit 21f7660

Please sign in to comment.