@@ -74,7 +74,7 @@ state type crate_ctxt = rec(session.session sess,
74
74
hashmap[ ast. def_id , @ast. item ] items,
75
75
hashmap[ ast. def_id ,
76
76
@ast. native_item ] native_items,
77
- hashmap[ ast . def_id , @tag_info] tags,
77
+ hashmap[ @ty . t , @tag_info] tags,
78
78
hashmap[ ast. def_id , ValueRef ] fn_pairs,
79
79
hashmap[ ast. def_id , ValueRef ] consts,
80
80
hashmap[ ast. def_id , ( ) ] obj_methods,
@@ -543,7 +543,7 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
543
543
case ( ty. ty_char ) { llty = T_char ( ) ; }
544
544
case ( ty. ty_str ) { llty = T_ptr ( T_str ( ) ) ; }
545
545
case ( ty. ty_tag ( ?tag_id, _) ) {
546
- llty = llvm. LLVMResolveTypeHandle ( cx. tags . get ( tag_id ) . th . llth ) ;
546
+ llty = llvm. LLVMResolveTypeHandle ( cx. tags . get ( t ) . th . llth ) ;
547
547
}
548
548
case ( ty. ty_box ( ?t) ) {
549
549
llty = T_ptr ( T_box ( type_of_inner ( cx, t) ) ) ;
@@ -1472,6 +1472,14 @@ fn tag_variants(@crate_ctxt cx, ast.def_id id) -> vec[ast.variant] {
1472
1472
fail; // not reached
1473
1473
}
1474
1474
1475
+ // Returns a new plain tag type of the given ID with no type parameters. Don't
1476
+ // use this function in new code; it's a hack to keep things working for now.
1477
+ fn mk_plain_tag( ast. def_id tid) -> @ty. t {
1478
+ let vec[ @ty. t] tps = vec( ) ;
1479
+ ret ty. plain_ty( ty. ty_tag( tid, tps) ) ;
1480
+ }
1481
+
1482
+
1475
1483
type val_and_ty_fn = fn ( @block_ctxt cx, ValueRef v, @ty. t t) -> result;
1476
1484
1477
1485
// Iterates through the elements of a structural type.
@@ -1521,8 +1529,7 @@ fn iter_structural_ty(@block_ctxt cx,
1521
1529
}
1522
1530
}
1523
1531
case ( ty. ty_tag( ?tid, ?tps) ) {
1524
- check ( cx. fcx. ccx. tags. contains_key( tid) ) ;
1525
- auto info = cx. fcx. ccx. tags. get( tid) ;
1532
+ auto info = cx. fcx. ccx. tags. get( mk_plain_tag( tid) ) ;
1526
1533
1527
1534
auto variants = tag_variants( cx. fcx. ccx, tid) ;
1528
1535
auto n_variants = _vec. len[ ast. variant] ( variants) ;
@@ -2591,7 +2598,6 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
2591
2598
ret lval_generic_fn( cx, ty. item_ty( fn_item) , did, ann) ;
2592
2599
}
2593
2600
case ( ast. def_variant( ?tid, ?vid) ) {
2594
- check ( cx. fcx. ccx. tags. contains_key( tid) ) ;
2595
2601
if ( cx. fcx. ccx. fn_pairs. contains_key( vid) ) {
2596
2602
check ( cx. fcx. ccx. items. contains_key( tid) ) ;
2597
2603
auto tag_item = cx. fcx. ccx. items. get( tid) ;
@@ -4247,7 +4253,9 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
4247
4253
auto arg_tys = arg_tys_of_fn( variant. ann) ;
4248
4254
copy_args_to_allocas( bcx, none[ TypeRef ] , fn_args, arg_tys) ;
4249
4255
4250
- auto info = cx. tags. get( tag_id) ;
4256
+ // FIXME: This is wrong for generic tags. We should be dynamically
4257
+ // computing "size" below based on the tydescs passed in.
4258
+ auto info = cx. tags. get( mk_plain_tag( tag_id) ) ;
4251
4259
4252
4260
auto lltagty = T_struct ( vec( T_int ( ) , T_array ( T_i8 ( ) , info. size) ) ) ;
4253
4261
@@ -4445,8 +4453,8 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
4445
4453
case ( ast. item_tag( _, ?variants, ?tps, ?tag_id) ) {
4446
4454
auto vi = new_def_hash[ uint] ( ) ;
4447
4455
auto navi = new_def_hash[ uint] ( ) ;
4448
- cx. tags. insert( tag_id, @rec( th=mk_type_handle( ) ,
4449
- mutable size=0 u) ) ;
4456
+ cx. tags. insert( mk_plain_tag ( tag_id) , @rec( th=mk_type_handle( ) ,
4457
+ mutable size=0 u) ) ;
4450
4458
cx. items. insert( tag_id, i) ;
4451
4459
}
4452
4460
@@ -4507,7 +4515,7 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
4507
4515
auto max_align = 0 u;
4508
4516
auto max_size = 0 u;
4509
4517
4510
- auto info = cx. tags. get( tag_id) ;
4518
+ auto info = cx. tags. get( mk_plain_tag ( tag_id) ) ;
4511
4519
4512
4520
for ( ast. variant variant in variants) {
4513
4521
if ( _vec. len [ ast. variant_arg ] ( variant. args ) > 0 u) {
@@ -4528,7 +4536,7 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
4528
4536
// FIXME: alignment is wrong here, manually insert padding I
4529
4537
// guess :(
4530
4538
auto tag_ty = T_struct ( vec ( T_int ( ) , T_array ( T_i8 ( ) , max_size) ) ) ;
4531
- auto th = cx . tags . get ( tag_id ) . th . llth ;
4539
+ auto th = info . th . llth ;
4532
4540
llvm. LLVMRefineType ( llvm. LLVMResolveTypeHandle ( th) , tag_ty) ;
4533
4541
}
4534
4542
case ( _) {
@@ -4554,7 +4562,7 @@ fn resolve_tag_types(@crate_ctxt cx, @ast.crate crate) {
4554
4562
fn trans_constant ( & @crate_ctxt cx , @ast. item it ) -> @crate_ctxt {
4555
4563
alt ( it. node ) {
4556
4564
case ( ast. item_tag ( _, ?variants, _, ?tag_id) ) {
4557
- auto info = cx. tags . get ( tag_id) ;
4565
+ auto info = cx. tags . get ( mk_plain_tag ( tag_id) ) ;
4558
4566
4559
4567
auto tag_ty = llvm. LLVMResolveTypeHandle ( info. th . llth ) ;
4560
4568
check ( llvm. LLVMCountStructElementTypes ( tag_ty) == 2 u) ;
@@ -4924,6 +4932,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
4924
4932
auto glues = make_glues ( llmod, tn) ;
4925
4933
auto hasher = ty. hash_ty ;
4926
4934
auto eqer = ty. eq_ty ;
4935
+ auto tags = map. mk_hashmap [ @ty. t , @tag_info] ( hasher, eqer) ;
4927
4936
auto tydescs = map. mk_hashmap [ @ty. t , ValueRef ] ( hasher, eqer) ;
4928
4937
let vec[ ast. ty_param ] obj_typarams = vec ( ) ;
4929
4938
let vec[ ast. obj_field ] obj_fields = vec ( ) ;
@@ -4939,7 +4948,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
4939
4948
item_ids = new_def_hash[ ValueRef ] ( ) ,
4940
4949
items = new_def_hash[ @ast. item ] ( ) ,
4941
4950
native_items = new_def_hash[ @ast. native_item ] ( ) ,
4942
- tags = new_def_hash [ @tag_info ] ( ) ,
4951
+ tags = tags ,
4943
4952
fn_pairs = new_def_hash[ ValueRef ] ( ) ,
4944
4953
consts = new_def_hash[ ValueRef ] ( ) ,
4945
4954
obj_methods = new_def_hash[ ( ) ] ( ) ,
0 commit comments