Commit Graph

49408 Commits

Author SHA1 Message Date
Scott Olson
9db76f311d Use fmt::Result instead of Result<(), Error>. 2016-01-04 16:11:32 -06:00
Scott Olson
5a0c1b3a88 Print BasicBlock names in lowercase. 2016-01-04 16:11:32 -06:00
Scott Olson
661976cbd1 Add a human-readable textual form for MIR.
This can be dumped for a particular `fn` with the attribute
`#![rustc_mir(pretty = "filename.mir"]`.
2016-01-04 16:11:32 -06:00
bors
41611baece Auto merge of #30661 - michaelwoerister:trans_fn_attrs, r=nrc
So far `librustc::trans::base::trans_fn()` and `trans_closure()` have been passed the list of attributes on the function being translated *only* if the function was local and non-generic. For generic functions, functions inlined from other crates, functions with foreign ABI and for closures, only an empty list of attributes was ever passed to `trans_fn()`.
This led to the case that generic functions marked with `#[rustc_mir]` where not actually translated via MIR but via the legacy translation path.

This PR makes function/closure attributes always be passed to `trans_fn()` and disables the one test where this makes a difference.

If there is an actual reason why attributes were not passed along in these cases, let me know.

cc @rust-lang/compiler
cc @luqmana regarding the test case
2016-01-04 22:09:52 +00:00
Tshepang Lekhonkhobe
ae96ce33e7 doc: these examples do not need Copy and Clone traits
Also sneak in a missing trailing comma
2016-01-04 22:38:27 +02:00
bors
badc23b6ad Auto merge of #30602 - tsion:mir-graphviz-display, r=nikomatsakis
r? @nikomatsakis

cc @eddyb @nagisa

This PR changes most of the MIR graphviz debug output, making it smaller and more consistent. Also, it changes all fonts to monospace and adds a graph label containing the type of the `fn` the MIR is for and all the values (arguments, named bindings, and compiler temporaries).

I chose to re-write the graphviz output code instead of using the existing libgraphviz API because I found it much easier to prototype usage of various graphviz features when I had full control of the text output. It also makes the code simpler, I think.

Below are a bunch of example functions and links to their output images on the current nightly vs. this PR. File names starting with numbers (e.g. `80-factorial_fold-new.png`) are for closures. There's still a bunch of low hanging fruit to make it even better, particularly around aggregates and references.

I also imagine the textual output for MIR will be able to closely match the graphviz output. The list of statements should look identical and the terminators will be the same except that the text form will have a list of target blocks (potentially using the same edge labels as the graphviz does). I can PR a simple text output right after this PR.

This is my first large change to the compiler, so if anything should be reorganized/renamed/etc, let me know! Also, feel free to bikeshed the details of the output, though any minor changes can come in future PRs.

```rust
fn empty() {}
```

http://vps.solson.me/mir-graphviz/empty-new.png
http://vps.solson.me/mir-graphviz/empty-old.png

```rust
fn constant() -> i32 {
    42
}
```

http://vps.solson.me/mir-graphviz/constant-new.png
http://vps.solson.me/mir-graphviz/constant-old.png

```rust
fn increment(x: i32) -> i32 {
    x + 1
}
```

http://vps.solson.me/mir-graphviz/increment-new.png
http://vps.solson.me/mir-graphviz/increment-old.png

```rust
fn factorial_recursive(n: usize) -> usize {
    if n == 0 {
        1
    } else {
        n * factorial_recursive(n - 1)
    }
}
```

http://vps.solson.me/mir-graphviz/factorial_recursive-new.png
http://vps.solson.me/mir-graphviz/factorial_recursive-old.png

```rust
fn factorial_iterative(n: usize) -> usize {
    let mut prod = 1;
    for x in 1..n {
        prod *= x;
    }
    prod
}
```

http://vps.solson.me/mir-graphviz/factorial_iterative-new.png
http://vps.solson.me/mir-graphviz/factorial_iterative-old.png

```rust
fn factorial_fold(n: usize) -> usize {
    (1..n).fold(1, |prod, x| prod * x)
}
```

http://vps.solson.me/mir-graphviz/factorial_fold-new.png
http://vps.solson.me/mir-graphviz/factorial_fold-old.png
http://vps.solson.me/mir-graphviz/80-factorial_fold-new.png
http://vps.solson.me/mir-graphviz/80-factorial_fold-old.png

```rust
fn collatz(mut n: usize) {
    while n != 1 {
        if n % 2 == 0 {
            n /= 2;
        } else {
            n = 3 * n + 1;
        }
    }
}
```

http://vps.solson.me/mir-graphviz/collatz-new.png
http://vps.solson.me/mir-graphviz/collatz-old.png

```rust
fn multi_switch(n: usize) -> usize {
    match n {
        5 | 10 | 15 => 3,
        20 | 30 => 2,
        _ => 1,
    }
}
```

