Skip to content

Commit 529ae38

Browse files
committed
Merge remote-tracking branch 'remotes/origin/incoming' into serial
2 parents 3564389 + a17a9d4 commit 529ae38

File tree

8 files changed

+88
-120
lines changed

8 files changed

+88
-120
lines changed

configure

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ do
881881
;;
882882
esac
883883
need_ok "LLVM configure failed"
884+
885+
# Hack the tools Makefile to turn off the clang build
886+
sed -i 's/clang//g' tools/Makefile
887+
884888
cd $CFG_BUILD_DIR
885889
fi
886890

doc/tutorial.md

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,46 @@ refer to that through a pointer.
10021002

10031003
## Owned boxes
10041004

1005-
An owned box (`~`) is a uniquely owned allocation on the heap. An owned box
1006-
inherits the mutability and lifetime of the owner as it would if there was no
1007-
box. The purpose of an owned box is to add a layer of indirection in order to
1008-
create recursive data structures or cheaply pass around an object larger than a
1009-
pointer.
1005+
An owned box (`~`) is a uniquely owned allocation on the heap. It inherits the
1006+
mutability and lifetime of the owner as it would if there was no box.
1007+
1008+
~~~~
1009+
let x = 5; // immutable
1010+
let mut y = 5; // mutable
1011+
y += 2;
1012+
1013+
let x = ~5; // immutable
1014+
let mut y = ~5; // mutable
1015+
*y += 2; // the * operator is needed to access the contained value
1016+
~~~~
1017+
1018+
The purpose of an owned box is to add a layer of indirection in order to create
1019+
recursive data structures or cheaply pass around an object larger than a
1020+
pointer. Since an owned box has a unique owner, it can be used to represent any
1021+
tree data structure.
1022+
1023+
The following struct won't compile, because the lack of indirection would mean
1024+
it has an infinite size:
1025+
1026+
~~~~ {.xfail-test}
1027+
struct Foo {
1028+
child: Option<Foo>
1029+
}
1030+
~~~~
1031+
1032+
> ***Note:*** The `Option` type is an enum that represents an *optional* value.
1033+
> It's comparable to a nullable pointer in many other languages, but stores the
1034+
> contained value unboxed.
1035+
1036+
Adding indirection with an owned pointer allocates the child outside of the
1037+
struct on the heap, which makes it a finite size and won't result in a
1038+
compile-time error:
1039+
1040+
~~~~
1041+
struct Foo {
1042+
child: Option<~Foo>
1043+
}
1044+
~~~~
10101045

10111046
## Managed boxes
10121047

@@ -1018,6 +1053,20 @@ mutability. They do own the contained object, and mutability is defined by the
10181053
type of the shared box (`@` or `@mut`). An object containing a managed box is
10191054
not `Owned`, and can't be sent between tasks.
10201055

1056+
~~~~
1057+
let a = @5; // immutable
1058+
1059+
let mut b = @5; // mutable variable, immutable box
1060+
b = @10;
1061+
1062+
let c = @mut 5; // immutable variable, mutable box
1063+
*c = 10;
1064+
1065+
let mut d = @mut 5; // mutable variable, mutable box
1066+
*d += 5;
1067+
d = @mut 15;
1068+
~~~~
1069+
10211070
# Move semantics
10221071

10231072
Rust uses a shallow copy for parameter passing, assignment and returning values
@@ -1035,10 +1084,10 @@ let z = x; // no new memory allocated, x can no longer be used
10351084
# Borrowed pointers
10361085

10371086
Rust's borrowed pointers are a general purpose reference type. In contrast with
1038-
owned pointers, where the holder of an owned pointer is the owner of the
1039-
pointed-to memory, borrowed pointers never imply ownership. A pointer can be
1040-
borrowed to any object, and the compiler verifies that it cannot outlive the
1041-
lifetime of the object.
1087+
owned boxes, where the holder of an owned box is the owner of the pointed-to
1088+
memory, borrowed pointers never imply ownership. A pointer can be borrowed to
1089+
any object, and the compiler verifies that it cannot outlive the lifetime of
1090+
the object.
10421091

