Skip to content

Commit c100dc0

Browse files
committed
---
yaml --- r: 140418 b: refs/heads/try2 c: 28ab152 h: refs/heads/master v: v3
1 parent 1855361 commit c100dc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1273
-970
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: 436657b5f04a6d7504cfc00224c26910569c67eb
8+
refs/heads/try2: 28ab152832450a69d36c027f3a7177faf8811f7c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ An example of `use` declarations:
802802

803803
~~~~
804804
use core::float::sin;
805-
use core::str::{slice, to_upper};
805+
use core::str::{slice, contains};
806806
use core::option::Some;
807807
808808
fn main() {
@@ -813,8 +813,8 @@ fn main() {
813813
info!(Some(1.0));
814814
815815
// Equivalent to
816-
// 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));'
817-
info!(to_upper(slice("foo", 0, 1)));
816+
// 'info!(core::str::contains(core::str::slice("foo", 0, 1), "oo"));'
817+
info!(contains(slice("foo", 0, 1), "oo"));
818818
}
819819
~~~~
820820

branches/try2/src/compiletest/errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
5050
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
5151
let start_kind = idx;
5252
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
53-
let kind = str::to_lower(str::slice(line, start_kind, idx).to_owned());
53+
54+
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
55+
// to_ascii_consume and to_str_consume to not do a unnecessary copy.
56+
let kind = str::slice(line, start_kind, idx);
57+
let kind = kind.to_ascii().to_lower().to_str_ascii();
5458

5559
// Extract msg:
5660
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }

branches/try2/src/libcore/char.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ pub fn is_alphanumeric(c: char) -> bool {
100100
unicode::general_category::No(c);
101101
}
102102

