Skip to content

Commit 9891fab

Browse files
committed
---
yaml --- r: 43006 b: refs/heads/try c: b081f59 h: refs/heads/master v: v3
1 parent 51a549b commit 9891fab

File tree

11 files changed

+63
-94
lines changed

11 files changed

+63
-94
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 6d13c9025611cf904c0ef209dfad3d0d29fd7d5a
5+
refs/heads/try: b081f594954385813fc3b3b0d26cfcc191f1ceeb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/librustc/middle/trans/_match.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,6 @@ pub fn pick_col(m: &[@Match]) -> uint {
10281028
pub enum branch_kind { no_branch, single, switch, compare, compare_vec_len, }
10291029
10301030
// Compiles a comparison between two things.
1031-
//
1032-
// NB: This must produce an i1, not a Rust bool (i8).
10331031
pub fn compare_values(cx: block,
10341032
lhs: ValueRef,
10351033
rhs: ValueRef,
@@ -1055,11 +1053,7 @@ pub fn compare_values(cx: block,
10551053
scratch_rhs],
10561054
expr::SaveIn(
10571055
scratch_result.val));
1058-
let result = scratch_result.to_result(bcx);
1059-
Result {
1060-
bcx: result.bcx,
1061-
val: bool_to_i1(result.bcx, result.val)
1062-
}
1056+
return scratch_result.to_result(bcx);
10631057
}
10641058
ty::ty_estr(_) => {
10651059
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
@@ -1069,11 +1063,7 @@ pub fn compare_values(cx: block,
10691063
~[lhs, rhs],
10701064
expr::SaveIn(
10711065
scratch_result.val));
1072-
let result = scratch_result.to_result(bcx);
1073-
Result {
1074-
bcx: result.bcx,
1075-
val: bool_to_i1(result.bcx, result.val)
1076-
}
1066+
return scratch_result.to_result(bcx);
10771067
}
10781068
_ => {
10791069
cx.tcx().sess.bug(~"only scalars and strings supported in \
@@ -1186,7 +1176,6 @@ pub fn compile_guard(bcx: block,
11861176
expr::trans_to_datum(bcx, guard_expr).to_result()
11871177
}
11881178
});
1189-
let val = bool_to_i1(bcx, val);
11901179
11911180
// Revoke the temp cleanups now that the guard successfully executed.
11921181
for temp_cleanups.each |llval| {

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,8 @@ pub fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: ~str) {
494494
// Used only for creating scalar comparison glue.
495495
pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, }
496496

