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

Request @descend_code_warntype #3

Closed
YingboMa opened this issue Nov 30, 2018 · 0 comments
Closed

Request @descend_code_warntype #3

YingboMa opened this issue Nov 30, 2018 · 0 comments

Comments

@YingboMa
Copy link
Contributor

I think that having an analog of @code_warntype would be really nice.

@vchuravy vchuravy closed this as completed Dec 1, 2018
aviatesk added a commit that referenced this issue Nov 1, 2021
- improve `ReturnTypeCallInfo` printing (see the example below)
- don't error when trying to descend into a failed `return_type` site

> before
```julia
julia> only_ints(::Integer) = 1;

julia> descend(; optimize=false) do
           t1 = Base._return_type(only_ints, Tuple{Int})     # successful `return_type`
           t2 = Base._return_type(only_ints, Tuple{Float64}) # failed `return_type`
           t1, t2
       end
(::var"#3#4")() in Main at REPL[3]:2
Variables
  #self#::Core.Const(var"#3#4"())
  t2::Type{Union{}}
  t1::Type{Int64}

│ ─ %-1  = invoke #3()::Core.Const((Int64, Union{}))
    @ REPL[3]:2 within `#3`
1 ─ %1 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %2 = Core.apply_type(Main.Tuple, Main.Int)::Core.Const(Tuple{Int64})
│        (t1 = (%1)(Main.only_ints, %2))::Core.Const(Int64)
│   @ REPL[3]:3 within `#3`
│   %4 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %5 = Core.apply_type(Main.Tuple, Main.Float64)::Core.Const(Tuple{Float64})
│        (t2 = (%4)(Main.only_ints, %5))::Core.Const(Union{})
│   @ REPL[3]:4 within `#3`
│   %7 = Core.tuple(t1::Core.Const(Int64), t2::Core.Const(Union{}))::Core.Const((Int64, Union{}))
└──      return %7
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.
 • %3  = return_type < only_ints(::Int64)::Core.Const(Int64) >
   %6  = return_type < → return_type(::typeof(only_ints),::Type{Tuple{Float64}})::Core.Const(Union{}) >
   ↩
```

> this commit
```julia
julia> only_ints(::Integer) = 1;

julia> descend(; optimize=false) do
           t1 = Base._return_type(only_ints, Tuple{Int})     # successful `return_type`
           t2 = Base._return_type(only_ints, Tuple{Float64}) # failed `return_type`
           t1, t2
       end
(::var"#3#4")() in Main at REPL[3]:2
Variables
  #self#::Core.Const(var"#3#4"())
  t2::Type{Union{}}
  t1::Type{Int64}

│ ─ %-1  = invoke #3()::Core.Const((Int64, Union{}))
    @ REPL[3]:2 within `#3`
1 ─ %1 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %2 = Core.apply_type(Main.Tuple, Main.Int)::Core.Const(Tuple{Int64})
│        (t1 = (%1)(Main.only_ints, %2))::Core.Const(Int64)
│   @ REPL[3]:3 within `#3`
│   %4 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %5 = Core.apply_type(Main.Tuple, Main.Float64)::Core.Const(Tuple{Float64})
│        (t2 = (%4)(Main.only_ints, %5))::Core.Const(Union{})
│   @ REPL[3]:4 within `#3`
│   %7 = Core.tuple(t1::Core.Const(Int64), t2::Core.Const(Union{}))::Core.Const((Int64, Union{}))
└──      return %7
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.
 • %3  = return_type < only_ints(::Int64)::Int64 >
   %6  = return_type < only_ints(::Float64)::Union{} >
   ↩
```
aviatesk added a commit that referenced this issue Nov 6, 2021
- improve `ReturnTypeCallInfo` printing (see the example below)
- don't error when trying to descend into a failed `return_type` site

> before
```julia
julia> only_ints(::Integer) = 1;

julia> descend(; optimize=false) do
           t1 = Base._return_type(only_ints, Tuple{Int})     # successful `return_type`
           t2 = Base._return_type(only_ints, Tuple{Float64}) # failed `return_type`
           t1, t2
       end
(::var"#3#4")() in Main at REPL[3]:2
Variables
  #self#::Core.Const(var"#3#4"())
  t2::Type{Union{}}
  t1::Type{Int64}

│ ─ %-1  = invoke #3()::Core.Const((Int64, Union{}))
    @ REPL[3]:2 within `#3`
1 ─ %1 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %2 = Core.apply_type(Main.Tuple, Main.Int)::Core.Const(Tuple{Int64})
│        (t1 = (%1)(Main.only_ints, %2))::Core.Const(Int64)
│   @ REPL[3]:3 within `#3`
│   %4 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %5 = Core.apply_type(Main.Tuple, Main.Float64)::Core.Const(Tuple{Float64})
│        (t2 = (%4)(Main.only_ints, %5))::Core.Const(Union{})
│   @ REPL[3]:4 within `#3`
│   %7 = Core.tuple(t1::Core.Const(Int64), t2::Core.Const(Union{}))::Core.Const((Int64, Union{}))
└──      return %7
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.
 • %3  = return_type < only_ints(::Int64)::Core.Const(Int64) >
   %6  = return_type < → return_type(::typeof(only_ints),::Type{Tuple{Float64}})::Core.Const(Union{}) >
   ↩
```

> this commit
```julia
julia> only_ints(::Integer) = 1;

julia> descend(; optimize=false) do
           t1 = Base._return_type(only_ints, Tuple{Int})     # successful `return_type`
           t2 = Base._return_type(only_ints, Tuple{Float64}) # failed `return_type`
           t1, t2
       end
(::var"#3#4")() in Main at REPL[3]:2
Variables
  #self#::Core.Const(var"#3#4"())
  t2::Type{Union{}}
  t1::Type{Int64}

│ ─ %-1  = invoke #3()::Core.Const((Int64, Union{}))
    @ REPL[3]:2 within `#3`
1 ─ %1 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %2 = Core.apply_type(Main.Tuple, Main.Int)::Core.Const(Tuple{Int64})
│        (t1 = (%1)(Main.only_ints, %2))::Core.Const(Int64)
│   @ REPL[3]:3 within `#3`
│   %4 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %5 = Core.apply_type(Main.Tuple, Main.Float64)::Core.Const(Tuple{Float64})
│        (t2 = (%4)(Main.only_ints, %5))::Core.Const(Union{})
│   @ REPL[3]:4 within `#3`
│   %7 = Core.tuple(t1::Core.Const(Int64), t2::Core.Const(Union{}))::Core.Const((Int64, Union{}))
└──      return %7
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.
 • %3  = return_type < only_ints(::Int64)::Int64 >
   %6  = return_type < only_ints(::Float64)::Union{} >
   ↩
```
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.
 • ↩
```
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