We usually speak of type stability for functions and we also have the tools to determine that (like @code_warntype).
But say I would like to check whether a struct is type-stable, in the sense that it is well defined and no field is of an abstract type.
For the small structs it is trivial, but for long composite nested structs it is quite hard to inspect it manually.
Is there a tool to handle this automatically ?
Not sure what exactly mean with fields being “well defined” (they always are), but this should do what you’re looking for:
julia> allconcrete(x::T) where T = all(isconcretetype, fieldtypes(T))
allconcrete (generic function with 1 method)
Note that this works through reflection via fieldtypes.
“type stable” as a term only makes sense in the context of a function using an object, since type stability only refers to some function whose return type depends on the value of its arguments instead of its types. It’s true that abstractly typed fields can lead to type instabilities in functions using that type, but I’m not sure we should refer to structs with non-concretely typed fields as “type unstable”. There are valid reasons for having a field typed as e.g. Any - for example when the field can take on a diverse number of types and specializing on it would not help (or even hinder) performance.