497-
// NB: This produces an i1, not a Rust bool (i8).
498-
pub fn compare_scalar_types(cx: block,
499-
lhs: ValueRef,
500-
rhs: ValueRef,
501-
t: ty::t,
502-
op: ast::binop)
503-
-> Result {
497+
pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
498+
t: ty::t, op: ast::binop) -> Result {
504499
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
505500

506501
match ty::get(t).sty {
@@ -526,12 +521,8 @@ pub fn compare_scalar_types(cx: block,
526521

527522

528523
// A helper function to do the actual comparison of scalar values.
529-
pub fn compare_scalar_values(cx: block,
530-
lhs: ValueRef,
531-
rhs: ValueRef,
532-
nt: scalar_type,
533-
op: ast::binop)
534-
-> ValueRef {
524+
pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
525+
nt: scalar_type, op: ast::binop) -> ValueRef {
535526
let _icx = cx.insn_ctxt("compare_scalar_values");
536527
fn die(cx: block) -> ! {
537528
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
@@ -542,8 +533,8 @@ pub fn compare_scalar_values(cx: block,
542533
// We don't need to do actual comparisons for nil.
543534
// () == () holds but () < () does not.
544535
match op {
545-
ast::eq | ast::le | ast::ge => return C_i1(true),
546-
ast::ne | ast::lt | ast::gt => return C_i1(false),
536+
ast::eq | ast::le | ast::ge => return C_bool(true),
537+
ast::ne | ast::lt | ast::gt => return C_bool(false),
547538
// refinements would be nice
548539
_ => die(cx)
549540
}
@@ -813,6 +804,27 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id,
813804
}
814805
}
815806

807+
pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
808+
unsafe {
809+
let _icx = ccx.insn_ctxt("lookup_discriminant");
810+
match ccx.discrims.find(&vid) {
811+
None => {
812+
// It's an external discriminant that we haven't seen yet.
813+
assert (vid.crate != ast::local_crate);
814+
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
815+
let gvar = str::as_c_str(sym, |buf| {
816+
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
817+
});
818+
lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
819+
llvm::LLVMSetGlobalConstant(gvar, True);
820+
ccx.discrims.insert(vid, gvar);
821+
return gvar;
822+
}
823+
Some(llval) => return llval,
824+
}
825+
}
826+
}
827+
816828
pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block {
817829
let _icx = bcx.insn_ctxt("invoke_");
818830
if bcx.unreachable { return bcx; }
@@ -1430,7 +1442,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
14301442
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
14311443
let size = IntCast(cx, n_bytes, ccx.int_type);
14321444
let align = C_i32(1i32);
1433-
let volatile = C_i1(false);
1445+
let volatile = C_bool(false);
14341446
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
14351447
}
14361448

@@ -1477,7 +1489,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
14771489
let llzeroval = C_u8(0);
14781490
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
14791491
let align = C_i32(1i32);
1480-
let volatile = C_i1(false);
1492+
let volatile = C_bool(false);
14811493
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
14821494
}
14831495

branches/try/src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,7 @@ pub fn trans_call_inner(
438438
let flag = alloca(bcx, T_bool());
439439
Store(bcx, C_bool(false), flag);
440440
Some(flag)
441-
} else {
442-
None
443-
};
441+
} else { None };
444442

445443
let (llfn, llenv) = unsafe {
446444
match callee.data {
@@ -508,8 +506,7 @@ pub fn trans_call_inner(
508506
if ty::type_is_bot(ret_ty) {
509507
Unreachable(bcx);
510508
} else if ret_in_loop {
511-
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
512-
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
509+
bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| {
513510
do option::iter(&copy bcx.fcx.loop_ret) |lret| {
514511
Store(bcx, C_bool(true), lret.flagptr);
515512
Store(bcx, C_bool(false), bcx.fcx.llretptr);

branches/try/src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ pub fn T_f32() -> TypeRef { unsafe { return llvm::LLVMFloatType(); } }
759759

760760
pub fn T_f64() -> TypeRef { unsafe { return llvm::LLVMDoubleType(); } }
761761

762-
pub fn T_bool() -> TypeRef { return T_i8(); }
762+
pub fn T_bool() -> TypeRef { return T_i1(); }
763763

764764
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
765765
return match targ_cfg.arch {
@@ -1109,10 +1109,6 @@ pub fn C_bool(b: bool) -> ValueRef {
11091109
C_integral(T_bool(), if b { 1u64 } else { 0u64 }, False)
11101110
}
11111111

1112-
pub fn C_i1(b: bool) -> ValueRef {
1113-
return C_integral(T_i1(), if b { 1 } else { 0 }, False);
1114-
}
1115-
11161112
pub fn C_i32(i: i32) -> ValueRef {
11171113
return C_integral(T_i32(), i as u64, True);
11181114
}
@@ -1439,11 +1435,6 @@ pub fn struct_dtor() -> [uint * 2] {
14391435
[0, 1]
14401436
}
14411437

1442-
// Casts a Rust bool value to an i1.
1443-
pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef {
1444-
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))
1445-
}
1446-
14471438
//
14481439
// Local Variables:
14491440
// mode: rust

branches/try/src/librustc/middle/trans/controlflow.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ pub fn trans_if(bcx: block,
6262

6363
let then_bcx_in = scope_block(bcx, thn.info(), ~"then");
6464
let else_bcx_in = scope_block(bcx, els.info(), ~"else");
65-
66-
let cond_val = bool_to_i1(bcx, cond_val);
6765
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
6866

6967
debug!("then_bcx_in=%s, else_bcx_in=%s",
@@ -141,7 +139,6 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block {
141139
// compile the condition
142140
let Result {bcx: cond_bcx_out, val: cond_val} =
143141
expr::trans_to_datum(cond_bcx_in, cond).to_result();
144-
let cond_val = bool_to_i1(cond_bcx_out, cond_val);
145142
let cond_bcx_out =
146143
trans_block_cleanups(cond_bcx_out, block_cleanups(cond_bcx_in));
147144
CondBr(cond_bcx_out, cond_val, body_bcx_in.llbb, next_bcx.llbb);
@@ -327,7 +324,6 @@ pub fn trans_check_expr(bcx: block,
327324
expr::trans_to_datum(bcx, pred_expr).to_result()
328325
}
329326
};
330-
let val = bool_to_i1(bcx, val);
331327
do with_cond(bcx, Not(bcx, val)) |bcx| {
332328
trans_fail(bcx, Some(pred_expr.span), /*bad*/copy expr_str)
333329
}

branches/try/src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn lli64(val: int) -> ValueRef {
7777
C_i64(val as i64)
7878
}
7979
fn lli1(bval: bool) -> ValueRef {
80-
C_i1(bval)
80+
C_bool(bval)
8181
}
8282
fn llmdnode(elems: ~[ValueRef]) -> ValueRef {
8383
unsafe {

branches/try/src/librustc/middle/trans/expr.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -696,15 +696,15 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
696696
return fn_data_to_datum(bcx, impl_did, fn_data, lldest);
697697
}
698698
ast::def_variant(tid, vid) => {
699-
let variant_info = ty::enum_variant_with_id(ccx.tcx, tid, vid);
700-
if variant_info.args.len() > 0u {
699+
if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u {
701700
// N-ary variant.
702701
let fn_data = callee::trans_fn_ref(bcx, vid, ref_expr.id);
703702
return fn_data_to_datum(bcx, vid, fn_data, lldest);
704703
} else {
705704
// Nullary variant.
706705
let lldiscrimptr = GEPi(bcx, lldest, [0u, 0u]);
707-
let lldiscrim = C_int(bcx.ccx(), variant_info.disr_val);
706+
let lldiscrim_gv = base::lookup_discriminant(ccx, vid);
707+
let lldiscrim = Load(bcx, lldiscrim_gv);
708708
Store(bcx, lldiscrim, lldiscrimptr);
709709
return bcx;
710710
}
@@ -1236,6 +1236,7 @@ fn trans_unary_datum(bcx: block,
12361236
un_expr: @ast::expr,
12371237
op: ast::unop,
12381238
sub_expr: @ast::expr) -> DatumBlock {
1239+
12391240
let _icx = bcx.insn_ctxt("trans_unary_datum");
12401241

12411242
// if deref, would be LvalueExpr
@@ -1250,21 +1251,7 @@ fn trans_unary_datum(bcx: block,
12501251
return match op {
12511252
ast::not => {
12521253
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
1253-
1254-
// If this is a boolean type, we must not use the LLVM Not
1255-
// instruction, as that is a *bitwise* not and we want *logical*
1256-
// not on our 8-bit boolean values.
1257-
let llresult = match ty::get(un_ty).sty {
1258-
ty::ty_bool => {
1259-
let llcond = ICmp(bcx,
1260-
lib::llvm::IntEQ,
1261-
val,
1262-
C_bool(false));
1263-
Select(bcx, llcond, C_bool(true), C_bool(false))
1264-
}
1265-
_ => Not(bcx, val)
1266-
};
1267-
immediate_rvalue_bcx(bcx, llresult, un_ty)
1254+
immediate_rvalue_bcx(bcx, Not(bcx, val), un_ty)
12681255
}
12691256
ast::neg => {
12701257
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
@@ -1321,8 +1308,8 @@ fn trans_eager_binop(bcx: block,
13211308
binop_ty: ty::t,
13221309
op: ast::binop,
13231310
lhs_datum: &Datum,
1324-
rhs_datum: &Datum)
1325-
-> DatumBlock {
1311+
rhs_datum: &Datum) -> DatumBlock
1312+
{
13261313
let mut bcx = bcx;
13271314
let _icx = bcx.insn_ctxt("trans_eager_binop");
13281315

@@ -1401,7 +1388,7 @@ fn trans_eager_binop(bcx: block,
14011388
}
14021389
let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
14031390
bcx = cmpr.bcx;
1404-
ZExt(bcx, cmpr.val, T_i8())
1391+
cmpr.val
14051392
}
14061393
}
14071394
_ => {
@@ -1419,7 +1406,8 @@ fn trans_lazy_binop(bcx: block,
14191406
binop_expr: @ast::expr,
14201407
op: lazy_binop_ty,
14211408
a: @ast::expr,
1422-
b: @ast::expr) -> DatumBlock {
1409+
b: @ast::expr) -> DatumBlock
1410+
{
14231411
let _icx = bcx.insn_ctxt("trans_lazy_binop");
14241412
let binop_ty = expr_ty(bcx, binop_expr);
14251413
let mut bcx = bcx;
@@ -1437,12 +1425,10 @@ fn trans_lazy_binop(bcx: block,
14371425
let join = base::sub_block(bcx, ~"join");
14381426
let before_rhs = base::sub_block(bcx, ~"rhs");
14391427

1440-
let lhs_i1 = bool_to_i1(past_lhs, lhs);
14411428
match op {
1442-
lazy_and => CondBr(past_lhs, lhs_i1, before_rhs.llbb, join.llbb),
1443-
lazy_or => CondBr(past_lhs, lhs_i1, join.llbb, before_rhs.llbb)
1429+
lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
1430+
lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
14441431
}
1445-
14461432
let Result {bcx: past_rhs, val: rhs} = {
14471433
do base::with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| {
14481434
trans_to_datum(bcx, b).to_result()

0 commit comments

Comments
 (0)