Description
This PR is the latest to propose a rule for AbstractArray
s that, in my opinion, is too broadly-typed. While I obviously sympathise with rule authors wanting to do this (it feels like the natural thing to do), we know that it causes real problems.
I wonder whether we should implement a test util comprising rrule_test
s and frule_test
s on a suite of different types of arrays that we insist any new rule that purports to support AbstractArray
s, or some subtype thereof, must pass. The idea being would would include
- examples of every concrete type of array that we can find in
Base
/ the standard libraries - examples from popular external packages, such as
StaticArrays
,FillArrays
, andBlockArrays
.
Crucially, I propose that the tests should pass if, for all arrays in the suite, either
- the standard rule tests pass, or
- no rule is found for that array.
This means that the rule author can pick and choose the kinds of arrays that they support, and obvious "gaming" of the tests would be addressed at review time (i.e. the idea is not to implement a rule of AbstractArray
s and then implement rules that return nothing
for each non-Array
array in the test suite).
This approach is obviously not a panacea since you clearly can't test against all concrete subtypes of AbstractArray
that will ever be written. Rather, the goal is to have enough coverage of types of arrays that break assumptions that hold for Array
-like AbstractArray
s to ensure that rule authors and reviewers don't accidentally implement something too loosely-typed. My hope is that this will encourage rule authors (and reviewers) to be cognisant of the issues surrounding implementing rules for abstract types.
While Number
s have generally been less troublesome in practice, they obviously suffer from the same issues and have caused problems from time to time. It might make sense to consider a similar thing for Number
s.
Maybe there are some other common types where this stuff goes wrong on a regular basis?
I'm not entirely sure how this should look in practice (do we want a formal testing function that actually runs a load of tests, or do we just want to provide a global const
Vector
of subtypes of AbstractArray
that we insist gets used when writing tests?), but if people like the general idea then we can think a little more carefully about how to make it work.