@@ -50,11 +50,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
50
50
fn_id=%s, \
51
51
real_substs=%s, \
52
52
vtables=%s, \
53
+ self_vtable=%s, \
53
54
impl_did_opt=%s, \
54
55
ref_id=%?)",
55
56
fn_id. repr( ccx. tcx) ,
56
57
real_substs. repr( ccx. tcx) ,
57
58
vtables. repr( ccx. tcx) ,
59
+ self_vtable. repr( ccx. tcx) ,
58
60
impl_did_opt. repr( ccx. tcx) ,
59
61
ref_id) ;
60
62
@@ -71,7 +73,16 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
71
73
for real_substs. tps. iter( ) . advance |s| { assert ! ( !ty:: type_has_params( * s) ) ; }
72
74
for substs. iter( ) . advance |s| { assert ! ( !ty:: type_has_params( * s) ) ; }
73
75
let param_uses = type_use:: type_uses_for( ccx, fn_id, substs. len( ) ) ;
74
- let hash_id = make_mono_id( ccx, fn_id, substs, vtables, impl_did_opt,
76
+
77
+ let psubsts = @param_substs {
78
+ tys : substs,
79
+ vtables : vtables,
80
+ self_ty : real_substs. self_ty,
81
+ self_vtable : self_vtable
82
+ } ;
83
+
84
+ let hash_id = make_mono_id ( ccx, fn_id, impl_did_opt,
85
+ & * psubsts,
75
86
Some ( param_uses) ) ;
76
87
if hash_id. params . iter ( ) . any_ (
77
88
|p| match * p { mono_precise( _, _) => false , _ => true } ) {
@@ -80,12 +91,10 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
80
91
81
92
debug ! ( "monomorphic_fn(\
82
93
fn_id=%s, \
83
- vtables=%s, \
84
- substs=%s, \
94
+ psubsts=%s, \
85
95
hash_id=%?)",
86
96
fn_id. repr( ccx. tcx) ,
87
- vtables. repr( ccx. tcx) ,
88
- substs. repr( ccx. tcx) ,
97
+ psubsts. repr( ccx. tcx) ,
89
98
hash_id) ;
90
99
91
100
match ccx. monomorphized . find ( & hash_id) {
@@ -142,8 +151,8 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
142
151
ast_map:: node_struct_ctor( _, i, pt) => ( pt, i. ident , i. span )
143
152
} ;
144
153
145
- let mono_ty = ty:: subst_tps( ccx. tcx, substs ,
146
- real_substs . self_ty, llitem_ty) ;
154
+ let mono_ty = ty:: subst_tps ( ccx. tcx , psubsts . tys ,
155
+ psubsts . self_ty , llitem_ty) ;
147
156
let llfty = type_of_fn_from_ty ( ccx, mono_ty) ;
148
157
149
158
ccx. stats . n_monos += 1 ;
@@ -172,13 +181,6 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
172
181
lldecl
173
182
} ;
174
183
175
- let psubsts = Some ( @param_substs {
176
- tys : substs,
177
- vtables : vtables,
178
- self_ty : real_substs. self_ty,
179
- self_vtable : self_vtable
180
- } ) ;
181
-
182
184
let lldecl = match map_node {
183
185
ast_map:: node_item( i@@ast:: item {
184
186
node : ast:: item_fn( ref decl, _, _, _, ref body) ,
@@ -192,7 +194,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
192
194
body,
193
195
d,
194
196
no_self,
195
- psubsts,
197
+ Some ( psubsts) ,
196
198
fn_id. node ,
197
199
[ ] ) ;
198
200
d
@@ -202,7 +204,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
202
204
}
203
205
ast_map:: node_foreign_item( i, _, _, _) => {
204
206
let d = mk_lldecl ( ) ;
205
- foreign:: trans_intrinsic( ccx, d, i, pt, psubsts. get ( ) , i. attrs,
207
+ foreign:: trans_intrinsic ( ccx, d, i, pt, psubsts, i. attrs ,
206
208
ref_id) ;
207
209
d
208
210
}
@@ -214,7 +216,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
214
216
match v. node . kind {
215
217
ast:: tuple_variant_kind( ref args) => {
216
218
trans_enum_variant ( ccx, enum_item. id , v, /*bad*/ copy * args,
217
- this_tv. disr_val, psubsts, d) ;
219
+ this_tv. disr_val , Some ( psubsts) , d) ;
218
220
}
219
221
ast:: struct_variant_kind( _) =>
220
222
ccx. tcx . sess . bug ( "can't monomorphize struct variants" ) ,
@@ -225,13 +227,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
225
227
// XXX: What should the self type be here?
226
228
let d = mk_lldecl ( ) ;
227
229
set_inline_hint_if_appr ( /*bad*/ copy mth. attrs , d) ;
228
- meth:: trans_method( ccx, pt, mth, psubsts, d) ;
230
+ meth:: trans_method ( ccx, pt, mth, Some ( psubsts) , d) ;
229
231
d
230
232
}
231
233
ast_map:: node_trait_method( @ast:: provided( mth) , _, pt) => {
232
234
let d = mk_lldecl ( ) ;
233
235
set_inline_hint_if_appr ( /*bad*/ copy mth. attrs , d) ;
234
- meth:: trans_method( ccx, /*bad*/ copy * pt, mth, psubsts, d) ;
236
+ meth:: trans_method ( ccx, /*bad*/ copy * pt, mth, Some ( psubsts) , d) ;
235
237
d
236
238
}
237
239
ast_map:: node_struct_ctor( struct_def, _, _) => {
@@ -241,7 +243,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
241
243
/*bad*/ copy struct_def. fields ,
242
244
struct_def. ctor_id . expect ( "ast-mapped tuple struct \
243
245
didn't have a ctor id") ,
244
- psubsts,
246
+ Some ( psubsts) ,
245
247
d) ;
246
248
d
247
249
}
@@ -320,26 +322,36 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
320
322
321
323
pub fn make_mono_id ( ccx : @mut CrateContext ,
322
324
item : ast:: def_id ,
323
- substs: & [ ty:: t] ,
324
- vtables: Option <typeck:: vtable_res>,
325
325
impl_did_opt : Option < ast:: def_id > ,
326
+ substs : & param_substs ,
326
327
param_uses : Option < @~[ type_use:: type_uses ] > ) -> mono_id {
327
328
// FIXME (possibly #5801): Need a lot of type hints to get
328
329
// .collect() to work.
329
- let precise_param_ids: ~[ ( ty:: t, Option <@~[ mono_id] >) ] = match vtables {
330
+ let substs_iter = substs. self_ty . iter ( ) . chain_ ( substs. tys . iter ( ) ) ;
331
+ let precise_param_ids: ~[ ( ty:: t , Option < @~[ mono_id ] > ) ] = match substs. vtables {
330
332
Some ( vts) => {
331
333
debug ! ( "make_mono_id vtables=%s substs=%s" ,
332
- vts. repr( ccx. tcx) , substs. repr( ccx. tcx) ) ;
333
- vts. iter( ) . zip( substs. iter( ) ) . transform( |( vtable, subst) | {
334
+ vts. repr( ccx. tcx) , substs. tys. repr( ccx. tcx) ) ;
335
+ let self_vtables = substs. self_vtable . map ( |vtbl| @~[ copy * vtbl] ) ;
336
+ let vts_iter = self_vtables. iter ( ) . chain_ ( vts. iter ( ) ) ;
337
+ vts_iter. zip ( substs_iter) . transform ( |( vtable, subst) | {
334
338
let v = vtable. map ( |vt| meth:: vtable_id ( ccx, vt) ) ;
335
339
( * subst, if !v. is_empty ( ) { Some ( @v) } else { None } )
336
340
} ) . collect ( )
337
341
}
338
- None => substs . iter ( ) . transform( |subst| ( * subst, None :: < @~[ mono_id ] > ) ) . collect( )
342
+ None => substs_iter . transform ( |subst| ( * subst, None :: < @~[ mono_id ] > ) ) . collect ( )
339
343
} ;
344
+
345
+
340
346
let param_ids = match param_uses {
341
347
Some ( ref uses) => {
342
- precise_param_ids. iter( ) . zip( uses. iter( ) ) . transform( |( id, uses) | {
348
+ // param_uses doesn't include a use for the self type.
349
+ // We just say it is fully used.
350
+ let self_use =
351
+ substs. self_ty . map ( |_| type_use:: use_repr|type_use:: use_tydesc) ;
352
+ let uses_iter = self_use. iter ( ) . chain_ ( uses. iter ( ) ) ;
353
+
354
+ precise_param_ids. iter ( ) . zip ( uses_iter) . transform ( |( id, uses) | {
343
355
if ccx. sess . no_monomorphic_collapse ( ) {
344
356
match copy * id {
345
357
( a, b) => mono_precise ( a, b)
0 commit comments