In Julia, we all use @code_warntype to conclude whether a function is type stable or not. However, @code_warntype returns a long text which tells us in detail the infered types of related variables. I wonder is there a way to show only a bool value, stable or not, to help me write cleaner code.
Sometimes, I imagine it would be better if I can test the code type stability as easy to test the correstness of code. For example,
@test_type func(a, b)
# this will return true or false
So, we can write a test set to test the type-stability of all functions of a package.
Note that the Test.@inferred macro and the upcoming DispatchDoctor.@stable macro mentioned above only care about the output of your function. If the output can be correctly inferred, but type instabilities happen inside of the function, you won’t be able to detect them with such tools.
The only tool I know that can detect type instabilities inside functions is JET.jl, specifically JET.@test_opt.