@@ -22,6 +22,7 @@ use middle::free_region::FreeRegionMap;
2222use middle:: region:: RegionMaps ;
2323use middle:: resolve_lifetime;
2424use middle:: stability;
25+ use mir:: Mir ;
2526use ty:: subst:: { Kind , Substs } ;
2627use traits;
2728use ty:: { self , TraitRef , Ty , TypeAndMut } ;
@@ -65,8 +66,9 @@ pub struct CtxtArenas<'tcx> {
6566
6667 // references
6768 generics : TypedArena < ty:: Generics < ' tcx > > ,
68- trait_defs : TypedArena < ty:: TraitDef < ' tcx > > ,
69- adt_defs : TypedArena < ty:: AdtDefData < ' tcx , ' tcx > > ,
69+ trait_def : TypedArena < ty:: TraitDef < ' tcx > > ,
70+ adt_def : TypedArena < ty:: AdtDefData < ' tcx , ' tcx > > ,
71+ mir : TypedArena < RefCell < Mir < ' tcx > > > ,
7072}
7173
7274impl < ' tcx > CtxtArenas < ' tcx > {
@@ -81,8 +83,9 @@ impl<'tcx> CtxtArenas<'tcx> {
8183 layout : TypedArena :: new ( ) ,
8284
8385 generics : TypedArena :: new ( ) ,
84- trait_defs : TypedArena :: new ( ) ,
85- adt_defs : TypedArena :: new ( )
86+ trait_def : TypedArena :: new ( ) ,
87+ adt_def : TypedArena :: new ( ) ,
88+ mir : TypedArena :: new ( )
8689 }
8790 }
8891}
@@ -358,6 +361,15 @@ pub struct GlobalCtxt<'tcx> {
358361
359362 pub map : ast_map:: Map < ' tcx > ,
360363
364+ /// Maps from the def-id of a function/method or const/static
365+ /// to its MIR. Mutation is done at an item granularity to
366+ /// allow MIR optimization passes to function and still
367+ /// access cross-crate MIR (e.g. inlining or const eval).
368+ ///
369+ /// Note that cross-crate MIR appears to be always borrowed
370+ /// (in the `RefCell` sense) to prevent accidental mutation.
371+ pub mir_map : RefCell < DepTrackingMap < maps:: Mir < ' tcx > > > ,
372+
361373 // Records the free variables refrenced by every closure
362374 // expression. Do not track deps for this, just recompute it from
363375 // scratch every time.
@@ -604,6 +616,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
604616 self . global_interners . arenas . generics . alloc ( generics)
605617 }
606618
619+ pub fn alloc_mir ( self , mir : Mir < ' gcx > ) -> & ' gcx RefCell < Mir < ' gcx > > {
620+ self . global_interners . arenas . mir . alloc ( RefCell :: new ( mir) )
621+ }
622+
607623 pub fn intern_trait_def ( self , def : ty:: TraitDef < ' gcx > )
608624 -> & ' gcx ty:: TraitDef < ' gcx > {
609625 let did = def. trait_ref . def_id ;
@@ -617,7 +633,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
617633
618634 pub fn alloc_trait_def ( self , def : ty:: TraitDef < ' gcx > )
619635 -> & ' gcx ty:: TraitDef < ' gcx > {
620- self . global_interners . arenas . trait_defs . alloc ( def)
636+ self . global_interners . arenas . trait_def . alloc ( def)
621637 }
622638
623639 pub fn insert_adt_def ( self , did : DefId , adt_def : ty:: AdtDefMaster < ' gcx > ) {
@@ -633,7 +649,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
633649 variants : Vec < ty:: VariantDefData < ' gcx , ' gcx > > )
634650 -> ty:: AdtDefMaster < ' gcx > {
635651 let def = ty:: AdtDefData :: new ( self , did, kind, variants) ;
636- let interned = self . global_interners . arenas . adt_defs . alloc ( def) ;
652+ let interned = self . global_interners . arenas . adt_def . alloc ( def) ;
637653 self . insert_adt_def ( did, interned) ;
638654 interned
639655 }
@@ -738,6 +754,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
738754 super_predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
739755 fulfilled_predicates : RefCell :: new ( fulfilled_predicates) ,
740756 map : map,
757+ mir_map : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
741758 freevars : RefCell :: new ( freevars) ,
742759 maybe_unused_trait_imports : maybe_unused_trait_imports,
743760 tcache : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
0 commit comments