@@ -22,6 +22,7 @@ use middle::free_region::FreeRegionMap;
22
22
use middle:: region:: RegionMaps ;
23
23
use middle:: resolve_lifetime;
24
24
use middle:: stability;
25
+ use mir:: Mir ;
25
26
use ty:: subst:: { Kind , Substs } ;
26
27
use traits;
27
28
use ty:: { self , TraitRef , Ty , TypeAndMut } ;
@@ -65,8 +66,9 @@ pub struct CtxtArenas<'tcx> {
65
66
66
67
// references
67
68
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 > > > ,
70
72
}
71
73
72
74
impl < ' tcx > CtxtArenas < ' tcx > {
@@ -81,8 +83,9 @@ impl<'tcx> CtxtArenas<'tcx> {
81
83
layout : TypedArena :: new ( ) ,
82
84
83
85
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 ( )
86
89
}
87
90
}
88
91
}
@@ -358,6 +361,15 @@ pub struct GlobalCtxt<'tcx> {
358
361
359
362
pub map : ast_map:: Map < ' tcx > ,
360
363
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
+
361
373
// Records the free variables refrenced by every closure
362
374
// expression. Do not track deps for this, just recompute it from
363
375
// scratch every time.
@@ -604,6 +616,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
604
616
self . global_interners . arenas . generics . alloc ( generics)
605
617
}
606
618
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
+
607
623
pub fn intern_trait_def ( self , def : ty:: TraitDef < ' gcx > )
608
624
-> & ' gcx ty:: TraitDef < ' gcx > {
609
625
let did = def. trait_ref . def_id ;
@@ -617,7 +633,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
617
633
618
634
pub fn alloc_trait_def ( self , def : ty:: TraitDef < ' gcx > )
619
635
-> & ' gcx ty:: TraitDef < ' gcx > {
620
- self . global_interners . arenas . trait_defs . alloc ( def)
636
+ self . global_interners . arenas . trait_def . alloc ( def)
621
637
}
622
638
623
639
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> {
633
649
variants : Vec < ty:: VariantDefData < ' gcx , ' gcx > > )
634
650
-> ty:: AdtDefMaster < ' gcx > {
635
651
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) ;
637
653
self . insert_adt_def ( did, interned) ;
638
654
interned
639
655
}
@@ -738,6 +754,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
738
754
super_predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
739
755
fulfilled_predicates : RefCell :: new ( fulfilled_predicates) ,
740
756
map : map,
757
+ mir_map : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
741
758
freevars : RefCell :: new ( freevars) ,
742
759
maybe_unused_trait_imports : maybe_unused_trait_imports,
743
760
tcache : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
0 commit comments