Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested if-else-end "hoisted" flips causes IRTools.Inner branch error #137

Open
mattxwang opened this issue May 12, 2023 · 1 comment
Open

Comments

@mattxwang
Copy link

I ran into this problem when doing HW2 for 267A (and I feel like it's now far enough from the HW to post!).

Consider this minimum-reproducible example:

using Dice

function same_door(door)
  f = flip(0.5)
  if door == DistUInt8(0)
    if f DistUInt8(0) else DistUInt8(1) end
  else
    if f DistUInt8(1) else DistUInt8(0) end
  end
end

door = discrete(DistUInt8,[1/2, 1/2])

println(pr(@dice(same_door(door))))

This produces the following error:

ERROR: LoadError: Error compiling @dynamo Dice.DiceDyna on (typeof(same_door), DistUInt8):
AssertionError: length(branches(bl)) == 2
Stacktrace:
  [1] functionalbranches!(bl::Any, pr::Any, labels::Any)
    @ IRTools.Inner ~/.julia/packages/IRTools/jcpZw/src/passes/cps.jl:36
  [2] _functional(ir::Any, tree::Any, vars::Any, cs::Any)
    @ IRTools.Inner ~/.julia/packages/IRTools/jcpZw/src/passes/cps.jl:66
  [3] _functional(ir::Any, tree::Any)
    @ IRTools.Inner ~/.julia/packages/IRTools/jcpZw/src/passes/cps.jl:50
  [4] functional(ir::Any)
    @ IRTools.Inner ~/.julia/packages/IRTools/jcpZw/src/passes/cps.jl:70
  [5] macro expansion
    @ ~/.julia/packages/Dice/OfImS/src/dsl.jl:53 [inlined]
  [6] macro expansion
    @ ./timing.jl:463 [inlined]
  [7] macro expansion
    @ ~/.julia/packages/Dice/OfImS/src/dsl.jl:50 [inlined]
  [8] transform(::Type{Dice.DiceDyna}, ::Type, ::Vararg{Type})
    @ Dice ~/.julia/packages/IRTools/jcpZw/src/reflection/dynamo.jl:197
  [9] dynamo(::Any, ::Any, ::Any, ::Any, ::Vararg{Any})
    @ IRTools.Inner ~/.julia/packages/IRTools/jcpZw/src/reflection/dynamo.jl:79
 [10] #s61#154
    @ ~/.julia/packages/IRTools/jcpZw/src/reflection/dynamo.jl:186 [inlined]
 [11] var"#s61#154"(dyna::Any, args::Any)
    @ Dice ./none:0
 [12] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core ./boot.jl:582
 [13] DiceDyna
    @ ~/.julia/packages/Dice/OfImS/src/dsl.jl:28 [inlined]
 [14] (::Dice.DiceDyna)(args::var"#17#18")
    @ Dice ~/.julia/packages/IRTools/jcpZw/src/reflection/dynamo.jl:0
 [15] dice(f::Function)
    @ Dice ~/.julia/packages/Dice/OfImS/src/dsl.jl:20
 [16] top-level scope
    @ ~/.julia/packages/Dice/OfImS/src/dsl.jl:27
 [17] include(fname::String)
    @ Base.MainInclude ./client.jl:476
 [18] top-level scope
    @ REPL[5]:1
in expression starting at /Users/matt/Dice.jl/examples/mini.jl:14

However, if I replace the inner if-else-end with the ifelse() function, I don't encounter the error:

using Dice

function same_door(door)
  f = flip(0.5)
  if door == DistUInt8(0)
    ifelse(f, DistUInt8(0), DistUInt8(1))
  else
    ifelse(f, DistUInt8(1), DistUInt8(0))
  end
end

door = discrete(DistUInt8,[1/2, 1/2])

println(pr(@dice(same_door(door))))
DataStructures.DefaultDict{Any, Any, Float64}(0 => 0.5, 1 => 0.5)

other reproducibility details

I'm running:

  • macOS 13.3.1 on an M1 Mac Pro
    • to resolve the "closures not supported on this platform", I'm running Julia with Rosetta
  • Julia 1.8
  • f9956fe
@guyvdbroeck
Copy link
Member

I think it is this known bug: FluxML/IRTools.jl#100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants