Skip to content

Commit b12d357

Browse files
committed
---
yaml --- r: 144096 b: refs/heads/try2 c: d597f54 h: refs/heads/master v: v3
1 parent 988254e commit b12d357

File tree

683 files changed

+8994
-4211
lines changed

Some content is hidden

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

683 files changed

+8994
-4211
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: 6c15f21bd76d0658866d2db431c4bb4bc6b2932e
8+
refs/heads/try2: d597f54fc2b864bcdf110fecb120758dc2feb5f6
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/po/tutorial-container.md.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ msgstr ""
481481
#, no-wrap
482482
msgid ""
483483
"~~~\n"
484-
"impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {\n"
485-
" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n"
484+
"impl<A> FromIterator<A> for ~[A] {\n"
485+
" pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {\n"
486486
" let (lower, _) = iterator.size_hint();\n"
487487
" let mut xs = with_capacity(lower);\n"
488488
" for x in iterator {\n"

branches/try2/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ a referencing source file, or by the name of the crate itself.
582582

583583
Each source file contains a sequence of zero or more `item` definitions,
584584
and may optionally begin with any number of `attributes` that apply to the containing module.
585-
Atributes on the anonymous crate module define important metadata that influences
585+
Attributes on the anonymous crate module define important metadata that influences
586586
the behavior of the compiler.
587587

588588
~~~~~~~~
@@ -1273,7 +1273,7 @@ since the typechecker checks that any type with an implementation of `Circle` al
12731273

12741274
In type-parameterized functions,
12751275
methods of the supertrait may be called on values of subtrait-bound type parameters.
1276-
Refering to the previous example of `trait Circle : Shape`:
1276+
Referring to the previous example of `trait Circle : Shape`:
12771277

