@@ -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+ /// In other contexts it might have different alignment.
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,13 @@ impl IntoDiagArg for NumScalableVectors {
17921800#[ cfg_attr( feature = "nightly" , derive( StableHash ) ) ]
17931801pub enum BackendRepr {
17941802 Scalar ( Scalar ) ,
1803+ /// Two scalars listed in *memory* order, so the first is at offset zero
1804+ /// and the second at a non-zero offset.
1805+ /// These need not be `FieldIdx(0)` and `FieldIdx(1)`.
1806+ ///
1807+ /// As of June 2026 the offset to the second scalar is the size of the first
1808+ /// scalar rounded up to the platform alignment of the second scalar.
1809+ /// That may soon change, however; see MCP#1007.
17951810 ScalarPair ( Scalar , Scalar ) ,
17961811 SimdScalableVector {
17971812 element : Scalar ,
@@ -1857,10 +1872,16 @@ impl BackendRepr {
18571872 /// The psABI alignment for a `Scalar` or `ScalarPair`
18581873 ///
18591874 /// `None` for other variants.
1860- pub fn scalar_align < C : HasDataLayout > ( & self , cx : & C ) -> Option < Align > {
1875+ ///
1876+ /// It's unclear whether this is a meaningful operation, and MCP#1007 proposes changes.
1877+ /// You should generally be using the alignment of the place or the type,
1878+ /// not calculating something from the `Scalar`s.
1879+ pub fn scalar_platform_align < C : HasDataLayout > ( & self , cx : & C ) -> Option < Align > {
18611880 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 ) ,
1881+ BackendRepr :: Scalar ( s) => Some ( s. default_align ( cx) . abi ) ,
1882+ BackendRepr :: ScalarPair ( s1, s2) => {
1883+ Some ( s1. default_align ( cx) . max ( s2. default_align ( cx) ) . abi )
1884+ }
18641885 // The align of a Vector can vary in surprising ways
18651886 BackendRepr :: SimdVector { .. }
18661887 | BackendRepr :: Memory { .. }
@@ -1877,9 +1898,9 @@ impl BackendRepr {
18771898 BackendRepr :: Scalar ( s) => Some ( s. size ( cx) ) ,
18781899 // May have some padding between the pair.
18791900 BackendRepr :: ScalarPair ( s1, s2) => {
1880- let field2_offset = s1. size ( cx) . align_to ( s2. align ( cx) . abi ) ;
1901+ let field2_offset = s1. size ( cx) . align_to ( s2. default_align ( cx) . abi ) ;
18811902 let size = ( field2_offset + s2. size ( cx) ) . align_to (
1882- self . scalar_align ( cx)
1903+ self . scalar_platform_align ( cx)
18831904 // We absolutely must have an answer here or everything is FUBAR.
18841905 . unwrap ( ) ,
18851906 ) ;
0 commit comments