http://vps.solson.me/mir-graphviz/multi_switch-new.png
http://vps.solson.me/mir-graphviz/multi_switch-old.png
2016-01-04 20:24:35 +00:00
Tshepang Lekhonkhobe
249b5c0b4a address review comment 2016-01-04 21:35:06 +02:00
Steve Klabnik
723ead6c9c Mention that structs can contain &mut Ts
Fixes #30254
2016-01-04 14:06:54 -05:00
bors
5e8cb3819b Auto merge of #30523 - ubsan:wrapping_op_assign, r=eddyb
Add OpAssign to Wrapping<T>, plus fix some problems in core::num::wrapping

including, but not limited to:

* Testing Wrapping<T>
* Pull out a lot of broken code that doesn't need to be there with the new stage0 compiler
* Adding Rem and RemAssign to Wrapping<T>
* Removed 3 (assumed accidental) re-exports, which is a minor [breaking-change].
* Change shl and shr to take all integer types, instead of a usize; this is a more major [breaking-change], because of values that were inferred before, but brings us in line with the integer shifts.

Fixes #30524 and #30523
2016-01-04 18:37:21 +00:00
Mike Anderson
6c8dd522df Add mention of warnings lint group to help message 2016-01-04 12:28:35 -06:00
Toby Scrace
33f3c52d32 Make float parsing "." return Err
This makes both of the following return Err:

    ".".parse::<f32>()
    ".".parse::<f64>()

This is a [breaking-change], which the libs team have classified as a
bug fix.
2016-01-04 18:23:33 +00:00
Steve Klabnik
ff3ebfa7b9 Mention that Sync/Send are automatically derived
Fixes #28581
2016-01-04 13:03:29 -05:00
Andrea Canciani
3fff63400b Update librustc_unicode/tables.rs
with a new version generated by src/etc/unicode.py.
2016-01-04 17:58:50 +01:00
bors
b62289153c Auto merge of #30553 - luqmana:mir-match-arm-guards, r=nikomatsakis
Fixes #30527.

```Rust

fn main() {
    let _abc = match Some(101i8) {
        Some(xyz) if xyz > 100 => xyz,
        Some(_) => -1,
        None => -2
    };
}
```

