Reorder passes so that AddValidation can run after ElaborateDrops

This commit is contained in:
Ralf Jung 2017-07-25 16:44:49 -07:00
parent 04f962adc3
commit b934506e68
2 changed files with 19 additions and 25 deletions

View File

@ -925,10 +925,6 @@ macro_rules! try_with_f {
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 @@ macro_rules! try_with_f {
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 @@ macro_rules! try_with_f {
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);

View File

@ -31,7 +31,6 @@
struct GatherBorrowedRegions {
seen_regions: FxHashSet<CodeExtent>,
in_validation_statement: bool,
}
struct DeleteTrivialEndRegions<'a> {
@ -44,8 +43,7 @@ fn run_pass<'a, 'tcx>(&self,
_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 @@ fn visit_statement(&mut self,
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);