Skip to content

Commit 2bcd951

Browse files
committed
auto merge of #11974 : huonw/rust/no-at-vec, r=pcwalton
This removes @[] from the parser as well as much of the handling of it (and `@str`) from the compiler as I can find. I've just rebased @pcwalton's (already reviewed) `@str` removal (and fixed the problems in a separate commit); the only new work is the trailing commits with my authorship. Closes #11967
2 parents 60ffbeb + 2125074 commit 2bcd951

File tree

162 files changed

+2078
-2639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+2078
-2639
lines changed

doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,7 @@ A value of type `str` is a Unicode string,
30793079
represented as a vector of 8-bit unsigned bytes holding a sequence of UTF-8 codepoints.
30803080
Since `str` is of unknown size, it is not a _first class_ type,
30813081
but can only be instantiated through a pointer type,
3082-
such as `&str`, `@str` or `~str`.
3082+
such as `&str` or `~str`.
30833083

30843084
### Tuple types
30853085

@@ -3115,7 +3115,7 @@ Such a definite-sized vector type is a first-class type, since its size is known
31153115
A vector without such a size is said to be of _indefinite_ size,
31163116
and is therefore not a _first-class_ type.
31173117
An indefinite-size vector can only be instantiated through a pointer type,
3118-
such as `&[T]`, `@[T]` or `~[T]`.
3118+
such as `&[T]` or `~[T]`.
31193119
The kind of a vector type depends on the kind of its element type,
31203120
as with other simple structural types.
31213121

src/libarena/lib.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,38 @@ extern mod extra;
2727
use extra::list::{List, Cons, Nil};
2828
use extra::list;
2929

30-
use std::at_vec;
3130
use std::cast::{transmute, transmute_mut, transmute_mut_region};
3231
use std::cast;
3332
use std::cell::{Cell, RefCell};
3433
use std::num;
3534
use std::ptr;
3635
use std::kinds::marker;
3736
use std::mem;
37+
use std::rc::Rc;
3838
use std::rt::global_heap;
3939
use std::unstable::intrinsics::{TyDesc, get_tydesc};
4040
use std::unstable::intrinsics;
4141
use std::util;
42+
use std::vec;
4243

4344
// The way arena uses arrays is really deeply awful. The arrays are
4445
// allocated, and have capacities reserved, but the fill for the array
4546
// will always stay at 0.
4647
#[deriving(Clone)]
4748
struct Chunk {
48-
data: RefCell<@[u8]>,
49+
data: Rc<RefCell<~[u8]>>,
4950
fill: Cell<uint>,
5051
is_pod: Cell<bool>,
5152
}
53+
impl Chunk {
54+
fn capacity(&self) -> uint {
55+
self.data.borrow().borrow().get().capacity()
56+
}
57+
58+
unsafe fn as_ptr(&self) -> *u8 {
59+
self.data.borrow().borrow().get().as_ptr()
60+
}
61+
}
5262

5363
// Arenas are used to quickly allocate objects that share a
5464
// lifetime. The arena uses ~[u8] vectors as a backing store to
@@ -97,10 +107,8 @@ impl Arena {
97107
}
98108

