@@ -18,6 +18,7 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1818use rustc_data_structures:: control_flow_graph:: dominators:: { Dominators , dominators} ;
1919use rustc_data_structures:: control_flow_graph:: { GraphPredecessors , GraphSuccessors } ;
2020use rustc_data_structures:: control_flow_graph:: ControlFlowGraph ;
21+ use rustc_serialize as serialize;
2122use hir:: def:: CtorKind ;
2223use hir:: def_id:: DefId ;
2324use ty:: subst:: { Subst , Substs } ;
@@ -33,7 +34,7 @@ use std::fmt::{self, Debug, Formatter, Write};
3334use std:: { iter, u32} ;
3435use std:: ops:: { Index , IndexMut } ;
3536use std:: vec:: IntoIter ;
36- use syntax:: ast:: Name ;
37+ use syntax:: ast:: { self , Name } ;
3738use syntax_pos:: Span ;
3839
3940mod cache;
@@ -96,6 +97,10 @@ pub struct Mir<'tcx> {
9697 /// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`.
9798 pub visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
9899
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+
99104 /// Rvalues promoted from this function, such as borrows of constants.
100105 /// Each of them is the Mir of a constant with the fn's type parameters
101106 /// in scope, but a separate set of locals.
@@ -151,6 +156,8 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
151156impl < ' tcx > Mir < ' tcx > {
152157 pub fn new ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
153158 visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
159+ visibility_scope_info : ClearOnDecode < IndexVec < VisibilityScope ,
160+ VisibilityScopeInfo > > ,
154161 promoted : IndexVec < Promoted , Mir < ' tcx > > ,
155162 return_ty : Ty < ' tcx > ,
156163 yield_ty : Option < Ty < ' tcx > > ,
@@ -167,6 +174,7 @@ impl<'tcx> Mir<'tcx> {
167174 Mir {
168175 basic_blocks,
169176 visibility_scopes,
177+ visibility_scope_info,
170178 promoted,
171179 return_ty,
172180 yield_ty,
@@ -278,9 +286,16 @@ impl<'tcx> Mir<'tcx> {
278286 }
279287}
280288
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+
281295impl_stable_hash_for ! ( struct Mir <' tcx> {
282296 basic_blocks,
283297 visibility_scopes,
298+ visibility_scope_info,
284299 promoted,
285300 return_ty,
286301 yield_ty,
@@ -310,6 +325,24 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
310325 }
311326}
312327
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+
313346/// Grouped information about the source code origin of a MIR entity.
314347/// Intended to be inspected by diagnostics and debuginfo.
315348/// Most passes can work with it as a whole, within a single function.
@@ -438,6 +471,12 @@ pub struct LocalDecl<'tcx> {
438471
439472 /// Source info of the local.
440473 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 ,
441480}
442481
443482impl < ' tcx > LocalDecl < ' tcx > {
@@ -452,6 +491,7 @@ impl<'tcx> LocalDecl<'tcx> {
452491 span,
453492 scope : ARGUMENT_VISIBILITY_SCOPE
454493 } ,
494+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
455495 internal : false ,
456496 is_user_variable : false
457497 }
@@ -468,6 +508,7 @@ impl<'tcx> LocalDecl<'tcx> {
468508 span,
469509 scope : ARGUMENT_VISIBILITY_SCOPE
470510 } ,
511+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
471512 internal : true ,
472513 is_user_variable : false
473514 }
@@ -485,6 +526,7 @@ impl<'tcx> LocalDecl<'tcx> {
485526 span,
486527 scope : ARGUMENT_VISIBILITY_SCOPE
487528 } ,
529+ lexical_scope : ARGUMENT_VISIBILITY_SCOPE ,
488530 internal : false ,
489531 name : None , // FIXME maybe we do want some name here?
490532 is_user_variable : false
@@ -1607,6 +1649,7 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
16071649 Mir {
16081650 basic_blocks : self . basic_blocks . fold_with ( folder) ,
16091651 visibility_scopes : self . visibility_scopes . clone ( ) ,
1652+ visibility_scope_info : self . visibility_scope_info . clone ( ) ,
16101653 promoted : self . promoted . fold_with ( folder) ,
16111654 return_ty : self . return_ty . fold_with ( folder) ,
16121655 yield_ty : self . yield_ty . fold_with ( folder) ,
0 commit comments