Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement FromZeroes for Option types? #293

Closed
3 tasks done
joshlf opened this issue Aug 29, 2023 · 0 comments · Fixed by #595
Closed
3 tasks done

Implement FromZeroes for Option types? #293

joshlf opened this issue Aug 29, 2023 · 0 comments · Fixed by #595
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking experience-hard This issue is hard, and requires a lot of experience help wanted Extra attention is needed

Comments

@joshlf
Copy link
Member

joshlf commented Aug 29, 2023

Some Option types have known layouts/bit validity (e.g., Option<&T> where T: Sized). Are these actually guaranteed, or just "in practice everyone knows that's how the compiler does it"? If it's the former, and we know that None is represented as a sequence of zeroes, then it should be sound to implement FromZeroes for these types.

Task:

  • Find types, T, for which we can implement FromZeroes for Option<T> (EDIT: Here's a breadcrumb)
  • For each such type, ensure that we can make a bulletproof soundness argument based on the Rust reference and the standard library documentation
  • Put up a PR to emit the appropriate impl.

I've submitted rust-lang/rust#115333 to clarify the representation of Options and hopefully unblock more of this issue.

@joshlf joshlf added help wanted Extra attention is needed experience-hard This issue is hard, and requires a lot of experience compatibility-nonbreaking Changes that are (likely to be) non-breaking labels Aug 29, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 3, 2023
Guarantee representation of None in NPO

This allows users to soundly transmute zeroes into `Option` types subject to the null pointer optimization (NPO). It unblocks google/zerocopy#293.
joshlf added a commit that referenced this issue Nov 4, 2023
For thin pointer types, `P` (`Box<T>`, `&T`, `&mut T`, and `NonNull<T>`
where `T: Sized`), implement `FromZeroes` for `Option<P>`.

Release 0.7.25.

Closes #293
github-merge-queue bot pushed a commit that referenced this issue Nov 4, 2023
For thin pointer types, `P` (`Box<T>`, `&T`, `&mut T`, and `NonNull<T>`
where `T: Sized`), implement `FromZeroes` for `Option<P>`.

Release 0.7.25.

Closes #293
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Nov 4, 2023
Guarantee representation of None in NPO

This allows users to soundly transmute zeroes into `Option` types subject to the null pointer optimization (NPO). It unblocks google/zerocopy#293.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
Guarantee representation of None in NPO

This allows users to soundly transmute zeroes into `Option` types subject to the null pointer optimization (NPO). It unblocks google/zerocopy#293.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Guarantee representation of None in NPO

This allows users to soundly transmute zeroes into `Option` types subject to the null pointer optimization (NPO). It unblocks google/zerocopy#293.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking experience-hard This issue is hard, and requires a lot of experience help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant