Skip to content

Commit 0ad323e

Browse files
add dispatch on DualEltypeChecker
1 parent 955616b commit 0ad323e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/forwarddiff.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
# all be unrolled and optimized away.
4343
# Being unrolled also means const prop can work for things like
4444
# `mapreduce(f, op, propertynames(x))`
45-
# where `f` may call `getfield` and thus have return type dependent
45+
# where `f` may call `getproperty` and thus have return type dependent
4646
# on the particular symbol.
4747
# `mapreduce` hasn't received any such specialization.
4848
@inline diffeqmapreduce(f::F, op::OP, x::Tuple) where {F, OP} = reduce_tup(op, map(f, x))
@@ -57,7 +57,14 @@ struct DualEltypeChecker{T}
5757
counter::Int
5858
DualEltypeChecker(x::T, counter::Int) where {T} = new{T}(x, counter + 1)
5959
end
60+
6061
function (dec::DualEltypeChecker)(::Val{Y}) where {Y}
62+
isdefined(dec.x, Y) || return Any
63+
anyeltypedual(getproperty(dec.x, Y), dec.counter)
64+
end
65+
66+
# use `getfield` for `Pairs`, see https://github.com/JuliaLang/julia/pull/39448
67+
function (dec::DualEltypeChecker{<:Base.Pairs})(::Val{Y}) where {Y}
6168
isdefined(dec.x, Y) || return Any
6269
anyeltypedual(getfield(dec.x, Y), dec.counter)
6370
end

0 commit comments

Comments
 (0)