@@ -207,7 +207,9 @@ pub fn trans_method_callee(bcx: block,
207
207
let method_name =
208
208
ty:: trait_method ( tcx, trait_id, method_index) . ident ;
209
209
let method_id =
210
- method_with_name ( bcx. ccx ( ) , impl_def_id, method_name) ;
210
+ method_with_name_or_default ( bcx. ccx ( ) ,
211
+ impl_def_id,
212
+ method_name) ;
211
213
origin = typeck:: method_static ( method_id) ;
212
214
}
213
215
typeck:: method_super( trait_id, method_index) => {
@@ -229,9 +231,10 @@ pub fn trans_method_callee(bcx: block,
229
231
ty:: method ( tcx, supertrait_method_def_ids[ method_index] ) . ident ;
230
232
// Now that we know the impl ID, we can look up the method
231
233
// ID from its name
232
- origin = typeck:: method_static ( method_with_name ( bcx. ccx ( ) ,
233
- impl_id,
234
- method_name) ) ;
234
+ origin = typeck:: method_static (
235
+ method_with_name_or_default ( bcx. ccx ( ) ,
236
+ impl_id,
237
+ method_name) ) ;
235
238
}
236
239
typeck:: method_static( * ) | typeck:: method_param( * ) |
237
240
typeck:: method_trait( * ) => { }
@@ -345,7 +348,9 @@ pub fn trans_static_method_callee(bcx: block,
345
348
typeck:: vtable_static( impl_did, ref rcvr_substs, rcvr_origins) => {
346
349
assert ! ( rcvr_substs. all( |t| !ty:: type_needs_infer( * t) ) ) ;
347
350
348
- let mth_id = method_with_name ( bcx. ccx ( ) , impl_did, mname) ;
351
+ let mth_id = method_with_name_or_default ( bcx. ccx ( ) ,
352
+ impl_did,
353
+ mname) ;
349
354
let callee_substs = combine_impl_and_methods_tps (
350
355
bcx, mth_id, impl_did, callee_id, * rcvr_substs) ;
351
356
let callee_origins = combine_impl_and_methods_origins (
@@ -374,23 +379,6 @@ pub fn method_from_methods(ms: &[@ast::method], name: ast::ident)
374
379
ms. find ( |m| m. ident == name) . map ( |m| ast_util:: local_def ( m. id ) )
375
380
}
376
381
377
- pub fn method_with_name ( ccx : @CrateContext , impl_id : ast:: def_id ,
378
- name : ast:: ident ) -> ast:: def_id {
379
- if impl_id. crate == ast:: local_crate {
380
- match ccx. tcx . items . get_copy ( & impl_id. node ) {
381
- ast_map:: node_item( @ast:: item {
382
- node : ast:: item_impl( _, _, _, ref ms) ,
383
- _
384
- } , _) => {
385
- method_from_methods ( * ms, name) . get ( )
386
- }
387
- _ => fail ! ( "method_with_name" )
388
- }
389
- } else {
390
- csearch:: get_impl_method ( ccx. sess . cstore , impl_id, name)
391
- }
392
- }
393
-
394
382
pub fn method_with_name_or_default ( ccx : @CrateContext ,
395
383
impl_id : ast:: def_id ,
396
384
name : ast:: ident ) -> ast:: def_id {
@@ -770,17 +758,17 @@ pub fn vtable_id(ccx: @CrateContext,
770
758
771
759
/// Creates a returns a dynamic vtable for the given type and vtable origin.
772
760
/// This is used only for objects.
773
- pub fn get_vtable ( ccx : @ CrateContext ,
761
+ pub fn get_vtable ( bcx : block ,
774
762
self_ty : ty:: t ,
775
763
origin : typeck:: vtable_origin )
776
764
-> ValueRef {
777
- let hash_id = vtable_id ( ccx, & origin) ;
778
- match ccx. vtables . find ( & hash_id) {
765
+ let hash_id = vtable_id ( bcx . ccx ( ) , & origin) ;
766
+ match bcx . ccx ( ) . vtables . find ( & hash_id) {
779
767
Some ( & val) => val,
780
768
None => {
781
769
match origin {
782
770
typeck:: vtable_static( id, substs, sub_vtables) => {
783
- make_impl_vtable ( ccx , id, self_ty, substs, sub_vtables)
771
+ make_impl_vtable ( bcx , id, self_ty, substs, sub_vtables)
784
772
}
785
773
_ => fail ! ( "get_vtable: expected a static origin" ) ,
786
774
}
@@ -814,12 +802,13 @@ pub fn make_vtable(ccx: @CrateContext,
814
802
}
815
803
816
804
/// Generates a dynamic vtable for objects.
817
- pub fn make_impl_vtable ( ccx : @ CrateContext ,
805
+ pub fn make_impl_vtable ( bcx : block ,
818
806
impl_id : ast:: def_id ,
819
807
self_ty : ty:: t ,
820
808
substs : ~[ ty:: t ] ,
821
809
vtables : typeck:: vtable_res )
822
810
-> ValueRef {
811
+ let ccx = bcx. ccx ( ) ;
823
812
let _icx = ccx. insn_ctxt ( "impl::make_impl_vtable" ) ;
824
813
let tcx = ccx. tcx ;
825
814
@@ -829,9 +818,6 @@ pub fn make_impl_vtable(ccx: @CrateContext,
829
818
make a vtable for a type impl!")
830
819
} ;
831
820
832
- let has_tps =
833
- !ty:: lookup_item_type ( ccx. tcx , impl_id) . generics . type_param_defs . is_empty ( ) ;
834
-
835
821
let trait_method_def_ids = ty:: trait_method_def_ids ( tcx, trt_id) ;
836
822
let methods = do trait_method_def_ids. map |method_def_id| {
837
823
let im = ty:: method ( tcx, * method_def_id) ;
@@ -846,22 +832,11 @@ pub fn make_impl_vtable(ccx: @CrateContext,
846
832
} else {
847
833
debug ! ( "(making impl vtable) adding method to vtable: %s" ,
848
834
* tcx. sess. str_of( im. ident) ) ;
849
- let mut m_id = method_with_name ( ccx, impl_id, im. ident ) ;
850
- if has_tps {
851
- // If the method is in another crate, need to make an inlined
852
- // copy first
853
- if m_id. crate != ast:: local_crate {
854
- // XXX: Set impl ID here?
855
- m_id = inline:: maybe_instantiate_inline ( ccx, m_id, true ) ;
856
- }
857
- let ( val, _) = monomorphize:: monomorphic_fn ( ccx, m_id, substs,
858
- Some ( vtables) , None , None ) ;
859
- val
860
- } else if m_id. crate == ast:: local_crate {
861
- get_item_val ( ccx, m_id. node )
862
- } else {
863
- trans_external_path ( ccx, m_id, fty)
864
- }
835
+ let m_id = method_with_name_or_default ( ccx, impl_id, im. ident ) ;
836
+
837
+ trans_fn_ref_with_vtables ( bcx, m_id, 0 ,
838
+ substs, Some ( vtables) ) . llfn
839
+
865
840
}
866
841
} ;
867
842
@@ -903,7 +878,7 @@ pub fn trans_trait_cast(bcx: block,
903
878
// Store the vtable into the pair or triple.
904
879
let orig = /*bad*/ copy ccx. maps . vtable_map . get ( & id) [ 0 ] ;
905
880
let orig = resolve_vtable_in_fn_ctxt ( bcx. fcx , orig) ;
906
- let vtable = get_vtable ( bcx. ccx ( ) , v_ty, orig) ;
881
+ let vtable = get_vtable ( bcx, v_ty, orig) ;
907
882
Store ( bcx, vtable, PointerCast ( bcx,
908
883
GEPi ( bcx, lldest, [ 0 u, abi:: trt_field_vtable] ) ,
909
884
T_ptr ( val_ty ( vtable) ) ) ) ;
0 commit comments