Ghost.jl icon indicating copy to clipboard operation
Ghost.jl copied to clipboard

Exception on Tracing

Open mharradon opened this issue 2 years ago • 2 comments

On main branch:

julia> using Ghost: trace, play!, compile

julia> function loop6(n)
           a = 0
           i = 1
           while true
               a += i
               if a > n
                   break
               end
           end
           return a
       end
loop6 (generic function with 1 method)

julia> v, tape = trace(loop6, 3)
ERROR: Error compiling @dynamo Ghost.IRTracer on (typeof(loop6), Int64):
type Bool has no field id
Stacktrace:
  [1] getproperty(x::Bool, f::Symbol)
    @ Base ./Base.jl:33
  [2] loop_condition_ir_id(block::IRTools.Inner.Block)
    @ Ghost ~/Ghost.jl/src/trace.jl:276
  [3] trace_loops!(ir::IRTools.Inner.IR)
    @ Ghost ~/Ghost.jl/src/trace.jl:561
  [4] macro expansion
    @ ~/Ghost.jl/src/trace.jl:631 [inlined]
  [5] transform(::Type{Ghost.IRTracer}, ::Type, ::Vararg{Type, N} where N)
    @ Ghost ~/.julia/packages/IRTools/isLV2/src/reflection/dynamo.jl:122
  [6] dynamo(::Any, ::Any, ::Any, ::Vararg{Any, N} where N)
    @ IRTools.Inner ~/.julia/packages/IRTools/isLV2/src/reflection/dynamo.jl:62
  [7] #s22#77
    @ ~/.julia/packages/IRTools/isLV2/src/reflection/dynamo.jl:114 [inlined]
  [8] var"#s22#77"(t::Any, args::Any)
    @ Ghost ./none:0
  [9] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any, N} where N)
    @ Core ./boot.jl:571
 [10] trace(f::Function, args::Int64; is_primitive::Function, primitives::Nothing, ctx::Dict{Any, Any})
    @ Ghost ~/Ghost.jl/src/trace.jl:661
 [11] trace(f::Function, args::Int64)
    @ Ghost ~/Ghost.jl/src/trace.jl:651
 [12] top-level scope
    @ REPL[7]:1

Commented out test has been added to this branch: https://github.com/dfdx/Ghost.jl/pull/24/files#diff-9cfffbdde1240d3bbc48e12d9b70b84e4e53674af55fb22fabc01f465af7991cR235

mharradon avatar Dec 02 '21 05:12 mharradon

This is because https://github.com/dfdx/Ghost.jl/blob/13c283a1e92a533686eff97736142ea7f3741901/src/trace.jl#L290-L293 branches can have Any conditions: https://github.com/FluxML/IRTools.jl/blob/948773227955e29a6caae44d109e8be56db6e605/src/ir/ir.jl#L39-L43

I suspect a false or true propagates to the condition.

femtomc avatar Dec 27 '21 20:12 femtomc

Yeah, looks like while true breaks this function. Intuitively, we need to return nothing in this case because there's no block designating the condition, but we need to test it thoroughly. I'm putting it into my backlog, please ping me if this is something blocking you.

dfdx avatar Dec 27 '21 23:12 dfdx