How to debug inlining fails?

I have a trait based system in LazyArrays.jl that isn’t inlining, which seems to be breaking type inference. Are there any tips for debugging why this is?

Sorry for the non-MWE but the code is below. For some reason @inferred _broadcastarray2broadcasted(a) fails but @inferred _broadcastarray2broadcasted(MemoryLayout(a), a) is fine, even though I’ve just copy-and-pasted the method definition.

The relevant lines are:

@inline _broadcastarray2broadcasted(lay::BroadcastLayout, a) = broadcasted(call(lay, a), map(_broadcastarray2broadcasted, arguments(lay, a))...)
@inline _broadcastarray2broadcasted(lay::BroadcastLayout, a::BroadcastArray) = broadcasted(call(lay, a), map(_broadcastarray2broadcasted, arguments(lay, a))...)
@inline _broadcastarray2broadcasted(_, a) = a
@inline _broadcastarray2broadcasted(lay, a::BroadcastArray) = error("Overload LazyArrays._broadcastarray2broadcasted(::$(lay), _)")
@inline _broadcastarray2broadcasted(::DualLayout{ML}, a) where ML = _broadcastarray2broadcasted(ML(), a)
@inline _broadcastarray2broadcasted(a) = _broadcastarray2broadcasted(MemoryLayout(a), a)
1 Like

Julia master has Base.print_statement_costs, maybe that will help. See also https://docs.julialang.org/en/v1.6-dev/devdocs/inference/#The-inlining-algorithm-(inline_worthy)

4 Likes