simplify more, ret_deref -> has_deref

This commit is contained in:
ouz-a 2022-05-16 16:23:42 +03:00
parent c0e4230bf5
commit c3e1e7a947
3 changed files with 9 additions and 11 deletions

View File

@ -435,13 +435,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
LocalRef::Place(place) => place, LocalRef::Place(place) => place,
LocalRef::UnsizedPlace(place) => bx.load_operand(place).deref(cx), LocalRef::UnsizedPlace(place) => bx.load_operand(place).deref(cx),
LocalRef::Operand(..) => { LocalRef::Operand(..) => {
if place_ref.ret_deref().is_some() { if place_ref.has_deref() {
base = 1; base = 1;
let cg_base = self.codegen_consume( let cg_base = self.codegen_consume(
bx, bx,
mir::PlaceRef { projection: &place_ref.projection[..0], ..place_ref }, mir::PlaceRef { projection: &place_ref.projection[..0], ..place_ref },
); );
cg_base.deref(bx.cx()) cg_base.deref(bx.cx())
} else { } else {
bug!("using operand local {:?} as place", place_ref); bug!("using operand local {:?} as place", place_ref);

View File

@ -1463,11 +1463,11 @@ impl<'tcx> Place<'tcx> {
/// If MirPhase >= Derefered and if projection contains Deref, /// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place /// It's guaranteed to be in the first place
pub fn ret_deref(&self) -> Option<PlaceElem<'tcx>> { pub fn has_deref(&self) -> bool {
if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref { if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
return Some(self.projection[0]); true
} else { } else {
None false
} }
} }
@ -1545,11 +1545,11 @@ impl<'tcx> PlaceRef<'tcx> {
/// If MirPhase >= Derefered and if projection contains Deref, /// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place /// It's guaranteed to be in the first place
pub fn ret_deref(&self) -> Option<PlaceElem<'tcx>> { pub fn has_deref(&self) -> bool {
if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref { if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
return Some(self.projection[0]); true
} else { } else {
None false
} }
} }

View File

@ -15,7 +15,7 @@ pub struct AddRetag;
/// (Concurrent accesses by other threads are no problem as these are anyway non-atomic /// (Concurrent accesses by other threads are no problem as these are anyway non-atomic
/// copies. Data races are UB.) /// copies. Data races are UB.)
fn is_stable(place: PlaceRef<'_>) -> bool { fn is_stable(place: PlaceRef<'_>) -> bool {
if place.ret_deref().is_some() { if place.has_deref() {
// Which place this evaluates to can change with any memory write, // Which place this evaluates to can change with any memory write,
// so cannot assume deref to be stable. // so cannot assume deref to be stable.
return false; return false;
@ -83,8 +83,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
let place_base_raw = |place: &Place<'tcx>| { let place_base_raw = |place: &Place<'tcx>| {
// If this is a `Deref`, get the type of what we are deref'ing. // If this is a `Deref`, get the type of what we are deref'ing.
if place.ret_deref().is_some() { if place.ret_deref().is_some() {
let base_proj = &place.projection[..0]; let ty = place.ty(local_decls, tcx).ty;
let ty = Place::ty_from(place.local, base_proj, &*local_decls, tcx).ty;
ty.is_unsafe_ptr() ty.is_unsafe_ptr()
} else { } else {
// Not a deref, and thus not raw. // Not a deref, and thus not raw.