# Warnings about type instability as a compilation side effect?

**URL:** <https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986>\
**Category:** General Usage\
**Created:** [November 25, 2018, 6:12pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986 "2018-11-25T18:12:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 25, 2018, 6:12pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/1 "2018-11-25T18:12:05Z")

</div>

The compiler has I believe sufficient information about type instability when a particular method gets compiled.  
Would it be possible to implement an option to produce a warning message during compilation that the method  
is type-unstable? This warning could be enabled by a command-line flag…

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 25, 2018, 7:24pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/2 "2018-11-25T19:24:54Z")

</div>

This goes a bit that direction: [Type stable block · Issue #10980 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/10980).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 25, 2018, 7:28pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/3 "2018-11-25T19:28:49Z")

</div>

Type stability is important for performance, but I usually fine tune this aspect of my code after the interface and most of the structure has stabilized and I am in the optimization phase. So I would not necessarily want warnings about it by enabled globally.

Also, some forms of “type instability” are [innocuous](https://docs.julialang.org/en/v1/devdocs/isbitsunionarrays/) and handled well by the compiler.

I think the best strategy is to obtain this information for parts that need to be fast, but then do it in a detailed way, eg like

> **[GitHub - JunoLab/Traceur.jl](https://github.com/JunoLab/Traceur.jl)**
>
> Contribute to JunoLab/Traceur.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 25, 2018, 9:28pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/4 "2018-11-25T21:28:36Z")

</div>

> [@Tamas\_Papp](#):
>
> So I would not necessarily want warnings about it by enabled globally.

That is why I suggested that this could be enabled/disabled by a command-line flag.  
The reason I brought this up is that it is usually a pain in the butt to extract pieces of code  
for explicit type checking with `@code_warntype`. The compiler probably has this information  
already, so why not print it out when I ask for it?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 25, 2018, 10:10pm UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/5 "2018-11-25T22:10:13Z")

</div>

I filed an “enhancement” issue ([https://github.com/JuliaLang/julia/issues/30155](https://github.com/JuliaLang/julia/issues/30155)).

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 26, 2018, 2:05am UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/6 "2018-11-26T02:05:42Z")

</div>

You might get a _lot_ of output. For example, any file reader (HDF.jl, JLD.jl, CSV.jl, ImageMagick.jl, etc.) is chock-full of instabilities—and there is no way around it short of the user knowing the exact type of each variable in advance.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 26, 2018, 2:35am UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/7 "2018-11-26T02:35:26Z")

</div>

I don’t think it is inconceivable that this could be controlled, for instance by delineating which blocks of code should be subject to the type-instability reporting.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 26, 2018, 3:07am UTC](https://discourse.julialang.org/t/warnings-about-type-instability-as-a-compilation-side-effect/17986/8 "2018-11-26T03:07:17Z")

</div>

Refer to [Type stable block · Issue #10980 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/10980) instead of to 30155 please.
