Skip to content

Commit 68c4844

Browse files
committed
make nll separately invokable
1 parent dde61f3 commit 68c4844

File tree

1 file changed

+13
-29
lines changed
  • src/librustc_mir/transform/nll

1 file changed

+13
-29
lines changed

src/librustc_mir/transform/nll/mod.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use self::mir_util::PassWhere;
2424
mod constraint_generation;
2525
mod subtype;
2626

27-
mod region_infer;
27+
pub(crate) mod region_infer;
2828
use self::region_infer::RegionInferenceContext;
2929

3030
mod renumber;
@@ -43,33 +43,23 @@ impl MirPass for NLL {
4343
return;
4444
}
4545

46-
tcx.infer_ctxt()
47-
.enter(|ref infcx| drop(compute_regions(infcx, source, input_mir)));
46+
tcx.infer_ctxt().enter(|ref infcx| {
47+
let mut mir = input_mir.clone();
48+
let _ = compute_regions(infcx, source, &mut mir);
49+
});
4850
}
4951
}
5052

51-
pub struct RegionComputation<'tcx> {
52-
/// A rewritten version of the input MIR where all the regions are
53-
/// rewritten to refer to inference variables.
54-
pub mir: Mir<'tcx>,
55-
56-
/// The definitions (along with their final values) for all regions.
57-
pub regioncx: RegionInferenceContext,
58-
}
59-
6053
/// Computes the (non-lexical) regions from the input MIR.
6154
///
6255
/// This may result in errors being reported.
6356
pub fn compute_regions<'a, 'gcx, 'tcx>(
6457
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
6558
source: MirSource,
66-
input_mir: &Mir<'tcx>,
67-
) -> RegionComputation<'tcx> {
68-
// Clone mir so we can mutate it without disturbing the rest of the compiler
69-
let mut mir = input_mir.clone();
70-
59+
mir: &mut Mir<'tcx>,
60+
) -> RegionInferenceContext {
7161
// Replace all regions with fresh inference variables.
72-
let num_region_variables = renumber::renumber_mir(infcx, &mut mir);
62+
let num_region_variables = renumber::renumber_mir(infcx, mir);
7363

7464
// Compute what is live where.
7565
let liveness = &LivenessResults {
@@ -98,13 +88,11 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
9888

9989
assert!(errors.is_empty(), "FIXME: report region inference failures");
10090

101-
let computation = RegionComputation { mir, regioncx };
102-
10391
// Dump MIR results into a file, if that is enabled. This let us
10492
// write unit-tests.
105-
dump_mir_results(infcx, liveness, source, &computation);
93+
dump_mir_results(infcx, liveness, source, &mir, &regioncx);
10694

107-
computation
95+
regioncx
10896
}
10997

11098
struct LivenessResults {
@@ -116,17 +104,13 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
116104
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
117105
liveness: &LivenessResults,
118106
source: MirSource,
119-
computation: &RegionComputation<'tcx>,
107+
mir: &Mir<'tcx>,
108+
regioncx: &RegionInferenceContext,
120109
) {
121110
if !mir_util::dump_enabled(infcx.tcx, "nll", source) {
122111
return;
123112
}
124113

125-
let RegionComputation {
126-
ref mir,
127-
ref regioncx,
128-
} = *computation;
129-
130114
let regular_liveness_per_location: FxHashMap<_, _> = mir.basic_blocks()
131115
.indices()
132116
.flat_map(|bb| {
@@ -216,7 +200,7 @@ newtype_index!(RegionIndex {
216200
/// assert that the region is a `ReVar` and convert the internal index
217201
/// into a `RegionIndex`. This is reasonable because in our MIR we
218202
/// replace all free regions with inference variables.
219-
trait ToRegionIndex {
203+
pub trait ToRegionIndex {
220204
fn to_region_index(&self) -> RegionIndex;
221205
}
222206

0 commit comments

Comments
 (0)