Skip to content

Commit f44b951

Browse files
committed
auto merge of #7451 : cmr/rust/rewrite-each-path, r=pcwalton
2 parents 4e4e2f7 + 4f04489 commit f44b951

File tree

193 files changed

+3434
-1863
lines changed

Some content is hidden

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

193 files changed

+3434
-1863
lines changed

doc/rust.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2862,13 +2862,13 @@ call to the method `make_string`.
28622862
Types in Rust are categorized into kinds, based on various properties of the components of the type.
28632863
The kinds are:
28642864

2865-
`Const`
2865+
`Freeze`
28662866
: Types of this kind are deeply immutable;
28672867
they contain no mutable memory locations directly or indirectly via pointers.
2868-
`Owned`
2868+
`Send`
28692869
: Types of this kind can be safely sent between tasks.
28702870
This kind includes scalars, owning pointers, owned closures, and
2871-
structural types containing only other owned types. All `Owned` types are `Static`.
2871+
structural types containing only other owned types. All `Send` types are `Static`.
28722872
`Static`
28732873
: Types of this kind do not contain any borrowed pointers;
28742874
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
@@ -2882,7 +2882,7 @@ The kinds are:
28822882
trait provides a single method `finalize` that takes no parameters, and is run
28832883
when values of the type are dropped. Such a method is called a "destructor",
28842884
and are always executed in "top-down" order: a value is completely destroyed
2885-
before any of the values it owns run their destructors. Only `Owned` types
2885+
before any of the values it owns run their destructors. Only `Send` types
28862886
that do not implement `Copy` can implement `Drop`.
28872887

28882888
> **Note:** The `finalize` method may be renamed in future versions of Rust.
@@ -2968,10 +2968,10 @@ frame they are allocated within.
29682968
A task owns all memory it can *safely* reach through local variables,
29692969
as well as managed, owning and borrowed pointers.
29702970

2971-
When a task sends a value that has the `Owned` trait to another task,
2971+
When a task sends a value that has the `Send` trait to another task,
29722972
it loses ownership of the value sent and can no longer refer to it.
29732973
This is statically guaranteed by the combined use of "move semantics",
2974-
and the compiler-checked _meaning_ of the `Owned` trait:
2974+
and the compiler-checked _meaning_ of the `Send` trait:
29752975
it is only instantiated for (transitively) sendable kinds of data constructor and pointers,
29762976
never including managed or borrowed pointers.
29772977

@@ -3116,7 +3116,7 @@ These include:
31163116
- read-only and read-write shared variables with various safe mutual exclusion patterns
31173117
- simple locks and semaphores
31183118

