Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
68cfe93
Add comments to randomize-layout implementation documenting guarantee…
zachs18 Jun 15, 2026
bec5d88
Add zero-variant enums to randomize-layout comments and tests.
zachs18 Jun 15, 2026
715a616
move batch
zedddie Jul 9, 2026
dd8996d
bless batch
zedddie Jul 9, 2026
b1bddeb
move batch
zedddie Jul 10, 2026
b23c2ee
bless batch
zedddie Jul 10, 2026
c703f8a
doc: document wasm import symbol mangling
kn1g78 Jul 11, 2026
c100aca
doc: clarify wasm import symbol mangling
kn1g78 Jul 13, 2026
f266337
doc: describe wasm import conflict behavior
kn1g78 Jul 13, 2026
032d959
ensure to check that the overview is current
tshepang Jul 15, 2026
a61a054
use sentence case for titles
tshepang Jul 15, 2026
6201540
Merge pull request #2928 from rust-lang/tshepang/sentence-case
tshepang Jul 15, 2026
821701a
fix rustup update command for autodiff
ZuseZ4 Jul 15, 2026
1912059
Merge pull request #2929 from rust-lang/rustup-enzyme-update2
ZuseZ4 Jul 15, 2026
4f1921c
use sentence case for titles
tshepang Jul 16, 2026
1a180c0
reflow
tshepang Jul 16, 2026
340f705
Merge pull request #2930 from rust-lang/tshepang/sentence-case
tshepang Jul 16, 2026
7587030
move batch
zedddie Jul 16, 2026
377748d
move batch
zedddie Jul 17, 2026
a2730fa
replace codeview.pdf with link to archived webpage
Walnut356 Jul 18, 2026
2d0b4b3
typo
tshepang Jul 18, 2026
37a4a74
Merge pull request #2931 from Walnut356/codeview
tshepang Jul 18, 2026
6d6092c
bless batch
zedddie Jul 17, 2026
fb119e0
Clarify what to do when you break a subtree build
panstromek Jul 18, 2026
2851cef
move batch
zedddie Jul 19, 2026
2e1df4d
Merge pull request #2932 from panstromek/patch-1
tshepang Jul 20, 2026
7726456
extraneous word
tshepang Jul 20, 2026
216b07a
deserves own sentence
tshepang Jul 20, 2026
a9d6ac1
Add test cases for a hoisting miscompilation
dianqk Jul 20, 2026
a22fed7
early_otherwise: Don't hoist dereferences when the otherwise branch i…
dianqk Jul 20, 2026
6c5df71
update thir output
tshepang Jul 20, 2026
4809e4c
sembr src/hir-typeck/summary.md
tshepang Jul 20, 2026
775b479
unusual use of colon
tshepang Jul 20, 2026
ef6ce22
sembr src/debuginfo/intro.md
tshepang Jul 20, 2026
c0c2829
reflow
tshepang Jul 20, 2026
53e1b93
sembr src/debuginfo/rust-codegen.md
tshepang Jul 20, 2026
ff8c0c5
reflow
tshepang Jul 20, 2026
5fab7f9
Prepare for merging from rust-lang/rust
invalid-email-address Jul 20, 2026
5355f97
Merge ref '9e71b3bc704e' from rust-lang/rust
invalid-email-address Jul 20, 2026
890741b
lighter markup
tshepang Jul 20, 2026
d6be727
use sentence case for titles
tshepang Jul 20, 2026
147ffe4
fix section title
tshepang Jul 20, 2026
1064b07
it will happen when it does
tshepang Jul 20, 2026
6af6107
use sentence case for titles
tshepang Jul 20, 2026
df163d8
sembr src/debuginfo/debugger-internals.md
tshepang Jul 20, 2026
3b999ca
bless batch
zedddie Jul 19, 2026
7ff730b
run `tests/assembly-llvm/asm/aarch64-types.rs` for `aarch64_be`
folkertdev Jul 21, 2026
9715950
Merge pull request #2934 from rust-lang/rustc-pull
tshepang Jul 22, 2026
fe94080
tests: add UI test for `.swap()` suggestion
senthilnathaa3 Jul 22, 2026
d548240
fix: add comment on top of test file to follow style spec
senthilnathaa3 Jul 23, 2026
f468568
reflow
tshepang Jul 23, 2026
31f2f15
sembr src/debuginfo/lldb-internals.md
tshepang Jul 23, 2026
225b77c
reflow
tshepang Jul 23, 2026
7b10686
sembr src/debuginfo/debugger-visualizers.md
tshepang Jul 23, 2026
7000c2a
reflow
tshepang Jul 23, 2026
b0f5d97
sembr src/debuginfo/gdb-internals.md
tshepang Jul 23, 2026
ca59dd7
sembr src/debuginfo/llvm-codegen.md
tshepang Jul 23, 2026
1bb944b
Prepare for merging from rust-lang/rust
invalid-email-address Jul 23, 2026
2ebc7ef
Merge pull request #2940 from rust-lang/tshepang/misc
tshepang Jul 23, 2026
bd101bb
Merge ref '390279b302ca' from rust-lang/rust
invalid-email-address Jul 23, 2026
de87ba1
Merge pull request #2941 from rust-lang/rustc-pull
tshepang Jul 23, 2026
e9ad00c
Remove 'static requirement on try_as_dyn
oli-obk Dec 16, 2025
b111aec
Add helper trait that restricts lifetimes and extra predicates to ens…
oli-obk Jan 13, 2026
e948729
the fixme is outdated as we eagerly normalize outside of the trait so…
chenyukang Jul 23, 2026
afb2e9c
use `minicore::simd::Simd` more
folkertdev Jul 23, 2026
7490d8e
add `difference` method to `range_set`
folkertdev Jul 17, 2026
0d2986a
add LLVM baseline test
folkertdev Jul 17, 2026
ff3b181
the tag is not padding
folkertdev Jul 17, 2026
91fe378
refactor
folkertdev Jul 17, 2026
7460074
clear the variant-dependent padding
folkertdev Jul 17, 2026
6574ec2
Add test for two cases 1. const argument expression 2. const argument…
Shourya742 Jun 27, 2026
899387f
make sure to emit error during hir_lowering for const statics
Shourya742 Jul 11, 2026
b4c60f0
add macroless_generic_const_args as feature
Shourya742 Jul 23, 2026
a6d0a76
Remove deref outdated workaround for `P` type
panstromek Jul 23, 2026
baffab0
rustfmt fix: ignore file not found errors for external mods with cust…
ytmimi Jul 22, 2026
bdd6ca8
use lowest edition the test accepts
tshepang Jul 23, 2026
cd9fd52
bless batch
zedddie Jul 16, 2026
d1c3582
handle bound vars in rpit method chain suggestion
sjwang05 Jul 23, 2026
020394d
Rollup merge of #150161 - oli-obk:try_as_dyn_non_static, r=BoxyUwU
jhpratt Jul 23, 2026
445d600
Rollup merge of #159412 - zedddie:gsoc-batch-26-meow, r=Kivooeo
jhpratt Jul 23, 2026
a2cc15f
Rollup merge of #159466 - folkertdev:clear-variant-dependent-padding,…
jhpratt Jul 23, 2026
9e78c8b
Rollup merge of #157905 - zachs18:randomize-layout-zst-note, r=davidtwco
jhpratt Jul 23, 2026
ef41fda
Rollup merge of #158479 - Shourya742:2026-06-27-emit-error-during-ast…
jhpratt Jul 23, 2026
f12d654
Rollup merge of #159041 - zedddie:gsoc-batch-22-meow, r=Kivooeo
jhpratt Jul 23, 2026
6f83dd2
Rollup merge of #159108 - zedddie:gsoc-batch-23-meow, r=Kivooeo
jhpratt Jul 23, 2026
9497ae7
Rollup merge of #159138 - kn1g78:doc-wasm-symbol-mangling, r=davidtwco
jhpratt Jul 23, 2026
ab0ec83
Rollup merge of #159531 - zedddie:gsoc-batch-28-meow, r=Kivooeo
jhpratt Jul 23, 2026
ace4ff7
Rollup merge of #159608 - dianqk:hoist-in-early-else, r=davidtwco
jhpratt Jul 23, 2026
b8e8ffb
Rollup merge of #159612 - zedddie:gsoc-batch-29-meow, r=Teapot4195
jhpratt Jul 23, 2026
087a886
Rollup merge of #159653 - folkertdev:aarch64_be-asm-types, r=davidtwco
jhpratt Jul 23, 2026
c1758b6
Rollup merge of #159719 - ssenthilnathan3:ui-test/add-suggest-swap, r…
jhpratt Jul 23, 2026
e701378
Rollup merge of #159737 - ytmimi:rustfmt_issue_6959, r=petrochenkov
jhpratt Jul 23, 2026
4a3d173
Rollup merge of #159759 - tshepang:rdg-sync, r=tshepang
jhpratt Jul 23, 2026
6fba6b1
Rollup merge of #159761 - chenyukang:yukang-remove-outdated-comment-i…
jhpratt Jul 23, 2026
85fbe5a
Rollup merge of #159764 - folkertdev:use-minicore-simd, r=jieyouxu
jhpratt Jul 23, 2026
2c7069c
Rollup merge of #159773 - panstromek:remove-p-workaround, r=fee1-dead
jhpratt Jul 23, 2026
8eb1150
Rollup merge of #159778 - tshepang:patch-2, r=fee1-dead
jhpratt Jul 23, 2026
fad9bb7
Rollup merge of #159788 - sjwang05:issue-159685, r=fee1-dead
jhpratt Jul 23, 2026
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
5 changes: 5 additions & 0 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
// the field ordering to try and catch some code making assumptions about layouts
// we don't guarantee.
// In the future, we might do more than shuffle field order (e.g. introduce extra padding),
// but never for `repr(Rust)` structs with only zero-sized fields, single-variant
// `repr(Rust)` enums with only zero-sized fields, or zero-variant `repr(Rust)` enums,
// which must remain zero-sized as per T-lang decisions in
// https://github.com/rust-lang/reference/pull/2262 and https://github.com/rust-lang/reference/pull/2293
if repr.can_randomize_type_layout() && cfg!(feature = "randomize") {
#[cfg(feature = "randomize")]
{
Expand Down
123 changes: 93 additions & 30 deletions compiler/rustc_abi/src/layout/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,35 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
found
}

/// Whether this type/layout has any padding that is dependent on a variant, i.e. has bytes that
/// are padding for some, but not all, valid values of this type.
pub fn has_variant_dependent_padding<C>(&self, cx: &C) -> bool
where
Ty: TyAbiInterface<'a, C> + Copy,
{
match self.variants {
Variants::Multiple { .. } => true,
Variants::Empty => false,
Variants::Single { .. } => match &self.fields {
FieldsShape::Primitive | FieldsShape::Union(_) => false,
FieldsShape::Array { count, .. } => {
*count > 0 && self.field(cx, 0).has_variant_dependent_padding(cx)
}
FieldsShape::Arbitrary { offsets, .. } => {
(0..offsets.len()).any(|i| self.field(cx, i).has_variant_dependent_padding(cx))
}
},
}
}

/// The ranges of bytes that are always ignored by the representation relation of this type.
///
/// In other words, for any sequence of bytes, if we reset the these padding bytes to uninit,
/// then these two sequences of bytes represent the same value (or they are both invalid).
/// This is the "guaranteed" padding. There may be more bytes that are padding for some
/// but not all variants of this type; those are not included.
/// (E.g. `Option<i8>` has no guaranteed padding so the empty range set is returned, but its `None` value still has padding).
pub fn padding_ranges<C>(&self, cx: &C) -> Vec<Range<Size>>
pub fn variant_independent_padding_ranges<C>(&self, cx: &C) -> Vec<Range<Size>>
where
Ty: TyAbiInterface<'a, C> + Copy,
{
Expand All @@ -316,6 +337,45 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
uninit_ranges
}

/// The ranges of bytes that are ignored by the representation relation of this variant.
///
/// The result does not include variant-independent padding.
pub fn variant_dependent_padding_ranges<C>(
&self,
cx: &C,
variant_index: VariantIdx,
) -> Vec<Range<Size>>
where
Ty: TyAbiInterface<'a, C> + Copy,
{
let Variants::Multiple { .. } = self.variants else {
return Vec::new();
};

// Bytes that are data in some variant.
let mut any = RangeSet::new();
self.add_data_ranges(cx, Size::ZERO, &mut any);

// Bytes that are data in this variant.
let mut this = RangeSet::new();

// The variants do not contain e.g. the discriminant or coroutine upvars.
let FieldsShape::Arbitrary { offsets, in_memory_order: _ } = &self.fields else {
unreachable!("a multi-variant layout should have `Arbitrary` fields")
};

// So add them explicitly.
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, offset, &mut this);
}

