3 ms·
Rust does let you do unsafe array indexing and other unsafe stuff. But it doesn't support switching the semantics of safe code to unsafe with a build flag, you
by zurn 11y ago
Rust does let you do unsafe array indexing and other unsafe stuff. But it doesn't support switching the semantics of safe code to unsafe with a build flag, you need to explicitly use "unsafe" in code.
- renox 11y ago> But it doesn't support switching the semantics of safe code to unsafe with a build flag Jai allow this for array indexing AND it also allow the reverse: reinserting array checks even when there is an 'unsafe access' operation: this way even if you made a mistake in adding an 'unsafe access' operation it's easy to find where the error is (assuming the error is reproducible of course).
- pcwalton 11y agoI haven't seen any cases in which adding a global build flag to turn off bounds checks would actually improve performance. People overfocus on bounds checks because they're an easy thing to understand, but they're just one of many performance issues when creating a new language, and not a particularly interesting one at that since APIs, compiler optimizations, and branch predictors all conspire to drive their overhead down to near-zero (in my experience).
- renox 11y agoSure, but I think that having one global flag to remove bound checks is useful as it allows you to measure this bounds checks performance impact easily. And then when you know how long it takes to find an index out-of-bound error and you see that the removal performance improve is small.. Well, you remove the flag.