@@ -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 } ;
@@ -63,8 +64,9 @@ pub struct CtxtArenas<'tcx> {
6364
6465 // references
6566 generics : TypedArena < ty:: Generics < ' tcx > > ,
66- trait_defs : TypedArena < ty:: TraitDef < ' tcx > > ,
67- adt_defs : TypedArena < ty:: AdtDefData < ' tcx , ' tcx > > ,
67+ trait_def : TypedArena < ty:: TraitDef < ' tcx > > ,
68+ adt_def : TypedArena < ty:: AdtDefData < ' tcx , ' tcx > > ,
69+ mir : TypedArena < RefCell < Mir < ' tcx > > > ,
6870}
6971
7072impl < ' tcx > CtxtArenas < ' tcx > {
@@ -79,8 +81,9 @@ impl<'tcx> CtxtArenas<'tcx> {
7981 layout : TypedArena :: new ( ) ,
8082
8183 generics : TypedArena :: new ( ) ,
82- trait_defs : TypedArena :: new ( ) ,
83- adt_defs : TypedArena :: new ( )
84+ trait_def : TypedArena :: new ( ) ,
85+ adt_def : TypedArena :: new ( ) ,
86+ mir : TypedArena :: new ( )
8487 }
8588 }
8689}
@@ -356,6 +359,15 @@ pub struct GlobalCtxt<'tcx> {
356359
357360 pub map : ast_map:: Map < ' tcx > ,
358361
362+ /// Maps from the def-id of a function/method or const/static
363+ /// to its MIR. Mutation is done at an item granularity to
364+ /// allow MIR optimization passes to function and still
365+ /// access cross-crate MIR (e.g. inlining or const eval).
366+ ///
367+ /// Note that cross-crate MIR appears to be always borrowed
368+ /// (in the `RefCell` sense) to prevent accidental mutation.
369+ pub mir_map : RefCell < DepTrackingMap < maps:: Mir < ' tcx > > > ,
370+
359371 // Records the free variables refrenced by every closure
360372 // expression. Do not track deps for this, just recompute it from
361373 // scratch every time.
@@ -602,6 +614,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
602614 self . global_interners . arenas . generics . alloc ( generics)
603615 }
604616
617+ pub fn alloc_mir ( self , mir : Mir < ' gcx > ) -> & ' gcx RefCell < Mir < ' gcx > > {
618+ self . global_interners . arenas . mir . alloc ( RefCell :: new ( mir) )
619+ }
620+
605621 pub fn intern_trait_def ( self , def : ty:: TraitDef < ' gcx > )
606622 -> & ' gcx ty:: TraitDef < ' gcx > {
607623 let did = def. trait_ref . def_id ;
@@ -615,7 +631,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
615631
616632 pub fn alloc_trait_def ( self , def : ty:: TraitDef < ' gcx > )
617633 -> & ' gcx ty:: TraitDef < ' gcx > {
618- self . global_interners . arenas . trait_defs . alloc ( def)
634+ self . global_interners . arenas . trait_def . alloc ( def)
619635 }
620636
621637 pub fn insert_adt_def ( self , did : DefId , adt_def : ty:: AdtDefMaster < ' gcx > ) {
@@ -631,7 +647,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
631647 variants : Vec < ty:: VariantDefData < ' gcx , ' gcx > > )
632648 -> ty:: AdtDefMaster < ' gcx > {
633649 let def = ty:: AdtDefData :: new ( self , did, kind, variants) ;
634- let interned = self . global_interners . arenas . adt_defs . alloc ( def) ;
650+ let interned = self . global_interners . arenas . adt_def . alloc ( def) ;
635651 self . insert_adt_def ( did, interned) ;
636652 interned
637653 }
@@ -736,6 +752,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
736752 super_predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
737753 fulfilled_predicates : RefCell :: new ( fulfilled_predicates) ,
738754 map : map,
755+ mir_map : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
739756 freevars : RefCell :: new ( freevars) ,
740757 maybe_unused_trait_imports : maybe_unused_trait_imports,
741758 tcache : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
0 commit comments