Range checking is an interesting thing - lets look at the compiler output for the following code with range checking:
procedure Test;
var
numbers: array of Integer;
i: Integer;
begin
SetLength(numbers, 10000000);
for i := Low(numbers) to High(numbers) do
numbers[i] := i;
end;
Project376.dpr.18: for i := Low(numbers) to High(numbers) do
004CF162 8B45FC mov eax,[ebp-$04]
004CF165 85C0 test eax,eax
004CF167 7405 jz $004cf16e
004CF169 83E804 sub eax,$04
004CF16C 8B00 mov eax,[eax]
004CF16E 8BD0 mov edx,eax
004CF170 4A dec edx
004CF171 85D2 test edx,edx
004CF173 7C1B jl $004cf190
004CF175 42 inc edx
004CF176 33C0 xor eax,eax
Project376.dpr.19: numbers[i] := i;
004CF178 8B4DFC mov ecx,[ebp-$04]
004CF17B 85C9 test ecx,ecx
004CF17D 7405 jz $004cf184
004CF17F 3B41FC cmp eax,[ecx-$04]
004CF182 7205 jb $004cf189
004CF184 E86F96F3FF call @BoundErr
004CF189 890481 mov [ecx+eax*4],eax
004CF18C 40 inc eax
Project376.dpr.18: for i := Low(numbers) to High(numbers) do
004CF18D 4A dec edx
004CF18E 75E8 jnz $004cf178
Now without range checking:
Project376.dpr.18: for i := Low(numbers) to High(numbers) do
004CF162 8B45FC mov eax,[ebp-$04]
004CF165 85C0 test eax,eax
004CF167 7405 jz $004cf16e
004CF169 83E804 sub eax,$04
004CF16C 8B00 mov eax,[eax]
004CF16E 8BD0 mov edx,eax
004CF170 4A dec edx
004CF171 85D2 test edx,edx
004CF173 7C0D jl $004cf182
004CF175 42 inc edx
004CF176 33C0 xor eax,eax
Project376.dpr.19: numbers[i] := i;
004CF178 8B4DFC mov ecx,[ebp-$04]
004CF17B 890481 mov [ecx+eax*4],eax
004CF17E 40 inc eax
Project376.dpr.18: for i := Low(numbers) to High(numbers) do
004CF17F 4A dec edx
004CF180 75F6 jnz $004cf178
The question is: does this code even need range checking? The answer is no - the loop range itself guarantees it.
What if the compiler would notice if I mistakenly would write:
for i := Low(numbers) to Length(numbers) do
numbers[i] := i;
instead of putting some code that slows things down and can optionally be turned off.
Of course this is a simple example of an out of range error and there are others that are not easily noticeable at compiletime - but those that are the compiler (or static code analysis) could do a whole lot of potential error detection.