Open Seelengrab opened 3 years ago
Here's an example what the code above looks like right now:
Containers with non-concretely typed fields do not introduce type instabilities per se. It is only if you access the field that a type instability is introduced and in this case code_warntype
will warn you appropriately.
Right, I'm aware of that. Type parameters are usually used to specify field types though, so having those incompletely specified will in most cases lead to type instabilities down the road, when accessing those fields (if the field is never accessed, why have it in the first place?). The problem is that this isn't apparent from @code_warntype
using one of those fields (e.g. in this example, fetch
doesn't even show up, masking the access of the field) - the functions and methods themselves are fine in any case and the problem lies with Container
. Communicating that possibility in @code_warntype
seems like a good idea.
Moreover, if you don't know that SMatrix
has 4 type parameters, simply looking at @code_warntype
leads to the confusing conclusion that the use is fine (as came up in this discourse post, which inspired this issue).
When using
@code_warntype
to check for type instabilities, sometimes some instability is induced by accessing incompletely specified type parameters/fields:In the above
@code_warntype
, all instances whereContainer{SMatrix{1, 1, Int64}}
is printed are blue, indicating type stability. Using that type and accessing its field however induces type instability, since its field is neither abstractly nor concretely typed. I think coloring that incompletely specified type parameter differently (yellow? red?) would be a good idea.