@@ -17,85 +17,77 @@ use dep_graph::{DepGraph, DepKind, DepTrackingMap, DepTrackingMapConfig};
17
17
use infer:: TransNormalize ;
18
18
use std:: cell:: RefCell ;
19
19
use std:: marker:: PhantomData ;
20
- use syntax:: ast;
21
- use syntax_pos:: Span ;
20
+ use syntax_pos:: DUMMY_SP ;
22
21
use traits:: { FulfillmentContext , Obligation , ObligationCause , SelectionContext , Vtable } ;
23
22
use ty:: { self , Ty , TyCtxt } ;
24
23
use ty:: subst:: { Subst , Substs } ;
25
24
use ty:: fold:: { TypeFoldable , TypeFolder } ;
26
25
use util:: common:: MemoizationMap ;
27
26
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
- presuming due to overflow",
70
- trait_ref) ;
71
- self . sess . span_fatal ( span,
72
- "reached the recursion limit during monomorphization \
73
- (selection ambiguity)") ;
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
+ presuming due to overflow",
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
+ }
98
89
90
+ impl < ' a , ' tcx > TyCtxt < ' a , ' tcx , ' tcx > {
99
91
/// Monomorphizes a type from the AST by first applying the in-scope
100
92
/// substitutions and then normalizing any associated types.
101
93
pub fn trans_apply_param_substs < T > ( self ,
@@ -149,14 +141,12 @@ impl<'a, 'gcx> TypeFolder<'gcx, 'gcx> for AssociatedTypeNormalizer<'a, 'gcx> {
149
141
/// Specializes caches used in trans -- in particular, they assume all
150
142
/// types are fully monomorphized and that free regions can be erased.
151
143
pub struct TransTraitCaches < ' tcx > {
152
- trait_cache : RefCell < DepTrackingMap < TraitSelectionCache < ' tcx > > > ,
153
144
project_cache : RefCell < DepTrackingMap < ProjectionCache < ' tcx > > > ,
154
145
}
155
146
156
147
impl < ' tcx > TransTraitCaches < ' tcx > {
157
148
pub fn new ( graph : DepGraph ) -> Self {
158
149
TransTraitCaches {
159
- trait_cache : RefCell :: new ( DepTrackingMap :: new ( graph. clone ( ) ) ) ,
160
150
project_cache : RefCell :: new ( DepTrackingMap :: new ( graph) ) ,
161
151
}
162
152
}
0 commit comments