Suppose I’ve defined a data type in Julia with its own call operator.
struct Adder x::Int end @noinline function (a::Adder)(y::Int) a.x + y end
How do I refer to the call operator I’ve just defined as a function? For example, I might want to check what sort of native code it compiles down to. However,
code_native(Adder, (Int,)) gives me the code for the
Adder constructor, while
code_native(Adder, (Adder, Int)) tells me there’s “no unique matching method found for the specified argument types.” What I really want to say is
code_native((a, x) -> a(x), (Adder, Int)), but this adds an additional level of indirection:
julia> code_native((a, x) -> a(x), (Adder, Int), syntax=:intel) .text ; ┌ @ In:1 within `#15' push rbp mov rbp, rsp sub rsp, 32 movabs rax, offset Adder call rax add rsp, 32 pop rbp ret nop word ptr [rax + rax] ; └
Of course, this could be fixed by marking
@inline function (a::Adder)(y::Int), but sometimes I define very long call operators for which this is wasteful.