10431092
As an example, consider a simple struct type, `Point`:
10441093

@@ -1124,10 +1173,7 @@ For a more in-depth explanation of borrowed pointers, read the
11241173
## Freezing
11251174
11261175
Borrowing an immutable pointer to an object freezes it and prevents mutation.
1127-
`Owned` objects have freezing enforced statically at compile-time. Mutable
1128-
managed boxes handle freezing dynamically when any of their contents are
1129-
borrowed, and the task will fail if an attempt to modify them is made while
1130-
they are frozen.
1176+
`Owned` objects have freezing enforced statically at compile-time.
11311177
11321178
~~~~
11331179
let mut x = 5;
@@ -1137,6 +1183,20 @@ let mut x = 5;
11371183
// x is now unfrozen again
11381184
~~~~
11391185
1186+
Mutable managed boxes handle freezing dynamically when any of their contents
1187+
are borrowed, and the task will fail if an attempt to modify them is made while
1188+
they are frozen:
1189+
1190+
~~~~
1191+
let x = @mut 5;
1192+
let y = x;
1193+
{
1194+
let y = &*y; // the managed box is now frozen
1195+
// modifying it through x or y will cause a task failure
1196+
}
1197+
// the box is now unfrozen again
1198+
~~~~
1199+
11401200
# Dereferencing pointers
11411201
11421202
Rust uses the unary star operator (`*`) to access the contents of a