Resulting MIR now includes the `Some(xyz)` arm, guard and all:
![match.dot](https://cloud.githubusercontent.com/assets/287063/11999413/066f7610-aa8b-11e5-927b-24215af57fc4.png)

~~Not quite sure how to write a test for this.~~ Thinking too hard, just tested the end result.

r? @nikomatsakis
2016-01-04 16:54:11 +00:00
Andrea Canciani
aa77f39ccf Improve the range comparison
As mentioned in #29734, the range comparison closure can be improved.

The LLVM IR and the assembly from the new version are much simpler and
unfortunately we cannot rely on the compiler to optimise this much, as
it would need to know that `lo <= hi`.

Besides from simpler code, there might also be a performance
advantage, although it is unlikely to appear on benchmarks, as we are
doing a binary search, which should always involve few comparisons.

The code is available on the playpen for ease of comparison:
http://is.gd/4raMmH
2016-01-04 17:51:12 +01:00
Andrea Canciani
cf3fcf7758 Reuse standard methods
Do not hand-code `Result::ok` or `cmp` in tables.rs.
2016-01-04 17:51:12 +01:00
Andrea Canciani
b081436ca4 Improve formatting of tables.rs
Make unicode.py generate a tables.rs which is more conformant to usual
Rust formatting (as per `rustfmt`).
2016-01-04 17:51:05 +01:00
Andrea Canciani
eab351ef3e Cleanup unicode.py
The methods related to char width are dead code since
464cdff102993ff1900eebbf65209e0a3c0be0d5; remove them.
2016-01-04 17:31:41 +01:00
bors
543bb03d3e Auto merge of #30690 - LawrenceWoodman:patch-2, r=steveklabnik
`fs::File` was being referenced without either calling via `std::fs::File` or by using `File` after having used `std::fs::File`.  Also `Path` was being referenced without first having used `std::path::Path`.
2016-01-04 14:09:15 +00:00
Niko Matsakis
15d32ffbb2 Feature-gate defaulted type parameters outside of types. 2016-01-04 05:18:56 -05:00
Lawrence Woodman
0c3d6b46ac Add missing use statements
fs::File was being referenced without either calling via std::fs::File or by using File after having used fs::File.  Also Path was being referenced without first having used std::path::Path.
2016-01-04 07:21:48 +00:00
bors
191ff2d8fd Auto merge of #30651 - nagisa:mir-fix-equality-checks, r=eddyb
This is not a fix to checks themselves per se (though we still use `Eq` MIR test instead of calling `PartialEq::eq`), but rather how we handle items we encounter in pattern position.

Previously we would just call `PartialEq` with the constant and the matchee, but now we essentially inline the constant instead. E.g. these two snippets are functionally equivalent at MIR level:

```
match val { Some(42) => true, _ => false }
```
and
```
const SECRET: Option<u8> = Some(42);
match val { SECRET => true, _ => false }
```

This approach also allows for more optimizations of matches. I.e. It can now exploit `SwitchInt` to switch on number inside a `Some` regardless of whether the value being an item or not.

This is based on @tsion’s already approved PR so I could reuse the file for more tests.

r? @eddyb
cc @nikomatsakis @tsion
2016-01-04 03:07:59 +00:00
Michael McConville
810c035450 Undo whitespace tweaks pending libbacktrace merge
These should probably be submitted upstream. They're inevitably going to
complicate merges, and because they're non-functional changes this just
isn't worth our time.
2016-01-03 20:53:31 -05:00
bors
99e59dec5a Auto merge of #29732 - nathansizemore:master, r=steveklabnik 2016-01-04 00:27:40 +00:00
Guillaume Gomez
6e68cdfcc2 Add test for "malformed macro lhs" and change back span_bug to span_fatal 2016-01-04 01:13:57 +01:00
bors
8f11a9ef4e Auto merge of #30677 - diwic:master, r=bluss
Obviously we can't remove the character one past the end of the String. And we can't today either - we'll just panic at char_at() instead - but if we're going to keep that assertion, we should at least have a correct assertion.
2016-01-03 21:00:46 +00:00
bors
cae9267d47 Auto merge of #29949 - fhahn:issue-21659-show-relevant-trait-impls, r=arielb1
This PR for #21659 uses `DefId.for_each_relevant_impl()` to show other possible implementations in the "trait not implemented" message.
2016-01-03 19:14:20 +00:00
Tshepang Lekhonkhobe
4a1062873e fix "make tidy" failure 2016-01-03 11:20:06 +02:00
Tshepang Lekhonkhobe
f20a139981 run rustfmt on syntax::parse::lexer 2016-01-03 11:14:09 +02:00
Lawrence Woodman
e5a846e90e Correct formatting use of tab instead of spaces 2016-01-03 08:15:24 +00:00
Wesley Wiser
4dee31c119 Rustdoc - Specify max-image size
Fixes #24861
2016-01-02 21:38:36 -05:00
Nicholas Mazzuca
402259da38 Take out Op<T>/OpAssign<T> for Wrapping<T> 2016-01-02 15:34:55 -08:00
Florian Hahn
a8d60708ec Refactor candidate selection 2016-01-03 00:11:48 +01:00
Nicholas Mazzuca
cd3aa31e6d Finish test implementation 2016-01-02 14:36:28 -08:00
diwic
8b398ed823 Fix off-by-one in String::remove
Obviously we can't remove the character one past the end of the String. And we can't today either - we'll just panic at char_at() instead - but if we're going to keep that assertion, we should at least have a correct assertion.
2016-01-02 22:36:50 +01:00
Florian Hahn
25e4389866 Use for_each_impl 2016-01-02 19:47:41 +01:00
Florian Hahn
ba24fbd404 Manually check trait implementations 2016-01-02 19:47:02 +01:00
Florian Hahn
6093ea8039 Add more tests 2016-01-02 19:46:31 +01:00
Florian Hahn
2c52cb424a Limit displaying relevant trait impls to 4 2016-01-02 19:46:31 +01:00
bors
4744472fe0 Auto merge of #30264 - GuillaumeGomez:patch-5, r=Manishearth
r? @Manishearth

Also: should I merged both commits? Not sure if it's really useful to keep the first one.
2016-01-02 16:56:15 +00:00
bors
44f020883e Auto merge of #30675 - jimmantooth:master, r=apasel422 2016-01-02 13:58:57 +00:00
Scott Olson
56343cd653 Add 'mut' to temporary vars in MIR graphviz output. 2016-01-02 07:12:35 -06:00
James Mantooth
877d55c1e0 Grammar fixes 2016-01-02 01:26:22 -06:00
Nathan
3e9d5fea48 Adjusted heading and created dedicated section in std::io docs 2016-01-02 00:27:16 -05:00
Nathan
66e842b6de Links and punctionaction fixes. 2016-01-02 00:25:42 -05:00
Nathan
7f36a18df8 Added platform notes to std::fs public functions. 2016-01-02 00:25:42 -05:00
Guillaume Gomez
55955f5a45 Add E0463 error explanation 2016-01-02 02:39:45 +01:00
bors
d4b67cd7cc Auto merge of #30672 - nagisa:to-degrad-stab, r=sfackler
f64 methods have been stable since rust 1.0, but f32 never got stabilised.

I suggest backporting this to beta as well (needs changing stablilisation version then).

r? @aturon

Fixes https://github.com/rust-lang/rfcs/issues/1438
2016-01-01 22:42:04 +00:00
Simonas Kazlauskas
c921abf9c0 Stabilise f32::to_{degrees,radians} to match f64
f64 methods have been stable since rust 1.0, but f32 never got stabilised.
2016-01-02 00:07:16 +02:00
Florian Hahn
335298e7b6 Show similar trait implementations if no matching impl is found
closes #21659
2016-01-01 17:50:43 +01:00