Skip to content

Commit bfdbfe4

Browse files
committed
---
yaml --- r: 140905 b: refs/heads/try2 c: c2baaa8 h: refs/heads/master i: 140903: 4622018 v: v3
1 parent caa99d6 commit bfdbfe4

File tree

14 files changed

+67
-276
lines changed

14 files changed

+67
-276
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: 77c98f081509733af957af6ed7b0b277e5f57871
8+
refs/heads/try2: c2baaa8d8432c8d7320e928e7ad706f225430bb3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/iter.rs

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ much easier to implement.
4343
#[cfg(not(stage0))] use cmp::Ord;
4444
#[cfg(not(stage0))] use option::{Option, Some, None};
4545
#[cfg(not(stage0))] use vec::OwnedVector;
46-
#[cfg(not(stage0))] use num::{One, Zero};
47-
#[cfg(not(stage0))] use ops::{Add, Mul};
4846

4947
#[cfg(stage0)]
5048
pub trait Times {
@@ -214,81 +212,6 @@ pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
214212
result
215213
}
216214

217-
/**
218-
* Reduce an iterator to an accumulated value.
219-
*
220-
* # Example:
221-
*
222-
* ~~~~
223-
* assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10);
224-
* ~~~~
225-
*/
226-
#[cfg(not(stage0))]
227-
#[inline]
228-
pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T, U)) -> T {
229-
let mut result = start;
230-
for iter |x| {
231-
f(&mut result, x);
232-
}
233-
result
234-
}
235-
236-
/**
237-
* Reduce an iterator to an accumulated value.
238-
*
239-
* `fold_ref` is usable in some generic functions where `fold` is too lenient to type-check, but it
240-
* forces the iterator to yield borrowed pointers.
241-
*
242-
* # Example:
243-
*
244-
* ~~~~
245-
* fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
246-
* fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x))
247-
* }
248-
* ~~~~
249-
*/
250-
#[cfg(not(stage0))]
251-
#[inline]
252-
pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&mut T, &U)) -> T {
253-
let mut result = start;
254-
for iter |x| {
255-
f(&mut result, x);
256-
}
257-
result
258-
}
259-
260-
/**
261-
* Return the sum of the items yielding by an iterator.
262-
*
263-
* # Example:
264-
*
265-
* ~~~~
266-
* let xs: ~[int] = ~[1, 2, 3, 4];
267-
* assert_eq!(do sum |f| { xs.each(f) }, 10);
268-
* ~~~~
269-
*/
270-
#[cfg(not(stage0))]
271-
#[inline(always)]
272-
pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
273-
fold_ref(Zero::zero::<T>(), iter, |a, x| *a = a.add(x))
274-
}
275-
276-
/**
277-
* Return the product of the items yielded by an iterator.
278-
*
279-
* # Example:
280-
*
281-
* ~~~~
282-
* let xs: ~[int] = ~[1, 2, 3, 4];
283-
* assert_eq!(do product |f| { xs.each(f) }, 24);
284-
* ~~~~
285-
*/
286-
#[cfg(not(stage0))]
287-
#[inline(always)]
288-
pub fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
289-
fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x))
290-
}
291-
292215
#[cfg(test)]
293216
mod tests {
294217
use super::*;
@@ -331,33 +254,4 @@ mod tests {
331254
let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
332255
assert_eq!(min(|f| xs.each(f)).unwrap(), &-5);
333256
}
334-
335-
#[test]
336-
fn test_fold() {
337-
assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10);
338-
}
339-
340-
#[test]
341-
fn test_sum() {
342-
let xs: ~[int] = ~[1, 2, 3, 4];
343-
assert_eq!(do sum |f| { xs.each(f) }, 10);
344-
}
345-
346-
#[test]
347-
fn test_empty_sum() {
348-
let xs: ~[int] = ~[];
349-
assert_eq!(do sum |f| { xs.each(f) }, 0);
350-
}
351-
352-
#[test]
353-
fn test_product() {
354-
let xs: ~[int] = ~[1, 2, 3, 4];
355-
assert_eq!(do product |f| { xs.each(f) }, 24);
356-
}
357-
358-
#[test]
359-
fn test_empty_product() {
360-
let xs: ~[int] = ~[];
361-
assert_eq!(do product |f| { xs.each(f) }, 1);
362-
}
363257
}

branches/try2/src/libcore/rt/stack.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ pub impl StackSegment {
3131

3232
/// Point one word beyond the high end of the allocated stack
3333
fn end(&self) -> *uint {
34-
unsafe {
35-
vec::raw::to_ptr(self.buf).offset(self.buf.len()) as *uint
36-
}
34+
vec::raw::to_ptr(self.buf).offset(self.buf.len()) as *uint
3735
}
3836
}
3937

