Warnings about type instability as a compilation side effect?


#1

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…


#2

This goes a bit that direction: https://github.com/JuliaLang/julia/issues/10980.


#3

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 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


#4

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?


#5

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


#6

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.


#7

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.


#8

Refer to https://github.com/JuliaLang/julia/issues/10980 instead of to 30155 please.