3119-
When such facilities carry values, the values are restricted to the [`Owned` type-kind](#type-kinds).
3119+
When such facilities carry values, the values are restricted to the [`Send` type-kind](#type-kinds).
31203120
Restricting communication interfaces to this kind ensures that no borrowed or managed pointers move between tasks.
31213121
Thus access to an entire data structure can be mediated through its owning "root" value;
31223122
no further locking or copying is required to avoid data races within the substructure of such a value.

doc/tutorial-ffi.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct Unique<T> {
159159
priv ptr: *mut T
160160
}
161161
162-
impl<T: Owned> Unique<T> {
162+
impl<T: Send> Unique<T> {
163163
pub fn new(value: T) -> Unique<T> {
164164
unsafe {
165165
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
@@ -182,7 +182,7 @@ impl<T: Owned> Unique<T> {
182182
}
183183
184184
#[unsafe_destructor]
185-
impl<T: Owned> Drop for Unique<T> {
185+
impl<T: Send> Drop for Unique<T> {
186186
fn drop(&self) {
187187
unsafe {
188188
let x = intrinsics::init(); // dummy value to swap in

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,9 @@ let your_crayons = ~[BananaMania, Beaver, Bittersweet];
12811281
// Add two vectors to create a new one
12821282
let our_crayons = my_crayons + your_crayons;
12831283
1284-
// += will append to a vector, provided it lives in a mutable slot
1284+
// .push_all() will append to a vector, provided it lives in a mutable slot
12851285
let mut my_crayons = my_crayons;
1286-
my_crayons += your_crayons;
1286+
my_crayons.push_all(your_crayons);
12871287
~~~~
12881288
12891289
> ***Note:*** The above examples of vector addition use owned

src/compiletest/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
2121
let mut line_num = 1u;
2222
while !rdr.eof() {
2323
let ln = rdr.read_line();
24-
error_patterns += parse_expected(line_num, ln);
24+
error_patterns.push_all_move(parse_expected(line_num, ln));
2525
line_num += 1u;
2626
}
2727
return error_patterns;

src/compiletest/runtest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ actual:\n\
226226
~"-L", config.build_base.to_str(),
227227
~"-L",
228228
aux_output_dir_name(config, testfile).to_str()];
229-
args += split_maybe_args(&config.rustcflags);
230-
args += split_maybe_args(&props.compile_flags);
229+
args.push_all_move(split_maybe_args(&config.rustcflags));
230+
args.push_all_move(split_maybe_args(&props.compile_flags));
231231
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
232232
}
233233
}
@@ -581,8 +581,8 @@ fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str],
581581
~"-o", xform(config, testfile).to_str(),
582582
~"-L", config.build_base.to_str()]
583583
+ extras;
584-
args += split_maybe_args(&config.rustcflags);
585-
args += split_maybe_args(&props.compile_flags);
584+
args.push_all_move(split_maybe_args(&config.rustcflags));
585+
args.push_all_move(split_maybe_args(&props.compile_flags));
586586
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
587587
}
588588

src/libextra/arc.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl<'self> Condvar<'self> {
112112
pub struct ARC<T> { x: UnsafeAtomicRcBox<T> }
113113

114114
/// Create an atomically reference counted wrapper.
115-
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
115+
pub fn ARC<T:Freeze + Send>(data: T) -> ARC<T> {
116116
ARC { x: UnsafeAtomicRcBox::new(data) }
117117
}
118118

119119
/**
120120
* Access the underlying data in an atomically reference counted
121121
* wrapper.
122122
*/
123-
impl<T:Const+Owned> ARC<T> {
123+
impl<T:Freeze+Send> ARC<T> {
124124
pub fn get<'a>(&'a self) -> &'a T {
125125
unsafe { &*self.x.get_immut() }
126126
}
@@ -133,7 +133,7 @@ impl<T:Const+Owned> ARC<T> {
133133
* object. However, one of the `arc` objects can be sent to another task,
134134
* allowing them to share the underlying data.
135135
*/
136-
impl<T:Const + Owned> Clone for ARC<T> {
136+
impl<T:Freeze + Send> Clone for ARC<T> {
137137
fn clone(&self) -> ARC<T> {
138138
ARC { x: self.x.clone() }
139139
}
@@ -149,22 +149,22 @@ struct MutexARCInner<T> { lock: Mutex, failed: bool, data: T }
149149
struct MutexARC<T> { x: UnsafeAtomicRcBox<MutexARCInner<T>> }
150150

151151
/// Create a mutex-protected ARC with the supplied data.
152-
pub fn MutexARC<T:Owned>(user_data: T) -> MutexARC<T> {
152+
pub fn MutexARC<T:Send>(user_data: T) -> MutexARC<T> {
153153
mutex_arc_with_condvars(user_data, 1)
154154
}
155155
/**
156156
* Create a mutex-protected ARC with the supplied data and a specified number
157157
* of condvars (as sync::mutex_with_condvars).
158158
*/
159-
pub fn mutex_arc_with_condvars<T:Owned>(user_data: T,
159+
pub fn mutex_arc_with_condvars<T:Send>(user_data: T,
160160
num_condvars: uint) -> MutexARC<T> {
161161
let data =
162162
MutexARCInner { lock: mutex_with_condvars(num_condvars),
163163
failed: false, data: user_data };
164164
MutexARC { x: UnsafeAtomicRcBox::new(data) }
165165
}
166166

167-
impl<T:Owned> Clone for MutexARC<T> {
167+
impl<T:Send> Clone for MutexARC<T> {
168168
/// Duplicate a mutex-protected ARC, as arc::clone.
169169
fn clone(&self) -> MutexARC<T> {
170170
// NB: Cloning the underlying mutex is not necessary. Its reference
@@ -173,7 +173,7 @@ impl<T:Owned> Clone for MutexARC<T> {
173173
}
174174
}
175175

176-
impl<T:Owned> MutexARC<T> {
176+
impl<T:Send> MutexARC<T> {
177177

178178
/**
179179
* Access the underlying mutable data with mutual exclusion from other
@@ -282,14 +282,14 @@ struct RWARC<T> {
282282
}
283283

284284
/// Create a reader/writer ARC with the supplied data.
285-
pub fn RWARC<T:Const + Owned>(user_data: T) -> RWARC<T> {
285+
pub fn RWARC<T:Freeze + Send>(user_data: T) -> RWARC<T> {
286286
rw_arc_with_condvars(user_data, 1)
287287
}
288288
/**
289289
* Create a reader/writer ARC with the supplied data and a specified number
290290
* of condvars (as sync::rwlock_with_condvars).
291291
*/
292-
pub fn rw_arc_with_condvars<T:Const + Owned>(
292+
pub fn rw_arc_with_condvars<T:Freeze + Send>(
293293
user_data: T,
294294
num_condvars: uint) -> RWARC<T>
295295
{
@@ -299,7 +299,7 @@ pub fn rw_arc_with_condvars<T:Const + Owned>(
299299
RWARC { x: UnsafeAtomicRcBox::new(data), }
300300
}
301301

302-
impl<T:Const + Owned> RWARC<T> {
302+
impl<T:Freeze + Send> RWARC<T> {
303303
/// Duplicate a rwlock-protected ARC, as arc::clone.
304304
pub fn clone(&self) -> RWARC<T> {
305305
RWARC {
@@ -309,7 +309,7 @@ impl<T:Const + Owned> RWARC<T> {
309309

310310
}
311311

312-
impl<T:Const + Owned> RWARC<T> {
312+
impl<T:Freeze + Send> RWARC<T> {
313313
/**
314314
* Access the underlying data mutably. Locks the rwlock in write mode;
315315
* other readers and writers will block.
@@ -435,7 +435,7 @@ impl<T:Const + Owned> RWARC<T> {
435435
// lock it. This wraps the unsafety, with the justification that the 'lock'
436436
// field is never overwritten; only 'failed' and 'data'.
437437
#[doc(hidden)]
438-
fn borrow_rwlock<T:Const + Owned>(state: *const RWARCInner<T>) -> *RWlock {
438+
fn borrow_rwlock<T:Freeze + Send>(state: *const RWARCInner<T>) -> *RWlock {
439439
unsafe { cast::transmute(&const (*state).lock) }
440440
}
441441

@@ -452,7 +452,7 @@ pub struct RWReadMode<'self, T> {
452452
token: sync::RWlockReadMode<'self>,
453453
}
454454

455-
impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
455+
impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
456456
/// Access the pre-downgrade RWARC in write mode.
457457
pub fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
458458
match *self {
@@ -493,7 +493,7 @@ impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
493493
}
494494
}
495495

496-
impl<'self, T:Const + Owned> RWReadMode<'self, T> {
496+
impl<'self, T:Freeze + Send> RWReadMode<'self, T> {
497497
/// Access the post-downgrade rwlock in read mode.
498498
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
499499
match *self {

src/libextra/arena.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,18 @@ impl Arena {
186186
#[inline]
187187
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
188188
unsafe {
189-
// XXX: Borrow check
190-
let head = transmute_mut_region(&mut self.pod_head);
191-
192-
let start = round_up_to(head.fill, align);
189+
let this = transmute_mut_region(self);
190+
let start = round_up_to(this.pod_head.fill, align);
193191
let end = start + n_bytes;
194-
if end > at_vec::capacity(head.data) {
195-
return self.alloc_pod_grow(n_bytes, align);
192+
if end > at_vec::capacity(this.pod_head.data) {
193+
return this.alloc_pod_grow(n_bytes, align);
196194
}
197-
head.fill = end;
195+
this.pod_head.fill = end;
198196

199197
//debug!("idx = %u, size = %u, align = %u, fill = %u",
200198
// start, n_bytes, align, head.fill);
201199

202-
ptr::offset(vec::raw::to_ptr(head.data), start)
200+
ptr::offset(vec::raw::to_ptr(this.pod_head.data), start)
203201
}
204202
}
205203

@@ -231,21 +229,31 @@ impl Arena {
231229
fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
232230
-> (*u8, *u8) {
233231
unsafe {
234-
let head = transmute_mut_region(&mut self.head);
232+
let start;
233+
let end;
234+
let tydesc_start;
235+
let after_tydesc;
236+
237+
{
238+
let head = transmute_mut_region(&mut self.head);
239+
240+
tydesc_start = head.fill;
241+
after_tydesc = head.fill + sys::size_of::<*TyDesc>();
242+
start = round_up_to(after_tydesc, align);
243+
end = start + n_bytes;
244+
}
235245

236-
let tydesc_start = head.fill;
237-
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
238-
let start = round_up_to(after_tydesc, align);
239-
let end = start + n_bytes;
240-
if end > at_vec::capacity(head.data) {
246+
if end > at_vec::capacity(self.head.data) {
241247
return self.alloc_nonpod_grow(n_bytes, align);
242248
}
249+
250+
let head = transmute_mut_region(&mut self.head);
243251
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
244252

245253
//debug!("idx = %u, size = %u, align = %u, fill = %u",
246254
// start, n_bytes, align, head.fill);
247255

248-
let buf = vec::raw::to_ptr(head.data);
256+
let buf = vec::raw::to_ptr(self.head.data);
249257
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
250258
}
251259
}

src/libextra/bitv.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,15 @@ impl Bitv {
476476
* character is either '0' or '1'.
477477
*/
478478
pub fn to_str(&self) -> ~str {
479-
let mut rs = ~"";
480-
for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } };
481-
rs
479+
let mut rs = ~"";
480+
for self.each() |i| {
481+
if i {
482+
rs.push_char('1');
483+
} else {
484+
rs.push_char('0');
485+
}
486+
};
487+
rs
482488
}
483489

484490

src/libextra/comm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct DuplexStream<T, U> {
3030
}
3131

3232
// Allow these methods to be used without import:
33-
impl<T:Owned,U:Owned> DuplexStream<T, U> {
33+
impl<T:Send,U:Send> DuplexStream<T, U> {
3434
pub fn send(&self, x: T) {
3535
self.chan.send(x)
3636
}
@@ -48,19 +48,19 @@ impl<T:Owned,U:Owned> DuplexStream<T, U> {
4848
}
4949
}
5050

51-
impl<T:Owned,U:Owned> GenericChan<T> for DuplexStream<T, U> {
51+
impl<T:Send,U:Send> GenericChan<T> for DuplexStream<T, U> {
5252
fn send(&self, x: T) {
5353
self.chan.send(x)
5454
}
5555
}
5656

57-
impl<T:Owned,U:Owned> GenericSmartChan<T> for DuplexStream<T, U> {
57+
impl<T:Send,U:Send> GenericSmartChan<T> for DuplexStream<T, U> {
5858
fn try_send(&self, x: T) -> bool {
5959
self.chan.try_send(x)
6060
}
6161
}
6262

63-
impl<T:Owned,U:Owned> GenericPort<U> for DuplexStream<T, U> {
63+
impl<T:Send,U:Send> GenericPort<U> for DuplexStream<T, U> {
6464
fn recv(&self) -> U {
6565
self.port.recv()
6666
}
@@ -70,20 +70,20 @@ impl<T:Owned,U:Owned> GenericPort<U> for DuplexStream<T, U> {
7070
}
7171
}
7272

73-
impl<T:Owned,U:Owned> Peekable<U> for DuplexStream<T, U> {
73+
impl<T:Send,U:Send> Peekable<U> for DuplexStream<T, U> {
7474
fn peek(&self) -> bool {
7575
self.port.peek()
7676
}
7777
}
7878

79-
impl<T:Owned,U:Owned> Selectable for DuplexStream<T, U> {
79+
impl<T:Send,U:Send> Selectable for DuplexStream<T, U> {
8080
fn header(&mut self) -> *mut pipes::PacketHeader {
8181
self.port.header()
8282
}
8383
}
8484

8585
/// Creates a bidirectional stream.
86-
pub fn DuplexStream<T:Owned,U:Owned>()
86+
pub fn DuplexStream<T:Send,U:Send>()
8787
-> (DuplexStream<T, U>, DuplexStream<U, T>)
8888
{
8989
let (p1, c2) = comm::stream();

src/libextra/crypto/digest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ fn to_hex(rr: &[u8]) -> ~str {
4949
for rr.iter().advance() |b| {
5050
let hex = uint::to_str_radix(*b as uint, 16u);
5151
if hex.len() == 1 {
52-
s += "0";
52+
s.push_char('0');
5353
}
54-
s += hex;
54+
s.push_str(hex);
5555
}
5656
return s;
5757
}

0 commit comments

Comments
 (0)