Skip to content

Commit d11babe

Browse files
committed
First attemt at using i32 for disr. values. It failed.
I am getting failed tests on x86_64. NEEDS WORK.
1 parent 5ac57d1 commit d11babe

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

src/comp/metadata/decoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ fn variant_tag_id(d: ebml::doc) -> ast::def_id {
8989
ret parse_def_id(ebml::doc_data(tagdoc));
9090
}
9191

92-
fn variant_disr_val(d: ebml::doc) -> option::t<int> {
92+
fn variant_disr_val(d: ebml::doc) -> option::t<i32> {
9393
alt ebml::maybe_get_doc(d, tag_disr_val) {
9494
some(val_doc) {
9595
let val_buf = ebml::doc_data(val_doc);
9696
let val = int::parse_buf(val_buf, 10u);
97-
ret some(val);
97+
ret some(val as i32);
9898
}
9999
_ { ret none;}
100100
}
@@ -242,7 +242,7 @@ fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
242242
let item = find_item(id, items);
243243
let infos: [ty::variant_info] = [];
244244
let variant_ids = tag_variant_ids(item, cdata);
245-
let disr_val = 0;
245+
let disr_val = 0_i32;
246246
for did: ast::def_id in variant_ids {
247247
let item = find_item(did.node, items);
248248
let ctor_ty = item_type(item, tcx, cdata);
@@ -260,7 +260,7 @@ fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
260260
}
261261
infos += [@{args: arg_tys, ctor_ty: ctor_ty, name: name,
262262
id: did, disr_val: disr_val}];
263-
disr_val += 1;
263+
disr_val += 1_i32;
264264
}
265265
ret infos;
266266
}

src/comp/metadata/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ fn encode_discriminant(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
216216
ebml::end_tag(ebml_w);
217217
}
218218

219-
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
219+
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: i32) {
220220
ebml::start_tag(ebml_w, tag_disr_val);
221-
ebml_w.writer.write(str::bytes(int::to_str(disr_val,10u)));
221+
ebml_w.writer.write(str::bytes(int::to_str(disr_val as int,10u)));
222222
ebml::end_tag(ebml_w);
223223
}
224224

@@ -231,7 +231,7 @@ fn encode_tag_id(ebml_w: ebml::writer, id: def_id) {
231231
fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
232232
id: node_id, variants: [variant],
233233
&index: [entry<int>], ty_params: [ty_param]) {
234-
let disr_val = 0;
234+
let disr_val = 0_i32;
235235
let i = 0;
236236
let vi = ty::tag_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
237237
for variant: variant in variants {
@@ -253,7 +253,7 @@ fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
253253
}
254254
encode_type_param_bounds(ebml_w, ecx, ty_params);
255255
ebml::end_tag(ebml_w);
256-
disr_val += 1;
256+
disr_val += 1_i32;
257257
i += 1;
258258
}
259259
}

src/comp/middle/trans.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
16841684

16851685
// NB: we must hit the discriminant first so that structural
16861686
// comparison know not to proceed when the discriminants differ.
1687-
cx = f(cx, lldiscrim_a_ptr, ty::mk_int(bcx_tcx(cx)));
1687+
cx = f(cx, lldiscrim_a_ptr, ty::mk_mach_int(bcx_tcx(cx),ast::ty_i32));
16881688
let unr_cx = new_sub_block_ctxt(cx, "tag-iter-unr");
16891689
Unreachable(unr_cx);
16901690
let llswitch = Switch(cx, lldiscrim_a, unr_cx.llbb, n_variants);
@@ -1693,8 +1693,10 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
16931693
let variant_cx =
16941694
new_sub_block_ctxt(cx,
16951695
"tag-iter-variant-" +
1696-
int::to_str(variant.disr_val, 10u));
1697-
AddCase(llswitch, C_int(ccx, variant.disr_val), variant_cx.llbb);
1696+
int::to_str(variant.disr_val as int,
1697+
10u));
1698+
AddCase(llswitch, C_i32(variant.disr_val),
1699+
variant_cx.llbb);
16981700
variant_cx =
16991701
iter_variant(variant_cx, llunion_a_ptr, variant, tps, tid, f);
17001702
Br(variant_cx, next_cx.llbb);
@@ -2612,7 +2614,7 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
26122614
let gvar =
26132615
str::as_buf(sym,
26142616
{|buf|
2615-
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
2617+
llvm::LLVMAddGlobal(ccx.llmod, T_i32(), buf)
26162618
});
26172619
llvm::LLVMSetLinkage(gvar,
26182620
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
@@ -4542,7 +4544,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::fn_decl,
45424544

45434545

45444546
fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
4545-
variant: ast::variant, disr: int, is_degen: bool,
4547+
variant: ast::variant, disr: i32, is_degen: bool,
45464548
ty_params: [ast::ty_param]) {
45474549
let ccx = cx.ccx;
45484550

@@ -4592,7 +4594,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
45924594
let lltagptr =
45934595
PointerCast(bcx, fcx.llretptr, T_opaque_tag_ptr(ccx));
45944596
let lldiscrimptr = GEPi(bcx, lltagptr, [0, 0]);
4595-
Store(bcx, C_int(ccx, disr), lldiscrimptr);
4597+
Store(bcx, C_i32(disr), lldiscrimptr);
45964598
GEPi(bcx, lltagptr, [0, 1])
45974599
};
45984600
i = 0u;
@@ -5282,9 +5284,9 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
52825284
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
52835285
let disr_val = vi[i].disr_val;
52845286
let discrim_gvar = str::as_buf(s, {|buf|
5285-
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
5287+
llvm::LLVMAddGlobal(ccx.llmod, T_i32(), buf)
52865288
});
5287-
llvm::LLVMSetInitializer(discrim_gvar, C_int(ccx, disr_val));
5289+
llvm::LLVMSetInitializer(discrim_gvar, C_i32(disr_val));
52885290
llvm::LLVMSetGlobalConstant(discrim_gvar, True);
52895291
ccx.discrims.insert(
52905292
ast_util::local_def(variant.node.id), discrim_gvar);

