Skip to content

Commit afbe101

Browse files
committed
clean up translate_outlives_facts
- remove dependency on `TypeChecker` - move to legacy fact generation module - group facts emitted during typeck together
1 parent 9d8f58a commit afbe101

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

compiler/rustc_borrowck/src/polonius/legacy/mod.rs

+33
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
//! Will be removed in the future, once the in-tree `-Zpolonius=next` implementation reaches feature
44
//! parity.
55
6+
use std::iter;
7+
8+
use either::Either;
69
use rustc_middle::mir::{Body, Local, LocalKind, Location, START_BLOCK};
710
use rustc_middle::ty::{GenericArg, TyCtxt};
811
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
912
use tracing::debug;
1013

1114
use crate::borrow_set::BorrowSet;
15+
use crate::constraints::OutlivesConstraint;
1216
use crate::facts::{AllFacts, PoloniusRegionVid};
1317
use crate::location::LocationTable;
18+
use crate::type_check::MirTypeckRegionConstraints;
1419
use crate::type_check::free_region_relations::UniversalRegionRelations;
1520
use crate::universal_regions::UniversalRegions;
1621

@@ -205,3 +210,31 @@ pub(crate) fn emit_drop_facts<'tcx>(
205210
});
206211
}
207212
}
213+
214+
/// Emit facts about the outlives constraints: the `subset` base relation, i.e. not a transitive
215+
/// closure.
216+
pub(crate) fn emit_outlives_facts<'tcx>(
217+
tcx: TyCtxt<'tcx>,
218+
constraints: &MirTypeckRegionConstraints<'tcx>,
219+
location_table: &LocationTable,
220+
all_facts: &mut Option<AllFacts>,
221+
) {
222+
if let Some(facts) = all_facts {
223+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
224+
facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map(
225+
|constraint: &OutlivesConstraint<'_>| {
226+
if let Some(from_location) = constraint.locations.from_location() {
227+
Either::Left(iter::once((
228+
constraint.sup.into(),
229+
constraint.sub.into(),
230+
location_table.mid_index(from_location),
231+
)))
232+
} else {
233+
Either::Right(location_table.all_points().map(move |location| {
234+
(constraint.sup.into(), constraint.sub.into(), location)
235+
}))
236+
}
237+
},
238+
));
239+
}
240+
}

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use tracing::debug;
1313

1414
use super::TypeChecker;
1515
use crate::constraints::OutlivesConstraintSet;
16-
use crate::polonius;
1716
use crate::region_infer::values::LivenessValues;
1817
use crate::universal_regions::UniversalRegions;
1918

@@ -45,15 +44,6 @@ pub(super) fn generate<'a, 'tcx>(
4544
let (relevant_live_locals, boring_locals) =
4645
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
4746

48-
polonius::legacy::emit_access_facts(
49-
typeck.tcx(),
50-
body,
51-
move_data,
52-
typeck.universal_regions,
53-
typeck.location_table,
54-
typeck.all_facts,
55-
);
56-
5747
trace::trace(
5848
typeck,
5949
body,

compiler/rustc_borrowck/src/type_check/mod.rs

+15-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::rc::Rc;
44
use std::{fmt, iter, mem};
55

6-
use either::Either;
76
use rustc_abi::{FIRST_VARIANT, FieldIdx};
87
use rustc_data_structures::frozen::Frozen;
98
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -60,7 +59,7 @@ use crate::renumber::RegionCtxt;
6059
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
6160
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
6261
use crate::universal_regions::{DefiningTy, UniversalRegions};
63-
use crate::{BorrowckInferCtxt, path_utils};
62+
use crate::{BorrowckInferCtxt, path_utils, polonius};
6463

6564
macro_rules! span_mirbug {
6665
($context:expr, $elem:expr, $($message:tt)*) => ({
@@ -182,7 +181,20 @@ pub(crate) fn type_check<'a, 'tcx>(
182181

183182
liveness::generate(&mut checker, body, &elements, flow_inits, move_data);
184183

185-
translate_outlives_facts(&mut checker);
184+
polonius::legacy::emit_access_facts(
185+
infcx.tcx,
186+
body,
187+
move_data,
188+
&universal_region_relations.universal_regions,
189+
location_table,
190+
checker.all_facts,
191+
);
192+
polonius::legacy::emit_outlives_facts(
193+
infcx.tcx,
194+
checker.constraints,
195+
location_table,
196+
checker.all_facts,
197+
);
186198
let opaque_type_values = infcx.take_opaque_types();
187199

188200
let opaque_type_values = opaque_type_values
@@ -234,30 +246,6 @@ pub(crate) fn type_check<'a, 'tcx>(
234246
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
235247
}
236248

237-
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
238-
if let Some(facts) = typeck.all_facts {
239-
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
240-
let location_table = typeck.location_table;
241-
facts.subset_base.extend(
242-
typeck.constraints.outlives_constraints.outlives().iter().flat_map(
243-
|constraint: &OutlivesConstraint<'_>| {
244-
if let Some(from_location) = constraint.locations.from_location() {
245-
Either::Left(iter::once((
246-
constraint.sup.into(),
247-
constraint.sub.into(),
248-
location_table.mid_index(from_location),
249-
)))
250-
} else {
251-
Either::Right(location_table.all_points().map(move |location| {
252-
(constraint.sup.into(), constraint.sub.into(), location)
253-
}))
254-
}
255-
},
256-
),
257-
);
258-
}
259-
}
260-
261249
#[track_caller]
262250
fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
263251
// We sometimes see MIR failures (notably predicate failures) due to

0 commit comments

Comments
 (0)