@@ -16,7 +16,6 @@ use middle::trans::base::{trans_enum_variant, push_ctxt, get_item_val};
16
16
use middle:: trans:: base:: { trans_fn, decl_internal_rust_fn} ;
17
17
use middle:: trans:: base;
18
18
use middle:: trans:: common:: * ;
19
- use middle:: trans:: meth;
20
19
use middle:: trans:: intrinsic;
21
20
use middle:: ty;
22
21
use middle:: typeck;
@@ -26,7 +25,7 @@ use syntax::abi;
26
25
use syntax:: ast;
27
26
use syntax:: ast_map;
28
27
use syntax:: ast_util:: local_def;
29
- use std:: hash:: sip;
28
+ use std:: hash:: { sip, Hash } ;
30
29
31
30
pub fn monomorphic_fn ( ccx : & CrateContext ,
32
31
fn_id : ast:: DefId ,
@@ -71,7 +70,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
71
70
} ) . collect ( )
72
71
} ;
73
72
74
- let hash_id = @ mono_id_ {
73
+ let hash_id = MonoId {
75
74
def : fn_id,
76
75
params : param_ids
77
76
} ;
@@ -194,16 +193,22 @@ pub fn monomorphic_fn(ccx: &CrateContext,
194
193
}
195
194
196
195
let s = ccx. tcx . map . with_path ( fn_id. node , |path| {
197
- exported_name ( path, format ! ( "h{}" , sip:: hash( & ( hash_id, mono_ty) ) ) ,
196
+ let mut state = sip:: SipState :: new ( ) ;
197
+ hash_id. hash ( & mut state) ;
198
+ mono_ty. hash ( & mut state) ;
199
+
200
+ exported_name ( path, format ! ( "h{}" , state. result( ) ) ,
198
201
ccx. link_meta . crateid . version_or_default ( ) )
199
202
} ) ;
200
203
debug ! ( "monomorphize_fn mangled to {}" , s) ;
201
204
205
+ // This shouldn't need to option dance.
206
+ let mut hash_id = Some ( hash_id) ;
202
207
let mk_lldecl = || {
203
208
let lldecl = decl_internal_rust_fn ( ccx, false ,
204
209
f. sig . inputs . as_slice ( ) ,
205
210
f. sig . output , s) ;
206
- ccx. monomorphized . borrow_mut ( ) . insert ( hash_id, lldecl) ;
211
+ ccx. monomorphized . borrow_mut ( ) . insert ( hash_id. take_unwrap ( ) , lldecl) ;
207
212
lldecl
208
213
} ;
209
214
@@ -305,21 +310,34 @@ pub fn monomorphic_fn(ccx: &CrateContext,
305
310
( lldecl, false )
306
311
}
307
312
313
+ // Used to identify cached monomorphized functions and vtables
314
+ #[ deriving( Eq , TotalEq , Hash ) ]
315
+ pub struct MonoParamId {
316
+ pub subst : ty:: t ,
317
+ // Do we really need the vtables to be hashed? Isn't the type enough?
318
+ pub vtables : Vec < MonoId >
319
+ }
320
+
321
+ #[ deriving( Eq , TotalEq , Hash ) ]
322
+ pub struct MonoId {
323
+ pub def : ast:: DefId ,
324
+ pub params : Vec < MonoParamId >
325
+ }
326
+
308
327
pub fn make_vtable_id ( ccx : & CrateContext ,
309
328
origin : & typeck:: vtable_origin )
310
- -> mono_id {
329
+ -> MonoId {
311
330
match origin {
312
331
& 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_ {
332
+ MonoId {
321
333
def : impl_id,
322
- params : param_ids
334
+ params : sub_vtables. iter ( ) . zip ( substs. iter ( ) ) . map ( |( vtable, subst) | {
335
+ MonoParamId {
336
+ subst : * subst,
337
+ // Do we really need the vtables to be hashed? Isn't the type enough?
338
+ vtables : vtable. iter ( ) . map ( |vt| make_vtable_id ( ccx, vt) ) . collect ( )
339
+ }
340
+ } ) . collect ( )
323
341
}
324
342
}
325
343
0 commit comments