@@ -876,8 +876,9 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
876
876
abs_pair = llvm:: LLVMResolveTypeHandle ( th. llth ) ;
877
877
llty = abs_pair;
878
878
}
879
- case ( ty:: ty_res ( _, ?sub) ) {
880
- ret T_struct ( [ T_i32 ( ) , type_of_inner ( cx, sp, sub) ] ) ;
879
+ case ( ty:: ty_res ( _, ?sub, ?tps) ) {
880
+ auto sub1 = ty:: substitute_type_params ( cx. tcx , tps, sub) ;
881
+ ret T_struct ( [ T_i32 ( ) , type_of_inner ( cx, sp, sub1) ] ) ;
881
882
}
882
883
case ( ty:: ty_var ( _) ) {
883
884
cx. tcx . sess . span_fatal ( sp, "trans::type_of called on ty_var" ) ;
@@ -1220,9 +1221,10 @@ fn simplify_type(&@crate_ctxt ccx, &ty::t typ) -> ty::t {
1220
1221
ty:: mk_imm_box ( ccx. tcx ,
1221
1222
ty:: mk_nil ( ccx. tcx ) ) ] ) ;
1222
1223
}
1223
- case ( ty:: ty_res ( _, ?sub) ) {
1224
+ case ( ty:: ty_res ( _, ?sub, ?tps) ) {
1225
+ auto sub1 = ty:: substitute_type_params ( ccx. tcx , tps, sub) ;
1224
1226
ret ty:: mk_imm_tup ( ccx. tcx , [ ty:: mk_int ( ccx. tcx ) ,
1225
- simplify_type ( ccx, sub ) ] ) ;
1227
+ simplify_type ( ccx, sub1 ) ] ) ;
1226
1228
}
1227
1229
case ( _) { ret typ; }
1228
1230
}
@@ -1716,8 +1718,7 @@ fn get_tydesc(&@block_ctxt cx, &ty::t t, bool escapes,
1716
1718
}
1717
1719
// Otherwise, generate a tydesc if necessary, and return it.
1718
1720
1719
- let vec[ uint] tps = [ ] ;
1720
- auto info = get_static_tydesc( cx, t, tps) ;
1721
+ auto info = get_static_tydesc( cx, t, [ ] ) ;
1721
1722
static_ti = some[ @tydesc_info] ( info) ;
1722
1723
ret rslt( cx, info. tydesc) ;
1723
1724
}
@@ -2089,8 +2090,8 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
2089
2090
cx. build. GEP ( v0, [ C_int ( 0 ) , C_int ( abi:: obj_field_box) ] ) ;
2090
2091
decr_refcnt_maybe_free( cx, box_cell, v0, t)
2091
2092
}
2092
- case ( ty:: ty_res( ?did, ?inner) ) {
2093
- trans_res_drop( cx, v0, did, inner)
2093
+ case ( ty:: ty_res( ?did, ?inner, ?tps ) ) {
2094
+ trans_res_drop( cx, v0, did, inner, tps )
2094
2095
}
2095
2096
case ( ty:: ty_fn( _, _, _, _, _) ) {
2096
2097
auto box_cell =
@@ -2108,9 +2109,11 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
2108
2109
}
2109
2110
2110
2111
fn trans_res_drop( @block_ctxt cx, ValueRef rs, & ast:: def_id did,
2111
- ty:: t inner_t) -> result {
2112
+ ty:: t inner_t, & vec [ ty :: t ] tps ) -> result {
2112
2113
auto ccx = cx. fcx. lcx. ccx;
2113
- auto tup_ty = ty:: mk_imm_tup( ccx. tcx, [ ty:: mk_int( ccx. tcx) , inner_t] ) ;
2114
+
2115
+ auto inner_t_s = ty:: substitute_type_params( ccx. tcx, tps, inner_t) ;
2116
+ auto tup_ty = ty:: mk_imm_tup( ccx. tcx, [ ty:: mk_int( ccx. tcx) , inner_t_s] ) ;
2114
2117
auto drop_cx = new_sub_block_ctxt( cx, "drop res") ;
2115
2118
auto next_cx = new_sub_block_ctxt( cx, "next") ;
2116
2119
@@ -2120,6 +2123,8 @@ fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
2120
2123
cx. build. CondBr ( null_test, next_cx. llbb, drop_cx. llbb) ;
2121
2124
cx = drop_cx;
2122
2125
2126
+ auto val = GEP_tup_like ( cx, tup_ty, rs, [ 0 , 1 ] ) ;
2127
+ cx = val. bcx;
2123
2128
// Find and call the actual destructor.
2124
2129
auto dtor_pair = if ( did. _0 == ast:: local_crate) {
2125
2130
ccx. fn_pairs. get( did. _1)
@@ -2136,15 +2141,25 @@ fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
2136
2141
( cx. build. GEP ( dtor_pair, [ C_int ( 0 ) , C_int ( abi:: fn_field_code) ] ) ) ;
2137
2142
auto dtor_env = cx. build. Load
2138
2143
( cx. build. GEP ( dtor_pair, [ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ) ;
2139
- auto val = GEP_tup_like ( cx, tup_ty, rs, [ 0 , 1 ] ) ;
2140
- cx = val. bcx;
2141
- cx. build. FastCall ( dtor_addr, [ cx. fcx. llretptr, cx. fcx. lltaskptr, dtor_env]
2142
- + cx. fcx. lltydescs + [ val. val] ) ;
2143
-
2144
- cx = drop_slot( cx, val. val, inner_t) . bcx;
2144
+ auto args = [ cx. fcx. llretptr, cx. fcx. lltaskptr, dtor_env] ;
2145
+ for ( ty:: t tp in tps) {
2146
+ let option:: t[ @tydesc_info] ti = none;
2147
+ auto td = get_tydesc( cx, tp, false, ti) ;
2148
+ args += [ td. val] ;
2149
+ cx = td. bcx;
2150
+ }
2151
+ // Kludge to work around the fact that we know the precise type of the
2152
+ // value here, but the dtor expects a type that still has opaque pointers
2153
+ // for type variables.
2154
+ auto val_llty = lib:: llvm:: fn_ty_param_tys
2155
+ ( llvm:: LLVMGetElementType ( llvm:: LLVMTypeOf ( dtor_addr) ) )
2156
+ . ( vec:: len( args) ) ;
2157
+ auto val_cast = cx. build. BitCast ( val. val, val_llty) ;
2158
+ cx. build. FastCall ( dtor_addr, args + [ val_cast] ) ;
2159
+
2160
+ cx = drop_slot( cx, val. val, inner_t_s) . bcx;
2145
2161
cx. build. Store ( C_int ( 0 ) , drop_flag. val) ;
2146
2162
cx. build. Br ( next_cx. llbb) ;
2147
-
2148
2163
ret rslt( next_cx, C_nil ( ) ) ;
2149
2164
}
2150
2165
@@ -2611,13 +2626,15 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
2611
2626
i += 1 ;
2612
2627
}
2613
2628
}
2614
- case ( ty:: ty_res( _, ?inner) ) {
2629
+ case ( ty:: ty_res( _, ?inner, ?tps) ) {
2630
+ auto inner1 = ty:: substitute_type_params( cx. fcx. lcx. ccx. tcx,
2631
+ tps, inner) ;
2615
2632
r = GEP_tup_like ( r. bcx, t, av, [ 0 , 1 ] ) ;
2616
2633
auto llfld_a = r. val;
2617
2634
r = GEP_tup_like ( r. bcx, t, bv, [ 0 , 1 ] ) ;
2618
2635
auto llfld_b = r. val;
2619
- f( r. bcx, load_if_immediate( r. bcx, llfld_a, inner ) ,
2620
- load_if_immediate( r. bcx, llfld_b, inner ) , inner ) ;
2636
+ f( r. bcx, load_if_immediate( r. bcx, llfld_a, inner1 ) ,
2637
+ load_if_immediate( r. bcx, llfld_b, inner1 ) , inner1 ) ;
2621
2638
}
2622
2639
case ( ty:: ty_tag( ?tid, ?tps) ) {
2623
2640
auto variants = ty:: tag_variants( cx. fcx. lcx. ccx. tcx, tid) ;
@@ -2891,9 +2908,9 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
2891
2908
T_glue_fn ( lcx. ccx. tn) ,
2892
2909
"drop") ;
2893
2910
ti. drop_glue = some[ ValueRef ] ( glue_fn) ;
2894
- auto dg = make_drop_glue;
2895
2911
make_generic_glue( lcx, cx. sp, ti. ty, glue_fn,
2896
- mgghf_single( dg) , ti. ty_params) ;
2912
+ mgghf_single( make_drop_glue) ,
2913
+ ti. ty_params) ;
2897
2914
log #fmt( "--- lazily_emit_tydesc_glue DROP %s",
2898
2915
ty_to_str( cx. fcx. lcx. ccx. tcx, ti. ty) ) ;
2899
2916
}
@@ -5026,7 +5043,7 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
5026
5043
auto t = ty:: expr_ty( cx. fcx. lcx. ccx. tcx, base) ;
5027
5044
auto offset = alt ( ty:: struct ( cx. fcx. lcx. ccx. tcx, t) ) {
5028
5045
case ( ty:: ty_box( _) ) { abi:: box_rc_field_body }
5029
- case ( ty:: ty_res( _, _) ) { 1 }
5046
+ case ( ty:: ty_res( _, _, _ ) ) { 1 }
5030
5047
} ;
5031
5048
auto val = sub. bcx. build. GEP ( sub. val, [ C_int ( 0 ) , C_int ( offset) ] ) ;
5032
5049
ret lval_mem( sub. bcx, val) ;
@@ -7850,10 +7867,17 @@ fn trans_res_ctor(@local_ctxt cx, &span sp, &ast::_fn dtor,
7850
7867
auto tup_t = ty:: mk_imm_tup( cx. ccx. tcx, [ ty:: mk_int( cx. ccx. tcx) , arg_t] ) ;
7851
7868
auto arg = load_if_immediate
7852
7869
( bcx, fcx. llargs. get( dtor. decl. inputs. ( 0 ) . id) , arg_t) ;
7853
- auto dst = GEP_tup_like ( bcx, tup_t, fcx. llretptr, [ 0 , 1 ] ) ;
7870
+
7871
+ auto llretptr = fcx. llretptr;
7872
+ if ( ty:: type_has_dynamic_size( cx. ccx. tcx, ret_t) ) {
7873
+ auto llret_t = T_ptr ( T_struct ( [ T_i32 ( ) , llvm:: LLVMTypeOf ( arg) ] ) ) ;
7874
+ llretptr = bcx. build. BitCast ( llretptr, llret_t) ;
7875
+ }
7876
+
7877
+ auto dst = GEP_tup_like ( bcx, tup_t, llretptr, [ 0 , 1 ] ) ;
7854
7878
bcx = dst. bcx;
7855
7879
bcx = copy_val( bcx, INIT , dst. val, arg, arg_t) . bcx;
7856
- auto flag = GEP_tup_like ( bcx, tup_t, fcx . llretptr, [ 0 , 0 ] ) ;
7880
+ auto flag = GEP_tup_like ( bcx, tup_t, llretptr, [ 0 , 0 ] ) ;
7857
7881
bcx = flag. bcx;
7858
7882
bcx. build. Store ( C_int ( 1 ) , flag. val) ;
7859
7883
bcx. build. RetVoid ( ) ;
@@ -7973,7 +7997,7 @@ fn trans_item(@local_ctxt cx, &ast::item item) {
7973
7997
trans_res_ctor( cx, item. span, dtor, ctor_id, tps) ;
7974
7998
// Create a function for the destructor
7975
7999
auto lldtor_decl = cx. ccx. item_ids. get( item. id) ;
7976
- trans_fn( cx, item. span, dtor, lldtor_decl, none, tps, dtor_id) ;
8000
+ trans_fn( cx, item. span, dtor, lldtor_decl, none, tps, dtor_id)
7977
8001
}
7978
8002
case ( ast:: item_mod( ?m) ) {
7979
8003
auto sub_cx =
0 commit comments