FluxML / IRTools.jl

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

Fails to build codeinfo from an IR of function with `try/catch` control flow #34

Closed aviatesk closed 4 years ago

aviatesk commented 4 years ago

MRE:

using IRTools
using IRTools: evalir
function trycatch()
  try
  catch _
  end
end
ir = @code_ir trycatch()
evalir(ir, trycatch)
Error:

    BoundsError: attempt to access 2-element Array{Core.Compiler.BasicBlock,1} at index [4]
    getindex(::Array{Core.Compiler.BasicBlock,1}, ::Int64) at array.jl:744
    replace_code_newstyle!(::Core.CodeInfo, ::Core.Compiler.IRCode, ::Int64) at legacy.jl:91
    update!(::Core.CodeInfo, ::Core.Compiler.IRCode) at utils.jl:95
    update! at utils.jl:103 [inlined]
    build_codeinfo(::IRTools.Inner.IR) at eval.jl:13
    #s148#251(::Any, ::Any) at eval.jl:18
    (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at boot.jl:524
    #invokelatest#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(Base.invokelatest), ::Any, ::Any, ::Vararg{Any,N} where N) at essentials.jl:709
    invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at essentials.jl:708
    evalir(::Module, ::IRTools.Inner.IR, ::Function, ::Vararg{Any,N} where N) at eval.jl:24
    evalir(::IRTools.Inner.IR, ::Function) at eval.jl:25
    top-level scope at runtests.jl:40
  

And obviously, this also happens when hooking a dynamo on a function with try/catch block.

SimonDanisch commented 4 years ago

Seems to be resolved in: https://github.com/MikeInnes/IRTools.jl/pull/36

MikeInnes commented 4 years ago

Ah, didn't realise we had an issue open for this. Yes, this should be resolved, let me know if not.