Skip to content

Commit 875e582

Browse files
committed
---
yaml --- r: 145264 b: refs/heads/try2 c: 068e042 h: refs/heads/master v: v3
1 parent 76900c6 commit 875e582

File tree

259 files changed

+5806
-4016
lines changed

Some content is hidden

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

259 files changed

+5806
-4016
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: 3bd0eb9f637794cefbdb700d4fbe125369de53dd
8+
refs/heads/try2: 068e04231ded7fccca349babb1ba58ab3d796f40
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/.gitattributes

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
[attr]rust text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4
22

3-
* text=auto
3+
* text eol=lf
44
*.cpp rust
55
*.h rust
66
*.rs rust
77
src/rt/msvc/* -whitespace
88
src/rt/vg/* -whitespace
99
src/rt/linenoise/* -whitespace
1010
src/rt/jemalloc/**/* -whitespace
11-
src/rt/jemalloc/include/jemalloc/jemalloc.h.in text eol=lf
12-
src/rt/jemalloc/include/jemalloc/jemalloc_defs.h.in text eol=lf
13-
src/rt/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in text eol=lf

branches/try2/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ CSREQ$(1)_T_$(2)_H_$(3) = \
442442
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
443443
$$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
444444
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
445+
$$(HBIN$(1)_H_$(3))/rustdoc_ng$$(X_$(3)) \
445446
$$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \
446447
$$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \
447448
$$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \

branches/try2/doc/rust.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ string_body : non_double_quote
248248
| '\x5c' [ '\x22' | common_escape ] ;
249249
250250
common_escape : '\x5c'
251-
| 'n' | 'r' | 't'
251+
| 'n' | 'r' | 't' | '0'
252252
| 'x' hex_digit 2
253253
| 'u' hex_digit 4
254254
| 'U' hex_digit 8 ;
@@ -962,24 +962,76 @@ parameters to allow methods with that trait to be called on values
962962
of that type.
963963

964964

