From 8723fe0b6b6f8563c2ca0f15c83adf309e780d2a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 4 Mar 2022 13:46:56 +1100 Subject: [PATCH] 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`. 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. --- src/abi/comments.rs | 10 ++++++++-- src/intrinsics/mod.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/abi/comments.rs b/src/abi/comments.rs index 5fbaed7283a6..37d2679c10d7 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -82,8 +82,14 @@ pub(super) fn add_local_place_comments<'tcx>( return; } let TyAndLayout { ty, layout } = place.layout(); - let rustc_target::abi::Layout { size, align, abi: _, variants: _, fields: _, largest_niche: _ } = - layout; + let rustc_target::abi::LayoutS { + size, + align, + abi: _, + variants: _, + fields: _, + largest_niche: _, + } = layout.0.0; let (kind, extra) = match *place.inner() { CPlaceInner::Var(place_local, var) => { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4dfb13476c28..6489b96be4b2 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1070,7 +1070,7 @@ fn codegen_regular_intrinsic_call<'tcx>( }; raw_eq, (v lhs_ref, v rhs_ref) { - let size = fx.layout_of(substs.type_at(0)).layout.size; + let size = fx.layout_of(substs.type_at(0)).layout.size(); // FIXME add and use emit_small_memcmp let is_eq_value = if size == Size::ZERO {