First, I like Julia’s approach to bounds checking, it seems ideal, better than most, in fact all, languages I know of.
My own idea: @inbounds
could be relaxed to check say every 4th loop iteration (configurable by the user?), to lessen overhead. Your code is still less safe, but you retain at least some safety. Seemingly the code would expand, but you may have expansion anyway, it’s common for compilers to unroll loops.
Background: Julia is mostly not made to be a safe language, while it is by default regarding bounds checks (but not e.g. overflows). And then you can to off locally with @inbounds
by the programmer (or globally, by the user, or force always on despite @inbounds
).
If you do turn of bounds checking (globally, or even in just one place) locally in your program, the program in no longer safe, i.e. it depends on the analysis of the programmer being right (and possibly inputs to the program).
Then the best you can hope for is a crash, rather than incorrect calculations.
I got the idea, while reading (and answering at) this thread on Rust (a language made to be safe above all, safer, really than Java):
See also:
https://www.sciencedirect.com/science/article/pii/S0167404819302457
we propose CHOP, a Convex Hull Optimization based framework, for bypassing redundant memory bounds checking via profile-guided inferences.