Skip to content

Commit eb7da16

Browse files
committed
move typeck constraints conversion to its own module
1 parent bc3e301 commit eb7da16

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

compiler/rustc_borrowck/src/polonius/mod.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,20 @@ mod constraints;
3737
mod dump;
3838
pub(crate) mod legacy;
3939
mod liveness_constraints;
40+
mod typeck_constraints;
4041

4142
use std::collections::BTreeMap;
4243

4344
use rustc_index::bit_set::SparseBitMatrix;
44-
use rustc_middle::mir::{Body, Location};
45+
use rustc_middle::mir::Body;
4546
use rustc_middle::ty::RegionVid;
4647
use rustc_mir_dataflow::points::PointIndex;
4748

4849
pub(crate) use self::constraints::*;
4950
pub(crate) use self::dump::dump_polonius_mir;
5051
use self::liveness_constraints::create_liveness_constraints;
52+
use self::typeck_constraints::convert_typeck_constraints;
5153
use crate::RegionInferenceContext;
52-
use crate::constraints::OutlivesConstraint;
53-
use crate::region_infer::values::LivenessValues;
54-
use crate::type_check::Locations;
5554

5655
/// This struct holds the data needed to create the Polonius localized constraints.
5756
pub(crate) struct PoloniusContext {
@@ -117,38 +116,3 @@ impl PoloniusContext {
117116
localized_outlives_constraints
118117
}
119118
}
120-
121-
/// Propagate loans throughout the subset graph at a given point (with some subtleties around the
122-
/// location where effects start to be visible).
123-
fn convert_typeck_constraints<'tcx>(
124-
body: &Body<'tcx>,
125-
liveness: &LivenessValues,
126-
outlives_constraints: impl Iterator<Item = OutlivesConstraint<'tcx>>,
127-
localized_outlives_constraints: &mut LocalizedOutlivesConstraintSet,
128-
) {
129-
for outlives_constraint in outlives_constraints {
130-
match outlives_constraint.locations {
131-
Locations::All(_) => {
132-
// For now, turn logical constraints holding at all points into physical edges at
133-
// every point in the graph.
134-
// FIXME: encode this into *traversal* instead.
135-
for (block, bb) in body.basic_blocks.iter_enumerated() {
136-
let statement_count = bb.statements.len();
137-
for statement_index in 0..=statement_count {
138-
let current_location = Location { block, statement_index };
139-
let current_point = liveness.point_from_location(current_location);
140-
141-
localized_outlives_constraints.push(LocalizedOutlivesConstraint {
142-
source: outlives_constraint.sup,
143-
from: current_point,
144-
target: outlives_constraint.sub,
145-
to: current_point,
146-
});
147-
}
148-
}
149-
}
150-
151-
_ => {}
152-
}
153-
}
154-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use rustc_middle::mir::{Body, Location};
2+
3+
use super::{LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSet};
4+
use crate::constraints::OutlivesConstraint;
5+
use crate::region_infer::values::LivenessValues;
6+
use crate::type_check::Locations;
7+
8+
/// Propagate loans throughout the subset graph at a given point (with some subtleties around the
9+
/// location where effects start to be visible).
10+
pub(super) fn convert_typeck_constraints<'tcx>(
11+
body: &Body<'tcx>,
12+
liveness: &LivenessValues,
13+
outlives_constraints: impl Iterator<Item = OutlivesConstraint<'tcx>>,
14+
localized_outlives_constraints: &mut LocalizedOutlivesConstraintSet,
15+
) {
16+
for outlives_constraint in outlives_constraints {
17+
match outlives_constraint.locations {
18+
Locations::All(_) => {
19+
// For now, turn logical constraints holding at all points into physical edges at
20+
// every point in the graph.
21+
// FIXME: encode this into *traversal* instead.
22+
for (block, bb) in body.basic_blocks.iter_enumerated() {
23+
let statement_count = bb.statements.len();
24+
for statement_index in 0..=statement_count {
25+
let current_location = Location { block, statement_index };
26+
let current_point = liveness.point_from_location(current_location);
27+
28+
localized_outlives_constraints.push(LocalizedOutlivesConstraint {
29+
source: outlives_constraint.sup,
30+
from: current_point,
31+
target: outlives_constraint.sub,
32+
to: current_point,
33+
});
34+
}
35+
}
36+
}
37+
38+
_ => {}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)