Skip to content

Commit 01f05e4

Browse files
committed
---
yaml --- r: 55294 b: refs/heads/master c: 21de574 h: refs/heads/master v: v3
1 parent 73440c7 commit 01f05e4

File tree

6 files changed

+77
-55
lines changed

6 files changed

+77
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 679b1dcb62b53f52f6e4ffe18cc89be8dbf5cc15
2+
refs/heads/master: 21de574625b5bb87126045da32d49ccee74a9060
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

trunk/doc/rust.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,28 @@ of runtime logging modules follows.
32513251
* `::rt::backtrace` Log a backtrace on task failure
32523252
* `::rt::callback` Unused
32533253

3254+
#### Logging Expressions
3255+
3256+
Rust provides several macros to log information. Here's a simple Rust program
3257+
that demonstrates all four of them:
3258+
3259+
```rust
3260+
fn main() {
3261+
error!("This is an error log")
3262+
warn!("This is a warn log")
3263+
info!("this is an info log")
3264+
debug!("This is a debug log")
3265+
}
3266+
```
3267+
3268+
These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`:
3269+
3270+
```bash
3271+
$ RUST_LOG=rust=3 ./rust
3272+
rust: ~"\"This is an error log\""
3273+
rust: ~"\"This is a warn log\""
3274+
rust: ~"\"this is an info log\""
3275+
```
32543276

32553277
# Appendix: Rationales and design tradeoffs
32563278

trunk/doc/tutorial-tasks.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,74 @@
22

33
# Introduction
44

5-
Rust provides safe concurrency through a combination
6-
of lightweight, memory-isolated tasks and message passing.
7-
This tutorial will describe the concurrency model in Rust, how it
8-
relates to the Rust type system, and introduce
9-
the fundamental library abstractions for constructing concurrent programs.
10-
11-
Rust tasks are not the same as traditional threads: rather,
12-
they are considered _green threads_, lightweight units of execution that the Rust
13-
runtime schedules cooperatively onto a small number of operating system threads.
14-
On a multi-core system Rust tasks will be scheduled in parallel by default.
15-
Because tasks are significantly
5+
The designers of Rust designed the language from the ground up to support pervasive
6+
and safe concurrency through lightweight, memory-isolated tasks and
7+
message passing.
8+
9+
Rust tasks are not the same as traditional threads: rather, they are more like
10+
_green threads_. The Rust runtime system schedules tasks cooperatively onto a
11+
small number of operating system threads. Because tasks are significantly
1612
cheaper to create than traditional threads, Rust can create hundreds of
1713
thousands of concurrent tasks on a typical 32-bit system.
18-
In general, all Rust code executes inside a task, including the `main` function.
19-
20-
In order to make efficient use of memory Rust tasks have dynamically sized stacks.
21-
A task begins its life with a small
22-
amount of stack space (currently in the low thousands of bytes, depending on
23-
platform), and acquires more stack as needed.
24-
Unlike in languages such as C, a Rust task cannot accidentally write to
25-
memory beyond the end of the stack, causing crashes or worse.
2614

27-
Tasks provide failure isolation and recovery. When a fatal error occurs in Rust
28-
code as a result of an explicit call to `fail!()`, an assertion failure, or
29-
another invalid operation, the runtime system destroys the entire
15+
Tasks provide failure isolation and recovery. When an exception occurs in Rust
16+
code (as a result of an explicit call to `fail!()`, an assertion failure, or
17+
another invalid operation), the runtime system destroys the entire
3018
task. Unlike in languages such as Java and C++, there is no way to `catch` an
3119
exception. Instead, tasks may monitor each other for failure.
3220

21+
Rust tasks have dynamically sized stacks. A task begins its life with a small
22+
amount of stack space (currently in the low thousands of bytes, depending on
23+
platform), and acquires more stack as needed. Unlike in languages such as C, a
24+
Rust task cannot run off the end of the stack. However, tasks do have a stack
25+
budget. If a Rust task exceeds its stack budget, then it will fail safely:
26+
with a checked exception.
27+
3328
Tasks use Rust's type system to provide strong memory safety guarantees. In
3429
particular, the type system guarantees that tasks cannot share mutable state
3530
with each other. Tasks communicate with each other by transferring _owned_
3631
data through the global _exchange heap_.
3732

33+
This tutorial explains the basics of tasks and communication in Rust,
34+
explores some typical patterns in concurrent Rust code, and finally
35+
discusses some of the more unusual synchronization types in the standard
36+
library.
37+
38+
> ***Warning:*** This tutorial is incomplete
39+
3840
## A note about the libraries
3941

4042
While Rust's type system provides the building blocks needed for safe
4143
and efficient tasks, all of the task functionality itself is implemented
4244
in the core and standard libraries, which are still under development
43-
and do not always present a consistent or complete interface.
45+
and do not always present a consistent interface.
46+
47+
In particular, there are currently two independent modules that provide a
48+
message passing interface to Rust code: `core::comm` and `core::pipes`.
49+
`core::comm` is an older, less efficient system that is being phased out in
50+
favor of `pipes`. At some point, we will remove the existing `core::comm` API
51+
and move the user-facing portions of `core::pipes` to `core::comm`. In this
52+
tutorial, we discuss `pipes` and ignore the `comm` API.
4453

4554
For your reference, these are the standard modules involved in Rust
4655
concurrency at this writing.
4756

4857
* [`core::task`] - All code relating to tasks and task scheduling
49-
* [`core::comm`] - The message passing interface
50-
* [`core::pipes`] - The underlying messaging infrastructure
51-
* [`std::comm`] - Additional messaging types based on `core::pipes`
58+
* [`core::comm`] - The deprecated message passing API
59+
* [`core::pipes`] - The new message passing infrastructure and API
60+
* [`std::comm`] - Higher level messaging types based on `core::pipes`
5261
* [`std::sync`] - More exotic synchronization tools, including locks
53-
* [`std::arc`] - The ARC (atomically reference counted) type,
54-
for safely sharing immutable data
62+
* [`std::arc`] - The ARC (atomic reference counted) type, for safely sharing
63+
immutable data
64+
* [`std::par`] - Some basic tools for implementing parallel algorithms
5565

5666
[`core::task`]: core/task.html
5767
[`core::comm`]: core/comm.html
5868
[`core::pipes`]: core/pipes.html
5969
[`std::comm`]: std/comm.html
6070
[`std::sync`]: std/sync.html
6171
[`std::arc`]: std/arc.html
72+
[`std::par`]: std/par.html
6273

6374
# Basics
6475

trunk/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ custom destructors.
988988

989989
# Boxes
990990

991-
Many modern languages represent values as as pointers to heap memory by
991+
Many modern languages represent values as pointers to heap memory by
992992
default. In contrast, Rust, like C and C++, represents such types directly.
993993
Another way to say this is that aggregate data in Rust are *unboxed*. This
994994
means that if you `let x = Point { x: 1f, y: 1f };`, you are creating a struct

trunk/src/librustc/middle/trans/base.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,17 +2243,17 @@ pub fn create_main_wrapper(ccx: @CrateContext,
22432243
}
22442244
22452245
fn create_entry_fn(ccx: @CrateContext, rust_main: ValueRef) {
2246-
#[cfg(windows)]
2247-
fn main_name() -> ~str { return ~"WinMain@16"; }
2248-
#[cfg(unix)]
2249-
fn main_name() -> ~str { return ~"main"; }
22502246
let llfty = T_fn(~[ccx.int_type, T_ptr(T_ptr(T_i8()))], ccx.int_type);
22512247
22522248
// FIXME #4404 android JNI hacks
22532249
let llfn = if *ccx.sess.building_library {
22542250
decl_cdecl_fn(ccx.llmod, ~"amain", llfty)
22552251
} else {
2256-
decl_cdecl_fn(ccx.llmod, main_name(), llfty)
2252+
let main_name = match ccx.sess.targ_cfg.os {
2253+
session::os_win32 => ~"WinMain@16",
2254+
_ => ~"main",
2255+
};
2256+
decl_cdecl_fn(ccx.llmod, main_name, llfty)
22572257
};
22582258
let llbb = str::as_c_str(~"top", |buf| {
22592259
unsafe {
@@ -2284,25 +2284,14 @@ pub fn create_main_wrapper(ccx: @CrateContext,
22842284
let opaque_crate_map = llvm::LLVMBuildPointerCast(
22852285
bld, crate_map, T_ptr(T_i8()), noname());
22862286
2287-
if *ccx.sess.building_library {
2288-
~[
2289-
retptr,
2290-
C_null(T_opaque_box_ptr(ccx)),
2291-
opaque_rust_main,
2292-
llvm::LLVMConstInt(T_i32(), 0u as c_ulonglong, False),
2293-
llvm::LLVMConstInt(T_i32(), 0u as c_ulonglong, False),
2294-
opaque_crate_map
2295-
]
2296-
} else {
2297-
~[
2298-
retptr,
2299-
C_null(T_opaque_box_ptr(ccx)),
2300-
opaque_rust_main,
2301-
llvm::LLVMGetParam(llfn, 0 as c_uint),
2302-
llvm::LLVMGetParam(llfn, 1 as c_uint),
2303-
opaque_crate_map
2304-
]
2305-
}
2287+
~[
2288+
retptr,
2289+
C_null(T_opaque_box_ptr(ccx)),
2290+
opaque_rust_main,
2291+
llvm::LLVMGetParam(llfn, 0 as c_uint),
2292+
llvm::LLVMGetParam(llfn, 1 as c_uint),
2293+
opaque_crate_map
2294+
]
23062295
};
23072296
23082297
unsafe {

trunk/src/libstd/fileinput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ mod test {
534534
fn test_empty_files() {
535535
let filenames = pathify(vec::from_fn(
536536
3,
537-
|i| fmt!("tmp/lib-fileinput-test-next-file-%u.tmp", i)),true);
537+
|i| fmt!("tmp/lib-fileinput-test-empty-files-%u.tmp", i)),true);
538538

539539
make_file(filenames[0].get_ref(), ~[~"1", ~"2"]);
540540
make_file(filenames[1].get_ref(), ~[]);

0 commit comments

Comments
 (0)