Skip to content

Commit 17a14fe

Browse files
committed
Merge branch 'incoming' of https://github.com/mozilla/rust into incoming
2 parents e4c7d8e + b3e1825 commit 17a14fe

File tree

21 files changed

+369
-153
lines changed

21 files changed

+369
-153
lines changed

RELEASES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 0.6 (?)
2+
---------------------------
3+
4+
* Libraries
5+
* `core::send_map` renamed to `core::hashmap`
6+
17
Version 0.5 (December 2012)
28
---------------------------
39

src/libcore/hashmap.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ pub mod linear {
4949
buckets: ~[Option<Bucket<K, V>>],
5050
}
5151

52-
// FIXME(#3148) -- we could rewrite FoundEntry
53-
// to have type Option<&Bucket<K, V>> which would be nifty
54-
// However, that won't work until #3148 is fixed
52+
// We could rewrite FoundEntry to have type Option<&Bucket<K, V>>
53+
// which would be nifty
5554
enum SearchResult {
5655
FoundEntry(uint), FoundHole(uint), TableFull
5756
}
@@ -296,8 +295,6 @@ pub mod linear {
296295
FoundEntry(idx) => {
297296
match self.buckets[idx] {
298297
Some(ref bkt) => {
299-
// FIXME(#3148)---should be inferred
300-
let bkt: &self/Bucket<K, V> = bkt;
301298
Some(&bkt.value)
302299
}
303300
None => {

src/libcore/rand.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,102 @@ use uint;
2323
use util;
2424
use vec;
2525

26+
/// A type that can be randomly generated using an RNG
27+
pub trait Rand {
28+
static fn rand(rng: rand::Rng) -> Self;
29+
}
30+
31+
impl int: Rand {
32+
static fn rand(rng: rand::Rng) -> int {
33+
rng.gen_int()
34+
}
35+
}
36+
37+
impl i8: Rand {
38+
static fn rand(rng: rand::Rng) -> i8 {
39+
rng.gen_i8()
40+
}
41+
}
42+
43+
impl i16: Rand {
44+
static fn rand(rng: rand::Rng) -> i16 {
45+
rng.gen_i16()
46+
}
47+
}
48+
49+
impl i32: Rand {
50+
static fn rand(rng: rand::Rng) -> i32 {
51+
rng.gen_i32()
52+
}
53+
}
54+
55+
impl i64: Rand {
56+
static fn rand(rng: rand::Rng) -> i64 {
57+
rng.gen_i64()
58+
}
59+
}
60+
61+
impl u8: Rand {
62+
static fn rand(rng: rand::Rng) -> u8 {
63+
rng.gen_u8()
64+
}
65+
}
66+
67+
impl u16: Rand {
68+
static fn rand(rng: rand::Rng) -> u16 {
69+
rng.gen_u16()
70+
}
71+
}
72+
73+
impl u32: Rand {
74+
static fn rand(rng: rand::Rng) -> u32 {
75+
rng.gen_u32()
76+
}
77+
}
78+
79+
impl u64: Rand {
80+
static fn rand(rng: rand::Rng) -> u64 {
81+
rng.gen_u64()
82+
}
83+
}
84+
85+
impl float: Rand {
86+
static fn rand(rng: rand::Rng) -> float {
87+
rng.gen_float()
88+
}
89+
}
90+
91+
impl f32: Rand {
92+
static fn rand(rng: rand::Rng) -> f32 {
93+
rng.gen_f32()
94+
}
95+
}
96+
97+
impl f64: Rand {
98+
static fn rand(rng: rand::Rng) -> f64 {
99+
rng.gen_f64()
100+
}
101+
}
102+
103+
impl char: Rand {
104+
static fn rand(rng: rand::Rng) -> char {
105+
rng.gen_char()
106+
}
107+
}
108+
109+
impl bool: Rand {
110+
static fn rand(rng: rand::Rng) -> bool {
111+
rng.gen_bool()
112+
}
113+
}
114+
115+
impl<T: Rand> Option<T>: Rand {
116+
static fn rand(rng: rand::Rng) -> Option<T> {
117+
if rng.gen_bool() { Some(Rand::rand(rng)) }
118+
else { None }
119+
}
120+
}
121+
26122
#[allow(non_camel_case_types)] // runtime type
27123
enum rctx {}
28124

@@ -49,6 +145,10 @@ pub struct Weighted<T> {
49145

50146
/// Extension methods for random number generators
51147
impl Rng {
148+
/// Return a random value for a Rand type
149+
fn gen<T: Rand>() -> T {
150+
Rand::rand(self)
151+
}
52152

53153
/// Return a random int
54154
fn gen_int() -> int {

src/librustc/lib/llvm.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,19 @@ pub extern mod llvm {
445445
Count: c_uint,
446446
Packed: Bool) -> ValueRef;
447447

448-
pub unsafe fn LLVMConstString(Str: *c_char, Length: c_uint,
449-
DontNullTerminate: Bool) -> ValueRef;
450-
pub unsafe fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
451-
Length: c_uint) -> ValueRef;
448+
pub unsafe fn LLVMConstString(Str: *c_char,
449+
Length: c_uint,
450+
DontNullTerminate: Bool)
451+
-> ValueRef;
452+
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
453+
ConstantVals: *ValueRef,
454+
Length: c_uint)
455+
-> ValueRef;
452456
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
453-
Count: c_uint, Packed: Bool) -> ValueRef;
457+
Count: c_uint,
458+
Packed: Bool) -> ValueRef;
454459
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
455-
Size: c_uint) -> ValueRef;
460+
Size: c_uint) -> ValueRef;
456461

457462
/* Constant expressions */
458463
pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
@@ -463,8 +468,8 @@ pub extern mod llvm {
463468
pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
464469
pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
465470
pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
466-
RHSConstant: ValueRef)
467-
-> ValueRef;
471+
RHSConstant: ValueRef)
472+
-> ValueRef;
468473
pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
469474
RHSConstant: ValueRef)
470475
-> ValueRef;
@@ -475,14 +480,14 @@ pub extern mod llvm {
475480
RHSConstant: ValueRef)
476481
-> ValueRef;
477482
pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
478-
RHSConstant: ValueRef)
479-
-> ValueRef;
483+
RHSConstant: ValueRef)
484+
-> ValueRef;
480485
pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
481-
RHSConstant: ValueRef)
482-
-> ValueRef;
486+
RHSConstant: ValueRef)
487+
-> ValueRef;
483488
pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
484-
RHSConstant: ValueRef)
485-
-> ValueRef;
489+
RHSConstant: ValueRef)
490+
-> ValueRef;
486491
pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
487492
RHSConstant: ValueRef)
488493
-> ValueRef;

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| {

src/librustc/middle/trans/base.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec,
137137
ccx.stats.fn_times.push({ident: name, time: elapsed});
138138
}
139139

