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

Make Ptr invariants opaque and more ergonomic #1876

Closed
joshlf opened this issue Oct 11, 2024 · 0 comments · Fixed by #1895
Closed

Make Ptr invariants opaque and more ergonomic #1876

joshlf opened this issue Oct 11, 2024 · 0 comments · Fixed by #1895

Comments

@joshlf
Copy link
Member

joshlf commented Oct 11, 2024

Once we publish 0.9, which will have a sufficiently high MSRV that we have access to GAT, we implement the following design. This will permit all concrete Invariants types to be private. This, in turn, means that we can preserve the ability to make future changes to how we represent invariants, or even add new invariants.

trait Invariants {
    // The invariants encoded by `Self`
    type Aliasing: Aliasing;
    type Alignment: Alignment;
    type Validity: Validity;

    // `Self` except with one invariant modified
    type WithAliasing<A: Aliasing>: Invariants<
        Aliasing = A,
        Alignment = Self::Alignment,
        Validity = Self::Validity,
    >;
    type WithAlignment<A: Alignment>: Invariants<
        Aliasing = Self::Aliasing,
        Alignment = A,
        Validity = Self::Validity,
    >;
    type WithValidity<A: Validity>: Invariants<
        Aliasing = Self::Aliasing,
        Alignment = Self::Alignment,
        Validity = V,
    >;
}

struct Ptr<'a, T, I: Invariants> { ... }

impl<'a, T, I: Invariants> Ptr<'a, T, I> {
    // Look! No concrete types!
    pub unsafe fn assume_aligned(self) -> Ptr<'a, T,  I::WithAlignment<Aligned>> { ... }
}
joshlf added a commit that referenced this issue Oct 12, 2024
joshlf added a commit that referenced this issue Oct 12, 2024
joshlf added a commit that referenced this issue Oct 13, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
joshlf added a commit that referenced this issue Oct 14, 2024
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 a pull request may close this issue.

1 participant