Commit Graph

28419 Commits

Author SHA1 Message Date
Alex Crichton
eb084b1818 rustdoc: Make static initalizers prettier
Previously, if an initializer took multiple lines or was just large in general,
it was pretty poorly rendered [1] [2]. This alters the logic to just link back
to the source for any multi-line static, with a placeholder of "[definition]".
This should make reading statics a little easier on the eyes. All single-line
statics are still inlined in the documentation.

Closes #13198

[1] - http://static.rust-lang.org/doc/master/sync/mutex/index.html#statics
[2] - http://static.rust-lang.org/doc/master/std/sync/atomics/index.html#statics
2014-05-03 02:09:30 -07:00
Alex Crichton
71a52a2edc syntax: Fix duplicate attributes on module files
The outer attributes were manually appended when a module file was parsed, but
the attributes were also added higher up the stack of parsing (when the module
finished parsing). This removes the append in parsing the module file.

Closes #13826
2014-05-03 02:09:30 -07:00
Alex Crichton
0b7954fa80 rustdoc: Put bangs on the names of macros
This makes them a little easier to search for and makes it clearer that they're
a macro and not an item to import.

Closes #13852
2014-05-03 02:09:29 -07:00
Alex Crichton
50fb77f8ba rustdoc: Stop requiring a crate ID attribute
This is mostly just an artificial requirement as it can use similar logic to the
compiler to infer the crate id.
2014-05-03 02:09:29 -07:00
Alex Crichton
5d145c1c18 rustdoc: Don't have rustc emit warnings
They're much more useful when building code, much less so when building
documentation.

Closes #13894
2014-05-03 02:09:29 -07:00
Alex Crichton
1547caf748 rustdoc: Fix inclusion of the new fonts
These fonts were moved into place by rust's makefiles, but rustdoc is widely
used outside of rustc itself. This moves the fonts into the rustdoc binary,
similarly to the other static assets, and writes them to the output location
whenever rustdoc generates documentation.

Closes #13593
Closes #13787
2014-05-03 02:09:29 -07:00
bors
3a321b001f auto merge of #13880 : TeXitoi/rust/biguint-always-use-u64, r=pcwalton
This change allow a speedup of ~1.5 on shootout-pidigits on a i32
system.  `MachineUint` is used to abstract the internal machine
unsigned integer to simplity future architecture specialization.
2014-05-02 20:56:52 -07:00
bors
e0d261e576 auto merge of #13579 : hirschenberger/rust/lint_unsigned_negate, r=alexcrichton
See #11273 and #13318
2014-05-02 16:51:50 -07:00
Falco Hirschenberger
6c26cbb602 Add lint check for negating uint literals and variables.
See #11273 and #13318
2014-05-03 00:13:26 +02:00
bors
b5d6b07370 auto merge of #13879 : huonw/rust/more-re, r=alexcrichton
Commits for details.

This shouldn't change the generated code at all (except for switching to `LitBinary` from an explicit ExprVec of individual ExprLit bytes for `prefix_bytes`).
2014-05-02 07:06:50 -07:00
Huon Wilson
1ad0cba5e6 regex_macros: simplify using AstBuilder & the improved quoting.
char literals now work in a quotation.

There were several instances of duplicated functionality in regex_macros
compared to AstBuilder so refactor those out.
2014-05-02 22:54:55 +10:00
Huon Wilson
1d43a98dea syntax: implement ToSource for more things in the quasiquoter.
The last few primitive types were missing.
2014-05-02 22:54:55 +10:00
Huon Wilson
5c424ba34a syntax: store char literals/tokens as chars rather than u32s.
Clearly storing them as `char` is semantically nicer, but this also
fixes a bug whereby `quote_expr!(cx, 'a')` wasn't working, because the
code created by quotation was not matching the actual AST definitions.
2014-05-02 22:54:55 +10:00
bors
e97d4e6c19 auto merge of #13789 : sfackler/rust/debug-assert, r=pcwalton
I switched the `assert!` calls in `RefCell` over to `debug_assert!`.
There are probably other instances that should be converted as well, but
I couldn't think of any off the top of my head.

RFC: 0015-assert
2014-05-01 23:41:46 -07:00
bors
adcbf53955 auto merge of #13886 : japaric/rust/fix-an-typos, r=alexcrichton
Found the first one in the rust reference docs. I was going to submit a PR with one fix, but figured I could look for more... This is the result.
2014-05-01 20:11:47 -07:00
Steven Fackler
ca84d79375 Remove useless assert! case 2014-05-01 19:07:41 -07:00
Steven Fackler
b0b7c252d7 Add debug_assert and debug_assert_eq macros
I also switched some `assert!` calls over to `debug_assert!`.

Closes #12049.

