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

Strengthen soundness proof for size_of_val_raw #1574

Merged
merged 2 commits into from
Aug 6, 2024
Merged

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Aug 6, 2024

Previously, we needed to rely on the fact that the instance of any valid Rust type with 0 elements has a size (in number of bytes) which is not greater than isize::MAX. Providing this as a guarantee turned out to be controversial. [1]

This was made possible by rust-lang/rust#126152.

[1] rust-lang/unsafe-code-guidelines#465 (comment)

@joshlf joshlf enabled auto-merge August 6, 2024 18:35
Comment on lines 152 to 154
// [1] TODO(#429),
// TODO(https://github.com/rust-lang/unsafe-code-guidelines/issues/465#issuecomment-1782206516):
// Citation for this?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is [1] still referenced somewhere after your revision?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed.

@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.70%. Comparing base (a51d64f) to head (d5ab566).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1574   +/-   ##
=======================================
  Coverage   87.70%   87.70%           
=======================================
  Files          15       15           
  Lines        5563     5563           
=======================================
  Hits         4879     4879           
  Misses        684      684           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Previously, we needed to rely on the fact that the instance of any valid
Rust type with 0 elements has a size (in number of bytes) which is not
greater than `isize::MAX`. Providing this as a guarantee turned out to
be controversial. [1]

This was made possible by rust-lang/rust#126152.

[1] rust-lang/unsafe-code-guidelines#465 (comment)
@djkoloski
Copy link
Member

Can we just use offset_of! now that it's stable?

@joshlf
Copy link
Member Author

joshlf commented Aug 6, 2024

Can we just use offset_of! now that it's stable?

A few issues:

  • It doesn't support our MSRV
  • It doesn't support DSTs

Note that size_of_val_raw isn't stable at all - this code is only tested on nightly (and not actually used anywhere) to make sure we're forwards-compatible with using it in the future. So DST support is really the issue that matters.

@joshlf joshlf added this pull request to the merge queue Aug 6, 2024
Merged via the queue into main with commit 50d9d62 Aug 6, 2024
77 checks passed
@joshlf joshlf deleted the size-of-val-raw-zero-dst branch August 6, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants