diff options
| author | bors <bors@rust-lang.org> | 2025-08-29 03:40:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-29 03:40:14 +0000 |
| commit | 41f2b6b39e7526a28d50ff6918dda6de48add5e4 (patch) | |
| tree | 75ea6c2437c22ed02fa6f4491d018b4a7f724a89 /compiler/rustc_abi/src/layout.rs | |
| parent | ef8d1d6f5bf59524a22943d9f64c002e5c883afd (diff) | |
| parent | 31eafafe3b706dcc5094c1a80d8a6cdcf91f2bac (diff) | |
| download | rust-41f2b6b39e7526a28d50ff6918dda6de48add5e4.tar.gz rust-41f2b6b39e7526a28d50ff6918dda6de48add5e4.zip | |
Auto merge of #145978 - Zalathar:rollup-0dzk72g, r=Zalathar
Rollup of 9 pull requests Successful merges: - rust-lang/rust#143713 (Add a mailmap entry for gnzlbg) - rust-lang/rust#144275 (implement Sum and Product for Saturating(u*)) - rust-lang/rust#144354 (fix(std): Fix undefined reference to __my_thread_exit on QNX 8.0) - rust-lang/rust#145387 (Remove TmpLayout in layout_of_enum) - rust-lang/rust#145793 (std library: use execinfo library also on NetBSD.) - rust-lang/rust#145884 (Test `instrument-mcount` codegen) - rust-lang/rust#145947 (Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml`) - rust-lang/rust#145972 (fix `core::marker::Destruct` doc) - rust-lang/rust#145977 (tests: Ignore basic-stepping.rs on riscv64) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_abi/src/layout.rs')
| -rw-r--r-- | compiler/rustc_abi/src/layout.rs | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index c2405553756..5004d0c8022 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -594,23 +594,13 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool), discriminants: impl Iterator<Item = (VariantIdx, i128)>, ) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> { - // Until we've decided whether to use the tagged or - // niche filling LayoutData, we don't want to intern the - // variant layouts, so we can't store them in the - // overall LayoutData. Store the overall LayoutData - // and the variant LayoutDatas here until then. - struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> { - layout: LayoutData<FieldIdx, VariantIdx>, - variants: IndexVec<VariantIdx, LayoutData<FieldIdx, VariantIdx>>, - } - let dl = self.cx.data_layout(); // bail if the enum has an incoherent repr that cannot be computed if repr.packed() { return Err(LayoutCalculatorError::ReprConflict); } - let calculate_niche_filling_layout = || -> Option<TmpLayout<FieldIdx, VariantIdx>> { + let calculate_niche_filling_layout = || -> Option<LayoutData<FieldIdx, VariantIdx>> { if repr.inhibit_enum_layout_opt() { return None; } @@ -746,7 +736,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { niche_start, }, tag_field: FieldIdx::new(0), - variants: IndexVec::new(), + variants: variant_layouts, }, fields: FieldsShape::Arbitrary { offsets: [niche_offset].into(), @@ -762,7 +752,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { randomization_seed: combined_seed, }; - Some(TmpLayout { layout, variants: variant_layouts }) + Some(layout) }; let niche_filling_layout = calculate_niche_filling_layout(); @@ -1093,7 +1083,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { tag, tag_encoding: TagEncoding::Direct, tag_field: FieldIdx::new(0), - variants: IndexVec::new(), + variants: layout_variants, }, fields: FieldsShape::Arbitrary { offsets: [Size::ZERO].into(), @@ -1109,18 +1099,16 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { randomization_seed: combined_seed, }; - let tagged_layout = TmpLayout { layout: tagged_layout, variants: layout_variants }; - - let mut best_layout = match (tagged_layout, niche_filling_layout) { + let best_layout = match (tagged_layout, niche_filling_layout) { (tl, Some(nl)) => { // Pick the smaller layout; otherwise, // pick the layout with the larger niche; otherwise, // pick tagged as it has simpler codegen. use cmp::Ordering::*; - let niche_size = |tmp_l: &TmpLayout<FieldIdx, VariantIdx>| { - tmp_l.layout.largest_niche.map_or(0, |n| n.available(dl)) + let niche_size = |l: &LayoutData<FieldIdx, VariantIdx>| { + l.largest_niche.map_or(0, |n| n.available(dl)) }; - match (tl.layout.size.cmp(&nl.layout.size), niche_size(&tl).cmp(&niche_size(&nl))) { + match (tl.size.cmp(&nl.size), niche_size(&tl).cmp(&niche_size(&nl))) { (Greater, _) => nl, (Equal, Less) => nl, _ => tl, @@ -1129,16 +1117,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { (tl, None) => tl, }; - // Now we can intern the variant layouts and store them in the enum layout. - best_layout.layout.variants = match best_layout.layout.variants { - Variants::Multiple { tag, tag_encoding, tag_field, .. } => { - Variants::Multiple { tag, tag_encoding, tag_field, variants: best_layout.variants } - } - Variants::Single { .. } | Variants::Empty => { - panic!("encountered a single-variant or empty enum during multi-variant layout") - } - }; - Ok(best_layout.layout) + Ok(best_layout) } fn univariant_biased< |
