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.
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 signs around it): https://gist.github.com/timholy/9d2aabaeabb22239b5e7a4e95e35d298. In case it’s not obvious, the function to study is bad_calls
.
1 Like
Traceur.jl is a Julia package that can help you find type instabilities.
1 Like
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> 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).
4 Likes