branches/try2/src/libcore/rt/uv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub type Buf = uvll::uv_buf_t;
362362
363363
/// Borrow a slice to a Buf
364364
pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
365-
let data = unsafe { vec::raw::to_ptr(v) };
365+
let data = vec::raw::to_ptr(v);
366366
unsafe { uvll::buf_init(data, v.len()) }
367367
}
368368

branches/try2/src/libcore/vec.rs

Lines changed: 20 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,46 +1445,6 @@ pub fn reverse<T>(v: &mut [T]) {
14451445
}
14461446
}
14471447

1448-
/**
1449-
* Reverse part of a vector in place.
1450-
*
1451-
* Reverse the elements in the vector between `start` and `end - 1`.
1452-
*
1453-
* If either start or end do not represent valid positions in the vector, the
1454-
* vector is returned unchanged.
1455-
*
1456-
* # Arguments
1457-
*
1458-
* * `v` - The mutable vector to be modified
1459-
*
1460-
* * `start` - Index of the first element of the slice
1461-
*
1462-
* * `end` - Index one past the final element to be reversed.
1463-
*
1464-
* # Example
1465-
*
1466-
* Assume a mutable vector `v` contains `[1,2,3,4,5]`. After the call:
1467-
*
1468-
* ~~~
1469-
*
1470-
* reverse_part(v, 1, 4);
1471-
*
1472-
* ~~~
1473-
*
1474-
* `v` now contains `[1,4,3,2,5]`.
1475-
*/
1476-
pub fn reverse_part<T>(v: &mut [T], start: uint, end : uint) {
1477-
let sz = v.len();
1478-
if start >= sz || end > sz { return; }
1479-
let mut i = start;
1480-
let mut j = end - 1;
1481-
while i < j {
1482-
vec::swap(v, i, j);
1483-
i += 1;
1484-
j -= 1;
1485-
}
1486-
}
1487-
14881448
/// Returns a vector with the order of elements reversed
14891449
pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
14901450
let mut rs: ~[T] = ~[];
@@ -1779,49 +1739,29 @@ pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T)
17791739
*
17801740
* The total number of permutations produced is `len(v)!`. If `v` contains
17811741
* repeated elements, then some permutations are repeated.
1782-
*
1783-
* See [Algorithms to generate
1784-
* permutations](http://en.wikipedia.org/wiki/Permutation).
1785-
*
1786-
* # Arguments
1787-
*
1788-
* * `values` - A vector of values from which the permutations are
1789-
* chosen
1790-
*
1791-
* * `fun` - The function to iterate over the combinations
17921742
*/
1793-
pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) -> bool {
1794-
let length = values.len();
1795-
let mut permutation = vec::from_fn(length, |i| values[i]);
1796-
if length <= 1 {
1797-
fun(permutation);
1798-
return true;
1799-
}
1800-
let mut indices = vec::from_fn(length, |i| i);
1801-
loop {
1802-
if !fun(permutation) { return true; }
1803-
// find largest k such that indices[k] < indices[k+1]
1804-
// if no such k exists, all permutations have been generated
1805-
let mut k = length - 2;
1806-
while k > 0 && indices[k] >= indices[k+1] {
1807-
k -= 1;
1808-
}
1809-
if k == 0 && indices[0] > indices[1] { return true; }
1810-
// find largest l such that indices[k] < indices[l]
1811-
// k+1 is guaranteed to be such
1812-
let mut l = length - 1;
1813-
while indices[k] >= indices[l] {
1814-
l -= 1;
1815-
}
1816-
// swap indices[k] and indices[l]; sort indices[k+1..]
1817-
// (they're just reversed)
1818-
vec::swap(indices, k, l);
1819-
reverse_part(indices, k+1, length);
1820-
// fixup permutation based on indices
1821-
for uint::range(k, length) |i| {
1822-
permutation[i] = values[indices[i]];
1743+
#[cfg(not(stage0))]
1744+
pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) -> bool {
1745+
let ln = len(v);
1746+
if ln <= 1 {
1747+
put(v);
1748+
} else {
1749+
// This does not seem like the most efficient implementation. You
1750+
// could make far fewer copies if you put your mind to it.
1751+
let mut i = 0u;
1752+
while i < ln {
1753+
let elt = v[i];
1754+
let mut rest = slice(v, 0u, i).to_vec();
1755+
rest.push_all(const_slice(v, i+1u, ln));
1756+
for each_permutation(rest) |permutation| {
1757+
if !put(append(~[elt], permutation)) {
1758+
return false;
1759+
}
1760+
}
1761+
i += 1u;
18231762
}
18241763
}
1764+
return true;
18251765
}
18261766

18271767
/**
@@ -4790,53 +4730,6 @@ mod tests {
47904730
}
47914731
}
47924732

4793-
#[test]
4794-
fn test_reverse_part() {
4795-
let mut values = [1,2,3,4,5];
4796-
reverse_part(values,1,4);
4797-
assert_eq!(values, [1,4,3,2,5]);
4798-
}
4799-
4800-
#[test]
4801-
fn test_permutations0() {
4802-
let values = [];
4803-
let mut v : ~[~[int]] = ~[];
4804-
for each_permutation(values) |p| {
4805-
v.push(p.to_owned());
4806-
}
4807-
assert_eq!(v, ~[~[]]);
4808-
}
4809-
4810-
#[test]
4811-
fn test_permutations1() {
4812-
let values = [1];
4813-
let mut v : ~[~[int]] = ~[];
4814-
for each_permutation(values) |p| {
4815-
v.push(p.to_owned());
4816-
}
4817-
assert_eq!(v, ~[~[1]]);
4818-
}
4819-
4820-
#[test]
4821-
fn test_permutations2() {
4822-
let values = [1,2];
4823-
let mut v : ~[~[int]] = ~[];
4824-
for each_permutation(values) |p| {
4825-
v.push(p.to_owned());
4826-
}
4827-
assert_eq!(v, ~[~[1,2],~[2,1]]);
4828-
}
4829-
4830-
#[test]
4831-
fn test_permutations3() {
4832-
let values = [1,2,3];
4833-
let mut v : ~[~[int]] = ~[];
4834-
for each_permutation(values) |p| {
4835-
v.push(p.to_owned());
4836-
}
4837-
assert_eq!(v, ~[~[1,2,3],~[1,3,2],~[2,1,3],~[2,3,1],~[3,1,2],~[3,2,1]]);
4838-
}
4839-
48404733
#[test]
48414734
fn test_each_val() {
48424735
use old_iter::CopyableNonstrictIter;

branches/try2/src/librustc/metadata/csearch.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
234234
}
235235
}
236236

237-
// Given a def_id for an impl, return the trait it implements,
238-
// if there is one.
239-
pub fn get_impl_trait(tcx: ty::ctxt,
240-
def: ast::def_id) -> Option<@ty::TraitRef> {
237+
// Given a def_id for an impl or class, return the traits it implements,
238+
// or the empty vector if it's not for an impl or for a class that implements
239+
// traits
240+
pub fn get_impl_traits(tcx: ty::ctxt,
241+
def: ast::def_id) -> ~[@ty::TraitRef] {
241242
let cstore = tcx.cstore;
242243
let cdata = cstore::get_crate_data(cstore, def.crate);
243-
decoder::get_impl_trait(cdata, def.node, tcx)
244+
decoder::get_impl_traits(cdata, def.node, tcx)
244245
}
245246

246247
pub fn get_impl_method(cstore: @mut cstore::CStore,

branches/try2/src/librustc/metadata/decoder.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,19 @@ pub fn get_type_param_count(data: @~[u8], id: ast::node_id) -> uint {
415415
item_ty_param_count(lookup_item(id, data))
416416
}
417417

418-
pub fn get_impl_trait(cdata: cmd,
418+
pub fn get_impl_traits(cdata: cmd,
419419
id: ast::node_id,
420-
tcx: ty::ctxt) -> Option<@ty::TraitRef>
420+
tcx: ty::ctxt) -> ~[@ty::TraitRef]
421421
{
422422
let item_doc = lookup_item(id, cdata.data);
423-
let mut result = None;
423+
let mut results = ~[];
424424
for reader::tagged_docs(item_doc, tag_item_trait_ref) |tp| {
425425
let trait_ref =
426426
@parse_trait_ref_data(tp.data, cdata.cnum, tp.start, tcx,
427427
|_, did| translate_def_id(cdata, did));
428-
result = Some(trait_ref);
429-
break;
428+
results.push(trait_ref);
430429
};
431-
result
430+
results
432431
}
433432

434433
pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,8 @@ pub fn register_fn_fuller(ccx: @CrateContext,
22282228
mangle_exported_name(ccx, /*bad*/copy path, node_type)
22292229
};
22302230
2231-
let llfn: ValueRef = decl_fn(ccx.llmod, ps, cc, llfty);
2231+
// XXX: Bad copy.
2232+
let llfn: ValueRef = decl_fn(ccx.llmod, copy ps, cc, llfty);
22322233
ccx.item_symbols.insert(node_id, ps);
22332234
22342235
// FIXME #4404 android JNI hacks

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ use middle::ty;
101101
use util::common::indenter;
102102
use util::ppaux::ty_to_str;
103103

104+
use core::container::Set; // XXX: this should not be necessary
104105
use core::to_bytes;
105106
use syntax::ast;
106107
use syntax::codemap::span;

0 commit comments

Comments
 (0)