RFC: 0015-assert
2014-05-01 19:07:40 -07:00
Jorge Aparicio
e4bf643b99 Fix a/an typos 2014-05-01 20:02:11 -05:00
bors
9f836d5a53 auto merge of #13877 : thestinger/rust/de-tilde-str-vec, r=alexcrichton 2014-05-01 16:06:48 -07:00
Daniel Micay
e93cb04c4b fix error message for obsolete &"foo" literal 2014-05-01 17:43:00 -04:00
Daniel Micay
7852625b86 remove leftover obsolete string literals 2014-05-01 17:42:57 -04:00
bors
fb72d7cfea auto merge of #13881 : aochagavia/rust/pr, r=alexcrichton 2014-05-01 13:31:59 -07:00
bors
e4ad24f1b2 auto merge of #13878 : brutal-chaos/rust/tutorial_grammar, r=alexcrichton 2014-05-01 12:06:52 -07:00
Guillaume Pinot
593f6a42d0 BigUint always use u64 as the internal machine unsigned integer
This change allow a speedup of ~1.5 on shootout-pidigits on a i32
system.  `DoubleBigDigit` is used to abstract the internal
unsigned integer used in computation to simplity future
architecture specialization.

`BigDigit::from_uint` and `BigDigit::to_uint` become
`BigDigit::from_doublebigdigit` and `BigDigit::to_doublebigdigit`.

[breaking-change]
2014-05-01 20:10:16 +02:00
bors
ee03529fa9 auto merge of #13875 : hjr3/rust/serialize-strbuf, r=alexcrichton
- implement Encodable and Decodable for StrBuf
- implement to_json for StrBuf
2014-05-01 09:41:54 -07:00
Adolfo Ochagavía
b537028116 Fixed outdated note in the tutorial 2014-05-01 17:52:17 +02:00
bors
239557de6d auto merge of #13724 : nikomatsakis/rust/expr-use-visitor, r=pnkfelix
Pre-step towards issue #12624 and others: Introduce ExprUseVisitor, remove the
moves computation. ExprUseVisitor is a visitor that walks the AST for a
function and calls a delegate to inform it where borrows, copies, and moves
occur.

In this patch, I rewrite the gather_loans visitor to use ExprUseVisitor, but in
future patches, I think we could rewrite regionck, check_loans, and possibly
other passes to use it as well. This would refactor the repeated code between
those places that tries to determine where copies/moves/etc occur.

r? @alexcrichton
2014-05-01 04:36:50 -07:00
Justin Noah
000667158b rustdoc tutorial: grammar change in list comments 2014-05-01 01:16:30 -07:00
bors
5c0abead82 auto merge of #13873 : alexcrichton/rust/issue-13872, r=Aatch
This was just a typo in the decoder using the source crate's number rather than
the destination crate's number of a reexport.

Closes #13872
2014-05-01 00:56:48 -07:00
Herman J. Radtke III
fa6efedccf Add serialization support for StrBuf
- implement Encodable and Decodable for StrBuf
- implement to_json for StrBuf
2014-04-30 23:49:00 -07:00
Alex Crichton
8c87eff700 rustc: Fix def ids of xcrate-reexported items
This was just a typo in the decoder using the source crate's number rather than
the destination crate's number of a reexport.

Closes #13872
2014-04-30 19:24:21 -07:00
Niko Matsakis
b9af043879 Address nits from @pnkfelix 2014-04-30 20:22:36 -04:00
Patrick Walton
4baff4e15f librustc: Remove ~"string" and &"string" from the language 2014-04-30 16:49:12 -07:00
bors
9f484e616e auto merge of #13648 : gereeter/rust/removed-rev, r=alexcrichton
In the process, `Splits` got changed to be more like `CharSplits` in `str` to present the DEI interface.

Note that `treemap` still has a `rev_iter` function because it seems like it would be a significant interface change to expose a DEI - the iterator would have to gain an extra pointer, the completion checks would be more complicated, and it isn't easy to check that such an implementation is correct due to the use of unsafety to subvert the aliasing properties of `&mut`.

This fixes #9391.
2014-04-30 15:46:47 -07:00
bors
3aadbed612 auto merge of #13864 : adrientetar/rust/fix-it-some-more, r=alexcrichton
Two selector fixes for rustdoc:

