Skip to content

Commit 3ef6170

Browse files
committed
Remove CPlace::NoPlace
1 parent 53307fd commit 3ef6170

File tree

6 files changed

+21
-47
lines changed

6 files changed

+21
-47
lines changed

src/abi/comments.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub(super) fn add_local_place_comments<'tcx>(
7676
assert_eq!(local, var);
7777
("ssa", std::borrow::Cow::Borrowed(""))
7878
}
79-
CPlaceInner::NoPlace => ("zst", "".into()),
8079
CPlaceInner::Addr(ptr, meta) => {
8180
let meta = if let Some(meta) = meta {
8281
Cow::Owned(format!(",meta={}", meta))

src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ pub(crate) fn codegen_drop<'tcx>(
657657
let drop_fn_ty = drop_fn.monomorphic_ty(fx.tcx);
658658
match ty.kind {
659659
ty::Dynamic(..) => {
660-
let (ptr, vtable) = drop_place.to_ptr_maybe_unsized(fx);
660+
let (ptr, vtable) = drop_place.to_ptr_maybe_unsized();
661661
let ptr = ptr.get_addr(fx);
662662
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
663663

src/abi/returning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
7070
let return_ptr = match output_pass_mode {
7171
PassMode::NoPass => None,
7272
PassMode::ByRef { sized: true } => match ret_place {
73-
Some(ret_place) => Some(ret_place.to_ptr(fx).get_addr(fx)),
73+
Some(ret_place) => Some(ret_place.to_ptr().get_addr(fx)),
7474
None => Some(fx.bcx.ins().iconst(fx.pointer_type, 43)),
7575
},
7676
PassMode::ByRef { sized: false } => todo!(),

src/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ fn codegen_array_len<'tcx>(
730730
fx.bcx.ins().iconst(fx.pointer_type, len)
731731
}
732732
ty::Slice(_elem_ty) => place
733-
.to_ptr_maybe_unsized(fx)
733+
.to_ptr_maybe_unsized()
734734
.1
735735
.expect("Length metadata for slice place"),
736736
_ => bug!("Rvalue::Len({:?})", place),
@@ -776,7 +776,7 @@ pub(crate) fn trans_place<'tcx>(
776776
ty::Array(elem_ty, _len) => {
777777
assert!(!from_end, "array subslices are never `from_end`");
778778
let elem_layout = fx.layout_of(elem_ty);
779-
let ptr = cplace.to_ptr(fx);
779+
let ptr = cplace.to_ptr();
780780
cplace = CPlace::for_ptr(
781781
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
782782
fx.layout_of(fx.tcx.mk_array(elem_ty, to as u64 - from as u64)),
@@ -785,7 +785,7 @@ pub(crate) fn trans_place<'tcx>(
785785
ty::Slice(elem_ty) => {
786786
assert!(from_end, "slice subslices should be `from_end`");
787787
let elem_layout = fx.layout_of(elem_ty);
788-
let (ptr, len) = cplace.to_ptr_maybe_unsized(fx);
788+
let (ptr, len) = cplace.to_ptr_maybe_unsized();
789789
let len = len.unwrap();
790790
cplace = CPlace::for_ptr_with_extra(
791791
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),

src/debuginfo/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ fn place_location<'a, 'tcx>(
348348
// For PointerBase::Stack:
349349
//AttributeValue::Exprloc(Expression(translate_loc(ValueLoc::Stack(*stack_slot), &context.func.stack_slots).unwrap()))
350350
}
351-
CPlaceInner::NoPlace => AttributeValue::Exprloc(Expression(vec![])),
352351
}
353352
}
354353

src/value_and_place.rs

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> CValue<'tcx> {
100100
CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => {
101101
let cplace = CPlace::new_stack_slot(fx, layout);
102102
cplace.write_cvalue(fx, self);
103-
(cplace.to_ptr(fx), None)
103+
(cplace.to_ptr(), None)
104104
}
105105
}
106106
}
@@ -259,7 +259,6 @@ pub(crate) struct CPlace<'tcx> {
259259
pub(crate) enum CPlaceInner {
260260
Var(Local),
261261
Addr(Pointer, Option<Value>),
262-
NoPlace,
263262
}
264263

265264
impl<'tcx> CPlace<'tcx> {
@@ -273,7 +272,7 @@ impl<'tcx> CPlace<'tcx> {
273272

274273
pub(crate) fn no_place(layout: TyAndLayout<'tcx>) -> CPlace<'tcx> {
275274
CPlace {
276-
inner: CPlaceInner::NoPlace,
275+
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
277276
layout,
278277
}
279278
}
@@ -284,10 +283,7 @@ impl<'tcx> CPlace<'tcx> {
284283
) -> CPlace<'tcx> {
285284
assert!(!layout.is_unsized());
286285
if layout.size.bytes() == 0 {
287-
return CPlace {
288-
inner: CPlaceInner::NoPlace,
289-
layout,
290-
};
286+
return CPlace::no_place(layout);
291287
}
292288

293289
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
@@ -343,33 +339,20 @@ impl<'tcx> CPlace<'tcx> {
343339
CValue::by_ref(ptr, layout)
344340
}
345341
}
346-
CPlaceInner::NoPlace => CValue::by_ref(
347-
Pointer::dangling(self.layout.align.pref),
348-
layout,
349-
),
350342
}
351343
}
352344

353-
pub(crate) fn to_ptr(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Pointer {
354-
match self.to_ptr_maybe_unsized(fx) {
345+
pub(crate) fn to_ptr(self) -> Pointer {
346+
match self.to_ptr_maybe_unsized() {
355347
(ptr, None) => ptr,
356348
(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self),
357349
}
358350
}
359351

360-
pub(crate) fn to_ptr_maybe_unsized(
361-
self,
362-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
363-
) -> (Pointer, Option<Value>) {
352+
pub(crate) fn to_ptr_maybe_unsized(self) -> (Pointer, Option<Value>) {
364353
match self.inner {
365354
CPlaceInner::Addr(ptr, extra) => (ptr, extra),
366-
CPlaceInner::NoPlace => {
367-
(
368-
Pointer::const_addr(fx, i64::try_from(self.layout.align.pref.bytes()).unwrap()),
369-
None,
370-
)
371-
}
372-
CPlaceInner::Var(_) => bug!("Expected CPlace::Addr, found CPlace::Var"),
355+
CPlaceInner::Var(_) => bug!("Expected CPlace::Addr, found {:?}", self),
373356
}
374357
}
375358

@@ -460,12 +443,11 @@ impl<'tcx> CPlace<'tcx> {
460443
fx.bcx.def_var(mir_var(var), data);
461444
return;
462445
}
463-
CPlaceInner::Addr(ptr, None) => ptr,
464-
CPlaceInner::NoPlace => {
465-
if dst_layout.abi != Abi::Uninhabited {
466-
assert_eq!(dst_layout.size.bytes(), 0, "{:?}", dst_layout);
446+
CPlaceInner::Addr(ptr, None) => {
447+
if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited {
448+
return;
467449
}
468-
return;
450+
ptr
469451
}
470452
CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self),
471453
};
@@ -524,7 +506,7 @@ impl<'tcx> CPlace<'tcx> {
524506
field: mir::Field,
525507
) -> CPlace<'tcx> {
526508
let layout = self.layout();
527-
let (base, extra) = self.to_ptr_maybe_unsized(fx);
509+
let (base, extra) = self.to_ptr_maybe_unsized();
528510

529511
let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field);
530512
if field_layout.is_unsized() {
@@ -540,8 +522,8 @@ impl<'tcx> CPlace<'tcx> {
540522
index: Value,
541523
) -> CPlace<'tcx> {
542524
let (elem_layout, ptr) = match self.layout().ty.kind {
543-
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.to_ptr(fx)),
544-
ty::Slice(elem_ty) => (fx.layout_of(elem_ty), self.to_ptr_maybe_unsized(fx).0),
525+
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.to_ptr()),
526+
ty::Slice(elem_ty) => (fx.layout_of(elem_ty), self.to_ptr_maybe_unsized().0),
545527
_ => bug!("place_index({:?})", self.layout().ty),
546528
};
547529

@@ -565,27 +547,21 @@ impl<'tcx> CPlace<'tcx> {
565547

566548
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
567549
if has_ptr_meta(fx.tcx, self.layout().ty) {
568-
let (ptr, extra) = self.to_ptr_maybe_unsized(fx);
550+
let (ptr, extra) = self.to_ptr_maybe_unsized();
569551
let ptr = CValue::by_val_pair(
570552
ptr.get_addr(fx),
571553
extra.expect("unsized type without metadata"),
572554
dest.layout(),
573555
);
574556
dest.write_cvalue(fx, ptr);
575557
} else {
576-
let ptr = CValue::by_val(self.to_ptr(fx).get_addr(fx), dest.layout());
558+
let ptr = CValue::by_val(self.to_ptr().get_addr(fx), dest.layout());
577559
dest.write_cvalue(fx, ptr);
578560
}
579561
}
580562

581563
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
582564
assert!(!self.layout().is_unsized());
583-
match self.inner {
584-
CPlaceInner::NoPlace => {
585-
assert!(layout.size.bytes() == 0);
586-
}
587-
_ => {}
588-
}
589565
CPlace {
590566
inner: self.inner,
591567
layout,

0 commit comments

Comments
 (0)