FluxML / IRTools.jl

Mike's Little Intermediate Representation
MIT License
111 stars 35 forks source link

Dispatch doesn't work #41

Open MikeInnes opened 4 years ago

MikeInnes commented 4 years ago

We can't define a dynamo just for a subset of methods.

julia> @dynamo function foo(f, x::Real)
         IR(f, x)
       end

julia> foo(sin, 0.5)
ERROR: Error compiling @dynamo typeof(foo) on (typeof(sin), Float64):
MethodError: no method matching transform(::Type{typeof(foo)}, ::Type{typeof(sin)}, ::Type{Float64})

This is doubly-wrong because (a) the generated function entry point has no type restrictions at all and (b) the transform inner function does have them, but they need to be lifted to accept an equivalent set of types rather than values (exactly like a generated function).

MikeInnes commented 4 years ago

42 address the second part of this. The first part is a bit tricky because we currently want the generated function to have a single args... slot so that the slots in the IR can easily be mapped to that original slot. I'm not sure we can express the right type signature directly there, so we might just have to settle for a more complicated mapping.