rust-ux / uX

Non standard integer types like `u7`, `u9`, `u10`, `u63`, `i7`, `i9`
Apache License 2.0
119 stars 37 forks source link

wishlist: Allow optimization of uninhabited values #27

Open chrysn opened 4 years ago

chrysn commented 4 years ago

The uX types could, conceptually, allow the compiler to do optimizations based on their constraints -- for example, an Option could fit in a u64, and (later when mechanisms to make use of Copy are in place to ensure there won't be pointer to the interior; possibly coming out of https://github.com/rust-lang/rust/issues/27060) a Result<u63, u63> could be too.

This can not be done in stable Rust now, and even the means to do it that are available in unstable (rustc_layout_scalar_valid_range_end) are internal attributes never meant to become stable.

This is not an issue that would be solved quickly (unless by a possible added unstable range_optimizations feature that could break on any nightly), but more a long-term point for visibility, and to document towards the language team the usefulness of a public way to achieve this.

chrysn commented 1 year ago

The most tracking-issue-like place for that Rust feature right now is probably https://github.com/rust-lang/rust/issues/94970 (which is asking for stabilization of a bunch of things, including _scalkar_valid_range_).

Kijewski commented 1 year ago

@chrysn, please have a look at https://github.com/kjetilkjeka/uX/pull/49.

chrysn commented 1 year ago

I think you meant #49. Thanks, looking at it.

Kijewski commented 1 year ago

Oops, yes. Pasting is hard. :)