From b883867d74dd394fcdd9dcfb776bc9003dd0fb18 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 1 May 2024 09:49:51 -0400 Subject: [PATCH 1/2] stage1: Mark `partial` and `primal` helpers as `@inline` It's unclear whether this is a compiler bug upstream, but I've observed invokes like this in the wild: ``` %xxx = invoke DAECompiler.partial(%135::Diffractor.TangentBundle{1}, 1::Int64)::Any ``` which are (clearly) very poorly typed. `%135` was a fully concrete type, so I'm not sure why the tangent type parameters ended up getting stripped off. In any case, the implementations here are so small that they are probably best just inlined anyway. --- src/stage1/forward.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/stage1/forward.jl b/src/stage1/forward.jl index 117debb7..26890d70 100644 --- a/src/stage1/forward.jl +++ b/src/stage1/forward.jl @@ -1,14 +1,14 @@ -partial(x::TangentBundle, i) = partial(getfield(x, :tangent), i) -partial(x::ExplicitTangent, i) = getfield(getfield(x, :partials), i) -partial(x::TaylorTangent, i) = getfield(getfield(x, :coeffs), i) -partial(x::UniformTangent, i) = getfield(x, :val) -partial(x::AbstractZero, i) = x +@inline partial(x::TangentBundle, i) = partial(getfield(x, :tangent), i) +@inline partial(x::ExplicitTangent, i) = getfield(getfield(x, :partials), i) +@inline partial(x::TaylorTangent, i) = getfield(getfield(x, :coeffs), i) +@inline partial(x::UniformTangent, i) = getfield(x, :val) +@inline partial(x::AbstractZero, i) = x -primal(x::AbstractTangentBundle) = x.primal -primal(z::ZeroTangent) = ZeroTangent() +@inline primal(x::AbstractTangentBundle) = x.primal +@inline primal(z::ZeroTangent) = ZeroTangent() -first_partial(x) = partial(x, 1) +@inline first_partial(x) = partial(x, 1) shuffle_down(b::UniformBundle{N, B, U}) where {N, B, U} = UniformBundle{N-1}(UniformBundle{1, B}(b.primal, b.tangent.val), From a8224ddb691f4ab1369edda0ef4811eba2358784 Mon Sep 17 00:00:00 2001 From: Frames White Date: Fri, 3 May 2024 20:43:38 +0800 Subject: [PATCH 2/2] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1e682148..96465444 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Diffractor" uuid = "9f5e2b26-1114-432f-b630-d3fe2085c51c" authors = ["Keno Fischer and contributors"] -version = "0.2.8" +version = "0.2.9" [deps] AbstractDifferentiation = "c29ec348-61ec-40c8-8164-b8c60e9d9f3d"