Skip to content

Commit

Permalink
Rollup merge of #99973 - RalfJung:layout-things, r=eddyb
Browse files Browse the repository at this point in the history
Layout things

These two commits are pretty independent, but didn't seem worth doing individual PRs for:
- Always check that size is a multiple of align, even without debug assertions
- Change Layout debug printing to put `variants` last, since it often huge and not usually the part we are most interested in

Cc `@eddyb`
  • Loading branch information
matthiaskrgr committed Jul 31, 2022
2 parents c98e893 + abd80d9 commit 549463f
Show file tree
Hide file tree
Showing 8 changed files with 931 additions and 926 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ fn sanity_check_layout<'tcx>(
assert!(layout.abi.is_uninhabited());
}

if layout.size.bytes() % layout.align.abi.bytes() != 0 {
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
}

if cfg!(debug_assertions) {
fn check_layout_abi<'tcx>(tcx: TyCtxt<'tcx>, layout: Layout<'tcx>) {
match layout.abi() {
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,14 @@ impl<'a> fmt::Debug for LayoutS<'a> {
// This is how `Layout` used to print before it become
// `Interned<LayoutS>`. We print it like this to avoid having to update
// expected output in a lot of tests.
let LayoutS { size, align, abi, fields, largest_niche, variants } = self;
f.debug_struct("Layout")
.field("fields", &self.fields)
.field("variants", &self.variants)
.field("abi", &self.abi)
.field("largest_niche", &self.largest_niche)
.field("align", &self.align)
.field("size", &self.size)
.field("size", size)
.field("align", align)
.field("abi", abi)
.field("fields", fields)
.field("largest_niche", largest_niche)
.field("variants", variants)
.finish()
}
}
Expand Down
Loading

0 comments on commit 549463f

Please sign in to comment.