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

[proofs] Initial commit #652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[proofs] Initial commit #652

wants to merge 1 commit into from

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Nov 28, 2023

Add axioms and lemmas which are useful in proving the soundness of some trait impls.

Makes progress on #429

@joshlf joshlf requested a review from jswrenn November 28, 2023 17:44
@joshlf joshlf force-pushed the proof-cleanup branch 2 times, most recently from 2a7f1b4 to 0ccf1e2 Compare November 28, 2023 17:59
/// field, which is `pub`. Per the reference [2], this means that the
/// `#[repr(transparent)]` attribute is "considered part of the public ABI".
/// `Wrapping<T>` is `#[repr(transparent)]` and has a single `T` field,
/// which is `pub`. [1] Per axiom-repr-transparent-layout-validity, we may
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should axiom-repr-transparent-layout-validity perhaps be a intradoc link? It'd give us a modest defense against proof rot.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oooh good idea. I'll also need to make sure that our safety doc comments are actually being parsed by rustdoc.

Comment on lines +14 to +29
//! ## transparent-layout-validity
//!
//! A type, `T`, has the property `transparent-layout-validity(U)` if the
//! following all hold:
//! - `T` and `U` have the same alignment
//! - For all `t: *const T`, `let u = t as *const U` is valid and
//! `size_of_val_raw(t) == size_of_val_raw(u)`.
//! - For all `u: *const U`, `let t = *const T` is valid and `size_of_val_raw(u)
//! == size_of_val_raw(t)`.
//! - For all `(t, u): (*const T, *const U)` where `size_of_val_raw(t) ==
//! size_of_val_raw(u)`:
//! - `t` and `u` refer to `UnsafeCell`s at the same byte ranges.
//! - If `*t` contains a valid `T`, that implies that `*u` contains a valid
//! `U`.
//! - If `*u` contains a valid `U`, that implies that `*t` contains a valid
//! `T`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Concretely:

/// A type, `T`, has the property `transparent-layout-validity(U)` if the
/// following all hold:
/// - `T` and `U` have the same alignment
/// - For all `t: *const T`, `let u = t as *const U` is valid and
///   `size_of_val_raw(t) == size_of_val_raw(u)`.
/// - For all `u: *const U`, `let t = *const T` is valid and `size_of_val_raw(u)
///   == size_of_val_raw(t)`.
/// - For all `(t, u): (*const T, *const U)` where `size_of_val_raw(t) ==
///   size_of_val_raw(u)`:
///   - `t` and `u` refer to `UnsafeCell`s at the same byte ranges.
///   - If `*t` contains a valid `T`, that implies that `*u` contains a valid
///     `U`.
///   - If `*u` contains a valid `U`, that implies that `*t` contains a valid
///     `T`.
#[allow(unsused)] // This only exists as an anchor for intradoc links.
const TRANSPARENT_LAYOUT_VALIDIDTY: () = ();

src/proof_utils.rs Show resolved Hide resolved
Add axioms and lemmas which are useful in proving the soundness of some
trait impls.

Makes progress on #429
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.

None yet

2 participants