auto merge of #5279 : alexcrichton/rust/no-dvec, r=pcwalton
Closes #4985 by removing the `dvec` module and all use cases throughout the compiler. A number of uses were directly convertible to `let mut foo = ~[];`, while others in hash maps and some fields had to be converted to `@mut ~[T]`. A small number of `DVec` instances in fields were able to be converted directly to `~[T]` without the `@`, but this was a difficult thing to do.
This commit is contained in:
commit
3bbcac3226
41 changed files with 327 additions and 902 deletions
|
@ -21,10 +21,10 @@ used features.
|
||||||
the floating point types, the `bool` type, tuples, characters, strings,
|
the floating point types, the `bool` type, tuples, characters, strings,
|
||||||
vectors (`vec`), managed boxes (`managed`), owned boxes (`owned`), and unsafe
|
vectors (`vec`), managed boxes (`managed`), owned boxes (`owned`), and unsafe
|
||||||
and borrowed pointers (`ptr`). Additionally, `core` provides task management
|
and borrowed pointers (`ptr`). Additionally, `core` provides task management
|
||||||
and creation (`task`), communication primitives (`comm` and `pipes`), an
|
and creation (`task`), communication primitives (`comm` and `pipes`), platform
|
||||||
efficient vector builder (`dvec`), platform abstractions (`os` and `path`),
|
abstractions (`os` and `path`), basic I/O abstractions (`io`), common traits
|
||||||
basic I/O abstractions (`io`), common traits (`cmp`, `num`, `to_str`), and
|
(`cmp`, `num`, `to_str`), and complete bindings to the C standard library
|
||||||
complete bindings to the C standard library (`libc`).
|
(`libc`).
|
||||||
|
|
||||||
`core` is linked to all crates by default and its contents imported.
|
`core` is linked to all crates by default and its contents imported.
|
||||||
Implicitly, all crates behave as if they included the following prologue:
|
Implicitly, all crates behave as if they included the following prologue:
|
||||||
|
@ -141,9 +141,6 @@ pub mod container;
|
||||||
pub mod option;
|
pub mod option;
|
||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod either;
|
pub mod either;
|
||||||
pub mod dvec;
|
|
||||||
#[path="iter-trait.rs"] #[merge = "iter-trait/dvec.rs"]
|
|
||||||
pub mod dvec_iter;
|
|
||||||
pub mod dlist;
|
pub mod dlist;
|
||||||
#[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"]
|
#[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"]
|
||||||
pub mod dlist_iter;
|
pub mod dlist_iter;
|
||||||
|
|
|
@ -1,355 +0,0 @@
|
||||||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
/*!
|
|
||||||
|
|
||||||
Dynamic vector
|
|
||||||
|
|
||||||
A growable vector that makes use of unique pointers so that the
|
|
||||||
result can be sent between tasks and so forth.
|
|
||||||
|
|
||||||
Note that recursive use is not permitted.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
use cast;
|
|
||||||
use prelude::*;
|
|
||||||
use ptr::null;
|
|
||||||
use vec;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A growable, modifiable vector type that accumulates elements into a
|
|
||||||
* unique vector.
|
|
||||||
*
|
|
||||||
* # Limitations on recursive use
|
|
||||||
*
|
|
||||||
* This class works by swapping the unique vector out of the data
|
|
||||||
* structure whenever it is to be used. Therefore, recursive use is not
|
|
||||||
* permitted. That is, while iterating through a vector, you cannot
|
|
||||||
* access the vector in any other way or else the program will fail. If
|
|
||||||
* you wish, you can use the `swap()` method to gain access to the raw
|
|
||||||
* vector and transform it or use it any way you like. Eventually, we
|
|
||||||
* may permit read-only access during iteration or other use.
|
|
||||||
*
|
|
||||||
* # WARNING
|
|
||||||
*
|
|
||||||
* For maximum performance, this type is implemented using some rather
|
|
||||||
* unsafe code. In particular, this innocent looking `~[mut A]` pointer
|
|
||||||
* *may be null!* Therefore, it is important you not reach into the
|
|
||||||
* data structure manually but instead use the provided extensions.
|
|
||||||
*
|
|
||||||
* The reason that I did not use an unsafe pointer in the structure
|
|
||||||
* itself is that I wanted to ensure that the vector would be freed when
|
|
||||||
* the dvec is dropped. The reason that I did not use an `Option<T>`
|
|
||||||
* instead of a nullable pointer is that I found experimentally that it
|
|
||||||
* becomes approximately 50% slower. This can probably be improved
|
|
||||||
* through optimization. You can run your own experiments using
|
|
||||||
* `src/test/bench/vec-append.rs`. My own tests found that using null
|
|
||||||
* pointers achieved about 103 million pushes/second. Using an option
|
|
||||||
* type could only produce 47 million pushes/second.
|
|
||||||
*/
|
|
||||||
pub struct DVec<A> {
|
|
||||||
mut data: ~[A]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new, empty dvec
|
|
||||||
pub pure fn DVec<A>() -> DVec<A> {
|
|
||||||
DVec {data: ~[]}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new dvec with a single element
|
|
||||||
pub pure fn from_elem<A>(e: A) -> DVec<A> {
|
|
||||||
DVec {data: ~[e]}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new dvec with the contents of a vector
|
|
||||||
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
|
|
||||||
DVec {data: v}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Consumes the vector and returns its contents
|
|
||||||
pub pure fn unwrap<A>(d: DVec<A>) -> ~[A] {
|
|
||||||
let DVec {data: v} = d;
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
priv impl<A> DVec<A> {
|
|
||||||
#[inline(always)]
|
|
||||||
pure fn check_not_borrowed(&self) {
|
|
||||||
unsafe {
|
|
||||||
let data: *() = cast::reinterpret_cast(&self.data);
|
|
||||||
if data.is_null() {
|
|
||||||
fail!(~"Recursive use of dvec");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn give_back(&self, data: ~[A]) {
|
|
||||||
unsafe {
|
|
||||||
self.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn unwrap(self) -> ~[A] { unwrap(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// In theory, most everything should work with any A, but in practice
|
|
||||||
// almost nothing works without the copy bound due to limitations
|
|
||||||
// around closures.
|
|
||||||
pub impl<A> DVec<A> {
|
|
||||||
// FIXME (#3758): This should not need to be public.
|
|
||||||
#[inline(always)]
|
|
||||||
fn check_out<B>(&self, f: &fn(v: ~[A]) -> B) -> B {
|
|
||||||
unsafe {
|
|
||||||
let mut data = cast::reinterpret_cast(&null::<()>());
|
|
||||||
data <-> self.data;
|
|
||||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
|
||||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
|
||||||
return f(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reserves space for N elements
|
|
||||||
fn reserve(&self, count: uint) {
|
|
||||||
vec::reserve(&mut self.data, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swaps out the current vector and hands it off to a user-provided
|
|
||||||
* function `f`. The function should transform it however is desired
|
|
||||||
* and return a new vector to replace it with.
|
|
||||||
*/
|
|
||||||
#[inline(always)]
|
|
||||||
fn swap(&self, f: &fn(v: ~[A]) -> ~[A]) {
|
|
||||||
self.check_out(|v| self.give_back(f(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the number of elements currently in the dvec
|
|
||||||
#[inline(always)]
|
|
||||||
pure fn len(&self) -> uint {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
return self.data.len();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overwrite the current contents
|
|
||||||
#[inline(always)]
|
|
||||||
fn set(&self, w: ~[A]) {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
self.data = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove and return the last element
|
|
||||||
fn pop(&self) -> A {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let mut v = v;
|
|
||||||
let result = v.pop();
|
|
||||||
self.give_back(v);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert a single item at the front of the list
|
|
||||||
fn unshift(&self, t: A) {
|
|
||||||
unsafe {
|
|
||||||
let mut data = cast::reinterpret_cast(&null::<()>());
|
|
||||||
data <-> self.data;
|
|
||||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
|
||||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
|
||||||
self.data = ~[t];
|
|
||||||
self.data.push_all_move(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Append a single item to the end of the list
|
|
||||||
#[inline(always)]
|
|
||||||
fn push(&self, t: A) {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
self.data.push(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove and return the first element
|
|
||||||
fn shift(&self) -> A {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let mut v = v;
|
|
||||||
let result = v.shift();
|
|
||||||
self.give_back(v);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reverse the elements in the list, in place
|
|
||||||
fn reverse(&self) {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let mut v = v;
|
|
||||||
vec::reverse(v);
|
|
||||||
self.give_back(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gives access to the vector as a slice with immutable contents
|
|
||||||
fn borrow<R>(&self, op: fn(x: &[A]) -> R) -> R {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let result = op(v);
|
|
||||||
self.give_back(v);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gives access to the vector as a slice with mutable contents
|
|
||||||
fn borrow_mut<R>(&self, op: &fn(x: &mut [A]) -> R) -> R {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let mut v = v;
|
|
||||||
let result = op(v);
|
|
||||||
self.give_back(v);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub impl<A:Copy> DVec<A> {
|
|
||||||
/**
|
|
||||||
* Append all elements of a vector to the end of the list
|
|
||||||
*
|
|
||||||
* Equivalent to `append_iter()` but potentially more efficient.
|
|
||||||
*/
|
|
||||||
fn push_all(&self, ts: &[const A]) {
|
|
||||||
self.push_slice(ts, 0u, vec::len(ts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Appends elements from `from_idx` to `to_idx` (exclusive)
|
|
||||||
fn push_slice(&self, ts: &[const A], from_idx: uint, to_idx: uint) {
|
|
||||||
do self.swap |v| {
|
|
||||||
let mut v = v;
|
|
||||||
let new_len = vec::len(v) + to_idx - from_idx;
|
|
||||||
vec::reserve(&mut v, new_len);
|
|
||||||
let mut i = from_idx;
|
|
||||||
while i < to_idx {
|
|
||||||
v.push(ts[i]);
|
|
||||||
i += 1u;
|
|
||||||
}
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append all elements of an iterable.
|
|
||||||
*
|
|
||||||
* Failure will occur if the iterable's `each()` method
|
|
||||||
* attempts to access this vector.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
|
|
||||||
do self.swap |v| {
|
|
||||||
let mut v = match ts.size_hint() {
|
|
||||||
none { v }
|
|
||||||
Some(h) {
|
|
||||||
let len = v.len() + h;
|
|
||||||
let mut v = v;
|
|
||||||
vec::reserve(v, len);
|
|
||||||
v
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for ts.each |t| { v.push(*t) };
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a copy of the current contents.
|
|
||||||
*
|
|
||||||
* See `unwrap()` if you do not wish to copy the contents.
|
|
||||||
*/
|
|
||||||
pure fn get(&self) -> ~[A] {
|
|
||||||
unsafe {
|
|
||||||
do self.check_out |v| {
|
|
||||||
let w = copy v;
|
|
||||||
self.give_back(v);
|
|
||||||
w
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Copy out an individual element
|
|
||||||
#[inline(always)]
|
|
||||||
pure fn get_elt(&self, idx: uint) -> A {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
return self.data[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overwrites the contents of the element at `idx` with `a`
|
|
||||||
fn set_elt(&self, idx: uint, a: A) {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
self.data[idx] = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites the contents of the element at `idx` with `a`,
|
|
||||||
* growing the vector if necessary. New elements will be initialized
|
|
||||||
* with `initval`
|
|
||||||
*/
|
|
||||||
fn grow_set_elt(&self, idx: uint, initval: &A, val: A) {
|
|
||||||
do self.swap |v| {
|
|
||||||
let mut v = v;
|
|
||||||
v.grow_set(idx, initval, val);
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the last element, failing if the vector is empty
|
|
||||||
#[inline(always)]
|
|
||||||
pure fn last(&self) -> A {
|
|
||||||
self.check_not_borrowed();
|
|
||||||
|
|
||||||
let length = self.len();
|
|
||||||
if length == 0 {
|
|
||||||
fail!(~"attempt to retrieve the last element of an empty vector");
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.data[length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Iterates over the elements in reverse order
|
|
||||||
#[inline(always)]
|
|
||||||
fn rev_each(&self, f: fn(v: &A) -> bool) {
|
|
||||||
do self.swap |v| {
|
|
||||||
// FIXME(#2263)---we should be able to write
|
|
||||||
// `vec::rev_each(v, f);` but we cannot write now
|
|
||||||
for vec::rev_each(v) |e| {
|
|
||||||
if !f(e) { break; }
|
|
||||||
}
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Iterates over the elements and indices in reverse order
|
|
||||||
#[inline(always)]
|
|
||||||
fn rev_eachi(&self, f: fn(uint, v: &A) -> bool) {
|
|
||||||
do self.swap |v| {
|
|
||||||
// FIXME(#2263)---we should be able to write
|
|
||||||
// `vec::rev_eachi(v, f);` but we cannot write now
|
|
||||||
for vec::rev_eachi(v) |i, e| {
|
|
||||||
if !f(i, e) { break; }
|
|
||||||
}
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A:Copy> Index<uint,A> for DVec<A> {
|
|
||||||
#[inline(always)]
|
|
||||||
pure fn index(&self, idx: uint) -> A {
|
|
||||||
self.get_elt(idx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ Basic input/output
|
||||||
|
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
use dvec::DVec;
|
|
||||||
use int;
|
use int;
|
||||||
use libc;
|
use libc;
|
||||||
use libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
|
use libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
|
||||||
|
@ -1109,30 +1108,25 @@ pub fn print(s: &str) { stdout().write_str(s); }
|
||||||
pub fn println(s: &str) { stdout().write_line(s); }
|
pub fn println(s: &str) { stdout().write_line(s); }
|
||||||
|
|
||||||
pub struct BytesWriter {
|
pub struct BytesWriter {
|
||||||
bytes: DVec<u8>,
|
mut bytes: ~[u8],
|
||||||
mut pos: uint,
|
mut pos: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer for BytesWriter {
|
impl Writer for BytesWriter {
|
||||||
fn write(&self, v: &[const u8]) {
|
fn write(&self, v: &[const u8]) {
|
||||||
do self.bytes.swap |bytes| {
|
let v_len = v.len();
|
||||||
let mut bytes = bytes;
|
let bytes_len = self.bytes.len();
|
||||||
let v_len = v.len();
|
|
||||||
let bytes_len = bytes.len();
|
|
||||||
|
|
||||||
let count = uint::max(bytes_len, self.pos + v_len);
|
let count = uint::max(bytes_len, self.pos + v_len);
|
||||||
vec::reserve(&mut bytes, count);
|
vec::reserve(&mut self.bytes, count);
|
||||||
unsafe { vec::raw::set_len(&mut bytes, count); }
|
|
||||||
|
|
||||||
{
|
unsafe {
|
||||||
let view = vec::mut_slice(bytes, self.pos, count);
|
vec::raw::set_len(&mut self.bytes, count);
|
||||||
vec::bytes::copy_memory(view, v, v_len);
|
let view = vec::mut_slice(self.bytes, self.pos, count);
|
||||||
}
|
vec::bytes::copy_memory(view, v, v_len);
|
||||||
|
|
||||||
self.pos += v_len;
|
|
||||||
|
|
||||||
bytes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.pos += v_len;
|
||||||
}
|
}
|
||||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
|
@ -1145,14 +1139,14 @@ impl Writer for BytesWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn BytesWriter() -> BytesWriter {
|
pub pure fn BytesWriter() -> BytesWriter {
|
||||||
BytesWriter { bytes: DVec(), mut pos: 0u }
|
BytesWriter { bytes: ~[], mut pos: 0u }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
|
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
|
||||||
let wr = @BytesWriter();
|
let wr = @BytesWriter();
|
||||||
f(wr as Writer);
|
f(wr as Writer);
|
||||||
// FIXME (#3758): This should not be needed.
|
let @BytesWriter{bytes, _} = wr;
|
||||||
unsafe { wr.bytes.check_out(|bytes| bytes) }
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
||||||
|
@ -1448,17 +1442,15 @@ mod tests {
|
||||||
fn bytes_buffer_overwrite() {
|
fn bytes_buffer_overwrite() {
|
||||||
let wr = BytesWriter();
|
let wr = BytesWriter();
|
||||||
wr.write(~[0u8, 1u8, 2u8, 3u8]);
|
wr.write(~[0u8, 1u8, 2u8, 3u8]);
|
||||||
fail_unless!(wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8]));
|
fail_unless!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]);
|
||||||
wr.seek(-2, SeekCur);
|
wr.seek(-2, SeekCur);
|
||||||
wr.write(~[4u8, 5u8, 6u8, 7u8]);
|
wr.write(~[4u8, 5u8, 6u8, 7u8]);
|
||||||
fail_unless!(wr.bytes.borrow(|bytes| bytes ==
|
fail_unless!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
|
||||||
~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]));
|
|
||||||
wr.seek(-2, SeekEnd);
|
wr.seek(-2, SeekEnd);
|
||||||
wr.write(~[8u8]);
|
wr.write(~[8u8]);
|
||||||
wr.seek(1, SeekSet);
|
wr.seek(1, SeekSet);
|
||||||
wr.write(~[9u8]);
|
wr.write(~[9u8]);
|
||||||
fail_unless!(wr.bytes.borrow(|bytes| bytes ==
|
fail_unless!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
|
||||||
~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
mod inst {
|
|
||||||
use dvec;
|
|
||||||
use option::{Option, Some};
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub type IMPL_T<A> = dvec::DVec<A>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterates through the current contents.
|
|
||||||
*
|
|
||||||
* Attempts to access this dvec during iteration will fail.
|
|
||||||
*/
|
|
||||||
#[inline(always)]
|
|
||||||
pub pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
|
|
||||||
unsafe {
|
|
||||||
do self.swap |v| {
|
|
||||||
v.each(f);
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
|
|
||||||
Some(self.len())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -50,7 +50,6 @@ pub use bool;
|
||||||
pub use cast;
|
pub use cast;
|
||||||
pub use char;
|
pub use char;
|
||||||
pub use cmp;
|
pub use cmp;
|
||||||
pub use dvec;
|
|
||||||
pub use either;
|
pub use either;
|
||||||
pub use f32;
|
pub use f32;
|
||||||
pub use f64;
|
pub use f64;
|
||||||
|
|
|
@ -16,7 +16,6 @@ More runtime type reflection
|
||||||
|
|
||||||
use cast::transmute;
|
use cast::transmute;
|
||||||
use char;
|
use char;
|
||||||
use dvec::DVec;
|
|
||||||
use intrinsic;
|
use intrinsic;
|
||||||
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
|
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
|
||||||
use io::{Writer, WriterUtil};
|
use io::{Writer, WriterUtil};
|
||||||
|
@ -147,14 +146,14 @@ enum VariantState {
|
||||||
|
|
||||||
pub struct ReprVisitor {
|
pub struct ReprVisitor {
|
||||||
mut ptr: *c_void,
|
mut ptr: *c_void,
|
||||||
ptr_stk: DVec<*c_void>,
|
mut ptr_stk: ~[*c_void],
|
||||||
var_stk: DVec<VariantState>,
|
mut var_stk: ~[VariantState],
|
||||||
writer: @Writer
|
writer: @Writer
|
||||||
}
|
}
|
||||||
pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor {
|
pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor {
|
||||||
ReprVisitor { ptr: ptr,
|
ReprVisitor { ptr: ptr,
|
||||||
ptr_stk: DVec(),
|
ptr_stk: ~[],
|
||||||
var_stk: DVec(),
|
var_stk: ~[],
|
||||||
writer: writer }
|
writer: writer }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +499,7 @@ impl TyVisitor for ReprVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
|
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
|
||||||
match self.var_stk.last() {
|
match self.var_stk[self.var_stk.len() - 1] {
|
||||||
Degenerate | TagMatch => {
|
Degenerate | TagMatch => {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
self.writer.write_str(", ");
|
self.writer.write_str(", ");
|
||||||
|
@ -518,7 +517,7 @@ impl TyVisitor for ReprVisitor {
|
||||||
_disr_val: int,
|
_disr_val: int,
|
||||||
n_fields: uint,
|
n_fields: uint,
|
||||||
_name: &str) -> bool {
|
_name: &str) -> bool {
|
||||||
match self.var_stk.last() {
|
match self.var_stk[self.var_stk.len() - 1] {
|
||||||
Degenerate | TagMatch => {
|
Degenerate | TagMatch => {
|
||||||
if n_fields > 0 {
|
if n_fields > 0 {
|
||||||
self.writer.write_char(')');
|
self.writer.write_char(')');
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
use cast;
|
use cast;
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
use dvec;
|
|
||||||
use libc;
|
use libc;
|
||||||
use option;
|
use option;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
@ -35,11 +34,11 @@ impl Eq for LocalData {
|
||||||
pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
|
pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use dvec because it's the best data structure in core. If TLS is used
|
// If TLS is used heavily in future, this could be made more efficient with a
|
||||||
// heavily in future, this could be made more efficient with a proper map.
|
// proper map.
|
||||||
type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
|
type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
|
||||||
// Has to be a pointer at outermost layer; the foreign call returns void *.
|
// Has to be a pointer at outermost layer; the foreign call returns void *.
|
||||||
type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
|
type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
|
||||||
|
|
||||||
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
|
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -60,17 +59,21 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
||||||
// drop when they finish. No "re-storing after modifying" is needed.
|
// drop when they finish. No "re-storing after modifying" is needed.
|
||||||
let map_ptr = rt::rust_get_task_local_data(task);
|
let map_ptr = rt::rust_get_task_local_data(task);
|
||||||
if map_ptr.is_null() {
|
if map_ptr.is_null() {
|
||||||
let map: TaskLocalMap = @dvec::DVec();
|
let map: TaskLocalMap = @mut ~[];
|
||||||
// Use reinterpret_cast -- transmute would take map away from us also.
|
// Use reinterpret_cast -- transmute would take map away from us also.
|
||||||
rt::rust_set_task_local_data(
|
rt::rust_set_task_local_data(
|
||||||
task, cast::reinterpret_cast(&map));
|
task, cast::reinterpret_cast(&map));
|
||||||
rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
||||||
// Also need to reference it an extra time to keep it for now.
|
// Also need to reference it an extra time to keep it for now.
|
||||||
cast::bump_box_refcount(map);
|
let nonmut = cast::transmute::<TaskLocalMap,
|
||||||
|
@~[Option<TaskLocalElement>]>(map);
|
||||||
|
cast::bump_box_refcount(nonmut);
|
||||||
map
|
map
|
||||||
} else {
|
} else {
|
||||||
let map = cast::transmute(map_ptr);
|
let map = cast::transmute(map_ptr);
|
||||||
cast::bump_box_refcount(map);
|
let nonmut = cast::transmute::<TaskLocalMap,
|
||||||
|
@~[Option<TaskLocalElement>]>(map);
|
||||||
|
cast::bump_box_refcount(nonmut);
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +121,7 @@ unsafe fn local_get_helper<T:Durable>(
|
||||||
let data: @T = cast::transmute(data_ptr);
|
let data: @T = cast::transmute(data_ptr);
|
||||||
cast::bump_box_refcount(data);
|
cast::bump_box_refcount(data);
|
||||||
if do_pop {
|
if do_pop {
|
||||||
(*map).set_elt(index, None);
|
map[index] = None;
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
@ -159,13 +162,13 @@ pub unsafe fn local_set<T:Durable>(
|
||||||
Some((index, _old_data_ptr)) => {
|
Some((index, _old_data_ptr)) => {
|
||||||
// Key already had a value set, _old_data_ptr, whose reference
|
// Key already had a value set, _old_data_ptr, whose reference
|
||||||
// will get dropped when the local_data box is overwritten.
|
// will get dropped when the local_data box is overwritten.
|
||||||
(*map).set_elt(index, new_entry);
|
map[index] = new_entry;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Find an empty slot. If not, grow the vector.
|
// Find an empty slot. If not, grow the vector.
|
||||||
match (*map).position(|x| x.is_none()) {
|
match (*map).position(|x| x.is_none()) {
|
||||||
Some(empty_index) => (*map).set_elt(empty_index, new_entry),
|
Some(empty_index) => { map[empty_index] = new_entry; }
|
||||||
None => (*map).push(new_entry)
|
None => { map.push(new_entry); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ use metadata::decoder;
|
||||||
use metadata;
|
use metadata;
|
||||||
use middle::{ty, resolve};
|
use middle::{ty, resolve};
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::vec;
|
use core::vec;
|
||||||
use reader = std::ebml::reader;
|
use reader = std::ebml::reader;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -136,7 +135,7 @@ pub fn get_supertraits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] {
|
||||||
|
|
||||||
pub fn get_method_names_if_trait(cstore: @mut cstore::CStore,
|
pub fn get_method_names_if_trait(cstore: @mut cstore::CStore,
|
||||||
def: ast::def_id)
|
def: ast::def_id)
|
||||||
-> Option<@DVec<(ast::ident, ast::self_ty_)>> {
|
-> Option<~[(ast::ident, ast::self_ty_)]> {
|
||||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||||
return decoder::get_method_names_if_trait(cstore.intr, cdata, def.node);
|
return decoder::get_method_names_if_trait(cstore.intr, cdata, def.node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@ use metadata::decoder;
|
||||||
use metadata::tydecode::{parse_ty_data, parse_def_id, parse_bounds_data};
|
use metadata::tydecode::{parse_ty_data, parse_def_id, parse_bounds_data};
|
||||||
use middle::{ty, resolve};
|
use middle::{ty, resolve};
|
||||||
|
|
||||||
use core::dvec;
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::hash::{Hash, HashUtil};
|
use core::hash::{Hash, HashUtil};
|
||||||
use core::int;
|
use core::int;
|
||||||
use core::io::WriterUtil;
|
use core::io::WriterUtil;
|
||||||
|
@ -766,12 +764,12 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
|
||||||
/// Returns the supertraits of the given trait.
|
/// Returns the supertraits of the given trait.
|
||||||
pub fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
pub fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||||
-> ~[ty::t] {
|
-> ~[ty::t] {
|
||||||
let results = dvec::DVec();
|
let mut results = ~[];
|
||||||
let item_doc = lookup_item(id, cdata.data);
|
let item_doc = lookup_item(id, cdata.data);
|
||||||
for reader::tagged_docs(item_doc, tag_impl_trait) |trait_doc| {
|
for reader::tagged_docs(item_doc, tag_impl_trait) |trait_doc| {
|
||||||
results.push(doc_type(trait_doc, tcx, cdata));
|
results.push(doc_type(trait_doc, tcx, cdata));
|
||||||
}
|
}
|
||||||
return dvec::unwrap(results);
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the item in question is a trait, returns its set of methods and
|
// If the item in question is a trait, returns its set of methods and
|
||||||
|
@ -779,14 +777,14 @@ pub fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||||
// annoying way with get_trait_methods.
|
// annoying way with get_trait_methods.
|
||||||
pub fn get_method_names_if_trait(intr: @ident_interner, cdata: cmd,
|
pub fn get_method_names_if_trait(intr: @ident_interner, cdata: cmd,
|
||||||
node_id: ast::node_id)
|
node_id: ast::node_id)
|
||||||
-> Option<@DVec<(ast::ident, ast::self_ty_)>> {
|
-> Option<~[(ast::ident, ast::self_ty_)]> {
|
||||||
|
|
||||||
let item = lookup_item(node_id, cdata.data);
|
let item = lookup_item(node_id, cdata.data);
|
||||||
if item_family(item) != Trait {
|
if item_family(item) != Trait {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resulting_methods = @DVec();
|
let mut resulting_methods = ~[];
|
||||||
for reader::tagged_docs(item, tag_item_trait_method) |method| {
|
for reader::tagged_docs(item, tag_item_trait_method) |method| {
|
||||||
resulting_methods.push(
|
resulting_methods.push(
|
||||||
(item_name(intr, method), get_self_ty(method)));
|
(item_name(intr, method), get_self_ty(method)));
|
||||||
|
@ -823,12 +821,12 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let impl_method_ids = DVec();
|
let mut impl_method_ids = ~[];
|
||||||
for reader::tagged_docs(item, tag_item_impl_method) |impl_method_doc| {
|
for reader::tagged_docs(item, tag_item_impl_method) |impl_method_doc| {
|
||||||
impl_method_ids.push(parse_def_id(reader::doc_data(impl_method_doc)));
|
impl_method_ids.push(parse_def_id(reader::doc_data(impl_method_doc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let static_impl_methods = DVec();
|
let mut static_impl_methods = ~[];
|
||||||
for impl_method_ids.each |impl_method_id| {
|
for impl_method_ids.each |impl_method_id| {
|
||||||
let impl_method_doc = lookup_item(impl_method_id.node, cdata.data);
|
let impl_method_doc = lookup_item(impl_method_id.node, cdata.data);
|
||||||
let family = item_family(impl_method_doc);
|
let family = item_family(impl_method_doc);
|
||||||
|
@ -852,7 +850,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(dvec::unwrap(static_impl_methods));
|
return Some(static_impl_methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item_attrs(cdata: cmd,
|
pub fn get_item_attrs(cdata: cmd,
|
||||||
|
|
|
@ -22,7 +22,6 @@ use middle::ty;
|
||||||
use middle;
|
use middle;
|
||||||
use util::ppaux::ty_to_str;
|
use util::ppaux::ty_to_str;
|
||||||
|
|
||||||
use core::dvec;
|
|
||||||
use core::flate;
|
use core::flate;
|
||||||
use core::hash::{Hash, HashUtil};
|
use core::hash::{Hash, HashUtil};
|
||||||
use core::int;
|
use core::int;
|
||||||
|
@ -857,7 +856,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item_trait(ref generics, ref traits, ref ms) => {
|
item_trait(ref generics, ref traits, ref ms) => {
|
||||||
let provided_methods = dvec::DVec();
|
let mut provided_methods = ~[];
|
||||||
|
|
||||||
add_to_index();
|
add_to_index();
|
||||||
ebml_w.start_tag(tag_items_data_item);
|
ebml_w.start_tag(tag_items_data_item);
|
||||||
|
@ -1366,13 +1365,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
|
||||||
|
|
||||||
if (parms.tcx.sess.meta_stats()) {
|
if (parms.tcx.sess.meta_stats()) {
|
||||||
|
|
||||||
do wr.bytes.borrow |v| {
|
do wr.bytes.each |e| {
|
||||||
do v.each |e| {
|
if *e == 0 {
|
||||||
if *e == 0 {
|
ecx.stats.zero_bytes += 1;
|
||||||
ecx.stats.zero_bytes += 1;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
io::println("metadata stats:");
|
io::println("metadata stats:");
|
||||||
|
@ -1401,7 +1398,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
|
||||||
|
|
||||||
(do str::as_bytes(&~"rust\x00\x00\x00\x01") |bytes| {
|
(do str::as_bytes(&~"rust\x00\x00\x00\x01") |bytes| {
|
||||||
vec::slice(*bytes, 0, 8).to_vec()
|
vec::slice(*bytes, 0, 8).to_vec()
|
||||||
}) + flate::deflate_bytes(wr.bytes.check_out(|buf| buf))
|
}) + flate::deflate_bytes(wr.bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the encoded string for a type
|
// Get the encoded string for a type
|
||||||
|
|
|
@ -25,7 +25,6 @@ use middle::{ty, typeck, moves};
|
||||||
use middle;
|
use middle;
|
||||||
use util::ppaux::ty_to_str;
|
use util::ppaux::ty_to_str;
|
||||||
|
|
||||||
use core::{dvec, io, option, vec};
|
|
||||||
use std::ebml::reader;
|
use std::ebml::reader;
|
||||||
use std::ebml;
|
use std::ebml;
|
||||||
use std::serialize;
|
use std::serialize;
|
||||||
|
@ -912,11 +911,11 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for maps.last_use_map.find(&id).each |m| {
|
for maps.last_use_map.find(&id).each |&m| {
|
||||||
do ebml_w.tag(c::tag_table_last_use) {
|
do ebml_w.tag(c::tag_table_last_use) {
|
||||||
ebml_w.id(id);
|
ebml_w.id(id);
|
||||||
do ebml_w.tag(c::tag_table_val) {
|
do ebml_w.tag(c::tag_table_val) {
|
||||||
do ebml_w.emit_from_vec((*m).get()) |id| {
|
do ebml_w.emit_from_vec(/*bad*/ copy *m) |id| {
|
||||||
id.encode(&ebml_w);
|
id.encode(&ebml_w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1131,8 +1130,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
|
||||||
let ids = val_dsr.read_to_vec(|| {
|
let ids = val_dsr.read_to_vec(|| {
|
||||||
xcx.tr_id(val_dsr.read_int())
|
xcx.tr_id(val_dsr.read_int())
|
||||||
});
|
});
|
||||||
let dvec = @dvec::from_vec(ids);
|
dcx.maps.last_use_map.insert(id, @mut ids);
|
||||||
dcx.maps.last_use_map.insert(id, dvec);
|
|
||||||
} else if tag == (c::tag_table_method_map as uint) {
|
} else if tag == (c::tag_table_method_map as uint) {
|
||||||
dcx.maps.method_map.insert(
|
dcx.maps.method_map.insert(
|
||||||
id,
|
id,
|
||||||
|
@ -1211,6 +1209,7 @@ fn mk_ctxt() -> fake_ext_ctxt {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn roundtrip(in_item: Option<@ast::item>) {
|
fn roundtrip(in_item: Option<@ast::item>) {
|
||||||
|
use core::io;
|
||||||
use std::prettyprint;
|
use std::prettyprint;
|
||||||
|
|
||||||
let in_item = in_item.get();
|
let in_item = in_item.get();
|
||||||
|
|
|
@ -32,7 +32,6 @@ use middle::ty;
|
||||||
use util::common::indenter;
|
use util::common::indenter;
|
||||||
use util::ppaux::{expr_repr, region_to_str};
|
use util::ppaux::{expr_repr, region_to_str};
|
||||||
|
|
||||||
use core::dvec;
|
|
||||||
use core::hashmap::linear::LinearSet;
|
use core::hashmap::linear::LinearSet;
|
||||||
use core::vec;
|
use core::vec;
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
|
@ -575,9 +574,8 @@ pub impl GatherLoanCtxt {
|
||||||
req_loans.push_all(loans);
|
req_loans.push_all(loans);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let dvec = @dvec::from_vec(loans);
|
|
||||||
let req_loan_map = self.req_maps.req_loan_map;
|
let req_loan_map = self.req_maps.req_loan_map;
|
||||||
req_loan_map.insert(scope_id, dvec);
|
req_loan_map.insert(scope_id, @mut loans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,6 @@ use middle::moves;
|
||||||
use util::common::{indenter, stmt_set};
|
use util::common::{indenter, stmt_set};
|
||||||
use util::ppaux::note_and_explain_region;
|
use util::ppaux::note_and_explain_region;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::io;
|
use core::io;
|
||||||
use core::result::{Result, Ok, Err};
|
use core::result::{Result, Ok, Err};
|
||||||
use core::to_bytes;
|
use core::to_bytes;
|
||||||
|
@ -406,7 +405,7 @@ pub struct Loan {
|
||||||
/// - `pure_map`: map from block/expr that must be pure to the error message
|
/// - `pure_map`: map from block/expr that must be pure to the error message
|
||||||
/// that should be reported if they are not pure
|
/// that should be reported if they are not pure
|
||||||
pub struct ReqMaps {
|
pub struct ReqMaps {
|
||||||
req_loan_map: HashMap<ast::node_id, @DVec<Loan>>,
|
req_loan_map: HashMap<ast::node_id, @mut ~[Loan]>,
|
||||||
pure_map: HashMap<ast::node_id, bckerr>
|
pure_map: HashMap<ast::node_id, bckerr>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ use middle::moves;
|
||||||
use util::ppaux::ty_to_str;
|
use util::ppaux::ty_to_str;
|
||||||
|
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::io::WriterUtil;
|
use core::io::WriterUtil;
|
||||||
use core::io;
|
use core::io;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
@ -136,7 +135,7 @@ use syntax::{visit, ast_util};
|
||||||
//
|
//
|
||||||
// Very subtle (#2633): borrowck will remove entries from this table
|
// Very subtle (#2633): borrowck will remove entries from this table
|
||||||
// if it detects an outstanding loan (that is, the addr is taken).
|
// if it detects an outstanding loan (that is, the addr is taken).
|
||||||
pub type last_use_map = HashMap<node_id, @DVec<node_id>>;
|
pub type last_use_map = HashMap<node_id, @mut ~[node_id]>;
|
||||||
|
|
||||||
enum Variable = uint;
|
enum Variable = uint;
|
||||||
enum LiveNode = uint;
|
enum LiveNode = uint;
|
||||||
|
@ -419,13 +418,13 @@ pub impl IrMaps {
|
||||||
let v = match self.last_use_map.find(&expr_id) {
|
let v = match self.last_use_map.find(&expr_id) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => {
|
None => {
|
||||||
let v = @DVec();
|
let v = @mut ~[];
|
||||||
self.last_use_map.insert(expr_id, v);
|
self.last_use_map.insert(expr_id, v);
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(*v).push(id);
|
v.push(id);
|
||||||
}
|
}
|
||||||
Arg(_, _, by_ref) |
|
Arg(_, _, by_ref) |
|
||||||
Arg(_, _, by_val) | ImplicitRet => {
|
Arg(_, _, by_val) | ImplicitRet => {
|
||||||
|
@ -667,7 +666,7 @@ struct Liveness {
|
||||||
users: @mut ~[Users],
|
users: @mut ~[Users],
|
||||||
// The list of node IDs for the nested loop scopes
|
// The list of node IDs for the nested loop scopes
|
||||||
// we're in.
|
// we're in.
|
||||||
loop_scope: DVec<node_id>,
|
loop_scope: @mut ~[node_id],
|
||||||
// mappings from loop node ID to LiveNode
|
// mappings from loop node ID to LiveNode
|
||||||
// ("break" label should map to loop node ID,
|
// ("break" label should map to loop node ID,
|
||||||
// it probably doesn't now)
|
// it probably doesn't now)
|
||||||
|
@ -683,7 +682,7 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
|
||||||
successors: @mut vec::from_elem(ir.num_live_nodes, invalid_node()),
|
successors: @mut vec::from_elem(ir.num_live_nodes, invalid_node()),
|
||||||
users: @mut vec::from_elem(ir.num_live_nodes * ir.num_vars,
|
users: @mut vec::from_elem(ir.num_live_nodes * ir.num_vars,
|
||||||
invalid_users()),
|
invalid_users()),
|
||||||
loop_scope: DVec(),
|
loop_scope: @mut ~[],
|
||||||
break_ln: HashMap(),
|
break_ln: HashMap(),
|
||||||
cont_ln: HashMap()
|
cont_ln: HashMap()
|
||||||
}
|
}
|
||||||
|
@ -856,11 +855,16 @@ pub impl Liveness {
|
||||||
self.tcx.sess.span_bug(sp, ~"break outside loop");
|
self.tcx.sess.span_bug(sp, ~"break outside loop");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.loop_scope.last()
|
// FIXME(#5275): this shouldn't have to be a method...
|
||||||
|
self.last_loop_scope()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn last_loop_scope(&self) -> node_id {
|
||||||
|
*self.loop_scope.last()
|
||||||
|
}
|
||||||
|
|
||||||
fn ln_str(&self, ln: LiveNode) -> ~str {
|
fn ln_str(&self, ln: LiveNode) -> ~str {
|
||||||
do io::with_str_writer |wr| {
|
do io::with_str_writer |wr| {
|
||||||
wr.write_str(~"[ln(");
|
wr.write_str(~"[ln(");
|
||||||
|
|
|
@ -21,7 +21,6 @@ use middle::typeck::{method_map, method_origin, method_param, method_self};
|
||||||
use middle::typeck::{method_super};
|
use middle::typeck::{method_super};
|
||||||
use middle::typeck::{method_static, method_trait};
|
use middle::typeck::{method_static, method_trait};
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::util::ignore;
|
use core::util::ignore;
|
||||||
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_struct};
|
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_struct};
|
||||||
use syntax::ast::{expr_unary, ident, item_struct, item_enum, item_impl};
|
use syntax::ast::{expr_unary, ident, item_struct, item_enum, item_impl};
|
||||||
|
@ -38,7 +37,7 @@ use syntax::visit;
|
||||||
pub fn check_crate(tcx: ty::ctxt,
|
pub fn check_crate(tcx: ty::ctxt,
|
||||||
method_map: &method_map,
|
method_map: &method_map,
|
||||||
crate: @ast::crate) {
|
crate: @ast::crate) {
|
||||||
let privileged_items = @DVec();
|
let privileged_items = @mut ~[];
|
||||||
|
|
||||||
// Adds structs that are privileged to this scope.
|
// Adds structs that are privileged to this scope.
|
||||||
let add_privileged_items: @fn(&[@ast::item]) -> uint = |items| {
|
let add_privileged_items: @fn(&[@ast::item]) -> uint = |items| {
|
||||||
|
|
|
@ -26,7 +26,6 @@ use middle::ty::{region_variance, rv_covariant, rv_invariant};
|
||||||
use middle::ty::{rv_contravariant};
|
use middle::ty::{rv_contravariant};
|
||||||
use middle::ty;
|
use middle::ty;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::vec;
|
use core::vec;
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
use syntax::ast_map;
|
use syntax::ast_map;
|
||||||
|
@ -395,7 +394,7 @@ pub struct region_dep {
|
||||||
id: ast::node_id
|
id: ast::node_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type dep_map = HashMap<ast::node_id, @DVec<region_dep>>;
|
pub type dep_map = HashMap<ast::node_id, @mut ~[region_dep]>;
|
||||||
|
|
||||||
pub struct DetermineRpCtxt {
|
pub struct DetermineRpCtxt {
|
||||||
sess: Session,
|
sess: Session,
|
||||||
|
@ -498,7 +497,7 @@ pub impl DetermineRpCtxt {
|
||||||
let vec = match self.dep_map.find(&from) {
|
let vec = match self.dep_map.find(&from) {
|
||||||
Some(vec) => vec,
|
Some(vec) => vec,
|
||||||
None => {
|
None => {
|
||||||
let vec = @DVec();
|
let vec = @mut ~[];
|
||||||
let dep_map = self.dep_map;
|
let dep_map = self.dep_map;
|
||||||
dep_map.insert(from, vec);
|
dep_map.insert(from, vec);
|
||||||
vec
|
vec
|
||||||
|
|
|
@ -75,7 +75,6 @@ use syntax::visit::{visit_foreign_item, visit_item, visit_method_helper};
|
||||||
use syntax::visit::{visit_mod, visit_ty, vt};
|
use syntax::visit::{visit_mod, visit_ty, vt};
|
||||||
use syntax::opt_vec::OptVec;
|
use syntax::opt_vec::OptVec;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::option::{Some, get, is_some, is_none};
|
use core::option::{Some, get, is_some, is_none};
|
||||||
use core::str::{connect, split_str};
|
use core::str::{connect, split_str};
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
|
@ -110,7 +109,7 @@ pub struct Impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trait method resolution
|
// Trait method resolution
|
||||||
pub type TraitMap = @HashMap<node_id,@DVec<def_id>>;
|
pub type TraitMap = @HashMap<node_id,@mut ~[def_id]>;
|
||||||
|
|
||||||
// This is the replacement export map. It maps a module to all of the exports
|
// This is the replacement export map. It maps a module to all of the exports
|
||||||
// within.
|
// within.
|
||||||
|
@ -350,13 +349,13 @@ pub fn Rib(kind: RibKind) -> Rib {
|
||||||
/// One import directive.
|
/// One import directive.
|
||||||
pub struct ImportDirective {
|
pub struct ImportDirective {
|
||||||
privacy: Privacy,
|
privacy: Privacy,
|
||||||
module_path: @DVec<ident>,
|
module_path: ~[ident],
|
||||||
subclass: @ImportDirectiveSubclass,
|
subclass: @ImportDirectiveSubclass,
|
||||||
span: span,
|
span: span,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ImportDirective(privacy: Privacy,
|
pub fn ImportDirective(privacy: Privacy,
|
||||||
module_path: @DVec<ident>,
|
+module_path: ~[ident],
|
||||||
subclass: @ImportDirectiveSubclass,
|
subclass: @ImportDirectiveSubclass,
|
||||||
span: span)
|
span: span)
|
||||||
-> ImportDirective {
|
-> ImportDirective {
|
||||||
|
@ -458,7 +457,7 @@ pub struct Module {
|
||||||
kind: ModuleKind,
|
kind: ModuleKind,
|
||||||
|
|
||||||
children: @HashMap<ident,@mut NameBindings>,
|
children: @HashMap<ident,@mut NameBindings>,
|
||||||
imports: @DVec<@ImportDirective>,
|
imports: ~[@ImportDirective],
|
||||||
|
|
||||||
// The anonymous children of this node. Anonymous children are pseudo-
|
// The anonymous children of this node. Anonymous children are pseudo-
|
||||||
// modules that are implicitly created around items contained within
|
// modules that are implicitly created around items contained within
|
||||||
|
@ -496,7 +495,7 @@ pub fn Module(parent_link: ParentLink,
|
||||||
def_id: def_id,
|
def_id: def_id,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
children: @HashMap(),
|
children: @HashMap(),
|
||||||
imports: @DVec(),
|
imports: ~[],
|
||||||
anonymous_children: @HashMap(),
|
anonymous_children: @HashMap(),
|
||||||
import_resolutions: @HashMap(),
|
import_resolutions: @HashMap(),
|
||||||
glob_count: 0,
|
glob_count: 0,
|
||||||
|
@ -781,9 +780,9 @@ pub fn Resolver(session: Session,
|
||||||
unresolved_imports: 0,
|
unresolved_imports: 0,
|
||||||
|
|
||||||
current_module: current_module,
|
current_module: current_module,
|
||||||
value_ribs: @DVec(),
|
value_ribs: ~[],
|
||||||
type_ribs: @DVec(),
|
type_ribs: ~[],
|
||||||
label_ribs: @DVec(),
|
label_ribs: ~[],
|
||||||
|
|
||||||
xray_context: NoXray,
|
xray_context: NoXray,
|
||||||
current_trait_refs: None,
|
current_trait_refs: None,
|
||||||
|
@ -830,20 +829,20 @@ pub struct Resolver {
|
||||||
|
|
||||||
// The current set of local scopes, for values.
|
// The current set of local scopes, for values.
|
||||||
// FIXME #4948: Reuse ribs to avoid allocation.
|
// FIXME #4948: Reuse ribs to avoid allocation.
|
||||||
value_ribs: @DVec<@Rib>,
|
value_ribs: ~[@Rib],
|
||||||
|
|
||||||
// The current set of local scopes, for types.
|
// The current set of local scopes, for types.
|
||||||
type_ribs: @DVec<@Rib>,
|
type_ribs: ~[@Rib],
|
||||||
|
|
||||||
// The current set of local scopes, for labels.
|
// The current set of local scopes, for labels.
|
||||||
label_ribs: @DVec<@Rib>,
|
label_ribs: ~[@Rib],
|
||||||
|
|
||||||
// Whether the current context is an X-ray context. An X-ray context is
|
// Whether the current context is an X-ray context. An X-ray context is
|
||||||
// allowed to access private names of any module.
|
// allowed to access private names of any module.
|
||||||
xray_context: XrayFlag,
|
xray_context: XrayFlag,
|
||||||
|
|
||||||
// The trait that the current context can refer to.
|
// The trait that the current context can refer to.
|
||||||
current_trait_refs: Option<@DVec<def_id>>,
|
current_trait_refs: Option<~[def_id]>,
|
||||||
|
|
||||||
// The ident for the keyword "self".
|
// The ident for the keyword "self".
|
||||||
self_ident: ident,
|
self_ident: ident,
|
||||||
|
@ -1407,7 +1406,7 @@ pub impl Resolver {
|
||||||
// globs and lists, the path is found directly in the AST;
|
// globs and lists, the path is found directly in the AST;
|
||||||
// for simple paths we have to munge the path a little.
|
// for simple paths we have to munge the path a little.
|
||||||
|
|
||||||
let module_path = @DVec();
|
let mut module_path = ~[];
|
||||||
match view_path.node {
|
match view_path.node {
|
||||||
view_path_simple(_, full_path, _, _) => {
|
view_path_simple(_, full_path, _, _) => {
|
||||||
let path_len = full_path.idents.len();
|
let path_len = full_path.idents.len();
|
||||||
|
@ -1415,7 +1414,7 @@ pub impl Resolver {
|
||||||
|
|
||||||
for full_path.idents.eachi |i, ident| {
|
for full_path.idents.eachi |i, ident| {
|
||||||
if i != path_len - 1 {
|
if i != path_len - 1 {
|
||||||
(*module_path).push(*ident);
|
module_path.push(*ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1423,7 +1422,7 @@ pub impl Resolver {
|
||||||
view_path_glob(module_ident_path, _) |
|
view_path_glob(module_ident_path, _) |
|
||||||
view_path_list(module_ident_path, _, _) => {
|
view_path_list(module_ident_path, _, _) => {
|
||||||
for module_ident_path.idents.each |ident| {
|
for module_ident_path.idents.each |ident| {
|
||||||
(*module_path).push(*ident);
|
module_path.push(*ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1456,7 @@ pub impl Resolver {
|
||||||
AnyNS);
|
AnyNS);
|
||||||
self.build_import_directive(privacy,
|
self.build_import_directive(privacy,
|
||||||
module_,
|
module_,
|
||||||
module_path,
|
copy module_path,
|
||||||
subclass,
|
subclass,
|
||||||
view_path.span,
|
view_path.span,
|
||||||
state);
|
state);
|
||||||
|
@ -1857,7 +1856,7 @@ pub impl Resolver {
|
||||||
fn build_import_directive(@mut self,
|
fn build_import_directive(@mut self,
|
||||||
privacy: Privacy,
|
privacy: Privacy,
|
||||||
module_: @mut Module,
|
module_: @mut Module,
|
||||||
module_path: @DVec<ident>,
|
+module_path: ~[ident],
|
||||||
subclass: @ImportDirectiveSubclass,
|
subclass: @ImportDirectiveSubclass,
|
||||||
span: span,
|
span: span,
|
||||||
state: @mut ImportState) {
|
state: @mut ImportState) {
|
||||||
|
@ -1873,7 +1872,7 @@ pub impl Resolver {
|
||||||
debug!("(building import directive) building import \
|
debug!("(building import directive) building import \
|
||||||
directive: privacy %? %s::%s",
|
directive: privacy %? %s::%s",
|
||||||
privacy,
|
privacy,
|
||||||
self.idents_to_str(module_path.get()),
|
self.idents_to_str(directive.module_path),
|
||||||
*self.session.str_of(target));
|
*self.session.str_of(target));
|
||||||
|
|
||||||
match module_.import_resolutions.find(&target) {
|
match module_.import_resolutions.find(&target) {
|
||||||
|
@ -1887,7 +1886,7 @@ pub impl Resolver {
|
||||||
let resolution = @mut ImportResolution(privacy,
|
let resolution = @mut ImportResolution(privacy,
|
||||||
span,
|
span,
|
||||||
state);
|
state);
|
||||||
let name = self.idents_to_str(module_path.get());
|
let name = self.idents_to_str(directive.module_path);
|
||||||
// Don't warn about unused intrinsics because they're
|
// Don't warn about unused intrinsics because they're
|
||||||
// automatically appended to all files
|
// automatically appended to all files
|
||||||
if name == ~"intrinsic::rusti" {
|
if name == ~"intrinsic::rusti" {
|
||||||
|
@ -1982,13 +1981,13 @@ pub impl Resolver {
|
||||||
let import_count = module.imports.len();
|
let import_count = module.imports.len();
|
||||||
while module.resolved_import_count < import_count {
|
while module.resolved_import_count < import_count {
|
||||||
let import_index = module.resolved_import_count;
|
let import_index = module.resolved_import_count;
|
||||||
let import_directive = module.imports.get_elt(import_index);
|
let import_directive = module.imports[import_index];
|
||||||
match self.resolve_import_for_module(module, import_directive) {
|
match self.resolve_import_for_module(module, import_directive) {
|
||||||
Failed => {
|
Failed => {
|
||||||
// We presumably emitted an error. Continue.
|
// We presumably emitted an error. Continue.
|
||||||
let idents = import_directive.module_path.get();
|
|
||||||
let msg = fmt!("failed to resolve import: %s",
|
let msg = fmt!("failed to resolve import: %s",
|
||||||
*self.import_path_to_str(idents,
|
*self.import_path_to_str(
|
||||||
|
import_directive.module_path,
|
||||||
*import_directive.subclass));
|
*import_directive.subclass));
|
||||||
self.session.span_err(import_directive.span, msg);
|
self.session.span_err(import_directive.span, msg);
|
||||||
}
|
}
|
||||||
|
@ -2005,7 +2004,7 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn idents_to_str(@mut self, idents: ~[ident]) -> ~str {
|
fn idents_to_str(@mut self, idents: &[ident]) -> ~str {
|
||||||
let ident_strs = do idents.map |ident| {
|
let ident_strs = do idents.map |ident| {
|
||||||
/*bad*/ copy *self.session.str_of(*ident)
|
/*bad*/ copy *self.session.str_of(*ident)
|
||||||
};
|
};
|
||||||
|
@ -2043,11 +2042,11 @@ pub impl Resolver {
|
||||||
import_directive: @ImportDirective)
|
import_directive: @ImportDirective)
|
||||||
-> ResolveResult<()> {
|
-> ResolveResult<()> {
|
||||||
let mut resolution_result = Failed;
|
let mut resolution_result = Failed;
|
||||||
let module_path = import_directive.module_path;
|
let module_path = &import_directive.module_path;
|
||||||
|
|
||||||
debug!("(resolving import for module) resolving import `%s::...` in \
|
debug!("(resolving import for module) resolving import `%s::...` in \
|
||||||
`%s`",
|
`%s`",
|
||||||
self.idents_to_str(module_path.get()),
|
self.idents_to_str(*module_path),
|
||||||
self.module_to_str(module_));
|
self.module_to_str(module_));
|
||||||
|
|
||||||
// First, resolve the module path for the directive, if necessary.
|
// First, resolve the module path for the directive, if necessary.
|
||||||
|
@ -2056,7 +2055,7 @@ pub impl Resolver {
|
||||||
Some(self.graph_root.get_module())
|
Some(self.graph_root.get_module())
|
||||||
} else {
|
} else {
|
||||||
match self.resolve_module_path_for_import(module_,
|
match self.resolve_module_path_for_import(module_,
|
||||||
module_path,
|
*module_path,
|
||||||
DontUseLexicalScope,
|
DontUseLexicalScope,
|
||||||
import_directive.span) {
|
import_directive.span) {
|
||||||
|
|
||||||
|
@ -2574,21 +2573,21 @@ pub impl Resolver {
|
||||||
/// Resolves the given module path from the given root `module_`.
|
/// Resolves the given module path from the given root `module_`.
|
||||||
fn resolve_module_path_from_root(@mut self,
|
fn resolve_module_path_from_root(@mut self,
|
||||||
module_: @mut Module,
|
module_: @mut Module,
|
||||||
module_path: @DVec<ident>,
|
module_path: ~[ident],
|
||||||
index: uint,
|
index: uint,
|
||||||
span: span,
|
span: span,
|
||||||
mut name_search_type: NameSearchType)
|
mut name_search_type: NameSearchType)
|
||||||
-> ResolveResult<@mut Module> {
|
-> ResolveResult<@mut Module> {
|
||||||
let mut search_module = module_;
|
let mut search_module = module_;
|
||||||
let mut index = index;
|
let mut index = index;
|
||||||
let module_path_len = (*module_path).len();
|
let module_path_len = module_path.len();
|
||||||
|
|
||||||
// Resolve the module part of the path. This does not involve looking
|
// Resolve the module part of the path. This does not involve looking
|
||||||
// upward though scope chains; we simply resolve names directly in
|
// upward though scope chains; we simply resolve names directly in
|
||||||
// modules as we go.
|
// modules as we go.
|
||||||
|
|
||||||
while index < module_path_len {
|
while index < module_path_len {
|
||||||
let name = (*module_path).get_elt(index);
|
let name = module_path[index];
|
||||||
match self.resolve_name_in_module(search_module,
|
match self.resolve_name_in_module(search_module,
|
||||||
name,
|
name,
|
||||||
TypeNS,
|
TypeNS,
|
||||||
|
@ -2659,7 +2658,7 @@ pub impl Resolver {
|
||||||
/// rooted at the given module.
|
/// rooted at the given module.
|
||||||
fn resolve_module_path_for_import(@mut self,
|
fn resolve_module_path_for_import(@mut self,
|
||||||
module_: @mut Module,
|
module_: @mut Module,
|
||||||
module_path: @DVec<ident>,
|
module_path: ~[ident],
|
||||||
use_lexical_scope: UseLexicalScopeFlag,
|
use_lexical_scope: UseLexicalScopeFlag,
|
||||||
span: span)
|
span: span)
|
||||||
-> ResolveResult<@mut Module> {
|
-> ResolveResult<@mut Module> {
|
||||||
|
@ -2668,7 +2667,7 @@ pub impl Resolver {
|
||||||
|
|
||||||
debug!("(resolving module path for import) processing `%s` rooted at \
|
debug!("(resolving module path for import) processing `%s` rooted at \
|
||||||
`%s`",
|
`%s`",
|
||||||
self.idents_to_str((*module_path).get()),
|
self.idents_to_str(module_path),
|
||||||
self.module_to_str(module_));
|
self.module_to_str(module_));
|
||||||
|
|
||||||
// Resolve the module prefix, if any.
|
// Resolve the module prefix, if any.
|
||||||
|
@ -2704,7 +2703,7 @@ pub impl Resolver {
|
||||||
// scope and then proceed to resolve below that.
|
// scope and then proceed to resolve below that.
|
||||||
let result = self.resolve_module_in_lexical_scope(
|
let result = self.resolve_module_in_lexical_scope(
|
||||||
module_,
|
module_,
|
||||||
module_path.get_elt(0));
|
module_path[0]);
|
||||||
match result {
|
match result {
|
||||||
Failed => {
|
Failed => {
|
||||||
self.session.span_err(span,
|
self.session.span_err(span,
|
||||||
|
@ -2945,7 +2944,7 @@ pub impl Resolver {
|
||||||
*/
|
*/
|
||||||
fn resolve_module_prefix(@mut self,
|
fn resolve_module_prefix(@mut self,
|
||||||
module_: @mut Module,
|
module_: @mut Module,
|
||||||
module_path: @DVec<ident>)
|
module_path: ~[ident])
|
||||||
-> ResolveResult<ModulePrefixResult> {
|
-> ResolveResult<ModulePrefixResult> {
|
||||||
let interner = self.session.parse_sess.interner;
|
let interner = self.session.parse_sess.interner;
|
||||||
|
|
||||||
|
@ -2953,11 +2952,11 @@ pub impl Resolver {
|
||||||
// top of the crate otherwise.
|
// top of the crate otherwise.
|
||||||
let mut containing_module;
|
let mut containing_module;
|
||||||
let mut i;
|
let mut i;
|
||||||
if *interner.get(module_path.get_elt(0)) == ~"self" {
|
if *interner.get(module_path[0]) == ~"self" {
|
||||||
containing_module =
|
containing_module =
|
||||||
self.get_nearest_normal_module_parent_or_self(module_);
|
self.get_nearest_normal_module_parent_or_self(module_);
|
||||||
i = 1;
|
i = 1;
|
||||||
} else if *interner.get(module_path.get_elt(0)) == ~"super" {
|
} else if *interner.get(module_path[0]) == ~"super" {
|
||||||
containing_module =
|
containing_module =
|
||||||
self.get_nearest_normal_module_parent_or_self(module_);
|
self.get_nearest_normal_module_parent_or_self(module_);
|
||||||
i = 0; // We'll handle `super` below.
|
i = 0; // We'll handle `super` below.
|
||||||
|
@ -2967,7 +2966,7 @@ pub impl Resolver {
|
||||||
|
|
||||||
// Now loop through all the `super`s we find.
|
// Now loop through all the `super`s we find.
|
||||||
while i < module_path.len() &&
|
while i < module_path.len() &&
|
||||||
*interner.get(module_path.get_elt(i)) == ~"super" {
|
*interner.get(module_path[i]) == ~"super" {
|
||||||
debug!("(resolving module prefix) resolving `super` at %s",
|
debug!("(resolving module prefix) resolving `super` at %s",
|
||||||
self.module_to_str(containing_module));
|
self.module_to_str(containing_module));
|
||||||
match self.get_nearest_normal_module_parent(containing_module) {
|
match self.get_nearest_normal_module_parent(containing_module) {
|
||||||
|
@ -3064,7 +3063,7 @@ pub impl Resolver {
|
||||||
let index = module_.resolved_import_count;
|
let index = module_.resolved_import_count;
|
||||||
let import_count = module_.imports.len();
|
let import_count = module_.imports.len();
|
||||||
if index != import_count {
|
if index != import_count {
|
||||||
self.session.span_err(module_.imports.get_elt(index).span,
|
self.session.span_err(module_.imports[index].span,
|
||||||
~"unresolved import");
|
~"unresolved import");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3283,7 +3282,7 @@ pub impl Resolver {
|
||||||
// wrappers.
|
// wrappers.
|
||||||
|
|
||||||
fn upvarify(@mut self,
|
fn upvarify(@mut self,
|
||||||
ribs: @DVec<@Rib>,
|
ribs: &mut ~[@Rib],
|
||||||
rib_index: uint,
|
rib_index: uint,
|
||||||
def_like: def_like,
|
def_like: def_like,
|
||||||
span: span,
|
span: span,
|
||||||
|
@ -3313,9 +3312,8 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut rib_index = rib_index + 1;
|
let mut rib_index = rib_index + 1;
|
||||||
while rib_index < (*ribs).len() {
|
while rib_index < ribs.len() {
|
||||||
let rib = (*ribs).get_elt(rib_index);
|
match ribs[rib_index].kind {
|
||||||
match rib.kind {
|
|
||||||
NormalRibKind => {
|
NormalRibKind => {
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
}
|
}
|
||||||
|
@ -3393,7 +3391,7 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_ribs(@mut self,
|
fn search_ribs(@mut self,
|
||||||
ribs: @DVec<@Rib>,
|
ribs: &mut ~[@Rib],
|
||||||
name: ident,
|
name: ident,
|
||||||
span: span,
|
span: span,
|
||||||
allow_capturing_self: AllowCapturingSelfFlag)
|
allow_capturing_self: AllowCapturingSelfFlag)
|
||||||
|
@ -3401,14 +3399,13 @@ pub impl Resolver {
|
||||||
// FIXME #4950: This should not use a while loop.
|
// FIXME #4950: This should not use a while loop.
|
||||||
// FIXME #4950: Try caching?
|
// FIXME #4950: Try caching?
|
||||||
|
|
||||||
let mut i = (*ribs).len();
|
let mut i = ribs.len();
|
||||||
while i != 0 {
|
while i != 0 {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
let rib = (*ribs).get_elt(i);
|
match ribs[i].bindings.find(&name) {
|
||||||
match rib.bindings.find(&name) {
|
|
||||||
Some(def_like) => {
|
Some(def_like) => {
|
||||||
return self.upvarify(ribs, i, def_like, span,
|
return self.upvarify(ribs, i, def_like, span,
|
||||||
allow_capturing_self);
|
allow_capturing_self);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Continue.
|
// Continue.
|
||||||
|
@ -3502,7 +3499,7 @@ pub impl Resolver {
|
||||||
item_trait(ref generics, ref traits, ref methods) => {
|
item_trait(ref generics, ref traits, ref methods) => {
|
||||||
// Create a new rib for the self type.
|
// Create a new rib for the self type.
|
||||||
let self_type_rib = @Rib(NormalRibKind);
|
let self_type_rib = @Rib(NormalRibKind);
|
||||||
(*self.type_ribs).push(self_type_rib);
|
self.type_ribs.push(self_type_rib);
|
||||||
self_type_rib.bindings.insert(self.type_self_ident,
|
self_type_rib.bindings.insert(self.type_self_ident,
|
||||||
dl_def(def_self_ty(item.id)));
|
dl_def(def_self_ty(item.id)));
|
||||||
|
|
||||||
|
@ -3573,7 +3570,7 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(*self.type_ribs).pop();
|
self.type_ribs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
item_struct(struct_def, ref generics) => {
|
item_struct(struct_def, ref generics) => {
|
||||||
|
@ -3706,15 +3703,15 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_label_rib(@mut self, f: fn()) {
|
fn with_label_rib(@mut self, f: fn()) {
|
||||||
(*self.label_ribs).push(@Rib(NormalRibKind));
|
self.label_ribs.push(@Rib(NormalRibKind));
|
||||||
f();
|
f();
|
||||||
(*self.label_ribs).pop();
|
self.label_ribs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_constant_rib(@mut self, f: fn()) {
|
fn with_constant_rib(@mut self, f: fn()) {
|
||||||
(*self.value_ribs).push(@Rib(ConstantItemRibKind));
|
self.value_ribs.push(@Rib(ConstantItemRibKind));
|
||||||
f();
|
f();
|
||||||
(*self.value_ribs).pop();
|
self.value_ribs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_function(@mut self,
|
fn resolve_function(@mut self,
|
||||||
|
@ -3726,11 +3723,11 @@ pub impl Resolver {
|
||||||
visitor: ResolveVisitor) {
|
visitor: ResolveVisitor) {
|
||||||
// Create a value rib for the function.
|
// Create a value rib for the function.
|
||||||
let function_value_rib = @Rib(rib_kind);
|
let function_value_rib = @Rib(rib_kind);
|
||||||
(*self.value_ribs).push(function_value_rib);
|
self.value_ribs.push(function_value_rib);
|
||||||
|
|
||||||
// Create a label rib for the function.
|
// Create a label rib for the function.
|
||||||
let function_label_rib = @Rib(rib_kind);
|
let function_label_rib = @Rib(rib_kind);
|
||||||
(*self.label_ribs).push(function_label_rib);
|
self.label_ribs.push(function_label_rib);
|
||||||
|
|
||||||
// If this function has type parameters, add them now.
|
// If this function has type parameters, add them now.
|
||||||
do self.with_type_parameter_rib(type_parameters) {
|
do self.with_type_parameter_rib(type_parameters) {
|
||||||
|
@ -3790,8 +3787,8 @@ pub impl Resolver {
|
||||||
debug!("(resolving function) leaving function");
|
debug!("(resolving function) leaving function");
|
||||||
}
|
}
|
||||||
|
|
||||||
(*self.label_ribs).pop();
|
self.label_ribs.pop();
|
||||||
(*self.value_ribs).pop();
|
self.value_ribs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_type_parameters(@mut self,
|
fn resolve_type_parameters(@mut self,
|
||||||
|
@ -3891,10 +3888,10 @@ pub impl Resolver {
|
||||||
visitor);
|
visitor);
|
||||||
|
|
||||||
// Resolve the trait reference, if necessary.
|
// Resolve the trait reference, if necessary.
|
||||||
let original_trait_refs = self.current_trait_refs;
|
let original_trait_refs;
|
||||||
match opt_trait_reference {
|
match opt_trait_reference {
|
||||||
Some(trait_reference) => {
|
Some(trait_reference) => {
|
||||||
let new_trait_refs = @DVec();
|
let mut new_trait_refs = ~[];
|
||||||
match self.resolve_path(
|
match self.resolve_path(
|
||||||
trait_reference.path, TypeNS, true, visitor) {
|
trait_reference.path, TypeNS, true, visitor) {
|
||||||
None => {
|
None => {
|
||||||
|
@ -3906,13 +3903,17 @@ pub impl Resolver {
|
||||||
self.record_def(trait_reference.ref_id, def);
|
self.record_def(trait_reference.ref_id, def);
|
||||||
|
|
||||||
// Record the current trait reference.
|
// Record the current trait reference.
|
||||||
(*new_trait_refs).push(def_id_of_def(def));
|
new_trait_refs.push(def_id_of_def(def));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Record the current set of trait references.
|
// Record the current set of trait references.
|
||||||
self.current_trait_refs = Some(new_trait_refs);
|
let mut old = Some(new_trait_refs);
|
||||||
|
self.current_trait_refs <-> old;
|
||||||
|
original_trait_refs = Some(old);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
original_trait_refs = None;
|
||||||
}
|
}
|
||||||
None => ()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the self type.
|
// Resolve the self type.
|
||||||
|
@ -3945,7 +3946,10 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore the original trait references.
|
// Restore the original trait references.
|
||||||
self.current_trait_refs = original_trait_refs;
|
match original_trait_refs {
|
||||||
|
Some(r) => { self.current_trait_refs = r; }
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4032,7 +4036,7 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) {
|
fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) {
|
||||||
(*self.value_ribs).push(@Rib(NormalRibKind));
|
self.value_ribs.push(@Rib(NormalRibKind));
|
||||||
|
|
||||||
let bindings_list = HashMap();
|
let bindings_list = HashMap();
|
||||||
for arm.pats.each |pattern| {
|
for arm.pats.each |pattern| {
|
||||||
|
@ -4047,12 +4051,12 @@ pub impl Resolver {
|
||||||
visit_expr_opt(arm.guard, (), visitor);
|
visit_expr_opt(arm.guard, (), visitor);
|
||||||
self.resolve_block(&arm.body, visitor);
|
self.resolve_block(&arm.body, visitor);
|
||||||
|
|
||||||
(*self.value_ribs).pop();
|
self.value_ribs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) {
|
fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) {
|
||||||
debug!("(resolving block) entering block");
|
debug!("(resolving block) entering block");
|
||||||
(*self.value_ribs).push(@Rib(NormalRibKind));
|
self.value_ribs.push(@Rib(NormalRibKind));
|
||||||
|
|
||||||
// Move down in the graph, if there's an anonymous module rooted here.
|
// Move down in the graph, if there's an anonymous module rooted here.
|
||||||
let orig_module = self.current_module;
|
let orig_module = self.current_module;
|
||||||
|
@ -4071,7 +4075,7 @@ pub impl Resolver {
|
||||||
// Move back up.
|
// Move back up.
|
||||||
self.current_module = orig_module;
|
self.current_module = orig_module;
|
||||||
|
|
||||||
(*self.value_ribs).pop();
|
self.value_ribs.pop();
|
||||||
debug!("(resolving block) leaving block");
|
debug!("(resolving block) leaving block");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4251,7 +4255,8 @@ pub impl Resolver {
|
||||||
Some(bindings_list)
|
Some(bindings_list)
|
||||||
if !bindings_list.contains_key(&ident)
|
if !bindings_list.contains_key(&ident)
|
||||||
=> {
|
=> {
|
||||||
let last_rib = (*self.value_ribs).last();
|
let last_rib = self.value_ribs[
|
||||||
|
self.value_ribs.len() - 1];
|
||||||
last_rib.bindings.insert(ident,
|
last_rib.bindings.insert(ident,
|
||||||
dl_def(def));
|
dl_def(def));
|
||||||
bindings_list.insert(ident, pat_id);
|
bindings_list.insert(ident, pat_id);
|
||||||
|
@ -4270,7 +4275,8 @@ pub impl Resolver {
|
||||||
// Not bound in the same pattern: do nothing
|
// Not bound in the same pattern: do nothing
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let last_rib = (*self.value_ribs).last();
|
let last_rib = self.value_ribs[
|
||||||
|
self.value_ribs.len() - 1];
|
||||||
last_rib.bindings.insert(ident,
|
last_rib.bindings.insert(ident,
|
||||||
dl_def(def));
|
dl_def(def));
|
||||||
}
|
}
|
||||||
|
@ -4510,14 +4516,14 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intern_module_part_of_path(@mut self, path: @path) -> @DVec<ident> {
|
fn intern_module_part_of_path(@mut self, path: @path) -> ~[ident] {
|
||||||
let module_path_idents = @DVec();
|
let mut module_path_idents = ~[];
|
||||||
for path.idents.eachi |index, ident| {
|
for path.idents.eachi |index, ident| {
|
||||||
if index == path.idents.len() - 1 {
|
if index == path.idents.len() - 1 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*module_path_idents).push(*ident);
|
module_path_idents.push(*ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
return module_path_idents;
|
return module_path_idents;
|
||||||
|
@ -4539,7 +4545,7 @@ pub impl Resolver {
|
||||||
self.session.span_err(path.span,
|
self.session.span_err(path.span,
|
||||||
fmt!("use of undeclared module `%s`",
|
fmt!("use of undeclared module `%s`",
|
||||||
self.idents_to_str(
|
self.idents_to_str(
|
||||||
(*module_path_idents).get())));
|
module_path_idents)));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4587,8 +4593,8 @@ pub impl Resolver {
|
||||||
Failed => {
|
Failed => {
|
||||||
self.session.span_err(path.span,
|
self.session.span_err(path.span,
|
||||||
fmt!("use of undeclared module `::%s`",
|
fmt!("use of undeclared module `::%s`",
|
||||||
self.idents_to_str
|
self.idents_to_str(
|
||||||
((*module_path_idents).get())));
|
module_path_idents)));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4625,12 +4631,13 @@ pub impl Resolver {
|
||||||
let mut search_result;
|
let mut search_result;
|
||||||
match namespace {
|
match namespace {
|
||||||
ValueNS => {
|
ValueNS => {
|
||||||
search_result = self.search_ribs(self.value_ribs, ident, span,
|
search_result = self.search_ribs(&mut self.value_ribs, ident,
|
||||||
|
span,
|
||||||
DontAllowCapturingSelf);
|
DontAllowCapturingSelf);
|
||||||
}
|
}
|
||||||
TypeNS => {
|
TypeNS => {
|
||||||
search_result = self.search_ribs(self.type_ribs, ident, span,
|
search_result = self.search_ribs(&mut self.type_ribs, ident,
|
||||||
AllowCapturingSelf);
|
span, AllowCapturingSelf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4688,8 +4695,7 @@ pub impl Resolver {
|
||||||
let mut j = self.value_ribs.len();
|
let mut j = self.value_ribs.len();
|
||||||
while j != 0 {
|
while j != 0 {
|
||||||
j -= 1;
|
j -= 1;
|
||||||
let rib = self.value_ribs.get_elt(j);
|
for self.value_ribs[j].bindings.each_entry |e| {
|
||||||
for rib.bindings.each_entry |e| {
|
|
||||||
vec::push(&mut maybes, copy *self.session.str_of(e.key));
|
vec::push(&mut maybes, copy *self.session.str_of(e.key));
|
||||||
vec::push(&mut values, uint::max_value);
|
vec::push(&mut values, uint::max_value);
|
||||||
}
|
}
|
||||||
|
@ -4721,8 +4727,7 @@ pub impl Resolver {
|
||||||
let mut i = self.type_ribs.len();
|
let mut i = self.type_ribs.len();
|
||||||
while i != 0 {
|
while i != 0 {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
let rib = self.type_ribs.get_elt(i);
|
match self.type_ribs[i].kind {
|
||||||
match rib.kind {
|
|
||||||
MethodRibKind(node_id, _) =>
|
MethodRibKind(node_id, _) =>
|
||||||
for self.crate.node.module.items.each |item| {
|
for self.crate.node.module.items.each |item| {
|
||||||
if item.id == node_id {
|
if item.id == node_id {
|
||||||
|
@ -4839,14 +4844,15 @@ pub impl Resolver {
|
||||||
expr_loop(_, Some(label)) => {
|
expr_loop(_, Some(label)) => {
|
||||||
do self.with_label_rib {
|
do self.with_label_rib {
|
||||||
let def_like = dl_def(def_label(expr.id));
|
let def_like = dl_def(def_label(expr.id));
|
||||||
self.label_ribs.last().bindings.insert(label, def_like);
|
let rib = self.label_ribs[self.label_ribs.len() - 1];
|
||||||
|
rib.bindings.insert(label, def_like);
|
||||||
|
|
||||||
visit_expr(expr, (), visitor);
|
visit_expr(expr, (), visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_break(Some(label)) | expr_again(Some(label)) => {
|
expr_break(Some(label)) | expr_again(Some(label)) => {
|
||||||
match self.search_ribs(self.label_ribs, label, expr.span,
|
match self.search_ribs(&mut self.label_ribs, label, expr.span,
|
||||||
DontAllowCapturingSelf) {
|
DontAllowCapturingSelf) {
|
||||||
None =>
|
None =>
|
||||||
self.session.span_err(expr.span,
|
self.session.span_err(expr.span,
|
||||||
|
@ -4873,11 +4879,11 @@ pub impl Resolver {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
expr_field(_, ident, _) => {
|
expr_field(_, ident, _) => {
|
||||||
let traits = self.search_for_traits_containing_method(ident);
|
let traits = self.search_for_traits_containing_method(ident);
|
||||||
self.trait_map.insert(expr.id, traits);
|
self.trait_map.insert(expr.id, @mut traits);
|
||||||
}
|
}
|
||||||
expr_method_call(_, ident, _, _, _) => {
|
expr_method_call(_, ident, _, _, _) => {
|
||||||
let traits = self.search_for_traits_containing_method(ident);
|
let traits = self.search_for_traits_containing_method(ident);
|
||||||
self.trait_map.insert(expr.id, traits);
|
self.trait_map.insert(expr.id, @mut traits);
|
||||||
}
|
}
|
||||||
expr_binary(add, _, _) | expr_assign_op(add, _, _) => {
|
expr_binary(add, _, _) | expr_assign_op(add, _, _) => {
|
||||||
self.add_fixed_trait_for_expr(expr.id,
|
self.add_fixed_trait_for_expr(expr.id,
|
||||||
|
@ -4948,11 +4954,11 @@ pub impl Resolver {
|
||||||
|
|
||||||
fn search_for_traits_containing_method(@mut self,
|
fn search_for_traits_containing_method(@mut self,
|
||||||
name: ident)
|
name: ident)
|
||||||
-> @DVec<def_id> {
|
-> ~[def_id] {
|
||||||
debug!("(searching for traits containing method) looking for '%s'",
|
debug!("(searching for traits containing method) looking for '%s'",
|
||||||
*self.session.str_of(name));
|
*self.session.str_of(name));
|
||||||
|
|
||||||
let found_traits = @DVec();
|
let mut found_traits = ~[];
|
||||||
let mut search_module = self.current_module;
|
let mut search_module = self.current_module;
|
||||||
loop {
|
loop {
|
||||||
// Look for the current trait.
|
// Look for the current trait.
|
||||||
|
@ -4960,7 +4966,7 @@ pub impl Resolver {
|
||||||
Some(trait_def_ids) => {
|
Some(trait_def_ids) => {
|
||||||
for trait_def_ids.each |trait_def_id| {
|
for trait_def_ids.each |trait_def_id| {
|
||||||
self.add_trait_info_if_containing_method(
|
self.add_trait_info_if_containing_method(
|
||||||
found_traits, *trait_def_id, name);
|
&mut found_traits, *trait_def_id, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -4975,7 +4981,7 @@ pub impl Resolver {
|
||||||
match def {
|
match def {
|
||||||
def_ty(trait_def_id) => {
|
def_ty(trait_def_id) => {
|
||||||
self.add_trait_info_if_containing_method(
|
self.add_trait_info_if_containing_method(
|
||||||
found_traits, trait_def_id, name);
|
&mut found_traits, trait_def_id, name);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Continue.
|
// Continue.
|
||||||
|
@ -5003,7 +5009,8 @@ pub impl Resolver {
|
||||||
def_ty(trait_def_id) => {
|
def_ty(trait_def_id) => {
|
||||||
let added = self.
|
let added = self.
|
||||||
add_trait_info_if_containing_method(
|
add_trait_info_if_containing_method(
|
||||||
found_traits, trait_def_id, name);
|
&mut found_traits,
|
||||||
|
trait_def_id, name);
|
||||||
if added {
|
if added {
|
||||||
import_resolution.state.used =
|
import_resolution.state.used =
|
||||||
true;
|
true;
|
||||||
|
@ -5039,7 +5046,7 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_trait_info_if_containing_method(@mut self,
|
fn add_trait_info_if_containing_method(@mut self,
|
||||||
found_traits: @DVec<def_id>,
|
found_traits: &mut ~[def_id],
|
||||||
trait_def_id: def_id,
|
trait_def_id: def_id,
|
||||||
name: ident)
|
name: ident)
|
||||||
-> bool {
|
-> bool {
|
||||||
|
@ -5056,7 +5063,7 @@ pub impl Resolver {
|
||||||
trait_def_id.crate,
|
trait_def_id.crate,
|
||||||
trait_def_id.node,
|
trait_def_id.node,
|
||||||
*self.session.str_of(name));
|
*self.session.str_of(name));
|
||||||
(*found_traits).push(trait_def_id);
|
found_traits.push(trait_def_id);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
|
@ -5068,9 +5075,7 @@ pub impl Resolver {
|
||||||
fn add_fixed_trait_for_expr(@mut self,
|
fn add_fixed_trait_for_expr(@mut self,
|
||||||
expr_id: node_id,
|
expr_id: node_id,
|
||||||
+trait_id: def_id) {
|
+trait_id: def_id) {
|
||||||
let traits = @DVec();
|
self.trait_map.insert(expr_id, @mut ~[trait_id]);
|
||||||
traits.push(trait_id);
|
|
||||||
self.trait_map.insert(expr_id, traits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_def(@mut self, node_id: node_id, def: def) {
|
fn record_def(@mut self, node_id: node_id, def: def) {
|
||||||
|
@ -5225,7 +5230,7 @@ pub impl Resolver {
|
||||||
|
|
||||||
/// A somewhat inefficient routine to obtain the name of a module.
|
/// A somewhat inefficient routine to obtain the name of a module.
|
||||||
fn module_to_str(@mut self, module_: @mut Module) -> ~str {
|
fn module_to_str(@mut self, module_: @mut Module) -> ~str {
|
||||||
let idents = DVec();
|
let mut idents = ~[];
|
||||||
let mut current_module = module_;
|
let mut current_module = module_;
|
||||||
loop {
|
loop {
|
||||||
match current_module.parent_link {
|
match current_module.parent_link {
|
||||||
|
@ -5246,7 +5251,7 @@ pub impl Resolver {
|
||||||
if idents.len() == 0 {
|
if idents.len() == 0 {
|
||||||
return ~"???";
|
return ~"???";
|
||||||
}
|
}
|
||||||
return self.idents_to_str(vec::reversed(idents.get()));
|
return self.idents_to_str(vec::reversed(idents));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_module(@mut self, module_: @mut Module) {
|
fn dump_module(@mut self, module_: @mut Module) {
|
||||||
|
|
|
@ -167,8 +167,6 @@ use middle::trans::type_of;
|
||||||
use middle::ty;
|
use middle::ty;
|
||||||
use util::common::indenter;
|
use util::common::indenter;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::dvec;
|
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::ident;
|
use syntax::ast::ident;
|
||||||
|
@ -553,7 +551,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
|
||||||
// Reorder the patterns into the same order they were
|
// Reorder the patterns into the same order they were
|
||||||
// specified in the struct definition. Also fill in
|
// specified in the struct definition. Also fill in
|
||||||
// unspecified fields with dummy.
|
// unspecified fields with dummy.
|
||||||
let reordered_patterns = dvec::DVec();
|
let mut reordered_patterns = ~[];
|
||||||
for ty::lookup_struct_fields(tcx, struct_id).each
|
for ty::lookup_struct_fields(tcx, struct_id).each
|
||||||
|field| {
|
|field| {
|
||||||
match field_pats.find(|p|
|
match field_pats.find(|p|
|
||||||
|
@ -562,7 +560,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
|
||||||
Some(fp) => reordered_patterns.push(fp.pat)
|
Some(fp) => reordered_patterns.push(fp.pat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(dvec::unwrap(reordered_patterns))
|
Some(reordered_patterns)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -764,32 +762,32 @@ pub fn enter_region(bcx: block,
|
||||||
// on a set of enum variants or a literal.
|
// on a set of enum variants or a literal.
|
||||||
pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
|
pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
|
||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
fn add_to_set(tcx: ty::ctxt, set: &DVec<Opt>, +val: Opt) {
|
fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], +val: Opt) {
|
||||||
if set.any(|l| opt_eq(tcx, l, &val)) {return;}
|
if set.any(|l| opt_eq(tcx, l, &val)) {return;}
|
||||||
set.push(val);
|
set.push(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
let found = DVec();
|
let mut found = ~[];
|
||||||
for vec::each(m) |br| {
|
for m.each |br| {
|
||||||
let cur = br.pats[col];
|
let cur = br.pats[col];
|
||||||
match /*bad*/copy cur.node {
|
match /*bad*/copy cur.node {
|
||||||
ast::pat_lit(l) => {
|
ast::pat_lit(l) => {
|
||||||
add_to_set(ccx.tcx, &found, lit(ExprLit(l)));
|
add_to_set(ccx.tcx, &mut found, lit(ExprLit(l)));
|
||||||
}
|
}
|
||||||
ast::pat_ident(*) => {
|
ast::pat_ident(*) => {
|
||||||
// This is one of: an enum variant, a unit-like struct, or a
|
// This is one of: an enum variant, a unit-like struct, or a
|
||||||
// variable binding.
|
// variable binding.
|
||||||
match ccx.tcx.def_map.find(&cur.id) {
|
match ccx.tcx.def_map.find(&cur.id) {
|
||||||
Some(ast::def_variant(*)) => {
|
Some(ast::def_variant(*)) => {
|
||||||
add_to_set(ccx.tcx, &found,
|
add_to_set(ccx.tcx, &mut found,
|
||||||
variant_opt(bcx, cur.id));
|
variant_opt(bcx, cur.id));
|
||||||
}
|
}
|
||||||
Some(ast::def_struct(*)) => {
|
Some(ast::def_struct(*)) => {
|
||||||
add_to_set(ccx.tcx, &found,
|
add_to_set(ccx.tcx, &mut found,
|
||||||
lit(UnitLikeStructLit(cur.id)));
|
lit(UnitLikeStructLit(cur.id)));
|
||||||
}
|
}
|
||||||
Some(ast::def_const(const_did)) => {
|
Some(ast::def_const(const_did)) => {
|
||||||
add_to_set(ccx.tcx, &found,
|
add_to_set(ccx.tcx, &mut found,
|
||||||
lit(ConstLit(const_did)));
|
lit(ConstLit(const_did)));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -800,26 +798,26 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
|
||||||
// struct-like enum variant, or a struct.
|
// struct-like enum variant, or a struct.
|
||||||
match ccx.tcx.def_map.find(&cur.id) {
|
match ccx.tcx.def_map.find(&cur.id) {
|
||||||
Some(ast::def_variant(*)) => {
|
Some(ast::def_variant(*)) => {
|
||||||
add_to_set(ccx.tcx, &found,
|
add_to_set(ccx.tcx, &mut found,
|
||||||
variant_opt(bcx, cur.id));
|
variant_opt(bcx, cur.id));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::pat_range(l1, l2) => {
|
ast::pat_range(l1, l2) => {
|
||||||
add_to_set(ccx.tcx, &found, range(l1, l2));
|
add_to_set(ccx.tcx, &mut found, range(l1, l2));
|
||||||
}
|
}
|
||||||
ast::pat_vec(elems, tail) => {
|
ast::pat_vec(elems, tail) => {
|
||||||
let opt = match tail {
|
let opt = match tail {
|
||||||
None => vec_len_eq(elems.len()),
|
None => vec_len_eq(elems.len()),
|
||||||
Some(_) => vec_len_ge(elems.len())
|
Some(_) => vec_len_ge(elems.len())
|
||||||
};
|
};
|
||||||
add_to_set(ccx.tcx, &found, opt);
|
add_to_set(ccx.tcx, &mut found, opt);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dvec::unwrap(found);
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExtractedBlock {
|
pub struct ExtractedBlock {
|
||||||
|
@ -1074,7 +1072,7 @@ pub fn compare_values(cx: block,
|
||||||
|
|
||||||
pub fn store_non_ref_bindings(bcx: block,
|
pub fn store_non_ref_bindings(bcx: block,
|
||||||
data: &ArmData,
|
data: &ArmData,
|
||||||
opt_temp_cleanups: Option<&DVec<ValueRef>>)
|
opt_temp_cleanups: Option<&mut ~[ValueRef]>)
|
||||||
-> block {
|
-> block {
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
|
@ -1166,8 +1164,8 @@ pub fn compile_guard(bcx: block,
|
||||||
let _indenter = indenter();
|
let _indenter = indenter();
|
||||||
|
|
||||||
let mut bcx = bcx;
|
let mut bcx = bcx;
|
||||||
let temp_cleanups = DVec();
|
let mut temp_cleanups = ~[];
|
||||||
bcx = store_non_ref_bindings(bcx, data, Some(&temp_cleanups));
|
bcx = store_non_ref_bindings(bcx, data, Some(&mut temp_cleanups));
|
||||||
bcx = insert_lllocals(bcx, data, false);
|
bcx = insert_lllocals(bcx, data, false);
|
||||||
|
|
||||||
let val = unpack_result!(bcx, {
|
let val = unpack_result!(bcx, {
|
||||||
|
@ -1627,7 +1625,7 @@ pub fn trans_match_inner(scope_cx: block,
|
||||||
let lldiscr = discr_datum.to_ref_llval(bcx);
|
let lldiscr = discr_datum.to_ref_llval(bcx);
|
||||||
compile_submatch(bcx, matches, ~[lldiscr], chk);
|
compile_submatch(bcx, matches, ~[lldiscr], chk);
|
||||||
|
|
||||||
let arm_cxs = DVec();
|
let mut arm_cxs = ~[];
|
||||||
for arm_datas.each |arm_data| {
|
for arm_datas.each |arm_data| {
|
||||||
let mut bcx = arm_data.bodycx;
|
let mut bcx = arm_data.bodycx;
|
||||||
|
|
||||||
|
@ -1647,7 +1645,7 @@ pub fn trans_match_inner(scope_cx: block,
|
||||||
arm_cxs.push(bcx);
|
arm_cxs.push(bcx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bcx = controlflow::join_blocks(scope_cx, dvec::unwrap(arm_cxs));
|
bcx = controlflow::join_blocks(scope_cx, arm_cxs);
|
||||||
return bcx;
|
return bcx;
|
||||||
|
|
||||||
fn mk_fail(bcx: block, sp: span, msg: @~str,
|
fn mk_fail(bcx: block, sp: span, msg: @~str,
|
||||||
|
|
|
@ -29,8 +29,6 @@ use util::common::{indenter};
|
||||||
|
|
||||||
use core::cast;
|
use core::cast;
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::dvec;
|
|
||||||
use core::ops;
|
use core::ops;
|
||||||
use core::option;
|
use core::option;
|
||||||
use core::ptr::to_unsafe_ptr;
|
use core::ptr::to_unsafe_ptr;
|
||||||
|
@ -213,7 +211,7 @@ pub enum AutoRefKind {
|
||||||
// This is a map from ID of each implementation to the method info and trait
|
// This is a map from ID of each implementation to the method info and trait
|
||||||
// method ID of each of the default methods belonging to the trait that that
|
// method ID of each of the default methods belonging to the trait that that
|
||||||
// implementation implements.
|
// implementation implements.
|
||||||
pub type ProvidedMethodsMap = HashMap<def_id,@DVec<@ProvidedMethodInfo>>;
|
pub type ProvidedMethodsMap = HashMap<def_id,@mut ~[@ProvidedMethodInfo]>;
|
||||||
|
|
||||||
// Stores the method info and definition ID of the associated trait method for
|
// Stores the method info and definition ID of the associated trait method for
|
||||||
// each instantiation of each provided method.
|
// each instantiation of each provided method.
|
||||||
|
@ -3522,7 +3520,7 @@ pub fn trait_supertraits(cx: ctxt,
|
||||||
|
|
||||||
// Get the supertraits out of the metadata and create the
|
// Get the supertraits out of the metadata and create the
|
||||||
// InstantiatedTraitRef for each.
|
// InstantiatedTraitRef for each.
|
||||||
let result = dvec::DVec();
|
let mut result = ~[];
|
||||||
for csearch::get_supertraits(cx, id).each |trait_type| {
|
for csearch::get_supertraits(cx, id).each |trait_type| {
|
||||||
match get(*trait_type).sty {
|
match get(*trait_type).sty {
|
||||||
ty_trait(def_id, ref substs, _) => {
|
ty_trait(def_id, ref substs, _) => {
|
||||||
|
@ -3539,7 +3537,7 @@ pub fn trait_supertraits(cx: ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unwrap and return the result.
|
// Unwrap and return the result.
|
||||||
return @dvec::unwrap(result);
|
return @result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
|
pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
|
||||||
|
|
|
@ -95,7 +95,6 @@ use middle::typeck::{method_self, method_static, method_trait, method_super};
|
||||||
use util::common::indenter;
|
use util::common::indenter;
|
||||||
use util::ppaux::expr_repr;
|
use util::ppaux::expr_repr;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::result;
|
use core::result;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
use core::vec;
|
use core::vec;
|
||||||
|
@ -127,8 +126,8 @@ pub fn lookup(
|
||||||
m_name: m_name,
|
m_name: m_name,
|
||||||
supplied_tps: supplied_tps,
|
supplied_tps: supplied_tps,
|
||||||
impl_dups: HashMap(),
|
impl_dups: HashMap(),
|
||||||
inherent_candidates: DVec(),
|
inherent_candidates: @mut ~[],
|
||||||
extension_candidates: DVec(),
|
extension_candidates: @mut ~[],
|
||||||
deref_args: deref_args,
|
deref_args: deref_args,
|
||||||
};
|
};
|
||||||
let mme = lcx.do_lookup(self_ty);
|
let mme = lcx.do_lookup(self_ty);
|
||||||
|
@ -145,8 +144,8 @@ pub struct LookupContext {
|
||||||
m_name: ast::ident,
|
m_name: ast::ident,
|
||||||
supplied_tps: &self/[ty::t],
|
supplied_tps: &self/[ty::t],
|
||||||
impl_dups: HashMap<def_id, ()>,
|
impl_dups: HashMap<def_id, ()>,
|
||||||
inherent_candidates: DVec<Candidate>,
|
inherent_candidates: @mut ~[Candidate],
|
||||||
extension_candidates: DVec<Candidate>,
|
extension_candidates: @mut ~[Candidate],
|
||||||
deref_args: check::DerefArgs,
|
deref_args: check::DerefArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +187,7 @@ pub impl LookupContext/&self {
|
||||||
self.push_inherent_candidates(self_ty);
|
self.push_inherent_candidates(self_ty);
|
||||||
self.push_extension_candidates(self_ty);
|
self.push_extension_candidates(self_ty);
|
||||||
|
|
||||||
let enum_dids = DVec();
|
let mut enum_dids = ~[];
|
||||||
let mut self_ty = self_ty;
|
let mut self_ty = self_ty;
|
||||||
let mut autoderefs = 0;
|
let mut autoderefs = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -224,7 +223,7 @@ pub impl LookupContext/&self {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.deref(self_ty, &enum_dids) {
|
match self.deref(self_ty, &mut enum_dids) {
|
||||||
None => { break; }
|
None => { break; }
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
self_ty = ty;
|
self_ty = ty;
|
||||||
|
@ -236,7 +235,7 @@ pub impl LookupContext/&self {
|
||||||
self.search_for_autosliced_method(self_ty, autoderefs)
|
self.search_for_autosliced_method(self_ty, autoderefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deref(ty: ty::t, enum_dids: &DVec<ast::def_id>) -> Option<ty::t> {
|
fn deref(ty: ty::t, enum_dids: &mut ~[ast::def_id]) -> Option<ty::t> {
|
||||||
match ty::get(ty).sty {
|
match ty::get(ty).sty {
|
||||||
ty_enum(did, _) => {
|
ty_enum(did, _) => {
|
||||||
// Watch out for newtype'd enums like "enum t = @T".
|
// Watch out for newtype'd enums like "enum t = @T".
|
||||||
|
@ -272,7 +271,7 @@ pub impl LookupContext/&self {
|
||||||
* example, if the receiver is @@C where `C` is a struct type,
|
* example, if the receiver is @@C where `C` is a struct type,
|
||||||
* we'll want to find the inherent impls for `C`. */
|
* we'll want to find the inherent impls for `C`. */
|
||||||
|
|
||||||
let enum_dids = DVec();
|
let mut enum_dids = ~[];
|
||||||
let mut self_ty = self_ty;
|
let mut self_ty = self_ty;
|
||||||
loop {
|
loop {
|
||||||
match get(self_ty).sty {
|
match get(self_ty).sty {
|
||||||
|
@ -307,7 +306,7 @@ pub impl LookupContext/&self {
|
||||||
// n.b.: Generally speaking, we only loop if we hit the
|
// n.b.: Generally speaking, we only loop if we hit the
|
||||||
// fallthrough case in the match above. The exception
|
// fallthrough case in the match above. The exception
|
||||||
// would be newtype enums.
|
// would be newtype enums.
|
||||||
self_ty = match self.deref(self_ty, &enum_dids) {
|
self_ty = match self.deref(self_ty, &mut enum_dids) {
|
||||||
None => { return; }
|
None => { return; }
|
||||||
Some(ty) => { ty }
|
Some(ty) => { ty }
|
||||||
}
|
}
|
||||||
|
@ -330,7 +329,7 @@ pub impl LookupContext/&self {
|
||||||
for opt_impl_infos.each |impl_infos| {
|
for opt_impl_infos.each |impl_infos| {
|
||||||
for impl_infos.each |impl_info| {
|
for impl_infos.each |impl_info| {
|
||||||
self.push_candidates_from_impl(
|
self.push_candidates_from_impl(
|
||||||
&self.extension_candidates, *impl_info);
|
self.extension_candidates, *impl_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +337,7 @@ pub impl LookupContext/&self {
|
||||||
match self.tcx().provided_methods.find(trait_did) {
|
match self.tcx().provided_methods.find(trait_did) {
|
||||||
Some(methods) => {
|
Some(methods) => {
|
||||||
self.push_candidates_from_provided_methods(
|
self.push_candidates_from_provided_methods(
|
||||||
&self.extension_candidates, self_ty, *trait_did,
|
self.extension_candidates, self_ty, *trait_did,
|
||||||
methods);
|
methods);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -606,12 +605,12 @@ pub impl LookupContext/&self {
|
||||||
for opt_impl_infos.each |impl_infos| {
|
for opt_impl_infos.each |impl_infos| {
|
||||||
for impl_infos.each |impl_info| {
|
for impl_infos.each |impl_info| {
|
||||||
self.push_candidates_from_impl(
|
self.push_candidates_from_impl(
|
||||||
&self.inherent_candidates, *impl_info);
|
self.inherent_candidates, *impl_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_candidates_from_impl(&self, candidates: &DVec<Candidate>,
|
fn push_candidates_from_impl(&self, candidates: &mut ~[Candidate],
|
||||||
impl_info: &resolve::Impl) {
|
impl_info: &resolve::Impl) {
|
||||||
if !self.impl_dups.insert(impl_info.did, ()) {
|
if !self.impl_dups.insert(impl_info.did, ()) {
|
||||||
return; // already visited
|
return; // already visited
|
||||||
|
@ -657,10 +656,10 @@ pub impl LookupContext/&self {
|
||||||
|
|
||||||
fn push_candidates_from_provided_methods(
|
fn push_candidates_from_provided_methods(
|
||||||
&self,
|
&self,
|
||||||
candidates: &DVec<Candidate>,
|
candidates: &mut ~[Candidate],
|
||||||
self_ty: ty::t,
|
self_ty: ty::t,
|
||||||
trait_def_id: def_id,
|
trait_def_id: def_id,
|
||||||
methods: @DVec<@ProvidedMethodInfo>) {
|
methods: &mut ~[@ProvidedMethodInfo]) {
|
||||||
debug!("(pushing candidates from provided methods) considering trait \
|
debug!("(pushing candidates from provided methods) considering trait \
|
||||||
id %d:%d",
|
id %d:%d",
|
||||||
trait_def_id.crate,
|
trait_def_id.crate,
|
||||||
|
@ -970,7 +969,7 @@ pub impl LookupContext/&self {
|
||||||
// existing code.
|
// existing code.
|
||||||
|
|
||||||
debug!("searching inherent candidates");
|
debug!("searching inherent candidates");
|
||||||
match self.consider_candidates(self_ty, &self.inherent_candidates) {
|
match self.consider_candidates(self_ty, self.inherent_candidates) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(mme) => {
|
Some(mme) => {
|
||||||
return Some(mme);
|
return Some(mme);
|
||||||
|
@ -978,7 +977,7 @@ pub impl LookupContext/&self {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("searching extension candidates");
|
debug!("searching extension candidates");
|
||||||
match self.consider_candidates(self_ty, &self.extension_candidates) {
|
match self.consider_candidates(self_ty, self.extension_candidates) {
|
||||||
None => {
|
None => {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -990,7 +989,7 @@ pub impl LookupContext/&self {
|
||||||
|
|
||||||
fn consider_candidates(&self,
|
fn consider_candidates(&self,
|
||||||
self_ty: ty::t,
|
self_ty: ty::t,
|
||||||
candidates: &DVec<Candidate>)
|
candidates: &mut ~[Candidate])
|
||||||
-> Option<method_map_entry>
|
-> Option<method_map_entry>
|
||||||
{
|
{
|
||||||
let relevant_candidates =
|
let relevant_candidates =
|
||||||
|
|
|
@ -55,7 +55,6 @@ use syntax::visit::{Visitor, SimpleVisitor};
|
||||||
use syntax::visit::{visit_mod};
|
use syntax::visit::{visit_mod};
|
||||||
use util::ppaux::ty_to_str;
|
use util::ppaux::ty_to_str;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::result::Ok;
|
use core::result::Ok;
|
||||||
use core::hashmap::linear::LinearSet;
|
use core::hashmap::linear::LinearSet;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
|
@ -151,11 +150,11 @@ pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
|
||||||
pub struct CoherenceInfo {
|
pub struct CoherenceInfo {
|
||||||
// Contains implementations of methods that are inherent to a type.
|
// Contains implementations of methods that are inherent to a type.
|
||||||
// Methods in these implementations don't need to be exported.
|
// Methods in these implementations don't need to be exported.
|
||||||
inherent_methods: HashMap<def_id,@DVec<@Impl>>,
|
inherent_methods: HashMap<def_id,@mut ~[@Impl]>,
|
||||||
|
|
||||||
// Contains implementations of methods associated with a trait. For these,
|
// Contains implementations of methods associated with a trait. For these,
|
||||||
// the associated trait must be imported at the call site.
|
// the associated trait must be imported at the call site.
|
||||||
extension_methods: HashMap<def_id,@DVec<@Impl>>,
|
extension_methods: HashMap<def_id,@mut ~[@Impl]>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,9 +371,8 @@ pub impl CoherenceChecker {
|
||||||
for method `%s`",
|
for method `%s`",
|
||||||
*self.crate_context.tcx.sess.str_of(
|
*self.crate_context.tcx.sess.str_of(
|
||||||
provided_method_info.method_info.ident));
|
provided_method_info.method_info.ident));
|
||||||
let method_infos = @DVec();
|
pmm.insert(local_def(impl_id),
|
||||||
method_infos.push(provided_method_info);
|
@mut ~[provided_method_info]);
|
||||||
pmm.insert(local_def(impl_id), method_infos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +384,7 @@ pub impl CoherenceChecker {
|
||||||
match self.crate_context.coherence_info.inherent_methods
|
match self.crate_context.coherence_info.inherent_methods
|
||||||
.find(&base_def_id) {
|
.find(&base_def_id) {
|
||||||
None => {
|
None => {
|
||||||
implementation_list = @DVec();
|
implementation_list = @mut ~[];
|
||||||
self.crate_context.coherence_info.inherent_methods
|
self.crate_context.coherence_info.inherent_methods
|
||||||
.insert(base_def_id, implementation_list);
|
.insert(base_def_id, implementation_list);
|
||||||
}
|
}
|
||||||
|
@ -403,7 +401,7 @@ pub impl CoherenceChecker {
|
||||||
match self.crate_context.coherence_info.extension_methods
|
match self.crate_context.coherence_info.extension_methods
|
||||||
.find(&trait_id) {
|
.find(&trait_id) {
|
||||||
None => {
|
None => {
|
||||||
implementation_list = @DVec();
|
implementation_list = @mut ~[];
|
||||||
self.crate_context.coherence_info.extension_methods
|
self.crate_context.coherence_info.extension_methods
|
||||||
.insert(trait_id, implementation_list);
|
.insert(trait_id, implementation_list);
|
||||||
}
|
}
|
||||||
|
@ -741,13 +739,13 @@ pub impl CoherenceChecker {
|
||||||
// Converts an implementation in the AST to an Impl structure.
|
// Converts an implementation in the AST to an Impl structure.
|
||||||
fn create_impl_from_item(&self, item: @item) -> @Impl {
|
fn create_impl_from_item(&self, item: @item) -> @Impl {
|
||||||
fn add_provided_methods(all_methods: &mut ~[@MethodInfo],
|
fn add_provided_methods(all_methods: &mut ~[@MethodInfo],
|
||||||
all_provided_methods: ~[@ProvidedMethodInfo],
|
all_provided_methods: &mut ~[@ProvidedMethodInfo],
|
||||||
sess: driver::session::Session) {
|
sess: driver::session::Session) {
|
||||||
for all_provided_methods.each |provided_method| {
|
for all_provided_methods.each |provided_method| {
|
||||||
debug!(
|
debug!(
|
||||||
"(creating impl) adding provided method `%s` to impl",
|
"(creating impl) adding provided method `%s` to impl",
|
||||||
*sess.str_of(provided_method.method_info.ident));
|
*sess.str_of(provided_method.method_info.ident));
|
||||||
vec::push(&mut *all_methods, provided_method.method_info);
|
vec::push(all_methods, provided_method.method_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,7 +788,7 @@ pub impl CoherenceChecker {
|
||||||
// Add all provided methods.
|
// Add all provided methods.
|
||||||
add_provided_methods(
|
add_provided_methods(
|
||||||
&mut methods,
|
&mut methods,
|
||||||
all_provided.get(),
|
all_provided,
|
||||||
self.crate_context.tcx.sess);
|
self.crate_context.tcx.sess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -943,9 +941,7 @@ pub impl CoherenceChecker {
|
||||||
trait_method_def_id: trait_method_info.def_id
|
trait_method_def_id: trait_method_info.def_id
|
||||||
};
|
};
|
||||||
|
|
||||||
let method_infos = @DVec();
|
pmm.insert(trait_def_id, @mut ~[provided_method_info]);
|
||||||
method_infos.push(provided_method_info);
|
|
||||||
pmm.insert(trait_def_id, method_infos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
|
||||||
use util::common::{indenter, pluralize};
|
use util::common::{indenter, pluralize};
|
||||||
use util::ppaux;
|
use util::ppaux;
|
||||||
|
|
||||||
use core::dvec;
|
|
||||||
use core::vec;
|
use core::vec;
|
||||||
use syntax::ast::{RegionTyParamBound, TraitTyParamBound};
|
use syntax::ast::{RegionTyParamBound, TraitTyParamBound};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -321,7 +320,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
|
||||||
let tcx = ccx.tcx;
|
let tcx = ccx.tcx;
|
||||||
if tcx.supertraits.contains_key(&local_def(id)) { return; }
|
if tcx.supertraits.contains_key(&local_def(id)) { return; }
|
||||||
|
|
||||||
let instantiated = dvec::DVec();
|
let mut instantiated = ~[];
|
||||||
for trait_refs.each |trait_ref| {
|
for trait_refs.each |trait_ref| {
|
||||||
let (did, tpt) = instantiate_trait_ref(ccx, *trait_ref, rp);
|
let (did, tpt) = instantiate_trait_ref(ccx, *trait_ref, rp);
|
||||||
if instantiated.any(|other_trait: &InstantiatedTraitRef|
|
if instantiated.any(|other_trait: &InstantiatedTraitRef|
|
||||||
|
@ -334,8 +333,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
|
||||||
}
|
}
|
||||||
instantiated.push(InstantiatedTraitRef { def_id: did, tpt: tpt });
|
instantiated.push(InstantiatedTraitRef { def_id: did, tpt: tpt });
|
||||||
}
|
}
|
||||||
tcx.supertraits.insert(local_def(id),
|
tcx.supertraits.insert(local_def(id), @instantiated);
|
||||||
@dvec::unwrap(instantiated));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -549,7 +549,6 @@ use util::ppaux::note_and_explain_region;
|
||||||
|
|
||||||
use core::cell::{Cell, empty_cell};
|
use core::cell::{Cell, empty_cell};
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::result::{Err, Ok, Result};
|
use core::result::{Err, Ok, Result};
|
||||||
use core::to_bytes;
|
use core::to_bytes;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
|
@ -627,7 +626,7 @@ type CombineMap = HashMap<TwoRegions, RegionVid>;
|
||||||
|
|
||||||
pub struct RegionVarBindings {
|
pub struct RegionVarBindings {
|
||||||
tcx: ty::ctxt,
|
tcx: ty::ctxt,
|
||||||
var_spans: DVec<span>,
|
var_spans: ~[span],
|
||||||
constraints: HashMap<Constraint, span>,
|
constraints: HashMap<Constraint, span>,
|
||||||
lubs: CombineMap,
|
lubs: CombineMap,
|
||||||
glbs: CombineMap,
|
glbs: CombineMap,
|
||||||
|
@ -653,7 +652,7 @@ pub struct RegionVarBindings {
|
||||||
pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
|
pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
|
||||||
RegionVarBindings {
|
RegionVarBindings {
|
||||||
tcx: tcx,
|
tcx: tcx,
|
||||||
var_spans: DVec(),
|
var_spans: ~[],
|
||||||
values: empty_cell(),
|
values: empty_cell(),
|
||||||
constraints: HashMap(),
|
constraints: HashMap(),
|
||||||
lubs: CombineMap(),
|
lubs: CombineMap(),
|
||||||
|
|
|
@ -452,12 +452,10 @@ pub mod flatteners {
|
||||||
|
|
||||||
pub fn serialize_value<D: Encoder + FromWriter,
|
pub fn serialize_value<D: Encoder + FromWriter,
|
||||||
T: Encodable<D>>(val: &T) -> ~[u8] {
|
T: Encodable<D>>(val: &T) -> ~[u8] {
|
||||||
let bytes_writer = @BytesWriter();
|
do io::with_bytes_writer |writer| {
|
||||||
let writer = bytes_writer as @Writer;
|
let ser = FromWriter::from_writer(writer);
|
||||||
let ser = FromWriter::from_writer(writer);
|
val.encode(&ser);
|
||||||
val.encode(&ser);
|
}
|
||||||
let bytes = bytes_writer.bytes.check_out(|bytes| bytes);
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromReader {
|
pub trait FromReader {
|
||||||
|
@ -651,7 +649,7 @@ mod test {
|
||||||
|
|
||||||
chan.send(10);
|
chan.send(10);
|
||||||
|
|
||||||
let bytes = chan.byte_chan.writer.bytes.get();
|
let bytes = copy chan.byte_chan.writer.bytes;
|
||||||
|
|
||||||
let reader = BufReader::new(bytes);
|
let reader = BufReader::new(bytes);
|
||||||
let port = serial::reader_port(reader);
|
let port = serial::reader_port(reader);
|
||||||
|
@ -697,7 +695,7 @@ mod test {
|
||||||
|
|
||||||
chan.send(10);
|
chan.send(10);
|
||||||
|
|
||||||
let bytes = chan.byte_chan.writer.bytes.get();
|
let bytes = copy chan.byte_chan.writer.bytes;
|
||||||
|
|
||||||
let reader = BufReader::new(bytes);
|
let reader = BufReader::new(bytes);
|
||||||
let port = pod::reader_port(reader);
|
let port = pod::reader_port(reader);
|
||||||
|
|
|
@ -27,7 +27,6 @@ use core::prelude::*;
|
||||||
use core::hashmap::linear::LinearMap;
|
use core::hashmap::linear::LinearMap;
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::to_str;
|
use core::to_str;
|
||||||
use core::vec;
|
|
||||||
|
|
||||||
/// Represents a json value
|
/// Represents a json value
|
||||||
pub enum Json {
|
pub enum Json {
|
||||||
|
@ -1312,8 +1311,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_equal(str::from_bytes(bw.bytes.data),
|
check_equal(str::from_bytes(bw.bytes), ~"[\"frog\",[\"Henry\",349]]");
|
||||||
~"[\"frog\",[\"Henry\",349]]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1328,8 +1326,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_equal(str::from_bytes(bw.bytes.data),
|
check_equal(str::from_bytes(bw.bytes), ~"\"jodhpurs\"");
|
||||||
~"\"jodhpurs\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1341,8 +1338,7 @@ mod tests {
|
||||||
do encoder.emit_enum_variant (~"None",37,1242) {
|
do encoder.emit_enum_variant (~"None",37,1242) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_equal(str::from_bytes(bw.bytes.data),
|
check_equal(str::from_bytes(bw.bytes), ~"null");
|
||||||
~"null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
//! Sorting methods
|
//! Sorting methods
|
||||||
|
|
||||||
use core::cmp::{Eq, Ord};
|
use core::cmp::{Eq, Ord};
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use core::util;
|
use core::util;
|
||||||
use core::vec::{len, push};
|
use core::vec::{len, push};
|
||||||
|
@ -189,7 +188,7 @@ pub fn tim_sort<T:Copy + Ord>(array: &mut [T]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ms = &MergeState();
|
let mut ms = MergeState();
|
||||||
let min_run = min_run_length(size);
|
let min_run = min_run_length(size);
|
||||||
|
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
|
@ -392,66 +391,63 @@ struct RunState {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MergeState<T> {
|
struct MergeState<T> {
|
||||||
mut min_gallop: uint,
|
min_gallop: uint,
|
||||||
runs: DVec<RunState>,
|
runs: ~[RunState],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixme (#3853) Move into MergeState
|
// Fixme (#3853) Move into MergeState
|
||||||
fn MergeState<T>() -> MergeState<T> {
|
fn MergeState<T>() -> MergeState<T> {
|
||||||
MergeState {
|
MergeState {
|
||||||
min_gallop: MIN_GALLOP,
|
min_gallop: MIN_GALLOP,
|
||||||
runs: DVec(),
|
runs: ~[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy + Ord> MergeState<T> {
|
impl<T:Copy + Ord> MergeState<T> {
|
||||||
fn push_run(&self, run_base: uint, run_len: uint) {
|
fn push_run(&mut self, run_base: uint, run_len: uint) {
|
||||||
let tmp = RunState{base: run_base, len: run_len};
|
let tmp = RunState{base: run_base, len: run_len};
|
||||||
self.runs.push(tmp);
|
self.runs.push(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_at(&self, n: uint, array: &mut [T]) {
|
fn merge_at(&mut self, n: uint, array: &mut [T]) {
|
||||||
let mut size = self.runs.len();
|
let mut size = self.runs.len();
|
||||||
fail_unless!(size >= 2);
|
fail_unless!(size >= 2);
|
||||||
fail_unless!(n == size-2 || n == size-3);
|
fail_unless!(n == size-2 || n == size-3);
|
||||||
|
|
||||||
do self.runs.borrow_mut |arr| {
|
let mut b1 = self.runs[n].base;
|
||||||
|
let mut l1 = self.runs[n].len;
|
||||||
|
let b2 = self.runs[n+1].base;
|
||||||
|
let l2 = self.runs[n+1].len;
|
||||||
|
|
||||||
let mut b1 = arr[n].base;
|
fail_unless!(l1 > 0 && l2 > 0);
|
||||||
let mut l1 = arr[n].len;
|
fail_unless!(b1 + l1 == b2);
|
||||||
let b2 = arr[n+1].base;
|
|
||||||
let l2 = arr[n+1].len;
|
|
||||||
|
|
||||||
fail_unless!(l1 > 0 && l2 > 0);
|
self.runs[n].len = l1 + l2;
|
||||||
fail_unless!(b1 + l1 == b2);
|
if n == size-3 {
|
||||||
|
self.runs[n+1].base = self.runs[n+2].base;
|
||||||
|
self.runs[n+1].len = self.runs[n+2].len;
|
||||||
|
}
|
||||||
|
|
||||||
arr[n].len = l1 + l2;
|
let slice = vec::mut_slice(array, b1, b1+l1);
|
||||||
if n == size-3 {
|
let k = gallop_right(&const array[b2], slice, 0);
|
||||||
arr[n+1].base = arr[n+2].base;
|
b1 += k;
|
||||||
arr[n+1].len = arr[n+2].len;
|
l1 -= k;
|
||||||
}
|
if l1 != 0 {
|
||||||
|
let slice = vec::mut_slice(array, b2, b2+l2);
|
||||||
let slice = vec::mut_slice(array, b1, b1+l1);
|
let l2 = gallop_left(
|
||||||
let k = gallop_right(&const array[b2], slice, 0);
|
&const array[b1+l1-1],slice,l2-1);
|
||||||
b1 += k;
|
if l2 > 0 {
|
||||||
l1 -= k;
|
if l1 <= l2 {
|
||||||
if l1 != 0 {
|
self.merge_lo(array, b1, l1, b2, l2);
|
||||||
let slice = vec::mut_slice(array, b2, b2+l2);
|
} else {
|
||||||
let l2 = gallop_left(
|
self.merge_hi(array, b1, l1, b2, l2);
|
||||||
&const array[b1+l1-1],slice,l2-1);
|
|
||||||
if l2 > 0 {
|
|
||||||
if l1 <= l2 {
|
|
||||||
self.merge_lo(array, b1, l1, b2, l2);
|
|
||||||
} else {
|
|
||||||
self.merge_hi(array, b1, l1, b2, l2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.runs.pop();
|
self.runs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_lo(&self, array: &mut [T], base1: uint, len1: uint,
|
fn merge_lo(&mut self, array: &mut [T], base1: uint, len1: uint,
|
||||||
base2: uint, len2: uint) {
|
base2: uint, len2: uint) {
|
||||||
fail_unless!(len1 != 0 && len2 != 0 && base1+len1 == base2);
|
fail_unless!(len1 != 0 && len2 != 0 && base1+len1 == base2);
|
||||||
|
|
||||||
|
@ -554,7 +550,7 @@ pub impl<T:Copy + Ord> MergeState<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_hi(&self, array: &mut [T], base1: uint, len1: uint,
|
fn merge_hi(&mut self, array: &mut [T], base1: uint, len1: uint,
|
||||||
base2: uint, len2: uint) {
|
base2: uint, len2: uint) {
|
||||||
fail_unless!(len1 != 1 && len2 != 0 && base1 + len1 == base2);
|
fail_unless!(len1 != 1 && len2 != 0 && base1 + len1 == base2);
|
||||||
|
|
||||||
|
@ -672,32 +668,28 @@ pub impl<T:Copy + Ord> MergeState<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_collapse(&self, array: &mut [T]) {
|
fn merge_collapse(&mut self, array: &mut [T]) {
|
||||||
while self.runs.len() > 1 {
|
while self.runs.len() > 1 {
|
||||||
let mut n = self.runs.len()-2;
|
let mut n = self.runs.len()-2;
|
||||||
let chk = do self.runs.borrow |arr| {
|
if n > 0 &&
|
||||||
if n > 0 && arr[n-1].len <= arr[n].len + arr[n+1].len {
|
self.runs[n-1].len <= self.runs[n].len + self.runs[n+1].len
|
||||||
if arr[n-1].len < arr[n+1].len { n -= 1; }
|
{
|
||||||
true
|
if self.runs[n-1].len < self.runs[n+1].len { n -= 1; }
|
||||||
} else if arr[n].len <= arr[n+1].len {
|
} else if self.runs[n].len <= self.runs[n+1].len {
|
||||||
true
|
/* keep going */
|
||||||
} else {
|
} else {
|
||||||
false
|
break;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
if !chk { break; }
|
|
||||||
self.merge_at(n, array);
|
self.merge_at(n, array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_force_collapse(&self, array: &mut [T]) {
|
fn merge_force_collapse(&mut self, array: &mut [T]) {
|
||||||
while self.runs.len() > 1 {
|
while self.runs.len() > 1 {
|
||||||
let mut n = self.runs.len()-2;
|
let mut n = self.runs.len()-2;
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
do self.runs.borrow |arr| {
|
if self.runs[n-1].len < self.runs[n+1].len {
|
||||||
if arr[n-1].len < arr[n+1].len {
|
n -= 1;
|
||||||
n -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.merge_at(n, array);
|
self.merge_at(n, array);
|
||||||
|
|
|
@ -24,7 +24,6 @@ source code snippets, etc.
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
|
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::to_bytes;
|
use core::to_bytes;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
|
@ -242,7 +241,7 @@ pub struct FileMap {
|
||||||
/// Locations of lines beginnings in the source code
|
/// Locations of lines beginnings in the source code
|
||||||
lines: @mut ~[BytePos],
|
lines: @mut ~[BytePos],
|
||||||
/// Locations of multi-byte characters in the source code
|
/// Locations of multi-byte characters in the source code
|
||||||
multibyte_chars: DVec<MultiByteChar>
|
multibyte_chars: @mut ~[MultiByteChar],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl FileMap {
|
pub impl FileMap {
|
||||||
|
@ -282,13 +281,13 @@ pub impl FileMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CodeMap {
|
pub struct CodeMap {
|
||||||
files: DVec<@FileMap>
|
files: @mut ~[@FileMap]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl CodeMap {
|
pub impl CodeMap {
|
||||||
static pub fn new() -> CodeMap {
|
static pub fn new() -> CodeMap {
|
||||||
CodeMap {
|
CodeMap {
|
||||||
files: DVec()
|
files: @mut ~[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ pub impl CodeMap {
|
||||||
name: filename, substr: substr, src: src,
|
name: filename, substr: substr, src: src,
|
||||||
start_pos: BytePos(start_pos),
|
start_pos: BytePos(start_pos),
|
||||||
lines: @mut ~[],
|
lines: @mut ~[],
|
||||||
multibyte_chars: DVec()
|
multibyte_chars: @mut ~[],
|
||||||
};
|
};
|
||||||
|
|
||||||
self.files.push(filemap);
|
self.files.push(filemap);
|
||||||
|
|
|
@ -18,7 +18,6 @@ use core::io;
|
||||||
use core::option;
|
use core::option;
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::vec;
|
use core::vec;
|
||||||
use core::dvec::DVec;
|
|
||||||
|
|
||||||
use std::term;
|
use std::term;
|
||||||
|
|
||||||
|
@ -203,7 +202,7 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: &str) {
|
||||||
io::stderr().write_str(fmt!(" %s\n", msg));
|
io::stderr().write_str(fmt!(" %s\n", msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect(messages: @DVec<~str>)
|
pub fn collect(messages: @mut ~[~str])
|
||||||
-> @fn(Option<(@codemap::CodeMap, span)>, &str, level) {
|
-> @fn(Option<(@codemap::CodeMap, span)>, &str, level) {
|
||||||
let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
|
let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
|
||||||
|_o, msg: &str, _l| { messages.push(msg.to_str()); };
|
|_o, msg: &str, _l| { messages.push(msg.to_str()); };
|
||||||
|
|
|
@ -29,7 +29,6 @@ use parse::token::special_idents::clownshoes_extensions;
|
||||||
use ast_util;
|
use ast_util;
|
||||||
use opt_vec;
|
use opt_vec;
|
||||||
|
|
||||||
use core::dvec;
|
|
||||||
use core::uint;
|
use core::uint;
|
||||||
|
|
||||||
enum Junction {
|
enum Junction {
|
||||||
|
@ -99,7 +98,7 @@ fn expand_deriving(cx: ext_ctxt,
|
||||||
expand_deriving_struct_def: ExpandDerivingStructDefFn,
|
expand_deriving_struct_def: ExpandDerivingStructDefFn,
|
||||||
expand_deriving_enum_def: ExpandDerivingEnumDefFn)
|
expand_deriving_enum_def: ExpandDerivingEnumDefFn)
|
||||||
-> ~[@item] {
|
-> ~[@item] {
|
||||||
let result = dvec::DVec();
|
let mut result = ~[];
|
||||||
for in_items.each |item| {
|
for in_items.each |item| {
|
||||||
result.push(copy *item);
|
result.push(copy *item);
|
||||||
match item.node {
|
match item.node {
|
||||||
|
@ -120,7 +119,7 @@ fn expand_deriving(cx: ext_ctxt,
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dvec::unwrap(result)
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item {
|
fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item {
|
||||||
|
@ -202,14 +201,13 @@ fn create_self_type_with_params(cx: ext_ctxt,
|
||||||
generics: &Generics)
|
generics: &Generics)
|
||||||
-> @Ty {
|
-> @Ty {
|
||||||
// Create the type parameters on the `self` path.
|
// Create the type parameters on the `self` path.
|
||||||
let self_ty_params = dvec::DVec();
|
let mut self_ty_params = ~[];
|
||||||
for generics.ty_params.each |ty_param| {
|
for generics.ty_params.each |ty_param| {
|
||||||
let self_ty_param = build::mk_simple_ty_path(cx,
|
let self_ty_param = build::mk_simple_ty_path(cx,
|
||||||
span,
|
span,
|
||||||
ty_param.ident);
|
ty_param.ident);
|
||||||
self_ty_params.push(self_ty_param);
|
self_ty_params.push(self_ty_param);
|
||||||
}
|
}
|
||||||
let self_ty_params = dvec::unwrap(self_ty_params);
|
|
||||||
|
|
||||||
// Create the type of `self`.
|
// Create the type of `self`.
|
||||||
let self_type = build::mk_raw_path_(span,
|
let self_type = build::mk_raw_path_(span,
|
||||||
|
@ -433,7 +431,7 @@ fn create_subpatterns(cx: ext_ctxt,
|
||||||
prefix: ~str,
|
prefix: ~str,
|
||||||
n: uint)
|
n: uint)
|
||||||
-> ~[@pat] {
|
-> ~[@pat] {
|
||||||
let subpats = dvec::DVec();
|
let mut subpats = ~[];
|
||||||
for uint::range(0, n) |_i| {
|
for uint::range(0, n) |_i| {
|
||||||
// Create the subidentifier.
|
// Create the subidentifier.
|
||||||
let index = subpats.len().to_str();
|
let index = subpats.len().to_str();
|
||||||
|
@ -445,7 +443,7 @@ fn create_subpatterns(cx: ext_ctxt,
|
||||||
let subpat = build::mk_pat(cx, span, subpat);
|
let subpat = build::mk_pat(cx, span, subpat);
|
||||||
subpats.push(subpat);
|
subpats.push(subpat);
|
||||||
}
|
}
|
||||||
return dvec::unwrap(subpats);
|
return subpats;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_struct_tuple(struct_def: &struct_def) -> bool {
|
fn is_struct_tuple(struct_def: &struct_def) -> bool {
|
||||||
|
@ -809,7 +807,7 @@ fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt,
|
||||||
let self_ident = cx.ident_of(~"self");
|
let self_ident = cx.ident_of(~"self");
|
||||||
|
|
||||||
// Create the body of the method.
|
// Create the body of the method.
|
||||||
let statements = dvec::DVec();
|
let mut statements = ~[];
|
||||||
for struct_def.fields.each |struct_field| {
|
for struct_def.fields.each |struct_field| {
|
||||||
match struct_field.node.kind {
|
match struct_field.node.kind {
|
||||||
named_field(ident, _, _) => {
|
named_field(ident, _, _) => {
|
||||||
|
@ -833,7 +831,6 @@ fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the method itself.
|
// Create the method itself.
|
||||||
let statements = dvec::unwrap(statements);
|
|
||||||
return create_iter_bytes_method(cx, span, statements);
|
return create_iter_bytes_method(cx, span, statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,9 +939,9 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the arms of the self match in the method body.
|
// Create the arms of the self match in the method body.
|
||||||
let self_arms = dvec::DVec();
|
let mut self_arms = ~[];
|
||||||
for enum_definition.variants.each |self_variant| {
|
for enum_definition.variants.each |self_variant| {
|
||||||
let other_arms = dvec::DVec();
|
let mut other_arms = ~[];
|
||||||
|
|
||||||
// Create the matching pattern.
|
// Create the matching pattern.
|
||||||
let matching_pat = create_enum_variant_pattern(cx,
|
let matching_pat = create_enum_variant_pattern(cx,
|
||||||
|
@ -1026,7 +1023,6 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
|
||||||
// Create the self pattern body.
|
// Create the self pattern body.
|
||||||
let other_expr = build::mk_path(cx, span, ~[ other_ident ]);
|
let other_expr = build::mk_path(cx, span, ~[ other_ident ]);
|
||||||
let other_expr = build::mk_unary(cx, span, deref, other_expr);
|
let other_expr = build::mk_unary(cx, span, deref, other_expr);
|
||||||
let other_arms = dvec::unwrap(other_arms);
|
|
||||||
let other_match_expr = expr_match(other_expr, other_arms);
|
let other_match_expr = expr_match(other_expr, other_arms);
|
||||||
let other_match_expr = build::mk_expr(cx,
|
let other_match_expr = build::mk_expr(cx,
|
||||||
span,
|
span,
|
||||||
|
@ -1047,7 +1043,6 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
|
||||||
// Create the method body.
|
// Create the method body.
|
||||||
let self_expr = build::mk_path(cx, span, ~[ self_ident ]);
|
let self_expr = build::mk_path(cx, span, ~[ self_ident ]);
|
||||||
let self_expr = build::mk_unary(cx, span, deref, self_expr);
|
let self_expr = build::mk_unary(cx, span, deref, self_expr);
|
||||||
let self_arms = dvec::unwrap(self_arms);
|
|
||||||
let self_match_expr = expr_match(self_expr, self_arms);
|
let self_match_expr = expr_match(self_expr, self_arms);
|
||||||
let self_match_expr = build::mk_expr(cx, span, self_match_expr);
|
let self_match_expr = build::mk_expr(cx, span, self_match_expr);
|
||||||
|
|
||||||
|
@ -1148,7 +1143,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feed the discriminant to the byte iteration function.
|
// Feed the discriminant to the byte iteration function.
|
||||||
let stmts = dvec::DVec();
|
let mut stmts = ~[];
|
||||||
let discrim_stmt = call_substructure_iter_bytes_method(cx,
|
let discrim_stmt = call_substructure_iter_bytes_method(cx,
|
||||||
span,
|
span,
|
||||||
discriminant);
|
discriminant);
|
||||||
|
@ -1167,7 +1162,6 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the pattern body.
|
// Create the pattern body.
|
||||||
let stmts = dvec::unwrap(stmts);
|
|
||||||
let match_body_block = build::mk_block_(cx, span, stmts);
|
let match_body_block = build::mk_block_(cx, span, stmts);
|
||||||
|
|
||||||
// Create the arm.
|
// Create the arm.
|
||||||
|
|
|
@ -19,8 +19,6 @@ use parse::parser::Parser;
|
||||||
use parse::token::{Token, EOF, to_str, nonterminal};
|
use parse::token::{Token, EOF, to_str, nonterminal};
|
||||||
use parse::token;
|
use parse::token;
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::dvec;
|
|
||||||
use core::option::{Option, Some, None};
|
use core::option::{Option, Some, None};
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
|
@ -115,7 +113,7 @@ pub struct MatcherPos {
|
||||||
sep: Option<Token>,
|
sep: Option<Token>,
|
||||||
idx: uint,
|
idx: uint,
|
||||||
up: matcher_pos_up, // mutable for swapping only
|
up: matcher_pos_up, // mutable for swapping only
|
||||||
matches: ~[DVec<@named_match>],
|
matches: ~[~[@named_match]],
|
||||||
match_lo: uint, match_hi: uint,
|
match_lo: uint, match_hi: uint,
|
||||||
sp_lo: BytePos,
|
sp_lo: BytePos,
|
||||||
}
|
}
|
||||||
|
@ -151,7 +149,7 @@ pub fn initial_matcher_pos(+ms: ~[matcher], +sep: Option<Token>, lo: BytePos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let matches = vec::from_fn(count_names(ms), |_i| dvec::DVec());
|
let matches = vec::from_fn(count_names(ms), |_i| ~[]);
|
||||||
~MatcherPos {
|
~MatcherPos {
|
||||||
elts: ms,
|
elts: ms,
|
||||||
sep: sep,
|
sep: sep,
|
||||||
|
@ -283,7 +281,7 @@ pub fn parse(
|
||||||
|
|
||||||
// Only touch the binders we have actually bound
|
// Only touch the binders we have actually bound
|
||||||
for uint::range(ei.match_lo, ei.match_hi) |idx| {
|
for uint::range(ei.match_lo, ei.match_hi) |idx| {
|
||||||
let sub = ei.matches[idx].get();
|
let sub = ei.matches[idx];
|
||||||
new_pos.matches[idx]
|
new_pos.matches[idx]
|
||||||
.push(@matched_seq(sub,
|
.push(@matched_seq(sub,
|
||||||
mk_sp(ei.sp_lo,
|
mk_sp(ei.sp_lo,
|
||||||
|
@ -331,7 +329,7 @@ pub fn parse(
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = vec::map(ei.matches, // fresh, same size:
|
let matches = vec::map(ei.matches, // fresh, same size:
|
||||||
|_m| DVec::<@named_match>());
|
|_m| ~[]);
|
||||||
let ei_t = ei;
|
let ei_t = ei;
|
||||||
cur_eis.push(~MatcherPos {
|
cur_eis.push(~MatcherPos {
|
||||||
elts: copy *matchers,
|
elts: copy *matchers,
|
||||||
|
@ -358,9 +356,11 @@ pub fn parse(
|
||||||
/* error messages here could be improved with links to orig. rules */
|
/* error messages here could be improved with links to orig. rules */
|
||||||
if tok == EOF {
|
if tok == EOF {
|
||||||
if eof_eis.len() == 1u {
|
if eof_eis.len() == 1u {
|
||||||
return success(
|
let mut v = ~[];
|
||||||
nameize(sess, ms,
|
for vec::each_mut(eof_eis[0u].matches) |dv| {
|
||||||
eof_eis[0u].matches.map(|dv| dv.pop())));
|
v.push(dv.pop());
|
||||||
|
}
|
||||||
|
return success(nameize(sess, ms, v));
|
||||||
} else if eof_eis.len() > 1u {
|
} else if eof_eis.len() > 1u {
|
||||||
return error(sp, ~"Ambiguity: multiple successful parses");
|
return error(sp, ~"Ambiguity: multiple successful parses");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -303,9 +303,9 @@ mod test {
|
||||||
use util::testing::*;
|
use util::testing::*;
|
||||||
|
|
||||||
#[test] fn to_json_str (val: Encodable<std::json::Encoder>) -> ~str {
|
#[test] fn to_json_str (val: Encodable<std::json::Encoder>) -> ~str {
|
||||||
let bw = @io::BytesWriter();
|
do io::with_str_writer |writer| {
|
||||||
val.encode(~std::json::Encoder(bw as io::Writer));
|
val.encode(~std::json::Encoder(writer));
|
||||||
str::from_bytes(bw.bytes.data)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn alltts () {
|
#[test] fn alltts () {
|
||||||
|
|
|
@ -28,7 +28,6 @@ use print::pp;
|
||||||
use print::pprust;
|
use print::pprust;
|
||||||
|
|
||||||
use core::char;
|
use core::char;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::io;
|
use core::io;
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::u64;
|
use core::u64;
|
||||||
|
@ -63,7 +62,7 @@ pub struct ps {
|
||||||
comments: Option<~[comments::cmnt]>,
|
comments: Option<~[comments::cmnt]>,
|
||||||
literals: Option<~[comments::lit]>,
|
literals: Option<~[comments::lit]>,
|
||||||
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral,
|
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral,
|
||||||
boxes: DVec<pp::breaks>,
|
boxes: @mut ~[pp::breaks],
|
||||||
ann: pp_ann
|
ann: pp_ann
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +87,7 @@ pub fn rust_printer(writer: io::Writer, intr: @ident_interner) -> @ps {
|
||||||
cur_cmnt: 0,
|
cur_cmnt: 0,
|
||||||
cur_lit: 0
|
cur_lit: 0
|
||||||
},
|
},
|
||||||
boxes: DVec(),
|
boxes: @mut ~[],
|
||||||
ann: no_ann()
|
ann: no_ann()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,7 @@ pub fn print_crate(cm: @CodeMap, intr: @ident_interner,
|
||||||
cur_cmnt: 0,
|
cur_cmnt: 0,
|
||||||
cur_lit: 0
|
cur_lit: 0
|
||||||
},
|
},
|
||||||
boxes: DVec(),
|
boxes: @mut ~[],
|
||||||
ann: ann
|
ann: ann
|
||||||
};
|
};
|
||||||
print_crate_(s, crate);
|
print_crate_(s, crate);
|
||||||
|
|
|
@ -13,12 +13,11 @@
|
||||||
// type, and vice versa.
|
// type, and vice versa.
|
||||||
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::hashmap::linear::LinearMap;
|
use core::hashmap::linear::LinearMap;
|
||||||
|
|
||||||
pub struct Interner<T> {
|
pub struct Interner<T> {
|
||||||
priv map: @mut LinearMap<T, uint>,
|
priv map: @mut LinearMap<T, uint>,
|
||||||
priv vect: DVec<T>,
|
priv vect: @mut ~[T],
|
||||||
}
|
}
|
||||||
|
|
||||||
// when traits can extend traits, we should extend index<uint,T> to get []
|
// when traits can extend traits, we should extend index<uint,T> to get []
|
||||||
|
@ -26,7 +25,7 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
|
||||||
static fn new() -> Interner<T> {
|
static fn new() -> Interner<T> {
|
||||||
Interner {
|
Interner {
|
||||||
map: @mut LinearMap::new(),
|
map: @mut LinearMap::new(),
|
||||||
vect: DVec(),
|
vect: @mut ~[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
|
||||||
// this isn't "pure" in the traditional sense, because it can go from
|
// this isn't "pure" in the traditional sense, because it can go from
|
||||||
// failing to returning a value as items are interned. But for typestate,
|
// failing to returning a value as items are interned. But for typestate,
|
||||||
// where we first check a pred and then rely on it, ceasing to fail is ok.
|
// where we first check a pred and then rely on it, ceasing to fail is ok.
|
||||||
pure fn get(&self, idx: uint) -> T { self.vect.get_elt(idx) }
|
pure fn get(&self, idx: uint) -> T { self.vect[idx] }
|
||||||
|
|
||||||
fn len(&self) -> uint { self.vect.len() }
|
fn len(&self) -> uint { self.vect.len() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,9 @@
|
||||||
|
|
||||||
#[legacy_modes];
|
#[legacy_modes];
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
|
|
||||||
pub struct Entry<A,B> {key: A, value: B}
|
pub struct Entry<A,B> {key: A, value: B}
|
||||||
|
|
||||||
pub struct alist<A,B> { eq_fn: @fn(A,A) -> bool, data: DVec<Entry<A,B>> }
|
pub struct alist<A,B> { eq_fn: @fn(A,A) -> bool, data: @mut ~[Entry<A,B>] }
|
||||||
|
|
||||||
pub fn alist_add<A:Copy,B:Copy>(lst: alist<A,B>, k: A, v: B) {
|
pub fn alist_add<A:Copy,B:Copy>(lst: alist<A,B>, k: A, v: B) {
|
||||||
lst.data.push(Entry{key:k, value:v});
|
lst.data.push(Entry{key:k, value:v});
|
||||||
|
@ -31,12 +29,12 @@ pub fn alist_get<A:Copy,B:Copy>(lst: alist<A,B>, k: A) -> B {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_int_alist<B:Copy>() -> alist<int, B> {
|
pub fn new_int_alist<B:Copy>() -> alist<int, B> {
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return alist {eq_fn: eq_int, data: DVec()};
|
return alist {eq_fn: eq_int, data: @mut ~[]};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_int_alist_2<B:Copy>() -> alist<int, B> {
|
pub fn new_int_alist_2<B:Copy>() -> alist<int, B> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return alist {eq_fn: eq_int, data: DVec()};
|
return alist {eq_fn: eq_int, data: @mut ~[]};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@
|
||||||
|
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
|
||||||
use core::dvec::*;
|
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
|
|
||||||
pub type header_map = HashMap<~str, @DVec<@~str>>;
|
pub type header_map = HashMap<~str, @mut ~[@~str]>;
|
||||||
|
|
||||||
// the unused ty param is necessary so this gets monomorphized
|
// the unused ty param is necessary so this gets monomorphized
|
||||||
pub fn request<T:Copy>(req: header_map) {
|
pub fn request<T:Copy>(req: header_map) {
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// A raw test of vector appending performance.
|
|
||||||
|
|
||||||
extern mod std;
|
|
||||||
use core::dvec::DVec;
|
|
||||||
use core::io::WriterUtil;
|
|
||||||
|
|
||||||
fn collect_raw(num: uint) -> ~[uint] {
|
|
||||||
let mut result = ~[];
|
|
||||||
for uint::range(0u, num) |i| {
|
|
||||||
result.push(i);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn collect_dvec(num: uint) -> ~[uint] {
|
|
||||||
let result = DVec();
|
|
||||||
for uint::range(0u, num) |i| {
|
|
||||||
result.push(i);
|
|
||||||
}
|
|
||||||
return dvec::unwrap(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let args = os::args();
|
|
||||||
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
||||||
~[~"", ~"50000000"]
|
|
||||||
} else if args.len() <= 1u {
|
|
||||||
~[~"", ~"100000"]
|
|
||||||
} else {
|
|
||||||
args
|
|
||||||
};
|
|
||||||
let max = uint::from_str(args[1]).get();
|
|
||||||
let start = std::time::precise_time_s();
|
|
||||||
let raw_v = collect_raw(max);
|
|
||||||
let mid = std::time::precise_time_s();
|
|
||||||
let dvec_v = collect_dvec(max);
|
|
||||||
let end = std::time::precise_time_s();
|
|
||||||
|
|
||||||
// check each vector
|
|
||||||
fail_unless!(raw_v.len() == max);
|
|
||||||
for raw_v.eachi |i, v| { fail_unless!(i == *v); }
|
|
||||||
fail_unless!(dvec_v.len() == max);
|
|
||||||
for dvec_v.eachi |i, v| { fail_unless!(i == *v); }
|
|
||||||
|
|
||||||
let raw = mid - start;
|
|
||||||
let dvec = end - mid;
|
|
||||||
|
|
||||||
let maxf = max as float;
|
|
||||||
let rawf = raw as float;
|
|
||||||
let dvecf = dvec as float;
|
|
||||||
|
|
||||||
io::stdout().write_str(fmt!("Raw : %? seconds\n", raw));
|
|
||||||
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/rawf));
|
|
||||||
io::stdout().write_str(fmt!("\n"));
|
|
||||||
io::stdout().write_str(fmt!("Dvec : %? seconds\n", dvec));
|
|
||||||
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/dvecf));
|
|
||||||
io::stdout().write_str(fmt!("\n"));
|
|
||||||
|
|
||||||
if dvec < raw {
|
|
||||||
io::stdout().write_str(fmt!("Dvec is %f%% faster than raw\n",
|
|
||||||
(rawf - dvecf) / rawf * 100.0));
|
|
||||||
} else {
|
|
||||||
io::stdout().write_str(fmt!("Raw is %f%% faster than dvec\n",
|
|
||||||
(dvecf - rawf) / dvecf * 100.0));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,10 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use core::dvec::DVec;
|
|
||||||
|
|
||||||
struct parser {
|
struct parser {
|
||||||
tokens: DVec<int>,
|
tokens: ~[int],
|
||||||
}
|
}
|
||||||
|
|
||||||
trait parse {
|
trait parse {
|
||||||
|
@ -20,7 +18,7 @@ trait parse {
|
||||||
|
|
||||||
impl parse for parser {
|
impl parse for parser {
|
||||||
fn parse() -> ~[int] {
|
fn parse() -> ~[int] {
|
||||||
::core::dvec::unwrap(self.tokens) //~ ERROR moving out of immutable field
|
self.tokens //~ ERROR moving out of immutable field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
fn foo() -> int { 22 }
|
fn foo() -> int { 22 }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = dvec::DVec::<@fn() -> int>();
|
let mut x: ~[@fn() -> int] = ~[];
|
||||||
x.push(foo);
|
x.push(foo);
|
||||||
fail_unless!((x[0])() == 22);
|
fail_unless!((x[0])() == 22);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let x = dvec::DVec();
|
|
||||||
x.push(1);
|
|
||||||
io::println(fmt!("%d", x[0]));
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let d = dvec::DVec();
|
|
||||||
d.push(3);
|
|
||||||
d.push(4);
|
|
||||||
fail_unless!(d.get() == ~[3, 4]);
|
|
||||||
d.set(~[5]);
|
|
||||||
d.push(6);
|
|
||||||
d.push(7);
|
|
||||||
d.push(8);
|
|
||||||
d.push(9);
|
|
||||||
d.push(10);
|
|
||||||
d.push_all(~[11, 12, 13]);
|
|
||||||
d.push_slice(~[11, 12, 13], 1u, 2u);
|
|
||||||
|
|
||||||
let exp = ~[5, 6, 7, 8, 9, 10, 11, 12, 13, 12];
|
|
||||||
fail_unless!(d.get() == exp);
|
|
||||||
fail_unless!(d.get() == exp);
|
|
||||||
fail_unless!(d.len() == exp.len());
|
|
||||||
|
|
||||||
for d.eachi |i, e| {
|
|
||||||
fail_unless!(*e == exp[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let v = dvec::unwrap(d);
|
|
||||||
fail_unless!(v == exp);
|
|
||||||
}
|
|
|
@ -15,12 +15,11 @@ extern mod req;
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
|
||||||
use req::*;
|
use req::*;
|
||||||
use std::oldmap::*;
|
|
||||||
use std::oldmap::HashMap;
|
use std::oldmap::HashMap;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let v = ~[@~"hi"];
|
let v = ~[@~"hi"];
|
||||||
let m: req::header_map = HashMap();
|
let m: req::header_map = HashMap();
|
||||||
m.insert(~"METHOD", @dvec::from_vec(v));
|
m.insert(~"METHOD", @mut v);
|
||||||
request::<int>(m);
|
request::<int>(m);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue