@@ -1404,7 +1404,11 @@ impl Primitive {
14041404 }
14051405 }
14061406
1407- pub fn align < C : HasDataLayout > ( self , cx : & C ) -> AbiAlign {
1407+ /// The *platform-specific* ABI alignment of this primitive.
1408+ ///
1409+ /// This is the type alignment for the corresponding built-in.
1410+ /// In other contexts it might have different alignment.
1411+ pub fn default_align < C : HasDataLayout > ( self , cx : & C ) -> AbiAlign {
14081412 use Primitive :: * ;
14091413 let dl = cx. data_layout ( ) ;
14101414
@@ -1579,8 +1583,12 @@ impl Scalar {
15791583 }
15801584 }
15811585
1582- pub fn align ( self , cx : & impl HasDataLayout ) -> AbiAlign {
1583- self . primitive ( ) . align ( cx)
1586+ /// The *platform-specific* ABI alignment of this scalar.
1587+ ///
1588+ /// This is the type alignment for the corresponding built-in.
1589+ /// This is *not* necessarily the correct alignment for a type that has this `BackendRepr::Scalar`!
1590+ pub fn default_align ( self , cx : & impl HasDataLayout ) -> AbiAlign {
1591+ self . primitive ( ) . default_align ( cx)
15841592 }
15851593
15861594 pub fn size ( self , cx : & impl HasDataLayout ) -> Size {
@@ -1792,6 +1800,14 @@ impl IntoDiagArg for NumScalableVectors {
17921800#[ cfg_attr( feature = "nightly" , derive( StableHash ) ) ]
17931801pub enum BackendRepr {
17941802 Scalar ( Scalar ) ,
1803+ /// The data contained in this type can be entirely represented by two scalars.
1804+ /// The two scalars are listed in *memory* order, so the first is at offset zero
1805+ /// and the second at a non-zero offset.
1806+ /// These need not be `FieldIdx(0)` and `FieldIdx(1)`.
1807+ ///
1808+ /// As of June 2026 the offset to the second scalar is the size of the first
1809+ /// scalar rounded up to the platform alignment of the second scalar.
1810+ /// That may soon change, however; see MCP#1007.
17951811 ScalarPair ( Scalar , Scalar ) ,
17961812 SimdScalableVector {
17971813 element : Scalar ,
@@ -1857,10 +1873,16 @@ impl BackendRepr {
18571873 /// The psABI alignment for a `Scalar` or `ScalarPair`
18581874 ///
18591875 /// `None` for other variants.
1860- pub fn scalar_align < C : HasDataLayout > ( & self , cx : & C ) -> Option < Align > {
1876+ ///
1877+ /// It's unclear whether this is a meaningful operation, and MCP#1007 proposes changes.
1878+ /// You should generally be using the alignment of the place or the type,
1879+ /// not calculating something from the `Scalar`s.
1880+ pub fn scalar_platform_align < C : HasDataLayout > ( & self , cx : & C ) -> Option < Align > {
18611881 match * self {
1862- BackendRepr :: Scalar ( s) => Some ( s. align ( cx) . abi ) ,
1863- BackendRepr :: ScalarPair ( s1, s2) => Some ( s1. align ( cx) . max ( s2. align ( cx) ) . abi ) ,
1882+ BackendRepr :: Scalar ( s) => Some ( s. default_align ( cx) . abi ) ,
1883+ BackendRepr :: ScalarPair ( s1, s2) => {
1884+ Some ( s1. default_align ( cx) . max ( s2. default_align ( cx) ) . abi )
1885+ }
18641886 // The align of a Vector can vary in surprising ways
18651887 BackendRepr :: SimdVector { .. }
18661888 | BackendRepr :: Memory { .. }
@@ -1877,9 +1899,9 @@ impl BackendRepr {
18771899 BackendRepr :: Scalar ( s) => Some ( s. size ( cx) ) ,
18781900 // May have some padding between the pair.
18791901 BackendRepr :: ScalarPair ( s1, s2) => {
1880- let field2_offset = s1. size ( cx) . align_to ( s2. align ( cx) . abi ) ;
1902+ let field2_offset = s1. size ( cx) . align_to ( s2. default_align ( cx) . abi ) ;
18811903 let size = ( field2_offset + s2. size ( cx) ) . align_to (
1882- self . scalar_align ( cx)
1904+ self . scalar_platform_align ( cx)
18831905 // We absolutely must have an answer here or everything is FUBAR.
18841906 . unwrap ( ) ,
18851907 ) ;
0 commit comments