@@ -292,15 +292,9 @@ pub fn trans_static_method_callee(bcx: block,
292292 //
293293 // So when we see a call to this function foo, we have to figure
294294 // out which impl the `Trait<T1...Tn>` bound on the type `self` was
295- // bound to. Due to the fact that we use a flattened list of
296- // impls, one per bound, this means we have to total up the bounds
297- // found on the type parametesr T1...Tn to find the index of the
298- // one we are interested in.
299- let bound_index = {
300- let trait_def = ty:: lookup_trait_def ( bcx. tcx ( ) , trait_id) ;
301- ty:: count_traits_and_supertraits (
302- bcx. tcx ( ) , * trait_def. generics . type_param_defs )
303- } ;
295+ // bound to.
296+ let bound_index = ty:: lookup_trait_def ( bcx. tcx ( ) , trait_id) .
297+ generics . type_param_defs . len ( ) ;
304298
305299 let mname = if method_id. crate == ast:: local_crate {
306300 match bcx. tcx ( ) . items . get_copy ( & method_id. node ) {
@@ -322,17 +316,17 @@ pub fn trans_static_method_callee(bcx: block,
322316 let vtbls = resolve_vtables_in_fn_ctxt (
323317 bcx. fcx , ccx. maps . vtable_map . get_copy ( & callee_id) ) ;
324318
325- match vtbls[ bound_index] {
319+ match vtbls[ bound_index] [ 0 ] {
326320 typeck:: vtable_static( impl_did, ref rcvr_substs, rcvr_origins) => {
327321 assert ! ( rcvr_substs. iter( ) . all( |t| !ty:: type_needs_infer( * t) ) ) ;
328322
329323 let mth_id = method_with_name_or_default ( bcx. ccx ( ) ,
330324 impl_did,
331325 mname) ;
332- let callee_substs = combine_impl_and_methods_tps (
333- bcx , mth_id , impl_did , callee_id , * rcvr_substs ) ;
334- let callee_origins = combine_impl_and_methods_origins (
335- bcx , mth_id , impl_did , callee_id , rcvr_origins) ;
326+ let ( callee_substs, callee_origins ) =
327+ combine_impl_and_methods_tps (
328+ bcx , mth_id , impl_did , callee_id ,
329+ * rcvr_substs , rcvr_origins) ;
336330
337331 let FnData { llfn : lval} =
338332 trans_fn_ref_with_vtables ( bcx,
@@ -428,10 +422,10 @@ pub fn trans_monomorphized_callee(bcx: block,
428422
429423 // create a concatenated set of substitutions which includes
430424 // those from the impl and those from the method:
431- let callee_substs = combine_impl_and_methods_tps (
432- bcx , mth_id , impl_did , callee_id , * rcvr_substs ) ;
433- let callee_origins = combine_impl_and_methods_origins (
434- bcx , mth_id , impl_did , callee_id , rcvr_origins) ;
425+ let ( callee_substs, callee_origins ) =
426+ combine_impl_and_methods_tps (
427+ bcx , mth_id , impl_did , callee_id ,
428+ * rcvr_substs , rcvr_origins) ;
435429
436430 // translate the function
437431 let callee = trans_fn_ref_with_vtables ( bcx,
@@ -471,8 +465,9 @@ pub fn combine_impl_and_methods_tps(bcx: block,
471465 mth_did : ast:: def_id ,
472466 impl_did : ast:: def_id ,
473467 callee_id : ast:: node_id ,
474- rcvr_substs : & [ ty:: t ] )
475- -> ~[ ty:: t ] {
468+ rcvr_substs : & [ ty:: t ] ,
469+ rcvr_origins : typeck:: vtable_res )
470+ -> ( ~[ ty:: t ] , typeck:: vtable_res ) {
476471 /*!
477472 *
478473 * Creates a concatenated set of substitutions which includes
@@ -501,52 +496,18 @@ pub fn combine_impl_and_methods_tps(bcx: block,
501496 debug ! ( "node_substs=%?" , node_substs. map( |t| bcx. ty_to_str( * t) ) ) ;
502497 debug ! ( "ty_substs=%?" , ty_substs. map( |t| bcx. ty_to_str( * t) ) ) ;
503498
504- return ty_substs;
505- }
506-
507- pub fn combine_impl_and_methods_origins ( bcx : block ,
508- mth_did : ast:: def_id ,
509- impl_did : ast:: def_id ,
510- callee_id : ast:: node_id ,
511- rcvr_origins : typeck:: vtable_res )
512- -> typeck:: vtable_res {
513- /*!
514- *
515- * Similar to `combine_impl_and_methods_tps`, but for vtables.
516- * This is much messier because of the flattened layout we are
517- * currently using (for some reason that I fail to understand).
518- * The proper fix is described in #3446.
519- */
520-
521499
522- // Find the bounds for the method, which are the tail of the
523- // bounds found in the item type, as the item type combines the
524- // rcvr + method bounds.
525- let ccx = bcx. ccx ( ) ;
526- let tcx = bcx. tcx ( ) ;
527- let n_m_tps = method_ty_param_count ( ccx, mth_did, impl_did) ;
528- let ty:: ty_param_bounds_and_ty {
529- generics : r_m_generics,
530- _
531- } = ty:: lookup_item_type ( tcx, mth_did) ;
532- let n_r_m_tps = r_m_generics. type_param_defs . len ( ) ; // rcvr + method tps
533- let m_type_param_defs =
534- r_m_generics. type_param_defs . slice ( n_r_m_tps - n_m_tps, n_r_m_tps) ;
535-
536- // Flatten out to find the number of vtables the method expects.
537- let m_vtables = ty:: count_traits_and_supertraits ( tcx, m_type_param_defs) ;
538-
539- // Find the vtables we computed at type check time and monomorphize them
500+ // Now, do the same work for the vtables. The vtables might not
501+ // exist, in which case we need to make them.
540502 let r_m_origins = match node_vtables ( bcx, callee_id) {
541503 Some ( vt) => vt,
542- None => @~[ ]
504+ None => @vec :: from_elem ( node_substs . len ( ) , @ ~[ ] )
543505 } ;
506+ let vtables
507+ = @vec:: append ( rcvr_origins. to_owned ( ) ,
508+ r_m_origins. tailn ( r_m_origins. len ( ) - n_m_tps) ) ;
544509
545- // Extract those that belong to method:
546- let m_origins = r_m_origins. tailn ( r_m_origins. len ( ) - m_vtables) ;
547-
548- // Combine rcvr + method to find the final result:
549- @vec:: append ( /*bad*/ copy * rcvr_origins, m_origins)
510+ return ( ty_substs, vtables) ;
550511}
551512
552513
@@ -845,7 +806,7 @@ pub fn trans_trait_cast(bcx: block,
845806 bcx = expr:: trans_into ( bcx, val, SaveIn ( llboxdest) ) ;
846807
847808 // Store the vtable into the pair or triple.
848- let orig = /*bad*/ copy ccx. maps . vtable_map . get ( & id) [ 0 ] ;
809+ let orig = /*bad*/ copy ccx. maps . vtable_map . get ( & id) [ 0 ] [ 0 ] ;
849810 let orig = resolve_vtable_in_fn_ctxt ( bcx. fcx , orig) ;
850811 let vtable = get_vtable ( bcx, v_ty, orig) ;
851812 Store ( bcx, vtable, PointerCast ( bcx,
0 commit comments