Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 44 additions & 65 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1556,16 +1556,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"

[[package]]
name = "futf"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843"
dependencies = [
"mac",
"new_debug_unreachable",
]

[[package]]
name = "generate-copyright"
version = "0.1.0"
Expand Down Expand Up @@ -1791,14 +1781,12 @@ dependencies = [

[[package]]
name = "html5ever"
version = "0.29.1"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b7410cae13cbc75623c98ac4cbfd1f0bedddf3227afc24f370cf0f50a44a11c"
checksum = "46a1761807faccc9a19e86944bbf40610014066306f96edcdedc2fb714bcb7b8"
dependencies = [
"log",
"mac",
"markup5ever",
"match_token",
]

[[package]]
Expand Down Expand Up @@ -2424,35 +2412,15 @@ dependencies = [
"pkg-config",
]

[[package]]
name = "mac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"

[[package]]
name = "markup5ever"
version = "0.14.1"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7a7213d12e1864c0f002f52c2923d4556935a43dec5e71355c2760e0f6e7a18"
checksum = "7122d987ec5f704ee56f6e5b41a7d93722e9aae27ae07cafa4036c4d3f9757de"
dependencies = [
"log",
"phf 0.11.3",
"phf_codegen",
"string_cache",
"string_cache_codegen",
"tendril",
]

[[package]]
name = "match_token"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88a9689d8d44bf9964484516275f5cd4c9b59457a6940c1d5d0ecbb94510a36b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"web_atoms",
]

