4 ms·
The NonZero type reminds me of something else I'd like to see in Rust; ranged integers. By which I mean integers that can only represent a specified range of nu
by ChrisSD 8y ago
The NonZero type reminds me of something else I'd like to see in Rust; ranged integers. By which I mean integers that can only represent a specified range of numbers.
This is not so much for optimization but for type safety (i.e. avoiding bugs).
- steveklabnik 8y agoWe'd like that too; it's likely to fall out of const generics, which are looking likely to hit stable sometime early next year.
- henrikeh 8y agoWith const generics ranged integers would be implemented as a user specified check. How viable would it be to implement an optimization step which seeks to minimize the number of these checks?
- steveklabnik 8y agoI'm not entirely sure what you mean, exactly. As far as I know, all of the usual optimization passes would already be working to minimize them.
- sanxiyn 8y agoRust could emit LLVM range metadata for ranged integers. IIRC, it already does so for enum discriminants.
- steveklabnik 8y agoThat seems quite good!
- masklinn 8y agoThat's probably down the line from const generics, as it has the additional constraint of defining the workings of those (API, over/underflow behaviour), how they'd interact with regular integral types (in terms of conversions back and forth), literals, …
- anderspitman 8y agoThat would be awesome, especially if it works similarly to Ada.