Skip to content

Commit 405f8a7

Browse files
committed
---
yaml --- r: 73463 b: refs/heads/dist-snap c: f5d4ea8 h: refs/heads/master i: 73461: b10e769 73459: 02b24c5 73455: 6386c49 v: v3
1 parent 2bf9740 commit 405f8a7

File tree

5 files changed

+248
-94
lines changed

5 files changed

+248
-94
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: dea667725137368dd9c928bae3c091b9ccf42e67
10+
refs/heads/dist-snap: f5d4ea84f5f38c230235a2bab142bfb55d6febdc
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

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

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
284284
# fn some_expensive_computation(_i: uint) -> int { 42 }
285285
~~~
286286

287-
## Backgrounding computations: Futures
287+
## Futures
288288
With `extra::future`, rust has a mechanism for requesting a computation and getting the result
289289
later.
290290

@@ -329,77 +329,6 @@ fn main() {
329329
}
330330
~~~
331331

332-
## Sharing immutable data without copy: ARC
333-
334-
To share immutable data between tasks, a first approach would be to only use pipes as we have seen
335-
previously. A copy of the data to share would then be made for each task. In some cases, this would
336-
add up to a significant amount of wasted memory and would require copying the same data more than
337-
necessary.
338-
339-
To tackle this issue, one can use an Atomically Reference Counted wrapper (`ARC`) as implemented in
340-
the `extra` library of Rust. With an ARC, the data will no longer be copied for each task. The ARC
341-
acts as a reference to the shared data and only this reference is shared and cloned.
342-
343-
Here is a small example showing how to use ARCs. We wish to run concurrently several computations on
344-
a single large vector of floats. Each task needs the full vector to perform its duty.
345-
~~~
346-
use extra::arc::ARC;
347-
348-
fn pnorm(nums: &~[float], p: uint) -> float {
349-
(vec::foldl(0.0, *nums, |a,b| a+(*b).pow(p as float) )).pow(1f / (p as float))
350-
}
351-
352-
fn main() {
353-
let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
354-
println(fmt!("Inf-norm = %?", numbers.max()));
355-
356-
let numbers_arc = ARC(numbers);
357-
358-
for uint::range(1,10) |num| {
359-
let (port, chan) = stream();
360-
chan.send(numbers_arc.clone());
361-
362-
do spawn {
363-
let local_arc : ARC<~[float]> = port.recv();
364-
let task_numbers = local_arc.get();
365-
println(fmt!("%u-norm = %?", num, pnorm(task_numbers, num)));
366-
}
367-
}
368-
}
369-
~~~
370-
371-
The function `pnorm` performs a simple computation on the vector (it computes the sum of its items
372-
at the power given as argument and takes the inverse power of this value). The ARC on the vector is
373-
created by the line
374-
~~~
375-
# use extra::arc::ARC;
376-
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
377-
let numbers_arc=ARC(numbers);
378-
~~~
379-
and a clone of it is sent to each task
380-
~~~
381-
# use extra::arc::ARC;
382-
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
383-
# let numbers_arc = ARC(numbers);
384-
# let (port, chan) = stream();
385-
chan.send(numbers_arc.clone());
386-
~~~
387-
copying only the wrapper and not its contents.
388-
389-
Each task recovers the underlying data by
390-
~~~
391-
# use extra::arc::ARC;
392-
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
393-
# let numbers_arc=ARC(numbers);
394-
# let (port, chan) = stream();
395-
# chan.send(numbers_arc.clone());
396-
# let local_arc : ARC<~[float]> = port.recv();
397-
let task_numbers = local_arc.get();
398-
~~~
399-
and can use it as if it were local.
400-
401-
The `arc` module also implements ARCs around mutable data that are not covered here.
402-
403332
# Handling task failure
404333

405334
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,20 @@ pub fn create_llargs_for_fn_args(cx: fn_ctxt,
16941694
vec::from_fn(args.len(), |i| {
16951695
unsafe {
16961696
let arg_n = first_real_arg + i;
1697-
llvm::LLVMGetParam(cx.llfn, arg_n as c_uint)
1697+
let arg = &args[i];
1698+
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
1699+
1700+
// Mark `&mut T` as no-alias, as the borrowck pass ensures it's true
1701+
match arg.ty.node {
1702+
ast::ty_rptr(_, mt) => {
1703+
if mt.mutbl == ast::m_mutbl {
1704+
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
1705+
}
1706+
}
1707+
_ => {}
1708+
}
1709+
1710+
llarg
16981711
}
16991712
})
17001713
}

branches/dist-snap/src/librustdoc/markdown_pass.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,32 @@ fn write_variants(
451451
fn write_variant(ctxt: &Ctxt, doc: doc::VariantDoc) {
452452
assert!(doc.sig.is_some());
453453
let sig = (&doc.sig).get();
454+
455+
// space out list items so they all end up within paragraph elements
456+
ctxt.w.put_line(~"");
457+
454458
match copy doc.desc {
455459
Some(desc) => {
456-
ctxt.w.put_line(fmt!("* `%s` - %s", sig, desc));
460+
ctxt.w.put_line(list_item_indent(fmt!("* `%s` - %s", sig, desc)));
457461
}
458462
None => {
459463
ctxt.w.put_line(fmt!("* `%s`", sig));
460464
}
461465
}
462466
}
463467

468+
fn list_item_indent(item: &str) -> ~str {
469+
let mut indented = ~[];
470+
for str::each_line_any(item) |line| {
471+
indented.push(line);
472+
}
473+
474+
// separate markdown elements within `*` lists must be indented by four
475+
// spaces, or they will escape the list context. indenting everything
476+
// seems fine though.
477+
str::connect_slices(indented, "\n ")
478+
}
479+
464480
fn write_trait(ctxt: &Ctxt, doc: doc::TraitDoc) {
465481
write_common(ctxt, doc.desc(), doc.sections());
466482
write_methods(ctxt, doc.methods);
@@ -807,7 +823,9 @@ mod test {
807823
assert!(str::contains(
808824
markdown,
809825
"\n\n#### Variants\n\
826+
\n\
810827
\n* `b` - test\
828+
\n\
811829
\n* `c` - test\n\n"));
812830
}
813831

@@ -817,7 +835,24 @@ mod test {
817835
assert!(str::contains(
818836
markdown,
819837
"\n\n#### Variants\n\
838+
\n\
820839
\n* `b`\
840+
\n\
841+
\n* `c`\n\n"));
842+
}
843+
844+
#[test]
845+
fn should_write_variant_list_with_indent() {
846+
let markdown = render(
847+
~"enum a { #[doc = \"line 1\\n\\nline 2\"] b, c }");
848+
assert!(str::contains(
849+
markdown,
850+
"\n\n#### Variants\n\
851+
\n\
852+
\n* `b` - line 1\
853+
\n \
854+
\n line 2\
855+
\n\
821856
\n* `c`\n\n"));
822857
}
823858

@@ -827,7 +862,9 @@ mod test {
827862
assert!(str::contains(
828863
markdown,
829864
"\n\n#### Variants\n\
865+
\n\
830866
\n* `b(int)`\
867+
\n\
831868
\n* `c(int)` - a\n\n"));
832869
}
833870

0 commit comments

Comments
 (0)