Skip to content

functional() throws error for a break statement #129

@PoorvaGarg

Description

@PoorvaGarg

Using functional() on a function that consist of a loop and a break statement throws a KeyError. I have included a minimal example below. I am using Julia version 1.10.5. This bug further causes issues in using Julia library functions like reduce as they use functions within Julia that have a loop with a break statement.

julia> using IRTools: @code_ir, functional

julia> function f()
           while true break end
       end
f (generic function with 1 method)

julia> functional(@code_ir f())
ERROR: KeyError: key 2 not found
Stacktrace:
 [1] getindex(h::Dict{Any, Any}, key::Int64)
   @ Base ./dict.jl:498
 [2] functionalbranches!(bl::Any, pr::Any, labels::Any)
   @ IRTools.Inner ~/Desktop/IRTools.jl/src/passes/cps.jl:31
 [3] _functional(ir::Any, tree::Any, vars::Any, cs::Any)
   @ IRTools.Inner ~/Desktop/IRTools.jl/src/passes/cps.jl:66
 [4] _functional
   @ ~/Desktop/IRTools.jl/src/passes/cps.jl:50 [inlined]
 [5] _functional(ir::Any, tree::Any, vars::Any, cs::Any)
   @ IRTools.Inner ~/Desktop/IRTools.jl/src/passes/cps.jl:62
 [6] _functional
   @ ~/Desktop/IRTools.jl/src/passes/cps.jl:50 [inlined]
 [7] functional(ir::Any)
   @ IRTools.Inner ~/Desktop/IRTools.jl/src/passes/cps.jl:70
 [8] top-level scope
   @ REPL[3]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions