Open danakj opened 1 year ago
I think a more general thing here would be integral types with a fixed range. NonZeroI8
is just an i8
with range 1..=MAX
. But it'd be nice to instead have BoundedI8<1, i8::MAX>
or something. The compiler can optimize on the bounds then, as .get()
could __assume()
stuff about the returned value?
The NeverValueField would be the min_bound-1 or max_bound+1, assuming either one is not MIN/MAX.
Bounded type A should implicitly convert to Bounded type B if B has bounds which cover A, regardless of the actual storage type.
The compiler can optimize on the bounds then, as .get() could __assume() stuff about the returned value?
Yes, as long as the method that returns the inner value is inlined, then the caller will optimize based on the bounds in Clang and GCC (MSVC does poorly but can clearly be improved).
Like https://doc.rust-lang.org/std/num/index.html
They should be NeverValueField types so they don't require an extra bool in Option.