@@ -611,6 +611,7 @@ pub struct ctxt<'tcx> {
611611 /// The arena that types are allocated from.
612612 type_arena : & ' tcx TypedArena < TyS < ' tcx > > ,
613613 substs_arena : & ' tcx TypedArena < Substs < ' tcx > > ,
614+ bare_fn_arena : & ' tcx TypedArena < BareFnTy < ' tcx > > ,
614615
615616 /// Specifically use a speedy hash algorithm for this hash map, it's used
616617 /// quite often.
@@ -619,6 +620,7 @@ pub struct ctxt<'tcx> {
619620 interner : RefCell < FnvHashMap < InternedTy < ' tcx > , Ty < ' tcx > > > ,
620621 // FIXME as above, use a hashset if equivalent elements can be queried.
621622 substs_interner : RefCell < FnvHashMap < & ' tcx Substs < ' tcx > , & ' tcx Substs < ' tcx > > > ,
623+ bare_fn_interner : RefCell < FnvHashMap < & ' tcx BareFnTy < ' tcx > , & ' tcx BareFnTy < ' tcx > > > ,
622624
623625 pub sess : Session ,
624626 pub def_map : DefMap ,
@@ -1327,7 +1329,7 @@ pub enum sty<'tcx> {
13271329
13281330 // If the def-id is Some(_), then this is the type of a specific
13291331 // fn item. Otherwise, if None(_), it a fn pointer type.
1330- ty_bare_fn( Option < DefId > , BareFnTy < ' tcx > ) ,
1332+ ty_bare_fn( Option < DefId > , & ' tcx BareFnTy < ' tcx > ) ,
13311333
13321334 ty_closure( Box < ClosureTy < ' tcx > > ) ,
13331335 ty_trait( Box < TyTrait < ' tcx > > ) ,
@@ -2056,6 +2058,7 @@ impl UnboxedClosureKind {
20562058pub fn mk_ctxt < ' tcx > ( s : Session ,
20572059 type_arena : & ' tcx TypedArena < TyS < ' tcx > > ,
20582060 substs_arena : & ' tcx TypedArena < Substs < ' tcx > > ,
2061+ bare_fn_arena : & ' tcx TypedArena < BareFnTy < ' tcx > > ,
20592062 dm : DefMap ,
20602063 named_region_map : resolve_lifetime:: NamedRegionMap ,
20612064 map : ast_map:: Map < ' tcx > ,
@@ -2067,8 +2070,10 @@ pub fn mk_ctxt<'tcx>(s: Session,
20672070 ctxt {
20682071 type_arena : type_arena,
20692072 substs_arena : substs_arena,
2073+ bare_fn_arena : bare_fn_arena,
20702074 interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
20712075 substs_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
2076+ bare_fn_interner : RefCell :: new ( FnvHashMap :: new ( ) ) ,
20722077 named_region_map : named_region_map,
20732078 item_variance_map : RefCell :: new ( DefIdMap :: new ( ) ) ,
20742079 variance_computed : Cell :: new ( false ) ,
@@ -2138,6 +2143,16 @@ impl<'tcx> ctxt<'tcx> {
21382143 self . substs_interner . borrow_mut ( ) . insert ( substs, substs) ;
21392144 substs
21402145 }
2146+
2147+ pub fn mk_bare_fn ( & self , bare_fn : BareFnTy < ' tcx > ) -> & ' tcx BareFnTy < ' tcx > {
2148+ if let Some ( bare_fn) = self . bare_fn_interner . borrow ( ) . get ( & bare_fn) {
2149+ return * bare_fn;
2150+ }
2151+
2152+ let bare_fn = self . bare_fn_arena . alloc ( bare_fn) ;
2153+ self . bare_fn_interner . borrow_mut ( ) . insert ( bare_fn, bare_fn) ;
2154+ bare_fn
2155+ }
21412156}
21422157
21432158// Interns a type/name combination, stores the resulting box in cx.interner,
@@ -2444,7 +2459,7 @@ pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> {
24442459
24452460pub fn mk_bare_fn < ' tcx > ( cx : & ctxt < ' tcx > ,
24462461 opt_def_id : Option < ast:: DefId > ,
2447- fty : BareFnTy < ' tcx > ) -> Ty < ' tcx > {
2462+ fty : & ' tcx BareFnTy < ' tcx > ) -> Ty < ' tcx > {
24482463 mk_t ( cx, ty_bare_fn ( opt_def_id, fty) )
24492464}
24502465
@@ -2455,15 +2470,15 @@ pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>,
24552470 let input_args = input_tys. iter ( ) . map ( |ty| * ty) . collect ( ) ;
24562471 mk_bare_fn ( cx,
24572472 Some ( def_id) ,
2458- BareFnTy {
2473+ cx . mk_bare_fn ( BareFnTy {
24592474 unsafety : ast:: Unsafety :: Normal ,
24602475 abi : abi:: Rust ,
24612476 sig : ty:: Binder ( FnSig {
24622477 inputs : input_args,
24632478 output : ty:: FnConverging ( output) ,
24642479 variadic : false
24652480 } )
2466- } )
2481+ } ) )
24672482}
24682483
24692484
0 commit comments