Skip to content

Commit 05460fc

Browse files
committed
auto merge of #6286 : nikomatsakis/rust/issue-5910-dyna-freeze, r=nikomatsakis
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)
2 parents bd5fd6e + 39a1190 commit 05460fc

File tree

238 files changed

+14334
-5152
lines changed

Some content is hidden

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

238 files changed

+14334
-5152
lines changed

Makefile.in

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ endif
110110
ifdef SAVE_TEMPS
111111
CFG_RUSTC_FLAGS += --save-temps
112112
endif
113+
ifdef ASM_COMMENTS
114+
CFG_RUSTC_FLAGS += -z asm-comments
115+
endif
113116
ifdef TIME_PASSES
114117
CFG_RUSTC_FLAGS += -Z time-passes
115118
endif

src/libcore/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn empty_cell<T>() -> Cell<T> {
4242
pub impl<T> Cell<T> {
4343
/// Yields the value, failing if the cell is empty.
4444
fn take(&self) -> T {
45-
let mut self = unsafe { transmute_mut(self) };
45+
let self = unsafe { transmute_mut(self) };
4646
if self.is_empty() {
4747
fail!(~"attempt to take an empty cell");
4848
}
@@ -54,7 +54,7 @@ pub impl<T> Cell<T> {
5454
5555
/// Returns the value, failing if the cell is full.
5656
fn put_back(&self, value: T) {
57-
let mut self = unsafe { transmute_mut(self) };
57+
let self = unsafe { transmute_mut(self) };
5858
if !self.is_empty() {
5959
fail!(~"attempt to put a value back into a full cell");
6060
}

src/libcore/cleanup.rs

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ptr::mut_null;
1515
use repr::BoxRepr;
1616
use sys::TypeDesc;
1717
use cast::transmute;
18+
#[cfg(notest)] use unstable::lang::clear_task_borrow_list;
1819

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

@@ -179,6 +180,10 @@ pub unsafe fn annihilate() {
179180
n_bytes_freed: 0
180181
};
181182

183+
// Quick hack: we need to free this list upon task exit, and this
184+
// is a convenient place to do it.
185+
clear_task_borrow_list();
186+
182187
// Pass 1: Make all boxes immortal.
183188
//
184189
// In this pass, nothing gets freed, so it does not matter whether

src/libcore/comm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ impl<T: Owned> Selectable for Port<T> {
205205
fn header(&self) -> *PacketHeader {
206206
unsafe {
207207
match self.endp {
208-
Some(ref endp) => endp.header(),
209-
None => fail!(~"peeking empty stream")
208+
Some(ref endp) => endp.header(),
209+
None => fail!(~"peeking empty stream")
210210
}
211211
}
212212
}

src/libcore/flate.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ pub mod rustrt {
2828
pub extern {
2929
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
3030
src_buf_len: size_t,
31-
pout_len: *size_t,
31+
pout_len: *mut size_t,
3232
flags: c_int)
3333
-> *c_void;
3434

3535
unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
3636
src_buf_len: size_t,
37-
pout_len: *size_t,
37+
pout_len: *mut size_t,
3838
flags: c_int)
3939
-> *c_void;
4040
}
@@ -52,11 +52,11 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
5252
let res =
5353
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
5454
len as size_t,
55-
&outsz,
55+
&mut outsz,
5656
lz_norm);
5757
assert!(res as int != 0);
5858
let out = vec::raw::from_buf_raw(res as *u8,
59-
outsz as uint);
59+
outsz as uint);
6060
libc::free(res);
6161
out
6262
}
@@ -66,11 +66,11 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
6666
pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
6767
do vec::as_const_buf(bytes) |b, len| {
6868
unsafe {
69-
let outsz : size_t = 0;
69+
let mut outsz : size_t = 0;
7070
let res =
7171
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
7272
len as size_t,
73-
&outsz,
73+
&mut outsz,
7474
0);
7575
assert!(res as int != 0);
7676
let out = vec::raw::from_buf_raw(res as *u8,

src/libcore/hashmap.rs

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rand;
2525
use uint;
2626
use vec;
2727
use util::unreachable;
28+
use kinds::Copy;
2829

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

@@ -529,6 +530,18 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
529530
}
530531
}
531532

533+
pub impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
534+
/// Like `find`, but returns a copy of the value.
535+
fn find_copy(&self, k: &K) -> Option<V> {
536+
self.find(k).map_consume(|v| copy *v)
537+
}
538+
539+
/// Like `get`, but returns a copy of the value.
540+
fn get_copy(&self, k: &K) -> V {
541+
copy *self.get(k)
542+
}
543+
}
544+
532545
impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
533546
fn eq(&self, other: &HashMap<K, V>) -> bool {
534547
if self.len() != other.len() { return false; }

src/libcore/io.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ pub enum WriterType { Screen, File }
10221022
pub trait Writer {
10231023
10241024
/// Write all of the given bytes.
1025-
fn write(&self, v: &const [u8]);
1025+
fn write(&self, v: &[u8]);
10261026
10271027
/// Move the current position within the stream. The second parameter
10281028
/// determines the position that the first parameter is relative to.
@@ -1039,23 +1039,23 @@ pub trait Writer {
10391039
}
10401040
10411041
impl Writer for @Writer {
1042-
fn write(&self, v: &const [u8]) { self.write(v) }
1042+
fn write(&self, v: &[u8]) { self.write(v) }
10431043
fn seek(&self, a: int, b: SeekStyle) { self.seek(a, b) }
10441044
fn tell(&self) -> uint { self.tell() }
10451045
fn flush(&self) -> int { self.flush() }
10461046
fn get_type(&self) -> WriterType { self.get_type() }
10471047
}
10481048
10491049
impl<W:Writer,C> Writer for Wrapper<W, C> {
1050-
fn write(&self, bs: &const [u8]) { self.base.write(bs); }
1050+
fn write(&self, bs: &[u8]) { self.base.write(bs); }
10511051
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
10521052
fn tell(&self) -> uint { self.base.tell() }
10531053
fn flush(&self) -> int { self.base.flush() }
10541054
fn get_type(&self) -> WriterType { File }
10551055
}
10561056
10571057
impl Writer for *libc::FILE {
1058-
fn write(&self, v: &const [u8]) {
1058+
fn write(&self, v: &[u8]) {
10591059
unsafe {
10601060
do vec::as_const_buf(v) |vbuf, len| {
10611061
let nout = libc::fwrite(vbuf as *c_void,
@@ -1105,7 +1105,7 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
11051105
}
11061106

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

1265-
pub fn u64_from_be_bytes(data: &const [u8],
1265+
pub fn u64_from_be_bytes(data: &[u8],
12661266
start: uint,
12671267
size: uint)
12681268
-> u64 {
@@ -1497,7 +1497,7 @@ pub struct BytesWriter {
14971497
}
14981498
14991499
impl Writer for BytesWriter {
1500-
fn write(&self, v: &const [u8]) {
1500+
fn write(&self, v: &[u8]) {
15011501
let v_len = v.len();
15021502
let bytes_len = vec::uniq_len(&const self.bytes);
15031503

src/libcore/libc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ pub mod types {
268268
pub type ssize_t = i32;
269269
}
270270
pub mod posix01 {
271-
use libc::types::os::arch::c95::{c_int, c_short, c_long,
272-
time_t};
271+
use libc::types::os::arch::c95::{c_short, c_long, time_t};
273272
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
274273
use libc::types::os::arch::posix88::{mode_t, off_t};
275274
use libc::types::os::arch::posix88::{uid_t};

src/libcore/os.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,13 @@ pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
352352
}
353353
}
354354

355-
pub struct Pipe { mut in: c_int, mut out: c_int }
355+
pub struct Pipe { in: c_int, out: c_int }
356356

357357
#[cfg(unix)]
358358
pub fn pipe() -> Pipe {
359359
unsafe {
360360
let mut fds = Pipe {in: 0 as c_int,
361-
out: 0 as c_int };
361+
out: 0 as c_int };
362362
assert!((libc::pipe(&mut fds.in) == (0 as c_int)));
363363
return Pipe {in: fds.in, out: fds.out};
364364
}
@@ -1025,10 +1025,10 @@ pub fn last_os_error() -> ~str {
10251025
#[cfg(target_os = "macos")]
10261026
#[cfg(target_os = "android")]
10271027
#[cfg(target_os = "freebsd")]
1028-
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
1028+
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
10291029
#[nolink]
10301030
extern {
1031-
unsafe fn strerror_r(errnum: c_int, buf: *c_char,
1031+
unsafe fn strerror_r(errnum: c_int, buf: *mut c_char,
10321032
buflen: size_t) -> c_int;
10331033
}
10341034
unsafe {
@@ -1040,10 +1040,10 @@ pub fn last_os_error() -> ~str {
10401040
// and requires macros to instead use the POSIX compliant variant.
10411041
// So we just use __xpg_strerror_r which is always POSIX compliant
10421042
#[cfg(target_os = "linux")]
1043-
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
1043+
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
10441044
#[nolink]
10451045
extern {
1046-
unsafe fn __xpg_strerror_r(errnum: c_int, buf: *c_char,
1046+
unsafe fn __xpg_strerror_r(errnum: c_int, buf: *mut c_char,
10471047
buflen: size_t) -> c_int;
10481048
}
10491049
unsafe {
@@ -1053,7 +1053,7 @@ pub fn last_os_error() -> ~str {
10531053
10541054
let mut buf = [0 as c_char, ..TMPBUF_SZ];
10551055
unsafe {
1056-
let err = strerror_r(errno() as c_int, &buf[0],
1056+
let err = strerror_r(errno() as c_int, &mut buf[0],
10571057
TMPBUF_SZ as size_t);
10581058
if err < 0 {
10591059
fail!(~"strerror_r failure");

src/libcore/ptr.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -296,34 +296,34 @@ impl<T> Ord for *const T {
296296
297297
// Equality for region pointers
298298
#[cfg(notest)]
299-
impl<'self,T:Eq> Eq for &'self const T {
299+
impl<'self,T:Eq> Eq for &'self T {
300300
#[inline(always)]
301-
fn eq(&self, other: & &'self const T) -> bool {
301+
fn eq(&self, other: & &'self T) -> bool {
302302
return *(*self) == *(*other);
303303
}
304304
#[inline(always)]
305-
fn ne(&self, other: & &'self const T) -> bool {
305+
fn ne(&self, other: & &'self T) -> bool {
306306
return *(*self) != *(*other);
307307
}
308308
}
309309
310310
// Comparison for region pointers
311311
#[cfg(notest)]
312-
impl<'self,T:Ord> Ord for &'self const T {
312+
impl<'self,T:Ord> Ord for &'self T {
313313
#[inline(always)]
314-
fn lt(&self, other: & &'self const T) -> bool {
314+
fn lt(&self, other: & &'self T) -> bool {
315315
*(*self) < *(*other)
316316
}
317317
#[inline(always)]
318-
fn le(&self, other: & &'self const T) -> bool {
318+
fn le(&self, other: & &'self T) -> bool {
319319
*(*self) <= *(*other)
320320
}
321321
#[inline(always)]
322-
fn ge(&self, other: & &'self const T) -> bool {
322+
fn ge(&self, other: & &'self T) -> bool {
323323
*(*self) >= *(*other)
324324
}
325325
#[inline(always)]
326-
fn gt(&self, other: & &'self const T) -> bool {
326+
fn gt(&self, other: & &'self T) -> bool {
327327
*(*self) > *(*other)
328328
}
329329
}

src/libcore/rt/env.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ pub struct Environment {
3131
argc: c_int,
3232
/// The argv value passed to main
3333
argv: **c_char,
34-
/// Print GC debugging info
35-
debug_mem: bool
34+
/// Print GC debugging info (true if env var RUST_DEBUG_MEM is set)
35+
debug_mem: bool,
36+
/// Print GC debugging info (true if env var RUST_DEBUG_BORROW is set)
37+
debug_borrow: bool,
3638
}
3739

3840
/// Get the global environment settings

src/libcore/rt/sched/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ pub impl Scheduler {
137137
/// Called by a running task to end execution, after which it will
138138
/// be recycled by the scheduler for reuse in a new task.
139139
fn terminate_current_task(~self) {
140-
let mut self = self;
141140
assert!(self.in_task_context());
142141

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

155154
fn schedule_new_task(~self, task: ~Task) {
156-
let mut self = self;
157155
assert!(self.in_task_context());
158156

159157
do self.switch_running_tasks_and_then(task) |last_task| {
@@ -305,7 +303,7 @@ pub impl Scheduler {
305303
unsafe {
306304
let last_task = transmute::<Option<&Task>, Option<&mut Task>>(last_task);
307305
let last_task_context = match last_task {
308-
Some(ref t) => Some(&mut t.saved_context), None => None
306+
Some(t) => Some(&mut t.saved_context), None => None
309307
};
310308
let next_task_context = match self.current_task {
311309
Some(ref mut t) => Some(&mut t.saved_context), None => None

src/libcore/str.rs

-12
Original file line numberDiff line numberDiff line change
@@ -2472,9 +2472,6 @@ pub trait StrSlice<'self> {
24722472
fn any(&self, it: &fn(char) -> bool) -> bool;
24732473
fn contains<'a>(&self, needle: &'a str) -> bool;
24742474
fn contains_char(&self, needle: char) -> bool;
2475-
#[cfg(stage1)]
2476-
#[cfg(stage2)]
2477-
#[cfg(stage3)]
24782475
fn char_iter(&self) -> StrCharIterator<'self>;
24792476
fn each(&self, it: &fn(u8) -> bool);
24802477
fn eachi(&self, it: &fn(uint, u8) -> bool);
@@ -2536,9 +2533,6 @@ impl<'self> StrSlice<'self> for &'self str {
25362533
contains_char(*self, needle)
25372534
}
25382535
2539-
#[cfg(stage1)]
2540-
#[cfg(stage2)]
2541-
#[cfg(stage3)]
25422536
#[inline]
25432537
fn char_iter(&self) -> StrCharIterator<'self> {
25442538
StrCharIterator {
@@ -2732,17 +2726,11 @@ impl Clone for ~str {
27322726
}
27332727
}
27342728
2735-
#[cfg(stage1)]
2736-
#[cfg(stage2)]
2737-
#[cfg(stage3)]
27382729
pub struct StrCharIterator<'self> {
27392730
priv index: uint,
27402731
priv string: &'self str,
27412732
}
27422733
2743-
#[cfg(stage1)]
2744-
#[cfg(stage2)]
2745-
#[cfg(stage3)]
27462734
impl<'self> Iterator<char> for StrCharIterator<'self> {
27472735
#[inline]
27482736
fn next(&mut self) -> Option<char> {

src/libcore/to_bytes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use io::Writer;
1919
use option::{None, Option, Some};
2020
use str;
2121

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

2424
/**
2525
* A trait to implement in order to make a type hashable;

0 commit comments

Comments
 (0)