99109
fn chunk(size: uint, is_pod: bool) -> Chunk {
100-
let mut v: @[u8] = @[];
101-
unsafe { at_vec::raw::reserve(&mut v, size); }
102110
Chunk {
103-
data: RefCell::new(unsafe { cast::transmute(v) }),
111+
data: Rc::new(RefCell::new(vec::with_capacity(size))),
104112
fill: Cell::new(0u),
105113
is_pod: Cell::new(is_pod),
106114
}
@@ -131,10 +139,7 @@ fn round_up(base: uint, align: uint) -> uint {
131139
// in it.
132140
unsafe fn destroy_chunk(chunk: &Chunk) {
133141
let mut idx = 0;
134-
let buf = {
135-
let data = chunk.data.borrow();
136-
data.get().as_ptr()
137-
};
142+
let buf = chunk.as_ptr();
138143
let fill = chunk.fill.get();
139144

140145
while idx < fill {
@@ -172,11 +177,13 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
172177
}
173178

174179
impl Arena {
180+
fn chunk_size(&self) -> uint {
181+
self.pod_head.capacity()
182+
}
175183
// Functions for the POD part of the arena
176184
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
177185
// Allocate a new chunk.
178-
let chunk_size = at_vec::capacity(self.pod_head.data.get());
179-
let new_min_chunk_size = num::max(n_bytes, chunk_size);
186+
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
180187
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
181188
self.pod_head =
182189
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -190,15 +197,15 @@ impl Arena {
190197
let this = transmute_mut_region(self);
191198
let start = round_up(this.pod_head.fill.get(), align);
192199
let end = start + n_bytes;
193-
if end > at_vec::capacity(this.pod_head.data.get()) {
200+
if end > self.chunk_size() {
194201
return this.alloc_pod_grow(n_bytes, align);
195202
}
196203
this.pod_head.fill.set(end);
197204

198205
//debug!("idx = {}, size = {}, align = {}, fill = {}",
199206
// start, n_bytes, align, head.fill.get());
200207

201-
ptr::offset(this.pod_head.data.get().as_ptr(), start as int)
208+
this.pod_head.as_ptr().offset(start as int)
202209
}
203210
}
204211

@@ -217,8 +224,7 @@ impl Arena {
217224
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
218225
-> (*u8, *u8) {
219226
// Allocate a new chunk.
220-
let chunk_size = at_vec::capacity(self.head.data.get());
221-
let new_min_chunk_size = num::max(n_bytes, chunk_size);
227+
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
222228
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
223229
self.head =
224230
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
@@ -244,7 +250,7 @@ impl Arena {
244250
end = start + n_bytes;
245251
}
246252

247-
if end > at_vec::capacity(self.head.data.get()) {
253+
if end > self.head.capacity() {
248254
return self.alloc_nonpod_grow(n_bytes, align);
249255
}
250256

@@ -254,7 +260,7 @@ impl Arena {
254260
//debug!("idx = {}, size = {}, align = {}, fill = {}",
255261
// start, n_bytes, align, head.fill);
256262

257-
let buf = self.head.data.get().as_ptr();
263+
let buf = self.head.as_ptr();
258264
return (ptr::offset(buf, tydesc_start as int), ptr::offset(buf, start as int));
259265
}
260266
}
@@ -606,5 +612,3 @@ mod test {
606612
})
607613
}
608614
}
609-
610-

src/libextra/num/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub mod BigDigit {
8080
/**
8181
A big unsigned integer type.
8282
83-
A `BigUint`-typed value `BigUint { data: @[a, b, c] }` represents a number
83+
A `BigUint`-typed value `BigUint { data: ~[a, b, c] }` represents a number
8484
`(a + b * BigDigit::base + c * BigDigit::base^2)`.
8585
*/
8686
#[deriving(Clone)]

src/libextra/serialize.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Core encoding and decoding interfaces.
1818
#[forbid(non_camel_case_types)];
1919

2020

21-
use std::at_vec;
2221
use std::hashmap::{HashMap, HashSet};
2322
use std::rc::Rc;
2423
use std::trie::{TrieMap, TrieSet};
@@ -310,18 +309,6 @@ impl<D:Decoder> Decodable<D> for ~str {
310309
}
311310
}
312311

313-
impl<S:Encoder> Encodable<S> for @str {
314-
fn encode(&self, s: &mut S) {
315-
s.emit_str(*self)
316-
}
317-
}
318-
319-
impl<D:Decoder> Decodable<D> for @str {
320-
fn decode(d: &mut D) -> @str {
321-
d.read_str().to_managed()
322-
}
323-
}
324-
325312
impl<S:Encoder> Encodable<S> for f32 {
326313
fn encode(&self, s: &mut S) {
327314
s.emit_f32(*self)
@@ -456,26 +443,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] {
456443
}
457444
}
458445

459-
impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] {
460-
fn encode(&self, s: &mut S) {
461-
s.emit_seq(self.len(), |s| {
462-
for (i, e) in self.iter().enumerate() {
463-
s.emit_seq_elt(i, |s| e.encode(s))
464-
}
465-
})
466-
}
467-
}
468-
469-
impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] {
470-
fn decode(d: &mut D) -> @[T] {
471-
d.read_seq(|d, len| {
472-
at_vec::from_fn(len, |i| {
473-
d.read_seq_elt(i, |d| Decodable::decode(d))
474-
})
475-
})
476-
}
477-
}
478-
479446
impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {
480447
fn encode(&self, s: &mut S) {
481448
s.emit_option(|s| {

src/librustc/back/link.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ pub fn build_link_meta(sess: Session,
473473
symbol_hasher: &mut Sha256)
474474
-> LinkMeta {
475475
// This calculates CMH as defined above
476-
fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> @str {
476+
fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> ~str {
477477
symbol_hasher.reset();
478478
symbol_hasher.input_str(crateid.to_str());
479-
truncated_hash_result(symbol_hasher).to_managed()
479+
truncated_hash_result(symbol_hasher)
480480
}
481481

482482
let crateid = match attr::find_crateid(attrs) {
@@ -510,7 +510,8 @@ fn truncated_hash_result(symbol_hasher: &mut Sha256) -> ~str {
510510
pub fn symbol_hash(tcx: ty::ctxt,
511511
symbol_hasher: &mut Sha256,
512512
t: ty::t,
513-
link_meta: &LinkMeta) -> @str {
513+
link_meta: &LinkMeta)
514+
-> ~str {
514515
// NB: do *not* use abbrevs here as we want the symbol names
515516
// to be independent of one another in the crate.
516517

@@ -523,23 +524,22 @@ pub fn symbol_hash(tcx: ty::ctxt,
523524
let mut hash = truncated_hash_result(symbol_hasher);
524525
// Prefix with 'h' so that it never blends into adjacent digits
525526
hash.unshift_char('h');
526-
// tjc: allocation is unfortunate; need to change std::hash
527-
hash.to_managed()
527+
hash
528528
}
529529

530-
pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> @str {
530+
pub fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
531531
{
532532
let type_hashcodes = ccx.type_hashcodes.borrow();
533533
match type_hashcodes.get().find(&t) {
534-
Some(&h) => return h,
534+
Some(h) => return h.to_str(),
535535
None => {}
536536
}
537537
}
538538

539539
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
540540
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
541541
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
542-
type_hashcodes.get().insert(t, hash);
542+
type_hashcodes.get().insert(t, hash.clone());
543543
hash
544544
}
545545

@@ -963,7 +963,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
963963

964964
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
965965
for &(cnum, ref path) in crates.iter() {
966-
let name = sess.cstore.get_crate_data(cnum).name;
966+
let name = sess.cstore.get_crate_data(cnum).name.clone();
967967
let p = match *path {
968968
Some(ref p) => p.clone(), None => {
969969
sess.err(format!("could not find rlib for: `{}`", name));
@@ -1221,7 +1221,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
12211221
// If we're not doing LTO, then our job is simply to just link
12221222
// against the archive.
12231223
if sess.lto() {
1224-
let name = sess.cstore.get_crate_data(cnum).name;
1224+
let name = sess.cstore.get_crate_data(cnum).name.clone();
12251225
time(sess.time_passes(), format!("altering {}.rlib", name),
12261226
(), |()| {
12271227
let dst = tmpdir.join(cratepath.filename().unwrap());

src/librustc/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
4242
// module that we've got.
4343
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
4444
for (cnum, path) in crates.move_iter() {
45-
let name = sess.cstore.get_crate_data(cnum).name;
45+
let name = sess.cstore.get_crate_data(cnum).name.clone();
4646
let path = match path {
4747
Some(p) => p,
4848
None => {

0 commit comments

Comments
 (0)