@@ -24,7 +24,7 @@ use self::mir_util::PassWhere;
24
24
mod constraint_generation;
25
25
mod subtype;
26
26
27
- mod region_infer;
27
+ pub ( crate ) mod region_infer;
28
28
use self :: region_infer:: RegionInferenceContext ;
29
29
30
30
mod renumber;
@@ -43,33 +43,23 @@ impl MirPass for NLL {
43
43
return ;
44
44
}
45
45
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
+ } ) ;
48
50
}
49
51
}
50
52
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
-
60
53
/// Computes the (non-lexical) regions from the input MIR.
61
54
///
62
55
/// This may result in errors being reported.
63
56
pub fn compute_regions < ' a , ' gcx , ' tcx > (
64
57
infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
65
58
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 {
71
61
// 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) ;
73
63
74
64
// Compute what is live where.
75
65
let liveness = & LivenessResults {
@@ -98,13 +88,11 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
98
88
99
89
assert ! ( errors. is_empty( ) , "FIXME: report region inference failures" ) ;
100
90
101
- let computation = RegionComputation { mir, regioncx } ;
102
-
103
91
// Dump MIR results into a file, if that is enabled. This let us
104
92
// write unit-tests.
105
- dump_mir_results ( infcx, liveness, source, & computation ) ;
93
+ dump_mir_results ( infcx, liveness, source, & mir , & regioncx ) ;
106
94
107
- computation
95
+ regioncx
108
96
}
109
97
110
98
struct LivenessResults {
@@ -116,17 +104,13 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
116
104
infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
117
105
liveness : & LivenessResults ,
118
106
source : MirSource ,
119
- computation : & RegionComputation < ' tcx > ,
107
+ mir : & Mir < ' tcx > ,
108
+ regioncx : & RegionInferenceContext ,
120
109
) {
121
110
if !mir_util:: dump_enabled ( infcx. tcx , "nll" , source) {
122
111
return ;
123
112
}
124
113
125
- let RegionComputation {
126
- ref mir,
127
- ref regioncx,
128
- } = * computation;
129
-
130
114
let regular_liveness_per_location: FxHashMap < _ , _ > = mir. basic_blocks ( )
131
115
. indices ( )
132
116
. flat_map ( |bb| {
@@ -216,7 +200,7 @@ newtype_index!(RegionIndex {
216
200
/// assert that the region is a `ReVar` and convert the internal index
217
201
/// into a `RegionIndex`. This is reasonable because in our MIR we
218
202
/// replace all free regions with inference variables.
219
- trait ToRegionIndex {
203
+ pub trait ToRegionIndex {
220
204
fn to_region_index ( & self ) -> RegionIndex ;
221
205
}
222
206
0 commit comments