Skip to content

Commit e6d8fbe

Browse files
committed
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
1 parent 883b6aa commit e6d8fbe

File tree

1 file changed

+14
-22
lines changed
  • src/librustc_mir/borrow_check/nll/type_check/liveness

1 file changed

+14
-22
lines changed

src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::util::liveness::{categorize, DefUse};
55
use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
66
use rustc::mir::{Local, Location, Place, ReadOnlyBodyAndCache};
77
use rustc::ty::subst::GenericArg;
8-
use rustc::ty::Ty;
98

109
use super::TypeChecker;
1110

@@ -84,17 +83,6 @@ impl Visitor<'tcx> for UseFactsExtractor<'_> {
8483
}
8584
}
8685

87-
fn add_var_uses_regions(typeck: &mut TypeChecker<'_, 'tcx>, local: Local, ty: Ty<'tcx>) {
88-
debug!("add_regions(local={:?}, type={:?})", local, ty);
89-
typeck.tcx().for_each_free_region(&ty, |region| {
90-
let region_vid = typeck.borrowck_context.universal_regions.to_region_vid(region);
91-
debug!("add_regions for region {:?}", region_vid);
92-
if let Some(facts) = typeck.borrowck_context.all_facts {
93-
facts.var_uses_region.push((local, region_vid));
94-
}
95-
});
96-
}
97-
9886
pub(super) fn populate_access_facts(
9987
typeck: &mut TypeChecker<'_, 'tcx>,
10088
body: ReadOnlyBodyAndCache<'_, 'tcx>,
@@ -118,10 +106,15 @@ pub(super) fn populate_access_facts(
118106
facts.var_drop_used.extend(drop_used.iter().map(|&(local, location)| {
119107
(local, location_table.mid_index(location))
120108
}));
121-
}
122109

123-
for (local, local_decl) in body.local_decls.iter_enumerated() {
124-
add_var_uses_regions(typeck, local, local_decl.ty);
110+
for (local, local_decl) in body.local_decls.iter_enumerated() {
111+
debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty);
112+
let universal_regions = &typeck.borrowck_context.universal_regions;
113+
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
114+
let region_vid = universal_regions.to_region_vid(region);
115+
facts.var_uses_region.push((local, region_vid));
116+
});
117+
}
125118
}
126119
}
127120

@@ -133,12 +126,11 @@ pub(super) fn add_var_drops_regions(
133126
kind: &GenericArg<'tcx>,
134127
) {
135128
debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind);
136-
let tcx = typeck.tcx();
137-
138-
tcx.for_each_free_region(kind, |drop_live_region| {
139-
let region_vid = typeck.borrowck_context.universal_regions.to_region_vid(drop_live_region);
140-
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
129+
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
130+
let universal_regions = &typeck.borrowck_context.universal_regions;
131+
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
132+
let region_vid = universal_regions.to_region_vid(drop_live_region);
141133
facts.var_drops_region.push((local, region_vid));
142-
};
143-
});
134+
});
135+
}
144136
}

0 commit comments

Comments
 (0)