Working on a pattern for interface-based dispatch that uses code-generation. Is this efficient?

I don’t think so. This is how an inferred check looks like:

julia> hh(a) = isimmutable(a) ? 1 : 2.0
hh (generic function with 1 method)

julia> @code_warntype hh(1)
Body::Int64
1 ─     return 1

julia> @code_warntype hh(:(1+1))
Body::Float64
1 ─     goto #3 if not false
2 ─     nothing
3 ┄     return 2.0

this is applicable:

julia> ff(fn) = applicable(fn, 1) ? 1 : 2.0
ff (generic function with 1 method)

julia> @code_warntype ff(sin)
Body::Union{Float64, Int64}
1 ─ %1 = (Main.applicable)(fn, 1)::Bool
└──      goto #3 if not %1
2 ─      return 1
3 ─      return 2.0

so it is not inferred.

2 Likes