self.for_variant(cx, variant_index).add_data_ranges(cx, Size::ZERO, &mut this);

// Padding specific to this variant: data in some variant, but not in this one.
any.difference(&this).0.iter().map(|&(offset, size)| offset..offset + size).collect()
}

/// Extend `out` with all ranges of bytes that *may* carry relevant data for values of this type.
/// For enums and unions there are offsets that are initialized for some
/// variants but not for others; those offset *will* get added to `out`.
Expand All @@ -327,39 +387,42 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
return;
}

match &self.variants {
Variants::Empty => { /* done */ }
Variants::Single { index: _ } => match &self.fields {
FieldsShape::Primitive => {
out.add_range(base_offset, self.size);
}
&FieldsShape::Union(field_count) => {
for field in 0..field_count.get() {
let field = self.field(cx, field);
field.add_data_ranges(cx, base_offset, out);
}
// Visit the fields of this value. For enum values the fields include the discriminant.
match &self.fields {
FieldsShape::Primitive => {
out.add_range(base_offset, self.size);
}
&FieldsShape::Union(field_count) => {
for field in 0..field_count.get() {
let field = self.field(cx, field);
field.add_data_ranges(cx, base_offset, out);
}
&FieldsShape::Array { stride, count } => {
let elem = self.field(cx, 0);

// For scalars we know there is no padding between the elements,
// so the entire array is a single big data range.
if elem.backend_repr.is_scalar() {
out.add_range(base_offset, elem.size * count);
} else {
// FIXME: this is really inefficient for large arrays.
for idx in 0..count {
elem.add_data_ranges(cx, base_offset + idx * stride, out);
}
}
&FieldsShape::Array { stride, count } => {
let elem = self.field(cx, 0);

// For scalars we know there is no padding between the elements,
// so the entire array is a single big data range.
if elem.backend_repr.is_scalar() {
out.add_range(base_offset, elem.size * count);
} else {
// FIXME: this is really inefficient for large arrays.
for idx in 0..count {
elem.add_data_ranges(cx, base_offset + idx * stride, out);
}
}
FieldsShape::Arbitrary { offsets, in_memory_order: _ } => {
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, base_offset + offset, out);
}
}
FieldsShape::Arbitrary { offsets, in_memory_order: _ } => {
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, base_offset + offset, out);
}
},
}
}

// Visit the fields of each variant.
match &self.variants {
Variants::Empty | Variants::Single { index: _ } => { /* done */ }
Variants::Multiple { variants, .. } => {
for variant in variants.indices() {
let variant = self.for_variant(cx, variant);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bitflags! {
/// If true, the type's crate has opted into layout randomization.
/// Other flags can still inhibit reordering and thus randomization.
/// The seed stored in `ReprOptions.field_shuffle_seed`.
///
/// `repr(Rust)` structs with only zero-sized fields, single-variant `repr(Rust)` enums with only
/// zero-sized fields, and zero-variant `repr(Rust)` enums must remain zero-sized as per
/// T-lang decisions in https://github.com/rust-lang/reference/pull/2262 and https://github.com/rust-lang/reference/pull/2293
const RANDOMIZE_LAYOUT = 1 << 4;
/// If true, the type is always passed indirectly by non-Rustic ABIs.
/// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
Expand Down
Loading
Loading