With such a strong focus on bounds checking, are there any 'systems programming' languages that you do find acceptable?
With such a strong focus on bounds checking, are there any 'systems programming' languages that you do find acceptable?
Unsafe blocks don't change the semantics of code, they just let you write code you couldn't write outside of them.
> So, for me, the placing of bounds checks when using that function is an implementation detail and therefore, if unsafe removes it, it does not effect the semantics.
The function is not marked as unsafe, so it promises that it will not corrupt memory and thus must perform bound checks. The designation of safe/unsafe for a function is compile-time and promises certain semantics.
It would be a semantic issue for a safe function to invoke unsafe behavior.
Even within an 'unsafe' block, calling safe functions should not cause memory corruption as long as your other unsafe calls / unsafe code didn't do anything "wrong".
Anyway, to implement a function like that, you'd need:
fn index(i) -> T {
if is_caller_in_unsafe_block() {
return unsafe { unsafe_index(i) }
} ...
}
The compiler does not, as far as I'm aware, have any "is_caller_in_unsafe_block" primitive, and adding one seems quite fraught.That's exactly why I get annoyed. How will it be fast if it branches on every access
> where the compiler could 'prove'
The compiler doesn't prove shit. It lets the optimizer do it. It's extremely easy to fool the optimizer
> there any 'systems programming' languages
The ones that don't make false claims (so not v or rust) and don't insert code I don't want