Commit Graph

28359 Commits

Author SHA1 Message Date
Brendan Zabarauskas
43320e5847 Document derived traits for bitset! macro 2014-04-29 18:50:31 -07:00
Brendan Zabarauskas
a3d9980b25 Document how generated bitflags can be extended with type and trait implementations 2014-04-29 18:50:31 -07:00
Brendan Zabarauskas
8b58981871 Add a bitflags! macro
The `bitflags!` macro generates a `struct` that holds a set of C-style bitmask flags. It is useful for creating typesafe wrappers for C APIs.

For example:

~~~rust
#[feature(phase)];
#[phase(syntax)] extern crate collections;

bitflags!(Flags: u32 {
    FlagA       = 0x00000001,
    FlagB       = 0x00000010,
    FlagC       = 0x00000100,
    FlagABC     = FlagA.bits
                | FlagB.bits
                | FlagC.bits
})

fn main() {
    let e1 = FlagA | FlagC;
    let e2 = FlagB | FlagC;
    assert!((e1 | e2) == FlagABC);   // union
    assert!((e1 & e2) == FlagC);     // intersection
    assert!((e1 - e2) == FlagA);     // set difference
}
~~~
2014-04-29 18:50:31 -07:00
bors
33259d9797 auto merge of #13833 : alexcrichton/rust/ffunction-sections, r=thestinger
The compiler has previously been producing binaries on the order of 1.8MB for
hello world programs "fn main() {}". This is largely a result of the compilation
model used by compiling entire libraries into a single object file and because
static linking is favored by default.

When linking, linkers will pull in the entire contents of an object file if any
symbol from the object file is used. This means that if any symbol from a rust
library is used, the entire library is pulled in unconditionally, regardless of
whether the library is used or not.

Traditional C/C++ projects do not normally encounter these large executable
problems because their archives (rust's rlibs) are composed of many objects.
Because of this, linkers can eliminate entire objects from being in the final
executable. With rustc, however, the linker does not have the opportunity to
leave out entire object files.

In order to get similar benefits from dead code stripping at link time, this
commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as
well as passing --gc-sections to the linker *by default*. This means that each
function and each global will be placed into its own section, allowing the
linker to GC all unused functions and data symbols.

By enabling these flags, rust is able to generate much smaller binaries default.
On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in
size). The output size of dynamic libraries remained constant, but the output
size of rlibs increased, as seen below:

    libarena       -  2.27% bigger
    libcollections -  0.64% bigger
    libflate       -  0.85% bigger
    libfourcc      - 14.67% bigger
    libgetopts     -  4.52% bigger
    libglob        -  2.74% bigger
    libgreen       -  9.68% bigger
    libhexfloat    - 13.68% bigger
    liblibc        - 10.79% bigger
    liblog         - 10.95% bigger
    libnative      -  8.34% bigger
    libnum         -  2.31% bigger
    librand        -  1.71% bigger
    libregex       -  6.43% bigger
    librustc       -  4.21% bigger
    librustdoc     -  8.98% bigger
    librustuv      -  4.11% bigger
    libsemver      -  2.68% bigger
    libserialize   -  1.92% bigger
    libstd         -  3.59% bigger
    libsync        -  3.96% bigger
    libsyntax      -  4.96% bigger
    libterm        - 13.96% bigger
    libtest        -  6.03% bigger
    libtime        -  2.86% bigger
    liburl         -  6.59% bigger
    libuuid        -  4.70% bigger
    libworkcache   -  8.44% bigger

This increase in size is a result of encoding many more section names into each
object file (rlib). These increases are moderate enough that this change seems
worthwhile to me, due to the drastic improvements seen in the final artifacts.
The overall increase of the stage2 target folder (not the size of an install)
went from 337MB to 348MB (3% increase).