src/librustc/middle/astencode.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -681,45 +681,6 @@ impl vtable_decoder_helpers for reader::Decoder {
681681
@self.read_to_vec(|| self.read_vtable_origin(xcx) )
682682
}
683683
684-
#[cfg(stage0)]
685-
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
686-
-> typeck::vtable_origin {
687-
do self.read_enum(~"vtable_origin") {
688-
do self.read_enum_variant |i| {
689-
match i {
690-
0 => {
691-
typeck::vtable_static(
692-
do self.read_enum_variant_arg(0u) {
693-
self.read_def_id(xcx)
694-
},
695-
do self.read_enum_variant_arg(1u) {
696-
self.read_tys(xcx)
697-
},
698-
do self.read_enum_variant_arg(2u) {
699-
self.read_vtable_res(xcx)
700-
}
701-
)
702-
}
703-
1 => {
704-
typeck::vtable_param(
705-
do self.read_enum_variant_arg(0u) {
706-
self.read_uint()
707-
},
708-
do self.read_enum_variant_arg(1u) {
709-
self.read_uint()
710-
}
711-
)
712-
}
713-
// hard to avoid - user input
714-
_ => fail!(~"bad enum variant")
715-
}
716-
}
717-
}
718-
}
719-
720-
#[cfg(stage1)]
721-
#[cfg(stage2)]
722-
#[cfg(stage3)]
723684
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
724685
-> typeck::vtable_origin {
725686
do self.read_enum("vtable_origin") {

src/libstd/ebml.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,6 @@ pub mod reader {
321321
self.push_doc(self.next_doc(EsEnum), f)
322322
}
323323
324-
#[cfg(stage0)]
325-
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T {
326-
debug!("read_enum_variant()");
327-
let idx = self._next_uint(EsEnumVid);
328-
debug!(" idx=%u", idx);
329-
do self.push_doc(self.next_doc(EsEnumBody)) {
330-
f(idx)
331-
}
332-
}
333-
334-
#[cfg(stage1)]
335-
#[cfg(stage2)]
336-
#[cfg(stage3)]
337324
fn read_enum_variant<T>(&self, _names: &[&str], f: &fn(uint) -> T) -> T {
338325
debug!("read_enum_variant()");
339326
let idx = self._next_uint(EsEnumVid);
@@ -373,23 +360,6 @@ pub mod reader {
373360
f()
374361
}
375362
376-
#[cfg(stage0)]
377-
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
378-
debug!("read_option()");
379-
do self.read_enum("Option") || {
380-
do self.read_enum_variant |idx| {
381-
match idx {
382-
0 => f(false),
383-
1 => f(true),
384-
_ => fail!(),
385-
}
386-
}
387-
}
388-
}
389-
390-
#[cfg(stage1)]
391-
#[cfg(stage2)]
392-
#[cfg(stage3)]
393363
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
394364
debug!("read_option()");
395365
do self.read_enum("Option") || {

src/libstd/json.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,19 +803,6 @@ impl serialize::Decoder for Decoder {
803803
f()
804804
}
805805
806-
#[cfg(stage0)]
807-
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T {
808-
debug!("read_enum_variant()");
809-
let idx = match self.stack.pop() {
810-
Null => { self.stack.push(Null); 0 },
811-
value => { self.stack.push(value); 1 },
812-
};
813-
f(idx)
814-
}
815-
816-
#[cfg(stage1)]
817-
#[cfg(stage2)]
818-
#[cfg(stage3)]
819806
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T {
820807
debug!("read_enum_variant(names=%?)", names);
821808
let name = match self.stack.pop() {

src/libstd/serialize.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ pub trait Decoder {
8383

8484
// Compound types:
8585
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T;
86-
#[cfg(stage0)]
87-
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T;
88-
#[cfg(stage1)]
89-
#[cfg(stage2)]
90-
#[cfg(stage3)]
9186
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
9287
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
9388

@@ -558,23 +553,6 @@ impl<
558553
K: Decodable<D> + Hash + IterBytes + Eq,
559554
V: Decodable<D>
560555
> Decodable<D> for LinearMap<K, V> {
561-
#[cfg(stage0)]
562-
fn decode(d: &D) -> LinearMap<K, V> {
563-
do d.read_map |len| {
564-
let mut map = LinearMap::new();
565-
map.reserve_at_least(len);
566-
for uint::range(0, len) |i| {
567-
let key = d.read_map_elt_key(i, || Decodable::decode(d));
568-
let val = d.read_map_elt_val(i, || Decodable::decode(d));
569-
map.insert(key, val);
570-
}
571-
map
572-
}
573-
}
574-
575-
#[cfg(stage1)]
576-
#[cfg(stage2)]
577-
#[cfg(stage3)]
578556
fn decode(d: &D) -> LinearMap<K, V> {
579557
do d.read_map |len| {
580558
let mut map = LinearMap::with_capacity(len);

src/libsyntax/ext/auto_encode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,13 +1281,13 @@ mod test {
12811281
f();
12821282
}
12831283
1284-
fn read_map<T>(&self, f: &fn(uint) -> T) -> T {
1284+
fn emit_map<T>(&self, f: &fn(uint) -> T) -> T {
12851285
self.add_unknown_to_log(); f(0);
12861286
}
1287-
fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T {
1287+
fn emit_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T {
12881288
self.add_unknown_to_log(); f();
12891289
}
1290-
fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T {
1290+
fn emit_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T {
12911291
self.add_unknown_to_log(); f();
12921292
}
12931293
}

src/snapshots.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
S 2013-03-28 f7a2371
2+
macos-i386 2e05a33716fc4982db53946c3b0dccf0194826fe
3+
macos-x86_64 fbd3feec8dd17a6b6c8df114e6e9b4cd17cc6172
4+
linux-i386 b89197edd3ba5be7c2ee6577f048d7663640e1d1
5+
linux-x86_64 61a4377c6d0ca5814c2b2b752d73b61b741a23c9
6+
winnt-i386 858a74afb210b30697227a87b67e44786b383a0c
7+
freebsd-x86_64 01f1e4b94504045e763eecb71c7e0852f6e85036
8+
19
S 2013-03-27 8c15409
210
macos-x86_64 05eb3801b60056d95715c891d00c5d372e34d00c
311
macos-i386 4119e3fa614fa86adf60ed0183d00db3ce6d0dbc

0 commit comments

Comments
 (0)