140-
pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
140+
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
141141
llty: TypeRef) -> ValueRef {
142142
let llfn: ValueRef = str::as_c_str(name, |buf| {
143143
unsafe {
@@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
150150
return llfn;
151151
}
152152

153-
pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef)
153+
pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef)
154154
-> ValueRef {
155155
return decl_fn(llmod, name, lib::llvm::CCallConv, llty);
156156
}
@@ -164,20 +164,19 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) ->
164164
return llfn;
165165
}
166166

167-
pub fn get_extern_fn(externs: HashMap<~str, ValueRef>,
167+
pub fn get_extern_fn(externs: ExternMap,
168168
llmod: ModuleRef,
169-
+name: ~str,
169+
name: @str,
170170
cc: lib::llvm::CallConv,
171171
ty: TypeRef) -> ValueRef {
172172
if externs.contains_key_ref(&name) { return externs.get(&name); }
173-
// XXX: Bad copy.
174-
let f = decl_fn(llmod, copy name, cc, ty);
173+
let f = decl_fn(llmod, name, cc, ty);
175174
externs.insert(name, f);
176175
return f;
177176
}
178177

179-
pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
180-
+name: ~str, ty: TypeRef) -> ValueRef {
178+
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
179+
name: @str, ty: TypeRef) -> ValueRef {
181180
unsafe {
182181
if externs.contains_key_ref(&name) { return externs.get(&name); }
183182
let c = str::as_c_str(name, |buf| {
@@ -189,9 +188,9 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
189188
}
190189

191190
fn get_simple_extern_fn(cx: block,
192-
externs: HashMap<~str, ValueRef>,
191+
externs: ExternMap,
193192
llmod: ModuleRef,
194-
+name: ~str,
193+
name: @str,
195194
n_args: int) -> ValueRef {
196195
let _icx = cx.insn_ctxt("get_simple_extern_fn");
197196
let ccx = cx.fcx.ccx;
@@ -201,8 +200,8 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
201200
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
202201
}
203202

204-
pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>,
205-
llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) ->
203+
pub fn trans_foreign_call(cx: block, externs: ExternMap,
204+
llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
206205
ValueRef {
207206
let _icx = cx.insn_ctxt("trans_foreign_call");
208207
let n = args.len() as int;
@@ -474,6 +473,7 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
474473
let class_ty = ty::subst_tps(tcx, substs, None,
475474
ty::lookup_item_type(tcx, parent_id).ty);
476475
let llty = type_of_dtor(ccx, class_ty);
476+
let name = name.to_managed(); // :-(
477477
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
478478
llty)
479479
}
@@ -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
}
@@ -766,7 +775,7 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {
766775
767776
pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
768777
-> ValueRef {
769-
let name = csearch::get_symbol(ccx.sess.cstore, did);
778+
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
770779
match ty::get(t).sty {
771780
ty::ty_fn(_) => {
772781
let llty = type_of_fn_from_ty(ccx, t);
@@ -1442,7 +1451,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
14421451
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
14431452
let size = IntCast(cx, n_bytes, ccx.int_type);
14441453
let align = C_i32(1i32);
1445-
let volatile = C_bool(false);
1454+
let volatile = C_i1(false);
14461455
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
14471456
}
14481457

@@ -1489,7 +1498,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
14891498
let llzeroval = C_u8(0);
14901499
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
14911500
let align = C_i32(1i32);
1492-
let volatile = C_bool(false);
1501+
let volatile = C_i1(false);
14931502
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
14941503
}
14951504

0 commit comments

Comments
 (0)