Skip to content

Demuting libsyntax #11167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
b311649
libsyntax: Make the parser mutable
pcwalton Dec 30, 2013
f203c56
libsyntax: De-`@mut` `quote_depth` in the parser
pcwalton Dec 30, 2013
0f2e8f0
libsyntax: De-`@mut` `token` in the parser
pcwalton Dec 30, 2013
2d19f34
libsyntax: De-`@mut` `Parser::span`
pcwalton Dec 30, 2013
2eb9bb7
libsyntax: De-`@mut` `Parser::last_span`
pcwalton Dec 30, 2013
eb0bd16
libsyntax: De-`@mut` `Parser::last_token`
pcwalton Dec 30, 2013
89e2934
libsyntax: De-`@mut` `Parser::buffer`
pcwalton Dec 30, 2013
e9f5c15
libsyntax: De-`@mut` `Parser::buffer_start` and `Parser::buffer_end`
pcwalton Dec 30, 2013
9380397
libsyntax: De-`@mut` `Parser::tokens_consumed`
pcwalton Dec 30, 2013
0ad82b8
libsyntax: De-`@mut` `Parser::restriction`
pcwalton Dec 30, 2013
75edbf4
libsyntax: De-`@mut` `Parser::obsolete_set`
pcwalton Dec 30, 2013
0beed3b
libsyntax: De-`@mut` `Parser::mod_path_stack`
pcwalton Dec 30, 2013
6221211
libsyntax: De-`@mut` `Parser::open_braces`
pcwalton Dec 30, 2013
1b55554
libsyntax: Remove increasingly inaccurate comment
pcwalton Dec 30, 2013
fbdc6cb
libsyntax: Long line
pcwalton Dec 31, 2013
f2fc9bf
libsyntax: De-`@mut` `ParseSess::included_mod_stack`
pcwalton Dec 27, 2013
461b2d8
librustc: De-`@mut` the parse session
pcwalton Dec 27, 2013
d360847
libsyntax: De-`@mut` `StringReader::pos`
pcwalton Dec 27, 2013
8b3f0a3
libsyntax: De-`@mut` `StringReader::last_pos`
pcwalton Dec 27, 2013
d18558f
libsyntax: De-`@mut` `StringReader::col`
pcwalton Dec 27, 2013
ed6a9c4
libsyntax: De-`@mut` `StringReader::curr`
pcwalton Dec 27, 2013
85c4603
libsyntax: De-`@mut` `StringReader::peek_tok`
pcwalton Dec 27, 2013
d529a12
libsyntax: De-`@mut` `StringReader::peek_span`
pcwalton Dec 27, 2013
2311d2a
libsyntax: De-`@mut` `TtReader::interpolations`
pcwalton Dec 27, 2013
fa9e05d
libsyntax: De-`@mut` `TtReader::repeat_idx`
pcwalton Dec 27, 2013
3f31553
libsyntax: De-`@mut` `TtReader::repeat_len`
pcwalton Dec 27, 2013
a184e55
libsyntax: De-`@mut` `TtReader::cur_tok`
pcwalton Dec 27, 2013
f96aef0
libsyntax: De-`@mut` `TtReader::cur_span`
pcwalton Dec 27, 2013
7baa437
libsyntax: De-`@mut` `TtReader::stack`
pcwalton Dec 27, 2013
02d0fcc
libsyntax: De-`@mut` `StringReader`, `TtReader`, and `reader`
pcwalton Dec 27, 2013
55e1adb
librustc: De-`@mut` the span handler
pcwalton Dec 27, 2013
33520e5
librustc: De-`@mut` (and de-`@`) the pretty printer
pcwalton Dec 27, 2013
8573c63
librustc: De-`@mut` all writers
pcwalton Dec 27, 2013
68f644d
librustc: De-`@mut` `SyntaxEnv`
pcwalton Dec 27, 2013
c176673
libsyntax: De-`@mut` `TtFrame::idx`
pcwalton Dec 27, 2013
e99a5aa
libsyntax: De-`@mut` `TtFrame`
pcwalton Dec 27, 2013
b57b04f
libsyntax: De-`@mut` `HandlerT::err_count`
pcwalton Dec 27, 2013
01d5020
libsyntax: De-`@mut` the handler
pcwalton Dec 27, 2013
68d9bb1
libsyntax: De-`@mut` the resolve table
pcwalton Dec 27, 2013
f2a725b
libsyntax: De-`@mut` `MapChain`
pcwalton Dec 27, 2013
cc313ec
libsyntax: De-`@mut` `CurrentCommentAndLiteral`
pcwalton Dec 27, 2013
8952fb4
librustc: De-`@mut` the AST map
pcwalton Dec 28, 2013
4b8779b
libsyntax: De-`@mut` `name_idx`
pcwalton Dec 28, 2013
f70348e
libsyntax: De-`@mut` the path in the AST mapping context
pcwalton Dec 28, 2013
05eeb93
libsyntax: De-`@mut` (and de-`@`) the AST mapping context
pcwalton Dec 28, 2013
6aaabd4
libsyntax: De-`@mut` the interner map
pcwalton Dec 28, 2013
13f7042
libsyntax: De-`@mut` `SCTable::table`
pcwalton Dec 28, 2013
42f7559
libsyntax: De-`@mut` `SCTable::mark_memo`
pcwalton Dec 28, 2013
25e3341
libsyntax: De-`@mut` `SCTable::rename_memo`
pcwalton Dec 28, 2013
05bbed3
libsyntax: De-`@mut` `SCTable`
pcwalton Dec 28, 2013
7d10c47
libsyntax: De-`@mut` `BlockInfo::pending_renames`
pcwalton Dec 28, 2013
4f3e080
libsyntax: Remove an unnecessary `@mut io::Reader`
pcwalton Dec 28, 2013
951b269
libsyntax: Correctly de-`@mut` the pretty printer writer
pcwalton Dec 28, 2013
c14d78b
libsyntax: De-`@mut` `FileMap::lines`
pcwalton Dec 31, 2013
e3383d2
libsyntax: De-`@mut` `FileMap::multibyte_chars`
pcwalton Dec 31, 2013
0a900f4
libsyntax: De-`@mut` `CodeMap::files`
pcwalton Dec 31, 2013
9df5ad0
libsyntax: De-`@mut` `Interner::vect`
pcwalton Dec 31, 2013
cf39f97
libsyntax: De-`@mut` (and de-`@`) `Printer::print_stack`
pcwalton Dec 31, 2013
869db32
libsyntax: De-`@mut` `ps::boxes`
pcwalton Dec 31, 2013
2843103
librustc: Eliminate an unnecessary `@mut` in pretty printing.
pcwalton Dec 31, 2013
8023485
librustpkg: De-`@mut` `rustpkg`
pcwalton Dec 31, 2013
50da7c9
librustdoc: De-`@mut` `librustdoc`
pcwalton Dec 31, 2013
9d61bee
libextra: De-`@mut` the arena
pcwalton Dec 31, 2013
3fe4c62
libextra: Remove unnecessary `@mut`s
pcwalton Dec 31, 2013
b441da1
libstd: Remove a spurious `@mut` from a disabled test
pcwalton Dec 31, 2013
24574fa
libextra: Remove `MutList`, as it's inexorably tied to `@mut`
pcwalton Dec 31, 2013
7e79948
libstd: De-`@mut` the `heap_cycles` test
pcwalton Dec 31, 2013
7185c16
libstd: Remove all support code related to `@mut`
pcwalton Dec 31, 2013
10c49f2
test: Remove all borrow check write guard tests
pcwalton Dec 31, 2013
5d592ec
test: Make `borrowck-assign-to-subfield` into a run-pass test, now that
pcwalton Dec 31, 2013
2a5765a
test: Get rid of some `@mut`s in borrow check tests
pcwalton Dec 31, 2013
bfc4984
test: De-`@mut` the test suite
pcwalton Dec 31, 2013
9ab76aa
doc: Remove all mentions of `@mut` from the documentation.
pcwalton Jan 1, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,8 @@ For a more in-depth explanation of borrowed pointers, read the
## Freezing

