Skip to content

Commit 1ee703f

Browse files
committed
Work around inference hang when inlining is off
1 parent a4492b0 commit 1ee703f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/core.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ reduced_indices0{N}(axs::Tuple{Vararg{Axis,N}}, region::Dims) =
306306

307307
@inline reduced_indices{Ax<:Axis}(axs::Tuple{Vararg{Axis}}, region::Type{Ax}) =
308308
_reduced_indices(reduced_axis, (), region, axs...)
309-
@inline reduced_indices(axs::Tuple{Vararg{Axis}}, region::Axis) =
310-
_reduced_indices(reduced_axis, (), region, axs...)
311309
@inline reduced_indices0{Ax<:Axis}(axs::Tuple{Vararg{Axis}}, region::Type{Ax}) =
312310
_reduced_indices(reduced_axis0, (), region, axs...)
311+
@inline reduced_indices(axs::Tuple{Vararg{Axis}}, region::Axis) =
312+
_reduced_indices(reduced_axis, (), region, axs...)
313313
@inline reduced_indices0(axs::Tuple{Vararg{Axis}}, region::Axis) =
314314
_reduced_indices(reduced_axis0, (), region, axs...)
315315

@@ -322,13 +322,22 @@ reduced_indices0(axs::Tuple{Vararg{Axis}}, region::Tuple) =
322322
reduced_indices0(axs::Tuple{Vararg{Axis}}, region::Tuple{Vararg{Axis}}) =
323323
reduced_indices0(reduced_indices0(axs, region[1]), tail(region))
324324

325-
@inline _reduced_indices{name}(f, out, chosen::Type{Axis{name}}, ax::Axis{name}, axs...) =
326-
_reduced_indices(f, (out..., f(ax)), chosen, axs...)
327-
@inline _reduced_indices{name}(f, out, chosen::Axis{name}, ax::Axis{name}, axs...) =
325+
@pure samesym{n1,n2}(::Type{Axis{n1}}, ::Type{Axis{n2}}) = Val{n1==n2}()
326+
samesym{n1,n2,T1,T2}(::Type{Axis{n1,T1}}, ::Type{Axis{n2,T2}}) = samesym(Axis{n1},Axis{n2})
327+
samesym{n1,n2}(::Type{Axis{n1}}, ::Axis{n2}) = samesym(Axis{n1}, Axis{n2})
328+
samesym{n1,n2}(::Axis{n1}, ::Type{Axis{n2}}) = samesym(Axis{n1}, Axis{n2})
329+
samesym{n1,n2}(::Axis{n1}, ::Axis{n2}) = samesym(Axis{n1}, Axis{n2})
330+
331+
@inline _reduced_indices{Ax<:Axis}(f, out, chosen::Type{Ax}, ax::Axis, axs...) =
332+
__reduced_indices(f, out, samesym(chosen, ax), chosen, ax, axs)
333+
@inline _reduced_indices(f, out, chosen::Axis, ax::Axis, axs...) =
334+
__reduced_indices(f, out, samesym(chosen, ax), chosen, ax, axs)
335+
_reduced_indices(f, out, chosen) = out
336+
337+
@inline __reduced_indices(f, out, ::Val{true}, chosen, ax, axs) =
328338
_reduced_indices(f, (out..., f(ax)), chosen, axs...)
329-
@inline _reduced_indices(f, out, chosen, ax::Axis, axs...) =
339+
@inline __reduced_indices(f, out, ::Val{false}, chosen, ax, axs) =
330340
_reduced_indices(f, (out..., ax), chosen, axs...)
331-
_reduced_indices(f, out, chosen) = out
332341

333342
reduced_axis(ax) = ax(oftype(ax.val, Base.OneTo(1)))
334343
reduced_axis0(ax) = ax(oftype(ax.val, length(ax.val) == 0 ? Base.OneTo(0) : Base.OneTo(1)))

test/core.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,15 @@ for C in (A, B)
222222
end
223223
C1t = @inferred(op(C, Axis{:y}))
224224
@test C1t == C1
225-
# Julia 0.5.x hangs in inference on the following tests when
226-
# inlining is off. We want this fixed for Julia 0.6.
227-
if VERSION > v"0.6.0-dev.1" || Base.JLOptions().can_inline==1
228-
C2t = @inferred(op(C, Axis{:x}))
229-
@test C2t == C2
230-
C12t = @inferred(op(C, (Axis{:y},Axis{:x})))
231-
@test C12t == C12
232-
C1t = @inferred(op(C, Axis{:y}()))
233-
@test C1t == C1
234-
C2t = @inferred(op(C, Axis{:x}()))
235-
@test C2t == C2
236-
C12t = @inferred(op(C, (Axis{:y}(),Axis{:x}())))
237-
@test C12t == C12
238-
end
225+
C2t = @inferred(op(C, Axis{:x}))
226+
@test C2t == C2
227+
C12t = @inferred(op(C, (Axis{:y},Axis{:x})))
228+
@test C12t == C12
229+
C1t = @inferred(op(C, Axis{:y}()))
230+
@test C1t == C1
231+
C2t = @inferred(op(C, Axis{:x}()))
232+
@test C2t == C2
233+
C12t = @inferred(op(C, (Axis{:y}(),Axis{:x}())))
234+
@test C12t == C12
239235
end
240236
end

0 commit comments

Comments
 (0)