Skip to content

Commit 195c73b

Browse files
committed
---
yaml --- r: 55709 b: refs/heads/master c: f0afe23 h: refs/heads/master i: 55707: 1b6d2d3 v: v3
1 parent ee41ce1 commit 195c73b

33 files changed

+344
-289
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 51a68eb9b14f5d6f8ac358eed8c11e8567d5f87b
2+
refs/heads/master: f0afe23dce9699f2776907d2adde126baea58f30
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

trunk/src/libcore/at_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod rustrt {
4141
pub fn capacity<T>(v: @[T]) -> uint {
4242
unsafe {
4343
let repr: **raw::VecRepr =
44-
::cast::transmute(addr_of(&v));
44+
::cast::reinterpret_cast(&addr_of(&v));
4545
(**repr).unboxed.alloc / sys::size_of::<T>()
4646
}
4747
}
@@ -208,7 +208,7 @@ pub mod raw {
208208
*/
209209
#[inline(always)]
210210
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
211-
let repr: **mut VecRepr = ::cast::transmute(addr_of(&v));
211+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
212212
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
213213
}
214214

@@ -226,7 +226,7 @@ pub mod raw {
226226

227227
#[inline(always)] // really pretty please
228228
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
229-
let repr: **mut VecRepr = ::cast::transmute(v);
229+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&v);
230230
let fill = (**repr).unboxed.fill;
231231
(**repr).unboxed.fill += sys::size_of::<T>();
232232
let p = addr_of(&((**repr).unboxed.data));
@@ -322,4 +322,4 @@ mod test {
322322
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
323323
assert!(from_slice([@[42]]) == @[@[42]]);
324324
}
325-
}
325+
}

trunk/src/libcore/gc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ pub mod rustrt {
7777
}
7878

7979
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
80-
return cast::transmute(ptr::offset(ptr, count));
80+
return cast::reinterpret_cast(&ptr::offset(ptr, count));
8181
}
8282

8383
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
8484
let align = sys::min_align_of::<*T>();
85-
let ptr: uint = cast::transmute(ptr);
85+
let ptr: uint = cast::reinterpret_cast(&ptr);
8686
let ptr = (ptr + (align - 1)) & -align;
87-
return cast::transmute(ptr);
87+
return cast::reinterpret_cast(&ptr);
8888
}
8989

9090
unsafe fn get_safe_point_count() -> uint {
@@ -129,8 +129,8 @@ type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
129129
// Walks the list of roots for the given safe point, and calls visitor
130130
// on each root.
131131
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
132-
let fp_bytes: *u8 = cast::transmute(fp);
133-
let sp_meta: *u32 = cast::transmute(sp.sp_meta);
132+
let fp_bytes: *u8 = cast::reinterpret_cast(&fp);
133+
let sp_meta: *u32 = cast::reinterpret_cast(&sp.sp_meta);
134134

135135
let num_stack_roots = *sp_meta as uint;
136136
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
@@ -171,9 +171,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
171171

172172
// Is fp contained in segment?
173173
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
174-
let begin: Word = cast::transmute(segment);
175-
let end: Word = cast::transmute((*segment).end);
176-
let frame: Word = cast::transmute(fp);
174+
let begin: Word = cast::reinterpret_cast(&segment);
175+
let end: Word = cast::reinterpret_cast(&(*segment).end);
176+
let frame: Word = cast::reinterpret_cast(&fp);
177177

178178
return begin <= frame && frame <= end;
179179
}
@@ -339,7 +339,7 @@ pub fn cleanup_stack_for_failure() {
339339
// own stack roots on the stack anyway.
340340
let sentinel_box = ~0;
341341
let sentinel: **Word = if expect_sentinel() {
342-
cast::transmute(ptr::addr_of(&sentinel_box))
342+
cast::reinterpret_cast(&ptr::addr_of(&sentinel_box))
343343
} else {
344344
ptr::null()
345345
};

trunk/src/libcore/iterator.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub trait IteratorUtil<A> {
3939
fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, Self>;
4040
fn skip(self, n: uint) -> SkipIterator<Self>;
4141
fn take(self, n: uint) -> TakeIterator<Self>;
42+
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
43+
-> ScanIterator<'r, A, B, Self, St>;
4244
fn advance(&mut self, f: &fn(A) -> bool);
4345
}
4446

@@ -93,6 +95,12 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
9395
TakeIterator{iter: self, n: n}
9496
}
9597