103-
/// Indicates whether the character is an ASCII character
104-
#[inline(always)]
105-
pub fn is_ascii(c: char) -> bool {
106-
c - ('\x7F' & c) == '\x00'
107-
}
108-
109103
/// Indicates whether the character is numeric (Nd, Nl, or No)
110104
#[inline(always)]
111105
pub fn is_digit(c: char) -> bool {
@@ -116,7 +110,7 @@ pub fn is_digit(c: char) -> bool {
116110

117111
/**
118112
* Checks if a character parses as a numeric digit in the given radix.
119-
* Compared to `is_digit()`, this function only recognizes the ascii
113+
* Compared to `is_digit()`, this function only recognizes the
120114
* characters `0-9`, `a-z` and `A-Z`.
121115
*
122116
* Returns `true` if `c` is a valid digit under `radix`, and `false`
@@ -163,7 +157,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
163157
}
164158

165159
/**
166-
* Converts a number to the ascii character representing it.
160+
* Converts a number to the character representing it.
167161
*
168162
* Returns `Some(char)` if `num` represents one digit under `radix`,
169163
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
@@ -316,12 +310,6 @@ fn test_to_digit() {
316310
assert!(to_digit('$', 36u).is_none());
317311
}
318312
319-
#[test]
320-
fn test_is_ascii() {
321-
assert!(str::all(~"banana", is_ascii));
322-
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
323-
}
324-
325313
#[test]
326314
fn test_is_digit() {
327315
assert!(is_digit('2'));

branches/try2/src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
105105
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
106106
pub use iter::{ExtendedMutableIter};
107107

108-
pub use num::{Num, NumCast};
108+
pub use num::{Num, Signed, Unsigned, Natural, NumCast};
109109
pub use ptr::Ptr;
110110
pub use to_str::ToStr;
111111
pub use clone::Clone;

branches/try2/src/libcore/flate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
8585
#[test]
8686
#[allow(non_implicitly_copyable_typarams)]
8787
fn test_flate_round_trip() {
88-
let r = rand::Rng();
88+
let r = rand::rng();
8989
let mut words = ~[];
9090
for 20.times {
9191
words.push(r.gen_bytes(r.gen_uint_range(1, 10)));

branches/try2/src/libcore/gc.rs

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -231,66 +231,64 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
231231
// the stack.
232232
let mut reached_sentinel = ptr::is_null(sentinel);
233233
for stackwalk::walk_stack |frame| {
234-
unsafe {
235-
let pc = last_ret;
236-
let Segment {segment: next_segment, boundary: boundary} =
237-
find_segment_for_frame(frame.fp, segment);
238-
segment = next_segment;
239-
// Each stack segment is bounded by a morestack frame. The
240-
// morestack frame includes two return addresses, one for
241-
// morestack itself, at the normal offset from the frame
242-
// pointer, and then a second return address for the
243-
// function prologue (which called morestack after
244-
// determining that it had hit the end of the stack).
245-
// Since morestack itself takes two parameters, the offset
246-
// for this second return address is 3 greater than the
247-
// return address for morestack.
248-
let ret_offset = if boundary { 4 } else { 1 };
249-
last_ret = *ptr::offset(frame.fp, ret_offset) as *Word;
250-
251-
if ptr::is_null(pc) {
252-
loop;
253-
}
234+
let pc = last_ret;
235+
let Segment {segment: next_segment, boundary: boundary} =
236+
find_segment_for_frame(frame.fp, segment);
237+
segment = next_segment;
238+
// Each stack segment is bounded by a morestack frame. The
239+
// morestack frame includes two return addresses, one for
240+
// morestack itself, at the normal offset from the frame
241+
// pointer, and then a second return address for the
242+
// function prologue (which called morestack after
243+
// determining that it had hit the end of the stack).
244+
// Since morestack itself takes two parameters, the offset
245+
// for this second return address is 3 greater than the
246+
// return address for morestack.
247+
let ret_offset = if boundary { 4 } else { 1 };
248+
last_ret = *ptr::offset(frame.fp, ret_offset) as *Word;
249+
250+
if ptr::is_null(pc) {
251+
loop;
252+
}
254253

255-
let mut delay_reached_sentinel = reached_sentinel;
256-
let sp = is_safe_point(pc);
257-
match sp {
258-
Some(sp_info) => {
259-
for walk_safe_point(frame.fp, sp_info) |root, tydesc| {
260-
// Skip roots until we see the sentinel.
261-
if !reached_sentinel {
262-
if root == sentinel {
263-
delay_reached_sentinel = true;
264-
}
265-
loop;
254+
let mut delay_reached_sentinel = reached_sentinel;
255+
let sp = is_safe_point(pc);
256+
match sp {
257+
Some(sp_info) => {
258+
for walk_safe_point(frame.fp, sp_info) |root, tydesc| {
259+
// Skip roots until we see the sentinel.
260+
if !reached_sentinel {
261+
if root == sentinel {
262+
delay_reached_sentinel = true;
266263
}
264+
loop;
265+
}
267266

268-
// Skip null pointers, which can occur when a
269-
// unique pointer has already been freed.
270-
if ptr::is_null(*root) {
271-
loop;
272-
}
267+
// Skip null pointers, which can occur when a
268+
// unique pointer has already been freed.
269+
if ptr::is_null(*root) {
270+
loop;
271+
}
273272

274-
if ptr::is_null(tydesc) {
275-
// Root is a generic box.
276-
let refcount = **root;
277-
if mem | task_local_heap != 0 && refcount != -1 {
278-
if !visitor(root, tydesc) { return; }
279-
} else if mem | exchange_heap != 0 && refcount == -1 {
280-
if !visitor(root, tydesc) { return; }
281-
}
282-
} else {
283-
// Root is a non-immediate.
284-
if mem | stack != 0 {
285-
if !visitor(root, tydesc) { return; }
286-
}
273+
if ptr::is_null(tydesc) {
274+
// Root is a generic box.
275+
let refcount = **root;
276+
if mem | task_local_heap != 0 && refcount != -1 {
277+
if !visitor(root, tydesc) { return; }
278+
} else if mem | exchange_heap != 0 && refcount == -1 {
279+
if !visitor(root, tydesc) { return; }
280+
}
281+
} else {
282+
// Root is a non-immediate.
283+
if mem | stack != 0 {
284+
if !visitor(root, tydesc) { return; }
287285
}
288286
}
289-
}
290-
None => ()
291287
}
292-
reached_sentinel = delay_reached_sentinel;
288+
}
289+
None => ()
293290
}
291+
reached_sentinel = delay_reached_sentinel;
294292
}
295293
}
296294

branches/try2/src/libcore/hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint {
5656
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
5757
initial_capacity: uint) -> HashMap<K, V> {
5858
let r = rand::task_rng();
59-
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
59+
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
6060
initial_capacity)
6161
}
6262

branches/try2/src/libcore/num/f32.rs

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Operations and constants for `f32`
1212
1313
use num::strconv;
14+
use num::Signed;
1415
use num;
1516
use option::Option;
1617
use from_str;
@@ -163,38 +164,6 @@ pub fn gt(x: f32, y: f32) -> bool { return x > y; }
163164
// FIXME (#1999): replace the predicates below with llvm intrinsics or
164165
// calls to the libmath macros in the rust runtime for performance.
165166

166-
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
167-
#[inline(always)]
168-
pub fn is_positive(x: f32) -> bool {
169-
x > 0.0f32 || (1.0f32/x) == infinity
170-
}
171-
172-
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
173-
#[inline(always)]
174-
pub fn is_negative(x: f32) -> bool {
175-
x < 0.0f32 || (1.0f32/x) == neg_infinity
176-
}
177-
178-
/**
179-
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
180-
*
181-
* This is the same as `f32::is_negative`.
182-
*/
183-
#[inline(always)]
184-
pub fn is_nonpositive(x: f32) -> bool {
185-
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
186-
}
187-
188-
/**
189-
* Returns true if `x` is a positive number, including +0.0f320 and +Infinity
190-
*
191-
* This is the same as `f32::is_positive`.)
192-
*/
193-
#[inline(always)]
194-
pub fn is_nonnegative(x: f32) -> bool {
195-
return x > 0.0f32 || (1.0f32/x) == infinity;
196-
}
197-
198167
/// Returns true if `x` is a zero number (positive or negative zero)
199168
#[inline(always)]
200169
pub fn is_zero(x: f32) -> bool {
@@ -259,11 +228,6 @@ pub mod consts {
259228
pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32;
260229
}
261230

262-
#[inline(always)]
263-
pub fn signbit(x: f32) -> int {
264-
if is_negative(x) { return 1; } else { return 0; }
265-
}
266-
267231
#[inline(always)]
268232
pub fn logarithm(n: f32, b: f32) -> f32 {
269233
return log2(n) / log2(b);
@@ -351,15 +315,41 @@ impl Neg<f32> for f32 {
351315
fn neg(&self) -> f32 { -*self }
352316
}
353317

318+
impl Signed for f32 {
319+
/// Computes the absolute value. Returns `NaN` if the number is `NaN`.
320+
#[inline(always)]
321+
fn abs(&self) -> f32 { abs(*self) }
322+
323+
/**
324+
* # Returns
325+
*
326+
* - `1.0` if the number is positive, `+0.0` or `infinity`
327+
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
328+
* - `NaN` if the number is `NaN`
329+
*/
330+
#[inline(always)]
331+
fn signum(&self) -> f32 {
332+
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
333+
}
334+
335+
/// Returns `true` if the number is positive, including `+0.0` and `infinity`
336+
#[inline(always)]
337+
fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == infinity }
338+
339+
/// Returns `true` if the number is negative, including `-0.0` and `neg_infinity`
340+
#[inline(always)]
341+
fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == neg_infinity }
342+
}
343+
354344
impl num::Round for f32 {
355345
#[inline(always)]
356346
fn round(&self, mode: num::RoundMode) -> f32 {
357347
match mode {
358348
num::RoundDown => floor(*self),
359349
num::RoundUp => ceil(*self),
360-
num::RoundToZero if is_negative(*self) => ceil(*self),
350+
num::RoundToZero if self.is_negative() => ceil(*self),
361351
num::RoundToZero => floor(*self),
362-
num::RoundFromZero if is_negative(*self) => floor(*self),
352+
num::RoundFromZero if self.is_negative() => floor(*self),
363353
num::RoundFromZero => ceil(*self)
364354
}
365355
}
@@ -370,7 +360,7 @@ impl num::Round for f32 {
370360
fn ceil(&self) -> f32 { ceil(*self) }
371361
#[inline(always)]
372362
fn fract(&self) -> f32 {
373-
if is_negative(*self) {
363+
if self.is_negative() {
374364
(*self) - ceil(*self)
375365
} else {
376366
(*self) - floor(*self)
@@ -595,6 +585,50 @@ impl num::FromStrRadix for f32 {
595585
}
596586
}
597587

588+
#[cfg(test)]
589+
mod tests {
590+
use f32::*;
591+
592+
#[test]
593+
pub fn test_signed() {
594+
assert_eq!(infinity.abs(), infinity);
595+
assert_eq!(1f32.abs(), 1f32);
596+
assert_eq!(0f32.abs(), 0f32);
597+
assert_eq!((-0f32).abs(), 0f32);
598+
assert_eq!((-1f32).abs(), 1f32);
599+
assert_eq!(neg_infinity.abs(), infinity);
600+
assert_eq!((1f32/neg_infinity).abs(), 0f32);
601+
assert!(is_NaN(NaN.abs()));
602+
603+
assert_eq!(infinity.signum(), 1f32);
604+
assert_eq!(1f32.signum(), 1f32);
605+
assert_eq!(0f32.signum(), 1f32);
606+
assert_eq!((-0f32).signum(), -1f32);
607+
assert_eq!((-1f32).signum(), -1f32);
608+
assert_eq!(neg_infinity.signum(), -1f32);
609+
assert_eq!((1f32/neg_infinity).signum(), -1f32);
610+
assert!(is_NaN(NaN.signum()));
611+
612+
assert!(infinity.is_positive());
613+
assert!(1f32.is_positive());
614+
assert!(0f32.is_positive());
615+
assert!(!(-0f32).is_positive());
616+
assert!(!(-1f32).is_positive());
617+
assert!(!neg_infinity.is_positive());
618+
assert!(!(1f32/neg_infinity).is_positive());
619+
assert!(!NaN.is_positive());
620+
621+
assert!(!infinity.is_negative());
622+
assert!(!1f32.is_negative());
623+
assert!(!0f32.is_negative());
624+
assert!((-0f32).is_negative());
625+
assert!((-1f32).is_negative());
626+
assert!(neg_infinity.is_negative());
627+
assert!((1f32/neg_infinity).is_negative());
628+
assert!(!NaN.is_negative());
629+
}
630+
}
631+
598632
//
599633
// Local Variables:
600634
// mode: rust

0 commit comments

Comments
 (0)