Skip to content

Commit 023901f

Browse files
committed
---
yaml --- r: 142975 b: refs/heads/try2 c: 91ebfbb h: refs/heads/master i: 142973: b11122d 142971: ba4b859 142967: 21cd97f 142959: 64b9d68 142943: d7d5758 142911: b27fb10 142847: c202baf v: v3
1 parent a1722f9 commit 023901f

File tree

403 files changed

+4660
-4348
lines changed

Some content is hidden

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

403 files changed

+4660
-4348
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 2d82d9364c194d0ee6c46c378dfdb4d8b04a581a
8+
refs/heads/try2: 91ebfbb9592a2262c62c684a5a2431111c987b1e
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/configure

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ opt optimize 1 "build optimized rust code"
372372
opt optimize-cxx 1 "build optimized C++ code"
373373
opt optimize-llvm 1 "build optimized LLVM"
374374
opt debug 0 "build with extra debug fun"
375+
opt ratchet-bench 0 "ratchet benchmarks"
375376
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
376377
opt manage-submodules 1 "let the build manage the git submodules"
377378
opt mingw-cross 0 "cross-compile for win32 using mingw"
@@ -749,18 +750,18 @@ then
749750
cd ${CFG_SRC_DIR}
750751

751752
msg "git: submodule sync"
752-
"${CFG_GIT}" submodule --quiet sync
753+
"${CFG_GIT}" submodule sync
753754

754755
msg "git: submodule update"
755-
"${CFG_GIT}" submodule --quiet update --init
756+
"${CFG_GIT}" submodule update --init
756757
need_ok "git failed"
757758

758759
msg "git: submodule foreach sync"
759-
"${CFG_GIT}" submodule --quiet foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
760+
"${CFG_GIT}" submodule foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
760761
need_ok "git failed"
761762

762763
msg "git: submodule foreach update"
763-
"${CFG_GIT}" submodule --quiet update --init --recursive
764+
"${CFG_GIT}" submodule update --init --recursive
764765
need_ok "git failed"
765766

766767
# NB: this is just for the sake of getting the submodule SHA1 values
@@ -769,9 +770,9 @@ then
769770
"${CFG_GIT}" submodule status --recursive
770771

771772
msg "git: submodule clobber"
772-
"${CFG_GIT}" submodule --quiet foreach --recursive git clean -dxf
773+
"${CFG_GIT}" submodule foreach --recursive git clean -dxf
773774
need_ok "git failed"
774-
"${CFG_GIT}" submodule --quiet foreach --recursive git checkout .
775+
"${CFG_GIT}" submodule foreach --recursive git checkout .
775776
need_ok "git failed"
776777

777778
cd ${CFG_BUILD_DIR}

branches/try2/doc/rust.md

Lines changed: 93 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ The keywords are the following strings:
206206
~~~~~~~~ {.keyword}
207207
as
208208
break
209-
copy
210209
do
211210
else enum extern
212211
false fn for
@@ -443,7 +442,7 @@ Two examples of paths with type arguments:
443442
~~~~
444443
# use std::hashmap::HashMap;
445444
# fn f() {
446-
# fn id<T:Copy>(t: T) -> T { t }
445+
# fn id<T>(t: T) -> T { t }
447446
type t = HashMap<int,~str>; // Type arguments used in a type expression
448447
let x = id::<int>(10); // Type arguments used in a call expression
449448
# }
@@ -907,11 +906,10 @@ example, `sys::size_of::<u32>() == 4`.
907906