[[package]]
Expand Down Expand Up @@ -2986,56 +2954,57 @@ dependencies = [

[[package]]
name = "phf"
version = "0.11.3"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
dependencies = [
"phf_shared 0.11.3",
"phf_shared 0.12.1",
]

[[package]]
name = "phf"
version = "0.12.1"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
dependencies = [
"phf_shared 0.12.1",
"phf_shared 0.13.1",
"serde",
]

[[package]]
name = "phf_codegen"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1"
dependencies = [
"phf_generator",
"phf_shared 0.11.3",
"phf_shared 0.13.1",
]

[[package]]
name = "phf_generator"
version = "0.11.3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
dependencies = [
"phf_shared 0.11.3",
"rand 0.8.5",
"fastrand",
"phf_shared 0.13.1",
]

[[package]]
name = "phf_shared"
version = "0.11.3"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981"
dependencies = [
"siphasher",
]

[[package]]
name = "phf_shared"
version = "0.12.1"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981"
checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
dependencies = [
"siphasher",
]
Expand Down Expand Up @@ -5425,25 +5394,24 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"

[[package]]
name = "string_cache"
version = "0.8.9"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f"
checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901"
dependencies = [
"new_debug_unreachable",
"parking_lot",
"phf_shared 0.11.3",
"phf_shared 0.13.1",
"precomputed-hash",
"serde",
]

[[package]]
name = "string_cache_codegen"
version = "0.5.4"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c711928715f1fe0fe509c53b43e993a9a557babc2d0a3567d0a3006f1ac931a0"
checksum = "585635e46db231059f76c5849798146164652513eb9e8ab2685939dd90f29b69"
dependencies = [
"phf_generator",
"phf_shared 0.11.3",
"phf_shared 0.13.1",
"proc-macro2",
"quote",
]
Expand Down Expand Up @@ -5533,12 +5501,11 @@ dependencies = [

[[package]]
name = "tendril"
version = "0.4.3"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0"
checksum = "c4790fc369d5a530f4b544b094e31388b9b3a37c0f4652ade4505945f5660d24"
dependencies = [
"futf",
"mac",
"new_debug_unreachable",
"utf-8",
]

Expand Down Expand Up @@ -6503,6 +6470,18 @@ dependencies = [
"wasm-bindgen",
]

[[package]]
name = "web_atoms"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "075474b12bcb3d2e3d4546580e9de478eeeead668a1761e2a8860c836b7ef297"
dependencies = [
"phf 0.13.1",
"phf_codegen",
"string_cache",
"string_cache_codegen",
]

[[package]]
name = "winapi-util"
version = "0.1.11"
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,14 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Ok(Some((repr, _))) => match repr {
// Mismatched alignment (e.g. union is #[repr(packed)]): disable opt
BackendRepr::Scalar(_) | BackendRepr::ScalarPair(_, _)
if repr.scalar_align(dl).unwrap() != align =>
if repr.scalar_platform_align(dl).unwrap() != align =>
{
BackendRepr::Memory { sized: true }
}
// Vectors require at least element alignment, else disable the opt
BackendRepr::SimdVector { element, count: _ } if element.align(dl).abi > align => {
BackendRepr::SimdVector { element, count: _ }
if element.default_align(dl).abi > align =>
{
BackendRepr::Memory { sized: true }
}
// the alignment tests passed and we can use this
Expand Down Expand Up @@ -986,7 +988,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
// roundtripping pointers through ptrtoint/inttoptr.
(p @ Primitive::Pointer(_), i @ Primitive::Int(..))
| (i @ Primitive::Int(..), p @ Primitive::Pointer(_))
if p.size(dl) == i.size(dl) && p.align(dl) == i.align(dl) =>
if p.size(dl) == i.size(dl)
&& p.default_align(dl) == i.default_align(dl) =>
{
p
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_abi/src/layout/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar);
let size = scalar.size(cx);
let align = scalar.align(cx);
let align = scalar.default_align(cx);

let range = scalar.valid_range(cx);

Expand Down Expand Up @@ -90,8 +90,8 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {

pub fn scalar_pair<C: HasDataLayout>(cx: &C, a: Scalar, b: Scalar) -> Self {
let dl = cx.data_layout();
let b_align = b.align(dl).abi;
let align = a.align(dl).abi.max(b_align).max(dl.aggregate_align);
let b_align = b.default_align(dl).abi;
let align = a.default_align(dl).abi.max(b_align).max(dl.aggregate_align);
let b_offset = a.size(dl).align_to(b_align);
let size = (b_offset + b.size(dl)).align_to(align);

Expand Down
38 changes: 30 additions & 8 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,11 @@ impl Primitive {
}
}

pub fn align<C: HasDataLayout>(self, cx: &C) -> AbiAlign {
/// The *platform-specific* ABI alignment of this primitive.
///
/// This is the type alignment for the corresponding built-in.
/// In other contexts it might have different alignment.
pub fn default_align<C: HasDataLayout>(self, cx: &C) -> AbiAlign {
use Primitive::*;
let dl = cx.data_layout();

Expand Down Expand Up @@ -1579,8 +1583,12 @@ impl Scalar {
}
}

pub fn align(self, cx: &impl HasDataLayout) -> AbiAlign {
self.primitive().align(cx)
/// The *platform-specific* ABI alignment of this scalar.
///
/// This is the type alignment for the corresponding built-in.
/// This is *not* necessarily the correct alignment for a type that has this `BackendRepr::Scalar`!
pub fn default_align(self, cx: &impl HasDataLayout) -> AbiAlign {
self.primitive().default_align(cx)
}

pub fn size(self, cx: &impl HasDataLayout) -> Size {
Expand Down Expand Up @@ -1792,6 +1800,14 @@ impl IntoDiagArg for NumScalableVectors {
#[cfg_attr(feature = "nightly", derive(StableHash))]
pub enum BackendRepr {
Scalar(Scalar),
/// The data contained in this type can be entirely represented by two scalars.
/// The two scalars are listed in *memory* order, so the first is at offset zero
/// and the second at a non-zero offset.
/// These need not be `FieldIdx(0)` and `FieldIdx(1)`.
///
/// As of June 2026 the offset to the second scalar is the size of the first
/// scalar rounded up to the platform alignment of the second scalar.
/// That may soon change, however; see MCP#1007.
ScalarPair(Scalar, Scalar),
SimdScalableVector {
element: Scalar,
Expand Down Expand Up @@ -1857,10 +1873,16 @@ impl BackendRepr {
/// The psABI alignment for a `Scalar` or `ScalarPair`
///
/// `None` for other variants.
pub fn scalar_align<C: HasDataLayout>(&self, cx: &C) -> Option<Align> {
///
/// It's unclear whether this is a meaningful operation, and MCP#1007 proposes changes.
/// You should generally be using the alignment of the place or the type,
/// not calculating something from the `Scalar`s.
pub fn scalar_platform_align<C: HasDataLayout>(&self, cx: &C) -> Option<Align> {
match *self {
BackendRepr::Scalar(s) => Some(s.align(cx).abi),
BackendRepr::ScalarPair(s1, s2) => Some(s1.align(cx).max(s2.align(cx)).abi),
BackendRepr::Scalar(s) => Some(s.default_align(cx).abi),
BackendRepr::ScalarPair(s1, s2) => {
Some(s1.default_align(cx).max(s2.default_align(cx)).abi)
}
// The align of a Vector can vary in surprising ways
BackendRepr::SimdVector { .. }
| BackendRepr::Memory { .. }
Expand All @@ -1877,9 +1899,9 @@ impl BackendRepr {
BackendRepr::Scalar(s) => Some(s.size(cx)),
// May have some padding between the pair.
BackendRepr::ScalarPair(s1, s2) => {
let field2_offset = s1.size(cx).align_to(s2.align(cx).abi);
let field2_offset = s1.size(cx).align_to(s2.default_align(cx).abi);
let size = (field2_offset + s2.size(cx)).align_to(
self.scalar_align(cx)
self.scalar_platform_align(cx)
// We absolutely must have an answer here or everything is FUBAR.
.unwrap(),
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn codegen_field<'tcx>(
}

fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 {
let b_offset = a_scalar.size(&tcx).align_to(b_scalar.align(&tcx).abi);
let b_offset = a_scalar.size(&tcx).align_to(b_scalar.default_align(&tcx).abi);
Offset32::new(b_offset.bytes().try_into().unwrap())
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
},
)
} else if let abi::BackendRepr::ScalarPair(ref a, ref b) = place.layout.backend_repr {
let b_offset = a.size(self).align_to(b.align(self).abi);
let b_offset = a.size(self).align_to(b.default_align(self).abi);

let mut load = |i, scalar: &abi::Scalar, align| {
let ptr = if i == 0 {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_gcc/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
return cx.type_i1();
}

let offset = if index == 0 { Size::ZERO } else { a.size(cx).align_to(b.align(cx).abi) };
let offset =
if index == 0 { Size::ZERO } else { a.size(cx).align_to(b.default_align(cx).abi) };
self.scalar_gcc_type_at(cx, scalar, offset)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
});
OperandValue::Immediate(llval)
} else if let abi::BackendRepr::ScalarPair(a, b) = place.layout.backend_repr {
let b_offset = a.size(self).align_to(b.align(self).abi);
let b_offset = a.size(self).align_to(b.default_align(self).abi);

let mut load = |i, scalar: abi::Scalar, layout, align, offset| {
let llptr = if i == 0 {
Expand Down
Loading
Loading