Skip to content

Commit 51a549b

Browse files
committed
---
yaml --- r: 43005 b: refs/heads/try c: 6d13c90 h: refs/heads/master i: 43003: 25c3f10 v: v3
1 parent db605bc commit 51a549b

File tree

11 files changed

+94
-65
lines changed

11 files changed

+94
-65
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: 79dc10dba91d242b2bbdc65e20dd0fe5fe7f3f40
5+
refs/heads/try: 6d13c9025611cf904c0ef209dfad3d0d29fd7d5a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/mk/docs.mk

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css
4545
--from=markdown --to=html \
4646
--css=rust.css \
4747
--css=manual.css \
48-
--include-before-body=doc/version_info.html \
48+
--include-before-body=doc/version_info.html \
4949
--output=$@
5050
endif
5151

@@ -66,7 +66,6 @@ doc/rust.tex: rust.md doc/version.md
6666
"$(CFG_PANDOC)" \
6767
--standalone --toc \
6868
--number-sections \
69-
--include-before-body=doc/version.md \
7069
--from=markdown --to=latex \
7170
--output=$@
7271

@@ -200,17 +199,16 @@ ifdef CFG_DISABLE_DOCS
200199
endif
201200

202201

203-
doc/version.md: $(MKFILE_DEPS) $(wildcard $(S)doc/*.*)
202+
doc/version.md: $(MKFILE_DEPS) rust.md
204203
@$(call E, version-stamp: $@)
205204
$(Q)echo "$(CFG_VERSION)" >$@
206205

207-
doc/version_info.html: version_info.html.template $(MKFILE_DEPS) \
208-
$(wildcard $(S)doc/*.*)
206+
doc/version_info.html: version_info.html.template
209207
@$(call E, version-info: $@)
210208
sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
211209
$(CFG_VER_HASH) | head -c 8)/;\
212210
s/STAMP/$(CFG_VER_HASH)/;" $< >$@
213211

214-
GENERATED += doc/version.md doc/version_info.html
212+
GENERATED += doc/version.md
215213

216214
docs: $(DOCS)

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,8 @@ 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).
10311033
pub fn compare_values(cx: block,
10321034
lhs: ValueRef,
10331035
rhs: ValueRef,
@@ -1053,7 +1055,11 @@ pub fn compare_values(cx: block,
10531055
scratch_rhs],
10541056
expr::SaveIn(
10551057
scratch_result.val));
1056-
return scratch_result.to_result(bcx);
1058+
let result = scratch_result.to_result(bcx);
1059+
Result {
1060+
bcx: result.bcx,
1061+
val: bool_to_i1(result.bcx, result.val)
1062+
}
10571063
}
10581064
ty::ty_estr(_) => {
10591065
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
@@ -1063,7 +1069,11 @@ pub fn compare_values(cx: block,
10631069
~[lhs, rhs],
10641070
expr::SaveIn(
10651071
scratch_result.val));
1066-
return scratch_result.to_result(bcx);
1072+
let result = scratch_result.to_result(bcx);
1073+
Result {
1074+
bcx: result.bcx,
1075+
val: bool_to_i1(result.bcx, result.val)
1076+
}
10671077
}
10681078
_ => {
10691079
cx.tcx().sess.bug(~"only scalars and strings supported in \
@@ -1176,6 +1186,7 @@ pub fn compile_guard(bcx: block,
11761186
expr::trans_to_datum(bcx, guard_expr).to_result()
11771187
}
11781188
});
1189+
let val = bool_to_i1(bcx, val);
11791190
11801191
// Revoke the temp cleanups now that the guard successfully executed.
11811192
for temp_cleanups.each |llval| {

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

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,13 @@ 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-
pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
498-
t: ty::t, op: ast::binop) -> Result {
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 {
499504
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
500505

501506
match ty::get(t).sty {
@@ -521,8 +526,12 @@ pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
521526

522527

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

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-
828816
pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block {
829817
let _icx = bcx.insn_ctxt("invoke_");
830818
if bcx.unreachable { return bcx; }
@@ -1442,7 +1430,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
14421430
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
14431431
let size = IntCast(cx, n_bytes, ccx.int_type);
14441432
let align = C_i32(1i32);
1445-
let volatile = C_bool(false);
1433+
let volatile = C_i1(false);
14461434
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
14471435
}
14481436

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

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

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

443445
let (llfn, llenv) = unsafe {
444446
match callee.data {
@@ -506,7 +508,8 @@ pub fn trans_call_inner(
506508
if ty::type_is_bot(ret_ty) {
507509
Unreachable(bcx);
508510
} else if ret_in_loop {
509-
bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| {
511+
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
512+
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
510513
do option::iter(&copy bcx.fcx.loop_ret) |lret| {
511514
Store(bcx, C_bool(true), lret.flagptr);
512515
Store(bcx, C_bool(false), bcx.fcx.llretptr);

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

Lines changed: 10 additions & 1 deletion
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_i1(); }
762+
pub fn T_bool() -> TypeRef { return T_i8(); }
763763

764764
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
765765
return match targ_cfg.arch {
@@ -1109,6 +1109,10 @@ 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+
11121116
pub fn C_i32(i: i32) -> ValueRef {
11131117
return C_integral(T_i32(), i as u64, True);
11141118
}
@@ -1435,6 +1439,11 @@ pub fn struct_dtor() -> [uint * 2] {
14351439
[0, 1]
14361440
}
14371441

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+
14381447
//
14391448
// Local Variables:
14401449
// mode: rust

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ 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);
6567
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
6668

6769
debug!("then_bcx_in=%s, else_bcx_in=%s",
@@ -139,6 +141,7 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block {
139141
// compile the condition
140142
let Result {bcx: cond_bcx_out, val: cond_val} =
141143
expr::trans_to_datum(cond_bcx_in, cond).to_result();
144+
let cond_val = bool_to_i1(cond_bcx_out, cond_val);
142145
let cond_bcx_out =
143146
trans_block_cleanups(cond_bcx_out, block_cleanups(cond_bcx_in));
144147
CondBr(cond_bcx_out, cond_val, body_bcx_in.llbb, next_bcx.llbb);
@@ -324,6 +327,7 @@ pub fn trans_check_expr(bcx: block,
324327
expr::trans_to_datum(bcx, pred_expr).to_result()
325328
}
326329
};
330+
let val = bool_to_i1(bcx, val);
327331
do with_cond(bcx, Not(bcx, val)) |bcx| {
328332
trans_fail(bcx, Some(pred_expr.span), /*bad*/copy expr_str)
329333
}

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_bool(bval)
80+
C_i1(bval)
8181
}
8282
fn llmdnode(elems: ~[ValueRef]) -> ValueRef {
8383
unsafe {

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

Lines changed: 26 additions & 12 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-
if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u {
699+
let variant_info = ty::enum_variant_with_id(ccx.tcx, tid, vid);
700+
if variant_info.args.len() > 0u {
700701
// N-ary variant.
701702
let fn_data = callee::trans_fn_ref(bcx, vid, ref_expr.id);
702703
return fn_data_to_datum(bcx, vid, fn_data, lldest);
703704
} else {
704705
// Nullary variant.
705706
let lldiscrimptr = GEPi(bcx, lldest, [0u, 0u]);
706-
let lldiscrim_gv = base::lookup_discriminant(ccx, vid);
707-
let lldiscrim = Load(bcx, lldiscrim_gv);
707+
let lldiscrim = C_int(bcx.ccx(), variant_info.disr_val);
708708
Store(bcx, lldiscrim, lldiscrimptr);
709709
return bcx;
710710
}
@@ -1236,7 +1236,6 @@ fn trans_unary_datum(bcx: block,
12361236
un_expr: @ast::expr,
12371237
op: ast::unop,
12381238
sub_expr: @ast::expr) -> DatumBlock {
1239-
12401239
let _icx = bcx.insn_ctxt("trans_unary_datum");
12411240

12421241
// if deref, would be LvalueExpr
@@ -1251,7 +1250,21 @@ fn trans_unary_datum(bcx: block,
12511250
return match op {
12521251
ast::not => {
12531252
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
1254-
immediate_rvalue_bcx(bcx, Not(bcx, val), un_ty)
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)
12551268
}
12561269
ast::neg => {
12571270
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
@@ -1308,8 +1321,8 @@ fn trans_eager_binop(bcx: block,
13081321
binop_ty: ty::t,
13091322
op: ast::binop,
13101323
lhs_datum: &Datum,
1311-
rhs_datum: &Datum) -> DatumBlock
1312-
{
1324+
rhs_datum: &Datum)
1325+
-> DatumBlock {
13131326
let mut bcx = bcx;
13141327
let _icx = bcx.insn_ctxt("trans_eager_binop");
13151328

@@ -1388,7 +1401,7 @@ fn trans_eager_binop(bcx: block,
13881401
}
13891402
let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
13901403
bcx = cmpr.bcx;
1391-
cmpr.val
1404+
ZExt(bcx, cmpr.val, T_i8())
13921405
}
13931406
}
13941407
_ => {
@@ -1406,8 +1419,7 @@ fn trans_lazy_binop(bcx: block,
14061419
binop_expr: @ast::expr,
14071420
op: lazy_binop_ty,
14081421
a: @ast::expr,
1409-
b: @ast::expr) -> DatumBlock
1410-
{
1422+
b: @ast::expr) -> DatumBlock {
14111423
let _icx = bcx.insn_ctxt("trans_lazy_binop");
14121424
let binop_ty = expr_ty(bcx, binop_expr);
14131425
let mut bcx = bcx;
@@ -1425,10 +1437,12 @@ fn trans_lazy_binop(bcx: block,
14251437
let join = base::sub_block(bcx, ~"join");
14261438
let before_rhs = base::sub_block(bcx, ~"rhs");
14271439

1440+
let lhs_i1 = bool_to_i1(past_lhs, lhs);
14281441
match op {
1429-
lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
1430-
lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
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)
14311444
}
1445+
14321446
let Result {bcx: past_rhs, val: rhs} = {
14331447
do base::with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| {
14341448
trans_to_datum(bcx, b).to_result()

0 commit comments

Comments
 (0)