@_inline_meta

I was going through some examples of generated functions in StaticArrays and I came across the following code snippet with the seemingly unearthly syntax of @_inline_meta and the 2 return statements. I would appreciate an earthly explanation for that and why it is necessary, thank you!

@generated function _A_mul_B(Sa::Size{sa}, Sb::Size{sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticMatrix{<:Any, <:Any, Tb}) where {sa, sb, Ta, Tb}
    # Heuristic choice for amount of codegen
    if sa[1]*sa[2]*sb[2] <= 8*8*8
        return quote
            @_inline_meta
            return A_mul_B_unrolled(Sa, Sb, a, b)
        end
    elseif sa[1] <= 14 && sa[2] <= 14 && sb[2] <= 14
        return quote
            @_inline_meta
            return A_mul_B_unrolled_chunks(Sa, Sb, a, b)
        end
    else
        return quote
            @_inline_meta
            return A_mul_B_loop(Sa, Sb, a, b)
        end
    end
end
1 Like

The generated function returns the expression of the functions it generates (which includes a return statement).

The inline meta stuff is the same as putting @inline on the function being generated (but since there is no actual function to put the macro on on you need to directly enter the meta-node into the expression).

10 Likes

Cool thanks.