@@ -427,12 +427,12 @@ impl CodegenBackend for MyBackend {
427427 // Replace self references with the trait name as to match signatures with the one we've put on the interface
428428 if of_trait. is_some ( ) {
429429 match oomir_function. signature . params . get ( 0 ) {
430- Some ( Type :: Class ( name) ) => {
430+ Some ( ( param_name , Type :: Class ( name) ) ) => {
431431 if * name != ident {
432432 continue ;
433433 }
434434 oomir_function. signature . params [ 0 ] =
435- Type :: Class ( of_trait. clone ( ) . unwrap ( ) ) ;
435+ ( param_name . clone ( ) , Type :: Class ( of_trait. clone ( ) . unwrap ( ) ) ) ;
436436
437437 // insert a Cast instruction to cast the trait (interface) object to the specific type of this class
438438 // this is needed because the method signature will be different than what MIR expects
@@ -456,12 +456,15 @@ impl CodegenBackend for MyBackend {
456456 ) ;
457457 }
458458 }
459- Some ( Type :: MutableReference ( box Type :: Class ( name) ) ) => {
459+ Some ( ( param_name , Type :: MutableReference ( box Type :: Class ( name) ) ) ) => {
460460 if * name != ident {
461461 continue ;
462462 }
463- oomir_function. signature . params [ 0 ] = Type :: MutableReference (
464- Box :: new ( Type :: Class ( of_trait. clone ( ) . unwrap ( ) ) ) ,
463+ oomir_function. signature . params [ 0 ] = (
464+ param_name. clone ( ) ,
465+ Type :: MutableReference (
466+ Box :: new ( Type :: Class ( of_trait. clone ( ) . unwrap ( ) ) ) ,
467+ ) ,
465468 ) ;
466469
467470 // insert a Cast instruction to cast the trait (interface) object to the specific type of this class
@@ -500,23 +503,23 @@ impl CodegenBackend for MyBackend {
500503 let mut new_params = vec ! [ ] ;
501504 // replace any MutableReference(Class(of_trait)) or Class(of_trait) with MutableReference(Class(ident))/ Class(ident)
502505 // this is just for the helper function, the actual method will use oomir_function.signature and we're only modifying helper_sig
503- for arg in & oomir_function. signature . params {
504- if let Type :: MutableReference ( box Type :: Class ( name) ) = arg {
506+ for ( param_name , param_ty ) in & oomir_function. signature . params {
507+ if let Type :: MutableReference ( box Type :: Class ( name) ) = param_ty {
505508 if * name == of_trait. clone ( ) . unwrap ( ) {
506- new_params. push ( Type :: MutableReference ( Box :: new ( Type :: Class (
509+ new_params. push ( ( param_name . clone ( ) , Type :: MutableReference ( Box :: new ( Type :: Class (
507510 ident. clone ( ) ,
508- ) ) ) ) ;
511+ ) ) ) ) ) ;
509512 } else {
510- new_params. push ( arg . clone ( ) ) ;
513+ new_params. push ( ( param_name . clone ( ) , param_ty . clone ( ) ) ) ;
511514 }
512- } else if let Type :: Class ( name) = arg {
515+ } else if let Type :: Class ( name) = param_ty {
513516 if * name == of_trait. clone ( ) . unwrap ( ) {
514- new_params. push ( Type :: Class ( ident. clone ( ) ) ) ;
517+ new_params. push ( ( param_name . clone ( ) , Type :: Class ( ident. clone ( ) ) ) ) ;
515518 } else {
516- new_params. push ( arg . clone ( ) ) ;
519+ new_params. push ( ( param_name . clone ( ) , param_ty . clone ( ) ) ) ;
517520 }
518521 } else {
519- new_params. push ( arg . clone ( ) ) ;
522+ new_params. push ( ( param_name . clone ( ) , param_ty . clone ( ) ) ) ;
520523 }
521524 }
522525 helper_sig. params = new_params;
@@ -531,12 +534,11 @@ impl CodegenBackend for MyBackend {
531534 let mut instructions = vec ! [ ] ;
532535
533536 let mut idx = 1 ;
534- for arg in & oomir_function. signature . params {
537+ for ( _param_name , param_ty ) in & oomir_function. signature . params {
535538 let arg_name = format ! ( "_{idx}" ) ;
536- let arg_ty = arg. clone ( ) ;
537539 let arg = Operand :: Variable {
538540 name : arg_name. clone ( ) ,
539- ty : arg_ty ,
541+ ty : param_ty . clone ( ) ,
540542 } ;
541543 args. push ( arg) ;
542544 idx += 1 ;
@@ -723,16 +725,22 @@ impl CodegenBackend for MyBackend {
723725 let data_types = & mut HashMap :: new ( ) ; // Consider if this should be shared across loop iterations or functions
724726
725727 // Use skip_binder here too, as inputs/outputs are bound by the same binder as the fn_sig
726- let params_oomir_ty : Vec < oomir:: Type > = params_ty
728+ let params_oomir : Vec < ( String , oomir:: Type ) > = params_ty
727729 . skip_binder ( )
728730 . iter ( )
729- . map ( |ty| lower1:: types:: ty_to_oomir_type ( * ty, tcx, data_types) )
731+ . enumerate ( )
732+ . map ( |( i, ty) | {
733+ // For trait methods, we don't have MIR, so use generic names
734+ let param_name = format ! ( "arg{}" , i) ;
735+ let oomir_type = lower1:: types:: ty_to_oomir_type ( * ty, tcx, data_types) ;
736+ ( param_name, oomir_type)
737+ } )
730738 . collect ( ) ;
731739 let return_oomir_ty: oomir:: Type =
732740 lower1:: types:: ty_to_oomir_type ( return_ty. skip_binder ( ) , tcx, data_types) ;
733741
734742 let mut signature = oomir:: Signature {
735- params : params_oomir_ty ,
743+ params : params_oomir ,
736744 ret : Box :: new ( return_oomir_ty. clone ( ) ) ,
737745 } ;
738746 signature. replace_class_in_signature ( "Self" , & ident) ;
@@ -741,9 +749,8 @@ impl CodegenBackend for MyBackend {
741749
742750 let mut args = vec ! [ ] ;
743751 let mut idx = 1 ;
744- for arg in signature. clone ( ) . params {
752+ for ( _arg_name_from_sig , arg_ty ) in signature. clone ( ) . params {
745753 let arg_name = format ! ( "_{idx}" ) ;
746- let arg_ty = arg. clone ( ) ;
747754 let arg = Operand :: Variable {
748755 name : arg_name. clone ( ) ,
749756 ty : arg_ty,
0 commit comments