@@ -18,6 +18,7 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
18
18
use rustc_data_structures:: control_flow_graph:: dominators:: { Dominators , dominators} ;
19
19
use rustc_data_structures:: control_flow_graph:: { GraphPredecessors , GraphSuccessors } ;
20
20
use rustc_data_structures:: control_flow_graph:: ControlFlowGraph ;
21
+ use rustc_serialize as serialize;
21
22
use hir:: def:: CtorKind ;
22
23
use hir:: def_id:: DefId ;
23
24
use ty:: subst:: { Subst , Substs } ;
@@ -33,7 +34,7 @@ use std::fmt::{self, Debug, Formatter, Write};
33
34
use std:: { iter, u32} ;
34
35
use std:: ops:: { Index , IndexMut } ;
35
36
use std:: vec:: IntoIter ;
36
- use syntax:: ast:: Name ;
37
+ use syntax:: ast:: { self , Name } ;
37
38
use syntax_pos:: Span ;
38
39
39
40
mod cache;
@@ -96,6 +97,10 @@ pub struct Mir<'tcx> {
96
97
/// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`.
97
98
pub visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
98
99
100
+ /// Crate-local information for each visibility scope, that can't (and
101
+ /// needn't) be tracked across crates.
102
+ pub visibility_scope_info : ClearOnDecode < IndexVec < VisibilityScope , VisibilityScopeInfo > > ,
103
+
99
104
/// Rvalues promoted from this function, such as borrows of constants.
100
105
/// Each of them is the Mir of a constant with the fn's type parameters
101
106
/// in scope, but a separate set of locals.
@@ -151,6 +156,8 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
151
156
impl < ' tcx > Mir < ' tcx > {
152
157
pub fn new ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
153
158
visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
159
+ visibility_scope_info : ClearOnDecode < IndexVec < VisibilityScope ,
160
+ VisibilityScopeInfo > > ,
154
161
promoted : IndexVec < Promoted , Mir < ' tcx > > ,
155
162
return_ty : Ty < ' tcx > ,
156
163
yield_ty : Option < Ty < ' tcx > > ,
@@ -167,6 +174,7 @@ impl<'tcx> Mir<'tcx> {
167
174
Mir {
168
175
basic_blocks,
169
176
visibility_scopes,
177
+ visibility_scope_info,
170
178
promoted,
171
179
return_ty,
172
180
yield_ty,
@@ -278,9 +286,16 @@ impl<'tcx> Mir<'tcx> {
278
286
}
279
287
}
280
288
289
+ #[ derive( Clone , Debug ) ]
290
+ pub struct VisibilityScopeInfo {
291
+ /// A NodeId with lint levels equivalent to this scope's lint levels.
292
+ pub lint_root : ast:: NodeId ,
293
+ }
294
+
281
295
impl_stable_hash_for ! ( struct Mir <' tcx> {
282
296
basic_blocks,
283
297
visibility_scopes,
298
+ visibility_scope_info,
284
299
promoted,
285
300
return_ty,
286
301
yield_ty,
@@ -310,6 +325,24 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
310
325
}
311
326
}
312
327
328
+ #[ derive( Clone , Debug ) ]
329
+ pub enum ClearOnDecode < T > {
330
+ Clear ,
331
+ Set ( T )
332
+ }
333
+
334
+ impl < T > serialize:: Encodable for ClearOnDecode < T > {
335
+ fn encode < S : serialize:: Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
336
+ serialize:: Encodable :: encode ( & ( ) , s)
337
+ }
338
+ }
339
+
340
+ impl < T > serialize:: Decodable for ClearOnDecode < T > {
341
+ fn decode < D : serialize:: Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {
342
+ serialize:: Decodable :: decode ( d) . map ( |( ) | ClearOnDecode :: Clear )
343
+ }
344
+ }
345
+
313
346
/// Grouped information about the source code origin of a MIR entity.
314
347
/// Intended to be inspected by diagnostics and debuginfo.
315
348
/// Most passes can work with it as a whole, within a single function.
@@ -438,6 +471,12 @@ pub struct LocalDecl<'tcx> {
438
471
439
472
/// Source info of the local.
440
473
pub source_info : SourceInfo ,
474
+
475
+ /// The *lexical* visibility scope the local is defined
476
+ /// in. If the local was defined in a let-statement, this
477
+ /// is *within* the let-statement, rather than outside
478
+ /// of iit.
479
+ pub lexical_scope : VisibilityScope ,
441
480
}
442
481
443
482
impl < ' tcx > LocalDecl < ' tcx > {
@@ -452,6 +491,7 @@ impl<'tcx> LocalDecl<'tcx> {
452
491
span,
453
492
scope : ARGUMENT_VISIBILITY_SCOPE
454
493
} ,
494
+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
455
495
internal : false ,
456
496
is_user_variable : false
457
497
}
@@ -468,6 +508,7 @@ impl<'tcx> LocalDecl<'tcx> {
468
508
span,
469
509
scope : ARGUMENT_VISIBILITY_SCOPE
470
510
} ,
511
+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
471
512
internal : true ,
472
513
is_user_variable : false
473
514
}
@@ -485,6 +526,7 @@ impl<'tcx> LocalDecl<'tcx> {
485
526
span,
486
527
scope : ARGUMENT_VISIBILITY_SCOPE
487
528
} ,
529
+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
488
530
internal : false ,
489
531
name : None , // FIXME maybe we do want some name here?
490
532
is_user_variable : false
@@ -1607,6 +1649,7 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
1607
1649
Mir {
1608
1650
basic_blocks : self . basic_blocks . fold_with ( folder) ,
1609
1651
visibility_scopes : self . visibility_scopes . clone ( ) ,
1652
+ visibility_scope_info : self . visibility_scope_info . clone ( ) ,
1610
1653
promoted : self . promoted . fold_with ( folder) ,
1611
1654
return_ty : self . return_ty . fold_with ( folder) ,
1612
1655
yield_ty : self . yield_ty . fold_with ( folder) ,
0 commit comments