src/comp/middle/trans_alt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import trans_common::*;
1919
// An option identifying a branch (either a literal, a tag variant or a range)
2020
tag opt {
2121
lit(@ast::expr);
22-
var(/* disr val */int, /* variant dids */{tg: def_id, var: def_id});
22+
var(/* disr val */i32, /* variant dids */{tg: def_id, var: def_id});
2323
range(@ast::expr, @ast::expr);
2424
}
2525
fn opt_eq(a: opt, b: opt) -> bool {
@@ -56,7 +56,9 @@ fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
5656
}
5757
}
5858
}
59-
var(disr_val, _) { ret single_result(rslt(bcx, C_int(ccx, disr_val))); }
59+
var(disr_val, _) {
60+
ret single_result(rslt(bcx, C_i32(disr_val)));
61+
}
6062
range(l1, l2) {
6163
ret range_result(rslt(bcx, trans::trans_const_expr(ccx, l1)),
6264
rslt(bcx, trans::trans_const_expr(ccx, l2)));

src/comp/middle/trans_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ fn T_opaque_cbox_ptr(cx: @crate_ctxt) -> TypeRef {
701701
ret t;
702702
}
703703

704-
fn T_tag_variant(cx: @crate_ctxt) -> TypeRef {
705-
ret cx.int_type;
704+
fn T_tag_variant(_cx: @crate_ctxt) -> TypeRef {
705+
ret T_i32();
706706
}
707707

708708
fn T_tag(cx: @crate_ctxt, size: uint) -> TypeRef {

src/comp/middle/ty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option::t<t> {
26342634

26352635
// Tag information
26362636
type variant_info = @{args: [ty::t], ctor_ty: ty::t, name: str,
2637-
id: ast::def_id, disr_val: int};
2637+
id: ast::def_id, disr_val: i32};
26382638

26392639
fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
26402640
alt cx.tag_var_cache.find(id) {
@@ -2649,7 +2649,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
26492649
// moved there to avoid having to call eval_const_expr twice.
26502650
alt cx.items.get(id.node) {
26512651
ast_map::node_item(@{node: ast::item_tag(variants, _), _}) {
2652-
let disr_val = -1;
2652+
let disr_val = -1_i32;
26532653
@vec::map(variants, {|variant|
26542654
let ctor_ty = node_id_to_monotype(cx, variant.node.id);
26552655
let arg_tys = if vec::len(variant.node.args) > 0u {
@@ -2659,10 +2659,10 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
26592659
some (ex) {
26602660
// FIXME: issue #1417
26612661
disr_val = alt syntax::ast_util::eval_const_expr(ex) {
2662-
ast_util::const_int(val) {val as int}
2662+
ast_util::const_int(val) {val as i32}
26632663
}
26642664
}
2665-
_ {disr_val += 1;}
2665+
_ {disr_val += 1_i32;}
26662666
}
26672667
@{args: arg_tys,
26682668
ctor_ty: ctor_ty,

src/comp/middle/typeck.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,8 @@ fn check_tag_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
24932493
// we may still get an internal compiler error.
24942494
alt syntax::ast_util::eval_const_expr(e) {
24952495
syntax::ast_util::const_int(val) {
2496+
// FIXME: Make sure val will fit in an i32 type as
2497+
// that is how they are represented internally
24962498
disr_val = val as int;
24972499
}
24982500
_ {

0 commit comments

Comments
 (0)