@@ -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 } ;
@@ -63,8 +64,9 @@ pub struct CtxtArenas<'tcx> {
63
64
64
65
// references
65
66
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 > > > ,
68
70
}
69
71
70
72
impl < ' tcx > CtxtArenas < ' tcx > {
@@ -79,8 +81,9 @@ impl<'tcx> CtxtArenas<'tcx> {
79
81
layout : TypedArena :: new ( ) ,
80
82
81
83
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 ( )
84
87
}
85
88
}
86
89
}
@@ -356,6 +359,15 @@ pub struct GlobalCtxt<'tcx> {
356
359
357
360
pub map : ast_map:: Map < ' tcx > ,
358
361
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
+
359
371
// Records the free variables refrenced by every closure
360
372
// expression. Do not track deps for this, just recompute it from
361
373
// scratch every time.
@@ -602,6 +614,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
602
614
self . global_interners . arenas . generics . alloc ( generics)
603
615
}
604
616
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
+
605
621
pub fn intern_trait_def ( self , def : ty:: TraitDef < ' gcx > )
606
622
-> & ' gcx ty:: TraitDef < ' gcx > {
607
623
let did = def. trait_ref . def_id ;
@@ -615,7 +631,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
615
631
616
632
pub fn alloc_trait_def ( self , def : ty:: TraitDef < ' gcx > )
617
633
-> & ' gcx ty:: TraitDef < ' gcx > {
618
- self . global_interners . arenas . trait_defs . alloc ( def)
634
+ self . global_interners . arenas . trait_def . alloc ( def)
619
635
}
620
636
621
637
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> {
631
647
variants : Vec < ty:: VariantDefData < ' gcx , ' gcx > > )
632
648
-> ty:: AdtDefMaster < ' gcx > {
633
649
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) ;
635
651
self . insert_adt_def ( did, interned) ;
636
652
interned
637
653
}
@@ -736,6 +752,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
736
752
super_predicates : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
737
753
fulfilled_predicates : RefCell :: new ( fulfilled_predicates) ,
738
754
map : map,
755
+ mir_map : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
739
756
freevars : RefCell :: new ( freevars) ,
740
757
maybe_unused_trait_imports : maybe_unused_trait_imports,
741
758
tcache : RefCell :: new ( DepTrackingMap :: new ( dep_graph. clone ( ) ) ) ,
0 commit comments