12781278
~~~
12791279
# trait Shape { fn area(&self) -> float; }
@@ -1914,7 +1914,7 @@ A field access on a record is an [lvalue](#lvalues-rvalues-and-temporaries) refe
19141914
When the field is mutable, it can be [assigned](#assignment-expressions) to.
19151915

19161916
When the type of the expression to the left of the dot is a pointer to a record or structure,
1917-
it is automatically derferenced to make the field access possible.
1917+
it is automatically dereferenced to make the field access possible.
19181918

19191919

19201920
### Vector expressions

branches/try2/doc/tutorial-container.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ iterator object. For example, vector slices several iterators available:
112112
113113
* `iter()` and `rev_iter()`, for immutable references to the elements
114114
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
115-
* `consume_iter()` and `consume_rev_iter`, to move the elements out by-value
115+
* `move_iter()` and `move_rev_iter`, to move the elements out by-value
116116
117117
A typical mutable container will implement at least `iter()`, `mut_iter()` and
118-
`consume_iter()` along with the reverse variants if it maintains an order.
118+
`move_iter()` along with the reverse variants if it maintains an order.
119119
120120
### Freezing
121121
@@ -139,9 +139,9 @@ and `&mut`.
139139
140140
## Iterator adaptors
141141
142-
The `IteratorUtil` trait implements common algorithms as methods extending
143-
every `Iterator` implementation. For example, the `fold` method will accumulate
144-
the items yielded by an `Iterator` into a single value:
142+
The `Iterator` trait provides many common algorithms as default methods. For
143+
example, the `fold` method will accumulate the items yielded by an `Iterator`
144+
into a single value:
145145
146146
~~~
147147
let xs = [1, 9, 2, 3, 14, 12];
@@ -154,14 +154,10 @@ Some adaptors return an adaptor object implementing the `Iterator` trait itself:
154154
~~~
155155
let xs = [1, 9, 2, 3, 14, 12];
156156
let ys = [5, 2, 1, 8];
157-
let sum = xs.iter().chain_(ys.iter()).fold(0, |a, b| a + *b);
157+
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
158158
assert_eq!(sum, 57);
159159
~~~
160160
161-
Note that some adaptors like the `chain_` method above use a trailing
162-
underscore to work around an issue with method resolve. The underscores will be
163-
dropped when they become unnecessary.
164-
165161
## For loops
166162
167163
The `for` keyword can be used as sugar for iterating through any iterator:
@@ -212,7 +208,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
212208
213209
~~~
214210
let xs = [0, 1, 1, 2, 3, 5, 8];
215-
let ys = xs.rev_iter().skip(1).transform(|&x| x * 2).collect::<~[int]>();
211+
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
216212
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
217213
~~~
218214
@@ -224,8 +220,8 @@ implementing the `FromIterator` trait. For example, the implementation for
224220
vectors is as follows:
225221
226222
~~~
227-
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
228-
pub fn from_iterator(iterator: &mut T) -> ~[A] {
223+
impl<A> FromIterator<A> for ~[A] {
224+
pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
229225
let (lower, _) = iterator.size_hint();
230226
let mut xs = with_capacity(lower);
231227
for x in iterator {
@@ -307,13 +303,13 @@ for &x in it.invert() {
307303
The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted
308304
version of the standard immutable and mutable vector iterators.
309305
310-
The `chain_`, `transform`, `filter`, `filter_map` and `peek` adaptors are
306+
The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
311307
`DoubleEndedIterator` implementations if the underlying iterators are.
312308
313309
~~~
314310
let xs = [1, 2, 3, 4];
315311
let ys = [5, 6, 7, 8];
316-
let mut it = xs.iter().chain_(ys.iter()).transform(|&x| x * 2);
312+
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
317313

318314
printfln!("%?", it.next()); // prints `Some(2)`
319315

@@ -329,13 +325,13 @@ The `RandomAccessIterator` trait represents an iterator offering random access
329325
to the whole range. The `indexable` method retrieves the number of elements
330326
accessible with the `idx` method.
331327
332-
The `chain_` adaptor is an implementation of `RandomAccessIterator` if the
328+
The `chain` adaptor is an implementation of `RandomAccessIterator` if the
333329
underlying iterators are.
334330
335331
~~~
336332
let xs = [1, 2, 3, 4, 5];
337333
let ys = ~[7, 9, 11];
338-
let mut it = xs.iter().chain_(ys.iter());
334+
let mut it = xs.iter().chain(ys.iter());
339335
printfln!("%?", it.idx(0)); // prints `Some(&1)`
340336
printfln!("%?", it.idx(5)); // prints `Some(&7)`
341337
printfln!("%?", it.idx(7)); // prints `Some(&11)`

branches/try2/doc/tutorial-ffi.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern {
1919
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
2020
}
2121
22+
#[fixed_stack_segment]
2223
fn main() {
2324
let x = unsafe { snappy_max_compressed_length(100) };
2425
println(fmt!("max compressed length of a 100 byte buffer: %?", x));
@@ -35,6 +36,11 @@ interfaces that aren't thread-safe, and almost any function that takes a pointer
3536
valid for all possible inputs since the pointer could be dangling, and raw pointers fall outside of
3637
Rust's safe memory model.
3738

39+
Finally, the `#[fixed_stack_segment]` annotation that appears on
40+
`main()` instructs the Rust compiler that when `main()` executes, it
41+
should request a "very large" stack segment. More details on
42+
stack management can be found in the following sections.
43+
3844
When declaring the argument types to a foreign function, the Rust compiler will not check if the
3945
declaration is correct, so specifying it correctly is part of keeping the binding correct at
4046
runtime.
@@ -75,6 +81,8 @@ length is number of elements currently contained, and the capacity is the total
7581
the allocated memory. The length is less than or equal to the capacity.
7682

7783
~~~~ {.xfail-test}
84+
#[fixed_stack_segment]
85+
#[inline(never)]
7886
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
7987
unsafe {
8088
snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0
@@ -86,6 +94,36 @@ The `validate_compressed_buffer` wrapper above makes use of an `unsafe` block, b
8694
guarantee that calling it is safe for all inputs by leaving off `unsafe` from the function
8795
signature.
8896

97+
The `validate_compressed_buffer` wrapper is also annotated with two
98+
attributes `#[fixed_stack_segment]` and `#[inline(never)]`. The
99+
purpose of these attributes is to guarantee that there will be
100+
sufficient stack for the C function to execute. This is necessary
101+
because Rust, unlike C, does not assume that the stack is allocated in
102+
one continuous chunk. Instead, we rely on a *segmented stack* scheme,
103+
in which the stack grows and shrinks as necessary. C code, however,
104+
expects one large stack, and so callers of C functions must request a
105+
large stack segment to ensure that the C routine will not run off the
106+
end of the stack.
107+
108+
The compiler includes a lint mode that will report an error if you
109+
call a C function without a `#[fixed_stack_segment]` attribute. More
110+
details on the lint mode are given in a later section.
111+
112+
You may be wondering why we include a `#[inline(never)]` directive.
113+
This directive informs the compiler never to inline this function.
114+
While not strictly necessary, it is usually a good idea to use an
115+
`#[inline(never)]` directive in concert with `#[fixed_stack_segment]`.
116+
The reason is that if a fn annotated with `fixed_stack_segment` is
117+
inlined, then its caller also inherits the `fixed_stack_segment`
118+
annotation. This means that rather than requesting a large stack
119+
segment only for the duration of the call into C, the large stack
120+
segment would be used for the entire duration of the caller. This is
121+
not necessarily *bad* -- it can for example be more efficient,
122+
particularly if `validate_compressed_buffer()` is called multiple
123+
times in a row -- but it does work against the purpose of the
124+
segmented stack scheme, which is to keep stacks small and thus
125+
conserve address space.
126+
89127
The `snappy_compress` and `snappy_uncompress` functions are more complex, since a buffer has to be
90128
allocated to hold the output too.
91129

@@ -96,6 +134,8 @@ the true length after compression for setting the length.
96134

97135
~~~~ {.xfail-test}
98136
pub fn compress(src: &[u8]) -> ~[u8] {
137+
#[fixed_stack_segment]; #[inline(never)];
138+
99139
unsafe {
100140
let srclen = src.len() as size_t;
101141
let psrc = vec::raw::to_ptr(src);
@@ -116,6 +156,8 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
116156

117157
~~~~ {.xfail-test}
118158
pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
159+
#[fixed_stack_segment]; #[inline(never)];
160+
119161
unsafe {
120162
let srclen = src.len() as size_t;
121163
let psrc = vec::raw::to_ptr(src);
@@ -139,6 +181,99 @@ pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
139181
For reference, the examples used here are also available as an [library on
140182
GitHub](https://github.com/thestinger/rust-snappy).
141183

184+
# Automatic wrappers
185+
186+
Sometimes writing Rust wrappers can be quite tedious. For example, if
187+
function does not take any pointer arguments, often there is no need
188+
for translating types. In such cases, it is usually still a good idea
189+
to have a Rust wrapper so as to manage the segmented stacks, but you
190+
can take advantage of the (standard) `externfn!` macro to remove some
191+
of the tedium.
192+
193+
In the initial section, we showed an extern block that added a call
194+
to a specific snappy API:
195+
196+
~~~~ {.xfail-test}
197+
use std::libc::size_t;
198+
199+
#[link_args = "-lsnappy"]
200+
extern {
201+
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
202+
}
203+
204+
#[fixed_stack_segment]
205+
fn main() {
206+
let x = unsafe { snappy_max_compressed_length(100) };
207+
println(fmt!("max compressed length of a 100 byte buffer: %?", x));
208+
}
209+
~~~~
210+
211+
To avoid the need to create a wrapper fn for `snappy_max_compressed_length()`,
212+
and also to avoid the need to think about `#[fixed_stack_segment]`, we
213+
could simply use the `externfn!` macro instead, as shown here:
214+
215+
~~~~ {.xfail-test}
216+
use std::libc::size_t;
217+
218+
externfn!(#[link_args = "-lsnappy"]
219+
fn snappy_max_compressed_length(source_length: size_t) -> size_t)
220+
221+
fn main() {
222+
let x = unsafe { snappy_max_compressed_length(100) };
223+
println(fmt!("max compressed length of a 100 byte buffer: %?", x));
224+
}
225+
~~~~
226+
227+
As you can see from the example, `externfn!` replaces the extern block
228+
entirely. After macro expansion, it will create something like this:
229+
230+
~~~~ {.xfail-test}
231+
use std::libc::size_t;
232+
233+
// Automatically generated by
234+
// externfn!(#[link_args = "-lsnappy"]
235+
// fn snappy_max_compressed_length(source_length: size_t) -> size_t)
236+
unsafe fn snappy_max_compressed_length(source_length: size_t) -> size_t {
237+
#[fixed_stack_segment]; #[inline(never)];
238+
return snappy_max_compressed_length(source_length);
239+
240+
#[link_args = "-lsnappy"]
241+
extern {
242+
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
243+
}
244+
}
245+
246+
fn main() {
247+
let x = unsafe { snappy_max_compressed_length(100) };
248+
println(fmt!("max compressed length of a 100 byte buffer: %?", x));
249+
}
250+
~~~~
251+
252+
# Segmented stacks and the linter
253+
254+
By default, whenever you invoke a non-Rust fn, the `cstack` lint will
255+
check that one of the following conditions holds:
256+
257+
1. The call occurs inside of a fn that has been annotated with
258+
`#[fixed_stack_segment]`;
259+
2. The call occurs inside of an `extern fn`;
260+
3. The call occurs within a stack closure created by some other
261+
safe fn.
262+
263+
All of these conditions ensure that you are running on a large stack
264+
segmented. However, they are sometimes too strict. If your application
265+
will be making many calls into C, it is often beneficial to promote
266+
the `#[fixed_stack_segment]` attribute higher up the call chain. For
267+
example, the Rust compiler actually labels main itself as requiring a
268+
`#[fixed_stack_segment]`. In such cases, the linter is just an
269+
annoyance, because all C calls that occur from within the Rust
270+
compiler are made on a large stack. Another situation where this
271+
frequently occurs is on a 64-bit architecture, where large stacks are
272+
the default. In cases, you can disable the linter by including a
273+
`#[allow(cstack)]` directive somewhere, which permits violations of
274+
the "cstack" rules given above (you can also use `#[warn(cstack)]` to
275+
convert the errors into warnings, if you prefer).
276+
142277
# Destructors
143278

144279
Foreign libraries often hand off ownership of resources to the calling code,
@@ -161,6 +296,9 @@ pub struct Unique<T> {
161296
162297
impl<T: Send> Unique<T> {
163298
pub fn new(value: T) -> Unique<T> {
299+
#[fixed_stack_segment];
300+
#[inline(never)];
301+
164302
unsafe {
165303
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
166304
assert!(!ptr::is_null(ptr));
@@ -184,6 +322,9 @@ impl<T: Send> Unique<T> {
184322
#[unsafe_destructor]
185323
impl<T: Send> Drop for Unique<T> {
186324
fn drop(&self) {
325+
#[fixed_stack_segment];
326+
#[inline(never)];
327+
187328
unsafe {
188329
let x = intrinsics::init(); // dummy value to swap in
189330
// moving the object out is needed to call the destructor

branches/try2/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ control reaches the end of the block:
436436
fn signum(x: int) -> int {
437437
if x < 0 { -1 }
438438
else if x > 0 { 1 }
439-
else { return 0 }
439+
else { 0 }
440440
}
441441
~~~~
442442

branches/try2/mk/rt.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ RUNTIME_CXXS_$(1)_$(2) := \
6868
rt/sync/rust_thread.cpp \
6969
rt/rust_builtin.cpp \
7070
rt/rust_run_program.cpp \
71-
rt/rust_env.cpp \
7271
rt/rust_rng.cpp \
73-
rt/rust_stack.cpp \
7472
rt/rust_upcall.cpp \
7573
rt/rust_uv.cpp \
7674
rt/rust_crate_map.cpp \

branches/try2/mk/target.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
6969
| $$(TLIB$(1)_T_$(2)_H_$(3))/
7070
@$$(call E, compile_and_link: $$@)
7171
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@))
72-
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) --out-dir $$(@D) $$< && touch $$@
72+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) $(BORROWCK) --out-dir $$(@D) $$< && touch $$@
7373
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@))
7474

7575
# Only build the compiler for host triples
@@ -90,7 +90,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
9090
| $$(TLIB$(1)_T_$(2)_H_$(3))/
9191
@$$(call E, compile_and_link: $$@)
9292
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
93-
$$(STAGE$(1)_T_$(2)_H_$(3)) --out-dir $$(@D) $$< && touch $$@
93+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
9494
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
9595

9696
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \

0 commit comments

Comments
 (0)