98+
#[inline(always)]
99+
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
100+
-> ScanIterator<'r, A, B, T, St> {
101+
ScanIterator{iter: self, f: f, state: initial_state}
102+
}
103+
96104
/// A shim implementing the `for` loop iteration protocol for iterator objects
97105
#[inline]
98106
fn advance(&mut self, f: &fn(A) -> bool) {
@@ -306,12 +314,13 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
306314

307315
pub struct UnfoldrIterator<'self, A, St> {
308316
priv f: &'self fn(&mut St) -> Option<A>,
309-
priv state: St
317+
state: St
310318
}
311319

312320
pub impl<'self, A, St> UnfoldrIterator<'self, A, St> {
313321
#[inline]
314-
fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St) -> UnfoldrIterator<'self, A, St> {
322+
fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
323+
-> UnfoldrIterator<'self, A, St> {
315324
UnfoldrIterator {
316325
f: f,
317326
state: initial_state
@@ -326,6 +335,19 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
326335
}
327336
}
328337

338+
pub struct ScanIterator<'self, A, B, T, St> {
339+
priv iter: T,
340+
priv f: &'self fn(&mut St, A) -> Option<B>,
341+
state: St
342+
}
343+
344+
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
345+
#[inline]
346+
fn next(&mut self) -> Option<B> {
347+
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
348+
}
349+
}
350+
329351
#[cfg(test)]
330352
mod tests {
331353
use super::*;
@@ -406,6 +428,25 @@ mod tests {
406428
assert_eq!(i, ys.len());
407429
}
408430

431+
#[test]
432+
fn test_iterator_scan() {
433+
// test the type inference
434+
fn add(old: &mut int, new: &uint) -> Option<float> {
435+
*old += *new as int;
436+
Some(*old as float)
437+
}
438+
let xs = [0u, 1, 2, 3, 4];
439+
let ys = [0f, 1f, 3f, 6f, 10f];
440+
441+
let mut it = xs.iter().scan(0, add);
442+
let mut i = 0;
443+
for it.advance |x| {
444+
assert_eq!(x, ys[i]);
445+
i += 1;
446+
}
447+
assert_eq!(i, ys.len());
448+
}
449+
409450
#[test]
410451
fn test_unfoldr() {
411452
fn count(st: &mut uint) -> Option<uint> {

trunk/src/libcore/num/f32.rs

Lines changed: 80 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010

1111
//! Operations and constants for `f32`
1212
13-
use cmath;
14-
use libc::{c_float, c_int};
1513
use num::strconv;
1614
use num;
1715
use option::Option;
18-
use unstable::intrinsics::floorf32;
1916
use from_str;
2017
use to_str;
2118

@@ -24,79 +21,93 @@ use to_str;
2421

2522
pub use cmath::c_float_targ_consts::*;
2623

24+
// An inner module is required to get the #[inline(always)] attribute on the
25+
// functions.
26+
pub use self::delegated::*;
27+
2728
macro_rules! delegate(
2829
(
29-
fn $name:ident(
30-
$(
31-
$arg:ident : $arg_ty:ty
32-
),*
33-
) -> $rv:ty = $bound_name:path
30+
$(
31+
fn $name:ident(
32+
$(
33+
$arg:ident : $arg_ty:ty
34+
),*
35+
) -> $rv:ty = $bound_name:path
36+
),*
3437
) => (
35-
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
36-
unsafe {
37-
$bound_name($( $arg ),*)
38-
}
38+
mod delegated {
39+
use cmath::c_float_utils;
40+
use libc::{c_float, c_int};
41+
use unstable::intrinsics;
42+
43+
$(
44+
#[inline(always)]
45+
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
46+
unsafe {
47+
$bound_name($( $arg ),*)
48+
}
49+
}
50+
)*
3951
}
4052
)
4153
)
4254

43-
delegate!(fn acos(n: c_float) -> c_float = cmath::c_float_utils::acos)
44-
delegate!(fn asin(n: c_float) -> c_float = cmath::c_float_utils::asin)
45-
delegate!(fn atan(n: c_float) -> c_float = cmath::c_float_utils::atan)
46-
delegate!(fn atan2(a: c_float, b: c_float) -> c_float =
47-
cmath::c_float_utils::atan2)
48-
delegate!(fn cbrt(n: c_float) -> c_float = cmath::c_float_utils::cbrt)
49-
delegate!(fn ceil(n: c_float) -> c_float = cmath::c_float_utils::ceil)
50-
delegate!(fn copysign(x: c_float, y: c_float) -> c_float =
51-
cmath::c_float_utils::copysign)
52-
delegate!(fn cos(n: c_float) -> c_float = cmath::c_float_utils::cos)
53-
delegate!(fn cosh(n: c_float) -> c_float = cmath::c_float_utils::cosh)
54-
delegate!(fn erf(n: c_float) -> c_float = cmath::c_float_utils::erf)
55-
delegate!(fn erfc(n: c_float) -> c_float = cmath::c_float_utils::erfc)
56-
delegate!(fn exp(n: c_float) -> c_float = cmath::c_float_utils::exp)
57-
delegate!(fn expm1(n: c_float) -> c_float = cmath::c_float_utils::expm1)
58-
delegate!(fn exp2(n: c_float) -> c_float = cmath::c_float_utils::exp2)
59-
delegate!(fn abs(n: c_float) -> c_float = cmath::c_float_utils::abs)
60-
delegate!(fn abs_sub(a: c_float, b: c_float) -> c_float =
61-
cmath::c_float_utils::abs_sub)
62-
delegate!(fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float =
63-
cmath::c_float_utils::mul_add)
64-
delegate!(fn fmax(a: c_float, b: c_float) -> c_float =
65-
cmath::c_float_utils::fmax)
66-
delegate!(fn fmin(a: c_float, b: c_float) -> c_float =
67-
cmath::c_float_utils::fmin)
68-
delegate!(fn nextafter(x: c_float, y: c_float) -> c_float =
69-
cmath::c_float_utils::nextafter)
70-
delegate!(fn frexp(n: c_float, value: &mut c_int) -> c_float =
71-
cmath::c_float_utils::frexp)
72-
delegate!(fn hypot(x: c_float, y: c_float) -> c_float =
73-
cmath::c_float_utils::hypot)
74-
delegate!(fn ldexp(x: c_float, n: c_int) -> c_float =
75-
cmath::c_float_utils::ldexp)
76-
delegate!(fn lgamma(n: c_float, sign: &mut c_int) -> c_float =
77-
cmath::c_float_utils::lgamma)
78-
delegate!(fn ln(n: c_float) -> c_float = cmath::c_float_utils::ln)
79-
delegate!(fn log_radix(n: c_float) -> c_float =
80-
cmath::c_float_utils::log_radix)
81-
delegate!(fn ln1p(n: c_float) -> c_float = cmath::c_float_utils::ln1p)
82-
delegate!(fn log10(n: c_float) -> c_float = cmath::c_float_utils::log10)
83-
delegate!(fn log2(n: c_float) -> c_float = cmath::c_float_utils::log2)
84-
delegate!(fn ilog_radix(n: c_float) -> c_int =
85-
cmath::c_float_utils::ilog_radix)
86-
delegate!(fn modf(n: c_float, iptr: &mut c_float) -> c_float =
87-
cmath::c_float_utils::modf)
88-
delegate!(fn pow(n: c_float, e: c_float) -> c_float =
89-
cmath::c_float_utils::pow)
90-
delegate!(fn round(n: c_float) -> c_float = cmath::c_float_utils::round)
91-
delegate!(fn ldexp_radix(n: c_float, i: c_int) -> c_float =
92-
cmath::c_float_utils::ldexp_radix)
93-
delegate!(fn sin(n: c_float) -> c_float = cmath::c_float_utils::sin)
94-
delegate!(fn sinh(n: c_float) -> c_float = cmath::c_float_utils::sinh)
95-
delegate!(fn sqrt(n: c_float) -> c_float = cmath::c_float_utils::sqrt)
96-
delegate!(fn tan(n: c_float) -> c_float = cmath::c_float_utils::tan)
97-
delegate!(fn tanh(n: c_float) -> c_float = cmath::c_float_utils::tanh)
98-
delegate!(fn tgamma(n: c_float) -> c_float = cmath::c_float_utils::tgamma)
99-
delegate!(fn trunc(n: c_float) -> c_float = cmath::c_float_utils::trunc)
55+
delegate!(
56+
// intrinsics
57+
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
58+
fn cos(n: f32) -> f32 = intrinsics::cosf32,
59+
fn exp(n: f32) -> f32 = intrinsics::expf32,
60+
fn exp2(n: f32) -> f32 = intrinsics::exp2f32,
61+
fn floor(x: f32) -> f32 = intrinsics::floorf32,
62+
fn ln(n: f32) -> f32 = intrinsics::logf32,
63+
fn log10(n: f32) -> f32 = intrinsics::log10f32,
64+
fn log2(n: f32) -> f32 = intrinsics::log2f32,
65+
fn mul_add(a: f32, b: f32, c: f32) -> f32 = intrinsics::fmaf32,
66+
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
67+
fn powi(n: f32, e: c_int) -> f32 = intrinsics::powif32,
68+
fn sin(n: f32) -> f32 = intrinsics::sinf32,
69+
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
70+
71+
// LLVM 3.3 required to use intrinsics for these four
72+
fn ceil(n: c_float) -> c_float = c_float_utils::ceil,
73+
fn trunc(n: c_float) -> c_float = c_float_utils::trunc,
74+
/*
75+
fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
76+
fn trunc(n: f32) -> f32 = intrinsics::truncf32,
77+
fn rint(n: f32) -> f32 = intrinsics::rintf32,
78+
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
79+
*/
80+
81+
// cmath
82+
fn acos(n: c_float) -> c_float = c_float_utils::acos,
83+
fn asin(n: c_float) -> c_float = c_float_utils::asin,
84+
fn atan(n: c_float) -> c_float = c_float_utils::atan,
85+
fn atan2(a: c_float, b: c_float) -> c_float = c_float_utils::atan2,
86+
fn cbrt(n: c_float) -> c_float = c_float_utils::cbrt,
87+
fn copysign(x: c_float, y: c_float) -> c_float = c_float_utils::copysign,
88+
fn cosh(n: c_float) -> c_float = c_float_utils::cosh,
89+
fn erf(n: c_float) -> c_float = c_float_utils::erf,
90+
fn erfc(n: c_float) -> c_float = c_float_utils::erfc,
91+
fn expm1(n: c_float) -> c_float = c_float_utils::expm1,
92+
fn abs_sub(a: c_float, b: c_float) -> c_float = c_float_utils::abs_sub,
93+
fn fmax(a: c_float, b: c_float) -> c_float = c_float_utils::fmax,
94+
fn fmin(a: c_float, b: c_float) -> c_float = c_float_utils::fmin,
95+
fn nextafter(x: c_float, y: c_float) -> c_float = c_float_utils::nextafter,
96+
fn frexp(n: c_float, value: &mut c_int) -> c_float = c_float_utils::frexp,
97+
fn hypot(x: c_float, y: c_float) -> c_float = c_float_utils::hypot,
98+
fn ldexp(x: c_float, n: c_int) -> c_float = c_float_utils::ldexp,
99+
fn lgamma(n: c_float, sign: &mut c_int) -> c_float = c_float_utils::lgamma,
100+
fn log_radix(n: c_float) -> c_float = c_float_utils::log_radix,
101+
fn ln1p(n: c_float) -> c_float = c_float_utils::ln1p,
102+
fn ilog_radix(n: c_float) -> c_int = c_float_utils::ilog_radix,
103+
fn modf(n: c_float, iptr: &mut c_float) -> c_float = c_float_utils::modf,
104+
fn round(n: c_float) -> c_float = c_float_utils::round,
105+
fn ldexp_radix(n: c_float, i: c_int) -> c_float = c_float_utils::ldexp_radix,
106+
fn sinh(n: c_float) -> c_float = c_float_utils::sinh,
107+
fn tan(n: c_float) -> c_float = c_float_utils::tan,
108+
fn tanh(n: c_float) -> c_float = c_float_utils::tanh,
109+
fn tgamma(n: c_float) -> c_float = c_float_utils::tgamma)
110+
100111

101112
// These are not defined inside consts:: for consistency with
102113
// the integer types
@@ -143,9 +154,6 @@ pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
143154
#[inline(always)]
144155
pub fn gt(x: f32, y: f32) -> bool { return x > y; }
145156

146-
/// Returns `x` rounded down
147-
#[inline(always)]
148-
pub fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
149157

150158
// FIXME (#1999): replace the predicates below with llvm intrinsics or
151159
// calls to the libmath macros in the rust runtime for performance.

0 commit comments

Comments
 (0)