Skip to content

Commit f0481b5

Browse files
committed
---
yaml --- r: 103479 b: refs/heads/auto c: 19fadf6 h: refs/heads/master i: 103477: 8dee514 103475: 8767486 103471: 370d3be v: v3
1 parent 90663cc commit f0481b5

File tree

17 files changed

+264
-58
lines changed

17 files changed

+264
-58
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 21454452b2f796268bef01764230ec09aa3a6d8e
16+
refs/heads/auto: 19fadf6567859bd46d3235c29d61917efc0e0685
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libnum/bigint.rs

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use Integer;
2121
use std::cmp;
2222
use std::fmt;
2323
use std::from_str::FromStr;
24+
use std::num::CheckedDiv;
2425
use std::num::{Bitwise, ToPrimitive, FromPrimitive};
2526
use std::num::{Zero, One, ToStrRadix, FromStrRadix};
2627
use std::rand::Rng;
@@ -338,6 +339,40 @@ impl Neg<BigUint> for BigUint {
338339
fn neg(&self) -> BigUint { fail!() }
339340
}
340341

342+
impl CheckedAdd for BigUint {
343+
#[inline]
344+
fn checked_add(&self, v: &BigUint) -> Option<BigUint> {
345+
return Some(self.add(v));
346+
}
347+
}
348+
349+
impl CheckedSub for BigUint {
350+
#[inline]
351+
fn checked_sub(&self, v: &BigUint) -> Option<BigUint> {
352+
if *self < *v {
353+
return None;
354+
}
355+
return Some(self.sub(v));
356+
}
357+
}
358+
359+
impl CheckedMul for BigUint {
360+
#[inline]
361+
fn checked_mul(&self, v: &BigUint) -> Option<BigUint> {
362+
return Some(self.mul(v));
363+
}
364+
}
365+
366+
impl CheckedDiv for BigUint {
367+
#[inline]
368+
fn checked_div(&self, v: &BigUint) -> Option<BigUint> {
369+
if v.is_zero() {
370+
return None;
371+
}
372+
return Some(self.div(v));
373+
}
374+
}
375+
341376
impl Integer for BigUint {
342377
#[inline]
343378
fn div_rem(&self, other: &BigUint) -> (BigUint, BigUint) {
@@ -1053,6 +1088,38 @@ impl Neg<BigInt> for BigInt {
10531088
}
10541089
}
10551090

1091+
impl CheckedAdd for BigInt {
1092+
#[inline]
1093+
fn checked_add(&self, v: &BigInt) -> Option<BigInt> {
1094+
return Some(self.add(v));
1095+
}
1096+
}
1097+
1098+
impl CheckedSub for BigInt {
1099+
#[inline]
1100+
fn checked_sub(&self, v: &BigInt) -> Option<BigInt> {
1101+
return Some(self.sub(v));
1102+
}
1103+
}
1104+
1105+
impl CheckedMul for BigInt {
1106+
#[inline]
1107+
fn checked_mul(&self, v: &BigInt) -> Option<BigInt> {
1108+
return Some(self.mul(v));
1109+
}
1110+
}
1111+
1112+
impl CheckedDiv for BigInt {
1113+
#[inline]
1114+
fn checked_div(&self, v: &BigInt) -> Option<BigInt> {
1115+
if v.is_zero() {
1116+
return None;
1117+
}
1118+
return Some(self.div(v));
1119+
}
1120+
}
1121+
1122+
10561123
impl Integer for BigInt {
10571124
#[inline]
10581125
fn div_rem(&self, other: &BigInt) -> (BigInt, BigInt) {
@@ -1402,6 +1469,7 @@ mod biguint_tests {
14021469
use std::i64;
14031470
use std::num::{Zero, One, FromStrRadix, ToStrRadix};
14041471
use std::num::{ToPrimitive, FromPrimitive};
1472+
use std::num::CheckedDiv;
14051473
use std::rand::{task_rng};
14061474
use std::str;
14071475
use std::u64;
@@ -1822,6 +1890,82 @@ mod biguint_tests {
18221890
}
18231891
}
18241892

1893+
#[test]
1894+
fn test_checked_add() {
1895+
for elm in sum_triples.iter() {
1896+
let (aVec, bVec, cVec) = *elm;
1897+
let a = BigUint::from_slice(aVec);
1898+
let b = BigUint::from_slice(bVec);
1899+
let c = BigUint::from_slice(cVec);
1900+
1901+
assert!(a.checked_add(&b).unwrap() == c);
1902+
assert!(b.checked_add(&a).unwrap() == c);
1903+
}
1904+
}
1905+
1906+
#[test]
1907+
fn test_checked_sub() {
1908+
for elm in sum_triples.iter() {
1909+
let (aVec, bVec, cVec) = *elm;
1910+
let a = BigUint::from_slice(aVec);
1911+
let b = BigUint::from_slice(bVec);
1912+
let c = BigUint::from_slice(cVec);
1913+
1914+
assert!(c.checked_sub(&a).unwrap() == b);
1915+
assert!(c.checked_sub(&b).unwrap() == a);
1916+
1917+
if a > c {
1918+
assert!(a.checked_sub(&c).is_none());
1919+
}
1920+
if b > c {
1921+
assert!(b.checked_sub(&c).is_none());
1922+
}
1923+
}
1924+
}
1925+
1926+
#[test]
1927+
fn test_checked_mul() {
1928+
for elm in mul_triples.iter() {
1929+
let (aVec, bVec, cVec) = *elm;
1930+
let a = BigUint::from_slice(aVec);
1931+
let b = BigUint::from_slice(bVec);
1932+
let c = BigUint::from_slice(cVec);
1933+
1934+
assert!(a.checked_mul(&b).unwrap() == c);
1935+
assert!(b.checked_mul(&a).unwrap() == c);
1936+
}
1937+
1938+
for elm in div_rem_quadruples.iter() {
1939+
let (aVec, bVec, cVec, dVec) = *elm;
1940+
let a = BigUint::from_slice(aVec);
1941+
let b = BigUint::from_slice(bVec);
1942+
let c = BigUint::from_slice(cVec);
1943+
let d = BigUint::from_slice(dVec);
1944+
1945+
assert!(a == b.checked_mul(&c).unwrap() + d);
1946+
assert!(a == c.checked_mul(&b).unwrap() + d);
1947+
}
1948+
}
1949+
1950+
#[test]
1951+
fn test_checked_div() {
1952+
for elm in mul_triples.iter() {
1953+
let (aVec, bVec, cVec) = *elm;
1954+
let a = BigUint::from_slice(aVec);
1955+
let b = BigUint::from_slice(bVec);
1956+
let c = BigUint::from_slice(cVec);
1957+
1958+
if !a.is_zero() {
1959+
assert!(c.checked_div(&a).unwrap() == b);
1960+
}
1961+
if !b.is_zero() {
1962+
assert!(c.checked_div(&b).unwrap() == a);
1963+
}
1964+
1965+
assert!(c.checked_div(&Zero::zero()).is_none());
1966+
}
1967+
}
1968+
18251969
#[test]
18261970
fn test_gcd() {
18271971
fn check(a: uint, b: uint, c: uint) {
@@ -2058,6 +2202,7 @@ mod bigint_tests {
20582202

20592203
use std::cmp::{Less, Equal, Greater};
20602204
use std::i64;
2205+
use std::num::CheckedDiv;
20612206
use std::num::{Zero, One, FromStrRadix, ToStrRadix};
20622207
use std::num::{ToPrimitive, FromPrimitive};
20632208
use std::rand::{task_rng};
@@ -2399,6 +2544,94 @@ mod bigint_tests {
23992544
}
24002545
}
24012546

2547+
#[test]
2548+
fn test_checked_add() {
2549+
for elm in sum_triples.iter() {
2550+
let (aVec, bVec, cVec) = *elm;
2551+
let a = BigInt::from_slice(Plus, aVec);
2552+
let b = BigInt::from_slice(Plus, bVec);
2553+
let c = BigInt::from_slice(Plus, cVec);
2554+
2555+
assert!(a.checked_add(&b).unwrap() == c);
2556+
assert!(b.checked_add(&a).unwrap() == c);
2557+
assert!(c.checked_add(&(-a)).unwrap() == b);
2558+
assert!(c.checked_add(&(-b)).unwrap() == a);
2559+
assert!(a.checked_add(&(-c)).unwrap() == (-b));
2560+
assert!(b.checked_add(&(-c)).unwrap() == (-a));
2561+
assert!((-a).checked_add(&(-b)).unwrap() == (-c))
2562+
assert!(a.checked_add(&(-a)).unwrap() == Zero::zero());
2563+
}
2564+
}
2565+
2566+
#[test]
2567+
fn test_checked_sub() {
2568+
for elm in sum_triples.iter() {
2569+
let (aVec, bVec, cVec) = *elm;
2570+
let a = BigInt::from_slice(Plus, aVec);
2571+
let b = BigInt::from_slice(Plus, bVec);
2572+
let c = BigInt::from_slice(Plus, cVec);
2573+
2574+
assert!(c.checked_sub(&a).unwrap() == b);
2575+
assert!(c.checked_sub(&b).unwrap() == a);
2576+
assert!((-b).checked_sub(&a).unwrap() == (-c))
2577+
assert!((-a).checked_sub(&b).unwrap() == (-c))
2578+
assert!(b.checked_sub(&(-a)).unwrap() == c);
2579+
assert!(a.checked_sub(&(-b)).unwrap() == c);
2580+
assert!((-c).checked_sub(&(-a)).unwrap() == (-b));
2581+
assert!(a.checked_sub(&a).unwrap() == Zero::zero());
2582+
}
2583+
}
2584+
2585+
#[test]
2586+
fn test_checked_mul() {
2587+
for elm in mul_triples.iter() {
2588+
let (aVec, bVec, cVec) = *elm;
2589+
let a = BigInt::from_slice(Plus, aVec);
2590+
let b = BigInt::from_slice(Plus, bVec);
2591+
let c = BigInt::from_slice(Plus, cVec);
2592+
2593+
assert!(a.checked_mul(&b).unwrap() == c);
2594+
assert!(b.checked_mul(&a).unwrap() == c);
2595+
2596+
assert!((-a).checked_mul(&b).unwrap() == -c);
2597+
assert!((-b).checked_mul(&a).unwrap() == -c);
2598+
}
2599+
2600+
for elm in div_rem_quadruples.iter() {
2601+
let (aVec, bVec, cVec, dVec) = *elm;
2602+
let a = BigInt::from_slice(Plus, aVec);
2603+
let b = BigInt::from_slice(Plus, bVec);
2604+
let c = BigInt::from_slice(Plus, cVec);
2605+
let d = BigInt::from_slice(Plus, dVec);
2606+
2607+
assert!(a == b.checked_mul(&c).unwrap() + d);
2608+
assert!(a == c.checked_mul(&b).unwrap() + d);
2609+
}
2610+
}
2611+
#[test]
2612+
fn test_checked_div() {
2613+
for elm in mul_triples.iter() {
2614+
let (aVec, bVec, cVec) = *elm;
2615+
let a = BigInt::from_slice(Plus, aVec);
2616+
let b = BigInt::from_slice(Plus, bVec);
2617+
let c = BigInt::from_slice(Plus, cVec);
2618+
2619+
if !a.is_zero() {
2620+
assert!(c.checked_div(&a).unwrap() == b);
2621+
assert!((-c).checked_div(&(-a)).unwrap() == b);
2622+
assert!((-c).checked_div(&a).unwrap() == -b);
2623+
}
2624+
if !b.is_zero() {
2625+
assert!(c.checked_div(&b).unwrap() == a);
2626+
assert!((-c).checked_div(&(-b)).unwrap() == a);
2627+
assert!((-c).checked_div(&b).unwrap() == -a);
2628+
}
2629+
2630+
assert!(c.checked_div(&Zero::zero()).is_none());
2631+
assert!((-c).checked_div(&Zero::zero()).is_none());
2632+
}
2633+
}
2634+
24022635
#[test]
24032636
fn test_gcd() {
24042637
fn check(a: int, b: int, c: int) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl CFGBuilder {
300300
guard_exit = self.opt_expr(arm.guard, guard_exit); // 2
301301
let pats_exit = self.pats_any(arm.pats.as_slice(),
302302
guard_exit); // 3
303-
let body_exit = self.block(arm.body, pats_exit); // 4
303+
let body_exit = self.expr(arm.body, pats_exit); // 4
304304
self.add_contained_edge(body_exit, expr_exit); // 5
305305
}
306306
expr_exit

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
534534
self.walk_pat_alternatives(arm.pats.as_slice(),
535535
body,
536536
loop_scopes);
537-
self.walk_block(arm.body, body, loop_scopes);
537+
self.walk_expr(arm.body, body, loop_scopes);
538538
join_bits(&self.dfcx.oper, body, in_out);
539539
}
540540
}
@@ -915,4 +915,3 @@ fn bit_str(bit: uint) -> ~str {
915915
let lobits = 1 << (bit & 0xFF);
916916
format!("[{}:{}-{:02x}]", bit, byte, lobits)
917917
}
918-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ impl Liveness {
11251125
let mut first_merge = true;
11261126
for arm in arms.iter() {
11271127
let body_succ =
1128-
self.propagate_through_block(arm.body, succ);
1128+
self.propagate_through_expr(arm.body, succ);
11291129
let guard_succ =
11301130
self.propagate_through_opt_expr(arm.guard, body_succ);
11311131
let arm_succ =

branches/auto/src/librustc/middle/moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl VisitContext {
632632
self.consume_expr(*guard);
633633
}
634634

635-
self.consume_block(arm.body);
635+
self.consume_expr(arm.body);
636636
}
637637

638638
pub fn use_pat(&mut self, pat: @Pat) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4248,7 +4248,7 @@ impl Resolver {
42484248
self.check_consistent_bindings(arm);
42494249

42504250
visit::walk_expr_opt(self, arm.guard, ());
4251-
self.resolve_block(arm.body);
4251+
self.resolve_expr(arm.body);
42524252

42534253
let mut value_ribs = self.value_ribs.borrow_mut();
42544254
value_ribs.get().pop();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
19391939
let cleanup_scope = fcx.push_custom_cleanup_scope();
19401940
bcx = insert_lllocals(bcx, arm_data.bindings_map,
19411941
cleanup::CustomScope(cleanup_scope));
1942-
bcx = controlflow::trans_block(bcx, arm_data.arm.body, dest);
1942+
bcx = expr::trans_into(bcx, arm_data.arm.body, dest);
19431943
bcx = fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
19441944
arm_cxs.push(bcx);
19451945
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ fn populate_scope_map(cx: &CrateContext,
26652665
walk_expr(cx, *guard_exp, scope_stack, scope_map)
26662666
}
26672667

2668-
walk_block(cx, arm_ref.body, scope_stack, scope_map);
2668+
walk_expr(cx, arm_ref.body, scope_stack, scope_map);
26692669
})
26702670
}
26712671
}

branches/auto/src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const};
1414
use middle::ty;
1515
use middle::typeck::check::demand;
16-
use middle::typeck::check::{check_block, check_expr_has_type, FnCtxt};
16+
use middle::typeck::check::{check_expr, check_expr_has_type, FnCtxt};
1717
use middle::typeck::check::{instantiate_path, lookup_def};
1818
use middle::typeck::check::{structure_of, valid_range_bounds};
1919
use middle::typeck::infer;
@@ -74,7 +74,7 @@ pub fn check_match(fcx: @FnCtxt,
7474
},
7575
None => ()
7676
}
77-
check_block(fcx, arm.body);
77+
check_expr(fcx, arm.body);
7878
let bty = fcx.node_ty(arm.body.id);
7979
saw_err = saw_err || ty::type_is_error(bty);
8080
if guard_err {

branches/auto/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub enum Decl_ {
491491
pub struct Arm {
492492
pats: Vec<@Pat> ,
493493
guard: Option<@Expr>,
494-
body: P<Block>,
494+
body: @Expr,
495495
}
496496

497497
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]

branches/auto/src/libsyntax/ext/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
679679
ast::Arm {
680680
pats: pats,
681681
guard: None,
682-
body: self.block_expr(expr)
682+
body: expr
683683
}
684684
}
685685

0 commit comments

Comments
 (0)