Skip to content

Commit 362a920

Browse files
committed
---
yaml --- r: 12097 b: refs/heads/master c: 042c532 h: refs/heads/master i: 12095: e5dfbeb v: v3
1 parent cf72c86 commit 362a920

25 files changed

+1001
-122
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: 40443768b16747cb3ef90a2fb2fd9e7f317ff383
2+
refs/heads/master: 042c532a084fa3871a3a2d8955ff82c246db8015
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ fn test_enumerate() {
169169
#[test]
170170
fn test_map_and_to_list() {
171171
let a = bind vec::iter([0, 1, 2], _);
172-
let b = bind map(a, {|i| i*2}, _);
172+
let b = bind map(a, {|i| 2*i}, _);
173173
let c = to_list(b);
174174
assert c == [0, 2, 4];
175175
}
176176

177177
#[test]
178178
fn test_map_directly_on_vec() {
179-
let b = bind map([0, 1, 2], {|i| i*2}, _);
179+
let b = bind map([0, 1, 2], {|i| 2*i}, _);
180180
let c = to_list(b);
181181
assert c == [0, 2, 4];
182182
}

trunk/src/libcore/result.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
9191
}
9292
}
9393

94+
#[doc = "
95+
Call a function based on a previous result
96+
97+
If `res` is `err` then the value is extracted and passed to `op`
98+
whereupon `op`s result is returned. if `res` is `ok` then it is
99+
immediately returned. This function can be used to pass through a
100+
successful result while handling an error.
101+
"]
102+
fn chain_err<T: copy, U: copy, V: copy>(
103+
res: result<T, V>,
104+
op: fn(V) -> result<T, U>)
105+
-> result<T, U> {
106+
alt res {
107+
ok(t) { ok(t) }
108+
err(v) { op(v) }
109+
}
110+
}
111+
94112
// ______________________________________________________________________
95113
// Note:
96114
//
@@ -171,6 +189,22 @@ fn map2<S,T,U:copy,V:copy,W>(ss: [S], ts: [T],
171189
ret nxt(vs);
172190
}
173191

