Skip to content

Commit 8723fe0

Browse files
committed
Clarify Layout interning.
`Layout` is another type that is sometimes interned, sometimes not, and we always use references to refer to it so we can't take any advantage of the uniqueness properties for hashing or equality checks. This commit renames `Layout` as `LayoutS`, and then introduces a new `Layout` that is a newtype around an `Interned<LayoutS>`. It also interns more layouts than before. Previously layouts within layouts (via the `variants` field) were never interned, but now they are. Hence the lifetime on the new `Layout` type. Unlike other interned types, these ones are in `rustc_target` instead of `rustc_middle`. This reflects the existing structure of the code, which does layout-specific stuff in `rustc_target` while `TyAndLayout` is generic over the `Ty`, allowing the type-specific stuff to occur in `rustc_middle`. The commit also adds a `HashStable` impl for `Interned`, which was needed. It hashes the contents, unlike the `Hash` impl which hashes the pointer.
1 parent 7c1a318 commit 8723fe0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/abi/comments.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ pub(super) fn add_local_place_comments<'tcx>(
8282
return;
8383
}
8484
let TyAndLayout { ty, layout } = place.layout();
85-
let rustc_target::abi::Layout { size, align, abi: _, variants: _, fields: _, largest_niche: _ } =
86-
layout;
85+
let rustc_target::abi::LayoutS {
86+
size,
87+
align,
88+
abi: _,
89+
variants: _,
90+
fields: _,
91+
largest_niche: _,
92+
} = layout.0.0;
8793

8894
let (kind, extra) = match *place.inner() {
8995
CPlaceInner::Var(place_local, var) => {

src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10701070
};
10711071

10721072
raw_eq, (v lhs_ref, v rhs_ref) {
1073-
let size = fx.layout_of(substs.type_at(0)).layout.size;
1073+
let size = fx.layout_of(substs.type_at(0)).layout.size();
10741074
// FIXME add and use emit_small_memcmp
10751075
let is_eq_value =
10761076
if size == Size::ZERO {

0 commit comments

Comments
 (0)