Skip to content

Commit 3e7035f

Browse files
committed
Auto merge of rust-lang#94690 - nnethercote:clarify-Layout-interning, r=fee1-dead
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. r? `@fee1-dead`
2 parents 0e36868 + d35fc85 commit 3e7035f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/intrinsic/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,20 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
272272
use rustc_target::abi::Abi::*;
273273
let tp_ty = substs.type_at(0);
274274
let layout = self.layout_of(tp_ty).layout;
275-
let _use_integer_compare = match layout.abi {
275+
let _use_integer_compare = match layout.abi() {
276276
Scalar(_) | ScalarPair(_, _) => true,
277277
Uninhabited | Vector { .. } => false,
278278
Aggregate { .. } => {
279279
// For rusty ABIs, small aggregates are actually passed
280280
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
281281
// so we re-use that same threshold here.
282-
layout.size <= self.data_layout().pointer_size * 2
282+
layout.size() <= self.data_layout().pointer_size * 2
283283
}
284284
};
285285

286286
let a = args[0].immediate();
287287
let b = args[1].immediate();
288-
if layout.size.bytes() == 0 {
288+
if layout.size().bytes() == 0 {
289289
self.const_bool(true)
290290
}
291291
/*else if use_integer_compare {
@@ -301,7 +301,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
301301
let void_ptr_type = self.context.new_type::<*const ()>();
302302
let a_ptr = self.bitcast(a, void_ptr_type);
303303
let b_ptr = self.bitcast(b, void_ptr_type);
304-
let n = self.context.new_cast(None, self.const_usize(layout.size.bytes()), self.sizet_type);
304+
let n = self.context.new_cast(None, self.const_usize(layout.size().bytes()), self.sizet_type);
305305
let builtin = self.context.get_builtin_function("memcmp");
306306
let cmp = self.context.new_call(None, builtin, &[a_ptr, b_ptr, n]);
307307
self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0))

0 commit comments

Comments
 (0)