@@ -47,21 +47,51 @@ pub fn monomorphic_fn(ccx: &CrateContext,
47
47
self_vtables. repr( ccx. tcx( ) ) ,
48
48
ref_id) ;
49
49
50
- assert ! ( real_substs. tps. iter( ) . all( |t| !ty:: type_needs_infer( * t) ) ) ;
50
+ assert ! ( real_substs. tps. iter( ) . all( |t| {
51
+ !ty:: type_needs_infer( * t) && !ty:: type_has_params( * t)
52
+ } ) ) ;
53
+
51
54
let _icx = push_ctxt ( "monomorphic_fn" ) ;
52
55
56
+ let substs_iter = real_substs. self_ty . iter ( ) . chain ( real_substs. tps . iter ( ) ) ;
57
+ let param_ids: Vec < MonoParamId > = match vtables {
58
+ Some ( ref vts) => {
59
+ debug ! ( "make_mono_id vtables={} psubsts={}" ,
60
+ vts. repr( ccx. tcx( ) ) , real_substs. tps. repr( ccx. tcx( ) ) ) ;
61
+ let vts_iter = self_vtables. iter ( ) . chain ( vts. iter ( ) ) ;
62
+ vts_iter. zip ( substs_iter) . map ( |( vtable, subst) | MonoParamId {
63
+ subst : * subst,
64
+ // Do we really need the vtables to be hashed? Isn't the type enough?
65
+ vtables : vtable. iter ( ) . map ( |vt| make_vtable_id ( ccx, vt) ) . collect ( )
66
+ } ) . collect ( )
67
+ }
68
+ None => substs_iter. map ( |subst| MonoParamId {
69
+ subst : * subst,
70
+ vtables : Vec :: new ( )
71
+ } ) . collect ( )
72
+ } ;
73
+
74
+ let hash_id = @mono_id_ {
75
+ def : fn_id,
76
+ params : param_ids
77
+ } ;
78
+
79
+ match ccx. monomorphized . borrow ( ) . find ( & hash_id) {
80
+ Some ( & val) => {
81
+ debug ! ( "leaving monomorphic fn {}" ,
82
+ ty:: item_path_str( ccx. tcx( ) , fn_id) ) ;
83
+ return ( val, false ) ;
84
+ }
85
+ None => ( )
86
+ }
87
+
53
88
let psubsts = @param_substs {
54
89
tys : real_substs. tps . clone ( ) ,
55
90
vtables : vtables,
56
91
self_ty : real_substs. self_ty . clone ( ) ,
57
92
self_vtables : self_vtables
58
93
} ;
59
94
60
- for s in real_substs. tps . iter ( ) { assert ! ( !ty:: type_has_params( * s) ) ; }
61
- for s in psubsts. tys . iter ( ) { assert ! ( !ty:: type_has_params( * s) ) ; }
62
-
63
- let hash_id = make_mono_id ( ccx, fn_id, & * psubsts) ;
64
-
65
95
debug ! ( "monomorphic_fn(\
66
96
fn_id={}, \
67
97
psubsts={}, \
@@ -70,15 +100,6 @@ pub fn monomorphic_fn(ccx: &CrateContext,
70
100
psubsts. repr( ccx. tcx( ) ) ,
71
101
hash_id) ;
72
102
73
- match ccx. monomorphized . borrow ( ) . find ( & hash_id) {
74
- Some ( & val) => {
75
- debug ! ( "leaving monomorphic fn {}" ,
76
- ty:: item_path_str( ccx. tcx( ) , fn_id) ) ;
77
- return ( val, false ) ;
78
- }
79
- None => ( )
80
- }
81
-
82
103
let tpt = ty:: lookup_item_type ( ccx. tcx ( ) , fn_id) ;
83
104
let llitem_ty = tpt. ty ;
84
105
@@ -117,8 +138,8 @@ pub fn monomorphic_fn(ccx: &CrateContext,
117
138
118
139
debug ! ( "monomorphic_fn about to subst into {}" , llitem_ty. repr( ccx. tcx( ) ) ) ;
119
140
let mono_ty = match is_static_provided {
120
- None => ty:: subst_tps ( ccx. tcx ( ) , psubsts . tys . as_slice ( ) ,
121
- psubsts . self_ty , llitem_ty) ,
141
+ None => ty:: subst_tps ( ccx. tcx ( ) , real_substs . tps . as_slice ( ) ,
142
+ real_substs . self_ty , llitem_ty) ,
122
143
Some ( num_method_ty_params) => {
123
144
// Static default methods are a little unfortunate, in
124
145
// that the "internal" and "external" type of them differ.
@@ -134,9 +155,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
134
155
// stick a substitution for the self type in.
135
156
// This is a bit unfortunate.
136
157
137
- let idx = psubsts . tys . len ( ) - num_method_ty_params;
138
- let substs = psubsts . tys . slice ( 0 , idx) +
139
- & [ psubsts . self_ty . unwrap ( ) ] + psubsts . tys . tailn ( idx) ;
158
+ let idx = real_substs . tps . len ( ) - num_method_ty_params;
159
+ let substs = real_substs . tps . slice ( 0 , idx) +
160
+ & [ real_substs . self_ty . unwrap ( ) ] + real_substs . tps . tailn ( idx) ;
140
161
debug ! ( "static default: changed substitution to {}" ,
141
162
substs. repr( ccx. tcx( ) ) ) ;
142
163
@@ -284,28 +305,25 @@ pub fn monomorphic_fn(ccx: &CrateContext,
284
305
( lldecl, false )
285
306
}
286
307
287
- pub fn make_mono_id ( ccx : & CrateContext ,
288
- item : ast:: DefId ,
289
- substs : & param_substs ) -> mono_id {
290
- let substs_iter = substs. self_ty . iter ( ) . chain ( substs. tys . iter ( ) ) ;
291
- let param_ids: Vec < MonoParamId > = match substs. vtables {
292
- Some ( ref vts) => {
293
- debug ! ( "make_mono_id vtables={} substs={}" ,
294
- vts. repr( ccx. tcx( ) ) , substs. tys. repr( ccx. tcx( ) ) ) ;
295
- let vts_iter = substs. self_vtables . iter ( ) . chain ( vts. iter ( ) ) ;
296
- vts_iter. zip ( substs_iter) . map ( |( vtable, subst) | MonoParamId {
297
- subst : * subst,
298
- vtables : vtable. iter ( ) . map ( |vt| meth:: vtable_id ( ccx, vt) ) . collect ( )
299
- } ) . collect ( )
308
+ pub fn make_vtable_id ( ccx : & CrateContext ,
309
+ origin : & typeck:: vtable_origin )
310
+ -> mono_id {
311
+ match origin {
312
+ & typeck:: vtable_static( impl_id, ref substs, ref sub_vtables) => {
313
+ let param_ids = sub_vtables. iter ( ) . zip ( substs. iter ( ) ) . map ( |( vtable, subst) | {
314
+ MonoParamId {
315
+ subst : * subst,
316
+ vtables : vtable. iter ( ) . map ( |vt| make_vtable_id ( ccx, vt) ) . collect ( )
317
+ }
318
+ } ) . collect ( ) ;
319
+
320
+ @mono_id_ {
321
+ def : impl_id,
322
+ params : param_ids
323
+ }
300
324
}
301
- None => substs_iter. map ( |subst| MonoParamId {
302
- subst : * subst,
303
- vtables : Vec :: new ( )
304
- } ) . collect ( )
305
- } ;
306
325
307
- @mono_id_ {
308
- def : item,
309
- params : param_ids
326
+ // can't this be checked at the callee?
327
+ _ => fail ! ( "make_vtable_id needs vtable_static" )
310
328
}
311
329
}
0 commit comments