- links colored in blue (#13807) was also affecting headers, which are anchored to their respective ids
- the header unstyling from #13776 was being applied to all headers also

Additionally, remove a stray title in the documentation. This makes the crate title of prelude appear as header instead of an inline paragraph of text (all others work normally and do not have that header tag).

The design is unchanged from my previous template (e.g. [here](http://adrientetar.legtux.org/cached/rust-docs/struct.CChars.htm)), however it is now properly applied.  
The last fix remaining is to enable webfonts service from `static.rust-lang.org`, this is #13593.

r? @alexcrichton, @brson
2014-04-30 14:06:47 -07:00
bors
a3f9f37014 auto merge of #13072 : bjz/rust/bitset, r=alexcrichton
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-30 11:11:49 -07:00
Brendan Zabarauskas
63ee7bb0db Update for language changes 2014-04-30 10:02:11 -07:00
Brendan Zabarauskas
464e375d2f Move bitflags module to libstd
This will allow us to provide type-safe APIs in libstd that are C-compatible.
2014-04-30 10:01:14 -07:00
bors
7e9f3ea423 auto merge of #13863 : huonw/rust/re-tweaks, r=pcwalton
Mostly code style e.g. avoiding `~` and using `for` + iterators.
2014-04-30 09:41:51 -07:00
Adrien Tétar
dbea4853a9 rustdoc: fix overly broad selectors 2014-04-30 17:35:54 +02:00
bors
ad37c0b97c auto merge of #12740 : nical/rust/json-streaming, r=erickt
Hi rust enthusiasts,

With this patch I propose to add a "streaming" API to the existing json parser in libserialize.

By "streaming" I mean a parser that let you act on JsonEvents that are generated as while parsing happens, as opposed to parsing the entire source, generating a big data structure and working with this data structure. I think both approaches have their pros and cons so this pull request adds the streaming API, preserving the existing one.

The streaming API is simple: It consist into an Iterator<JsonEvent> that consumes an Iterator<char>. JsonEvent is an enum with values such as NumberValue(f64), BeginList, EndList, BeginObject, etc.

The user would ideally use the API as follows:

```
for evt in StreamingParser::new(src) {
  match evt {
    BeginList => {
       // ...
    }
    // ...
  }
}
```

The iterator provides a stack() method returning a slice of StackNodes which represent "where we currently are" in the logical structure of the json stream (for instance at "foo.bar[3].x" you get [ Key("foo"), Key("bar"), Index(3), Key("x") ].)

I wrote "ideally" above because the current way rust expands for loops, you can't call the stack() method because the iterator is already borrowed. So for know you need to manually advance the iterator in the loop. I hope this is something we can cope with, until for loops are better integrated with the compiler.

Streaming parsers are useful when you want to read from a json stream, generate a custom data structure and you know how the json is going to be structured. For example, imagine you have to parse a 3D mesh file represented in the json format. In this case you probably expect to have large arrays of vertices and using the generic parser will be very inefficient because it will create a big list of all these vertices, which you will copy into a contiguous array afterwards (so you end up doing a lot of small allocations, parsing the json once and parsing the data structure afterwards). With a streaming parser, you can add the vertices to a contiguous array as they come in without paying the cost of creating the intermediate Json data structure. You have much fewer allocations since you write directly in the final data structure and you can be smart in how you will pre-allocate it.

I added added this directly into serialize::json rather than in its own library because it turns out I can reuse most of the existing code whereas maintaining a separate library (which I did originally) forces me to duplicate this code.

I wrote this trying to minimize the size of the patch so there may be places where the code could be nicer at the expenses of more changes (let me know what you prefer).

This is my first (potential) contribution to rust, so please let me know if I am doing something wrong (maybe I should have first introduced this proposition in the mailing list, or opened a github issue, etc.?). I work a few meters away from @pknfelix so I am not too hard to find :)
2014-04-30 02:01:43 -07:00
bors
f77784b57f auto merge of #13857 : alexcrichton/rust/add-dylib-paths, r=brson
When a syntax extension is loaded by the compiler, the dylib that is opened may
have other dylibs that it depends on. The dynamic linker must be able to find
these libraries on the system or else the library will fail to load.

Currently, unix gets by with the use of rpaths. This relies on the dylib not
moving around too drastically relative to its dependencies. For windows,
however, this is no rpath available, and in theory unix should work without
rpaths as well.

This modifies the compiler to add all -L search directories to the dynamic
linker's set of load paths. This is currently managed through environment
variables for each platform.

Closes #13848
2014-04-29 19:46:44 -07:00
Alex Crichton
1a367c62cd rustc: Add search paths to dylib load paths
When a syntax extension is loaded by the compiler, the dylib that is opened may
have other dylibs that it depends on. The dynamic linker must be able to find
these libraries on the system or else the library will fail to load.

Currently, unix gets by with the use of rpaths. This relies on the dylib not
moving around too drastically relative to its dependencies. For windows,
however, this is no rpath available, and in theory unix should work without
rpaths as well.

This modifies the compiler to add all -L search directories to the dynamic
linker's set of load paths. This is currently managed through environment
variables for each platform.

Closes #13848
2014-04-29 18:58:39 -07:00
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
cbf113182c auto merge of #13776 : adrientetar/rust/rustdoc-fix, r=brson
- Closes #13591. Relevant example: http://adrientetar.legtux.org/cached/rust-docs/struct.CChars.htm
(Had to use `!important` to override CSS selector precedence, namely matching over parent class.)
- Implement changes from #13780 feedback, namely:
  * Changed font-size from 18px to 15px
  * Reintroduced gray background for code samples
  * Tightened up the margins
- Fix point 1 and point 4 of #13804.

Samples:

- [enum.FileType](http://adrientetar.legtux.org/cached/rust-docs/enum.FileType.htm)
- [struct.CChars](http://adrientetar.legtux.org/cached/rust-docs/struct.CChars.htm)
- [std](http://adrientetar.legtux.org/cached/rust-docs/std.htm)
- [std::io](http://adrientetar.legtux.org/cached/rust-docs/io.htm).

r? @brson
2014-04-29 18:26:44 -07:00
Huon Wilson
33f98ada02 regex: General style tweaks.
For loops are nicer than manual whiles, etc.
2014-04-30 10:35:20 +10: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