Skip to content

Commit 5c23076

Browse files
committed
---
yaml --- r: 42385 b: refs/heads/master c: 9599cc8 h: refs/heads/master i: 42383: e1bff77 v: v3
1 parent bf69134 commit 5c23076

25 files changed

+153
-332
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: bc1fb62c343639f9ac66cb0017b8c1813d5e06a7
2+
refs/heads/master: 9599cc86f0bb8bcb45b96c666dd56b34e97c07b1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/libcargo/cargo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ pub fn try_parse_sources(filename: &Path,
495495
let c = io::read_whole_file_str(filename);
496496
match json::from_str(c.get()) {
497497
Ok(json::Object(j)) => {
498-
for j.each |k, v| {
498+
for j.each |&(k, v)| {
499499
sources.insert(copy *k, parse_source(*k, v));
500500
debug!("source: %s", *k);
501501
}

trunk/src/libcore/container.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub trait Map<K, V>: Mutable {
2929
/// Return true if the map contains a value for the specified key
3030
pure fn contains_key(&self, key: &K) -> bool;
3131

32-
/// Visit all key-value pairs
33-
pure fn each(&self, f: fn(&K, &V) -> bool);
34-
3532
/// Visit all keys
3633
pure fn each_key(&self, f: fn(&K) -> bool);
3734

trunk/src/libcore/hashmap.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ pub mod linear {
235235
}
236236
}
237237
238+
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: BaseIter<(&K, &V)> {
239+
/// Visit all key-value pairs
240+
pure fn each(&self, blk: fn(&(&self/K, &self/V)) -> bool) {
241+
for uint::range(0, self.buckets.len()) |i| {
242+
let mut broke = false;
243+
do self.buckets[i].map |bucket| {
244+
if !blk(&(&bucket.key, &bucket.value)) {
245+
broke = true; // FIXME(#3064) just write "break;"
246+
}
247+
};
248+
if broke { break; }
249+
}
250+
}
251+
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
252+
}
253+
254+
238255
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: Container {
239256
/// Return the number of elements in the map
240257
pure fn len(&self) -> uint { self.size }
@@ -262,27 +279,14 @@ pub mod linear {
262279
}
263280
}
264281
265-
/// Visit all key-value pairs
266-
pure fn each(&self, blk: fn(k: &K, v: &V) -> bool) {
267-
for self.buckets.each |slot| {
268-
let mut broke = false;
269-
do slot.iter |bucket| {
270-
if !blk(&bucket.key, &bucket.value) {
271-
broke = true; // FIXME(#3064) just write "break;"
272-
}
273-
}
274-
if broke { break; }
275-
}
276-
}
277-
278282
/// Visit all keys
279283
pure fn each_key(&self, blk: fn(k: &K) -> bool) {
280-
self.each(|k, _| blk(k))
284+
self.each(|&(k, _)| blk(k))
281285
}
282286
283287
/// Visit all values
284288
pure fn each_value(&self, blk: fn(v: &V) -> bool) {
285-
self.each(|_, v| blk(v))
289+
self.each(|&(_, v)| blk(v))
286290
}
287291
288292
/// Return the value corresponding to the key in the map
@@ -388,7 +392,7 @@ pub mod linear {
388392
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
389393
if self.len() != other.len() { return false; }
390394

391-
for self.each |key, value| {
395+
for self.each |&(key, value)| {
392396
match other.find(key) {
393397
None => return false,
394398
Some(v) => if value != v { return false },
@@ -603,7 +607,7 @@ mod test_map {
603607
assert m.insert(i, i*2);
604608
}
605609
let mut observed = 0;
606-
for m.each |k, v| {
610+
for m.each |&(k, v)| {
607611
assert *v == *k * 2;
608612
observed |= (1 << *k);
609613
}

trunk/src/libcore/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub trait BaseIter<A> {
2727
pure fn size_hint(&self) -> Option<uint>;
2828
}
2929

30+
pub trait ReverseIter<A>: BaseIter<A> {
31+
pure fn each_reverse(&self, blk: fn(&A) -> bool);
32+
}
33+
3034
pub trait ExtendedIter<A> {
3135
pure fn eachi(&self, blk: fn(uint, v: &A) -> bool);
3236
pure fn all(&self, blk: fn(&A) -> bool) -> bool;

trunk/src/libcore/option.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
102102
}
103103
104104
#[inline(always)]
105-
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
105+
pub pure fn map<T, U>(opt: &r/Option<T>, f: fn(x: &r/T) -> U) -> Option<U> {
106106
//! Maps a `some` value by reference from one type to another
107107
108108
match *opt { Some(ref x) => Some(f(x)), None => None }
@@ -193,8 +193,8 @@ pub pure fn get_or_default<T: Copy>(opt: Option<T>, def: T) -> T {
193193
}
194194
195195
#[inline(always)]
196-
pub pure fn map_default<T, U>(opt: &Option<T>, def: U,
197-
f: fn(x: &T) -> U) -> U {
196+
pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
197+
f: fn(&r/T) -> U) -> U {
198198
//! Applies a function to the contained value or returns a default
199199
200200
match *opt { None => move def, Some(ref t) => f(t) }
@@ -273,7 +273,7 @@ impl<T> Option<T> {
273273
274274
/// Maps a `some` value from one type to another by reference
275275
#[inline(always)]
276-
pure fn map<U>(&self, f: fn(x: &T) -> U) -> Option<U> { map(self, f) }
276+
pure fn map<U>(&self, f: fn(&self/T) -> U) -> Option<U> { map(self, f) }
277277
278278
/// As `map`, but consumes the option and gives `f` ownership to avoid
279279
/// copying.
@@ -284,7 +284,7 @@ impl<T> Option<T> {
284284
285285
/// Applies a function to the contained value or returns a default
286286
#[inline(always)]
287-
pure fn map_default<U>(&self, def: U, f: fn(x: &T) -> U) -> U {
287+
pure fn map_default<U>(&self, def: U, f: fn(&self/T) -> U) -> U {
288288
map_default(self, move def, f)
289289
}
290290

trunk/src/librustc/lib/llvm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ pub extern mod llvm {
382382
pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
383383

384384
/* Operations on Users */
385-
pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
386385
pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
387386
pub unsafe fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
388387

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,9 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr])
7373
let vec_ty = ty::expr_ty(cx.tcx, e);
7474
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
7575
let llunitty = type_of::type_of(cx, unit_ty);
76+
let v = C_array(llunitty, es.map(|e| const_expr(cx, *e)));
7677
let unit_sz = machine::llsize_of(cx, llunitty);
7778
let sz = llvm::LLVMConstMul(C_uint(cx, es.len()), unit_sz);
78-
let vs = es.map(|e| const_expr(cx, *e));
79-
// If the vector contains enums, an LLVM array won't work.
80-
let v = if vs.any(|vi| val_ty(*vi) != llunitty) {
81-
C_struct(vs)
82-
} else {
83-
C_array(llunitty, vs)
84-
};
8579
return (v, sz, llunitty);
8680
}
8781
}
@@ -285,17 +279,15 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
285279
// call. Despite that being "a const", it's not the kind of
286280
// const you can ask for the integer-value of, evidently. This
287281
// might be an LLVM bug, not sure. In any case, to work around
288-
// this we obtain the initializer and count how many elements it
289-
// has, ignoring the length we pulled out of the slice. (Note
290-
// that the initializer might be a struct rather than an array,
291-
// if enums are involved.) This only works because we picked out
292-
// the original globalvar via const_deref and so can recover the
293-
// array-size of the underlying array (or the element count of
294-
// the underlying struct), and all this will hold together
295-
// exactly as long as we _don't_ support const sub-slices (that
296-
// is, slices that represent something other than a whole
297-
// array). At that point we'll have more and uglier work to do
298-
// here, but for now this should work.
282+
// this we drop down to the array-type level here and just ask
283+
// how long the array-type itself is, ignoring the length we
284+
// pulled out of the slice. This in turn only works because we
285+
// picked out the original globalvar via const_deref and so can
286+
// recover the array-size of the underlying array, and all this
287+
// will hold together exactly as long as we _don't_ support
288+
// const sub-slices (that is, slices that represent something
289+
// other than a whole array). At that point we'll have more and
290+
// uglier work to do here, but for now this should work.
299291
//
300292
// In the future, what we should be doing here is the
301293
// moral equivalent of:
@@ -307,7 +299,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
307299
// not want to consider sizeof() a constant expression
308300
// we can get the value (as a number) out of.
309301

310-
let len = llvm::LLVMGetNumOperands(arr) as u64;
302+
let len = llvm::LLVMGetArrayLength(val_ty(arr)) as u64;
311303
let len = match ty::get(bt).sty {
312304
ty::ty_estr(*) => {assert len > 0; len - 1},
313305
_ => len
@@ -354,8 +346,10 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
354346
}
355347
ast::expr_addr_of(ast::m_imm, sub) => {
356348
let cv = const_expr(cx, sub);
349+
let subty = ty::expr_ty(cx.tcx, sub),
350+
llty = type_of::type_of(cx, subty);
357351
let gv = do str::as_c_str("const") |name| {
358-
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
352+
llvm::LLVMAddGlobal(cx.llmod, llty, name)
359353
};
360354
llvm::LLVMSetInitializer(gv, cv);
361355
llvm::LLVMSetGlobalConstant(gv, True);
@@ -383,7 +377,8 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
383377
}
384378
})
385379
};
386-
C_struct([C_struct(cs)])
380+
let llty = type_of::type_of(cx, ety);
381+
C_named_struct(llty, [C_struct(cs)])
387382
}
388383
ast::expr_vec(es, ast::m_imm) => {
389384
let (v, _, _) = const_vec(cx, e, es);
@@ -439,13 +434,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
439434
let lldiscrim = base::get_discrim_val(cx, e.span,
440435
enum_did,
441436
variant_did);
442-
// However, we still have to pad it out to the
443-
// size of the full enum; see the expr_call case,
444-
// below.
445-
let ety = ty::expr_ty(cx.tcx, e);
446-
let size = machine::static_size_of_enum(cx, ety);
447-
let padding = C_null(T_array(T_i8(), size));
448-
C_struct(~[lldiscrim, padding])
437+
C_struct(~[lldiscrim])
449438
}
450439
Some(ast::def_struct(_)) => {
451440
let ety = ty::expr_ty(cx.tcx, e);
@@ -461,12 +450,14 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
461450
ast::expr_call(callee, args, _) => {
462451
match cx.tcx.def_map.find(&callee.id) {
463452
Some(ast::def_struct(def_id)) => {
453+
let ety = ty::expr_ty(cx.tcx, e);
454+
let llty = type_of::type_of(cx, ety);
464455
let llstructbody =
465456
C_struct(args.map(|a| const_expr(cx, *a)));
466457
if ty::ty_dtor(cx.tcx, def_id).is_present() {
467-
C_struct(~[ llstructbody, C_u8(0) ])
458+
C_named_struct(llty, ~[ llstructbody, C_u8(0) ])
468459
} else {
469-
C_struct(~[ llstructbody ])
460+
C_named_struct(llty, ~[ llstructbody ])
470461
}
471462
}
472463
Some(ast::def_variant(tid, vid)) => {
@@ -479,20 +470,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
479470

480471
// FIXME (#1645): enum body alignment is generaly wrong.
481472
if !degen {
482-
// Pad out the data to the size of its type_of;
483-
// this is necessary if the enum is contained
484-
// within an aggregate (tuple, struct, vector) so
485-
// that the next element is at the right offset.
486-
let actual_size =
487-
machine::llsize_of_real(cx, llvm::LLVMTypeOf(c_args));
488-
let padding =
489-
C_null(T_array(T_i8(), size - actual_size));
490-
// A packed_struct has an alignment of 1; thus,
491-
// wrapping one around c_args will misalign it the
492-
// same way we normally misalign enum bodies
493-
// without affecting its internal alignment or
494-
// changing the alignment of the enum.
495-
C_struct(~[discrim, C_packed_struct(~[c_args]), padding])
473+
C_packed_struct(~[discrim, c_args])
496474
} else if size == 0 {
497475
C_struct(~[discrim])
498476
} else {

trunk/src/libstd/json.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub impl<S: serialize::Encoder> Json: serialize::Encodable<S> {
302302
Object(ref v) => {
303303
do s.emit_rec || {
304304
let mut idx = 0;
305-
for v.each |key, value| {
305+
for v.each |&(key, value)| {
306306
do s.emit_field(*key, idx) {
307307
value.encode(s);
308308
}
@@ -936,7 +936,7 @@ impl Json : Eq {
936936
&Object(ref d1) => {
937937
if d0.len() == d1.len() {
938938
let mut equal = true;
939-
for d0.each |k, v0| {
939+
for d0.each |&(k, v0)| {
940940
match d1.find(k) {
941941
Some(v1) if v0 == v1 => { },
942942
_ => { equal = false; break }
@@ -1000,12 +1000,12 @@ impl Json : Ord {
10001000
let mut d1_flat = ~[];
10011001
10021002
// FIXME #4430: this is horribly inefficient...
1003-
for d0.each |k, v| {
1003+
for d0.each |&(k, v)| {
10041004
d0_flat.push((@copy *k, @copy *v));
10051005
}
10061006
d0_flat.qsort();
10071007
1008-
for d1.each |k, v| {
1008+
for d1.each |&(k, v)| {
10091009
d1_flat.push((@copy *k, @copy *v));
10101010
}
10111011
d1_flat.qsort();
@@ -1146,7 +1146,7 @@ impl <A: ToJson> ~[A]: ToJson {
11461146
impl <A: ToJson Copy> LinearMap<~str, A>: ToJson {
11471147
fn to_json() -> Json {
11481148
let mut d = LinearMap::new();
1149-
for self.each() |key, value| {
1149+
for self.each |&(key, value)| {
11501150
d.insert(copy *key, value.to_json());
11511151
}
11521152
Object(~d)

trunk/src/libstd/net_url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ pub fn encode_form_urlencoded(m: &LinearMap<~str, ~[~str]>) -> ~str {
219219
let mut out = ~"";
220220
let mut first = true;
221221

222-
for m.each |key, values| {
222+
for m.each |&(key, values)| {
223223
let key = encode_plus(*key);
224224

225-
for (*values).each |value| {
225+
for values.each |value| {
226226
if first {
227227
first = false;
228228
} else {

trunk/src/libstd/priority_queue.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
use core::container::{Container, Mutable};
1414
use core::cmp::Ord;
15+
use core::iter::BaseIter;
1516
use core::prelude::*;
1617
use core::ptr::addr_of;
1718
use core::vec;
@@ -26,6 +27,14 @@ pub struct PriorityQueue<T> {
2627
priv data: ~[T],
2728
}
2829

30+
impl <T: Ord> PriorityQueue<T>: BaseIter<T> {
31+
/// Visit all values in the underlying vector.
32+
///
33+
/// The values are **not** visited in order.
34+
pure fn each(&self, f: fn(&T) -> bool) { self.data.each(f) }
35+
pure fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
36+
}
37+
2938
impl <T: Ord> PriorityQueue<T>: Container {
3039
/// Returns the length of the queue
3140
pure fn len(&self) -> uint { self.data.len() }

0 commit comments

Comments
 (0)