We need better things to ensure certain stuffs (like static array size or complicated types) gets computed at compile time. If only there were some function decorators or some “const-expression” which says “if the input is compile-time, run the function at compile time, compile-time if/else, etc…, maybe even error out if they aren’t at compile-time. Currently, lots of stuffs are left at the mercy of constant-propagation.
Have you considered macros? The concept of compile time can be a bit fuzzy in Julia since we are compiling code all the time. Macros on the other hand perform operations at parse time.
Yes, I should have added, “without going full macros”. Macros are solutions but it comes with all the headaches of metaprogramming.
Not necessary because Julia is not AOT compiled. Instead you would just compute the expression, assign it to a const
global, and use that in functions.
Generated functions do computations on argument types and parameters at guaranteed compile-time. Definitely a bit harder than generic functions, feels more like a macro because you’re generating function body expressions. So if you can call simple functions like eltype(A)
and let the compiler do those at compile time in a generic function, do that before resorting to generated functions.