Lending an immutable pointer to an object freezes it and prevents mutation.
`Freeze` objects have freezing enforced statically at compile-time. Examples
of non-`Freeze` types are `@mut` and [`RefCell<T>`][refcell].
`Freeze` objects have freezing enforced statically at compile-time. An example
of a non-`Freeze` type is [`RefCell<T>`][refcell].

~~~~
let mut x = 5;
Expand All @@ -1443,20 +1443,6 @@ let mut x = 5;
# x = 3;
~~~~

Mutable managed boxes handle freezing dynamically when any of their contents
are borrowed, and the task will fail if an attempt to modify them is made while
they are frozen:

~~~~
let x = @mut 5;
let y = x;
{
let z = &*y; // the managed box is now frozen
// modifying it through x or y will cause a task failure
}
// the box is now unfrozen again
~~~~

[refcell]: http://static.rust-lang.org/doc/master/std/cell/struct.RefCell.html

# Dereferencing pointers
Expand All @@ -1477,7 +1463,7 @@ assignments. Such an assignment modifies the value that the pointer
points to.

~~~
let managed = @mut 10;
let managed = @10;
let mut owned = ~20;

let mut value = 30;
Expand Down Expand Up @@ -2113,8 +2099,7 @@ unless they contain managed boxes, managed closures, or borrowed pointers.

