From c0e4230bf5596d83d61c7a4ca5b06f0490ac4dba Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 12 May 2022 00:27:06 +0300 Subject: simplify some code that depend on Deref --- compiler/rustc_codegen_ssa/src/mir/place.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 58cee0c8bb0..38e09f539de 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -435,16 +435,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { LocalRef::Place(place) => place, LocalRef::UnsizedPlace(place) => bx.load_operand(place).deref(cx), LocalRef::Operand(..) => { - if let Some(elem) = place_ref - .projection - .iter() - .enumerate() - .find(|elem| matches!(elem.1, mir::ProjectionElem::Deref)) - { - base = elem.0 + 1; + if place_ref.ret_deref().is_some() { + base = 1; let cg_base = self.codegen_consume( bx, - mir::PlaceRef { projection: &place_ref.projection[..elem.0], ..place_ref }, + mir::PlaceRef { projection: &place_ref.projection[..0], ..place_ref }, ); cg_base.deref(bx.cx()) -- cgit 1.4.1-3-g733a5 From c3e1e7a947e65f16b35cbd4af9607fc670474542 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 16 May 2022 16:23:42 +0300 Subject: simplify more, ret_deref -> has_deref --- compiler/rustc_codegen_ssa/src/mir/place.rs | 3 +-- compiler/rustc_middle/src/mir/mod.rs | 12 ++++++------ compiler/rustc_mir_transform/src/add_retag.rs | 5 ++--- 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 38e09f539de..268c4d76503 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -435,13 +435,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { LocalRef::Place(place) => place, LocalRef::UnsizedPlace(place) => bx.load_operand(place).deref(cx), LocalRef::Operand(..) => { - if place_ref.ret_deref().is_some() { + if place_ref.has_deref() { base = 1; let cg_base = self.codegen_consume( bx, mir::PlaceRef { projection: &place_ref.projection[..0], ..place_ref }, ); - cg_base.deref(bx.cx()) } else { bug!("using operand local {:?} as place", place_ref); diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 2a31441ec7b..e2084a12cbe 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1463,11 +1463,11 @@ impl<'tcx> Place<'tcx> { /// If MirPhase >= Derefered and if projection contains Deref, /// It's guaranteed to be in the first place - pub fn ret_deref(&self) -> Option> { + pub fn has_deref(&self) -> bool { if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref { - return Some(self.projection[0]); + true } else { - None + false } } @@ -1545,11 +1545,11 @@ impl<'tcx> PlaceRef<'tcx> { /// If MirPhase >= Derefered and if projection contains Deref, /// It's guaranteed to be in the first place - pub fn ret_deref(&self) -> Option> { + pub fn has_deref(&self) -> bool { if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref { - return Some(self.projection[0]); + true } else { - None + false } } diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index b0cbcff600c..c91b3044c4f 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -15,7 +15,7 @@ pub struct AddRetag; /// (Concurrent accesses by other threads are no problem as these are anyway non-atomic /// copies. Data races are UB.) 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, // so cannot assume deref to be stable. return false; @@ -83,8 +83,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag { let place_base_raw = |place: &Place<'tcx>| { // If this is a `Deref`, get the type of what we are deref'ing. if place.ret_deref().is_some() { - let base_proj = &place.projection[..0]; - let ty = Place::ty_from(place.local, base_proj, &*local_decls, tcx).ty; + let ty = place.ty(local_decls, tcx).ty; ty.is_unsafe_ptr() } else { // Not a deref, and thus not raw. -- cgit 1.4.1-3-g733a5