@@ -17,85 +17,77 @@ use dep_graph::{DepGraph, DepKind, DepTrackingMap, DepTrackingMapConfig};
1717use  infer:: TransNormalize ; 
1818use  std:: cell:: RefCell ; 
1919use  std:: marker:: PhantomData ; 
20- use  syntax:: ast; 
21- use  syntax_pos:: Span ; 
20+ use  syntax_pos:: DUMMY_SP ; 
2221use  traits:: { FulfillmentContext ,  Obligation ,  ObligationCause ,  SelectionContext ,  Vtable } ; 
2322use  ty:: { self ,  Ty ,  TyCtxt } ; 
2423use  ty:: subst:: { Subst ,  Substs } ; 
2524use  ty:: fold:: { TypeFoldable ,  TypeFolder } ; 
2625use  util:: common:: MemoizationMap ; 
2726
28- impl < ' a ,  ' tcx >  TyCtxt < ' a ,  ' tcx ,  ' tcx >  { 
29-     /// Attempts to resolve an obligation to a vtable.. The result is 
30- /// a shallow vtable resolution -- meaning that we do not 
31- /// (necessarily) resolve all nested obligations on the impl. Note 
32- /// that type check should guarantee to us that all nested 
33- /// obligations *could be* resolved if we wanted to. 
34- /// Assumes that this is run after the entire crate has been successfully type-checked. 
35- pub  fn  trans_fulfill_obligation ( self , 
36-                                     span :  Span , 
37-                                     param_env :  ty:: ParamEnv < ' tcx > , 
38-                                     trait_ref :  ty:: PolyTraitRef < ' tcx > ) 
39-                                     -> Vtable < ' tcx ,  ( ) > 
40-     { 
41-         // Remove any references to regions; this helps improve caching. 
42-         let  trait_ref = self . erase_regions ( & trait_ref) ; 
43- 
44-         self . trans_trait_caches . trait_cache . memoize ( ( param_env,  trait_ref) ,  || { 
45-             debug ! ( "trans::fulfill_obligation(trait_ref={:?}, def_id={:?})" , 
46-                    ( param_env,  trait_ref) ,  trait_ref. def_id( ) ) ; 
47- 
48-             // Do the initial selection for the obligation. This yields the 
49-             // shallow result we are looking for -- that is, what specific impl. 
50-             self . infer_ctxt ( ) . enter ( |infcx| { 
51-                 let  mut  selcx = SelectionContext :: new ( & infcx) ; 
52- 
53-                 let  obligation_cause = ObligationCause :: misc ( span, 
54-                                                              ast:: DUMMY_NODE_ID ) ; 
55-                 let  obligation = Obligation :: new ( obligation_cause, 
56-                                                  param_env, 
57-                                                  trait_ref. to_poly_trait_predicate ( ) ) ; 
58- 
59-                 let  selection = match  selcx. select ( & obligation)  { 
60-                     Ok ( Some ( selection) )  => selection, 
61-                     Ok ( None )  => { 
62-                         // Ambiguity can happen when monomorphizing during trans 
63-                         // expands to some humongo type that never occurred 
64-                         // statically -- this humongo type can then overflow, 
65-                         // leading to an ambiguous result. So report this as an 
66-                         // overflow bug, since I believe this is the only case 
67-                         // where ambiguity can result. 
68-                         debug ! ( "Encountered ambiguity selecting `{:?}` during trans, \  
69- , 
70-                                trait_ref) ; 
71-                         self . sess . span_fatal ( span, 
72-                                             "reached the recursion limit during monomorphization \  
73- ) ; 
74-                     } 
75-                     Err ( e)  => { 
76-                         span_bug ! ( span,  "Encountered error `{:?}` selecting `{:?}` during trans" , 
77-                                   e,  trait_ref) 
78-                     } 
79-                 } ; 
80- 
81-                 debug ! ( "fulfill_obligation: selection={:?}" ,  selection) ; 
82- 
83-                 // Currently, we use a fulfillment context to completely resolve 
84-                 // all nested obligations. This is because they can inform the 
85-                 // inference of the impl's type parameters. 
86-                 let  mut  fulfill_cx = FulfillmentContext :: new ( ) ; 
87-                 let  vtable = selection. map ( |predicate| { 
88-                     debug ! ( "fulfill_obligation: register_predicate_obligation {:?}" ,  predicate) ; 
89-                     fulfill_cx. register_predicate_obligation ( & infcx,  predicate) ; 
90-                 } ) ; 
91-                 let  vtable = infcx. drain_fulfillment_cx_or_panic ( span,  & mut  fulfill_cx,  & vtable) ; 
92- 
93-                 info ! ( "Cache miss: {:?} => {:?}" ,  trait_ref,  vtable) ; 
94-                 vtable
95-             } ) 
96-         } ) 
97-     } 
27+ /// Attempts to resolve an obligation to a vtable.. The result is 
28+ /// a shallow vtable resolution -- meaning that we do not 
29+ /// (necessarily) resolve all nested obligations on the impl. Note 
30+ /// that type check should guarantee to us that all nested 
31+ /// obligations *could be* resolved if we wanted to. 
32+ /// Assumes that this is run after the entire crate has been successfully type-checked. 
33+ pub  fn  trans_fulfill_obligation < ' a ,  ' tcx > ( ty :  TyCtxt < ' a ,  ' tcx ,  ' tcx > , 
34+                                           ( param_env,  trait_ref) : 
35+                                           ( ty:: ParamEnv < ' tcx > ,  ty:: PolyTraitRef < ' tcx > ) ) 
36+                                           -> Vtable < ' tcx ,  ( ) > 
37+ { 
38+     // Remove any references to regions; this helps improve caching. 
39+     let  trait_ref = ty. erase_regions ( & trait_ref) ; 
40+ 
41+     debug ! ( "trans::fulfill_obligation(trait_ref={:?}, def_id={:?})" , 
42+             ( param_env,  trait_ref) ,  trait_ref. def_id( ) ) ; 
43+ 
44+     // Do the initial selection for the obligation. This yields the 
45+     // shallow result we are looking for -- that is, what specific impl. 
46+     ty. infer_ctxt ( ) . enter ( |infcx| { 
47+         let  mut  selcx = SelectionContext :: new ( & infcx) ; 
48+ 
49+         let  obligation_cause = ObligationCause :: dummy ( ) ; 
50+         let  obligation = Obligation :: new ( obligation_cause, 
51+                                             param_env, 
52+                                             trait_ref. to_poly_trait_predicate ( ) ) ; 
53+ 
54+         let  selection = match  selcx. select ( & obligation)  { 
55+             Ok ( Some ( selection) )  => selection, 
56+             Ok ( None )  => { 
57+                 // Ambiguity can happen when monomorphizing during trans 
58+                 // expands to some humongo type that never occurred 
59+                 // statically -- this humongo type can then overflow, 
60+                 // leading to an ambiguous result. So report this as an 
61+                 // overflow bug, since I believe this is the only case 
62+                 // where ambiguity can result. 
63+                 bug ! ( "Encountered ambiguity selecting `{:?}` during trans, \  
64+ , 
65+                         trait_ref) 
66+             } 
67+             Err ( e)  => { 
68+                 bug ! ( "Encountered error `{:?}` selecting `{:?}` during trans" , 
69+                             e,  trait_ref) 
70+             } 
71+         } ; 
72+ 
73+         debug ! ( "fulfill_obligation: selection={:?}" ,  selection) ; 
74+ 
75+         // Currently, we use a fulfillment context to completely resolve 
76+         // all nested obligations. This is because they can inform the 
77+         // inference of the impl's type parameters. 
78+         let  mut  fulfill_cx = FulfillmentContext :: new ( ) ; 
79+         let  vtable = selection. map ( |predicate| { 
80+             debug ! ( "fulfill_obligation: register_predicate_obligation {:?}" ,  predicate) ; 
81+             fulfill_cx. register_predicate_obligation ( & infcx,  predicate) ; 
82+         } ) ; 
83+         let  vtable = infcx. drain_fulfillment_cx_or_panic ( DUMMY_SP ,  & mut  fulfill_cx,  & vtable) ; 
84+ 
85+         info ! ( "Cache miss: {:?} => {:?}" ,  trait_ref,  vtable) ; 
86+         vtable
87+     } ) 
88+ } 
9889
90+ impl < ' a ,  ' tcx >  TyCtxt < ' a ,  ' tcx ,  ' tcx >  { 
9991    /// Monomorphizes a type from the AST by first applying the in-scope 
10092/// substitutions and then normalizing any associated types. 
10193pub  fn  trans_apply_param_substs < T > ( self , 
@@ -149,14 +141,12 @@ impl<'a, 'gcx> TypeFolder<'gcx, 'gcx> for AssociatedTypeNormalizer<'a, 'gcx> {
149141/// Specializes caches used in trans -- in particular, they assume all 
150142/// types are fully monomorphized and that free regions can be erased. 
151143pub  struct  TransTraitCaches < ' tcx >  { 
152-     trait_cache :  RefCell < DepTrackingMap < TraitSelectionCache < ' tcx > > > , 
153144    project_cache :  RefCell < DepTrackingMap < ProjectionCache < ' tcx > > > , 
154145} 
155146
156147impl < ' tcx >  TransTraitCaches < ' tcx >  { 
157148    pub  fn  new ( graph :  DepGraph )  -> Self  { 
158149        TransTraitCaches  { 
159-             trait_cache :  RefCell :: new ( DepTrackingMap :: new ( graph. clone ( ) ) ) , 
160150            project_cache :  RefCell :: new ( DepTrackingMap :: new ( graph) ) , 
161151        } 
162152    } 
0 commit comments