@@ -1185,18 +1185,27 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
1185
1185
// This function uses GEP_tup_like() above and automatically performs casts as
1186
1186
// appropriate. @llblobptr is the data part of a tag value; its actual type is
1187
1187
// meaningless, as it will be cast away.
1188
- fn GEP_tag ( @block_ctxt cx , ValueRef llblobptr , & ast. variant variant , int ix)
1188
+ fn GEP_tag ( @block_ctxt cx ,
1189
+ ValueRef llblobptr ,
1190
+ & ast. def_id tag_id ,
1191
+ & ast. def_id variant_id ,
1192
+ vec[ @ty. t] ty_substs,
1193
+ int ix )
1189
1194
-> result {
1195
+ auto ty_params = tag_ty_params ( cx. fcx . ccx , tag_id) ;
1196
+ auto variant = tag_variant_with_id ( cx. fcx . ccx , tag_id, variant_id) ;
1197
+
1190
1198
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
1191
1199
// Separately, store the type of the element we're interested in.
1192
1200
auto arg_tys = arg_tys_of_fn ( variant. ann ) ;
1193
1201
auto elem_ty = ty. plain_ty ( ty. ty_nil ) ; // typestate infelicity
1194
1202
auto i = 0 ;
1195
1203
let vec[ @ty. t] true_arg_tys = vec ( ) ;
1196
1204
for ( ty. arg a in arg_tys) {
1197
- true_arg_tys += vec ( a. ty ) ;
1205
+ auto arg_ty = ty. substitute_ty_params( ty_params, ty_substs, a. ty) ;
1206
+ true_arg_tys += vec( arg_ty) ;
1198
1207
if ( i == ix) {
1199
- elem_ty = a . ty ;
1208
+ elem_ty = arg_ty ;
1200
1209
}
1201
1210
1202
1211
i += 1 ;
@@ -2283,6 +2292,24 @@ fn node_ann_type(@crate_ctxt cx, &ast.ann a) -> @ty.t {
2283
2292
}
2284
2293
}
2285
2294
2295
+ fn node_ann_ty_params( & ast. ann a) -> vec[ @ty. t] {
2296
+ alt ( a) {
2297
+ case ( ast. ann_none) {
2298
+ log "missing type annotation";
2299
+ fail;
2300
+ }
2301
+ case ( ast. ann_type( _, ?tps_opt) ) {
2302
+ alt ( tps_opt) {
2303
+ case ( none[ vec[ @ty. t] ] ) {
2304
+ log "type annotation has no ty params";
2305
+ fail;
2306
+ }
2307
+ case ( some[ vec[ @ty. t] ] ( ?tps) ) { ret tps; }
2308
+ }
2309
+ }
2310
+ }
2311
+ }
2312
+
2286
2313
fn node_type( @crate_ctxt cx, & ast. ann a) -> TypeRef {
2287
2314
ret type_of( cx, node_ann_type( cx, a) ) ;
2288
2315
}
@@ -2981,13 +3008,15 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
2981
3008
C_int ( variant_tag) ) ;
2982
3009
cx. build. CondBr ( lleq, matched_cx. llbb, next_cx. llbb) ;
2983
3010
3011
+ auto ty_params = node_ann_ty_params( ann) ;
3012
+
2984
3013
if ( _vec. len[ @ast. pat] ( subpats) > 0 u) {
2985
3014
auto llblobptr = matched_cx. build. GEP ( lltagptr,
2986
3015
vec( C_int ( 0 ) , C_int ( 1 ) ) ) ;
2987
3016
auto i = 0 ;
2988
3017
for ( @ast. pat subpat in subpats) {
2989
- auto rslt = GEP_tag ( matched_cx, llblobptr, variants . ( i ) ,
2990
- i) ;
3018
+ auto rslt = GEP_tag ( matched_cx, llblobptr, vdef . _0 ,
3019
+ vdef . _1 , ty_params , i) ;
2991
3020
auto llsubvalptr = rslt. val;
2992
3021
matched_cx = rslt. bcx;
2993
3022
@@ -3025,7 +3054,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
3025
3054
3026
3055
ret copy_ty( bcx, INIT , dst, llval, ty) ;
3027
3056
}
3028
- case ( ast. pat_tag( _, ?subpats, ?vdef_opt, _ ) ) {
3057
+ case ( ast. pat_tag( _, ?subpats, ?vdef_opt, ?ann ) ) {
3029
3058
if ( _vec. len[ @ast. pat] ( subpats) == 0 u) { ret res( cx, llval) ; }
3030
3059
3031
3060
// Get the appropriate variant for this tag.
@@ -3036,10 +3065,13 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
3036
3065
T_opaque_tag_ptr ( cx. fcx. ccx. tn) ) ;
3037
3066
auto llblobptr = cx. build. GEP ( lltagptr, vec( C_int ( 0 ) , C_int ( 1 ) ) ) ;
3038
3067
3068
+ auto ty_param_substs = node_ann_ty_params( ann) ;
3069
+
3039
3070
auto this_cx = cx;
3040
3071
auto i = 0 ;
3041
3072
for ( @ast. pat subpat in subpats) {
3042
- auto rslt = GEP_tag ( this_cx, llblobptr, variant, i) ;
3073
+ auto rslt = GEP_tag ( this_cx, llblobptr, vdef. _0, vdef. _1,
3074
+ ty_param_substs, i) ;
3043
3075
this_cx = rslt. bcx;
3044
3076
auto llsubvalptr = rslt. val;
3045
3077
@@ -4926,6 +4958,11 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
4926
4958
none[ TypeRef ] , ret_ty_of_fn( variant. ann) ,
4927
4959
fn_args, ty_params) ;
4928
4960
4961
+ let vec[ @ty. t] ty_param_substs = vec( ) ;
4962
+ for ( ast. ty_param tp in ty_params) {
4963
+ ty_param_substs += vec( plain_ty( ty. ty_param( tp. id) ) ) ;
4964
+ }
4965
+
4929
4966
auto bcx = new_top_block_ctxt( fcx) ;
4930
4967
4931
4968
auto arg_tys = arg_tys_of_fn( variant. ann) ;
@@ -4944,7 +4981,8 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
4944
4981
4945
4982
i = 0 u;
4946
4983
for ( ast. variant_arg va in variant. args) {
4947
- auto rslt = GEP_tag ( bcx, llblobptr, variant, i as int) ;
4984
+ auto rslt = GEP_tag ( bcx, llblobptr, tag_id, variant. id,
4985
+ ty_param_substs, i as int) ;
4948
4986
bcx = rslt. bcx;
4949
4987
auto lldestptr = rslt. val;
4950
4988
0 commit comments