Skip to content

Commit 4aba9af

Browse files
committed
---
yaml --- r: 144955 b: refs/heads/try2 c: 67ed30c h: refs/heads/master i: 144953: 2a4d3e4 144951: 3f4152e v: v3
1 parent b4e7eb2 commit 4aba9af

File tree

32 files changed

+1214
-887
lines changed

32 files changed

+1214
-887
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: eb32ec13f1d870e5b85b03b353b659b59a7481bb
8+
refs/heads/try2: 67ed30cd5eab9af1976a994c50d146a3dbeccad4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/num/bigint.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2323
use std::int;
2424
use std::num;
2525
use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
26+
use std::rand::{Rng, RngUtil};
2627
use std::str;
2728
use std::uint;
2829
use std::vec;
@@ -1088,6 +1089,53 @@ impl FromStrRadix for BigInt {
10881089
}
10891090
}
10901091
1092+
trait RandBigInt {
1093+
/// Generate a random BigUint of the given bit size.
1094+
fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
1095+
1096+
/// Generate a random BigInt of the given bit size.
1097+
fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
1098+
}
1099+
1100+
impl<R: Rng> RandBigInt for R {
1101+
/// Generate a random BigUint of the given bit size.
1102+
fn gen_biguint(&mut self, bit_size: uint) -> BigUint {
1103+
let (digits, rem) = bit_size.div_rem(&BigDigit::bits);
1104+
let mut data = vec::with_capacity(digits+1);
1105+
for _ in range(0, digits) {
1106+
data.push(self.gen());
1107+
}
1108+
if rem > 0 {
1109+
let final_digit: BigDigit = self.gen();
1110+
data.push(final_digit >> (BigDigit::bits - rem));
1111+
}
1112+
return BigUint::new(data);
1113+
}
1114+
1115+
/// Generate a random BigInt of the given bit size.
1116+
fn gen_bigint(&mut self, bit_size: uint) -> BigInt {
1117+
// Generate a random BigUint...
1118+
let biguint = self.gen_biguint(bit_size);
1119+
// ...and then randomly assign it a Sign...
1120+
let sign = if biguint.is_zero() {
1121+
// ...except that if the BigUint is zero, we need to try
1122+
// again with probability 0.5. This is because otherwise,
1123+
// the probability of generating a zero BigInt would be
1124+
// double that of any other number.
1125+
if self.gen() {
1126+
return self.gen_bigint(bit_size);
1127+
} else {
1128+
Zero
1129+
}
1130+
} else if self.gen() {
1131+
Plus
1132+
} else {
1133+
Minus
1134+
};
1135+
return BigInt::from_biguint(sign, biguint);
1136+
}
1137+
}
1138+
10911139
impl BigInt {
10921140
/// Creates and initializes an BigInt.
10931141
#[inline]
@@ -1149,6 +1197,7 @@ mod biguint_tests {
11491197
use std::cmp::{Less, Equal, Greater};
11501198
use std::int;
11511199
use std::num::{IntConvertible, Zero, One, FromStrRadix};
1200+
use std::rand::{task_rng};
11521201
use std::str;
11531202
use std::uint;
11541203
use std::vec;
@@ -1656,6 +1705,13 @@ mod biguint_tests {
16561705
check(20, "2432902008176640000");
16571706
check(30, "265252859812191058636308480000000");
16581707
}
1708+
1709+
#[test]
1710+
fn test_rand() {
1711+
let mut rng = task_rng();
1712+
let _n: BigUint = rng.gen_biguint(137);
1713+
assert!(rng.gen_biguint(0).is_zero());
1714+
}
16591715
}
16601716

16611717
#[cfg(test)]
@@ -1665,6 +1721,7 @@ mod bigint_tests {
16651721
use std::cmp::{Less, Equal, Greater};
16661722
use std::int;
16671723
use std::num::{IntConvertible, Zero, One, FromStrRadix};
1724+
use std::rand::{task_rng};
16681725
use std::uint;
16691726

16701727
#[test]
@@ -2085,6 +2142,13 @@ mod bigint_tests {
20852142
let zero: BigInt = Zero::zero();
20862143
assert_eq!(-zero, zero);
20872144
}
2145+
2146+
#[test]
2147+
fn test_rand() {
2148+
let mut rng = task_rng();
2149+
let _n: BigInt = rng.gen_bigint(137);
2150+
assert!(rng.gen_bigint(0).is_zero());
2151+
}
20882152
}
20892153

20902154
#[cfg(test)]

branches/try2/src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl CFGBuilder {
488488

489489
fn find_scope(&self,
490490
expr: @ast::Expr,
491-
label: Option<ast::Ident>) -> LoopScope {
491+
label: Option<ast::Name>) -> LoopScope {
492492
match label {
493493
None => {
494494
return *self.loop_scopes.last();

branches/try2/src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
867867

868868
fn find_scope<'a>(&self,
869869
expr: @ast::Expr,
870-
label: Option<ast::Ident>,
870+
label: Option<ast::Name>,
871871
loop_scopes: &'a mut ~[LoopScope]) -> &'a mut LoopScope {
872872
let index = match label {
873873
None => {

branches/try2/src/librustc/middle/effect.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ impl Visitor<()> for EffectCheckVisitor {
102102
fn visit_block(&mut self, block:&Block, _:()) {
103103

104104
let old_unsafe_context = self.context.unsafe_context;
105-
if block.rules == ast::UnsafeBlock &&
106-
self.context.unsafe_context == SafeContext {
105+
let is_unsafe = match block.rules {
106+
ast::UnsafeBlock(*) => true, ast::DefaultBlock => false
107+
};
108+
if is_unsafe && self.context.unsafe_context == SafeContext {
107109
self.context.unsafe_context = UnsafeBlock(block.id)
108110
}
109111

branches/try2/src/librustc/middle/lint.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,11 @@ impl Visitor<@mut Context> for UnusedUnsafeLintVisitor {
11311131
fn visit_expr(&mut self, e:@ast::Expr, cx:@mut Context) {
11321132

11331133
match e.node {
1134-
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock => {
1135-
if !cx.tcx.used_unsafe.contains(&blk.id) {
1134+
// Don't warn about generated blocks, that'll just pollute the
1135+
// output.
1136+
ast::ExprBlock(ref blk) => {
1137+
if blk.rules == ast::UnsafeBlock(ast::UserProvided) &&
1138+
!cx.tcx.used_unsafe.contains(&blk.id) {
11361139
cx.span_lint(unused_unsafe, blk.span,
11371140
"unnecessary `unsafe` block");
11381141
}

branches/try2/src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl Liveness {
756756
}
757757

758758
pub fn find_loop_scope(&self,
759-
opt_label: Option<Ident>,
759+
opt_label: Option<Name>,
760760
id: NodeId,
761761
sp: Span)
762762
-> NodeId {

branches/try2/src/librustc/middle/resolve.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,15 +5157,13 @@ impl Resolver {
51575157
ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
51585158

51595159
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
5160-
let name = label.name;
5161-
match self.search_ribs(self.label_ribs, name, expr.span,
5160+
match self.search_ribs(self.label_ribs, label, expr.span,
51625161
DontAllowCapturingSelf) {
51635162
None =>
51645163
self.resolve_error(expr.span,
51655164
fmt!("use of undeclared label \
51665165
`%s`",
5167-
self.session.str_of(
5168-
label))),
5166+
interner_get(label))),
51695167
Some(DlDef(def @ DefLabel(_))) => {
51705168
self.record_def(expr.id, def)
51715169
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use std::vec;
7676
use std::local_data;
7777
use extra::time;
7878
use extra::sort;
79-
use syntax::ast::Ident;
79+
use syntax::ast::Name;
8080
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
8181
use syntax::ast_util::{local_def};
8282
use syntax::attr;
@@ -1189,7 +1189,7 @@ pub fn scope_block(bcx: @mut Block,
11891189

11901190
pub fn loop_scope_block(bcx: @mut Block,
11911191
loop_break: @mut Block,
1192-
loop_label: Option<Ident>,
1192+
loop_label: Option<Name>,
11931193
n: &str,
11941194
opt_node_info: Option<NodeInfo>) -> @mut Block {
11951195
return new_block(bcx.fcx, Some(bcx), Some(@mut ScopeInfo {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::cast;
3838
use std::hashmap::{HashMap};
3939
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
4040
use std::vec;
41-
use syntax::ast::Ident;
41+
use syntax::ast::{Name,Ident};
4242
use syntax::ast_map::{path, path_elt, path_pretty_name};
4343
use syntax::codemap::Span;
4444
use syntax::parse::token;
@@ -463,7 +463,7 @@ pub fn block_cleanups(bcx: @mut Block) -> ~[cleanup] {
463463
pub struct ScopeInfo {
464464
parent: Option<@mut ScopeInfo>,
465465
loop_break: Option<@mut Block>,
466-
loop_label: Option<Ident>,
466+
loop_label: Option<Name>,
467467
// A list of functions that must be run at when leaving this
468468
// block, cleaning up any variables that were introduced in the
469469
// block.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use util::ppaux;
2222
use middle::trans::type_::Type;
2323

2424
use syntax::ast;
25-
use syntax::ast::Ident;
25+
use syntax::ast::Name;
2626
use syntax::ast_util;
2727
use syntax::codemap::Span;
2828

@@ -188,7 +188,7 @@ pub fn trans_while(bcx: @mut Block, cond: @ast::Expr, body: &ast::Block) -> @mut
188188

189189
pub fn trans_loop(bcx:@mut Block,
190190
body: &ast::Block,
191-
opt_label: Option<Ident>)
191+
opt_label: Option<Name>)
192192
-> @mut Block {
193193
let _icx = push_ctxt("trans_loop");
194194
let next_bcx = sub_block(bcx, "next");
@@ -201,7 +201,7 @@ pub fn trans_loop(bcx:@mut Block,
201201
}
202202

203203
pub fn trans_break_cont(bcx: @mut Block,
204-
opt_label: Option<Ident>,
204+
opt_label: Option<Name>,
205205
to_end: bool)
206206
-> @mut Block {
207207
let _icx = push_ctxt("trans_break_cont");
@@ -254,11 +254,11 @@ pub fn trans_break_cont(bcx: @mut Block,
254254
return bcx;
255255
}
256256

257-
pub fn trans_break(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
257+
pub fn trans_break(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
258258
return trans_break_cont(bcx, label_opt, true);
259259
}
260260

261-
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
261+
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
262262
return trans_break_cont(bcx, label_opt, false);
263263
}
264264

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ fn trans_rvalue_stmt_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> @mut Block
617617
return controlflow::trans_while(bcx, cond, body);
618618
}
619619
ast::ExprLoop(ref body, opt_label) => {
620-
return controlflow::trans_loop(bcx, body, opt_label);
620+
// FIXME #6993: map can go away when ast.rs is changed
621+
return controlflow::trans_loop(bcx, body, opt_label.map(|x| x.name));
621622
}
622623
ast::ExprAssign(dst, src) => {
623624
let src_datum = unpack_datum!(

branches/try2/src/librustc/middle/ty.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,8 +4266,7 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
42664266
static tycat_char: int = 2;
42674267
static tycat_int: int = 3;
42684268
static tycat_float: int = 4;
4269-
static tycat_struct: int = 5;
4270-
static tycat_bot: int = 6;
4269+
static tycat_bot: int = 5;
42714270

42724271
static opcat_add: int = 0;
42734272
static opcat_sub: int = 1;
@@ -4310,7 +4309,6 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
43104309
ty_bool => tycat_bool,
43114310
ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int,
43124311
ty_float(_) | ty_infer(FloatVar(_)) => tycat_float,
4313-
ty_tup(_) | ty_enum(_, _) => tycat_struct,
43144312
ty_bot => tycat_bot,
43154313
_ => tycat_other
43164314
}
@@ -4326,8 +4324,7 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
43264324
/*char*/ [f, f, f, f, t, t, f, f],
43274325
/*int*/ [t, t, t, t, t, t, t, f],
43284326
/*float*/ [t, t, t, f, t, t, f, f],
4329-
/*bot*/ [f, f, f, f, f, f, f, f],
4330-
/*struct*/ [t, t, t, t, f, f, t, t]];
4327+
/*bot*/ [t, t, t, t, f, f, t, t]];
43314328

43324329
return tbl[tycat(cx, ty)][opcat(op)];
43334330
}

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl PurityState {
200200

201201
purity => {
202202
let (purity, def) = match blk.rules {
203-
ast::UnsafeBlock => (ast::unsafe_fn, blk.id),
203+
ast::UnsafeBlock(*) => (ast::unsafe_fn, blk.id),
204204
ast::DefaultBlock => (purity, self.def),
205205
};
206206
PurityState{ def: def,

branches/try2/src/librustpkg/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub fn default_context(p: Path) -> BuildContext {
2929
pub fn new_default_context(c: workcache::Context, p: Path) -> BuildContext {
3030
BuildContext {
3131
context: Context {
32+
cfgs: ~[],
33+
rustc_flags: RustcFlags::default(),
3234
use_rust_path_hack: false,
3335
sysroot: p
3436
},
@@ -44,7 +46,6 @@ fn binary_is_fresh(path: &str, in_hash: &str) -> bool {
4446
in_hash == digest_only_date(&Path(path))
4547
}
4648

47-
4849
pub fn new_workcache_context(p: &Path) -> workcache::Context {
4950
let db_file = p.push("rustpkg_db.json"); // ??? probably wrong
5051
debug!("Workcache database file: %s", db_file.to_str());

0 commit comments

Comments
 (0)