FluxML / IRTools.jl

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

Simple recursive dynamo does not like sin function #52

Closed MasonProtter closed 4 years ago

MasonProtter commented 4 years ago
julia> using IRTools: @dynamo, IR, recurse!
[ Info: Precompiling IRTools [7869d1d1-7146-5819-86e3-90919afe41df]

julia> @dynamo function round_trip(args...)
           ir = IR(args...)
           ir == nothing && return
           recurse!(ir)
           return ir
       end

julia> round_trip() do 
           sin(1.0)
       end
ERROR: Error compiling @dynamo typeof(round_trip) on (typeof(invoke), typeof(evalpoly), Type{Tuple{Any,Tuple}}, Float64, Tuple{Float64,Float64,Float64}):                                                                                                           
type Nothing has no field code
Stacktrace:
 [1] getproperty(::Nothing, ::Symbol) at ./Base.jl:33
 [2] meta(::Type{T} where T; world::UInt64) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/reflection.jl:117
 [3] invoke_meta(::Type{T} where T; world::UInt64) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/reflection.jl:135
 [4] meta(::Type{T} where T; world::UInt64) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/reflection.jl:102
 [5] meta(::Type{T} where T) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/reflection.jl:101
 [6] IRTools.Inner.IR(::Type{T} where T, ::Vararg{Type{T} where T,N} where N; slots::Bool, prune::Bool) at /home/mason/.julia/packages/IRTools/DXHt2/src/ir/wrap.jl:209
 [7] IRTools.Inner.IR(::Type{T} where T, ::Vararg{Type{T} where T,N} where N) at /home/mason/.julia/packages/IRTools/DXHt2/src/ir/wrap.jl:209
 [8] macro expansion at ./REPL[3]:2 [inlined]
 [9] transform(::Type{typeof(round_trip)}, ::Type{T} where T, ::Vararg{Type{T} where T,N} where N) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/dynamo.jl:122
 [10] dynamo(::Dict{Any,Any}, ::Type{T} where T, ::Type{T} where T, ::Vararg{Type{T} where T,N} where N) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/dynamo.jl:62
 [11] #s15#7(::Any, ::Any) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/dynamo.jl:114
 [12] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:526
 [13] cos_kernel at ./special/trig.jl:140 [inlined]
 [14] sin at ./special/trig.jl:46 [inlined]
 [15] round_trip(::typeof(sin), ::Float64) at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/dynamo.jl:0
 [16] #9 at ./REPL[4]:2 [inlined]
 [17] round_trip(::var"#9#10") at /home/mason/.julia/packages/IRTools/DXHt2/src/reflection/dynamo.jl:0
 [18] top-level scope at REPL[4]:1
 [19] eval(::Module, ::Any) at ./boot.jl:331
 [20] eval_user_input(::Any, ::REPL.REPLBackend) at /home/mason/julia/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [21] run_backend(::REPL.REPLBackend) at /home/mason/.julia/packages/Revise/C272c/src/Revise.jl:1075
 [22] top-level scope at none:0

(@v1.4) pkg> st IRTools
Status `~/.julia/environments/v1.4/Project.toml`
  [7869d1d1] IRTools v0.3.1 #master (https://github.com/MikeInnes/IRTools.jl.git)

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 5 2600 Six-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, znver1)
Environment:
  JULIA_NUM_THREADS = 6

Reading the error thrown, I thought maybe this had to do with the useage of invoke in the new @evalpoly but it seems to not mind in other contexts:

julia> round_trip() do
           @evalpoly(3.0, 1.0, 2.0, 3.0)
       end
34.0
MikeInnes commented 4 years ago

Fortunately just a small bug with invoke + generated functions; to get the right code you have to specialise on the input types, not the types used for method selection.