# Is possible to enabled an option so that type-instable functions will throw an error?

**URL:** <https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278>\
**Category:** General Usage\
**Created:** [June 30, 2020, 2:17am UTC](https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278 "2020-06-30T02:17:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [June 30, 2020, 2:17am UTC](https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278/1 "2020-06-30T02:17:39Z")

</div>

I wonder if it’s possible run a function so that after running the function, all type instable functions will throw error, e.g. it looks into the `@code_warntypes`, detects if there are any `Any` and throw an error it does?

The user can suppress this with a `@allow_type_instabiliy function abc() ...`

I was thinking this is a more efficient way to hunt for type instability and so we only mark functions that can have type instability with a macro.

---

<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:** [June 30, 2020, 2:31am UTC](https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278/2 "2020-06-30T02:31:31Z")

</div>

There’s nothing in Julia right now, but you can do this yourself with a bit of analysis. Just a couple of days ago I posted a script that should get you well along the way (though if this were the TeXbook I would put [double-dangerous](http://www.truetex.com/db.htm) signs around it): [https://gist.github.com/timholy/9d2aabaeabb22239b5e7a4e95e35d298](https://gist.github.com/timholy/9d2aabaeabb22239b5e7a4e95e35d298). In case it’s not obvious, the function to study is `bad_calls`.

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [June 30, 2020, 2:35am UTC](https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278/3 "2020-06-30T02:35:42Z")

</div>

Traceur.jl is a Julia package that can help you find type instabilities.

---

<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:** [June 30, 2020, 2:50am UTC](https://discourse.julialang.org/t/is-possible-to-enabled-an-option-so-that-type-instable-functions-will-throw-an-error/42278/4 "2020-06-30T02:50:39Z")

</div>

Traceur is cool and newbie friendly, but frankly I’d recommend Cthulhu. I know it’s a _lot_ more demanding to understand, but in the long run it’s immensely rewarding. I challenge anyone to figure out how to “fix” or even improve `Base.shell_parse` from

```julia
julia> f(x) = Base.shell_parse(x[1])
f (generic function with 1 method)

julia> x = AbstractString["hello"]
1-element Array{AbstractString,1}:
 "hello"

julia> @trace f(x)

```

run on Julia 1.4 or 1.5. Whereas with Cthulhu it’s pretty easy, once you get the hang of it (answer: [https://github.com/JuliaLang/julia/pull/36427](https://github.com/JuliaLang/julia/pull/36427)).
