Take for example the last one above, the helper_arrows. It’s a simple internal function. Why is it invalidated?
Great question! If you look at the source of helper_arrows
, you can see it calls *
. For one or more of the calls x * y
(the same as *(x, y)
), the type of x
and/or y
must not be inferrable. Thus when you precompile GMT, helper_arrows
gets compiled with a potential list of *
methods that might apply, but loading ChainRulesCore added a new *
method that also might apply. So it threw away all the old compiled code so that it could be recompiled to take this new possibility into account.
You can learn more like this:
julia> using GMT # thanks for making GMT easy to build!!!!
julia> code_warntype(GMT.helper_arrows, (Dict, Bool))
and look for red. Unfortunately it looks like the file & line numbers don’t work for code_warntype
, but you can use code_typed(GMT.helper_arrows, (Dict, Bool); debuginfo=:source, optimize=false)
and track down those statements that correspond to the lines with red.
In your case, it looks like your call to string(::Real)
is inferred as ::Any
; if you put ::String
after that call, you might fix it. I.e., "$val"::String
for your specific code.
FWIW, this type of analysis is better done with ascend
, and highly recommended if you have a lot of invalidations to fix. But there’s a bit of a learning curve, so using code_typed
is a good alternative.