@@ -59,7 +59,11 @@ type glue_fns = rec(ValueRef activate_glue,
59
59
ValueRef memcpy_glue ,
60
60
ValueRef bzero_glue ) ;
61
61
62
- type tag_info = rec ( type_handle th, mutable uint size) ;
62
+ type tag_info = rec (
63
+ type_handle th,
64
+ mutable uint size,
65
+ mutable @hashmap[ ast. def_id, ValueRef ] lldiscrims
66
+ ) ;
63
67
64
68
state type crate_ctxt = rec ( session. session sess,
65
69
ModuleRef llmod,
@@ -2774,9 +2778,23 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
2774
2778
}
2775
2779
ret lval_generic_fn( cx, tup( params, fty) , vid, ann) ;
2776
2780
} else {
2777
- // Nullary variants are just scalar constants.
2778
- check ( cx. fcx. ccx. item_ids. contains_key( vid) ) ;
2779
- ret lval_val( cx, cx. fcx. ccx. item_ids. get( vid) ) ;
2781
+ // Nullary variant.
2782
+ auto tag_ty = node_ann_type( cx. fcx. ccx, ann) ;
2783
+ auto info = cx. fcx. ccx. tags. get( tag_ty) ;
2784
+ check ( info. lldiscrims. contains_key( vid) ) ;
2785
+ auto lldiscrim_gv = info. lldiscrims. get( vid) ;
2786
+ auto lldiscrim = cx. build. Load ( lldiscrim_gv) ;
2787
+
2788
+ auto alloc_result = alloc_ty( cx, tag_ty) ;
2789
+ auto lltagblob = alloc_result. val;
2790
+ auto lltagptr = alloc_result. bcx. build. PointerCast (
2791
+ lltagblob, T_ptr ( type_of( cx. fcx. ccx, tag_ty) ) ) ;
2792
+
2793
+ auto lldiscrimptr = alloc_result. bcx. build. GEP (
2794
+ lltagptr, vec( C_int ( 0 ) , C_int ( 0 ) ) ) ;
2795
+ alloc_result. bcx. build. Store ( lldiscrim, lldiscrimptr) ;
2796
+
2797
+ ret lval_val( alloc_result. bcx, lltagptr) ;
2780
2798
}
2781
2799
}
2782
2800
case ( ast. def_const( ?did) ) {
@@ -4637,8 +4655,14 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
4637
4655
case ( ast. item_tag( _, ?variants, ?tps, ?tag_id) ) {
4638
4656
auto vi = new_def_hash[ uint] ( ) ;
4639
4657
auto navi = new_def_hash[ uint] ( ) ;
4640
- cx. tags. insert( mk_plain_tag( tag_id) , @rec( th=mk_type_handle( ) ,
4641
- mutable size=0 u) ) ;
4658
+
4659
+ auto info = @rec(
4660
+ th=mk_type_handle( ) ,
4661
+ mutable size=0 u,
4662
+ mutable lldiscrims=@new_def_hash[ ValueRef ] ( )
4663
+ ) ;
4664
+
4665
+ cx. tags. insert( mk_plain_tag( tag_id) , info) ;
4642
4666
cx. items. insert( tag_id, i) ;
4643
4667
}
4644
4668
@@ -4772,22 +4796,7 @@ fn trans_constant(&@crate_ctxt cx, @ast.item it) -> @crate_ctxt {
4772
4796
llvm. LLVMSetLinkage ( discrim_gvar, lib. llvm . LLVMPrivateLinkage
4773
4797
as llvm . Linkage ) ;
4774
4798
4775
- if ( _vec. len [ ast. variant_arg ] ( variant. args ) == 0 u) {
4776
- // Nullary tags become constants. (N-ary tags are treated
4777
- // as functions and generated later.)
4778
-
4779
- auto union_val = C_zero_byte_arr ( info. size as uint ) ;
4780
- auto val = C_struct ( vec ( discrim_val, union_val) ) ;
4781
-
4782
- // FIXME: better name
4783
- auto gvar = llvm. LLVMAddGlobal ( cx. llmod , val_ty ( val) ,
4784
- _str. buf ( "tag" ) ) ;
4785
- llvm. LLVMSetInitializer ( gvar, val) ;
4786
- llvm. LLVMSetGlobalConstant ( gvar, True ) ;
4787
- llvm. LLVMSetLinkage ( gvar, lib. llvm . LLVMPrivateLinkage
4788
- as llvm . Linkage ) ;
4789
- cx. item_ids . insert ( variant. id , gvar) ;
4790
- }
4799
+ info. lldiscrims . insert ( variant. id , discrim_gvar) ;
4791
4800
4792
4801
i += 1 u;
4793
4802
}
0 commit comments