Skip to content

Commit cbab89d

Browse files
committed
---
yaml --- r: 93811 b: refs/heads/try c: cd9069c h: refs/heads/master i: 93809: 8470f76 93807: 9163ef8 v: v3
1 parent 09e73c7 commit cbab89d

File tree

164 files changed

+1408
-1030
lines changed

Some content is hidden

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

164 files changed

+1408
-1030
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: 93a0dec2029f5c0658478187984eddf3afcc84b3
5+
refs/heads/try: cd9069ca734fe89fe446c16dc821e54b973506f5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/configure

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,20 @@ then
520520
fi
521521
fi
522522

523+
BIN_SUF=
524+
if [ $CFG_OSTYPE = "pc-mingw32" ]
525+
then
526+
BIN_SUF=.exe
527+
fi
528+
523529
if [ ! -z "$CFG_ENABLE_LOCAL_RUST" ]
524530
then
525-
if [ ! -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc ]
531+
if [ ! -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
526532
then
527533
err "no local rust to use"
528534
else
529-
LRV=`${CFG_LOCAL_RUST_ROOT}/bin/rustc --version`
530-
step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: " $LRV
535+
LRV=`${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} --version`
536+
step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
531537
fi
532538
fi
533539

branches/try/doc/rust.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,8 @@ block.
11311131
let fptr: extern "C" fn() -> ~[int] = new_vec;
11321132
~~~~
11331133

1134-
Extern functions may be called from Rust code, but
1135-
caution must be taken with respect to the size of the stack
1136-
segment, just as when calling an extern function normally.
1134+
Extern functions may be called directly from Rust code as Rust uses large,
1135+
contiguous stack segments like C.
11371136

11381137
### Type definitions
11391138

@@ -3162,7 +3161,7 @@ Borrowed pointers (`&`)
31623161
Borrowed pointers arise by (automatic) conversion from owning pointers, managed pointers,
31633162
or by applying the borrowing operator `&` to some other value,
31643163
including [lvalues, rvalues or temporaries](#lvalues-rvalues-and-temporaries).
3165-
Borrowed pointers are written `&content`, or in some cases `&f/content` for some lifetime-variable `f`,
3164+
Borrowed pointers are written `&content`, or in some cases `&'f content` for some lifetime-variable `f`,
31663165
for example `&int` means a borrowed pointer to an integer.
31673166
Copying a borrowed pointer is a "shallow" operation:
31683167
it involves only copying the pointer itself.
@@ -3597,9 +3596,9 @@ and releases them back to its environment when they are no longer needed.
35973596
The default implementation of the service-provider interface
35983597
consists of the C runtime functions `malloc` and `free`.
35993598

3600-
The runtime memory-management system, in turn, supplies Rust tasks
3601-
with facilities for allocating, extending and releasing stacks,
3602-
as well as allocating and freeing heap data.
3599+
The runtime memory-management system, in turn, supplies Rust tasks with
3600+
facilities for allocating releasing stacks, as well as allocating and freeing
3601+
heap data.
36033602

36043603
### Built in types
36053604

@@ -3762,7 +3761,6 @@ have come and gone during the course of Rust's development:
37623761

37633762
Additional specific influences can be seen from the following languages:
37643763

3765-
* The stack-growth implementation of Go.
37663764
* The structural algebraic types and compilation manager of SML.
37673765
* The attribute and assembly systems of C#.
37683766
* The references and deterministic destructor system of C++.

branches/try/doc/tutorial.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,7 @@ calling the destructor, and the owner determines whether the object is mutable.
890890

891891
Ownership is recursive, so mutability is inherited recursively and a destructor
892892
destroys the contained tree of owned objects. Variables are top-level owners
893-
and destroy the contained object when they go out of scope. A box managed by
894-
the garbage collector starts a new ownership tree, and the destructor is called
895-
when it is collected.
893+
and destroy the contained object when they go out of scope.
896894

897895
~~~~
898896
// the struct owns the objects contained in the `x` and `y` fields
@@ -1009,51 +1007,6 @@ let mut s = r; // box becomes mutable
10091007
let t = s; // box becomes immutable
10101008
~~~~
10111009

1012-
# Managed boxes
1013-
1014-
A managed box (`@`) is a heap allocation with the lifetime managed by a
1015-
task-local garbage collector. It will be destroyed at some point after there
1016-
are no references left to the box, no later than the end of the task. Managed
1017-
boxes lack an owner, so they start a new ownership tree and don't inherit
1018-
mutability. They do own the contained object, and mutability is defined by the
1019-
type of the managed box (`@` or `@mut`). An object containing a managed box is
1020-
not `Owned`, and can't be sent between tasks.
1021-
1022-
~~~~
1023-
let a = @5; // immutable
1024-
1025-
let mut b = @5; // mutable variable, immutable box
1026-
b = @10;
1027-
1028-
let c = @mut 5; // immutable variable, mutable box
1029-
*c = 10;
1030-
1031-
let mut d = @mut 5; // mutable variable, mutable box
1032-
*d += 5;
1033-
d = @mut 15;
1034-
~~~~
1035-
1036-
A mutable variable and an immutable variable can refer to the same box, given
1037-
that their types are compatible. Mutability of a box is a property of its type,
1038-
however, so for example a mutable handle to an immutable box cannot be
1039-
assigned a reference to a mutable box.
1040-
1041-
~~~~
1042-
let a = @1; // immutable box
1043-
let b = @mut 2; // mutable box
1044-
1045-
let mut c : @int; // declare a variable with type managed immutable int
1046-
let mut d : @mut int; // and one of type managed mutable int
1047-
1048-
c = a; // box type is the same, okay
1049-
d = b; // box type is the same, okay
1050-
~~~~
1051-
1052-
~~~~ {.xfail-test}
1053-
// but b cannot be assigned to c, or a to d
1054-
c = b; // error
1055-
~~~~
1056-
10571010
# Borrowed pointers
10581011

10591012
Rust's borrowed pointers are a general purpose reference type. In contrast with
@@ -1347,6 +1300,53 @@ defined in [`std::vec`] and [`std::str`].
13471300
[`std::vec`]: std/vec/index.html
13481301
[`std::str`]: std/str/index.html
13491302
1303+
# Ownership escape hatches
1304+
1305+
Ownership can cleanly describe tree-like data structures, and borrowed pointers provide non-owning
1306+
references. However, more flexibility is often desired and Rust provides ways to escape from strict
1307+
single parent ownership.
1308+
1309+
The standard library provides the `std::rc::Rc` pointer type to express *shared ownership* over a
1310+
reference counted box. As soon as all of the `Rc` pointers go out of scope, the box and the
1311+
contained value are destroyed.
1312+
1313+
~~~
1314+
use std::rc::Rc;
1315+
1316+
// A fixed-size array allocated in a reference-counted box
1317+
let x = Rc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1318+
let y = x.clone(); // a new owner
1319+
let z = x; // this moves `x` into `z`, rather than creating a new owner
1320+
1321+
assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1322+
1323+
// the variable is mutable, but not the contents of the box
1324+
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
1325+
a = z;
1326+
~~~
1327+
1328+
A garbage collected pointer is provided via `std::gc::Gc`, with a task-local garbage collector
1329+
having ownership of the box. It allows the creation of cycles, and the individual `Gc` pointers do
1330+
not have a destructor.
1331+
1332+
~~~
1333+
use std::gc::Gc;
1334+
1335+
// A fixed-size array allocated in a garbage-collected box
1336+
let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1337+
let y = x; // does not perform a move, unlike with `Rc`
1338+
let z = x;
1339+
1340+
assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1341+
~~~
1342+
1343+
With shared ownership, mutability cannot be inherited so the boxes are always immutable. However,
1344+
it's possible to use *dynamic* mutability via types like `std::cell::Cell` where freezing is handled
1345+
via dynamic checks and can fail at runtime.
1346+
1347+
The `Rc` and `Gc` types are not sendable, so they cannot be used to share memory between tasks. Safe
1348+
immutable and mutable shared memory is provided by the `extra::arc` module.
1349+
13501350
# Closures
13511351
13521352
Named functions, like those we've seen so far, may not refer to local

branches/try/src/etc/local_stage0.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
TARG_DIR=$1
44
PREFIX=$2
55

6-
BINDIR=bin
7-
LIBDIR=lib
6+
LIB_DIR=lib
7+
LIB_PREFIX=lib
88

99
OS=`uname -s`
1010
case $OS in
@@ -21,7 +21,8 @@ case $OS in
2121
(*)
2222
BIN_SUF=.exe
2323
LIB_SUF=.dll
24-
LIBDIR=bin
24+
LIB_DIR=bin
25+
LIB_PREFIX=
2526
break
2627
;;
2728
esac
@@ -31,7 +32,7 @@ if [ -z $PREFIX ]; then
3132
exit 1
3233
fi
3334

34-
if [ ! -e ${PREFIX}/bin/rustc ]; then
35+
if [ ! -e ${PREFIX}/bin/rustc${BIN_SUF} ]; then
3536
echo "No local rust installed at ${PREFIX}"
3637
exit 1
3738
fi
@@ -41,9 +42,9 @@ if [ -z $TARG_DIR ]; then
4142
exit 1
4243
fi
4344

44-
cp ${PREFIX}/bin/rustc ${TARG_DIR}/stage0/bin/
45-
cp ${PREFIX}/lib/rustc/${TARG_DIR}/${LIBDIR}/* ${TARG_DIR}/stage0/${LIBDIR}/
46-
cp ${PREFIX}/lib/libextra*${LIB_SUF} ${TARG_DIR}/stage0/${LIBDIR}/
47-
cp ${PREFIX}/lib/librust*${LIB_SUF} ${TARG_DIR}/stage0/${LIBDIR}/
48-
cp ${PREFIX}/lib/libstd*${LIB_SUF} ${TARG_DIR}/stage0/${LIBDIR}/
49-
cp ${PREFIX}/lib/libsyntax*${LIB_SUF} ${TARG_DIR}/stage0/${LIBDIR}/
45+
cp ${PREFIX}/bin/rustc${BIN_SUF} ${TARG_DIR}/stage0/bin/
46+
cp ${PREFIX}/${LIB_DIR}/rustc/${TARG_DIR}/${LIB_DIR}/* ${TARG_DIR}/stage0/${LIB_DIR}/
47+
cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}extra*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
48+
cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}rust*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
49+
cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}std*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
50+
cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}syntax*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/

branches/try/src/libextra/arc.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<T:Send> MutexArc<T> {
220220
* blocked on the mutex) will also fail immediately.
221221
*/
222222
#[inline]
223-
pub unsafe fn unsafe_access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
223+
pub unsafe fn unsafe_access<U>(&self, blk: |x: &mut T| -> U) -> U {
224224
let state = self.x.get();
225225
// Borrowck would complain about this if the function were
226226
// not already unsafe. See borrow_rwlock, far below.
@@ -234,8 +234,7 @@ impl<T:Send> MutexArc<T> {
234234
/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
235235
#[inline]
236236
pub unsafe fn unsafe_access_cond<U>(&self,
237-
blk: &fn(x: &mut T,
238-
c: &Condvar) -> U)
237+
blk: |x: &mut T, c: &Condvar| -> U)
239238
-> U {
240239
let state = self.x.get();
241240
do (&(*state).lock).lock_cond |cond| {
@@ -284,15 +283,14 @@ impl<T:Freeze + Send> MutexArc<T> {
284283
* unsafe_access_cond.
285284
*/
286285
#[inline]
287-
pub fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
286+
pub fn access<U>(&self, blk: |x: &mut T| -> U) -> U {
288287
unsafe { self.unsafe_access(blk) }
289288
}
290289

291290
/// As unsafe_access_cond but safe and Freeze.
292291
#[inline]
293292
pub fn access_cond<U>(&self,
294-
blk: &fn(x: &mut T,
295-
c: &Condvar) -> U)
293+
blk: |x: &mut T, c: &Condvar| -> U)
296294
-> U {
297295
unsafe { self.unsafe_access_cond(blk) }
298296
}
@@ -389,7 +387,7 @@ impl<T:Freeze + Send> RWArc<T> {
389387
* poison the Arc, so subsequent readers and writers will both also fail.
390388
*/
391389
#[inline]
392-
pub fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
390+
pub fn write<U>(&self, blk: |x: &mut T| -> U) -> U {
393391
unsafe {
394392
let state = self.x.get();
395393
do (*borrow_rwlock(state)).write {
@@ -403,7 +401,7 @@ impl<T:Freeze + Send> RWArc<T> {
403401
/// As write(), but with a condvar, as sync::rwlock.write_cond().
404402
#[inline]
405403
pub fn write_cond<U>(&self,
406-
blk: &fn(x: &mut T, c: &Condvar) -> U)
404+
blk: |x: &mut T, c: &Condvar| -> U)
407405
-> U {
408406
unsafe {
409407
let state = self.x.get();
@@ -427,7 +425,7 @@ impl<T:Freeze + Send> RWArc<T> {
427425
* Failing will unlock the Arc while unwinding. However, unlike all other
428426
* access modes, this will not poison the Arc.
429427
*/
430-
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
428+
pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
431429
unsafe {
432430
let state = self.x.get();
433431
do (*state).lock.read {
@@ -457,7 +455,7 @@ impl<T:Freeze + Send> RWArc<T> {
457455
* }
458456
* ```
459457
*/
460-
pub fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U {
458+
pub fn write_downgrade<U>(&self, blk: |v: RWWriteMode<T>| -> U) -> U {
461459
unsafe {
462460
let state = self.x.get();
463461
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
@@ -539,7 +537,7 @@ pub struct RWReadMode<'self, T> {
539537

540538
impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
541539
/// Access the pre-downgrade RWArc in write mode.
542-
pub fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
540+
pub fn write<U>(&mut self, blk: |x: &mut T| -> U) -> U {
543541
match *self {
544542
RWWriteMode {
545543
data: &ref mut data,
@@ -555,7 +553,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
555553

556554
/// Access the pre-downgrade RWArc in write mode with a condvar.
557555
pub fn write_cond<U>(&mut self,
558-
blk: &fn(x: &mut T, c: &Condvar) -> U)
556+
blk: |x: &mut T, c: &Condvar| -> U)
559557
-> U {
560558
match *self {
561559
RWWriteMode {
@@ -580,7 +578,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
580578

581579
impl<'self, T:Freeze + Send> RWReadMode<'self, T> {
582580
/// Access the post-downgrade rwlock in read mode.
583-
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
581+
pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
584582
match *self {
585583
RWReadMode {
586584
data: data,

branches/try/src/libextra/arena.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Arena {
184184
}
185185

186186
#[inline]
187-
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
187+
fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
188188
unsafe {
189189
let tydesc = get_tydesc::<T>();
190190
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@@ -241,7 +241,7 @@ impl Arena {
241241
}
242242

243243
#[inline]
244-
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
244+
fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
245245
unsafe {
246246
let tydesc = get_tydesc::<T>();
247247
let (ty_ptr, ptr) =
@@ -263,7 +263,7 @@ impl Arena {
263263

264264
// The external interface
265265
#[inline]
266-
pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
266+
pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T {
267267
unsafe {
268268
// XXX: Borrow check
269269
let this = transmute_mut(self);

0 commit comments

Comments
 (0)