-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
GVN: Elide more intermediate transmutes #151622
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,12 @@ use crate::{cmp, fmt, hash, mem, num}; | |
| #[unstable(feature = "ptr_alignment_type", issue = "102070")] | ||
| #[derive(Copy, Clone, PartialEq, Eq)] | ||
| #[repr(transparent)] | ||
| pub struct Alignment(AlignmentEnum); | ||
| pub struct Alignment { | ||
| // This field is never used directly (nor is the enum), | ||
| // as it's just there to convey the validity invariant. | ||
| // (Hopefully it'll eventually be a pattern type instead.) | ||
| _inner_repr_trick: AlignmentEnum, | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this change be done in its own commit? This would make easier to understand what changes from the mir opt diff.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely. I split it to three:
That way all the library changes are separated. |
||
|
|
||
| // Alignment is `repr(usize)`, but via extra steps. | ||
| const _: () = assert!(size_of::<Alignment>() == size_of::<usize>()); | ||
|
|
@@ -37,7 +42,7 @@ impl Alignment { | |
| /// assert_eq!(Alignment::MIN.as_usize(), 1); | ||
| /// ``` | ||
| #[unstable(feature = "ptr_alignment_type", issue = "102070")] | ||
| pub const MIN: Self = Self(AlignmentEnum::_Align1Shl0); | ||
| pub const MIN: Self = Self::new(1).unwrap(); | ||
|
|
||
| /// Returns the alignment for a type. | ||
| /// | ||
|
|
@@ -166,7 +171,10 @@ impl Alignment { | |
| #[unstable(feature = "ptr_alignment_type", issue = "102070")] | ||
| #[inline] | ||
| pub const fn as_usize(self) -> usize { | ||
| self.0 as usize | ||
| // Going through `as_nonzero` helps this be more clearly the inverse of | ||
| // `new_unchecked`, letting MIR optimizations fold it away. | ||
|
|
||
| self.as_nonzero().get() | ||
| } | ||
|
|
||
| /// Returns the alignment as a <code>[NonZero]<[usize]></code>. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind commenting the logic? This looks good to me, but it took me a few frowns to understand, for instance why ranges are compared the way you wrote it