diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 68e6b0f50d1..2b667d83e35 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -925,10 +925,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, let mut passes = Passes::new(); passes.push_hook(mir::transform::dump_mir::DumpMir); - // Insert AcquireValid and ReleaseValid calls. Conceptually, this - // pass is actually part of MIR building. - passes.push_pass(MIR_CONST, mir::transform::add_validation::AddValidation); - // Remove all `EndRegion` statements that are not involved in borrows. passes.push_pass(MIR_CONST, mir::transform::clean_end_regions::CleanEndRegions); @@ -937,6 +933,8 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, passes.push_pass(MIR_CONST, mir::transform::type_check::TypeckMir); passes.push_pass(MIR_CONST, mir::transform::rustc_peek::SanityCheck); + // We compute "constant qualifications" betwen MIR_CONST and MIR_VALIDATED. + // What we need to run borrowck etc. passes.push_pass(MIR_VALIDATED, mir::transform::qualify_consts::QualifyAndPromoteConstants); passes.push_pass(MIR_VALIDATED, @@ -944,18 +942,23 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, passes.push_pass(MIR_VALIDATED, mir::transform::simplify::SimplifyCfg::new("qualify-consts")); passes.push_pass(MIR_VALIDATED, mir::transform::nll::NLL); - // Optimizations begin. - passes.push_pass(MIR_OPTIMIZED, mir::transform::no_landing_pads::NoLandingPads); - passes.push_pass(MIR_OPTIMIZED, mir::transform::simplify::SimplifyCfg::new("no-landing-pads")); + // borrowck runs between MIR_VALIDATED and MIR_OPTIMIZED. - // From here on out, regions are gone. - passes.push_pass(MIR_OPTIMIZED, mir::transform::erase_regions::EraseRegions); + // These next passes must be executed together + passes.push_pass(MIR_OPTIMIZED, mir::transform::no_landing_pads::NoLandingPads); passes.push_pass(MIR_OPTIMIZED, mir::transform::add_call_guards::AddCallGuards); passes.push_pass(MIR_OPTIMIZED, mir::transform::elaborate_drops::ElaborateDrops); passes.push_pass(MIR_OPTIMIZED, mir::transform::no_landing_pads::NoLandingPads); passes.push_pass(MIR_OPTIMIZED, mir::transform::simplify::SimplifyCfg::new("elaborate-drops")); - // No lifetime analysis based on borrowing can be done from here on out. + + // AddValidation needs to run after ElaborateDrops and before EraseRegions. + passes.push_pass(MIR_OPTIMIZED, mir::transform::add_validation::AddValidation); + + // From here on out, regions are gone. + passes.push_pass(MIR_OPTIMIZED, mir::transform::erase_regions::EraseRegions); + + // Optimizations begin. passes.push_pass(MIR_OPTIMIZED, mir::transform::inline::Inline); passes.push_pass(MIR_OPTIMIZED, mir::transform::instcombine::InstCombine); passes.push_pass(MIR_OPTIMIZED, mir::transform::deaggregator::Deaggregator); diff --git a/src/librustc_mir/transform/clean_end_regions.rs b/src/librustc_mir/transform/clean_end_regions.rs index 1a31bf97530..d7ec58384a4 100644 --- a/src/librustc_mir/transform/clean_end_regions.rs +++ b/src/librustc_mir/transform/clean_end_regions.rs @@ -31,7 +31,6 @@ pub struct CleanEndRegions; struct GatherBorrowedRegions { seen_regions: FxHashSet, - in_validation_statement: bool, } struct DeleteTrivialEndRegions<'a> { @@ -44,8 +43,7 @@ impl MirPass for CleanEndRegions { _source: MirSource, mir: &mut Mir<'tcx>) { let mut gather = GatherBorrowedRegions { - seen_regions: FxHashSet(), - in_validation_statement: false + seen_regions: FxHashSet() }; gather.visit_mir(mir); @@ -71,22 +69,15 @@ impl<'tcx> Visitor<'tcx> for GatherBorrowedRegions { block: BasicBlock, statement: &Statement<'tcx>, location: Location) { - self.in_validation_statement = match statement.kind { - StatementKind::Validate(..) => true, - _ => false, - }; self.super_statement(block, statement, location); - self.in_validation_statement = false; } fn visit_ty(&mut self, ty: &Ty<'tcx>, _: Lookup) { - // Gather regions that occur in types inside AcquireValid/ReleaseValid statements - if self.in_validation_statement { - for re in ty.walk().flat_map(|t| t.regions()) { - match *re { - RegionKind::ReScope(ce) => { self.seen_regions.insert(ce); } - _ => {}, - } + // Gather regions that occur in types + for re in ty.walk().flat_map(|t| t.regions()) { + match *re { + RegionKind::ReScope(ce) => { self.seen_regions.insert(ce); } + _ => {}, } } self.super_ty(ty);