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

assertion failure for optimize=false #5

Closed
jrevels opened this issue Dec 8, 2018 · 2 comments
Closed

assertion failure for optimize=false #5

jrevels opened this issue Dec 8, 2018 · 2 comments

Comments

@jrevels
Copy link
Collaborator

jrevels commented Dec 8, 2018

julia> using Cassette, Cthulhu

julia> Cassette.@context NoOp
Cassette.Context{nametype(NoOp),M,P,T,B} where B<:Union{Nothing, IdDict{Module,Dict{Symbol,BindingMeta}}} where P<:Cassette.AbstractPass where T<:Union{Nothing, Tag} where M

julia> f(x) = sin(x)
f (generic function with 1 method)

julia> f2(x) = Cassette.overdub(NoOp(), f::typeof(f), x)
f2 (generic function with 1 method)

julia> f3(x) = Cassette.overdub(NoOp(), f2::typeof(f2), x)
f3 (generic function with 1 method)

julia> @descend optimize=false f3(1)

│ ─ %-1 = invoke f3(::Int64)::Any
CodeInfo(
1%1 = Cassette.overdub::Const(overdub, false)
│   %2 = (Main.NoOp)()::Const(Context{nametype(NoOp),Nothing,NoPass,Nothing,Nothing}(nametype(NoOp)(), nothing, NoPass(), nothing, nothing), false)
│   %3 = (Main.typeof)(Main.f2)::Const(typeof(f2), false)
│   %4 = (Core.typeassert)(Main.f2, %3)::Const(f2, false)
│   %5 = (%1)(%2, %4, x)::Any
└──      return %5
) => Any

