When writing julia code, I find a lot of my time is spent on a common themes: trying to ensure some piece of code is either constant propagating or inferring as I intend / expect. I find this stuff quite difficult to systematically test for or ensure - it’s often a bit of trial and error, and is quite tedious. The annoying thing is that if this gets messed up, nothing errors - the compiler just generates bad code. It can be quite easy to make a change, and for it to negatively affect some downstream codepath.
Has there been much discussion around ways of communicating these expectations to the compiler, and erroring at compile time if they are violated?
For the constant propagation side of things, I was imagining something analogous to
constexpr in C++ - just a way of saying “this variable value or function return value should be known to you, compiler”.
For the inference side of things, it is a little harder due to the issue of deciding what counts as “bad” inference / a degradation in type-specificity - has anyone given this much thought? Does the compiler currently have some internal notion of this?
Irrespective, there are probably some simple but immediately useful heuristics that could be attached to methods somehow. For example: “there should be any
Anys in the return type of this method”, or “there shouldn’t be any
Unions in the return type of this method”, or perhaps something like “if none of the inputs had
Any in them, there shouldn’t be any
Anys in the return type” - etc.
Looking forward to your thoughts.