Skip to content

Commit 721f342

Browse files
committed
---
yaml --- r: 71954 b: refs/heads/dist-snap c: 74fee15 h: refs/heads/master v: v3
1 parent c6ff9de commit 721f342

Some content is hidden

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

104 files changed

+3316
-2523
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: 2ec2d99bbd1a15a8f278b3cb82ddfa9ebafa96b3
10+
refs/heads/dist-snap: 74fee15bc1b6c3c558bab72a644b2600c91d0d2d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/rust.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ expression context, the final namespace qualifier is omitted.
441441
Two examples of paths with type arguments:
442442

443443
~~~~
444-
# use core::hashmap::linear::LinearMap;
444+
# use core::hashmap::HashMap;
445445
# fn f() {
446446
# fn id<T:Copy>(t: T) -> T { t }
447-
type t = LinearMap<int,~str>; // Type arguments used in a type expression
447+
type t = HashMap<int,~str>; // Type arguments used in a type expression
448448
let x = id::<int>(10); // Type arguments used in a call expression
449449
# }
450450
~~~~
@@ -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

branches/dist-snap/doc/tutorial-tasks.md

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

33
# Introduction
44

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
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
1216
cheaper to create than traditional threads, Rust can create hundreds of
1317
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.
1426

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
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
1830
task. Unlike in languages such as Java and C++, there is no way to `catch` an
1931
exception. Instead, tasks may monitor each other for failure.
2032

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-
2833
Tasks use Rust's type system to provide strong memory safety guarantees. In
2934
particular, the type system guarantees that tasks cannot share mutable state
3035
with each other. Tasks communicate with each other by transferring _owned_
3136
data through the global _exchange heap_.
3237

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-
4038
## A note about the libraries
4139

4240
While Rust's type system provides the building blocks needed for safe
4341
and efficient tasks, all of the task functionality itself is implemented
4442
in the core and standard libraries, which are still under development
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.
43+
and do not always present a consistent or complete interface.
5344

5445
For your reference, these are the standard modules involved in Rust
5546
concurrency at this writing.
5647

