@@ -177,9 +177,7 @@ pub fn trans_method_callee(bcx: block,
177
177
// Now that we know the impl ID, we can look up the method
178
178
// ID from its name
179
179
origin = typeck:: method_static(
180
- method_with_name_or_default( bcx. ccx( ) ,
181
- impl_id,
182
- method_name) ) ;
180
+ method_with_name( bcx. ccx( ) , impl_id, method_name) ) ;
183
181
}
184
182
typeck:: method_self( * ) |
185
183
typeck:: method_static( * ) | typeck:: method_param( * ) |
@@ -308,12 +306,10 @@ pub fn trans_static_method_callee(bcx: block,
308
306
typeck:: vtable_static( impl_did, ref rcvr_substs, rcvr_origins) => {
309
307
assert ! ( rcvr_substs. iter( ) . all( |t| !ty:: type_needs_infer( * t) ) ) ;
310
308
311
- let mth_id = method_with_name_or_default( bcx. ccx( ) ,
312
- impl_did,
313
- mname) ;
309
+ let mth_id = method_with_name( bcx. ccx( ) , impl_did, mname) ;
314
310
let ( callee_substs, callee_origins) =
315
311
combine_impl_and_methods_tps(
316
- bcx, mth_id, impl_did , callee_id,
312
+ bcx, mth_id, callee_id,
317
313
* rcvr_substs, rcvr_origins) ;
318
314
319
315
let FnData { llfn : lval} =
@@ -334,58 +330,22 @@ pub fn trans_static_method_callee(bcx: block,
334
330
}
335
331
}
336
332
337
- pub fn method_from_methods( ms: & [ @ast:: method] , name: ast:: ident)
338
- -> Option < ast:: def_id > {
339
- ms. iter( ) . find_( |m| m. ident == name) . map( |m| ast_util:: local_def( m. id) )
340
- }
341
-
342
- pub fn method_with_name_or_default( ccx: & mut CrateContext ,
343
- impl_id: ast:: def_id,
344
- name: ast:: ident) -> ast:: def_id {
345
- let imp = ccx. impl_method_cache. find_copy( & ( impl_id, name) ) ;
346
- match imp {
333
+ pub fn method_with_name( ccx: & mut CrateContext ,
334
+ impl_id: ast:: def_id,
335
+ name: ast:: ident) -> ast:: def_id {
336
+ let meth_id_opt = ccx. impl_method_cache. find_copy( & ( impl_id, name) ) ;
337
+ match meth_id_opt {
347
338
Some ( m) => return m,
348
339
None => { }
349
340
}
350
341
351
- // None of this feels like it should be the best way to do this.
352
- let mut did = if impl_id. crate == ast:: local_crate {
353
- match ccx. tcx. items. get_copy( & impl_id. node) {
354
- ast_map:: node_item( @ast:: item {
355
- node : ast:: item_impl( _, _, _, ref ms) , _
356
- } , _) => { method_from_methods( * ms, name) } ,
357
- _ => fail ! ( "method_with_name" )
358
- }
359
- } else {
360
- csearch:: get_impl_method( ccx. sess. cstore, impl_id, name)
361
- } ;
362
-
363
- if did. is_none( ) {
364
- // Look for a default method
365
- let pmm = ccx. tcx. provided_methods;
366
- match pmm. find( & impl_id) {
367
- Some ( pmis) => {
368
- for pmis. iter( ) . advance |pmi| {
369
- if pmi. method_info. ident == name {
370
- debug!( "pmi.method_info.did = %?" ,
371
- pmi. method_info. did) ;
372
- did = Some ( pmi. method_info. did) ;
373
- }
374
- }
375
- }
376
- None => { }
377
- }
378
- }
379
-
380
- let imp = did. expect( "could not find method while translating" ) ;
381
- ccx. impl_method_cache. insert( ( impl_id, name) , imp) ;
382
- imp
383
- }
342
+ let imp = ccx. tcx. impls. find( & impl_id)
343
+ . expect( "could not find impl while translating" ) ;
344
+ let meth = imp. methods. iter( ) . find_( |m| m. ident == name)
345
+ . expect( "could not find method while translating" ) ;
384
346
385
- pub fn method_ty_param_count( ccx: & CrateContext , m_id: ast:: def_id,
386
- i_id: ast:: def_id) -> uint {
387
- debug!( "method_ty_param_count: m_id: %?, i_id: %?" , m_id, i_id) ;
388
- ty:: method( ccx. tcx, m_id) . generics. type_param_defs. len( )
347
+ ccx. impl_method_cache. insert( ( impl_id, name) , meth. did) ;
348
+ meth. did
389
349
}
390
350
391
351
pub fn trans_monomorphized_callee( bcx: block,
@@ -401,8 +361,7 @@ pub fn trans_monomorphized_callee(bcx: block,
401
361
typeck : : vtable_static( impl_did, ref rcvr_substs, rcvr_origins) => {
402
362
let ccx = bcx. ccx( ) ;
403
363
let mname = ty:: trait_method( ccx. tcx, trait_id, n_method) . ident;
404
- let mth_id = method_with_name_or_default(
405
- bcx. ccx( ) , impl_did, mname) ;
364
+ let mth_id = method_with_name( bcx. ccx( ) , impl_did, mname) ;
406
365
407
366
// obtain the `self` value:
408
367
let mut temp_cleanups = ~[ ] ;
@@ -413,7 +372,7 @@ pub fn trans_monomorphized_callee(bcx: block,
413
372
// those from the impl and those from the method:
414
373
let ( callee_substs, callee_origins) =
415
374
combine_impl_and_methods_tps(
416
- bcx, mth_id, impl_did , callee_id,
375
+ bcx, mth_id, callee_id,
417
376
* rcvr_substs, rcvr_origins) ;
418
377
419
378
// translate the function
@@ -452,7 +411,6 @@ pub fn trans_monomorphized_callee(bcx: block,
452
411
453
412
pub fn combine_impl_and_methods_tps( bcx: block,
454
413
mth_did: ast:: def_id,
455
- impl_did: ast:: def_id,
456
414
callee_id: ast:: node_id,
457
415
rcvr_substs: & [ ty:: t] ,
458
416
rcvr_origins: typeck:: vtable_res)
@@ -475,15 +433,16 @@ pub fn combine_impl_and_methods_tps(bcx: block,
475
433
* mapped to. */
476
434
477
435
let ccx = bcx. ccx( ) ;
478
- let n_m_tps = method_ty_param_count( ccx, mth_did, impl_did) ;
436
+ let method = ty:: method( ccx. tcx, mth_did) ;
437
+ let n_m_tps = method. generics. type_param_defs. len( ) ;
479
438
let node_substs = node_id_type_params( bcx, callee_id) ;
480
- debug!( "rcvr_substs=%?", rcvr_substs. map ( |t| bcx . ty_to_str ( * t ) ) ) ;
439
+ debug ! ( "rcvr_substs=%?" , rcvr_substs. repr ( ccx . tcx ) ) ;
481
440
let ty_substs
482
441
= vec:: append( rcvr_substs. to_owned( ) ,
483
442
node_substs. tailn( node_substs. len( ) - n_m_tps) ) ;
484
443
debug ! ( "n_m_tps=%?" , n_m_tps) ;
485
- debug!( "node_substs=%?", node_substs. map ( |t| bcx . ty_to_str ( * t ) ) ) ;
486
- debug!( "ty_substs=%?", ty_substs. map ( |t| bcx . ty_to_str ( * t ) ) ) ;
444
+ debug ! ( "node_substs=%?" , node_substs. repr ( ccx . tcx ) ) ;
445
+ debug ! ( "ty_substs=%?" , ty_substs. repr ( ccx . tcx ) ) ;
487
446
488
447
489
448
// Now, do the same work for the vtables. The vtables might not
@@ -744,7 +703,7 @@ pub fn make_impl_vtable(bcx: block,
744
703
} else {
745
704
debug ! ( "(making impl vtable) adding method to vtable: %s" ,
746
705
tcx. sess. str_of( im. ident) ) ;
747
- let m_id = method_with_name_or_default ( ccx, impl_id, im. ident) ;
706
+ let m_id = method_with_name ( ccx, impl_id, im. ident) ;
748
707
749
708
trans_fn_ref_with_vtables( bcx, m_id, 0 ,
750
709
substs, Some ( vtables) ) . llfn
0 commit comments