In `f3` select a call to descend into or  to ascend. [q] to quit.
   %2 = invoke Cassette.Context{nametype(NoOp),M,P,T,B} where B<:Union{Nothing, IdDict{Module,Dict{Symbol,BindingMeta}}} where P<:Cassette.AbstractPass where T<:Union{Nothing, Tag} where M()::Core.Compiler.Const(Cassette.Context{namety..%5 = invoke Cassette.overdub(::Cassette.Context{nametype(NoOp),Nothing,Cassette.NoPass,Nothing,Nothing},::typeof(f2),::Int64)::Any
   
ERROR: AssertionError: arg.head === :static_parameter
Stacktrace:
 [1] find_type(::Core.CodeInfo, ::Type, ::Expr) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:121
 [2] find_type(::Core.CodeInfo, ::DataType, ::Core.SlotNumber) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:143
 [3] (::getfield(Cthulhu, Symbol("##4#6")){Core.CodeInfo,DataType})(::Core.SlotNumber) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:187
 [4] collect_to!(::Array{DataType,1}, ::Base.Generator{Array{Any,1},getfield(Cthulhu, Symbol("##4#6")){Core.CodeInfo,DataType}}, ::Int64, ::Int64) at ./generator.jl:47
 [5] collect_to_with_first!(::Array{DataType,1}, ::Type, ::Base.Generator{Array{Any,1},getfield(Cthulhu, Symbol("##4#6")){Core.CodeInfo,DataType}}, ::Int64) at ./array.jl:627
 [6] _collect(::Array{Any,1}, ::Base.Generator{Array{Any,1},getfield(Cthulhu, Symbol("##4#6")){Core.CodeInfo,DataType}}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at ./array.jl:621
 [7] collect_similar(::Array{Any,1}, ::Base.Generator{Array{Any,1},getfield(Cthulhu, Symbol("##4#6")){Core.CodeInfo,DataType}}) at ./array.jl:545
 [8] map(::Function, ::Array{Any,1}) at ./abstractarray.jl:2014
 [9] #find_callsites#3(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:optimize,),Tuple{Bool}}}, ::Function, ::Core.CodeInfo, ::Type) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:187
 [10] (::getfield(Cthulhu, Symbol("#kw##find_callsites")))(::NamedTuple{(:optimize,),Tuple{Bool}}, ::typeof(Cthulhu.find_callsites), ::Core.CodeInfo, ::Type) at ./none:0
 [11] #_descend#8(::Bool, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:optimize,),Tuple{Bool}}}, ::Function, ::Any, ::Any) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:229
 [12] #_descend at ./none:0 [inlined]
 [13] #_descend#8(::Bool, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:optimize,),Tuple{Bool}}}, ::Function, ::Any, ::Any) at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:246
 [14] #_descend_with_error_handling#2(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple{(:iswarn, :optimize),Tuple{Bool,Bool}}}, ::Function, ::Function, ::Any) at ./none:0
 [15] #_descend_with_error_handling at ./none:0 [inlined]
 [16] #descend_code_typed#1 at /Users/jarrettrevels/.julia/dev/Cthulhu/src/Cthulhu.jl:80 [inlined]
 [17] (::getfield(Cthulhu, Symbol("#kw##descend_code_typed")))(::NamedTuple{(:optimize,),Tuple{Bool}}, ::typeof(descend_code_typed), ::Function, ::Type) at ./none:0
 [18] top-level scope at none:0

Note also that I had to put ::typeof(f2) etc. in there; if I leave those annotations out, Cthulhu thinks that those arguments are ::GlobalRef in the invoke signature (which is obviously bonkers)

julia> versioninfo()
Julia Version 1.1.0-DEV.772
Commit 3dd678f646 (2018-11-30 22:20 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin17.5.0)
  CPU: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

holy moly this package is amazing for debugging the inference cache

@vchuravy
Copy link
Member

Different reproducer:

 12 f(A, B, C, D) = A .+ B .+ C .+ D
 11 A = rand(256, 256, 1, 10);
 10 B = rand(256, 256, 1, 10);
  9 C = rand(256, 256, 1, 10);
  8 D = rand(256, 256, 1, 10);
  7 
  6 # @code_typed optimize = false debuginfo = :source f(A, B, C, D)
  5 # @code_typed optimize = true debuginfo = :source f(A, B, C, D)
  4 
  3 using Base.Broadcast: broadcasted, materialize
  2 
  1 f_bc(A, B, C, D) = broadcasted(+, broadcasted(+, broadcasted(+, A, B), C), D)

@descend optimize=false f_bc(A, B, C, D)

@vchuravy
Copy link
Member

vchuravy commented Feb 5, 2019

Can no longer reproduce this. I suspect #10 fixed this.

@vchuravy vchuravy closed this as completed Feb 5, 2019
aviatesk added a commit that referenced this issue Nov 24, 2021
…rpreter` params

```julia
julia> function summer(f, xs)
           s = zero(eltype(xs))
           for x in xs
               s += f(x)
           end
           s
       end
summer (generic function with 1 method)

julia> @Descend interp=CC.NativeInterpreter(; opt_params=CC.OptimizationParams(; inline_nonleaf_penalty=10)) inline_cost=true summer(sin, Number[1,2,3])
summer(f, xs) in Main at REPL[9]:1
│ ─ %-1  = invoke summer(::typeof(sin),::Vector{Number})::Any
3 1 ──  1 %1  = Base.bitcast(UInt64, 1)::UInt64        │╻╷╷   iterate
  │     1 %2  = Base.sub_int(%1, 0x0000000000000001)::UInt64   iterate
  │     4 %3  = Base.arraylen(_3)::Int64               │││╻     length
  │     1 %4  = Base.sle_int(0, %3)::Bool              ││││╻╷    >=
  │     1 %5  = Base.bitcast(UInt64, %3)::UInt64       │││││╻     reinterpret
  │     1 %6  = Base.ult_int(%2, %5)::Bool             ││││╻     <
  │     1 %7  = Base.and_int(%4, %6)::Bool             ││││╻     &
  └───  0       goto #3 if not %7                      │││
  2 ──  4 %9  = Base.arrayref(false, _3, 1)::Number    │││╻     getindex
  │     1 %10 = Base.add_int(1, 1)::Int64              │││╻     +
  └───  0       goto #4                                │││
  3 ──  0       Base.nothing::Core.Const(nothing)      │││
  └───  0       goto #4                                │││
  4 ┄─  0 %14 = φ (#2 => false, #3 => true)::Bool      ││
  │     0 %15 = φ (#2 => %9)::Number                   ││
  │     0 %16 = φ (#2 => %10)::Int64                   ││
  └───  0       goto #5                                ││
  5 ──  0 %18 = Base.not_int(%14)::Bool                │
  └───  0       goto #11 if not %18                    │
  6 ┄─  0 %20 = φ (#5 => %15, #10 => %38)::Number      │
  │     0 %21 = φ (#5 => %16, #10 => %39)::Int64       │
  │     0 %22 = φ (#5 => 0, #10 => %24)::Any           │
4 │    10 %23 = (_2)(%20)::Any                         │
  │    10 %24 = (%22 + %23)::Any                       │
5 │     1 %25 = Base.bitcast(UInt64, %21)::UInt64      │╻╷    iterate
  │     1 %26 = Base.sub_int(%25, 0x0000000000000001)::UInt64  -
  │     4 %27 = Base.arraylen(_3)::Int64               ││╻     length
  │     1 %28 = Base.sle_int(0, %27)::Bool             │││╻╷    >=
  │     1 %29 = Base.bitcast(UInt64, %27)::UInt64      ││││╻     reinterpret
  │     1 %30 = Base.ult_int(%26, %29)::Bool           │││╻     <
  │     1 %31 = Base.and_int(%28, %30)::Bool           │││╻     &
  └───  0       goto #8 if not %31                     ││
  7 ──  4 %33 = Base.arrayref(false, _3, %21)::Number  ││╻     getindex
  │     1 %34 = Base.add_int(%21, 1)::Int64            ││╻     +
  └───  0       goto #9                                ││
  8 ──  0       Base.nothing::Core.Const(nothing)      ││
  └───  0       goto #9                                ││
  9 ┄─  0 %38 = φ (#7 => %33)::Number                  │
  │     0 %39 = φ (#7 => %34)::Int64                   │
  │     0 %40 = φ (#7 => false, #8 => true)::Bool      │
  │     0 %41 = Base.not_int(%40)::Bool                │
  └───  0       goto #11 if not %41                    │
  10 ─ 40       goto #6                                │
6 11 ┄  0 %44 = φ (#9 => %24, #5 => 0)::Any            │
  └───  0       return %44                             │
Select a call to descend into or ↩ to ascend. [q]uit. [b]ookmark.
Toggles: [o]ptimize, [w]arn, [h]ide type-stable statements, [d]ebuginfo, [r]emarks, [i]nlining costs, [t]ype annotations, [s]yntax highlight for Source/LLVM/Native.
Show: [S]ource code, [A]ST, [T]yped code, [L]LVM IR, [N]ative code
Actions: [E]dit source code, [R]evise and redisplay
Advanced: dump [P]arams cache.
 • ↩
```
aviatesk added a commit that referenced this issue Nov 24, 2021
…rpreter` params (#251)

```julia
julia> function summer(f, xs)
           s = zero(eltype(xs))
           for x in xs
               s += f(x)
           end
           s
       end
summer (generic function with 1 method)

julia> @Descend interp=CC.NativeInterpreter(; opt_params=CC.OptimizationParams(; inline_nonleaf_penalty=10)) inline_cost=true summer(sin, Number[1,2,3])
summer(f, xs) in Main at REPL[9]:1
│ ─ %-1  = invoke summer(::typeof(sin),::Vector{Number})::Any
3 1 ──  1 %1  = Base.bitcast(UInt64, 1)::UInt64        │╻╷╷   iterate
  │     1 %2  = Base.sub_int(%1, 0x0000000000000001)::UInt64   iterate
  │     4 %3  = Base.arraylen(_3)::Int64               │││╻     length
  │     1 %4  = Base.sle_int(0, %3)::Bool              ││││╻╷    >=
  │     1 %5  = Base.bitcast(UInt64, %3)::UInt64       │││││╻     reinterpret
  │     1 %6  = Base.ult_int(%2, %5)::Bool             ││││╻     <
  │     1 %7  = Base.and_int(%4, %6)::Bool             ││││╻     &
  └───  0       goto #3 if not %7                      │││
  2 ──  4 %9  = Base.arrayref(false, _3, 1)::Number    │││╻     getindex
  │     1 %10 = Base.add_int(1, 1)::Int64              │││╻     +
  └───  0       goto #4                                │││
  3 ──  0       Base.nothing::Core.Const(nothing)      │││
  └───  0       goto #4                                │││
  4 ┄─  0 %14 = φ (#2 => false, #3 => true)::Bool      ││
  │     0 %15 = φ (#2 => %9)::Number                   ││
  │     0 %16 = φ (#2 => %10)::Int64                   ││
  └───  0       goto #5                                ││
  5 ──  0 %18 = Base.not_int(%14)::Bool                │
  └───  0       goto #11 if not %18                    │
  6 ┄─  0 %20 = φ (#5 => %15, #10 => %38)::Number      │
  │     0 %21 = φ (#5 => %16, #10 => %39)::Int64       │
  │     0 %22 = φ (#5 => 0, #10 => %24)::Any           │
4 │    10 %23 = (_2)(%20)::Any                         │
  │    10 %24 = (%22 + %23)::Any                       │
5 │     1 %25 = Base.bitcast(UInt64, %21)::UInt64      │╻╷    iterate
  │     1 %26 = Base.sub_int(%25, 0x0000000000000001)::UInt64  -
  │     4 %27 = Base.arraylen(_3)::Int64               ││╻     length
  │     1 %28 = Base.sle_int(0, %27)::Bool             │││╻╷    >=
  │     1 %29 = Base.bitcast(UInt64, %27)::UInt64      ││││╻     reinterpret
  │     1 %30 = Base.ult_int(%26, %29)::Bool           │││╻     <
  │     1 %31 = Base.and_int(%28, %30)::Bool           │││╻     &
  └───  0       goto #8 if not %31                     ││
  7 ──  4 %33 = Base.arrayref(false, _3, %21)::Number  ││╻     getindex
  │     1 %34 = Base.add_int(%21, 1)::Int64            ││╻     +
  └───  0       goto #9                                ││
  8 ──  0       Base.nothing::Core.Const(nothing)      ││
  └───  0       goto #9                                ││
  9 ┄─  0 %38 = φ (#7 => %33)::Number                  │
  │     0 %39 = φ (#7 => %34)::Int64                   │
  │     0 %40 = φ (#7 => false, #8 => true)::Bool      │
  │     0 %41 = Base.not_int(%40)::Bool                │
  └───  0       goto #11 if not %41                    │
  10 ─ 40       goto #6                                │
6 11 ┄  0 %44 = φ (#9 => %24, #5 => 0)::Any            │
  └───  0       return %44                             │
Select a call to descend into or ↩ to ascend. [q]uit. [b]ookmark.
Toggles: [o]ptimize, [w]arn, [h]ide type-stable statements, [d]ebuginfo, [r]emarks, [i]nlining costs, [t]ype annotations, [s]yntax highlight for Source/LLVM/Native.
Show: [S]ource code, [A]ST, [T]yped code, [L]LVM IR, [N]ative code
Actions: [E]dit source code, [R]evise and redisplay
Advanced: dump [P]arams cache.
 • ↩
```
This issue was closed.
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