@@ -39,6 +39,7 @@ use middle::astencode;
39
39
use middle:: borrowck:: RootInfo ;
40
40
use middle:: resolve;
41
41
use middle:: trans:: _match;
42
+ use middle:: trans:: adt;
42
43
use middle:: trans:: base;
43
44
use middle:: trans:: build:: * ;
44
45
use middle:: trans:: callee;
@@ -1861,7 +1862,6 @@ pub fn trans_enum_variant(ccx: @CrateContext,
1861
1862
variant : ast:: variant ,
1862
1863
args : & [ ast:: variant_arg ] ,
1863
1864
disr : int ,
1864
- is_degen : bool ,
1865
1865
param_substs : Option < @param_substs > ,
1866
1866
llfndecl : ValueRef ) {
1867
1867
let _icx = ccx. insn_ctxt ( "trans_enum_variant" ) ;
@@ -1890,21 +1890,15 @@ pub fn trans_enum_variant(ccx: @CrateContext,
1890
1890
let arg_tys = ty:: ty_fn_args ( node_id_type ( bcx, variant. node . id ) ) ;
1891
1891
let bcx = copy_args_to_allocas ( fcx, bcx, fn_args, raw_llargs, arg_tys) ;
1892
1892
1893
- // Cast the enum to a type we can GEP into.
1894
- let llblobptr = if is_degen {
1895
- fcx. llretptr
1896
- } else {
1897
- let llenumptr =
1898
- PointerCast ( bcx, fcx. llretptr , T_opaque_enum_ptr ( ccx) ) ;
1899
- let lldiscrimptr = GEPi ( bcx, llenumptr, [ 0 u, 0 u] ) ;
1900
- Store ( bcx, C_int ( ccx, disr) , lldiscrimptr) ;
1901
- GEPi ( bcx, llenumptr, [ 0 u, 1 u] )
1902
- } ;
1903
- let t_id = local_def ( enum_id) ;
1904
- let v_id = local_def ( variant. node . id ) ;
1893
+ // XXX is there a better way to reconstruct the ty::t?
1894
+ let enum_ty = ty:: subst_tps ( ccx. tcx , ty_param_substs, None ,
1895
+ ty:: node_id_to_type ( ccx. tcx , enum_id) ) ;
1896
+ let repr = adt:: represent_type ( ccx, enum_ty) ;
1897
+
1898
+ adt:: trans_set_discr ( bcx, & repr, fcx. llretptr , disr) ;
1905
1899
for vec:: eachi( args) |i, va| {
1906
- let lldestptr = GEP_enum ( bcx, llblobptr , t_id , v_id ,
1907
- /*bad*/ copy ty_param_substs , i ) ;
1900
+ let lldestptr = adt :: trans_GEP ( bcx, & repr , fcx . llretptr , disr , i ) ;
1901
+
1908
1902
// If this argument to this function is a enum, it'll have come in to
1909
1903
// this function as an opaque blob due to the way that type_of()
1910
1904
// works. So we have to cast to the destination's view of the type.
@@ -2014,7 +2008,7 @@ pub fn trans_struct_dtor(ccx: @CrateContext,
2014
2008
}
2015
2009
2016
2010
pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
2017
- id: ast::node_id, degen: bool,
2011
+ id: ast::node_id,
2018
2012
path: @ast_map::path, vi: @~[ty::VariantInfo],
2019
2013
i: &mut uint) {
2020
2014
for vec::each(enum_definition.variants) |variant| {
@@ -2025,7 +2019,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
2025
2019
ast::tuple_variant_kind(ref args) if args.len() > 0 => {
2026
2020
let llfn = get_item_val(ccx, variant.node.id);
2027
2021
trans_enum_variant(ccx, id, *variant, /*bad*/copy *args,
2028
- disr_val, degen, None, llfn);
2022
+ disr_val, None, llfn);
2029
2023
}
2030
2024
ast::tuple_variant_kind(_) => {
2031
2025
// Nothing to do.
@@ -2038,7 +2032,6 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
2038
2032
trans_enum_def(ccx,
2039
2033
*enum_definition,
2040
2034
id,
2041
- degen,
2042
2035
path,
2043
2036
vi,
2044
2037
&mut *i);
@@ -2089,11 +2082,10 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
2089
2082
}
2090
2083
ast::item_enum(ref enum_definition, ref generics) => {
2091
2084
if !generics.is_type_parameterized() {
2092
- let degen = (*enum_definition).variants.len() == 1u;
2093
2085
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
2094
2086
let mut i = 0;
2095
2087
trans_enum_def(ccx, (*enum_definition), item.id,
2096
- degen, path, vi, &mut i);
2088
+ path, vi, &mut i);
2097
2089
}
2098
2090
}
2099
2091
ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id),
0 commit comments