FluxML / IRTools.jl

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

MWE: functional(ir) throws with Julia 1.4.1 (but works with 1.5-DEV) #55

Open tkf opened 4 years ago

tkf commented 4 years ago
using IRTools
using IRTools: @dynamo, IR, functional

@dynamo function cpsify(f, args...)
    ir = IR(f, args...)
    ir === nothing && return :(f(args...))
    return functional(ir)
end

return_false() = false

function demo(xs)
    for x in xs
        return_false() && return
    end
end

cpsify(demo, 1:1)

throws

ERROR: Error compiling @dynamo typeof(cpsify) on (typeof(demo), UnitRange{Int64}):
KeyError: key 2 not found
Stacktrace:
 [1] getindex at ./dict.jl:477 [inlined]
 [2] (::IRTools.Inner.var"#brfunc#198"{Dict{Any,Any}})(::IRTools.Inner.Branch) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:41
 [3] functionalbranches!(::IRTools.Inner.IR, ::IRTools.Inner.Pipe, ::Dict{Any,Any}) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:43
 [4] _functional(::IRTools.Inner.IR, ::Pair{Int64,Any}, ::Array{Any,1}, ::Dict{Any,Any}) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:66
 [5] _functional(::IRTools.Inner.IR, ::Pair{Int64,Any}, ::Array{Any,1}) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:50
 [6] _functional(::IRTools.Inner.IR, ::Pair{Int64,Any}, ::Array{Any,1}, ::Dict{Any,Any}) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:62
 [7] _functional(::IRTools.Inner.IR, ::Pair{Int64,Any}) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:50
 [8] functional(::IRTools.Inner.IR) at /home/takafumi/.julia/dev/IRTools/src/passes/cps.jl:70
 [9] macro expansion at ./REPL[3]:4 [inlined]
 [10] transform(::Type{typeof(cpsify)}, ::Type{T} where T, ::Type{T} where T) at /home/takafumi/.julia/dev/IRTools/src/reflection/dynamo.jl:122
 [11] dynamo(::Dict{Any,Any}, ::Type{T} where T, ::Type{T} where T, ::Vararg{Type{T} where T,N} where N) at /home/takafumi/.julia/dev/IRTools/src/reflection/dynamo.jl:62
 [12] #s15#9(::Any, ::Any) at /home/takafumi/.julia/dev/IRTools/src/reflection/dynamo.jl:114
 [13] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:526
 [14] top-level scope at REPL[6]:1

in Julia 1.3.1 and 1.4.1 but not in 1.5.0-DEV.683.

I checked this with IRTools v0.3.2 6d227c0edb828b7c761c97fe899dd33c03e69b56