Frank Heckenbach wrote:
CBFalconer wrote:
Frank Heckenbach wrote:
... snip ...
I.e., it has to resolve equations!? (If a is an array [1 .. 20] and in the loop it says `a [i * i - 3]', it should find that i is allowed to be in the range 2 .. 4 and -4 .. -2?
Horrors. If i is a subrange, the compiler can calculate (mini * mini - 3) and (maxi * maxi - 3). If these are satisfactory then it omits the range checks on the index operation.
Nice, but wrong (e.g.: i: -4 .. 4)!
Pointing out that the check has to be performed at index time. The decision to be made is not whether to perform the check, but whether to omit the check.
This is simply pushing the calculated index, a min and a max from the array declaration, and calling chk.
As I said, we'll do inline checks which are faster (and probably even easier). That's really not the problem.
What if the loop calls any routine which might (directly or indirectly) call Halt conditionally?
So what? A halt is a halt is a halt.
If the analysis finds that a `for' loop has an "inevitable" range error, but `Halt' is called before it, the error is not that inevitable.
Again, this is the wrong perspective. The default should be to check things. The complex (and inevitably initially buggy) analysis decides to omit the check. The decision is not that a range error is inevitable, but that it is impossible.