Additionally, linking is generally slower when executed with all these new
sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the
`rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three
megabytes are shaved off the binary. I found this increase in link time to be
acceptable relative to the benefits of code size gained.

This commit only enables --gc-sections for *executables*, not dynamic libraries.
LLVM does all the heavy lifting when producing an object file for a dynamic
library, so there is little else for the linker to do (remember that we only
have one object file).

I conducted similar experiments by putting a *module's* functions and data
symbols into its own section (granularity moved to a module level instead of a
function/static level). The size benefits of a hello world were seen to be on
the order of 400K rather than 1.2MB. It seemed that enough benefit was gained
using ffunction-sections that this route was less desirable, despite the lesser
increases in binary rlib size.
2014-04-29 16:16:46 -07:00
bors
95f2c4bcc3 auto merge of #13772 : brson/rust/cratedocs, r=alexcrichton
Also move prelude explanation to the prelude module.

This tries to provide a guide to what's in the standard library, organized bottom up from primitives to I/O.
2014-04-29 14:26:49 -07:00
bors
7f6fa048df auto merge of #13845 : alexcrichton/rust/regex-deps, r=brson
There is currently not much precedent for target crates requiring syntax
extensions to compile their test versions. This dependency is possible, but
can't be encoded through the normal means of DEPS_regex because it is a
test-only dependency and it must be a *host* dependency (it's a syntax
extension).

Closes #13844
2014-04-29 12:31:52 -07:00
Alex Crichton
58ab4a0064 rustc: Enable -f{function,data}-sections
The compiler has previously been producing binaries on the order of 1.8MB for
hello world programs "fn main() {}". This is largely a result of the compilation
model used by compiling entire libraries into a single object file and because
static linking is favored by default.

When linking, linkers will pull in the entire contents of an object file if any
symbol from the object file is used. This means that if any symbol from a rust
library is used, the entire library is pulled in unconditionally, regardless of
whether the library is used or not.

Traditional C/C++ projects do not normally encounter these large executable
problems because their archives (rust's rlibs) are composed of many objects.
Because of this, linkers can eliminate entire objects from being in the final
executable. With rustc, however, the linker does not have the opportunity to
leave out entire object files.

In order to get similar benefits from dead code stripping at link time, this
commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as
well as passing --gc-sections to the linker *by default*. This means that each
function and each global will be placed into its own section, allowing the
linker to GC all unused functions and data symbols.

By enabling these flags, rust is able to generate much smaller binaries default.
On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in
size). The output size of dynamic libraries remained constant, but the output
size of rlibs increased, as seen below:

    libarena         -  2.27% bigger (   292872 =>    299508)
    libcollections   -  0.64% bigger (  6765884 =>   6809076)
    libflate         -  0.83% bigger (   186516 =>    188060)
    libfourcc        - 14.71% bigger (   307290 =>    352498)
    libgetopts       -  4.42% bigger (   761468 =>    795102)
    libglob          -  2.73% bigger (   899932 =>    924542)
    libgreen         -  9.63% bigger (  1281718 =>   1405124)
    libhexfloat      - 13.88% bigger (   333738 =>    380060)
    liblibc          - 10.79% bigger (   551280 =>    610736)
    liblog           - 10.93% bigger (   218208 =>    242060)
    libnative        -  8.26% bigger (  1362096 =>   1474658)
    libnum           -  2.34% bigger (  2583400 =>   2643916)
    librand          -  1.72% bigger (  1608684 =>   1636394)
    libregex         -  6.50% bigger (  1747768 =>   1861398)
    librustc         -  4.21% bigger (151820192 => 158218924)
    librustdoc       -  8.96% bigger ( 13142604 =>  14320544)
    librustuv        -  4.13% bigger (  4366896 =>   4547304)
    libsemver        -  2.66% bigger (   396166 =>    406686)
    libserialize     -  1.91% bigger (  6878396 =>   7009822)
    libstd           -  3.59% bigger ( 39485286 =>  40902218)
    libsync          -  3.95% bigger (  1386390 =>   1441204)
    libsyntax        -  4.96% bigger ( 35757202 =>  37530798)
    libterm          - 13.99% bigger (   924580 =>   1053902)
    libtest          -  6.04% bigger (  2455720 =>   2604092)
    libtime          -  2.84% bigger (  1075708 =>   1106242)
    liburl           -  6.53% bigger (   590458 =>    629004)
    libuuid          -  4.63% bigger (   326350 =>    341466)
    libworkcache     -  8.45% bigger (  1230702 =>   1334750)

This increase in size is a result of encoding many more section names into each
object file (rlib). These increases are moderate enough that this change seems
worthwhile to me, due to the drastic improvements seen in the final artifacts.
The overall increase of the stage2 target folder (not the size of an install)
went from 337MB to 348MB (3% increase).

Additionally, linking is generally slower when executed with all these new
sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the
`rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three
megabytes are shaved off the binary. I found this increase in link time to be
acceptable relative to the benefits of code size gained.

