# @code\_warntype does not produce a helpful output when called with keyword arguments

**URL:** <https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279>\
**Category:** General Usage\
**Tags:** type\
**Created:** [February 7, 2020, 2:43am UTC](https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279 "2020-02-07T02:43:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomohiro\_soejima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomohiro_soejima/32/8056_2.png) [@tomohiro\_soejima](https://discourse.julialang.org/u/tomohiro_soejima)\
**Post date:** [February 7, 2020, 2:43am UTC](https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279/1 "2020-02-07T02:43:31Z")

</div>

Hello,

I noticed @code\_warntype does not produce a helpful output when the function in question has keyword arguments. Is there a way to call @code\_warntype, such that we get more information?

Here is a minimal example I could find in `julia-1.3.0`. The following are two type unstable functions that do exactly the same thing.

```julia
function array1(arr)
    if length(arr) > 3
        result = rand(3)
    else
        result = arr
    end
    
    result
end

function array2(arr; ϵ = 10e-12)
    if length(arr) > 3
        result = rand(3)
    else
        result = arr
    end
    
    result
end

```

However, when called with @code\_warntype, they return very different outputs.

```julia
@code_warntype array1([2,2])

Variables
  #self#::Core.Compiler.Const(array1, false)
  arr::Array{Int64,1}
  result::Union{Array{Float64,1}, Array{Int64,1}}

Body::Union{Array{Float64,1}, Array{Int64,1}}
1 ─ Core.NewvarNode(:(result))
│ %2 = Main.length(arr)::Int64
│ %3 = (%2 > 3)::Bool
└── goto #3 if not %3
2 ─ (result = Main.rand(3))
└── goto #4
3 ─ (result = arr)
4 ┄ return result

```

and

```julia
@code_warntype array2([2,2])

Variables
  #self#::Core.Compiler.Const(array2, false)
  arr::Array{Int64,1}

Body::Union{Array{Float64,1}, Array{Int64,1}}
1 ─ %1 = Main.:(var"#array2#9")(1.0e-11, #self#, arr)::Union{Array{Float64,1}, Array{Int64,1}}
└── return %1

```

In the case of array1, @code\_warntype tells us about internal function calls, such as Main.length, whereas in the case of array2, we only get a single `Main.:(var"#array2#9")(1.0e-11, #self#, arr)`, and no information about what’s happening inside the function.  
When trying to understand type instability of complicated functions with keyword arguments, this is a pretty huge roadblock. Is there a way around this?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 7, 2020, 5:02am UTC](https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279/2 "2020-02-07T05:02:09Z")

</div>

This is an unfortunate limitation of `@code_warntype`. The standard workaround I believe is to use the package [Cthulhu.jl](https://github.com/JuliaDebug/Cthulhu.jl) to be able to descend into function calls inside the outermost function. Cthulhu allows you to iteratively diplays `code_warntype` for functions called by the outermost function.

---

<div class="post-metadata">

**Author:** ![tomohiro\_soejima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomohiro_soejima/32/8056_2.png) [@tomohiro\_soejima](https://discourse.julialang.org/u/tomohiro_soejima)\
**Post date:** [February 7, 2020, 5:52am UTC](https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279/3 "2020-02-07T05:52:45Z")

</div>

Ah thanks! I just tested @descend\_code\_warntype from Chulhu.jl, and it seemed to have worked, though a bit cumbersome to read.

```julia
│ ─ %-1 = invoke array2(::Array{Int64,1})::Union{Array{Float64,1}, Array{Int64,1}}
Body::Union{Array{Float64,1}, Array{Int64,1}}
    @ In[5]:12 within `array2'
   ┌ @ In[5]:12 within `#array2#3'
   │┌ @ array.jl:216 within `length'
1 ─││ %1 = Base.arraylen(arr)::Int64
│ │└
│ │┌ @ operators.jl:294 within `>'
│ ││┌ @ int.jl:49 within `<'
│ │││ %2 = Base.slt_int(3, %1)::Bool
│ │└└
└──│ goto #3 if not %2
   │ @ In[5]:13 within `#array2#3'
   │┌ @ D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Random\src\Random.jl:277 within `rand'
2 ─││ %4 = invoke Random.rand(Random.Float64::Type{Float64}, (3,)::Tuple{Int64})::Array{Float64,1}
│ │└
└──│ goto #4
3 ─│ nothing
   │ @ In[5]:18 within `#array2#3'
4 ┄│ %7 = φ (#2 => %4, #3 => _2)::Union{Array{Float64,1}, Array{Int64,1}}
└──│ goto #5
   └
5 ─ return %7

```

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 7, 2020, 5:58am UTC](https://discourse.julialang.org/t/code-warntype-does-not-produce-a-helpful-output-when-called-with-keyword-arguments/34279/4 "2020-02-07T05:58:21Z")

</div>

You can turn off some of the printouts, check the bottom of the printout for keyboard shortcuts to disable some information. I seem to recall that I usually typed `d` to turn off debug info