* `Freeze` - Constant (immutable) types.
These are types that do not contain anything intrinsically mutable.
Intrinsically mutable values include `@mut`
and `Cell` in the standard library.
Intrinsically mutable values include `Cell` in the standard library.

* `'static` - Non-borrowed types.
These are types that do not contain any data whose lifetime is bound to
Expand Down
61 changes: 34 additions & 27 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
#[allow(missing_doc)];


use list::{MutList, MutCons, MutNil};
use list::{List, Cons, Nil};
use list;

use std::at_vec;
use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast;
use std::cell::{Cell, RefCell};
use std::num;
use std::ptr;
use std::mem;
Expand All @@ -50,10 +52,11 @@ use std::unstable::intrinsics::{TyDesc, get_tydesc};
// The way arena uses arrays is really deeply awful. The arrays are
// allocated, and have capacities reserved, but the fill for the array
// will always stay at 0.
#[deriving(Clone)]
struct Chunk {
data: @[u8],
fill: uint,
is_pod: bool,
data: RefCell<@[u8]>,
fill: Cell<uint>,
is_pod: Cell<bool>,
}

#[no_freeze]
Expand All @@ -63,7 +66,7 @@ pub struct Arena {
// access the head.
priv head: Chunk,
priv pod_head: Chunk,
priv chunks: @mut MutList<Chunk>,
priv chunks: RefCell<@List<Chunk>>,
}

impl Arena {
Expand All @@ -75,7 +78,7 @@ impl Arena {
Arena {
head: chunk(initial_size, false),
pod_head: chunk(initial_size, true),
chunks: @mut MutNil,
chunks: RefCell::new(@Nil),
}
}
}
Expand All @@ -84,9 +87,9 @@ fn chunk(size: uint, is_pod: bool) -> Chunk {
let mut v: @[u8] = @[];
unsafe { at_vec::raw::reserve(&mut v, size); }
Chunk {
data: unsafe { cast::transmute(v) },
fill: 0u,
is_pod: is_pod,
data: RefCell::new(unsafe { cast::transmute(v) }),
fill: Cell::new(0u),
is_pod: Cell::new(is_pod),
}
}