This commit only enables --gc-sections for *executables*, not dynamic libraries.
LLVM does all the heavy lifting when producing an object file for a dynamic
library, so there is little else for the linker to do (remember that we only
have one object file).

I conducted similar experiments by putting a *module's* functions and data
symbols into its own section (granularity moved to a module level instead of a
function/static level). The size benefits of a hello world were seen to be on
the order of 400K rather than 1.2MB. It seemed that enough benefit was gained
using ffunction-sections that this route was less desirable, despite the lesser
increases in binary rlib size.
2014-04-29 10:29:00 -07:00
Alex Crichton
7b3650da7a mk: Depend on regex_macros for tests appropriately
There is currently not much precedent for target crates requiring syntax
extensions to compile their test versions. This dependency is possible, but
can't be encoded through the normal means of DEPS_regex because it is a
test-only dependency and it must be a *host* dependency (it's a syntax
extension).

Closes #13844
2014-04-29 08:55:40 -07:00
bors
30e373390f auto merge of #13807 : ipetkov/rust/issue-13771, r=alexcrichton
All links inside docblocks will have their color set to `#4e8bca` (a light blue color to contrast against the black text). This color also offers a visible contrast from the surrounding text if viewed as grayscale, making it suitable for accessability.
    
Docblock links will also be underlined when hovered over.