192+
fn iter2<S,T,U:copy>(ss: [S], ts: [T],
193+
op: fn(S,T) -> result<(),U>)
194+
: vec::same_length(ss, ts)
195+
-> result<(),U> {
196+
let n = vec::len(ts);
197+
let mut i = 0u;
198+
while i < n {
199+
alt op(ss[i],ts[i]) {
200+
ok(()) { }
201+
err(u) { ret err(u); }
202+
}
203+
i += 1u;
204+
}
205+
ret ok(());
206+
}
207+
174208
#[cfg(test)]
175209
mod tests {
176210
fn op1() -> result::result<int, str> { result::ok(666) }

trunk/src/libcore/vec.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export rsplit;
2727
export rsplitn;
2828
export shift;
2929
export pop;
30+
export clear;
3031
export push;
3132
export grow;
3233
export grow_fn;
@@ -164,6 +165,13 @@ fn from_mut<T>(+v: [mutable T]) -> [T] unsafe {
164165
r
165166
}
166167

168+
// This function only exists to work around bugs in the type checker.
169+
fn from_const<T>(+v: [const T]) -> [T] unsafe {
170+
let r = ::unsafe::reinterpret_cast(v);
171+
::unsafe::forget(v);
172+
r
173+
}
174+
167175
// Accessors
168176

169177
#[doc = "Returns the first element of a vector"]
@@ -336,6 +344,14 @@ fn pop<T>(&v: [const T]) -> T unsafe {
336344
val
337345
}
338346

347+
#[doc = "
348+
Removes all elements from a vector without affecting
349+
how much space is reserved.
350+
"]
351+
fn clear<T>(&v: [const T]) unsafe {
352+
unsafe::set_len(v, 0u);
353+
}
354+
339355
#[doc = "Append an element to a vector"]
340356
fn push<T>(&v: [const T], +initval: T) {
341357
v += [initval];
@@ -466,8 +482,8 @@ Concatenate a vector of vectors.
466482
Flattens a vector of vectors of T into a single vector of T.
467483
"]
468484
fn concat<T: copy>(v: [const [const T]]) -> [T] {
469-
let mut r: [T] = [];
470-
for inner: [T] in v { r += inner; }
485+
let mut r = [];
486+
for inner in v { r += from_const(inner); }
471487
ret r;
472488
}
473489

@@ -477,9 +493,9 @@ Concatenate a vector of vectors, placing a given separator between each
477493
fn connect<T: copy>(v: [const [const T]], sep: T) -> [T] {
478494
let mut r: [T] = [];
479495
let mut first = true;
480-
for inner: [T] in v {
496+
for inner in v {
481497
if first { first = false; } else { push(r, sep); }
482-
r += inner;
498+
r += from_const(inner);
483499
}
484500
ret r;
485501
}
@@ -885,7 +901,7 @@ fn as_mut_buf<E,T>(v: [mutable E], f: fn(*mutable E) -> T) -> T unsafe {
885901
}
886902

887903
#[doc = "An extension implementation providing a `len` method"]
888-
impl vec_len<T> for [T] {
904+
impl vec_len<T> for [const T] {
889905
#[doc = "Return the length of the vector"]
890906
#[inline(always)]
891907
fn len() -> uint { len(self) }

trunk/src/libstd/getopts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export opt_str;
6363
export opt_strs;
6464
export opt_maybe_str;
6565
export opt_default;
66+
export result; //NDM
6667

6768
enum name { long(str), short(char), }
6869

trunk/src/rustc/metadata/astencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ impl helpers for @e::encode_ctxt {
634634
fn ty_str_ctxt() -> @tyencode::ctxt {
635635
@{ds: e::def_to_str,
636636
tcx: self.ccx.tcx,
637+
reachable: self.ccx.reachable,
637638
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}
638639
}
639640
}

trunk/src/rustc/metadata/encoder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ fn encode_type_param_bounds(ebml_w: ebml::writer, ecx: @encode_ctxt,
221221
params: [ty_param]) {
222222
let ty_str_ctxt = @{ds: def_to_str,
223223
tcx: ecx.ccx.tcx,
224+
reachable: ecx.ccx.reachable,
224225
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
225226
for param in params {
226227
ebml_w.start_tag(tag_items_data_item_ty_param_bounds);
@@ -240,6 +241,7 @@ fn write_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
240241
let ty_str_ctxt =
241242
@{ds: def_to_str,
242243
tcx: ecx.ccx.tcx,
244+
reachable: ecx.ccx.reachable,
243245
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
244246
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
245247
}
@@ -966,7 +968,10 @@ fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> [u8] {
966968

967969
// Get the encoded string for a type
968970
fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> str {
969-
let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs};
971+
let cx = @{ds: def_to_str,
972+
tcx: tcx,
973+
reachable: std::map::int_hash(),
974+
abbrevs: tyencode::ac_no_abbrevs};
970975
let buf = io::mem_buffer();
971976
tyencode::enc_ty(io::mem_buffer_writer(buf), cx, t);
972977
ret io::mem_buffer_str(buf);

trunk/src/rustc/metadata/tyencode.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import syntax::ast::*;
66
import driver::session::session;
77
import middle::ty;
88
import syntax::print::pprust::*;
9+
import middle::trans::reachable;
910

1011
export ctxt;
1112
export ty_abbrev;
@@ -18,7 +19,8 @@ export enc_mode;
1819
type ctxt =
1920
// Def -> str Callback:
2021
// The type context.
21-
{ds: fn@(def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt};
22+
{ds: fn@(def_id) -> str, tcx: ty::ctxt,
23+
reachable: reachable::map, abbrevs: abbrev_ctxt};
2224

2325
// Compact string representation for ty.t values. API ty_str & parse_from_str.
2426
// Extra parameters are for converting to/from def_ids in the string rep.
@@ -55,9 +57,14 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
5557
let pos = w.tell();
5658
alt ty::type_def_id(t) {
5759
some(def_id) {
58-
w.write_char('"');
59-
w.write_str(cx.ds(def_id));
60-
w.write_char('|');
60+
// Do not emit node ids that map to unexported names. Those
61+
// are not helpful.
62+
if def_id.crate != local_crate ||
63+
cx.reachable.contains_key(def_id.node) {
64+
w.write_char('"');
65+
w.write_str(cx.ds(def_id));
66+
w.write_char('|');
67+
}
6168
}
6269
_ {}
6370
}

0 commit comments

Comments
 (0)