forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#120080 - cuviper:128-align-packed, r=nikic
Pack u128 in the compiler to mitigate new alignment This is based on rust-lang#116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places: * `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes. * `LitKind::Int`, so that entire `enum` can stay 24 bytes. * This change definitely has far-reaching effects though, since it's public.
- Loading branch information
Showing
43 changed files
with
173 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::stable_hasher::{HashStable, StableHasher}; | ||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; | ||
use std::cmp::Ordering; | ||
use std::fmt; | ||
|
||
#[repr(packed(8))] | ||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Pu128(pub u128); | ||
|
||
impl Pu128 { | ||
#[inline] | ||
pub fn get(self) -> u128 { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<u128> for Pu128 { | ||
#[inline] | ||
fn from(value: u128) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl PartialEq<u128> for Pu128 { | ||
#[inline] | ||
fn eq(&self, other: &u128) -> bool { | ||
({ self.0 }) == *other | ||
} | ||
} | ||
|
||
impl PartialOrd<u128> for Pu128 { | ||
#[inline] | ||
fn partial_cmp(&self, other: &u128) -> Option<Ordering> { | ||
{ self.0 }.partial_cmp(other) | ||
} | ||
} | ||
|
||
impl fmt::Display for Pu128 { | ||
#[inline] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
{ self.0 }.fmt(f) | ||
} | ||
} | ||
|
||
impl fmt::UpperHex for Pu128 { | ||
#[inline] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
{ self.0 }.fmt(f) | ||
} | ||
} | ||
|
||
impl<CTX> HashStable<CTX> for Pu128 { | ||
#[inline] | ||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { | ||
{ self.0 }.hash_stable(ctx, hasher) | ||
} | ||
} | ||
|
||
impl<S: Encoder> Encodable<S> for Pu128 { | ||
#[inline] | ||
fn encode(&self, s: &mut S) { | ||
{ self.0 }.encode(s); | ||
} | ||
} | ||
|
||
impl<D: Decoder> Decodable<D> for Pu128 { | ||
#[inline] | ||
fn decode(d: &mut D) -> Self { | ||
Self(u128::decode(d)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.