Before:
![screen shot 2014-04-27 at 12 47 06 pm](https://cloud.githubusercontent.com/assets/1638690/2812157/00e53a32-ce45-11e3-81e8-7b1dc692f6b7.png)



After (links underlined only on hover, cursor not shown in image):
![screen shot 2014-04-27 at 12 47 48 pm](https://cloud.githubusercontent.com/assets/1638690/2812158/04fa94b4-ce45-11e3-9ead-2344753c251d.png)

Fix #13771
2014-04-29 00:26:48 -07:00
bors
cbe6bd0a9d auto merge of #13829 : alexcrichton/rust/dead-strip, r=thestinger
This flag to the linker asks it to strip away all dead code during linking, as
well as dead data. This reduces the size of hello world from 1.7MB to 458K on my
system (70% reduction).

I have not seen this impact link times negatively, and I have seen this pass
'make check' successfully. I am slightly wary of adding this option, but the
benefits are so huge tha I think we should work hard to work around any issues
rather than avoid using the flag entirely.
2014-04-28 23:06:50 -07:00
Ivan Petkov
3a0d8fd980 rustdoc: #13771: Make html links inside paragraphs more readable
All links inside docblocks will have their color set to `#4e8bca` (a
light blue color to contrast against the black text). This color also
offers a visible contrast from the surrounding text if viewed as
grayscale, making it suitable for accessability.

Docblock links will also be underlined when hovered over.
2014-04-28 20:55:10 -07:00
bors
8fdf1e2cb8 auto merge of #13834 : nick29581/rust/str_fix, r=luqmana 2014-04-28 19:41:47 -07:00
Nick Cameron
f3c33893b6 Remove internal support for fixed length strings 2014-04-29 13:10:23 +12:00
bors
a72a6ec897 auto merge of #13830 : noamraph/rust/doc-browser-history, r=kballard
Currently, in both chrome and firefox, if I type something in the search box in the reference docs I get immediately the search results. That's great. However, if I want to go back to the doc I was reading and try to press the back button, I am immediately forwarded again to the search results. This is caused by the fact that the search term is (deliberately) left in the search box, and the search() function is called as if I typed the search term again.
I disabled calling the search() function if there's no search term in the URL, and now it seems to work fine.

I hope I'm sending the pull request correctly - I'm not really used to git and github.
2014-04-28 17:32:00 -07:00
bors
3cd6c1e008 auto merge of #13827 : lifthrasiir/rust/rustdoc-hidden-pub-field, r=alexcrichton
Fixes #13806. Also adds a note to `HiddenStructField` about why it doesn't appear in the `clean` module itself.
2014-04-28 15:56:45 -07:00
Noam Yorav-Raphael
5b2e477629 rustdoc: Make going back in browser history work after typing a search term 2014-04-29 01:29:14 +03:00
bors
a3b28cb1f8 auto merge of #13819 : nick29581/rust/ty_str, r=pcwalton
Similar to my recent changes to ~[T]/&[T], these changes remove the vstore abstraction and represent str types as ~(str) and &(str). The Option<uint> in ty_str is the length of the string, None if the string is dynamically sized.
2014-04-28 14:26:48 -07:00
Alex Crichton
edd8bb0aa1 rustc: Pass -dead_strip on OSX
This flag to the linker asks it to strip away all dead code during linking, as
well as dead data. This reduces the size of hello world from 1.7MB to 458K on my
system (70% reduction).

I have not seen this impact link times negatively, and I have seen this pass
'make check' successfully. I am slightly wary of adding this option, but the
benefits are so huge tha I think we should work hard to work around any issues
rather than avoid using the flag entirely.
2014-04-28 13:20:08 -07:00
bors
23262a8390 auto merge of #13812 : alxgnon/rust/master, r=alexcrichton
This is a quick fix for repeated documentation descriptions in certain modules.
Following is a list of the faulty modules I found. I ran `pcregrep -r -M "<p>(.+)\n\1" doc` on the html documentation to help identify them.

- [rustuv::uvio](http://static.rust-lang.org/doc/master/rustuv/uvio/index.html)
- [rustuv::uvll](http://static.rust-lang.org/doc/master/rustuv/uvll/index.html)
- [std::rt::backtrace](http://static.rust-lang.org/doc/master/std/rt/backtrace/index.html)
- [std::rt::env](http://static.rust-lang.org/doc/master/std/rt/env/index.html)
- [std::rt::global_heap](http://static.rust-lang.org/doc/master/std/rt/global_heap/index.html)
- [std::rt::local_heap](http://static.rust-lang.org/doc/master/std/rt/local_heap/index.html)
- [std::rt::rtio](http://static.rust-lang.org/doc/master/std/rt/rtio/index.html)
- [std::rt::task](http://static.rust-lang.org/doc/master/std/rt/task/index.html)
- [std::rt::thread](http://static.rust-lang.org/doc/master/std/rt/thread/index.html)
- [std::rt::unwind](http://static.rust-lang.org/doc/master/std/rt/unwind/index.html)
- [syntax::parse::classify](http://static.rust-lang.org/doc/master/syntax/parse/classify/index.html)
- [syntax::parse::common](http://static.rust-lang.org/doc/master/syntax/parse/common/index.html)

After a little testing, I discovered that moving the documentation inside (`//!`) instead of outside (`///`) modules fixed the immediate problem. I went through the trouble of moving the documentation, and with this commit there are no more repeated descriptions within those faulty modules.

This does not fix the underlying problem though. We should look into why having the documentation outside instead of inside caused the descriptions to be repeated. I will create a separate issue with my findings on the subject if necessary.
In the meantime, this simple fix should be enough.
2014-04-28 12:56:49 -07:00
Kang Seonghoon
3b5d6b4de5 rustdoc: Make strip_hidden use a dedicated hidden item if any.
fixes #13806.
2014-04-29 04:01:55 +09:00
bors
1f4278d650 auto merge of #13797 : lifthrasiir/rust/std-mem-replace-doc, r=alexcrichton
Inspired by @steveklabnik's [comment](http://www.reddit.com/r/rust/comments/240p9s/eli5_stdmemreplace/ch2gxw8), this PR adds the practical use cases to the documentation of `std::mem::replace`.

Caveat: We need a `compile-fail` equivalent for doctest. :p
2014-04-28 11:32:07 -07:00
bors
3e284eeb21 auto merge of #13821 : aochagavia/rust/pr3, r=alexcrichton 2014-04-28 10:01:57 -07:00
Adolfo Ochagavía
ac170b100e Fixed typo in std::vec 2014-04-28 15:39:11 +02:00
Kang Seonghoon
1be93e61da std: Add more docs to std::mem::replace. 2014-04-28 22:28:47 +09:00
bors
a1ad41b93d auto merge of #13791 : lifthrasiir/rust/mod-inner-span, r=huonw
This PR is primarily motivated by (and fixes) #12926.

We currently only have a span for the individual item itself and not for the referred contents. This normally does not cause a problem since both are located in the same file; it *is* possible that the contained statement or item is located in the other file (the syntax extension can do that), but even in that case the syntax extension should be located in the same file as the item. The module item (i.e. `mod foo;`) is the only exception here, and thus warrants a special treatment.

Rustdoc would now distinguish `mod foo;` from `mod foo {...}` by checking if the span for the module item and module contents is in different files. If it's the case, we'd prefer module contents over module item. There are alternative strategies, but as noted above we will have some corner cases if we don't record the contents span explicitly.
2014-04-28 05:21:46 -07:00
Nick Cameron
c0ff3caae1 Refactor ty_str to use a ~(str) representation.
Similar to my recent changes to ~[T]/&[T], these changes remove the vstore abstraction and represent str types as ~(str) and &(str). The Option<uint> in ty_str is the length of the string, None if the string is dynamically sized.
2014-04-28 21:02:18 +12:00
bors
7a19a82d11 auto merge of #13811 : alexcrichton/rust/closed-issues, r=sfackler
Closes #5518
Closes #7320
Closes #8391
Closes #8827
Closes #8983
Closes #10683
Closes #10802
Closes #11515
2014-04-27 23:06:41 -07:00
Alex Crichton
35f295d2a9 test: Add tests for closed issues
Closes #5518
Closes #7320
Closes #8391
Closes #8827
Closes #8983
Closes #10683
Closes #10802
Closes #11515
2014-04-27 20:35:51 -07:00
bors
4e55bc7ac3 auto merge of #13795 : klutzy/rust/win-make-check, r=alexcrichton
Fixes #12303.

Also contains a partial fix for `make check` failure.
2014-04-27 20:31:37 -07:00
klutzy
405861ed0a test: Fix run-make on windows 2014-04-28 11:45:30 +09:00
Alexandre Gagnon
6c41253a47 Fix repeated module documentation 2014-04-27 22:17:49 -04:00
bors
ff25d62165 auto merge of #13809 : prattmic/rust/tutorial_debug, r=alexcrichton
As of cc6ec8df, the Owned closures example uses println! instead of
debug!, making a note about seeing debug seem out-of-place in this
section.

Since debug! is not used elsewhere in the tutorial, remove the note
entirely.
2014-04-27 19:06:38 -07:00
Brian Anderson
3525bd8959 std: Rewrite crate docs
Also move prelude explanation to the prelude module.
2014-04-27 18:43:56 -07:00
bors
c2b6ab94e2 auto merge of #13801 : ryantm/rust/master, r=alexcrichton
The previous error message using assert_eq! was quite cryptic. This should be more clear. I also added a test for the underflow case.
2014-04-27 17:26:37 -07:00
bors
8b24964012 auto merge of #13799 : m-r-r/rust/patch-std-io-standard_error, r=alexcrichton
Hello,

With the latest version of Rust, calling to the function [`std::io::standard_error()`](http://static.rust-lang.org/doc/master/std/io/fn.standard_error.html) succeeds only if the value of the argument is `EndOfFile`, `IoUnavailable` or `InvalidInput`. If the function is called with another value as argument, it fails without message.

Here is a piece of code that reproduces the problem:

```rust
use std::io::{standard_error,EndOfFile,FileNotFound,PermissionDenied};

fn main() {
     println!("Error 1: {}", standard_error(EndOfFile)); // does not fail
     println!("Error 2: {}", standard_error(FileNotFound)); // fails
     println!("Error 3: {}", standard_error(PermissionDenied)); //fails
}
```
This was because the `IoErrorKind` passed as argument wasn't matched against all the possible values.

I added the missing branches in the `match` statement inside the function, and i removed the call to the `fail!()` macro. I rebuilt the crate with the latest `rustc` version and it seems to works.
2014-04-27 16:01:39 -07:00
Michael Pratt
bc330063d8 doc: Remove out-of-place debug! note
As of cc6ec8df, the Owned closures example uses println! instead of
debug!, making a note about seeing debug seem out-of-place in this
section.

Since debug! is not used elsewhere in the tutorial, remove the note
entirely.
2014-04-27 18:27:40 -04:00
bors
479b8a812c auto merge of #13792 : jacob-hegna/rust/master, r=alexcrichton
Just modified the documentation for parse_bytes to make it more clear how the bytes were parsed (big endian) and to show an example of what it returned.  I also added documentation for the to_str_bytes which previously had no documentation (besides one stackoverflow post).
2014-04-27 14:36:41 -07:00
Jacob Hegna
b8f5090a9a Rewrote documentation for parse_bytes and to_str_bytes in {int, uint}_macros.rs 2014-04-27 15:49:47 -05:00
bors
02ba8e2754 auto merge of #13798 : aochagavia/rust/pr, r=alexcrichton 2014-04-27 13:11:43 -07:00
bors
1be19f9cc8 auto merge of #13796 : ema-fox/rust/patch-1, r=kballard 2014-04-27 11:46:46 -07:00
Ryan Mulligan
550c87e17d add BigUint subtraction underflow error message 2014-04-27 10:37:02 -07:00
Adolfo Ochagavía
af064c7bb0 Fixed typo in std::iter 2014-04-27 16:50:55 +02:00
m-r-r
a7b8a13e14 Added missing values in std::io::standard_error() 2014-04-27 14:45:28 +02:00
Emanuel Rylke
107da87996 Fix link to hashmap.rs and json.rs in sample code FAQ 2014-04-27 14:17:06 +02:00
Kang Seonghoon
c8a29c4c59 rustdoc: External module item links to the module contents. Fixes #12926.
the basic strategy is to distinguish `mod foo;` from `mod foo {...}`
by checking if the span for the module item and module contents is
in different files. if it's the case, we prefer module contents.

it is technically possible to fix #12926 without changing the AST,
probably by checking the individual items' span. this is not without
a problem though, since it is possible that some items inside
`mod foo {...}` may have originated from other file (e.g. `include!`).
therefore it is better to record both spans explicitly.
2014-04-27 19:54:31 +09:00
bors
b2a8fae84c auto merge of #13783 : wackywendell/rust/permfix, r=kballard
I filed bugs #13734 and #13759 recently, and then realized I could probably fix them myself. This does exactly that, with a couple additional modifications and additions to the test-suite to pick up on that.

I've never done this before, so please feel free to tell me all the things I'm doing wrong or could be doing better.
2014-04-26 23:41:31 -07:00
klutzy
1efb668aaa test: Rename a test to bypass UAC on windows 2014-04-27 15:13:37 +09:00
Kang Seonghoon
dee21a67b8 syntax: Mod records the span for inner contents.
this is useful when the module item and module contents are defined
from different files (like rustdoc). in most cases the original span
for the module item would be used; in other cases, the span for
module contents is available separately at the `inner` field.
2014-04-27 14:52:30 +09:00
Wendell Smith
b7d0feb90c Fixing permutation of small lists, such that [], [x] -> [[]], [[x]], and updating size_hints.
Fixes #13734 and #13759.
2014-04-26 22:27:36 -04:00
bors
3ffe56ce38 auto merge of #13777 : lifthrasiir/rust/no-multi-viewitemuse, r=alexcrichton
It reflected the obsolete syntax `use a, b, c;` and did not make past the parser (though it was a non-fatal error so we can continue). This legacy affected many portions of rustc and rustdoc as well, so this PR cleans them up altogether.

As a side effect of cleanup, we now have `SCHEMA_VERSION` in `rustdoc::clean` (instead of the crate root), so it has a better chance to be updated when `rustdoc::clean` gets updated.
2014-04-26 17:01:28 -07:00