Skip to content

Remove @mut from the language. #11251

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

Merged
merged 60 commits into from
Jan 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f553701
libsyntax: De-`@mut` `ParseSess::included_mod_stack`
pcwalton Dec 27, 2013
3aa19a6
librustc: De-`@mut` the parse session
pcwalton Dec 27, 2013
b33386d
libsyntax: De-`@mut` `StringReader::pos`
pcwalton Dec 27, 2013
13b235d
libsyntax: De-`@mut` `StringReader::last_pos`
pcwalton Dec 27, 2013
aa3527a
libsyntax: De-`@mut` `StringReader::col`
pcwalton Dec 27, 2013
501a6c8
libsyntax: De-`@mut` `StringReader::curr`
pcwalton Dec 27, 2013
a214b8e
libsyntax: De-`@mut` `StringReader::peek_tok`
pcwalton Dec 27, 2013
1856087
libsyntax: De-`@mut` `StringReader::peek_span`
pcwalton Dec 27, 2013
3810bea
libsyntax: De-`@mut` `TtReader::interpolations`
pcwalton Dec 27, 2013
db21387
libsyntax: De-`@mut` `TtReader::repeat_idx`
pcwalton Dec 27, 2013
bac8b2e
libsyntax: De-`@mut` `TtReader::repeat_len`
pcwalton Dec 27, 2013
c233c2e
libsyntax: De-`@mut` `TtReader::cur_tok`
pcwalton Dec 27, 2013
b597207
libsyntax: De-`@mut` `TtReader::cur_span`
pcwalton Dec 27, 2013
2b83377
libsyntax: De-`@mut` `TtReader::stack`
pcwalton Dec 27, 2013
7e1b535
libsyntax: De-`@mut` `StringReader`, `TtReader`, and `reader`
pcwalton Dec 27, 2013
4d66af2
librustc: De-`@mut` the span handler
pcwalton Dec 27, 2013
b26018c
librustc: De-`@mut` (and de-`@`) the pretty printer
pcwalton Dec 27, 2013
497b63d
librustc: De-`@mut` all writers
pcwalton Dec 27, 2013
a7f7482
libsyntax: De-`@mut` `TtFrame::idx`
pcwalton Dec 27, 2013
d347d5a
libsyntax: De-`@mut` `TtFrame`
pcwalton Dec 27, 2013
a2b7367
libsyntax: De-`@mut` `HandlerT::err_count`
pcwalton Dec 27, 2013
8ed6f3e
libsyntax: De-`@mut` the handler
pcwalton Dec 27, 2013
522a68d
libsyntax: De-`@mut` the resolve table
pcwalton Dec 27, 2013
12ad1b0
libsyntax: De-`@mut` `CurrentCommentAndLiteral`
pcwalton Dec 27, 2013
449ebee
librustc: De-`@mut` the AST map
pcwalton Dec 28, 2013
4269f85
libsyntax: De-`@mut` `name_idx`
pcwalton Dec 28, 2013
acdc998
libsyntax: De-`@mut` the path in the AST mapping context
pcwalton Dec 28, 2013
9d6f8cd
libsyntax: De-`@mut` (and de-`@`) the AST mapping context
pcwalton Dec 28, 2013
96f807d
libsyntax: De-`@mut` the interner map
pcwalton Dec 28, 2013
be17a1b
libsyntax: De-`@mut` `SCTable::table`
pcwalton Dec 28, 2013
4d6dde7
libsyntax: De-`@mut` `SCTable::mark_memo`
pcwalton Dec 28, 2013
b476d97
libsyntax: De-`@mut` `SCTable::rename_memo`
pcwalton Dec 28, 2013
1dbeb5b
libsyntax: De-`@mut` `SCTable`
pcwalton Dec 28, 2013
39f0270
libsyntax: Remove an unnecessary `@mut io::Reader`
pcwalton Dec 28, 2013
ada9150
libsyntax: Correctly de-`@mut` the pretty printer writer
pcwalton Dec 28, 2013
27cc3d2
libsyntax: De-`@mut` `FileMap::lines`
pcwalton Dec 31, 2013
39f39ed
libsyntax: De-`@mut` `FileMap::multibyte_chars`
pcwalton Dec 31, 2013
4c85cf7
libsyntax: De-`@mut` `CodeMap::files`
pcwalton Dec 31, 2013
982cb82
libsyntax: De-`@mut` `Interner::vect`
pcwalton Dec 31, 2013
5eafcc4
libsyntax: De-`@mut` (and de-`@`) `Printer::print_stack`
pcwalton Dec 31, 2013
6043957
libsyntax: De-`@mut` `ps::boxes`
pcwalton Dec 31, 2013
1d29163
librustc: Eliminate an unnecessary `@mut` in pretty printing.
pcwalton Dec 31, 2013
901df8a
libsyntax: Remove unused `MultiRenamer`
pcwalton Jan 3, 2014
af0439b
librustpkg: De-`@mut` `rustpkg`
pcwalton Dec 31, 2013
c38456a
librustdoc: De-`@mut` `librustdoc`
pcwalton Dec 31, 2013
c1d6f5e
libextra: De-`@mut` the arena
pcwalton Dec 31, 2013
07bbc41
libextra: Remove unnecessary `@mut`s
pcwalton Dec 31, 2013
84e977c
libstd: Remove a spurious `@mut` from a disabled test
pcwalton Dec 31, 2013
aa93e6e
libextra: Remove `MutList`, as it's inexorably tied to `@mut`
pcwalton Dec 31, 2013
e095889
libstd: De-`@mut` the `heap_cycles` test
pcwalton Dec 31, 2013
b6e5168
libstd: Remove all support code related to `@mut`
pcwalton Dec 31, 2013
179c054
test: Remove all borrow check write guard tests
pcwalton Dec 31, 2013
65d55af
test: Make `borrowck-assign-to-subfield` into a run-pass test, now that
pcwalton Dec 31, 2013
df13c64
test: Get rid of some `@mut`s in borrow check tests
pcwalton Dec 31, 2013
c3694d7
test: De-`@mut` the test suite
pcwalton Dec 31, 2013
9b35ae7
doc: Remove all mentions of `@mut` from the documentation.
pcwalton Jan 1, 2014
8828129
librustc: Remove `@mut` support from the typechecker and borrow checker
pcwalton Dec 31, 2013
82a09b9
librustc: Remove `@mut` support from the parser
pcwalton Dec 31, 2013
02c1d2f
test: Make all the run-pass tests use `pub fn main`
pcwalton Jan 3, 2014
8092153
libsyntax: Fix tests.
pcwalton Jan 4, 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
24 changes: 4 additions & 20 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,13 +1463,12 @@ 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;
let borrowed = &mut value;

*managed = *owned + 10;
*owned = *borrowed + 100;
*borrowed = *managed + 1000;
~~~
Expand Down Expand Up @@ -2113,8 +2098,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 @@ -949,7 +949,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