@@ -222,8 +222,8 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
222222 size_val,
223223 )
224224 . unwrap ( ) ;
225- if let PLType :: Struct ( _ ) = pltype {
226- let f = self . get_or_insert_st_visit_fn_handle ( & p) ;
225+ if let PLType :: Struct ( tp ) = pltype {
226+ let f = self . get_or_insert_st_visit_fn_handle ( & p, tp ) ;
227227 let i = self . builder . build_ptr_to_int (
228228 f. as_global_value ( ) . as_pointer_value ( ) ,
229229 self . context . i64_type ( ) ,
@@ -526,10 +526,13 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
526526 PriType :: BOOL => self . context . bool_type ( ) . as_basic_type_enum ( ) ,
527527 }
528528 }
529- fn get_or_insert_st_visit_fn_handle ( & self , p : & PointerValue < ' ctx > ) -> FunctionValue < ' ctx > {
529+ fn get_or_insert_st_visit_fn_handle (
530+ & self ,
531+ p : & PointerValue < ' ctx > ,
532+ st : & STType ,
533+ ) -> FunctionValue < ' ctx > {
530534 let ptrtp = p. get_type ( ) ;
531- let ty = ptrtp. get_element_type ( ) . into_struct_type ( ) ;
532- let llvmname = ty. get_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) + "@" ;
535+ let llvmname = st. get_st_full_name ( ) + "@" ;
533536 if let Some ( v) = self . module . get_function ( & llvmname) {
534537 return v;
535538 }
@@ -948,32 +951,37 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
948951 self . module
949952 . add_function ( & llvmname, fn_type, Some ( Linkage :: External ) )
950953 }
954+ fn get_fields ( & self , pltp : & STType , ctx : & mut Ctx < ' a > ) -> Vec < BasicTypeEnum > {
955+ ctx. run_in_type_mod ( pltp, |ctx, pltp| {
956+ pltp. get_all_field ( )
957+ . iter ( )
958+ . map ( |order_field| {
959+ self . get_basic_type_op (
960+ & order_field
961+ . typenode
962+ . get_type ( ctx, & self . clone ( ) . into ( ) )
963+ . unwrap ( )
964+ . borrow ( ) ,
965+ ctx,
966+ )
967+ . unwrap ( )
968+ } )
969+ . collect :: < Vec < _ > > ( )
970+ } )
971+ }
972+
951973 fn struct_type ( & self , pltp : & STType , ctx : & mut Ctx < ' a > ) -> StructType < ' ctx > {
952974 let st = self . module . get_struct_type ( & pltp. get_st_full_name ( ) ) ;
953975 if let Some ( st) = st {
954976 return st;
955977 }
978+
979+ if pltp. is_tuple {
980+ let fields = & self . get_fields ( pltp, ctx) ;
981+ return self . context . struct_type ( fields, false ) ;
982+ }
956983 let st = self . context . opaque_struct_type ( & pltp. get_st_full_name ( ) ) ;
957- ctx. run_in_type_mod ( pltp, |ctx, pltp| {
958- st. set_body (
959- & pltp
960- . get_all_field ( )
961- . iter ( )
962- . map ( |order_field| {
963- self . get_basic_type_op (
964- & order_field
965- . typenode
966- . get_type ( ctx, & self . clone ( ) . into ( ) )
967- . unwrap ( )
968- . borrow ( ) ,
969- ctx,
970- )
971- . unwrap ( )
972- } )
973- . collect :: < Vec < _ > > ( ) ,
974- false ,
975- ) ;
976- } ) ;
984+ st. set_body ( & self . get_fields ( pltp, ctx) , false ) ;
977985 st
978986 }
979987
@@ -1716,11 +1724,9 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
17161724 let ptrtp = self . struct_type ( v, ctx) . ptr_type ( AddressSpace :: default ( ) ) ;
17171725 let ty = ptrtp. get_element_type ( ) . into_struct_type ( ) ;
17181726 let ftp = self . mark_fn_tp ( ptrtp) ;
1719- let f = self . module . add_function (
1720- & ( ty. get_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) + "@" ) ,
1721- ftp,
1722- None ,
1723- ) ;
1727+ let f = self
1728+ . module
1729+ . add_function ( & ( v. get_st_full_name ( ) + "@" ) , ftp, None ) ;
17241730 let bb = self . context . append_basic_block ( f, "entry" ) ;
17251731 self . builder . position_at_end ( bb) ;
17261732 let fieldn = ty. count_fields ( ) ;
0 commit comments