908907
Since a parameter type is opaque to the generic function, the set of
909908
operations that can be performed on it is limited. Values of parameter
910-
type can always be moved, but they can only be copied when the
911-
parameter is given a [`Copy` bound](#type-kinds).
909+
type can only be moved, not copied.
912910

913911
~~~~
914-
fn id<T: Copy>(x: T) -> T { x }
912+
fn id<T>(x: T) -> T { x }
915913
~~~~
916914

917915
Similarly, [trait](#traits) bounds can be specified for type
@@ -1124,6 +1122,41 @@ static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
11241122
};
11251123
~~~~
11261124

1125+
#### Mutable statics
1126+
1127+
If a static item is declared with the ```mut``` keyword, then it is allowed to
1128+
be modified by the program. One of Rust's goals is to make concurrency bugs hard
1129+
to run into, and this is obviously a very large source of race conditions or
1130+
other bugs. For this reason, an ```unsafe``` block is required when either
1131+
reading or writing a mutable static variable. Care should be taken to ensure
1132+
that modifications to a mutable static are safe with respect to other tasks
1133+
running in the same process.
1134+
1135+
Mutable statics are still very useful, however. They can be used with C
1136+
libraries and can also be bound from C libraries (in an ```extern``` block).
1137+
1138+
~~~
1139+
# fn atomic_add(_: &mut uint, _: uint) -> uint { 2 }
1140+
1141+
static mut LEVELS: uint = 0;
1142+
1143+
// This violates the idea of no shared state, and this doesn't internally
1144+
// protect against races, so this function is `unsafe`
1145+
unsafe fn bump_levels_unsafe1() -> uint {
1146+
let ret = LEVELS;
1147+
LEVELS += 1;
1148+
return ret;
1149+
}
1150+
1151+
// Assuming that we have an atomic_add function which returns the old value,
1152+
// this function is "safe" but the meaning of the return value may not be what
1153+
// callers expect, so it's still marked as `unsafe`
1154+
unsafe fn bump_levels_unsafe2() -> uint {
1155+
return atomic_add(&mut LEVELS, 1);
1156+
}
1157+
1158+
~~~
1159+
11271160
### Traits
11281161

11291162
A _trait_ describes a set of method types.
@@ -1519,8 +1552,6 @@ A complete list of the built-in language items follows:
15191552

15201553
`const`
15211554
: Cannot be mutated.
1522-
`copy`
1523-
: Can be implicitly copied.
15241555
`owned`
15251556
: Are uniquely owned.
15261557
`durable`
@@ -1587,7 +1618,8 @@ A complete list of the built-in language items follows:
15871618
`check_not_borrowed`
15881619
: Fail if a value has existing borrowed pointers to it.
15891620
`strdup_uniq`
1590-
: Return a new unique string containing a copy of the contents of a unique string.
1621+
: Return a new unique string
1622+
containing a copy of the contents of a unique string.
15911623

15921624
> **Note:** This list is likely to become out of date. We should auto-generate it
15931625
> from `librustc/middle/lang_items.rs`.
@@ -1736,10 +1768,13 @@ A temporary's lifetime equals the largest lifetime of any borrowed pointer that
17361768

17371769
#### Moved and copied types
17381770

1739-
When a [local variable](#memory-slots) is used as an [rvalue](#lvalues-rvalues-and-temporaries)
1740-
the variable will either be [moved](#move-expressions) or [copied](#copy-expressions),
1771+
When a [local variable](#memory-slots) is used
1772+
as an [rvalue](#lvalues-rvalues-and-temporaries)
1773+
the variable will either be [moved](#move-expressions) or copied,
17411774
depending on its type.
1742-
For types that contain mutable fields or [owning pointers](#owning-pointers), the variable is moved.
1775+
For types that contain [owning pointers](#owning-pointers)
1776+
or values that implement the special trait `Drop`,
1777+
the variable is moved.
17431778
All other types are copied.
17441779

17451780

@@ -1918,9 +1953,9 @@ task in a _failing state_.
19181953

19191954
### Unary operator expressions
19201955

1921-
Rust defines six symbolic unary operators,
1922-
in addition to the unary [copy](#unary-copy-expressions) and [move](#unary-move-expressions) operators.
1923-
They are all written as prefix operators, before the expression they apply to.
1956+
Rust defines six symbolic unary operators.
1957+
They are all written as prefix operators,
1958+
before the expression they apply to.
19241959

19251960
`-`
19261961
: Negation. May only be applied to numeric types.
@@ -2119,60 +2154,6 @@ An example of a parenthesized expression:
21192154
let x = (2 + 3) * 4;
21202155
~~~~
21212156

2122-
### Unary copy expressions
2123-
2124-
~~~~~~~~{.ebnf .gram}
2125-
copy_expr : "copy" expr ;
2126-
~~~~~~~~
2127-
2128-
> **Note:** `copy` expressions are deprecated. It's preferable to use
2129-
> the `Clone` trait and `clone()` method.
2130-
2131-
A _unary copy expression_ consists of the unary `copy` operator applied to
2132-
some argument expression.
2133-
2134-
Evaluating a copy expression first evaluates the argument expression, then
2135-
copies the resulting value, allocating any memory necessary to hold the new
2136-
copy.
2137-
2138-
[Managed boxes](#pointer-types) (type `@`) are, as usual, shallow-copied,
2139-
as are raw and borrowed pointers.
2140-
[Owned boxes](#pointer-types), [owned vectors](#vector-types) and similar owned types are deep-copied.
2141-
2142-
Since the binary [assignment operator](#assignment-expressions) `=` performs a copy or move implicitly,
2143-
the unary copy operator is typically only used to cause an argument to a function to be copied and passed by value.
2144-
2145-
An example of a copy expression:
2146-
2147-
~~~~
2148-
fn mutate(mut vec: ~[int]) {
2149-
vec[0] = 10;
2150-
}
2151-
2152-
let v = ~[1,2,3];
2153-
2154-
mutate(copy v); // Pass a copy
2155-
2156-
assert!(v[0] == 1); // Original was not modified
2157-
~~~~
2158-
2159-
### Unary move expressions
2160-
2161-
~~~~~~~~{.ebnf .gram}
2162-
move_expr : "move" expr ;
2163-
~~~~~~~~
2164-
2165-
A _unary move expression_ is similar to a [unary copy](#unary-copy-expressions) expression,
2166-
except that it can only be applied to a [local variable](#memory-slots),
2167-
and it performs a _move_ on its operand, rather than a copy.
2168-
That is, the memory location denoted by its operand is de-initialized after evaluation,
2169-
and the resulting value is a shallow copy of the operand,
2170-
even if the operand is an [owning type](#type-kinds).
2171-
2172-
2173-
> **Note:** In future versions of Rust, `move` may be removed as a separate operator;
2174-
> moves are now [automatically performed](#moved-and-copied-types) for most cases `move` would be appropriate.
2175-
21762157

21772158
### Call expressions
21782159

@@ -2507,10 +2488,11 @@ match x {
25072488
}
25082489
~~~~
25092490

2510-
Patterns that bind variables default to binding to a copy or move of the matched value
2491+
Patterns that bind variables
2492+
default to binding to a copy or move of the matched value
25112493
(depending on the matched value's type).
2512-
This can be made explicit using the ```copy``` keyword,
2513-
changed to bind to a borrowed pointer by using the ```ref``` keyword,
2494+
This can be changed to bind to a borrowed pointer by
2495+
using the ```ref``` keyword,
25142496
or to a mutable borrowed pointer using ```ref mut```.
25152497

25162498
A pattern that's just an identifier,
@@ -2896,16 +2878,18 @@ and the cast expression in `main`.
28962878
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
28972879

28982880
~~~~~~~
2899-
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
2900-
if xs.len() == 0 { return ~[]; }
2901-
let first: B = f(copy xs[0]);
2902-
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
2903-
return ~[first] + rest;
2881+
fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
2882+
if xs.len() == 0 {
2883+
return ~[];
2884+
}
2885+
let first: B = f(xs[0].clone());
2886+
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
2887+
return ~[first] + rest;
29042888
}
29052889
~~~~~~~
29062890

2907-
Here, `first` has type `B`, referring to `map`'s `B` type parameter; and `rest` has
2908-
type `~[B]`, a vector type with element type `B`.
2891+
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
2892+
and `rest` has type `~[B]`, a vector type with element type `B`.
29092893

29102894
### Self types
29112895

@@ -2919,7 +2903,9 @@ trait Printable {
29192903
}
29202904
29212905
impl Printable for ~str {
2922-
fn make_string(&self) -> ~str { copy *self }
2906+
fn make_string(&self) -> ~str {
2907+
(*self).clone()
2908+
}
29232909
}
29242910
~~~~~~~~
29252911

@@ -2933,23 +2919,29 @@ The kinds are:
29332919

29342920
`Freeze`
29352921
: Types of this kind are deeply immutable;
2936-
they contain no mutable memory locations directly or indirectly via pointers.
2922+
they contain no mutable memory locations
2923+
directly or indirectly via pointers.
29372924
`Send`
29382925
: Types of this kind can be safely sent between tasks.
29392926
This kind includes scalars, owning pointers, owned closures, and
2940-
structural types containing only other owned types. All `Send` types are `Static`.
2941-
`Copy`
2942-
: This kind includes all types that can be copied. All types with
2943-
sendable kind are copyable, as are managed boxes, managed closures,
2944-
trait types, and structural types built out of these.
2945-
Types with destructors (types that implement `Drop`) can not implement `Copy`.
2927+
structural types containing only other owned types.
2928+
All `Send` types are `'static`.
2929+
`'static`
2930+
: Types of this kind do not contain any borrowed pointers;
2931+
this can be a useful guarantee for code
2932+
that breaks borrowing assumptions
2933+
using [`unsafe` operations](#unsafe-functions).
29462934
`Drop`
2947-
: This is not strictly a kind, but its presence interacts with kinds: the `Drop`
2948-
trait provides a single method `drop` that takes no parameters, and is run
2949-
when values of the type are dropped. Such a method is called a "destructor",
2950-
and are always executed in "top-down" order: a value is completely destroyed
2951-
before any of the values it owns run their destructors. Only `Send` types
2952-
that do not implement `Copy` can implement `Drop`.
2935+
: This is not strictly a kind,
2936+
but its presence interacts with kinds:
2937+
the `Drop` trait provides a single method `drop`
2938+
that takes no parameters,
2939+
and is run when values of the type are dropped.
2940+
Such a method is called a "destructor",
2941+
and are always executed in "top-down" order:
2942+
a value is completely destroyed
2943+
before any of the values it owns run their destructors.
2944+
Only `Send` types can implement `Drop`.
29532945

29542946
_Default_
29552947
: Types with destructors, closure environments,
@@ -2962,30 +2954,15 @@ Kinds can be supplied as _bounds_ on type parameters, like traits,
29622954
in which case the parameter is constrained to types satisfying that kind.
29632955

29642956
By default, type parameters do not carry any assumed kind-bounds at all.
2957+
When instantiating a type parameter,
2958+
the kind bounds on the parameter are checked
2959+
to be the same or narrower than the kind
2960+
of the type that it is instantiated with.
29652961

2966-
Any operation that causes a value to be copied requires the type of that value to be of copyable kind,
2967-
so the `Copy` bound is frequently required on function type parameters.
2968-
For example, this is not a valid program:
2969-
2970-
~~~~{.xfail-test}
2971-
fn box<T>(x: T) -> @T { @x }
2972-
~~~~
2973-
2974-
Putting `x` into a managed box involves copying, and the `T` parameter has the default (non-copyable) kind.
2975-
To change that, a bound is declared:
2976-
2977-
~~~~
2978-
fn box<T: Copy>(x: T) -> @T { @x }
2979-
~~~~
2980-
2981-
Calling this second version of `box` on a noncopyable type is not
2982-
allowed. When instantiating a type parameter, the kind bounds on the
2983-
parameter are checked to be the same or narrower than the kind of the
2984-
type that it is instantiated with.
2985-
2986-
Sending operations are not part of the Rust language, but are
2987-
implemented in the library. Generic functions that send values bound
2988-
the kind of these values to sendable.
2962+
Sending operations are not part of the Rust language,
2963+
but are implemented in the library.
2964+
Generic functions that send values
2965+
bound the kind of these values to sendable.
29892966

29902967
# Memory and concurrency models
29912968

@@ -3093,9 +3070,7 @@ managed box value makes a shallow copy of the pointer (optionally incrementing
30933070
a reference count, if the managed box is implemented through
30943071
reference-counting).
30953072

3096-
Owned box values exist in 1:1 correspondence with their heap allocation;
3097-
copying an owned box value makes a deep copy of the heap allocation and
3098-
produces a pointer to the new allocation.
3073+
Owned box values exist in 1:1 correspondence with their heap allocation.
30993074

31003075
An example of constructing one managed box type and value, and one owned box
31013076
type and value:

0 commit comments

Comments
 (0)