Remove CPlace::NoPlace
This commit is contained in:
parent
53307fd2e1
commit
3ef6170142
@ -76,7 +76,6 @@ pub(super) fn add_local_place_comments<'tcx>(
|
||||
assert_eq!(local, var);
|
||||
("ssa", std::borrow::Cow::Borrowed(""))
|
||||
}
|
||||
CPlaceInner::NoPlace => ("zst", "".into()),
|
||||
CPlaceInner::Addr(ptr, meta) => {
|
||||
let meta = if let Some(meta) = meta {
|
||||
Cow::Owned(format!(",meta={}", meta))
|
||||
|
@ -657,7 +657,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
let drop_fn_ty = drop_fn.monomorphic_ty(fx.tcx);
|
||||
match ty.kind {
|
||||
ty::Dynamic(..) => {
|
||||
let (ptr, vtable) = drop_place.to_ptr_maybe_unsized(fx);
|
||||
let (ptr, vtable) = drop_place.to_ptr_maybe_unsized();
|
||||
let ptr = ptr.get_addr(fx);
|
||||
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
|
||||
let return_ptr = match output_pass_mode {
|
||||
PassMode::NoPass => None,
|
||||
PassMode::ByRef { sized: true } => match ret_place {
|
||||
Some(ret_place) => Some(ret_place.to_ptr(fx).get_addr(fx)),
|
||||
Some(ret_place) => Some(ret_place.to_ptr().get_addr(fx)),
|
||||
None => Some(fx.bcx.ins().iconst(fx.pointer_type, 43)),
|
||||
},
|
||||
PassMode::ByRef { sized: false } => todo!(),
|
||||
|
@ -730,7 +730,7 @@ fn codegen_array_len<'tcx>(
|
||||
fx.bcx.ins().iconst(fx.pointer_type, len)
|
||||
}
|
||||
ty::Slice(_elem_ty) => place
|
||||
.to_ptr_maybe_unsized(fx)
|
||||
.to_ptr_maybe_unsized()
|
||||
.1
|
||||
.expect("Length metadata for slice place"),
|
||||
_ => bug!("Rvalue::Len({:?})", place),
|
||||
@ -776,7 +776,7 @@ pub(crate) fn trans_place<'tcx>(
|
||||
ty::Array(elem_ty, _len) => {
|
||||
assert!(!from_end, "array subslices are never `from_end`");
|
||||
let elem_layout = fx.layout_of(elem_ty);
|
||||
let ptr = cplace.to_ptr(fx);
|
||||
let ptr = cplace.to_ptr();
|
||||
cplace = CPlace::for_ptr(
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
|
||||
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>(
|
||||
ty::Slice(elem_ty) => {
|
||||
assert!(from_end, "slice subslices should be `from_end`");
|
||||
let elem_layout = fx.layout_of(elem_ty);
|
||||
let (ptr, len) = cplace.to_ptr_maybe_unsized(fx);
|
||||
let (ptr, len) = cplace.to_ptr_maybe_unsized();
|
||||
let len = len.unwrap();
|
||||
cplace = CPlace::for_ptr_with_extra(
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
|
||||
|
@ -348,7 +348,6 @@ fn place_location<'a, 'tcx>(
|
||||
// For PointerBase::Stack:
|
||||
//AttributeValue::Exprloc(Expression(translate_loc(ValueLoc::Stack(*stack_slot), &context.func.stack_slots).unwrap()))
|
||||
}
|
||||
CPlaceInner::NoPlace => AttributeValue::Exprloc(Expression(vec![])),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ impl<'tcx> CValue<'tcx> {
|
||||
CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => {
|
||||
let cplace = CPlace::new_stack_slot(fx, layout);
|
||||
cplace.write_cvalue(fx, self);
|
||||
(cplace.to_ptr(fx), None)
|
||||
(cplace.to_ptr(), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,6 @@ pub(crate) struct CPlace<'tcx> {
|
||||
pub(crate) enum CPlaceInner {
|
||||
Var(Local),
|
||||
Addr(Pointer, Option<Value>),
|
||||
NoPlace,
|
||||
}
|
||||
|
||||
impl<'tcx> CPlace<'tcx> {
|
||||
@ -273,7 +272,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
|
||||
pub(crate) fn no_place(layout: TyAndLayout<'tcx>) -> CPlace<'tcx> {
|
||||
CPlace {
|
||||
inner: CPlaceInner::NoPlace,
|
||||
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
|
||||
layout,
|
||||
}
|
||||
}
|
||||
@ -284,10 +283,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
) -> CPlace<'tcx> {
|
||||
assert!(!layout.is_unsized());
|
||||
if layout.size.bytes() == 0 {
|
||||
return CPlace {
|
||||
inner: CPlaceInner::NoPlace,
|
||||
layout,
|
||||
};
|
||||
return CPlace::no_place(layout);
|
||||
}
|
||||
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
@ -343,33 +339,20 @@ impl<'tcx> CPlace<'tcx> {
|
||||
CValue::by_ref(ptr, layout)
|
||||
}
|
||||
}
|
||||
CPlaceInner::NoPlace => CValue::by_ref(
|
||||
Pointer::dangling(self.layout.align.pref),
|
||||
layout,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_ptr(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Pointer {
|
||||
match self.to_ptr_maybe_unsized(fx) {
|
||||
pub(crate) fn to_ptr(self) -> Pointer {
|
||||
match self.to_ptr_maybe_unsized() {
|
||||
(ptr, None) => ptr,
|
||||
(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_ptr_maybe_unsized(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||
) -> (Pointer, Option<Value>) {
|
||||
pub(crate) fn to_ptr_maybe_unsized(self) -> (Pointer, Option<Value>) {
|
||||
match self.inner {
|
||||
CPlaceInner::Addr(ptr, extra) => (ptr, extra),
|
||||
CPlaceInner::NoPlace => {
|
||||
(
|
||||
Pointer::const_addr(fx, i64::try_from(self.layout.align.pref.bytes()).unwrap()),
|
||||
None,
|
||||
)
|
||||
}
|
||||
CPlaceInner::Var(_) => bug!("Expected CPlace::Addr, found CPlace::Var"),
|
||||
CPlaceInner::Var(_) => bug!("Expected CPlace::Addr, found {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,12 +443,11 @@ impl<'tcx> CPlace<'tcx> {
|
||||
fx.bcx.def_var(mir_var(var), data);
|
||||
return;
|
||||
}
|
||||
CPlaceInner::Addr(ptr, None) => ptr,
|
||||
CPlaceInner::NoPlace => {
|
||||
if dst_layout.abi != Abi::Uninhabited {
|
||||
assert_eq!(dst_layout.size.bytes(), 0, "{:?}", dst_layout);
|
||||
CPlaceInner::Addr(ptr, None) => {
|
||||
if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
ptr
|
||||
}
|
||||
CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self),
|
||||
};
|
||||
@ -524,7 +506,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
field: mir::Field,
|
||||
) -> CPlace<'tcx> {
|
||||
let layout = self.layout();
|
||||
let (base, extra) = self.to_ptr_maybe_unsized(fx);
|
||||
let (base, extra) = self.to_ptr_maybe_unsized();
|
||||
|
||||
let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field);
|
||||
if field_layout.is_unsized() {
|
||||
@ -540,8 +522,8 @@ impl<'tcx> CPlace<'tcx> {
|
||||
index: Value,
|
||||
) -> CPlace<'tcx> {
|
||||
let (elem_layout, ptr) = match self.layout().ty.kind {
|
||||
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.to_ptr(fx)),
|
||||
ty::Slice(elem_ty) => (fx.layout_of(elem_ty), self.to_ptr_maybe_unsized(fx).0),
|
||||
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.to_ptr()),
|
||||
ty::Slice(elem_ty) => (fx.layout_of(elem_ty), self.to_ptr_maybe_unsized().0),
|
||||
_ => bug!("place_index({:?})", self.layout().ty),
|
||||
};
|
||||
|
||||
@ -565,7 +547,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
|
||||
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
|
||||
if has_ptr_meta(fx.tcx, self.layout().ty) {
|
||||
let (ptr, extra) = self.to_ptr_maybe_unsized(fx);
|
||||
let (ptr, extra) = self.to_ptr_maybe_unsized();
|
||||
let ptr = CValue::by_val_pair(
|
||||
ptr.get_addr(fx),
|
||||
extra.expect("unsized type without metadata"),
|
||||
@ -573,19 +555,13 @@ impl<'tcx> CPlace<'tcx> {
|
||||
);
|
||||
dest.write_cvalue(fx, ptr);
|
||||
} else {
|
||||
let ptr = CValue::by_val(self.to_ptr(fx).get_addr(fx), dest.layout());
|
||||
let ptr = CValue::by_val(self.to_ptr().get_addr(fx), dest.layout());
|
||||
dest.write_cvalue(fx, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
|
||||
assert!(!self.layout().is_unsized());
|
||||
match self.inner {
|
||||
CPlaceInner::NoPlace => {
|
||||
assert!(layout.size.bytes() == 0);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
CPlace {
|
||||
inner: self.inner,
|
||||
layout,
|
||||
|
Loading…
x
Reference in New Issue
Block a user