Expand All @@ -95,8 +98,9 @@ impl Drop for Arena {
fn drop(&mut self) {
unsafe {
destroy_chunk(&self.head);
self.chunks.each(|chunk| {
if !chunk.is_pod {

list::each(self.chunks.get(), |chunk| {
if !chunk.is_pod.get() {
destroy_chunk(chunk);
}
true
Expand All @@ -114,8 +118,11 @@ fn round_up_to(base: uint, align: uint) -> uint {
// in it.
unsafe fn destroy_chunk(chunk: &Chunk) {
let mut idx = 0;
let buf = chunk.data.as_ptr();
let fill = chunk.fill;
let buf = {
let data = chunk.data.borrow();
data.get().as_ptr()
};
let fill = chunk.fill.get();

while idx < fill {
let tydesc_data: *uint = transmute(ptr::offset(buf, idx as int));
Expand Down Expand Up @@ -155,9 +162,9 @@ impl Arena {
// Functions for the POD part of the arena
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.pod_head.data);
let chunk_size = at_vec::capacity(self.pod_head.data.get());
let new_min_chunk_size = num::max(n_bytes, chunk_size);
self.chunks = @mut MutCons(self.pod_head, self.chunks);
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
self.pod_head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);

Expand All @@ -168,17 +175,17 @@ impl Arena {
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
unsafe {
let this = transmute_mut_region(self);
let start = round_up_to(this.pod_head.fill, align);
let start = round_up_to(this.pod_head.fill.get(), align);
let end = start + n_bytes;
if end > at_vec::capacity(this.pod_head.data) {
if end > at_vec::capacity(this.pod_head.data.get()) {
return this.alloc_pod_grow(n_bytes, align);
}
this.pod_head.fill = end;
this.pod_head.fill.set(end);

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

ptr::offset(this.pod_head.data.as_ptr(), start as int)
ptr::offset(this.pod_head.data.get().as_ptr(), start as int)
}
}

Expand All @@ -197,9 +204,9 @@ impl Arena {
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
-> (*u8, *u8) {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.head.data);
let chunk_size = at_vec::capacity(self.head.data.get());
let new_min_chunk_size = num::max(n_bytes, chunk_size);
self.chunks = @mut MutCons(self.head, self.chunks);
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
self.head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);

Expand All @@ -218,23 +225,23 @@ impl Arena {
{
let head = transmute_mut_region(&mut self.head);

tydesc_start = head.fill;
after_tydesc = head.fill + mem::size_of::<*TyDesc>();
tydesc_start = head.fill.get();
after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
start = round_up_to(after_tydesc, align);
end = start + n_bytes;
}

if end > at_vec::capacity(self.head.data) {
if end > at_vec::capacity(self.head.data.get()) {
return self.alloc_nonpod_grow(n_bytes, align);
}

let head = transmute_mut_region(&mut self.head);
head.fill = round_up_to(end, mem::pref_align_of::<*TyDesc>());
head.fill.set(round_up_to(end, mem::pref_align_of::<*TyDesc>()));

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

let buf = self.head.data.as_ptr();
let buf = self.head.data.get().as_ptr();
return (ptr::offset(buf, tydesc_start as int), ptr::offset(buf, start as int));
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/libextra/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ pub enum List<T> {
Nil,
}

#[deriving(Eq)]
#[allow(missing_doc)]
pub enum MutList<T> {
MutCons(T, @mut MutList<T>),
MutNil,
}

/// Create a list from a vector
pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons((*h).clone(), t))
Expand Down Expand Up @@ -158,26 +151,6 @@ pub fn each<T>(l: @List<T>, f: |&T| -> bool) -> bool {
}
}

impl<T> MutList<T> {
/// Iterate over a mutable list
pub fn each(@mut self, f: |&mut T| -> bool) -> bool {
let mut cur = self;
loop {
let borrowed = &mut *cur;
cur = match *borrowed {
MutCons(ref mut hd, tl) => {
if !f(hd) {
return false;
}
tl
}
MutNil => break
}
}
return true;
}
}

#[cfg(test)]
mod tests {
use list::*;
Expand Down
12 changes: 0 additions & 12 deletions src/libextra/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,6 @@ impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
}
}

impl<S:Encoder,T:Encodable<S>> Encodable<S> for @mut T {
fn encode(&self, s: &mut S) {
(**self).encode(s)
}
}

impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @mut T {
fn decode(d: &mut D) -> @mut T {
@mut Decodable::decode(d)
}
}

impl<'a, S:Encoder,T:Encodable<S>> Encodable<S> for &'a [T] {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ impl<T: Writer> Terminal<T> {
return Err(entry.unwrap_err());
}

let ti = parse(entry.unwrap(), false);
let mut file = entry.unwrap();
let ti = parse(&mut file, false);
if ti.is_err() {
return Err(ti.unwrap_err());
}
Expand Down
14 changes: 9 additions & 5 deletions src/libextra/terminfo/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
/// Implement ncurses-compatible database discovery
/// Does not support hashed database, only filesystem!

use std::{os, str};
use std::os::getenv;
use std::io;
use std::io::File;
use std::os::getenv;
use std::{os, str};

/// Return path to database entry for `term`
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
Expand Down Expand Up @@ -74,9 +73,14 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
}

/// Return open file for `term`
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
pub fn open(term: &str) -> Result<File, ~str> {
match get_dbpath_for_term(term) {
Some(x) => Ok(@mut File::open(x) as @mut io::Reader),
Some(x) => {
match File::open(x) {
Some(file) => Ok(file),
None => Err(~"error opening file"),
}
}
None => Err(format!("could not find terminfo entry for {}", term))
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,8 @@ impl MetricMap {

/// Write MetricDiff to a file.
pub fn save(&self, p: &Path) {
self.to_json().to_pretty_writer(@mut File::create(p) as @mut io::Writer);
let mut file = File::create(p);
self.to_json().to_pretty_writer(&mut file)
}

/// Compare against another MetricMap. Optionally compare all
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ mod test {
use serialize::{Encodable, Decodable};

let u = Uuid::new_v4();
let wr = @mut MemWriter::new();
u.encode(&mut ebml::writer::Encoder(wr));
let mut wr = MemWriter::new();
u.encode(&mut ebml::writer::Encoder(&mut wr));
let doc = ebml::reader::Doc(wr.inner_ref().as_slice());
let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc));
assert_eq!(u, u2);
Expand Down
10 changes: 6 additions & 4 deletions src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl Database {

// FIXME #4330: This should have &mut self and should set self.db_dirty to false.
fn save(&self) {
let f = @mut File::create(&self.db_filename);
self.db_cache.to_json().to_pretty_writer(f as @mut io::Writer);
let mut f = File::create(&self.db_filename);
self.db_cache.to_json().to_pretty_writer(&mut f);
}

fn load(&mut self) {
Expand All @@ -184,14 +184,16 @@ impl Database {
Err(e) => fail!("Couldn't load workcache database {}: {}",
self.db_filename.display(),
e.desc),
Ok(r) =>
match json::from_reader(@mut r.unwrap() as @mut io::Reader) {
Ok(r) => {
let mut stream = r.unwrap();
match json::from_reader(&mut stream) {
Err(e) => fail!("Couldn't parse workcache database (from file {}): {}",
self.db_filename.display(), e.to_str()),
Ok(r) => {
let mut decoder = json::Decoder::new(r);
self.db_cache = Decodable::decode(&mut decoder);
}
}
}
}
}
Expand Down
Loading