965-
#### Unsafe functions
966-
967-
Unsafe functions are those containing unsafe operations that are not contained in an [`unsafe` block](#unsafe-blocks).
968-
Such a function must be prefixed with the keyword `unsafe`.
965+
#### Unsafety
969966

970967
Unsafe operations are those that potentially violate the memory-safety guarantees of Rust's static semantics.
971-
Specifically, the following operations are considered unsafe:
968+
969+
The following language level features cannot be used in the safe subset of Rust:
972970

973971
- Dereferencing a [raw pointer](#pointer-types).
974-
- Casting a [raw pointer](#pointer-types) to a safe pointer type.
975-
- Calling an unsafe function.
972+
- Calling an unsafe function (including an intrinsic or foreign function).
976973

977-
##### Unsafe blocks
974+
##### Unsafe functions
978975

979-
A block of code can also be prefixed with the `unsafe` keyword, to permit a sequence of unsafe operations in an otherwise-safe function.
980-
This facility exists because the static semantics of Rust are a necessary approximation of the dynamic semantics.
981-
When a programmer has sufficient conviction that a sequence of unsafe operations is actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The compiler will consider uses of such code "safe", to the surrounding context.
976+
Unsafe functions are functions that are not safe in all contexts and/or for all possible inputs.
977+
Such a function must be prefixed with the keyword `unsafe`.
978+
979+
##### Unsafe blocks
982980

981+
A block of code can also be prefixed with the `unsafe` keyword, to permit calling `unsafe` functions
982+
or dereferencing raw pointers within a safe function.
983+
984+
When a programmer has sufficient conviction that a sequence of potentially unsafe operations is
985+
actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The
986+
compiler will consider uses of such code safe, in the surrounding context.
987+
988+
Unsafe blocks are used to wrap foreign libraries, make direct use of hardware or implement features
989+
not directly present in the language. For example, Rust provides the language features necessary to
990+
implement memory-safe concurrency in the language but the implementation of tasks and message
991+
passing is in the standard library.
992+
993+
Rust's type system is a conservative approximation of the dynamic safety requirements, so in some
994+
cases there is a performance cost to using safe code. For example, a doubly-linked list is not a
995+
tree structure and can only be represented with managed or reference-counted pointers in safe code.
996+
By using `unsafe` blocks to represent the reverse links as raw pointers, it can be implemented with
997+
only owned pointers.
998+
999+
##### Behavior considered unsafe
1000+
1001+
This is a list of behavior which is forbidden in all Rust code. Type checking provides the guarantee
1002+
that these issues are never caused by safe code. An `unsafe` block or function is responsible for
1003+
never invoking this behaviour or exposing an API making it possible for it to occur in safe code.
1004+
1005+
* Data races
1006+
* Dereferencing a null/dangling raw pointer
1007+
* Mutating an immutable value/reference, if it is not marked as non-`Freeze`
1008+
* Reads of [undef](http://llvm.org/docs/LangRef.html#undefined-values) (uninitialized) memory
1009+
* Breaking the [pointer aliasing rules](http://llvm.org/docs/LangRef.html#pointer-aliasing-rules)
1010+
with raw pointers (a subset of the rules used by C)
1011+
* Invoking undefined behavior via compiler intrinsics:
1012+
* Indexing outside of the bounds of an object with `std::ptr::offset` (`offset` intrinsic), with
1013+
the exception of one byte past the end which is permitted.
1014+
* Using `std::ptr::copy_nonoverlapping_memory` (`memcpy32`/`memcpy64` instrinsics) on
1015+
overlapping buffers
1016+
* Invalid values in primitive types, even in private fields/locals:
1017+
* Dangling/null pointers in non-raw pointers, or slices
1018+
* A value other than `false` (0) or `true` (1) in a `bool`
1019+
* A discriminant in an `enum` not included in the type definition
1020+
* A value in a `char` which is a surrogate or above `char::MAX`
1021+
* non-UTF-8 byte sequences in a `str`
1022+
1023+
##### Behaviour not considered unsafe
1024+
1025+
This is a list of behaviour not considered *unsafe* in Rust terms, but that may be undesired.
1026+
1027+
* Deadlocks
1028+
* Reading data from private fields (`std::repr`, `format!("{:?}", x)`)
1029+
* Leaks due to reference count cycles, even in the global heap
1030+
* Exiting without calling destructors
1031+
* Sending signals
1032+
* Accessing/modifying the file system
1033+
* Unsigned integer overflow (well-defined as wrapping)
1034+
* Signed integer overflow (well-defined as two's complement representation wrapping)
9831035

9841036
#### Diverging functions
9851037

branches/try2/doc/tutorial-ffi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<T: Send> Unique<T> {
321321
322322
#[unsafe_destructor]
323323
impl<T: Send> Drop for Unique<T> {
324-
fn drop(&self) {
324+
fn drop(&mut self) {
325325
#[fixed_stack_segment];
326326
#[inline(never)];
327327

branches/try2/doc/tutorial-rustpkg.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
% Rust Packaging Tutorial
2+
3+
# Introduction
4+
5+
Sharing is caring. Rust comes with a tool, `rustpkg`, which allows you to
6+
package up your Rust code and share it with other people. This tutorial will
7+
get you started on all of the concepts and commands you need to give the gift
8+
of Rust code to someone else.
9+
10+
## Installing External Packages
11+
12+
First, let's try to use an external package somehow. I've made a sample package
13+
called `hello` to demonstrate how to do so. Here's how `hello` is used:
14+
15+
~~~~
16+
extern mod hello;
17+
18+
fn main() {
19+
hello::world();
20+
}
21+
~~~~
22+
23+
Easy! But if you try to compile this, you'll get an error:
24+
25+
~~~~ {.notrust}
26+
$ rustc main.rs
27+
main.rs:1:0: 1:17 error: can't find crate for `hello`
28+
main.rs:1 extern mod hello;
29+
^~~~~~~~~~~~~~~~~
30+
31+
~~~~
32+
33+
This makes sense, as we haven't gotten it from anywhere yet! Luckily for us,
34+
`rustpkg` has an easy way to fetch others' code: the `install` command. It's
35+
used like this:
36+
37+
~~~ {.notrust}
38+
$ rustpkg install pkg_id
39+
~~~
40+
41+
This will install a package named 'pkg_id' into your current Rust environment.
42+
I called it 'pkg_id' in this example because `rustpkg` calls this a 'package
43+
identifier.' When using it with an external package like this, it's often a
44+
URI fragment. You see, Rust has no central authority for packages. You can
45+
build your own `hello` library if you want, and that's fine. We'd both host
46+
them in different places and different projects would rely on whichever version
47+
they preferred.
48+
49+
To install the `hello` library, simply run this in your terminal:
50+
51+
~~~ {.notrust}
52+
$ rustpkg install github.com/steveklabnik/hello
53+
~~~
54+
55+
You should see a message that looks like this:
56+
57+
~~~ {.notrust}
58+
note: Installed package github.com/steveklabnik/hello-0.1 to /some/path/.rust
59+
~~~
60+
61+
Now, compiling our example should work:
62+
63+
~~~ {.notrust}
64+
$ rustc main.rs
65+
$ ./main
66+
Hello, world.
67+
~~~
68+
69+
Simple! That's all it takes.
70+
71+
## Workspaces
72+
73+
Before we can talk about how to make packages of your own, you have to
74+
understand the big concept with `rustpkg`: workspaces. A 'workspace' is simply
75+
a directory that has certain sub-directories that `rustpkg` expects. Different
76+
Rust projects will go into different workspaces.
77+
78+
A workspace consists of any directory that has the following
79+
directories:
80+
81+
* `src`: The directory where all the source code goes.
82+
* `build`: This directory contains all of the build output.
83+
* `lib`: The directory where any libraries distributed with the package go.
84+
* `bin`: This directory holds any binaries distributed with the package.
85+
86+
There are also default file names you'll want to follow as well:
87+
88+
* `main.rs`: A file that's going to become an executable.
89+
* `lib.rs`: A file that's going to become a library.
90+
91+
## Building your own Package
92+
93+
Now that you've got workspaces down, let's build your own copy of `hello`. Go
94+
to wherever you keep your personal projects, and let's make all of the
95+
directories we'll need. I'll refer to this personal project directory as
96+
`~/src` for the rest of this tutorial.
97+
98+
### Creating our workspace
99+
100+
~~~ {.notrust}
101+
$ cd ~/src
102+
$ mkdir -p hello/src/hello
103+
$ cd hello
104+
~~~
105+
106+
Easy enough! Let's do one or two more things that are nice to do:
107+
108+
~~~ {.notrust}
109+
$ git init .
110+
$ cat > README.md
111+
# hello
112+
113+
A simple package for Rust.
114+
115+
## Installation
116+
117+
```
118+
$ rustpkg install github.com/YOUR_USERNAME/hello
119+
```
120+
^D
121+
$ cat > .gitignore
122+
.rust
123+
build
124+
^D
125+
$ git commit -am "Initial commit."
126+
~~~
127+
128+
If you're not familliar with the `cat >` idiom, it will make files with the
129+
text you type inside. Control-D (`^D`) ends the text for the file.
130+
131+
Anyway, we've got a README and a `.gitignore`. Let's talk about that
132+
`.gitignore` for a minute: we are ignoring two directories, `build` and
133+
`.rust`. `build`, as we discussed earlier, is for build artifacts, and we don't
134+
want to check those into a repository. `.rust` is a directory that `rustpkg`
135+
uses to keep track of its own settings, as well as the source code of any other
136+
external packages that this workspace uses. This is where that `rustpkg
137+
install` puts all of its files. Those are also not to go into our repository,
138+
so we ignore it all as well.
139+
140+
Next, let's add a source file:
141+
142+
~~~
143+
#[desc = "A hello world Rust package."];
144+
#[license = "MIT"];
145+
146+
pub fn world() {
147+
println("Hello, world.");
148+
}
149+
~~~
150+
151+
Put this into `src/hello/lib.rs`. Let's talk about each of these attributes:
152+
153+
### Crate attributes for packages
154+
155+
`license` is equally simple: the license we want this code to have. I chose MIT
156+
here, but you should pick whatever license makes the most sense for you.
157+
158+
`desc` is a description of the package and what it does. This should just be a
159+
sentence or two.
160+
161+
### Building your package
162+
163+
Building your package is simple:
164+
165+
~~~ {.notrust}
166+
$ rustpkg build hello
167+
~~~
168+
169+
This will compile `src/hello/lib.rs` into a library. After this process
170+
completes, you'll want to check out `build`:
171+
172+
~~~ {.notrust}
173+
$ ls build/x86_64-unknown-linux-gnu/hello/
174+
libhello-ed8619dad9ce7d58-0.1.0.so
175+
~~~
176+
177+
This directory naming structure is called a 'build triple,' and is because I'm
178+
on 64 bit Linux. Yours may differ based on platform.
179+
180+
You'll also notice that `src/hello/lib.rs` turned into
181+
`libhello-ed8619dad9ce7d58-0.1.0.so`. This is a simple combination of the
182+
library name, a hash of its content, and the version.
183+
184+
Now that your library builds, you'll want to commit:
185+
186+
~~~ {.notrust}
187+
$ git add src
188+
$ git commit -m "Adding source code."
189+
~~~
190+
191+
If you're using GitHub, after creating the project, do this:
192+
193+
~~~ {.notrust}
194+
$ git remote add origin [email protected]:YOUR_USERNAME/hello.git
195+
$ git push origin -u master
196+
~~~
197+
198+
Now you can install and use it! Go anywhere else in your filesystem:
199+
200+
~~~ {.notrust}
201+
$ cd ~/src/foo
202+
$ rustpkg install github/YOUR_USERNAME/hello
203+
WARNING: The Rust package manager is experimental and may be unstable
204+
note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/yourusername/src/hello/.rust
205+
~~~
206+
207+
That's it!
208+
209+
## More resources
210+
211+
There's a lot more going on with `rustpkg`, this is just to get you started.
212+
Check out [the rustpkg manual](rustpkg.html) for the full details on how to
213+
customize `rustpkg`.
214+
215+
A tag was created on GitHub specifically for `rustpkg`-related issues. You can
216+
[see all the Issues for rustpkg
217+
here](https://github.com/mozilla/rust/issues?direction=desc&labels=A-pkg&sort=created&state=open),
218+
with bugs as well as new feature plans. `rustpkg` is still under development,
219+
and so may be a bit flaky at the moment.
220+
221+
You may also want to check out [this blog
222+
post](http://tim.dreamwidth.org/1820526.html), which contains some of the early
223+
design decisions and justifications.

branches/try2/doc/tutorial-tasks.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ concurrency at this writing:
4747

4848
* [`std::task`] - All code relating to tasks and task scheduling,
4949
* [`std::comm`] - The message passing interface,
50-
* [`std::pipes`] - The underlying messaging infrastructure,
51-
* [`extra::comm`] - Additional messaging types based on `std::pipes`,
50+
* [`extra::comm`] - Additional messaging types based on `std::comm`,
5251
* [`extra::sync`] - More exotic synchronization tools, including locks,
5352
* [`extra::arc`] - The Arc (atomically reference counted) type,
5453
for safely sharing immutable data,
5554
* [`extra::future`] - A type representing values that may be computed concurrently and retrieved at a later time.
5655

5756
[`std::task`]: std/task.html
5857
[`std::comm`]: std/comm.html
59-
[`std::pipes`]: std/pipes.html
6058
[`extra::comm`]: extra/comm.html
6159
[`extra::sync`]: extra/sync.html
6260
[`extra::arc`]: extra/arc.html
@@ -125,7 +123,7 @@ receiving messages. Pipes are low-level communication building-blocks and so
125123
come in a variety of forms, each one appropriate for a different use case. In
126124
what follows, we cover the most commonly used varieties.
127125

128-
The simplest way to create a pipe is to use the `pipes::stream`
126+
The simplest way to create a pipe is to use the `comm::stream`
129127
function to create a `(Port, Chan)` pair. In Rust parlance, a *channel*
130128
is a sending endpoint of a pipe, and a *port* is the receiving
131129
endpoint. Consider the following example of calculating two results

0 commit comments

Comments
 (0)