Skip to content

Commit

Permalink
auto merge of #6286 : nikomatsakis/rust/issue-5910-dyna-freeze, r=nik…
Browse files Browse the repository at this point in the history
…omatsakis

This rather sprawling branch refactors the borrow checker and much of the region code, addressing a number of outstanding issues. I will close them manually after validating that there are test cases for each one, but here is a (probably partial) list:

  - #4903: Flow sensitivity
  - #3387: Moves in overloaded operators
  - #3850: Region granularity
  - #4666: Odd loaning errors
  - #6021: borrow check errors with hashmaps
  - #5910: @mut broken

cc #5047

(take 5)
  • Loading branch information
bors committed May 7, 2013
2 parents bd5fd6e + 39a1190 commit 05460fc
Show file tree
Hide file tree
Showing 238 changed files with 14,334 additions and 5,152 deletions.
3 changes: 3 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ endif
ifdef SAVE_TEMPS
CFG_RUSTC_FLAGS += --save-temps
endif
ifdef ASM_COMMENTS
CFG_RUSTC_FLAGS += -z asm-comments
endif
ifdef TIME_PASSES
CFG_RUSTC_FLAGS += -Z time-passes
endif
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn empty_cell<T>() -> Cell<T> {
pub impl<T> Cell<T> {
/// Yields the value, failing if the cell is empty.
fn take(&self) -> T {
let mut self = unsafe { transmute_mut(self) };
let self = unsafe { transmute_mut(self) };
if self.is_empty() {
fail!(~"attempt to take an empty cell");
}
Expand All @@ -54,7 +54,7 @@ pub impl<T> Cell<T> {
/// Returns the value, failing if the cell is full.
fn put_back(&self, value: T) {
let mut self = unsafe { transmute_mut(self) };
let self = unsafe { transmute_mut(self) };
if !self.is_empty() {
fail!(~"attempt to put a value back into a full cell");
}
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use ptr::mut_null;
use repr::BoxRepr;
use sys::TypeDesc;
use cast::transmute;
#[cfg(notest)] use unstable::lang::clear_task_borrow_list;

#[cfg(notest)] use ptr::to_unsafe_ptr;

Expand Down Expand Up @@ -179,6 +180,10 @@ pub unsafe fn annihilate() {
n_bytes_freed: 0
};

// Quick hack: we need to free this list upon task exit, and this
// is a convenient place to do it.
clear_task_borrow_list();

// Pass 1: Make all boxes immortal.
//
// In this pass, nothing gets freed, so it does not matter whether
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl<T: Owned> Selectable for Port<T> {
fn header(&self) -> *PacketHeader {
unsafe {
match self.endp {
Some(ref endp) => endp.header(),
None => fail!(~"peeking empty stream")
Some(ref endp) => endp.header(),
None => fail!(~"peeking empty stream")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub mod rustrt {
pub extern {
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;

unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;
}
Expand All @@ -52,11 +52,11 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
let res =
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
len as size_t,
&outsz,
&mut outsz,
lz_norm);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,
outsz as uint);
outsz as uint);
libc::free(res);
out
}
Expand All @@ -66,11 +66,11 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
do vec::as_const_buf(bytes) |b, len| {
unsafe {
let outsz : size_t = 0;
let mut outsz : size_t = 0;
let res =
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
len as size_t,
&outsz,
&mut outsz,
0);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,
Expand Down
13 changes: 13 additions & 0 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rand;
use uint;
use vec;
use util::unreachable;
use kinds::Copy;

static INITIAL_CAPACITY: uint = 32u; // 2^5

Expand Down Expand Up @@ -529,6 +530,18 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
}
}

pub impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
/// Like `find`, but returns a copy of the value.
fn find_copy(&self, k: &K) -> Option<V> {
self.find(k).map_consume(|v| copy *v)
}

/// Like `get`, but returns a copy of the value.
fn get_copy(&self, k: &K) -> V {
copy *self.get(k)
}
}

impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
fn eq(&self, other: &HashMap<K, V>) -> bool {
if self.len() != other.len() { return false; }
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ pub enum WriterType { Screen, File }
pub trait Writer {
/// Write all of the given bytes.
fn write(&self, v: &const [u8]);
fn write(&self, v: &[u8]);
/// Move the current position within the stream. The second parameter
/// determines the position that the first parameter is relative to.
Expand All @@ -1039,23 +1039,23 @@ pub trait Writer {
}
impl Writer for @Writer {
fn write(&self, v: &const [u8]) { self.write(v) }
fn write(&self, v: &[u8]) { self.write(v) }
fn seek(&self, a: int, b: SeekStyle) { self.seek(a, b) }
fn tell(&self) -> uint { self.tell() }
fn flush(&self) -> int { self.flush() }
fn get_type(&self) -> WriterType { self.get_type() }
}
impl<W:Writer,C> Writer for Wrapper<W, C> {
fn write(&self, bs: &const [u8]) { self.base.write(bs); }
fn write(&self, bs: &[u8]) { self.base.write(bs); }
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
fn tell(&self) -> uint { self.base.tell() }
fn flush(&self) -> int { self.base.flush() }
fn get_type(&self) -> WriterType { File }
}
impl Writer for *libc::FILE {
fn write(&self, v: &const [u8]) {
fn write(&self, v: &[u8]) {
unsafe {
do vec::as_const_buf(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void,
Expand Down Expand Up @@ -1105,7 +1105,7 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
}

impl Writer for fd_t {
fn write(&self, v: &const [u8]) {
fn write(&self, v: &[u8]) {
unsafe {
let mut count = 0u;
do vec::as_const_buf(v) |vbuf, len| {
Expand Down Expand Up @@ -1262,7 +1262,7 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint,
}
}

pub fn u64_from_be_bytes(data: &const [u8],
pub fn u64_from_be_bytes(data: &[u8],
start: uint,
size: uint)
-> u64 {
Expand Down Expand Up @@ -1497,7 +1497,7 @@ pub struct BytesWriter {
}
impl Writer for BytesWriter {
fn write(&self, v: &const [u8]) {
fn write(&self, v: &[u8]) {
let v_len = v.len();
let bytes_len = vec::uniq_len(&const self.bytes);
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ pub mod types {
pub type ssize_t = i32;
}
pub mod posix01 {
use libc::types::os::arch::c95::{c_int, c_short, c_long,
time_t};
use libc::types::os::arch::c95::{c_short, c_long, time_t};
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
use libc::types::os::arch::posix88::{mode_t, off_t};
use libc::types::os::arch::posix88::{uid_t};
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
}
}

pub struct Pipe { mut in: c_int, mut out: c_int }
pub struct Pipe { in: c_int, out: c_int }

#[cfg(unix)]
pub fn pipe() -> Pipe {
unsafe {
let mut fds = Pipe {in: 0 as c_int,
out: 0 as c_int };
out: 0 as c_int };
assert!((libc::pipe(&mut fds.in) == (0 as c_int)));
return Pipe {in: fds.in, out: fds.out};
}
Expand Down Expand Up @@ -1025,10 +1025,10 @@ pub fn last_os_error() -> ~str {
#[cfg(target_os = "macos")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
#[nolink]
extern {
unsafe fn strerror_r(errnum: c_int, buf: *c_char,
unsafe fn strerror_r(errnum: c_int, buf: *mut c_char,
buflen: size_t) -> c_int;
}
unsafe {
Expand All @@ -1040,10 +1040,10 @@ pub fn last_os_error() -> ~str {
// and requires macros to instead use the POSIX compliant variant.
// So we just use __xpg_strerror_r which is always POSIX compliant
#[cfg(target_os = "linux")]
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
#[nolink]
extern {
unsafe fn __xpg_strerror_r(errnum: c_int, buf: *c_char,
unsafe fn __xpg_strerror_r(errnum: c_int, buf: *mut c_char,
buflen: size_t) -> c_int;
}
unsafe {
Expand All @@ -1053,7 +1053,7 @@ pub fn last_os_error() -> ~str {
let mut buf = [0 as c_char, ..TMPBUF_SZ];
unsafe {
let err = strerror_r(errno() as c_int, &buf[0],
let err = strerror_r(errno() as c_int, &mut buf[0],
TMPBUF_SZ as size_t);
if err < 0 {
fail!(~"strerror_r failure");
Expand Down
16 changes: 8 additions & 8 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,34 +296,34 @@ impl<T> Ord for *const T {
// Equality for region pointers
#[cfg(notest)]
impl<'self,T:Eq> Eq for &'self const T {
impl<'self,T:Eq> Eq for &'self T {
#[inline(always)]
fn eq(&self, other: & &'self const T) -> bool {
fn eq(&self, other: & &'self T) -> bool {
return *(*self) == *(*other);
}
#[inline(always)]
fn ne(&self, other: & &'self const T) -> bool {
fn ne(&self, other: & &'self T) -> bool {
return *(*self) != *(*other);
}
}
// Comparison for region pointers
#[cfg(notest)]
impl<'self,T:Ord> Ord for &'self const T {
impl<'self,T:Ord> Ord for &'self T {
#[inline(always)]
fn lt(&self, other: & &'self const T) -> bool {
fn lt(&self, other: & &'self T) -> bool {
*(*self) < *(*other)
}
#[inline(always)]
fn le(&self, other: & &'self const T) -> bool {
fn le(&self, other: & &'self T) -> bool {
*(*self) <= *(*other)
}
#[inline(always)]
fn ge(&self, other: & &'self const T) -> bool {
fn ge(&self, other: & &'self T) -> bool {
*(*self) >= *(*other)
}
#[inline(always)]
fn gt(&self, other: & &'self const T) -> bool {
fn gt(&self, other: & &'self T) -> bool {
*(*self) > *(*other)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/rt/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub struct Environment {
argc: c_int,
/// The argv value passed to main
argv: **c_char,
/// Print GC debugging info
debug_mem: bool
/// Print GC debugging info (true if env var RUST_DEBUG_MEM is set)
debug_mem: bool,
/// Print GC debugging info (true if env var RUST_DEBUG_BORROW is set)
debug_borrow: bool,
}

/// Get the global environment settings
Expand Down
4 changes: 1 addition & 3 deletions src/libcore/rt/sched/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ pub impl Scheduler {
/// Called by a running task to end execution, after which it will
/// be recycled by the scheduler for reuse in a new task.
fn terminate_current_task(~self) {
let mut self = self;
assert!(self.in_task_context());

rtdebug!("ending running task");
Expand All @@ -153,7 +152,6 @@ pub impl Scheduler {
}

fn schedule_new_task(~self, task: ~Task) {
let mut self = self;
assert!(self.in_task_context());

do self.switch_running_tasks_and_then(task) |last_task| {
Expand Down Expand Up @@ -305,7 +303,7 @@ pub impl Scheduler {
unsafe {
let last_task = transmute::<Option<&Task>, Option<&mut Task>>(last_task);
let last_task_context = match last_task {
Some(ref t) => Some(&mut t.saved_context), None => None
Some(t) => Some(&mut t.saved_context), None => None
};
let next_task_context = match self.current_task {
Some(ref mut t) => Some(&mut t.saved_context), None => None
Expand Down
12 changes: 0 additions & 12 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,9 +2472,6 @@ pub trait StrSlice<'self> {
fn any(&self, it: &fn(char) -> bool) -> bool;
fn contains<'a>(&self, needle: &'a str) -> bool;
fn contains_char(&self, needle: char) -> bool;
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn char_iter(&self) -> StrCharIterator<'self>;
fn each(&self, it: &fn(u8) -> bool);
fn eachi(&self, it: &fn(uint, u8) -> bool);
Expand Down Expand Up @@ -2536,9 +2533,6 @@ impl<'self> StrSlice<'self> for &'self str {
contains_char(*self, needle)
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[inline]
fn char_iter(&self) -> StrCharIterator<'self> {
StrCharIterator {
Expand Down Expand Up @@ -2732,17 +2726,11 @@ impl Clone for ~str {
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub struct StrCharIterator<'self> {
priv index: uint,
priv string: &'self str,
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
impl<'self> Iterator<char> for StrCharIterator<'self> {
#[inline]
fn next(&mut self) -> Option<char> {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use io::Writer;
use option::{None, Option, Some};
use str;

pub type Cb<'self> = &'self fn(buf: &const [u8]) -> bool;
pub type Cb<'self> = &'self fn(buf: &[u8]) -> bool;

/**
* A trait to implement in order to make a type hashable;
Expand Down
Loading

0 comments on commit 05460fc

Please sign in to comment.