Move some code over to iterator-for to see how it performs.
This commit is contained in:
parent
cbad6925c1
commit
b5a4fa9456
27 changed files with 194 additions and 180 deletions
|
@ -25,7 +25,7 @@ fn lefts<T: copy, U>(eithers: [either<T, U>]) -> [T] {
|
|||
#[doc = "Extracts from a vector of either all the left values"];
|
||||
|
||||
let mut result: [T] = [];
|
||||
for elt: either<T, U> in eithers {
|
||||
for vec::each(eithers) {|elt|
|
||||
alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } }
|
||||
}
|
||||
ret result;
|
||||
|
@ -35,7 +35,7 @@ fn rights<T, U: copy>(eithers: [either<T, U>]) -> [U] {
|
|||
#[doc = "Extracts from a vector of either all the right values"];
|
||||
|
||||
let mut result: [U] = [];
|
||||
for elt: either<T, U> in eithers {
|
||||
for vec::each(eithers) {|elt|
|
||||
alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } }
|
||||
}
|
||||
ret result;
|
||||
|
@ -52,7 +52,7 @@ fn partition<T: copy, U: copy>(eithers: [either<T, U>])
|
|||
|
||||
let mut lefts: [T] = [];
|
||||
let mut rights: [U] = [];
|
||||
for elt: either<T, U> in eithers {
|
||||
for vec::each(eithers) {|elt|
|
||||
alt elt { left(l) { lefts += [l]; } right(r) { rights += [r]; } }
|
||||
}
|
||||
ret {lefts: lefts, rights: rights};
|
||||
|
|
|
@ -429,7 +429,7 @@ mod rt {
|
|||
ret padstr + s;
|
||||
}
|
||||
fn have_flag(flags: [flag], f: flag) -> bool {
|
||||
for candidate: flag in flags { if candidate == f { ret true; } }
|
||||
for vec::each(flags) {|candidate| if candidate == f { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -389,7 +389,7 @@ fn mk_file_writer(path: str, flags: [fileflag])
|
|||
fn wb() -> c_int { O_WRONLY as c_int }
|
||||
|
||||
let mut fflags: c_int = wb();
|
||||
for f: fileflag in flags {
|
||||
for vec::each(flags) {|f|
|
||||
alt f {
|
||||
append { fflags |= O_APPEND as c_int; }
|
||||
create { fflags |= O_CREAT as c_int; }
|
||||
|
@ -521,7 +521,7 @@ impl of writer for mem_buffer {
|
|||
fn write(v: [const u8]) {
|
||||
// Fast path.
|
||||
if self.pos == vec::len(self.buf) {
|
||||
for b: u8 in v { self.buf += [mut b]; }
|
||||
for vec::each(v) {|b| self.buf += [mut b]; }
|
||||
self.pos += vec::len(v);
|
||||
ret;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ native mod rustrt {
|
|||
|
||||
fn env() -> [(str,str)] {
|
||||
let mut pairs = [];
|
||||
for p in rustrt::rust_env_pairs() {
|
||||
for vec::each(rustrt::rust_env_pairs()) {|p|
|
||||
let vs = str::splitn_char(p, '=', 1u);
|
||||
assert vec::len(vs) == 2u;
|
||||
pairs += [(vs[0], vs[1])];
|
||||
|
@ -464,7 +464,7 @@ fn list_dir(p: path) -> [str] {
|
|||
p += path::path_sep();
|
||||
}
|
||||
let mut full_paths: [str] = [];
|
||||
for filename: str in rustrt::rust_list_files(p + star()) {
|
||||
for vec::each(rustrt::rust_list_files(p + star())) {|filename|
|
||||
if !str::eq(filename, ".") {
|
||||
if !str::eq(filename, "..") {
|
||||
full_paths += [p + filename];
|
||||
|
@ -645,7 +645,8 @@ mod tests {
|
|||
fn test_env_getenv() {
|
||||
let e = env();
|
||||
assert vec::len(e) > 0u;
|
||||
for (n, v) in e {
|
||||
for vec::each(e) {|p|
|
||||
let (n, v) = p;
|
||||
log(debug, n);
|
||||
let v2 = getenv(n);
|
||||
// MingW seems to set some funky environment variables like
|
||||
|
@ -734,7 +735,7 @@ mod tests {
|
|||
// Just assuming that we've got some contents in the current directory
|
||||
assert (vec::len(dirs) > 0u);
|
||||
|
||||
for dir in dirs { log(debug, dir); }
|
||||
for vec::each(dirs) {|dir| log(debug, dir); }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -139,7 +139,7 @@ checking for overflow:
|
|||
fn map<T,U:copy,V:copy>(ts: [T], op: fn(T) -> result<V,U>) -> result<[V],U> {
|
||||
let mut vs: [V] = [];
|
||||
vec::reserve(vs, vec::len(ts));
|
||||
for t in ts {
|
||||
for vec::each(ts) {|t|
|
||||
alt op(t) {
|
||||
ok(v) { vs += [v]; }
|
||||
err(u) { ret err(u); }
|
||||
|
|
|
@ -81,7 +81,7 @@ fn with_argv<T>(prog: str, args: [str],
|
|||
cb: fn(**libc::c_char) -> T) -> T unsafe {
|
||||
let mut argptrs = str::as_c_str(prog) {|b| [b] };
|
||||
let mut tmps = [];
|
||||
for arg in args {
|
||||
for vec::each(args) {|arg|
|
||||
let t = @arg;
|
||||
tmps += [t];
|
||||
argptrs += str::as_c_str(*t) {|b| [b] };
|
||||
|
@ -102,7 +102,8 @@ fn with_envp<T>(env: option<[(str,str)]>,
|
|||
let mut tmps = [];
|
||||
let mut ptrs = [];
|
||||
|
||||
for (k,v) in es {
|
||||
for vec::each(es) {|e|
|
||||
let (k,v) = e;
|
||||
let t = @(#fmt("%s=%s", k, v));
|
||||
vec::push(tmps, t);
|
||||
ptrs += str::as_c_str(*t) {|b| [b]};
|
||||
|
@ -125,7 +126,8 @@ fn with_envp<T>(env: option<[(str,str)]>,
|
|||
alt env {
|
||||
some (es) {
|
||||
let mut blk : [u8] = [];
|
||||
for (k,v) in es {
|
||||
for vec::each(es) {|e|
|
||||
let (k,v) = e;
|
||||
let t = #fmt("%s=%s", k, v);
|
||||
let mut v : [u8] = ::unsafe::reinterpret_cast(t);
|
||||
blk += v;
|
||||
|
|
|
@ -55,6 +55,7 @@ export
|
|||
all, any,
|
||||
all_between, any_between,
|
||||
map,
|
||||
each,
|
||||
bytes_iter,
|
||||
chars_iter,
|
||||
split_char_iter,
|
||||
|
@ -176,14 +177,14 @@ fn from_char(ch: char) -> str {
|
|||
fn from_chars(chs: [char]) -> str {
|
||||
let mut buf = "";
|
||||
reserve(buf, chs.len());
|
||||
for ch in chs { push_char(buf, ch); }
|
||||
for vec::each(chs) {|ch| push_char(buf, ch); }
|
||||
ret buf;
|
||||
}
|
||||
|
||||
#[doc = "Concatenate a vector of strings"]
|
||||
fn concat(v: [str]) -> str {
|
||||
let mut s: str = "";
|
||||
for ss: str in v { s += ss; }
|
||||
for vec::each(v) {|ss| s += ss; }
|
||||
ret s;
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ Concatenate a vector of strings, placing a given separator between each
|
|||
"]
|
||||
fn connect(v: [str], sep: str) -> str {
|
||||
let mut s = "", first = true;
|
||||
for ss: str in v {
|
||||
for vec::each(v) {|ss|
|
||||
if first { first = false; } else { s += sep; }
|
||||
s += ss;
|
||||
}
|
||||
|
@ -538,7 +539,7 @@ fn hash(&&s: str) -> uint {
|
|||
// djb hash.
|
||||
// FIXME: replace with murmur.
|
||||
let mut u: uint = 5381u;
|
||||
for c: u8 in s { u *= 33u; u += c as uint; }
|
||||
for each(s) {|c| u *= 33u; u += c as uint; }
|
||||
ret u;
|
||||
}
|
||||
|
||||
|
@ -581,6 +582,16 @@ fn bytes_iter(ss: str, it: fn(u8)) {
|
|||
}
|
||||
}
|
||||
|
||||
#[doc = "Iterate over the bytes in a string"]
|
||||
#[inline(always)]
|
||||
fn each(s: str, it: fn(u8) -> bool) {
|
||||
let mut i = 0u, l = len(s);
|
||||
while (i < l) {
|
||||
if !it(s[i]) { break; }
|
||||
i += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = "Iterate over the characters in a string"]
|
||||
fn chars_iter(s: str, it: fn(char)) {
|
||||
let mut pos = 0u;
|
||||
|
@ -938,7 +949,7 @@ fn rfind_between(s: str, start: uint, end: uint, f: fn(char) -> bool)
|
|||
// Utility used by various searching functions
|
||||
fn match_at(haystack: str, needle: str, at: uint) -> bool {
|
||||
let mut i = at;
|
||||
for c in needle { if haystack[i] != c { ret false; } i += 1u; }
|
||||
for each(needle) {|c| if haystack[i] != c { ret false; } i += 1u; }
|
||||
ret true;
|
||||
}
|
||||
|
||||
|
@ -1074,7 +1085,7 @@ fn is_ascii(s: str) -> bool {
|
|||
}
|
||||
|
||||
#[doc = "Returns true if the string has length 0"]
|
||||
pure fn is_empty(s: str) -> bool { for c: u8 in s { ret false; } ret true; }
|
||||
pure fn is_empty(s: str) -> bool { len(s) == 0u }
|
||||
|
||||
#[doc = "Returns true if the string has length greater than 0"]
|
||||
pure fn is_not_empty(s: str) -> bool { !is_empty(s) }
|
||||
|
@ -1588,7 +1599,7 @@ mod unsafe {
|
|||
|
||||
#[doc = "Appends a vector of bytes to a string. (Not UTF-8 safe)."]
|
||||
unsafe fn push_bytes(&s: str, bytes: [u8]) {
|
||||
for byte in bytes { rustrt::rust_str_push(s, byte); }
|
||||
for vec::each(bytes) {|byte| rustrt::rust_str_push(s, byte); }
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
|
@ -2472,7 +2483,8 @@ mod tests {
|
|||
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
|
||||
0x000a_u16 ]) ];
|
||||
|
||||
for (s, u) in pairs {
|
||||
for vec::each(pairs) {|p|
|
||||
let (s, u) = p;
|
||||
assert to_utf16(s) == u;
|
||||
assert from_utf16(u) == s;
|
||||
assert from_utf16(to_utf16(s)) == s;
|
||||
|
|
|
@ -38,7 +38,7 @@ impl <A: to_str copy, B: to_str copy, C: to_str copy> of to_str for (A, B, C){
|
|||
impl <A: to_str> of to_str for [A] {
|
||||
fn to_str() -> str {
|
||||
let mut acc = "[", first = true;
|
||||
for elt in self {
|
||||
for vec::each(self) {|elt|
|
||||
if first { first = false; }
|
||||
else { acc += ", "; }
|
||||
acc += elt.to_str();
|
||||
|
|
|
@ -410,7 +410,7 @@ Apply a function to each element of a vector and return the results
|
|||
fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
|
||||
let mut result = [];
|
||||
reserve(result, len(v));
|
||||
for elem: T in v { result += [f(elem)]; }
|
||||
for each(v) {|elem| result += [f(elem)]; }
|
||||
ret result;
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ of each result vector
|
|||
"]
|
||||
fn flat_map<T, U>(v: [T], f: fn(T) -> [U]) -> [U] {
|
||||
let mut result = [];
|
||||
for elem: T in v { result += f(elem); }
|
||||
for each(v) {|elem| result += f(elem); }
|
||||
ret result;
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ the resulting vector.
|
|||
fn filter_map<T, U: copy>(v: [T], f: fn(T) -> option<U>)
|
||||
-> [U] {
|
||||
let mut result = [];
|
||||
for elem: T in v {
|
||||
for each(v) {|elem|
|
||||
alt f(elem) {
|
||||
none {/* no-op */ }
|
||||
some(result_elem) { result += [result_elem]; }
|
||||
|
@ -464,7 +464,7 @@ only those elements for which `f` returned true.
|
|||
"]
|
||||
fn filter<T: copy>(v: [T], f: fn(T) -> bool) -> [T] {
|
||||
let mut result = [];
|
||||
for elem: T in v {
|
||||
for each(v) {|elem|
|
||||
if f(elem) { result += [elem]; }
|
||||
}
|
||||
ret result;
|
||||
|
@ -477,7 +477,7 @@ Flattens a vector of vectors of T into a single vector of T.
|
|||
"]
|
||||
fn concat<T: copy>(v: [const [const T]]) -> [T] {
|
||||
let mut r = [];
|
||||
for inner in v { r += from_const(inner); }
|
||||
for each(v) {|inner| r += from_const(inner); }
|
||||
ret r;
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ Concatenate a vector of vectors, placing a given separator between each
|
|||
fn connect<T: copy>(v: [const [const T]], sep: T) -> [T] {
|
||||
let mut r: [T] = [];
|
||||
let mut first = true;
|
||||
for inner in v {
|
||||
for each(v) {|inner|
|
||||
if first { first = false; } else { push(r, sep); }
|
||||
r += from_const(inner);
|
||||
}
|
||||
|
@ -518,7 +518,7 @@ Return true if a predicate matches any elements
|
|||
If the vector contains no elements then false is returned.
|
||||
"]
|
||||
fn any<T>(v: [T], f: fn(T) -> bool) -> bool {
|
||||
for elem: T in v { if f(elem) { ret true; } }
|
||||
for each(v) {|elem| if f(elem) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,7 @@ Return true if a predicate matches all elements
|
|||
If the vector contains no elements then true is returned.
|
||||
"]
|
||||
fn all<T>(v: [T], f: fn(T) -> bool) -> bool {
|
||||
for elem: T in v { if !f(elem) { ret false; } }
|
||||
for each(v) {|elem| if !f(elem) { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
|
@ -563,14 +563,14 @@ fn all2<T, U>(v0: [const T], v1: [const U], f: fn(T, U) -> bool) -> bool {
|
|||
|
||||
#[doc = "Return true if a vector contains an element with the given value"]
|
||||
fn contains<T>(v: [const T], x: T) -> bool {
|
||||
for elt: T in v { if x == elt { ret true; } }
|
||||
for each(v) {|elt| if x == elt { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
#[doc = "Returns the number of elements that are equal to a given value"]
|
||||
fn count<T>(v: [const T], x: T) -> uint {
|
||||
let mut cnt = 0u;
|
||||
for elt: T in v { if x == elt { cnt += 1u; } }
|
||||
for each(v) {|elt| if x == elt { cnt += 1u; } }
|
||||
ret cnt;
|
||||
}
|
||||
|
||||
|
@ -701,7 +701,7 @@ of the i-th tuple of the input vector.
|
|||
"]
|
||||
fn unzip<T: copy, U: copy>(v: [const (T, U)]) -> ([T], [U]) {
|
||||
let mut as = [], bs = [];
|
||||
for (a, b) in v { as += [a]; bs += [b]; }
|
||||
for each(v) {|p| let (a, b) = p; as += [a]; bs += [b]; }
|
||||
ret (as, bs);
|
||||
}
|
||||
|
||||
|
@ -807,7 +807,7 @@ Iterates over a vector's elements and indices
|
|||
fn eachi<T>(v: [const T], f: fn(uint, T) -> bool) unsafe {
|
||||
let mut i = 0u, l = len(v);
|
||||
let mut p = ptr::offset(unsafe::to_ptr(v), 0u);
|
||||
while i > l {
|
||||
while i < l {
|
||||
if !f(i, *p) { break; }
|
||||
p = ptr::offset(p, 1u);
|
||||
i += 1u;
|
||||
|
|
|
@ -173,14 +173,14 @@ fn set(v: bitv, i: uint, x: bool) {
|
|||
|
||||
#[doc = "Returns true if all bits are 1"]
|
||||
fn is_true(v: bitv) -> bool {
|
||||
for i: uint in to_vec(v) { if i != 1u { ret false; } }
|
||||
for each(v) {|i| if !i { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
|
||||
#[doc = "Returns true if all bits are 0"]
|
||||
fn is_false(v: bitv) -> bool {
|
||||
for i: uint in to_vec(v) { if i == 1u { ret false; } }
|
||||
for each(v) {|i| if i { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
|
@ -198,6 +198,12 @@ fn to_vec(v: bitv) -> [uint] {
|
|||
ret vec::from_fn::<uint>(v.nbits, sub);
|
||||
}
|
||||
|
||||
fn each(v: bitv, f: fn(bool) -> bool) {
|
||||
let mut i = 0u;
|
||||
while i < v.nbits {
|
||||
if !f(get(v, i)) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Converts the bitvector to a string.
|
||||
|
@ -207,7 +213,7 @@ is either '0' or '1'.
|
|||
"]
|
||||
fn to_str(v: bitv) -> str {
|
||||
let mut rs = "";
|
||||
for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
|
||||
for each(v) {|i| if i { rs += "1"; } else { rs += "0"; } }
|
||||
ret rs;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
|
|||
}
|
||||
}
|
||||
let mut name_pos = 0u;
|
||||
for nm: name in names {
|
||||
for vec::each(names) {|nm|
|
||||
name_pos += 1u;
|
||||
let optid = alt find_opt(opts, nm) {
|
||||
some(id) { id }
|
||||
|
@ -290,7 +290,7 @@ Used when an option accepts multiple values.
|
|||
"]
|
||||
fn opt_strs(m: match, nm: str) -> [str] {
|
||||
let mut acc: [str] = [];
|
||||
for v: optval in opt_vals(m, nm) {
|
||||
for vec::each(opt_vals(m, nm)) {|v|
|
||||
alt v { val(s) { acc += [s]; } _ { } }
|
||||
}
|
||||
ret acc;
|
||||
|
|
|
@ -63,7 +63,7 @@ fn sha1() -> sha1 {
|
|||
fn add_input(st: sha1state, msg: [u8]) {
|
||||
// FIXME: Should be typestate precondition
|
||||
assert (!st.computed);
|
||||
for element: u8 in msg {
|
||||
for vec::each(msg) {|element|
|
||||
st.msg_block[st.msg_block_idx] = element;
|
||||
st.msg_block_idx += 1u;
|
||||
st.len_low += 8u32;
|
||||
|
@ -161,7 +161,7 @@ fn sha1() -> sha1 {
|
|||
fn mk_result(st: sha1state) -> [u8] {
|
||||
if !st.computed { pad_msg(st); st.computed = true; }
|
||||
let mut rs: [u8] = [];
|
||||
for hpart: u32 in st.h {
|
||||
for vec::each(st.h) {|hpart|
|
||||
let a = (hpart >> 24u32 & 0xFFu32) as u8;
|
||||
let b = (hpart >> 16u32 & 0xFFu32) as u8;
|
||||
let c = (hpart >> 8u32 & 0xFFu32) as u8;
|
||||
|
@ -238,7 +238,7 @@ fn sha1() -> sha1 {
|
|||
fn result_str() -> str {
|
||||
let r = mk_result(self);
|
||||
let mut s = "";
|
||||
for b: u8 in r { s += uint::to_str(b as uint, 16u); }
|
||||
for vec::each(r) {|b| s += uint::to_str(b as uint, 16u); }
|
||||
ret s;
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ mod tests {
|
|||
// Test that it works when accepting the message all at once
|
||||
|
||||
let sh = sha1::sha1();
|
||||
for t: test in tests {
|
||||
for vec::each(tests) {|t|
|
||||
sh.input_str(t.input);
|
||||
let out = sh.result();
|
||||
check_vec_eq(t.output, out);
|
||||
|
@ -336,7 +336,7 @@ mod tests {
|
|||
|
||||
|
||||
// Test that it works when accepting the message in pieces
|
||||
for t: test in tests {
|
||||
for vec::each(tests) {|t|
|
||||
let len = str::len(t.input);
|
||||
let mut left = len;
|
||||
while left > 0u {
|
||||
|
|
|
@ -254,7 +254,11 @@ mod test_qsort {
|
|||
let immut_names = vec::from_mut(names);
|
||||
|
||||
let pairs = vec::zip(expected, immut_names);
|
||||
for (a, b) in pairs { #debug("%d %d", a, b); assert (a == b); }
|
||||
for vec::each(pairs) {|p|
|
||||
let (a, b) = p;
|
||||
#debug("%d %d", a, b);
|
||||
assert (a == b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ fn color_supported() -> bool {
|
|||
"screen-bce", "xterm-256color"];
|
||||
ret alt os::getenv("TERM") {
|
||||
option::some(env) {
|
||||
for term: str in supported_terms {
|
||||
for vec::each(supported_terms) {|term|
|
||||
if str::eq(term, env) { ret true; }
|
||||
}
|
||||
false
|
||||
|
|
|
@ -183,7 +183,7 @@ fn print_failures(st: console_test_state) {
|
|||
st.out.write_line("\nfailures:");
|
||||
let failures = vec::map(copy st.failures) {|test| test.name};
|
||||
let failures = sort::merge_sort(str::le, failures);
|
||||
for name in failures {
|
||||
for vec::each(failures) {|name|
|
||||
st.out.write_line(#fmt[" %s", name]);
|
||||
}
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ mod tests {
|
|||
{
|
||||
let testfn = fn~() { };
|
||||
let mut tests = [];
|
||||
for name: str in names {
|
||||
for vec::each(names) {|name|
|
||||
let test = {name: name, fn: testfn, ignore: false,
|
||||
should_fail: false};
|
||||
tests += [test];
|
||||
|
@ -510,7 +510,7 @@ mod tests {
|
|||
|
||||
let pairs = vec::zip(expected, filtered);
|
||||
|
||||
for (a, b) in pairs { assert (a == b.name); }
|
||||
for vec::each(pairs) {|p| let (a, b) = p; assert (a == b.name); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
|
|||
fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> opt {
|
||||
let vdef = ast_util::variant_def_ids(tcx.def_map.get(pat_id));
|
||||
let variants = ty::enum_variants(tcx, vdef.enm);
|
||||
for v: ty::variant_info in *variants {
|
||||
for vec::each(*variants) {|v|
|
||||
if vdef.var == v.id { ret var(v.disr_val, vdef); }
|
||||
}
|
||||
core::unreachable();
|
||||
|
@ -78,7 +78,7 @@ fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> opt {
|
|||
|
||||
type bind_map = [{ident: ast::ident, val: ValueRef}];
|
||||
fn assoc(key: str, list: bind_map) -> option<ValueRef> {
|
||||
for elt: {ident: ast::ident, val: ValueRef} in list {
|
||||
for vec::each(list) {|elt|
|
||||
if str::eq(elt.ident, key) { ret some(elt.val); }
|
||||
}
|
||||
ret none;
|
||||
|
@ -93,7 +93,7 @@ type match_branch =
|
|||
type match = [match_branch];
|
||||
|
||||
fn has_nested_bindings(m: match, col: uint) -> bool {
|
||||
for br in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node {
|
||||
ast::pat_ident(_, some(_)) { ret true; }
|
||||
_ {}
|
||||
|
@ -104,7 +104,7 @@ fn has_nested_bindings(m: match, col: uint) -> bool {
|
|||
|
||||
fn expand_nested_bindings(m: match, col: uint, val: ValueRef) -> match {
|
||||
let mut result = [];
|
||||
for br in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node {
|
||||
ast::pat_ident(name, some(inner)) {
|
||||
let pats = vec::slice(br.pats, 0u, col) + [inner] +
|
||||
|
@ -125,7 +125,7 @@ type enter_pat = fn(@ast::pat) -> option<[@ast::pat]>;
|
|||
fn enter_match(dm: def_map, m: match, col: uint, val: ValueRef,
|
||||
e: enter_pat) -> match {
|
||||
let mut result = [];
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
alt e(br.pats[col]) {
|
||||
some(sub) {
|
||||
let pats = sub + vec::slice(br.pats, 0u, col) +
|
||||
|
@ -188,9 +188,9 @@ fn enter_rec(dm: def_map, m: match, col: uint, fields: [ast::ident],
|
|||
alt p.node {
|
||||
ast::pat_rec(fpats, _) {
|
||||
let mut pats = [];
|
||||
for fname: ast::ident in fields {
|
||||
for vec::each(fields) {|fname|
|
||||
let mut pat = dummy;
|
||||
for fpat: ast::field_pat in fpats {
|
||||
for vec::each(fpats) {|fpat|
|
||||
if str::eq(fpat.ident, fname) { pat = fpat.pat; break; }
|
||||
}
|
||||
pats += [pat];
|
||||
|
@ -235,12 +235,12 @@ fn enter_uniq(dm: def_map, m: match, col: uint, val: ValueRef) -> match {
|
|||
|
||||
fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> [opt] {
|
||||
fn add_to_set(tcx: ty::ctxt, &set: [opt], val: opt) {
|
||||
for l in set { if opt_eq(tcx, l, val) { ret; } }
|
||||
for vec::each(set) {|l| if opt_eq(tcx, l, val) { ret; } }
|
||||
set += [val];
|
||||
}
|
||||
|
||||
let mut found = [];
|
||||
for br in m {
|
||||
for vec::each(m) {|br|
|
||||
let cur = br.pats[col];
|
||||
if pat_is_variant(ccx.tcx.def_map, cur) {
|
||||
add_to_set(ccx.tcx, found, variant_opt(ccx.tcx, br.pats[col].id));
|
||||
|
@ -288,10 +288,10 @@ fn extract_variant_args(bcx: block, pat_id: ast::node_id,
|
|||
|
||||
fn collect_record_fields(m: match, col: uint) -> [ast::ident] {
|
||||
let mut fields = [];
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node {
|
||||
ast::pat_rec(fs, _) {
|
||||
for f: ast::field_pat in fs {
|
||||
for vec::each(fs) {|f|
|
||||
if !vec::any(fields, bind str::eq(f.ident, _)) {
|
||||
fields += [f.ident];
|
||||
}
|
||||
|
@ -304,21 +304,21 @@ fn collect_record_fields(m: match, col: uint) -> [ast::ident] {
|
|||
}
|
||||
|
||||
fn any_box_pat(m: match, col: uint) -> bool {
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node { ast::pat_box(_) { ret true; } _ { } }
|
||||
}
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn any_uniq_pat(m: match, col: uint) -> bool {
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node { ast::pat_uniq(_) { ret true; } _ { } }
|
||||
}
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn any_tup_pat(m: match, col: uint) -> bool {
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } }
|
||||
}
|
||||
ret false;
|
||||
|
@ -336,14 +336,14 @@ fn pick_col(m: match) -> uint {
|
|||
}
|
||||
}
|
||||
let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u));
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
let mut i = 0u;
|
||||
for p: @ast::pat in br.pats { scores[i] += score(p); i += 1u; }
|
||||
for vec::each(br.pats) {|p| scores[i] += score(p); i += 1u; }
|
||||
}
|
||||
let mut max_score = 0u;
|
||||
let mut best_col = 0u;
|
||||
let mut i = 0u;
|
||||
for score: uint in scores {
|
||||
for vec::each(scores) {|score|
|
||||
// Irrefutable columns always go first, they'd only be duplicated in
|
||||
// the branches.
|
||||
if score == 0u { ret i; }
|
||||
|
@ -398,7 +398,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||
vec::slice(vals, col + 1u, vals.len());
|
||||
let ccx = bcx.fcx.ccx;
|
||||
let mut pat_id = 0;
|
||||
for br: match_branch in m {
|
||||
for vec::each(m) {|br|
|
||||
// Find a real id (we're adding placeholder wildcard patterns, but
|
||||
// each column is guaranteed to have at least one real pattern)
|
||||
if pat_id == 0 { pat_id = br.pats[col].id; }
|
||||
|
@ -409,7 +409,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||
if rec_fields.len() > 0u {
|
||||
let fields = ty::get_fields(node_id_type(bcx, pat_id));
|
||||
let mut rec_vals = [];
|
||||
for field_name: ast::ident in rec_fields {
|
||||
for vec::each(rec_fields) {|field_name|
|
||||
let ix = option::get(ty::field_idx(field_name, fields));
|
||||
rec_vals += [GEPi(bcx, val, [0, ix as int])];
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||
}
|
||||
}
|
||||
}
|
||||
for o: opt in opts {
|
||||
for vec::each(opts) {|o|
|
||||
alt o {
|
||||
range(_, _) { kind = compare; break; }
|
||||
_ { }
|
||||
|
@ -499,7 +499,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||
let len = opts.len();
|
||||
let mut i = 0u;
|
||||
// Compile subtrees for each option
|
||||
for opt in opts {
|
||||
for vec::each(opts) {|opt|
|
||||
i += 1u;
|
||||
let mut opt_cx = else_cx;
|
||||
if !exhaustive || i < len {
|
||||
|
@ -570,7 +570,7 @@ fn make_phi_bindings(bcx: block, map: [exit_node],
|
|||
ids.items {|name, node_id|
|
||||
let mut llbbs = [];
|
||||
let mut vals = [];
|
||||
for ex: exit_node in map {
|
||||
for vec::each(map) {|ex|
|
||||
if ex.to as uint == our_block {
|
||||
alt assoc(name, ex.bound) {
|
||||
some(val) { llbbs += [ex.from]; vals += [val]; }
|
||||
|
@ -624,12 +624,12 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: [ast::arm],
|
|||
let {bcx, val, _} = trans_temp_expr(bcx, expr);
|
||||
if bcx.unreachable { ret bcx; }
|
||||
|
||||
for a in arms {
|
||||
for vec::each(arms) {|a|
|
||||
let body = scope_block(bcx, "case_body");
|
||||
body.block_span = some(a.body.span);
|
||||
let id_map = pat_util::pat_id_map(tcx.def_map, a.pats[0]);
|
||||
bodies += [body];
|
||||
for p in a.pats {
|
||||
for vec::each(a.pats) {|p|
|
||||
match += [@{pats: [p],
|
||||
bound: [],
|
||||
data: @{body: body.llbb, guard: a.guard,
|
||||
|
@ -659,7 +659,7 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: [ast::arm],
|
|||
compile_submatch(bcx, match, [spilled], mk_fail, exit_map);
|
||||
|
||||
let mut arm_cxs = [], arm_dests = [], i = 0u;
|
||||
for a in arms {
|
||||
for vec::each(arms) {|a|
|
||||
let body_cx = bodies[i];
|
||||
let id_map = pat_util::pat_id_map(tcx.def_map, a.pats[0]);
|
||||
if make_phi_bindings(body_cx, exit_map, id_map) {
|
||||
|
@ -703,14 +703,14 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef,
|
|||
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
|
||||
let args = extract_variant_args(bcx, pat.id, vdefs, val);
|
||||
let mut i = 0;
|
||||
for argval: ValueRef in args.vals {
|
||||
for vec::each(args.vals) {|argval|
|
||||
bcx = bind_irrefutable_pat(bcx, sub[i], argval, make_copy);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
ast::pat_rec(fields, _) {
|
||||
let rec_fields = ty::get_fields(node_id_type(bcx, pat.id));
|
||||
for f: ast::field_pat in fields {
|
||||
for vec::each(fields) {|f|
|
||||
let ix = option::get(ty::field_idx(f.ident, rec_fields));
|
||||
// how to get rid of this check?
|
||||
let fldptr = GEPi(bcx, val, [0, ix as int]);
|
||||
|
@ -719,7 +719,7 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef,
|
|||
}
|
||||
ast::pat_tup(elems) {
|
||||
let mut i = 0u;
|
||||
for elem in elems {
|
||||
for vec::each(elems) {|elem|
|
||||
let fldptr = GEPi(bcx, val, [0, i as int]);
|
||||
bcx = bind_irrefutable_pat(bcx, elem, fldptr, make_copy);
|
||||
i += 1u;
|
||||
|
|
|
@ -111,7 +111,7 @@ fn join_returns(parent_cx: block, in_cxs: [block],
|
|||
in_ds: [dest], out_dest: dest) -> block {
|
||||
let out = sub_block(parent_cx, "join");
|
||||
let mut reachable = false, i = 0u, phi = none;
|
||||
for cx in in_cxs {
|
||||
for vec::each(in_cxs) {|cx|
|
||||
if !cx.unreachable {
|
||||
Br(cx, out.llbb);
|
||||
reachable = true;
|
||||
|
@ -222,7 +222,7 @@ fn trans_native_call(cx: block, externs: hashmap<str, ValueRef>,
|
|||
let llnative: ValueRef =
|
||||
get_simple_extern_fn(cx, externs, llmod, name, n);
|
||||
let mut call_args: [ValueRef] = [];
|
||||
for a: ValueRef in args {
|
||||
for vec::each(args) {|a|
|
||||
call_args += [ZExtOrBitCast(cx, a, cx.ccx().int_type)];
|
||||
}
|
||||
ret Call(cx, llnative, call_args);
|
||||
|
@ -877,7 +877,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||
ty::ty_fn({inputs: args, _}) {
|
||||
let mut j = 0u;
|
||||
let v_id = variant.id;
|
||||
for a: ty::arg in args {
|
||||
for vec::each(args) {|a|
|
||||
let llfldp_a = GEP_enum(cx, a_tup, tid, v_id, tps, j);
|
||||
let ty_subst = ty::substitute_type_params(ccx.tcx, tps, a.ty);
|
||||
cx = f(cx, llfldp_a, ty_subst);
|
||||
|
@ -895,19 +895,15 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||
let mut cx = cx;
|
||||
alt ty::get(t).struct {
|
||||
ty::ty_rec(fields) {
|
||||
let mut i: int = 0;
|
||||
for fld: ty::field in fields {
|
||||
let llfld_a = GEPi(cx, av, [0, i]);
|
||||
for vec::eachi(fields) {|i, fld|
|
||||
let llfld_a = GEPi(cx, av, [0, i as int]);
|
||||
cx = f(cx, llfld_a, fld.mt.ty);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
ty::ty_tup(args) {
|
||||
let mut i = 0;
|
||||
for arg in args {
|
||||
let llfld_a = GEPi(cx, av, [0, i]);
|
||||
for vec::eachi(args) {|i, arg|
|
||||
let llfld_a = GEPi(cx, av, [0, i as int]);
|
||||
cx = f(cx, llfld_a, arg);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
ty::ty_res(_, inner, tps) {
|
||||
|
@ -939,7 +935,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||
Unreachable(unr_cx);
|
||||
let llswitch = Switch(cx, lldiscrim_a, unr_cx.llbb, n_variants);
|
||||
let next_cx = sub_block(cx, "enum-iter-next");
|
||||
for variant: ty::variant_info in *variants {
|
||||
for vec::each(*variants) {|variant|
|
||||
let variant_cx =
|
||||
sub_block(cx,
|
||||
"enum-iter-variant-" +
|
||||
|
@ -954,7 +950,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||
ty::ty_class(did, tps) {
|
||||
// a class is like a record type
|
||||
let mut i: int = 0;
|
||||
for fld: ty::field in ty::class_items_as_fields(cx.tcx(), did) {
|
||||
for vec::each(ty::class_items_as_fields(cx.tcx(), did)) {|fld|
|
||||
let llfld_a = GEPi(cx, av, [0, i]);
|
||||
cx = f(cx, llfld_a, fld.mt.ty);
|
||||
i += 1;
|
||||
|
@ -1846,7 +1842,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: [ty::t],
|
|||
let mut i = 0u;
|
||||
vec::map2(*bounds, substs, {|bounds, subst|
|
||||
let mut v = [];
|
||||
for bound in *bounds {
|
||||
for vec::each(*bounds) {|bound|
|
||||
alt bound {
|
||||
ty::bound_iface(_) {
|
||||
v += [impl::vtable_id(ccx, vts[i])];
|
||||
|
@ -2889,14 +2885,14 @@ fn trans_tup(bcx: block, elts: [@ast::expr], dest: dest) -> block {
|
|||
let mut bcx = bcx;
|
||||
let addr = alt dest {
|
||||
ignore {
|
||||
for ex in elts { bcx = trans_expr(bcx, ex, ignore); }
|
||||
for vec::each(elts) {|ex| bcx = trans_expr(bcx, ex, ignore); }
|
||||
ret bcx;
|
||||
}
|
||||
save_in(pos) { pos }
|
||||
_ { bcx.tcx().sess.bug("trans_tup: weird dest"); }
|
||||
};
|
||||
let mut temp_cleanups = [], i = 0;
|
||||
for e in elts {
|
||||
for vec::each(elts) {|e|
|
||||
let dst = GEPi(bcx, addr, [0, i]);
|
||||
let e_ty = expr_ty(bcx, e);
|
||||
bcx = trans_expr_save_in(bcx, e, dst);
|
||||
|
@ -2904,7 +2900,7 @@ fn trans_tup(bcx: block, elts: [@ast::expr], dest: dest) -> block {
|
|||
temp_cleanups += [dst];
|
||||
i += 1;
|
||||
}
|
||||
for cleanup in temp_cleanups { revoke_clean(bcx, cleanup); }
|
||||
for vec::each(temp_cleanups) {|cleanup| revoke_clean(bcx, cleanup); }
|
||||
ret bcx;
|
||||
}
|
||||
|
||||
|
@ -2914,21 +2910,18 @@ fn trans_rec(bcx: block, fields: [ast::field],
|
|||
let _icx = bcx.insn_ctxt("trans_rec");
|
||||
let t = node_id_type(bcx, id);
|
||||
let mut bcx = bcx;
|
||||
let addr = alt dest {
|
||||
let addr = alt check dest {
|
||||
ignore {
|
||||
for fld in fields {
|
||||
for vec::each(fields) {|fld|
|
||||
bcx = trans_expr(bcx, fld.node.expr, ignore);
|
||||
}
|
||||
ret bcx;
|
||||
}
|
||||
save_in(pos) { pos }
|
||||
_ { bcx.tcx().sess.bug("trans_rec: weird dest"); }
|
||||
};
|
||||
|
||||
let ty_fields = alt ty::get(t).struct {
|
||||
ty::ty_rec(f) { f }
|
||||
_ { bcx.tcx().sess.bug("trans_rec: id doesn't\
|
||||
have a record type") } };
|
||||
let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) { f } };
|
||||
|
||||
let mut temp_cleanups = [];
|
||||
for fld in fields {
|
||||
let ix = option::get(vec::position(ty_fields, {|ft|
|
||||
|
@ -3584,7 +3577,7 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
|
|||
ast::stmt_decl(d, _) {
|
||||
alt d.node {
|
||||
ast::decl_local(locals) {
|
||||
for local in locals {
|
||||
for vec::each(locals) {|local|
|
||||
bcx = init_local(bcx, local);
|
||||
if cx.sess().opts.extra_debuginfo {
|
||||
debuginfo::create_local_var(bcx, local);
|
||||
|
@ -3702,9 +3695,9 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>,
|
|||
loop {
|
||||
alt cur.kind {
|
||||
block_scope(info) if info.cleanups.len() > 0u {
|
||||
for exists in info.cleanup_paths {
|
||||
if exists.target == leave {
|
||||
Br(bcx, exists.dest);
|
||||
for cp in info.cleanup_paths {
|
||||
if cp.target == leave {
|
||||
Br(bcx, cp.dest);
|
||||
ret;
|
||||
}
|
||||
}
|
||||
|
@ -3770,12 +3763,12 @@ fn with_cond(bcx: block, val: ValueRef, f: fn(block) -> block) -> block {
|
|||
}
|
||||
|
||||
fn block_locals(b: ast::blk, it: fn(@ast::local)) {
|
||||
for s: @ast::stmt in b.node.stmts {
|
||||
for vec::each(b.node.stmts) {|s|
|
||||
alt s.node {
|
||||
ast::stmt_decl(d, _) {
|
||||
alt d.node {
|
||||
ast::decl_local(locals) {
|
||||
for local in locals { it(local); }
|
||||
for vec::each(locals) {|local| it(local); }
|
||||
}
|
||||
_ {/* fall through */ }
|
||||
}
|
||||
|
@ -3829,7 +3822,7 @@ fn trans_block(bcx: block, b: ast::blk, dest: dest)
|
|||
let _icx = bcx.insn_ctxt("trans_block");
|
||||
let mut bcx = bcx;
|
||||
block_locals(b) {|local| bcx = alloc_local(bcx, local); };
|
||||
for s: @ast::stmt in b.node.stmts {
|
||||
for vec::each(b.node.stmts) {|s|
|
||||
debuginfo::update_source_pos(bcx, b.span);
|
||||
bcx = trans_stmt(bcx, *s);
|
||||
}
|
||||
|
@ -3920,7 +3913,7 @@ fn create_llargs_for_fn_args(cx: fn_ctxt,
|
|||
|
||||
// Populate the llargs field of the function context with the ValueRefs
|
||||
// that we get from llvm::LLVMGetParam for each argument.
|
||||
for arg: ast::arg in args {
|
||||
for vec::each(args) {|arg|
|
||||
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
|
||||
assert (llarg as int != 0);
|
||||
// Note that this uses local_mem even for things passed by value.
|
||||
|
@ -3940,7 +3933,7 @@ fn copy_args_to_allocas(fcx: fn_ctxt, bcx: block, args: [ast::arg],
|
|||
tcx.sess.bug("someone forgot\
|
||||
to document an invariant in copy_args_to_allocas!");
|
||||
};
|
||||
for arg in arg_tys {
|
||||
for vec::each(arg_tys) {|arg|
|
||||
let id = args[arg_n].id;
|
||||
let argval = alt fcx.llargs.get(id) { local_mem(v) { v }
|
||||
_ { epic_fail() } };
|
||||
|
@ -4096,13 +4089,12 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id,
|
|||
llfndecl: ValueRef) {
|
||||
let _icx = ccx.insn_ctxt("trans_enum_variant");
|
||||
// Translate variant arguments to function arguments.
|
||||
let mut fn_args = [], i = 0u;
|
||||
for varg in variant.node.args {
|
||||
fn_args += [{mode: ast::expl(ast::by_copy),
|
||||
ty: varg.ty,
|
||||
ident: "arg" + uint::to_str(i, 10u),
|
||||
id: varg.id}];
|
||||
}
|
||||
let fn_args = vec::map(variant.node.args, {|varg|
|
||||
{mode: ast::expl(ast::by_copy),
|
||||
ty: varg.ty,
|
||||
ident: "arg",
|
||||
id: varg.id}
|
||||
});
|
||||
let fcx = new_fn_ctxt_w_id(ccx, [], llfndecl, variant.node.id,
|
||||
param_substs, none);
|
||||
create_llargs_for_fn_args(fcx, no_self, fn_args);
|
||||
|
@ -4127,7 +4119,7 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id,
|
|||
let mut i = 0u;
|
||||
let t_id = local_def(enum_id);
|
||||
let v_id = local_def(variant.node.id);
|
||||
for va: ast::variant_arg in variant.node.args {
|
||||
for vec::each(variant.node.args) {|va|
|
||||
let lldestptr = GEP_enum(bcx, llblobptr, t_id, v_id,
|
||||
ty_param_substs, i);
|
||||
// If this argument to this function is a enum, it'll have come in to
|
||||
|
@ -4270,7 +4262,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
|||
trans_fn(ccx, *path + [path_name(item.ident)], decl, body,
|
||||
llfndecl, no_self, none, item.id);
|
||||
} else {
|
||||
for stmt in body.node.stmts {
|
||||
for vec::each(body.node.stmts) {|stmt|
|
||||
alt stmt.node {
|
||||
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) {
|
||||
trans_item(ccx, *i);
|
||||
|
@ -4301,7 +4293,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
|||
let degen = variants.len() == 1u;
|
||||
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
|
||||
let mut i = 0;
|
||||
for variant: ast::variant in variants {
|
||||
for vec::each(variants) {|variant|
|
||||
if variant.node.args.len() > 0u {
|
||||
let llfn = get_item_val(ccx, variant.node.id);
|
||||
trans_enum_variant(ccx, item.id, variant,
|
||||
|
@ -4331,12 +4323,9 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
|||
// kludgy -- this wouldn't be necessary if the typechecker
|
||||
// special-cased constructors, then we could just look up
|
||||
// the ctor's return type.
|
||||
let mut ty_args = [], i = 0u;
|
||||
for tp in tps {
|
||||
ty_args += [ty::mk_param(ccx.tcx, i,
|
||||
local_def(tps[i].id))];
|
||||
i += 1u;
|
||||
}
|
||||
let ty_args = vec::from_fn(tps.len(), {|i|
|
||||
ty::mk_param(ccx.tcx, i, local_def(tps[i].id))
|
||||
});
|
||||
let rslt_ty = ty::mk_class(ccx.tcx,
|
||||
local_def(item.id),
|
||||
ty_args);
|
||||
|
@ -4383,7 +4372,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
|||
// and control visibility.
|
||||
fn trans_mod(ccx: @crate_ctxt, m: ast::_mod) {
|
||||
let _icx = ccx.insn_ctxt("trans_mod");
|
||||
for item in m.items { trans_item(ccx, *item); }
|
||||
for vec::each(m.items) {|item| trans_item(ccx, *item); }
|
||||
}
|
||||
|
||||
fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
|
||||
|
@ -4620,7 +4609,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
|
|||
node: it.id});
|
||||
let mut i = 0;
|
||||
let path = item_path(ccx, it);
|
||||
for variant in variants {
|
||||
for vec::each(variants) {|variant|
|
||||
let p = path + [path_name(variant.node.name),
|
||||
path_name("discrim")];
|
||||
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
|
||||
|
@ -4933,7 +4922,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
|
|||
io::println(#fmt("n_null_glues: %u", ccx.stats.n_null_glues));
|
||||
io::println(#fmt("n_real_glues: %u", ccx.stats.n_real_glues));
|
||||
|
||||
for timing: {ident: str, time: int} in *ccx.stats.fn_times {
|
||||
for vec::each(copy *ccx.stats.fn_times) {|timing|
|
||||
io::println(#fmt("time: %s took %d ms", timing.ident,
|
||||
timing.time));
|
||||
}
|
||||
|
|
|
@ -429,7 +429,7 @@ fn GEP(cx: block, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
|
|||
// in C_i32()
|
||||
fn GEPi(cx: block, base: ValueRef, ixs: [int]) -> ValueRef {
|
||||
let mut v: [ValueRef] = [];
|
||||
for i: int in ixs { v += [C_i32(i as i32)]; }
|
||||
for vec::each(ixs) {|i| v += [C_i32(i as i32)]; }
|
||||
count_insn(cx, "gepi");
|
||||
ret InBoundsGEP(cx, base, v);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ fn mk_closure_tys(tcx: ty::ctxt,
|
|||
let mut bound_tys = [];
|
||||
|
||||
// Compute the closed over data
|
||||
for bv in bound_values {
|
||||
for vec::each(bound_values) {|bv|
|
||||
bound_tys += [alt bv {
|
||||
env_copy(_, t, _) { t }
|
||||
env_move(_, t, _) { t }
|
||||
|
@ -277,7 +277,7 @@ fn store_environment(bcx: block,
|
|||
}
|
||||
}
|
||||
}
|
||||
for cleanup in temp_cleanups { revoke_clean(bcx, cleanup); }
|
||||
for vec::each(temp_cleanups) {|cleanup| revoke_clean(bcx, cleanup); }
|
||||
|
||||
ret {llbox: llbox, cdata_ty: cdata_ty, bcx: bcx};
|
||||
}
|
||||
|
@ -445,12 +445,12 @@ fn trans_bind_1(cx: block, outgoing_fty: ty::t,
|
|||
let _icx = cx.insn_ctxt("closure::trans_bind1");
|
||||
let ccx = cx.ccx();
|
||||
let mut bound: [@ast::expr] = [];
|
||||
for argopt: option<@ast::expr> in args {
|
||||
for vec::each(args) {|argopt|
|
||||
alt argopt { none { } some(e) { bound += [e]; } }
|
||||
}
|
||||
let mut bcx = f_res.bcx;
|
||||
if dest == ignore {
|
||||
for ex in bound { bcx = trans_expr(bcx, ex, ignore); }
|
||||
for vec::each(bound) {|ex| bcx = trans_expr(bcx, ex, ignore); }
|
||||
ret bcx;
|
||||
}
|
||||
|
||||
|
@ -746,7 +746,7 @@ fn trans_bind_thunk(ccx: @crate_ctxt,
|
|||
let mut a: uint = first_real_arg; // retptr, env come first
|
||||
let mut b: int = starting_idx;
|
||||
let mut outgoing_arg_index: uint = 0u;
|
||||
for arg: option<@ast::expr> in args {
|
||||
for vec::each(args) {|arg|
|
||||
let out_arg = outgoing_args[outgoing_arg_index];
|
||||
alt arg {
|
||||
// Arg provided at binding time; thunk copies it from
|
||||
|
|
|
@ -818,12 +818,12 @@ enum mono_param_id {
|
|||
type mono_id = @{def: ast::def_id, params: [mono_param_id]};
|
||||
fn hash_mono_id(&&mi: mono_id) -> uint {
|
||||
let mut h = syntax::ast_util::hash_def_id(mi.def);
|
||||
for param in mi.params {
|
||||
for vec::each(mi.params) {|param|
|
||||
h = h * alt param {
|
||||
mono_precise(ty, vts) {
|
||||
let mut h = ty::type_id(ty);
|
||||
option::may(vts) {|vts|
|
||||
for vt in vts { h += hash_mono_id(vt); }
|
||||
for vec::each(vts) {|vt| h += hash_mono_id(vt); }
|
||||
}
|
||||
h
|
||||
}
|
||||
|
@ -852,7 +852,7 @@ fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef {
|
|||
|
||||
fn path_str(p: path) -> str {
|
||||
let mut r = "", first = true;
|
||||
for e in p {
|
||||
for vec::each(p) {|e|
|
||||
alt e { ast_map::path_name(s) | ast_map::path_mod(s) {
|
||||
if first { first = false; }
|
||||
else { r += "::"; }
|
||||
|
|
|
@ -19,7 +19,7 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
|
|||
let _icx = ccx.insn_ctxt("impl::trans_impl");
|
||||
if tps.len() > 0u { ret; }
|
||||
let sub_path = path + [path_name(name)];
|
||||
for m in methods {
|
||||
for vec::each(methods) {|m|
|
||||
if m.tps.len() == 0u {
|
||||
let llfn = get_item_val(ccx, m.id);
|
||||
trans_fn(ccx, sub_path + [path_name(m.ident)], m.decl, m.body,
|
||||
|
@ -156,9 +156,9 @@ fn find_vtable_in_fn_ctxt(ps: param_substs, n_param: uint, n_bound: uint)
|
|||
let mut vtable_off = n_bound, i = 0u;
|
||||
// Vtables are stored in a flat array, finding the right one is
|
||||
// somewhat awkward
|
||||
for bounds in *ps.bounds {
|
||||
for vec::each(*ps.bounds) {|bounds|
|
||||
if i >= n_param { break; }
|
||||
for bound in *bounds {
|
||||
for vec::each(*bounds) {|bound|
|
||||
alt bound { ty::bound_iface(_) { vtable_off += 1u; } _ {} }
|
||||
}
|
||||
i += 1u;
|
||||
|
|
|
@ -144,7 +144,7 @@ fn classify_ty(ty: TypeRef) -> [x86_64_reg_class] {
|
|||
classify(T_i64(), cls, i, off);
|
||||
} else {
|
||||
let mut field_off = off;
|
||||
for ty in tys {
|
||||
for vec::each(tys) {|ty|
|
||||
field_off = align(field_off, ty);
|
||||
classify(ty, cls, i, field_off);
|
||||
field_off += ty_size(ty);
|
||||
|
@ -252,7 +252,7 @@ fn classify_ty(ty: TypeRef) -> [x86_64_reg_class] {
|
|||
fn llreg_ty(cls: [x86_64_reg_class]) -> TypeRef {
|
||||
fn llvec_len(cls: [x86_64_reg_class]) -> uint {
|
||||
let mut len = 1u;
|
||||
for c in cls {
|
||||
for vec::each(cls) {|c|
|
||||
if c != sseup_class {
|
||||
break;
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ fn x86_64_tys(atys: [TypeRef],
|
|||
|
||||
let mut arg_tys = [];
|
||||
let mut attrs = [];
|
||||
for t in atys {
|
||||
for vec::each(atys) {|t|
|
||||
let (ty, attr) = x86_64_ty(t, is_pass_byval, ByValAttribute);
|
||||
arg_tys += [ty];
|
||||
attrs += [attr];
|
||||
|
@ -735,7 +735,7 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
|||
ast::native_abi_stdcall { lib::llvm::X86StdcallCallConv }
|
||||
};
|
||||
|
||||
for native_item in native_mod.items {
|
||||
for vec::each(native_mod.items) {|native_item|
|
||||
alt native_item.node {
|
||||
ast::native_item_fn(fn_decl, _) {
|
||||
let id = native_item.id;
|
||||
|
|
|
@ -31,11 +31,11 @@ fn find_reachable(crate_mod: _mod, exp_map: resolve::exp_map,
|
|||
|
||||
fn traverse_exports(cx: ctx, vis: [@view_item]) -> bool {
|
||||
let mut found_export = false;
|
||||
for vi in vis {
|
||||
for vec::each(vis) {|vi|
|
||||
alt vi.node {
|
||||
view_item_export(vps) {
|
||||
found_export = true;
|
||||
for vp in vps {
|
||||
for vec::each(vps) {|vp|
|
||||
alt vp.node {
|
||||
view_path_simple(_, _, id) | view_path_glob(_, id) |
|
||||
view_path_list(_, _, id) {
|
||||
|
@ -52,7 +52,7 @@ fn traverse_exports(cx: ctx, vis: [@view_item]) -> bool {
|
|||
|
||||
fn traverse_export(cx: ctx, exp_id: node_id) {
|
||||
option::may(cx.exp_map.find(exp_id)) {|defs|
|
||||
for def in defs { traverse_def_id(cx, def.id); }
|
||||
for vec::each(defs) {|def| traverse_def_id(cx, def.id); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ fn traverse_def_id(cx: ctx, did: def_id) {
|
|||
fn traverse_public_mod(cx: ctx, m: _mod) {
|
||||
if !traverse_exports(cx, m.view_items) {
|
||||
// No exports, so every local item is exported
|
||||
for item in m.items { traverse_public_item(cx, item); }
|
||||
for vec::each(m.items) {|item| traverse_public_item(cx, item); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
|||
item_mod(m) { traverse_public_mod(cx, m); }
|
||||
item_native_mod(nm) {
|
||||
if !traverse_exports(cx, nm.view_items) {
|
||||
for item in nm.items { cx.rmap.insert(item.id, ()); }
|
||||
for vec::each(nm.items) {|item| cx.rmap.insert(item.id, ()); }
|
||||
}
|
||||
}
|
||||
item_res(_, tps, blk, _, _) | item_fn(_, tps, blk) {
|
||||
|
@ -91,7 +91,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
|||
}
|
||||
}
|
||||
item_impl(tps, _, _, ms) {
|
||||
for m in ms {
|
||||
for vec::each(ms) {|m|
|
||||
if tps.len() > 0u || m.tps.len() > 0u ||
|
||||
attr::find_inline_attr(m.attrs) != attr::ia_none {
|
||||
traverse_inline_body(cx, m.body);
|
||||
|
@ -100,7 +100,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
|||
}
|
||||
item_class(tps, items, ctor) {
|
||||
cx.rmap.insert(ctor.node.id, ());
|
||||
for item in items {
|
||||
for vec::each(items) {|item|
|
||||
alt item.node.decl {
|
||||
class_method(m) {
|
||||
cx.rmap.insert(m.id, ());
|
||||
|
|
|
@ -66,7 +66,7 @@ fn hash_res_info(ri: res_info) -> uint {
|
|||
h += ri.did.crate as uint;
|
||||
h *= 33u;
|
||||
h += ri.did.node as uint;
|
||||
for t in ri.tps {
|
||||
for vec::each(ri.tps) {|t|
|
||||
h *= 33u;
|
||||
h += ty::type_id(t);
|
||||
}
|
||||
|
@ -104,10 +104,10 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
|||
// just T.
|
||||
let mut ranges = [];
|
||||
let variants = ty::enum_variants(ccx.tcx, tag_id);
|
||||
for variant: ty::variant_info in *variants {
|
||||
for vec::each(*variants) {|variant|
|
||||
let mut bounded = true;
|
||||
let mut min_size = 0u, min_align = 0u;
|
||||
for elem_t: ty::t in variant.args {
|
||||
for vec::each(variant.args) {|elem_t|
|
||||
if ty::type_has_params(elem_t) {
|
||||
// FIXME: We could do better here; this causes us to
|
||||
// conservatively assume that (int, T) has minimum size 0,
|
||||
|
@ -127,7 +127,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
|||
|
||||
// Initialize the candidate set to contain all variants.
|
||||
let mut candidates = [mut];
|
||||
for variant in *variants { candidates += [mut true]; }
|
||||
for vec::each(*variants) {|_v| candidates += [mut true]; }
|
||||
|
||||
// Do a pairwise comparison among all variants still in the candidate set.
|
||||
// Throw out any variant that we know has size and alignment at least as
|
||||
|
@ -180,10 +180,10 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
|
|||
let mut max_size = 0u16;
|
||||
let mut max_align = 1u8;
|
||||
let variants = ty::enum_variants(ccx.tcx, did);
|
||||
for vid: uint in largest_variants {
|
||||
for vec::each(largest_variants) {|vid|
|
||||
// We increment a "virtual data pointer" to compute the size.
|
||||
let mut lltys = [];
|
||||
for typ: ty::t in variants[vid].args {
|
||||
for vec::each(variants[vid].args) {|typ|
|
||||
lltys += [type_of::type_of(ccx, typ)];
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
|||
add_u16(s, id as u16);
|
||||
|
||||
add_u16(s, vec::len(tps) as u16);
|
||||
for tp: ty::t in tps {
|
||||
for vec::each(tps) {|tp|
|
||||
let subshape = shape_of(ccx, tp, ty_param_map);
|
||||
add_u16(s, vec::len(subshape) as u16);
|
||||
s += subshape;
|
||||
|
@ -355,7 +355,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
|||
}
|
||||
ty::ty_rec(fields) {
|
||||
let mut s = [shape_struct], sub = [];
|
||||
for f: field in fields {
|
||||
for vec::each(fields) {|f|
|
||||
sub += shape_of(ccx, f.mt.ty, ty_param_map);
|
||||
}
|
||||
add_substr(s, sub);
|
||||
|
@ -363,7 +363,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
|||
}
|
||||
ty::ty_tup(elts) {
|
||||
let mut s = [shape_struct], sub = [];
|
||||
for elt in elts {
|
||||
for vec::each(elts) {|elt|
|
||||
sub += shape_of(ccx, elt, ty_param_map);
|
||||
}
|
||||
add_substr(s, sub);
|
||||
|
@ -384,7 +384,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
|||
let mut s = [shape_res];
|
||||
add_u16(s, id as u16);
|
||||
add_u16(s, vec::len(tps) as u16);
|
||||
for tp: ty::t in tps {
|
||||
for vec::each(tps) {|tp|
|
||||
add_substr(s, shape_of(ccx, tp, ty_param_map));
|
||||
}
|
||||
add_substr(s, shape_of(ccx, subt, ty_param_map));
|
||||
|
@ -418,7 +418,7 @@ fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
|
|||
while i < ty_param_count { ty_param_map += [i]; i += 1u; }
|
||||
|
||||
let mut s = [];
|
||||
for t: ty::t in v.args { s += shape_of(ccx, t, ty_param_map); }
|
||||
for vec::each(v.args) {|t| s += shape_of(ccx, t, ty_param_map); }
|
||||
ret s;
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
|
|||
let data_sz = vec::len(data) as u16;
|
||||
|
||||
let mut info_sz = 0u16;
|
||||
for did_: ast::def_id in ccx.shape_cx.tag_order {
|
||||
for did_ in ccx.shape_cx.tag_order {
|
||||
let did = did_; // Satisfy alias checker.
|
||||
let num_variants = vec::len(*ty::enum_variants(ccx.tcx, did)) as u16;
|
||||
add_u16(header, header_sz + info_sz);
|
||||
|
@ -471,7 +471,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
|
|||
|
||||
let mut lv_table = [];
|
||||
i = 0u;
|
||||
for did_: ast::def_id in ccx.shape_cx.tag_order {
|
||||
for did_ in ccx.shape_cx.tag_order {
|
||||
let did = did_; // Satisfy alias checker.
|
||||
let variants = ty::enum_variants(ccx.tcx, did);
|
||||
add_u16(info, vec::len(*variants) as u16);
|
||||
|
@ -482,7 +482,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
|
|||
|
||||
let lv = largest_variants(ccx, did);
|
||||
add_u16(lv_table, vec::len(lv) as u16);
|
||||
for v: uint in lv { add_u16(lv_table, v as u16); }
|
||||
for vec::each(lv) {|v| add_u16(lv_table, v as u16); }
|
||||
|
||||
// Determine whether the enum has dynamic size.
|
||||
let dynamic = vec::any(*variants, {|v|
|
||||
|
@ -498,7 +498,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
|
|||
info += [size_align.align];
|
||||
|
||||
// Now write in the offset of each variant.
|
||||
for v: ty::variant_info in *variants {
|
||||
for vec::each(*variants) {|_v|
|
||||
add_u16(info, header_sz + info_sz + offsets[i]);
|
||||
i += 1u;
|
||||
}
|
||||
|
@ -594,7 +594,7 @@ fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
|
|||
// Compute max(variant sizes).
|
||||
let mut max_size = 0u;
|
||||
let variants = ty::enum_variants(cx.tcx, tid);
|
||||
for variant: ty::variant_info in *variants {
|
||||
for vec::each(*variants) {|variant|
|
||||
let tup_ty = simplify_type(cx.tcx,
|
||||
ty::mk_tup(cx.tcx, variant.args));
|
||||
// Perform any type parameter substitutions.
|
||||
|
|
|
@ -103,7 +103,7 @@ fn trans_vec(bcx: block, args: [@ast::expr], id: ast::node_id,
|
|||
let ccx = bcx.ccx();
|
||||
let mut bcx = bcx;
|
||||
if dest == base::ignore {
|
||||
for arg in args {
|
||||
for vec::each(args) {|arg|
|
||||
bcx = base::trans_expr(bcx, arg, base::ignore);
|
||||
}
|
||||
ret bcx;
|
||||
|
@ -118,14 +118,14 @@ fn trans_vec(bcx: block, args: [@ast::expr], id: ast::node_id,
|
|||
// Store the individual elements.
|
||||
let dataptr = get_dataptr(bcx, vptr, llunitty);
|
||||
let mut i = 0u, temp_cleanups = [vptr];
|
||||
for e in args {
|
||||
for vec::each(args) {|e|
|
||||
let lleltptr = InBoundsGEP(bcx, dataptr, [C_uint(ccx, i)]);
|
||||
bcx = base::trans_expr_save_in(bcx, e, lleltptr);
|
||||
add_clean_temp_mem(bcx, lleltptr, unit_ty);
|
||||
temp_cleanups += [lleltptr];
|
||||
i += 1u;
|
||||
}
|
||||
for cln in temp_cleanups { revoke_clean(bcx, cln); }
|
||||
for vec::each(temp_cleanups) {|cln| revoke_clean(bcx, cln); }
|
||||
ret base::store_in_dest(bcx, vptr, dest);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
|
|||
let elt_llty = type_of::type_of(ccx, elt_ty);
|
||||
let elt_sz = shape::llsize_of(ccx, elt_llty);
|
||||
let scratch = base::alloca(bcx, elt_llty);
|
||||
for val in vals {
|
||||
for vec::each(vals) {|val|
|
||||
bcx = base::trans_expr_save_in(bcx, val, scratch);
|
||||
let vptr = Load(bcx, vptrptr);
|
||||
let old_fill = get_fill(bcx, vptr);
|
||||
|
|
|
@ -58,7 +58,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
|
|||
ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) }
|
||||
ty::ty_rec(fields) {
|
||||
let mut tys: [TypeRef] = [];
|
||||
for f: ty::field in fields {
|
||||
for vec::each(fields) {|f|
|
||||
let mt_ty = f.mt.ty;
|
||||
tys += [type_of(cx, mt_ty)];
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
|
|||
ty::ty_type { T_ptr(cx.tydesc_type) }
|
||||
ty::ty_tup(elts) {
|
||||
let mut tys = [];
|
||||
for elt in elts {
|
||||
for vec::each(elts) {|elt|
|
||||
tys += [type_of(cx, elt)];
|
||||
}
|
||||
T_struct(tys)
|
||||
|
|
|
@ -45,7 +45,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
|
|||
let cx = {ccx: ccx, uses: vec::to_mut(vec::from_elem(n_tps, 0u))};
|
||||
alt ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct {
|
||||
ty::ty_fn({inputs, _}) {
|
||||
for arg in inputs {
|
||||
for vec::each(inputs) {|arg|
|
||||
if arg.mode == expl(by_val) { type_needs(cx, use_repr, arg.ty); }
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
|
|||
fn type_needs(cx: ctx, use: uint, ty: ty::t) {
|
||||
let mut done = true;
|
||||
// Optimization -- don't descend type if all params already have this use
|
||||
for u in cx.uses { if u & use != use { done = false } }
|
||||
for vec::each(cx.uses) {|u| if u & use != use { done = false } }
|
||||
if !done { type_needs_inner(cx, use, ty); }
|
||||
}
|
||||
|
||||
|
@ -101,8 +101,8 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t) {
|
|||
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _) |
|
||||
ty::ty_box(_) | ty::ty_iface(_, _) { false }
|
||||
ty::ty_enum(did, tps) {
|
||||
for v in *ty::enum_variants(cx.ccx.tcx, did) {
|
||||
for aty in v.args {
|
||||
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) {|v|
|
||||
for vec::each(v.args) {|aty|
|
||||
let t = ty::substitute_type_params(cx.ccx.tcx, tps,
|
||||
aty);
|
||||
type_needs_inner(cx, use, t);
|
||||
|
@ -152,7 +152,7 @@ fn mark_for_expr(cx: ctx, e: @expr) {
|
|||
alt ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
|
||||
proto_bare | proto_any | proto_uniq {}
|
||||
proto_box | proto_block {
|
||||
for fv in *freevars::get_freevars(cx.ccx.tcx, e.id) {
|
||||
for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) {|fv|
|
||||
let node_id = ast_util::def_id_of_def(fv.def).node;
|
||||
node_type_needs(cx, use_repr, node_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue