Would a function istypestable(foo, x) make sense for beginners?

Given the importance for performances of type stability, I wonder if the @code_warntype macro, where the type stability is somehow hidden in the type of Body: is the easiest pick for newcomers or if instead a simpler istypestable(foo,x) (or @istypestable foo(x) ) would be easier to pick for them.

3 Likes

@inferred does what you want.

1 Like

well, yes… but not exactly… first it requires Test and then it either returns nothing or generates a “strange” error (from the point of view of a newcomer).
I think istypestable (returning a simple true/false) would be a more direct message…

I think in the “improving time to first X” long thread there was some sort of method shown to find Core.Box instances. So if my memory serves me correctly, that could be a good starting point for a function like this.

1 Like

Another way it might not be exact is that a method call can have a fully inferred return type but still have type instabilities and performance hits in the middle, an example is a type-unstable method patched with an annotated return type.

So there are at least 2 methods of interest, the 1st returns the inferred return type (which could be abstract), and the 2nd checks if @code_warntype has fully inferred types throughout. I say at least 2 because some type instabilities are fine with Union-splitting, so there may also be a version that overlooks the small Unions.

1 Like

On another note, it seems to me that such a function would maybe not only be good for beginners but might also be nice for unit testing of performance-critical code. Afaik there seems to be no way of doing this in Base Julia.

JET.jl kind of does this but better.

2 Likes