diff options
| author | Remy Rakic <remy.rakic@gmail.com> | 2019-12-09 18:54:06 +0100 |
|---|---|---|
| committer | Remy Rakic <remy.rakic@gmail.com> | 2019-12-10 11:44:44 +0100 |
| commit | e6d8fbede2e492e55283072e426ba81ec90f54ae (patch) | |
| tree | f566055751e0513c0c5f17c3e4d589b4faf6a2b3 | |
| parent | 883b6aacba85b524a194577a24a47f115106ecc8 (diff) | |
| download | rust-e6d8fbede2e492e55283072e426ba81ec90f54ae.tar.gz rust-e6d8fbede2e492e55283072e426ba81ec90f54ae.zip | |
cleanup polonius liveness fact generation
For the var_uses_region and var_drops_region relations: - check for all facts existence only once - remove function only used once - pull var_uses_region with the other access facts instead of on its own
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs index 810811f9f5c..deb49b61e8d 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs @@ -5,7 +5,6 @@ use crate::util::liveness::{categorize, DefUse}; use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc::mir::{Local, Location, Place, ReadOnlyBodyAndCache}; use rustc::ty::subst::GenericArg; -use rustc::ty::Ty; use super::TypeChecker; @@ -84,17 +83,6 @@ impl Visitor<'tcx> for UseFactsExtractor<'_> { } } -fn add_var_uses_regions(typeck: &mut TypeChecker<'_, 'tcx>, local: Local, ty: Ty<'tcx>) { - debug!("add_regions(local={:?}, type={:?})", local, ty); - typeck.tcx().for_each_free_region(&ty, |region| { - let region_vid = typeck.borrowck_context.universal_regions.to_region_vid(region); - debug!("add_regions for region {:?}", region_vid); - if let Some(facts) = typeck.borrowck_context.all_facts { - facts.var_uses_region.push((local, region_vid)); - } - }); -} - pub(super) fn populate_access_facts( typeck: &mut TypeChecker<'_, 'tcx>, body: ReadOnlyBodyAndCache<'_, 'tcx>, @@ -118,10 +106,15 @@ pub(super) fn populate_access_facts( facts.var_drop_used.extend(drop_used.iter().map(|&(local, location)| { (local, location_table.mid_index(location)) })); - } - for (local, local_decl) in body.local_decls.iter_enumerated() { - add_var_uses_regions(typeck, local, local_decl.ty); + for (local, local_decl) in body.local_decls.iter_enumerated() { + debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty); + let universal_regions = &typeck.borrowck_context.universal_regions; + typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| { + let region_vid = universal_regions.to_region_vid(region); + facts.var_uses_region.push((local, region_vid)); + }); + } } } @@ -133,12 +126,11 @@ pub(super) fn add_var_drops_regions( kind: &GenericArg<'tcx>, ) { debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind); - let tcx = typeck.tcx(); - - tcx.for_each_free_region(kind, |drop_live_region| { - let region_vid = typeck.borrowck_context.universal_regions.to_region_vid(drop_live_region); - if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { + if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { + let universal_regions = &typeck.borrowck_context.universal_regions; + typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| { + let region_vid = universal_regions.to_region_vid(drop_live_region); facts.var_drops_region.push((local, region_vid)); - }; - }); + }); + } } |
