]>
Commit | Line | Data |
---|---|---|
3b2f2976 | 1 | //! This pass erases all early-bound regions from the types occurring in the MIR. |
94b46f34 | 2 | //! We want to do this once just before codegen, so codegen does not have to take |
92a42be0 | 3 | //! care erasing regions all over the place. |
9fa01778 XL |
4 | //! N.B., we do _not_ erase regions of statements that are relevant for |
5 | //! "types-as-contracts"-validation, namely, `AcquireValid` and `ReleaseValid`. | |
92a42be0 | 6 | |
532ac7d7 | 7 | use rustc::ty::subst::SubstsRef; |
ea8adc8c | 8 | use rustc::ty::{self, Ty, TyCtxt}; |
c30ab7b3 | 9 | use rustc::mir::*; |
abe05a73 | 10 | use rustc::mir::visit::{MutVisitor, TyContext}; |
9fa01778 | 11 | use crate::transform::{MirPass, MirSource}; |
92a42be0 | 12 | |
dc9dc135 XL |
13 | struct EraseRegionsVisitor<'tcx> { |
14 | tcx: TyCtxt<'tcx>, | |
92a42be0 SL |
15 | } |
16 | ||
dc9dc135 XL |
17 | impl EraseRegionsVisitor<'tcx> { |
18 | pub fn new(tcx: TyCtxt<'tcx>) -> Self { | |
7453a54e | 19 | EraseRegionsVisitor { |
3b2f2976 | 20 | tcx, |
92a42be0 | 21 | } |
92a42be0 | 22 | } |
7453a54e | 23 | } |
92a42be0 | 24 | |
dc9dc135 | 25 | impl MutVisitor<'tcx> for EraseRegionsVisitor<'tcx> { |
abe05a73 | 26 | fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) { |
a1dfa0c6 | 27 | *ty = self.tcx.erase_regions(ty); |
3b2f2976 | 28 | self.super_ty(ty); |
92a42be0 SL |
29 | } |
30 | ||
ea8adc8c | 31 | fn visit_region(&mut self, region: &mut ty::Region<'tcx>, _: Location) { |
48663c56 | 32 | *region = self.tcx.lifetimes.re_erased; |
92a42be0 | 33 | } |
cc61c64b | 34 | |
532ac7d7 | 35 | fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, _: Location) { |
ea8adc8c XL |
36 | *constant = self.tcx.erase_regions(constant); |
37 | } | |
38 | ||
532ac7d7 | 39 | fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) { |
ea8adc8c | 40 | *substs = self.tcx.erase_regions(substs); |
cc61c64b XL |
41 | } |
42 | ||
041b39d2 | 43 | fn visit_statement(&mut self, |
041b39d2 XL |
44 | statement: &mut Statement<'tcx>, |
45 | location: Location) { | |
48663c56 | 46 | self.super_statement(statement, location); |
041b39d2 | 47 | } |
54a0048b | 48 | } |
92a42be0 | 49 | |
54a0048b | 50 | pub struct EraseRegions; |
7453a54e | 51 | |
7cac9316 | 52 | impl MirPass for EraseRegions { |
dc9dc135 XL |
53 | fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { |
54 | EraseRegionsVisitor::new(tcx).visit_body(body); | |
92a42be0 SL |
55 | } |
56 | } |