Skip to content

Commit 3740152

Browse files
committed
shrink OpTy back down to 80 bytes
1 parent ca4e394 commit 3740152

File tree

12 files changed

+205
-162
lines changed

12 files changed

+205
-162
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ pub(super) fn op_to_const<'tcx>(
116116
// instead allow `ConstValue::Scalar` to store `ScalarMaybeUninit`, but that would affect all
117117
// the usual cases of extracting e.g. a `usize`, without there being a real use case for the
118118
// `Undef` situation.
119-
let try_as_immediate = match op.layout.abi {
119+
let try_as_immediate = match op.layout().abi {
120120
Abi::Scalar(abi::Scalar::Initialized { .. }) => true,
121-
Abi::ScalarPair(..) => match op.layout.ty.kind() {
121+
Abi::ScalarPair(..) => match op.layout().ty.kind() {
122122
ty::Ref(_, inner, _) => match *inner.kind() {
123123
ty::Slice(elem) => elem == ecx.tcx.types.u8,
124124
ty::Str => true,

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
119119
.map(|i| {
120120
let field_op = ecx.operand_field(&down, i)?;
121121
let val = op_to_const(&ecx, &field_op);
122-
Ok(mir::ConstantKind::Val(val, field_op.layout.ty))
122+
Ok(mir::ConstantKind::Val(val, field_op.layout().ty))
123123
})
124124
.collect::<InterpResult<'tcx, Vec<_>>>()?;
125125
let fields = tcx.arena.alloc_from_iter(fields_iter);

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5757

5858
Pointer(PointerCast::ReifyFnPointer) => {
5959
// The src operand does not matter, just its type
60-
match *src.layout.ty.kind() {
60+
match *src.layout().ty.kind() {
6161
ty::FnDef(def_id, substs) => {
6262
// All reifications must be monomorphic, bail out otherwise.
63-
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
63+
ensure_monomorphic_enough(*self.tcx, src.layout().ty)?;
6464

6565
let instance = ty::Instance::resolve_for_fn_ptr(
6666
*self.tcx,
@@ -73,7 +73,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7373
let fn_ptr = self.create_fn_alloc_ptr(FnVal::Instance(instance));
7474
self.write_pointer(fn_ptr, dest)?;
7575
}
76-
_ => span_bug!(self.cur_span(), "reify fn pointer on {:?}", src.layout.ty),
76+
_ => span_bug!(self.cur_span(), "reify fn pointer on {:?}", src.layout().ty),
7777
}
7878
}
7979

@@ -90,10 +90,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9090

9191
Pointer(PointerCast::ClosureFnPointer(_)) => {
9292
// The src operand does not matter, just its type
93-
match *src.layout.ty.kind() {
93+
match *src.layout().ty.kind() {
9494
ty::Closure(def_id, substs) => {
9595
// All reifications must be monomorphic, bail out otherwise.
96-
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
96+
ensure_monomorphic_enough(*self.tcx, src.layout().ty)?;
9797

9898
let instance = ty::Instance::resolve_closure(
9999
*self.tcx,
@@ -105,7 +105,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
105105
let fn_ptr = self.create_fn_alloc_ptr(FnVal::Instance(instance));
106106
self.write_pointer(fn_ptr, dest)?;
107107
}
108-
_ => span_bug!(self.cur_span(), "closure fn pointer on {:?}", src.layout.ty),
108+
_ => span_bug!(self.cur_span(), "closure fn pointer on {:?}", src.layout().ty),
109109
}
110110
}
111111
}
@@ -328,7 +328,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
328328
}
329329

330330
_ => {
331-
span_bug!(self.cur_span(), "invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty)
331+
span_bug!(
332+
self.cur_span(),
333+
"invalid unsizing {:?} -> {:?}",
334+
src.layout().ty,
335+
cast_ty
336+
)
332337
}
333338
}
334339
}
@@ -339,8 +344,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
339344
cast_ty: TyAndLayout<'tcx>,
340345
dest: &PlaceTy<'tcx, M::PointerTag>,
341346
) -> InterpResult<'tcx> {
342-
trace!("Unsizing {:?} of type {} into {:?}", *src, src.layout.ty, cast_ty.ty);
343-
match (&src.layout.ty.kind(), &cast_ty.ty.kind()) {
347+
trace!("Unsizing {:?} of type {} into {:?}", *src, src.layout().ty, cast_ty.ty);
348+
match (&src.layout().ty.kind(), &cast_ty.ty.kind()) {
344349
(&ty::Ref(_, s, _), &ty::Ref(_, c, _) | &ty::RawPtr(TypeAndMut { ty: c, .. }))
345350
| (&ty::RawPtr(TypeAndMut { ty: s, .. }), &ty::RawPtr(TypeAndMut { ty: c, .. })) => {
346351
self.unsize_into_ptr(src, dest, *s, *c)
@@ -351,14 +356,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
351356
// unsizing of generic struct with pointer fields
352357
// Example: `Arc<T>` -> `Arc<Trait>`
353358
// here we need to increase the size of every &T thin ptr field to a fat ptr
354-
for i in 0..src.layout.fields.count() {
359+
for i in 0..src.layout().fields.count() {
355360
let cast_ty_field = cast_ty.field(self, i);
356361
if cast_ty_field.is_zst() {
357362
continue;
358363
}
359364
let src_field = self.operand_field(src, i)?;
360365
let dst_field = self.place_field(dest, i)?;
361-
if src_field.layout.ty == cast_ty_field.ty {
366+
if src_field.layout().ty == cast_ty_field.ty {
362367
self.copy_op(&src_field, &dst_field, /*allow_transmute*/ false)?;
363368
} else {
364369
self.unsize_into(&src_field, cast_ty_field, &dst_field)?;
@@ -369,7 +374,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
369374
_ => span_bug!(
370375
self.cur_span(),
371376
"unsize_into: invalid conversion: {:?} -> {:?}",
372-
src.layout,
377+
src.layout(),
373378
dest.layout
374379
),
375380
}

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
604604
nonoverlapping: bool,
605605
) -> InterpResult<'tcx> {
606606
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
607-
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
607+
let layout = self.layout_of(src.layout().ty.builtin_deref(true).unwrap().ty)?;
608608
let (size, align) = (layout.size, layout.align.abi);
609609
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
610610
// but no actual allocation can be big enough for the difference to be noticeable.
@@ -627,7 +627,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
627627
byte: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
628628
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
629629
) -> InterpResult<'tcx> {
630-
let layout = self.layout_of(dst.layout.ty.builtin_deref(true).unwrap().ty)?;
630+
let layout = self.layout_of(dst.layout().ty.builtin_deref(true).unwrap().ty)?;
631631

632632
let dst = self.read_pointer(&dst)?;
633633
let byte = self.read_scalar(&byte)?.to_u8()?;
@@ -649,7 +649,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
649649
lhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
650650
rhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
651651
) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
652-
let layout = self.layout_of(lhs.layout.ty.builtin_deref(true).unwrap().ty)?;
652+
let layout = self.layout_of(lhs.layout().ty.builtin_deref(true).unwrap().ty)?;
653653
assert!(!layout.is_unsized());
654654

655655
let lhs = self.read_pointer(lhs)?;

0 commit comments

Comments
 (0)