Skip to content

Commit

Permalink
stage1: Mark partial and primal helpers as @inline
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
topolarity committed May 1, 2024
1 parent d0b3e3e commit b883867
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/stage1/forward.jl
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 5 in src/stage1/forward.jl

View check run for this annotation

Codecov / codecov/patch

src/stage1/forward.jl#L5

Added line #L5 was not covered by tests


primal(x::AbstractTangentBundle) = x.primal
primal(z::ZeroTangent) = ZeroTangent()
@inline primal(x::AbstractTangentBundle) = x.primal
@inline primal(z::ZeroTangent) = ZeroTangent()

Check warning on line 9 in src/stage1/forward.jl

View check run for this annotation

Codecov / codecov/patch

src/stage1/forward.jl#L9

Added line #L9 was not covered by tests

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),
Expand Down

0 comments on commit b883867

Please sign in to comment.