f is a function that has quite a few methods and I use it somewhere deep in the call stack. I have two very similar methods, g, in one of them the return type of f is always inferred correctly for all x, and in the other one the return type of f is Any. Something like:
function g(x, y, z)
fx = f(x) # inferred as ::Any
h(fx, y, z)
end
function g(x, y)
fx = f(x) # inferred correctly
h(fx, y)
end
What are the criteria for julia to give up on type inference?
Cthulhu.jl can be helpful in helping you debug these sorts of problems — you can @descend into the function and keep asking Julia for its code_warntype until you spot the issue.
I probably wouldn’t even have notice this, because it is not in a performance sensitive part of the code but the issue was that there were only h(fx::SomeAbstractType, ...) methods which caused the compiler to assume that h would never be called and the program crashed with “Reached the unreachable” errors.
This could easily be fixed by adding f(x)::SomeAbstractType but finding the issue caused me a lot of headache.
I finally found the issue with Cthulhu.jl, it saved me from madness.
Reached the unreachable errors are always Julia bugs — not yours! If you can, please take the time to file a bug report so we can continue shaking these things out.