5748
* [`core::task`] - All code relating to tasks and task scheduling
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`
49+
* [`core::comm`] - The message passing interface
50+
* [`core::pipes`] - The underlying messaging infrastructure
51+
* [`std::comm`] - Additional messaging types based on `core::pipes`
6152
* [`std::sync`] - More exotic synchronization tools, including locks
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
53+
* [`std::arc`] - The ARC (atomically reference counted) type,
54+
for safely sharing immutable data
6555

6656
[`core::task`]: core/task.html
6757
[`core::comm`]: core/comm.html
6858
[`core::pipes`]: core/pipes.html
6959
[`std::comm`]: std/comm.html
7060
[`std::sync`]: std/sync.html
7161
[`std::arc`]: std/arc.html
72-
[`std::par`]: std/par.html
7362

7463
# Basics
7564

branches/dist-snap/doc/tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ omitted.
495495

496496
A powerful application of pattern matching is *destructuring*:
497497
matching in order to bind names to the contents of data
498-
types. Remember that `(float, float)` is a tuple of two floats:
498+
types. Assuming that `(float, float)` is a tuple of two floats:
499499

500500
~~~~
501501
fn angle(vector: (float, float)) -> float {
@@ -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
@@ -1191,7 +1191,7 @@ they are frozen:
11911191
let x = @mut 5;
11921192
let y = x;
11931193
{
1194-
let y = &*y; // the managed box is now frozen
1194+
let z = &*y; // the managed box is now frozen
11951195
// modifying it through x or y will cause a task failure
11961196
}
11971197
// the box is now unfrozen again
@@ -1888,8 +1888,8 @@ illegal to copy and pass by value.
18881888
Generic `type`, `struct`, and `enum` declarations follow the same pattern:
18891889

18901890
~~~~
1891-
# use core::hashmap::linear::LinearMap;
1892-
type Set<T> = LinearMap<T, ()>;
1891+
# use core::hashmap::HashMap;
1892+
type Set<T> = HashMap<T, ()>;
18931893
18941894
struct Stack<T> {
18951895
elements: ~[T]

branches/dist-snap/mk/install.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_TRIPLE)_H_$(CFG_BUILD_TRIPLE))
119119
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBSYNTAX_GLOB_$(CFG_BUILD_TRIPLE)))
120120
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTI_GLOB_$(CFG_BUILD_TRIPLE)))
121121
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUST_GLOB_$(CFG_BUILD_TRIPLE)))
122+
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTPKG_GLOB_$(CFG_BUILD_TRIPLE)))
123+
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(LIBRUSTDOC_GLOB_$(CFG_BUILD_TRIPLE)))
122124
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE)))
123125
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE)))
124126
$(Q)$(call INSTALL,$(S)/man, \

branches/dist-snap/mk/platform.mk

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ CFG_RUN_arm-linux-androideabi=
239239
CFG_RUN_TARG_arm-linux-androideabi=
240240
RUSTC_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
241241

242+
# mips-unknown-linux-gnu configuration
243+
CC_mips-unknown-linux-gnu=mips-linux-gnu-gcc
244+
CXX_mips-unknown-linux-gnu=mips-linux-gnu-g++
245+
CPP_mips-unknown-linux-gnu=mips-linux-gnu-gcc -E
246+
AR_mips-unknown-linux-gnu=mips-linux-gnu-ar
247+
CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
248+
CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
249+
CFG_LIB_DSYM_GLOB_mips-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
250+
CFG_GCCISH_CFLAGS_mips-unknown-linux-gnu := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32
251+
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-gnu := -fno-rtti
252+
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-gnu := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32
253+
CFG_GCCISH_DEF_FLAG_mips-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
254+
CFG_GCCISH_PRE_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-whole-archive
255+
CFG_GCCISH_POST_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-no-whole-archive -Wl,-znoexecstack
256+
CFG_DEF_SUFFIX_mips-unknown-linux-gnu := .linux.def
257+
CFG_INSTALL_NAME_mips-unknown-linux-gnu =
258+
CFG_LIBUV_LINK_FLAGS_mips-unknown-linux-gnu =
259+
CFG_EXE_SUFFIX_mips-unknown-linux-gnu :=
260+
CFG_WINDOWSY_mips-unknown-linux-gnu :=
261+
CFG_UNIXY_mips-unknown-linux-gnu := 1
262+
CFG_PATH_MUNGE_mips-unknown-linux-gnu := true
263+
CFG_LDPATH_mips-unknown-linux-gnu :=
264+
CFG_RUN_mips-unknown-linux-gnu=
265+
CFG_RUN_TARG_mips-unknown-linux-gnu=
266+
242267
# i686-pc-mingw32 configuration
243268
CC_i686-pc-mingw32=$(CC)
244269
CXX_i686-pc-mingw32=$(CXX)

branches/dist-snap/mk/rt.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
LIBUV_FLAGS_i386 = -m32 -fPIC
2828
LIBUV_FLAGS_x86_64 = -m64 -fPIC
2929
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
30+
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
3031

3132
# when we're doing a snapshot build, we intentionally degrade as many
3233
# features in libuv and the runtime as possible, to ease portability.
@@ -180,6 +181,10 @@ else
180181
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
181182
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
182183
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
184+
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
185+
CC="$$(CC_$(1))" \
186+
CXX="$$(CXX_$(1))" \
187+
AR="$$(AR_$(1))" \
183188
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
184189
V=$$(VERBOSE)
185190
endif

branches/dist-snap/src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
2626

2727
// Make sure we include the aux directory in the path
2828
assert!(prog.ends_with(~".exe"));
29-
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";
29+
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ~".libaux";
3030
3131
env = do vec::map(env) |pair| {
3232
let (k,v) = *pair;

branches/dist-snap/src/libcore/at_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub mod raw {
208208
*/
209209
#[inline(always)]
210210
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
211-
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
211+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
212212
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
213213
}
214214

@@ -226,7 +226,7 @@ pub mod raw {
226226

227227
#[inline(always)] // really pretty please
228228
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
229-
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
229+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&v);
230230
let fill = (**repr).unboxed.fill;
231231
(**repr).unboxed.fill += sys::size_of::<T>();
232232
let p = addr_of(&((**repr).unboxed.data));

branches/dist-snap/src/libcore/cell.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! A mutable, nullable memory location
1212
13-
use cast::transmute;
13+
use cast::transmute_mut;
1414
use prelude::*;
1515

1616
/*
@@ -20,16 +20,12 @@ Similar to a mutable option type, but friendlier.
2020
*/
2121

2222
pub struct Cell<T> {
23-
mut value: Option<T>
23+
value: Option<T>
2424
}
2525

2626
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
2727
fn eq(&self, other: &Cell<T>) -> bool {
28-
unsafe {
29-
let frozen_self: &Option<T> = transmute(&mut self.value);
30-
let frozen_other: &Option<T> = transmute(&mut other.value);
31-
frozen_self == frozen_other
32-
}
28+
(self.value) == (other.value)
3329
}
3430
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
3531
}
@@ -46,6 +42,7 @@ pub fn empty_cell<T>() -> Cell<T> {
4642
pub impl<T> Cell<T> {
4743
/// Yields the value, failing if the cell is empty.
4844
fn take(&self) -> T {
45+
let mut self = unsafe { transmute_mut(self) };
4946
if self.is_empty() {
5047
fail!(~"attempt to take an empty cell");
5148
}
@@ -57,6 +54,7 @@ pub impl<T> Cell<T> {
5754
5855
/// Returns the value, failing if the cell is full.
5956
fn put_back(&self, value: T) {
57+
let mut self = unsafe { transmute_mut(self) };
6058
if !self.is_empty() {
6159
fail!(~"attempt to put a value back into a full cell");
6260
}
@@ -75,6 +73,14 @@ pub impl<T> Cell<T> {
7573
self.put_back(v);
7674
r
7775
}
76+
77+
// Calls a closure with a mutable reference to the value.
78+
fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
79+
let mut v = self.take();
80+
let r = op(&mut v);
81+
self.put_back(v);
82+
r
83+
}
7884
}
7985

8086
#[test]
@@ -103,3 +109,21 @@ fn test_put_back_non_empty() {
103109
let value_cell = Cell(~10);
104110
value_cell.put_back(~20);
105111
}
112+
113+
#[test]
114+
fn test_with_ref() {
115+
let good = 6;
116+
let c = Cell(~[1, 2, 3, 4, 5, 6]);
117+
let l = do c.with_ref() |v| { v.len() };
118+
assert!(l == good);
119+
}
120+
121+
#[test]
122+
fn test_with_mut_ref() {
123+
let good = ~[1, 2, 3];
124+
let mut v = ~[1, 2];
125+
let c = Cell(v);
126+
do c.with_mut_ref() |v| { v.push(3); }
127+
let v = c.take();
128+
assert!(v == good);
129+
}

branches/dist-snap/src/libcore/gc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use io;
4343
use libc::{size_t, uintptr_t};
4444
use option::{None, Option, Some};
4545
use ptr;
46-
use hashmap::linear::LinearSet;
46+
use hashmap::HashSet;
4747
use stackwalk;
4848
use sys;
4949

@@ -344,7 +344,7 @@ pub fn cleanup_stack_for_failure() {
344344
ptr::null()
345345
};
346346

347-
let mut roots = LinearSet::new();
347+
let mut roots = HashSet::new();
348348
for walk_gc_roots(need_cleanup, sentinel) |root, tydesc| {
349349
// Track roots to avoid double frees.
350350
if roots.contains(&*root) {

0 commit comments

Comments
 (0)