use let else more consistently in fact generation

also remove a useless trace
This commit is contained in:
Rémy Rakic 2024-12-11 13:57:34 +00:00
parent afbe101f0e
commit 5486857448
2 changed files with 43 additions and 49 deletions

View file

@ -21,30 +21,24 @@ pub(crate) fn emit_access_facts<'tcx>(
location_table: &LocationTable,
all_facts: &mut Option<AllFacts>,
) {
if let Some(facts) = all_facts.as_mut() {
debug!("emit_access_facts()");
let Some(facts) = all_facts.as_mut() else { return };
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let mut extractor = AccessFactsExtractor {
var_defined_at: &mut facts.var_defined_at,
var_used_at: &mut facts.var_used_at,
var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table,
move_data,
};
extractor.visit_body(body);
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let mut extractor = AccessFactsExtractor {
var_defined_at: &mut facts.var_defined_at,
var_used_at: &mut facts.var_used_at,
var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table,
move_data,
};
extractor.visit_body(body);
for (local, local_decl) in body.local_decls.iter_enumerated() {
debug!(
"add use_of_var_derefs_origin facts - local={:?}, type={:?}",
local, local_decl.ty
);
tcx.for_each_free_region(&local_decl.ty, |region| {
let region_vid = universal_regions.to_region_vid(region);
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
});
}
for (local, local_decl) in body.local_decls.iter_enumerated() {
debug!("add use_of_var_derefs_origin facts - local={:?}, type={:?}", local, local_decl.ty);
tcx.for_each_free_region(&local_decl.ty, |region| {
let region_vid = universal_regions.to_region_vid(region);
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
});
}
}

View file

@ -39,8 +39,8 @@ pub(crate) fn emit_facts<'tcx>(
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
move_data: &MoveData<'_>,
universal_region_relations: &UniversalRegionRelations<'_>,
move_data: &MoveData<'tcx>,
universal_region_relations: &UniversalRegionRelations<'tcx>,
) {
let Some(all_facts) = all_facts else {
// We don't do anything if there are no facts to fill.
@ -202,13 +202,12 @@ pub(crate) fn emit_drop_facts<'tcx>(
all_facts: &mut Option<AllFacts>,
) {
debug!("emit_drop_facts(local={:?}, kind={:?}", local, kind);
if let Some(facts) = all_facts.as_mut() {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
tcx.for_each_free_region(kind, |drop_live_region| {
let region_vid = universal_regions.to_region_vid(drop_live_region);
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));
});
}
let Some(facts) = all_facts.as_mut() else { return };
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
tcx.for_each_free_region(kind, |drop_live_region| {
let region_vid = universal_regions.to_region_vid(drop_live_region);
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));
});
}
/// Emit facts about the outlives constraints: the `subset` base relation, i.e. not a transitive
@ -219,22 +218,23 @@ pub(crate) fn emit_outlives_facts<'tcx>(
location_table: &LocationTable,
all_facts: &mut Option<AllFacts>,
) {
if let Some(facts) = all_facts {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map(
|constraint: &OutlivesConstraint<'_>| {
if let Some(from_location) = constraint.locations.from_location() {
Either::Left(iter::once((
constraint.sup.into(),
constraint.sub.into(),
location_table.mid_index(from_location),
)))
} else {
Either::Right(location_table.all_points().map(move |location| {
let Some(facts) = all_facts else { return };
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map(
|constraint: &OutlivesConstraint<'_>| {
if let Some(from_location) = constraint.locations.from_location() {
Either::Left(iter::once((
constraint.sup.into(),
constraint.sub.into(),
location_table.mid_index(from_location),
)))
} else {
Either::Right(
location_table.all_points().map(move |location| {
(constraint.sup.into(), constraint.sub.into(), location)
}))
}
},
));
}
}),
)
}
},
));
}