diff options
| author | ouz-a <ouz.agz@gmail.com> | 2023-08-28 11:19:19 +0300 |
|---|---|---|
| committer | ouz-a <ouz.agz@gmail.com> | 2023-10-02 23:39:44 +0300 |
| commit | cd7f47193182d1d557a83593bcff6afe0568fc53 (patch) | |
| tree | 5ae299b1d8d300839a57994f58b37d0f20541594 /compiler/rustc_mir_transform/src | |
| parent | 3148e6a9933b17b28ed6c7b8d8bd6c8e49fe4a50 (diff) | |
| download | rust-cd7f47193182d1d557a83593bcff6afe0568fc53.tar.gz rust-cd7f47193182d1d557a83593bcff6afe0568fc53.zip | |
Add docs, remove code, change subtyper code
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_subtyping_projections.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/gvn.rs | 1 |
2 files changed, 12 insertions, 9 deletions
diff --git a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs index e51f4a2ff21..594bb9bf142 100644 --- a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs +++ b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs @@ -7,13 +7,13 @@ use rustc_middle::ty::TyCtxt; pub struct Subtyper; -pub struct SubTypeCheker<'a, 'tcx> { +pub struct SubTypeChecker<'a, 'tcx> { tcx: TyCtxt<'tcx>, patcher: MirPatch<'tcx>, local_decls: &'a IndexVec<Local, LocalDecl<'tcx>>, } -impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeCheker<'a, 'tcx> { +impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -25,28 +25,30 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeCheker<'a, 'tcx> { location: Location, ) { let place_ty = place.ty(self.local_decls, self.tcx); - let rval_ty = rvalue.ty(self.local_decls, self.tcx); + let mut rval_ty = rvalue.ty(self.local_decls, self.tcx); if place_ty.ty != rval_ty { + // Not erasing this causes `Free Regions` errors in validator, + // when rval is `ReStatic`. + rval_ty = self.tcx.erase_regions_ty(rval_ty); let temp = self .patcher .new_temp(rval_ty, self.local_decls[place.as_ref().local].source_info.span); - let new_place = - Place::from(temp).project_deeper(&[ProjectionElem::Subtype(place_ty.ty)], self.tcx); + let new_place = Place::from(temp); self.patcher.add_assign(location, new_place, rvalue.clone()); - let new_rval = Rvalue::Use(Operand::Move(new_place)); - *rvalue = new_rval; + let subtyped = + new_place.project_deeper(&[ProjectionElem::Subtype(place_ty.ty)], self.tcx); + *rvalue = Rvalue::Use(Operand::Move(subtyped)); } } } pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let patch = MirPatch::new(body); - let mut checker = SubTypeCheker { tcx, patcher: patch, local_decls: &body.local_decls }; + let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls }; for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() { checker.visit_basic_block_data(bb, data); } - checker.patcher.apply(body); } diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 449bade3322..56bdc5a171a 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -306,6 +306,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { } ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index), ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), + ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty), }; value = self.insert(Value::Projection(value, proj)); } |
