Commit Graph

49189 Commits

Author SHA1 Message Date
Michael F. Lamb
fcc356373b Remove extraneous [], replace accidental removed link to heap section 2016-01-07 11:44:03 -08:00
Michael F. Lamb
3a6dbb30a2 Be consistent about what is a "chapter" versus a "section" 2016-01-06 16:06:55 -08:00
Michael F. Lamb
936678adb1 Link to section on references when we use the term prior to defining it 2016-01-06 16:06:55 -08:00
Michael F. Lamb
3557e6941d Link to references section when they first appear
In a straight-through read of "Syntax and Semantics," the concept of a
"reference" is used here before it is explained. Mention that and link to
the section explaining references.
2016-01-06 16:06:55 -08:00
Michael F. Lamb
e22ceea1a7 Explain surprising new syntax appearing in example code
In a straight-through read of "Syntax and Semantics," the first time we
meet a generic, and the first time we meet a vector, is when a Vec<T> shows
up in this example. I'm not sure that I could argue that the whole section
should appear later in the book than the ones on vectors and generics, so
instead just give the reader a brief introduction to both and a promise to
follow up later.
2016-01-06 16:06:55 -08:00
bors
5daa75373d Auto merge of #30654 - nrc:panictry, r=brson
The motivation (other than removing boilerplate) is that this is a baby step towards a parser with error recovery.

[breaking-change] if you use any of the changed functions, you'll need to remove a try! or panictry!
2016-01-06 20:30:55 +00:00
bors
e8c337b5ca Auto merge of #30532 - nikomatsakis:cross-item-dependencies, r=mw
This is roughly the same as my previous PR that created a dependency graph, but that:

1. The dependency graph is only optionally constructed, though this doesn't seem to make much of a difference in terms of overhead (see measurements below).
2. The dependency graph is simpler (I combined a lot of nodes).
3. The dependency graph debugging facilities are much better: you can now use `RUST_DEP_GRAPH_FILTER` to filter the dep graph to just the nodes you are interested in, which is super help.
4. The tests are somewhat more elaborate, including a few known bugs I need to fix in a second pass.

This is potentially a `[breaking-change]` for plugin authors. If you are poking about in tcx state or something like that, you probably want to add `let _ignore = tcx.dep_graph.in_ignore();`, which will cause your reads/writes to be ignored and not affect the dep-graph.

After this, or perhaps as an add-on to this PR in some cases, what I would like to do is the following:

- [x] Write-up a little guide to how to use this system, the debugging options available, and what the possible failure modes are.
- [ ] Introduce read-only and perhaps the `Meta` node
- [x] Replace "memoization tasks" with node from the map itself
- [ ] Fix the shortcomings, obviously! Notably, the HIR map needs to register reads, and there is some state that is not yet tracked. (Maybe as a separate PR.)
- [x] Refactor the dep-graph code so that the actual maintenance of the dep-graph occurs in a parallel thread, and the main thread simply throws things into a shared channel (probably a fixed-size channel). There is no reason for dep-graph construction to be on the main thread. (Maybe as a separate PR.)

Regarding performance: adding this tracking does add some overhead, approximately 2% in my measurements (I was comparing the build times for rustdoc). Interestingly, enabling or disabling tracking doesn't seem to do very much. I want to poke at this some more and gather a bit more data -- in some tests I've seen that 2% go away, but on others it comes back. It's not entirely clear to me if that 2% is truly due to constructing the dep-graph at all.

The next big step after this is write some code to dump the dep-graph to disk and reload it.

r? @michaelwoerister
2016-01-06 18:37:57 +00:00
Niko Matsakis
93996b160c Fix dependency graph test cases to have correct commments and use -Z incr-comp 2016-01-06 11:29:00 -05:00
Niko Matsakis
876de6e495 Fix tidy errors 2016-01-06 11:28:53 -05:00
Niko Matsakis
0c8ee65020 Use memoized helper more often. 2016-01-06 10:16:58 -05:00
bors
21b025f55f Auto merge of #30733 - ubsan:wrapping_op_assign, r=eddyb
Fix a breaking change in #30523

While this does fix a breaking change, it is also, technically, a
[breaking-change] to go back to our original way
2016-01-06 15:00:17 +00:00
Niko Matsakis
a9d7e36668 Fix numerous typos, renamings, and minor nits raised by mw. 2016-01-06 09:19:19 -05:00
bors
d5ac1a1da3 Auto merge of #30481 - nagisa:mir-calls-2, r=nikomatsakis
r? @nikomatsakis

This is a pretty big PR conflating changes to a few different block terminators (Call, DivergingCall, Panic, Resume, Diverge), because they are somewhat closely related.

Each commit has a pretty good description on what is being changed in each commit. The end result is greatly simplified CFG and translation for calls (no success branch if the function is diverging, no cleanup branch if there’s nothing to cleanup etc).

Fixes https://github.com/rust-lang/rust/issues/30480
Fixes https://github.com/rust-lang/rust/issues/29767
Partialy solves https://github.com/rust-lang/rust/issues/29575
Fixes https://github.com/rust-lang/rust/issues/29573
2016-01-06 13:11:18 +00:00
Simonas Kazlauskas
36b3951c73 Create personality slot when translating Resume
This considerably simplifies code around calling functions and translation of Resume itself. This
removes requirement that a block containing Resume terminator is always translated after something
which creates a landing pad, thus allowing us to actually translate some valid MIRs we could not
translate before.

However, an assumption is added that translator is correct (in regards to landing pad generation)
and code will never reach the Resume terminator without going through a landing pad first. Breaking
these assumptions would pass an `undef` value into the personality functions.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
f9814242dc panic/panic_bounds_check to destructure tys
Not any more beautiful.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
d1c644c1e9 Merge Call and DivergingCall diffs into CallKind
This merges two separate Call terminators and uses a separate CallKind sub-enum instead.

A little bit unrelatedly, copying into destination value for a certain kind of invoke, is also
implemented here. See the associated comment in code for various details that arise with this
implementation.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
50107034c0 Add tests 2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
cef6aee369 Don’t generate landing-pads if -Z no-landing-pads 2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
20ec53a0d3 Fix ReturnPointer generation for void return types
Fixes #30480
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
924bb1e5eb Refine call terminator translation
* Implement landing pads; and
* Implement DivergingCall translation; and
* Modernise previous implementation of Call somewhat.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
a1e13983f7 Have a cached unreachable block inside MIR state
It is useful for various cases where direct unreachable cannot be translated and a separate block
is necessary.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
4e86dcdb72 Remove diverge terminator
Unreachable terminator can be contained all within the trans.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
5b34690842 Remove the Panic block terminator 2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
ecf4d0e3ad Add Resume Terminator which corresponds to resume
Diverge should eventually go away
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
6f18b559df Generate DivergingCall terminator
This simplifies CFG greatly for some cases :)
2016-01-06 13:57:47 +02:00
Simonas Kazlauskas
893a66d7a1 Split Call into Call and DivergingCall
DivergingCall is different enough from the regular converging Call to warrant the split. This also
inlines CallData struct and creates a new CallTargets enum in order to have a way to differentiate
between calls that do not have an associated cleanup block.

Note, that this patch still does not produce DivergingCall terminator anywhere. Look for that in
the next patches.
2016-01-06 13:40:57 +02:00
bors
7312e0a163 Auto merge of #30692 - michaelwoerister:mir-overloaded-fn-calls, r=nikomatsakis
So far, calls going through `Fn::call`, `FnMut::call_mut`, or `FnOnce::call_once` have not been translated properly into MIR:
The call `f(a, b, c)` where `f: Fn(T1, T2, T3)` would end up in MIR as:
```
call `f` with arguments  `a`, `b`, `c`
```
What we really want is:
```
call `Fn::call` with arguments  `f`, `a`, `b`, `c`
```
This PR transforms these kinds of overloaded calls during `HIR -> HAIR` translation.

What's still a bit funky is that the `Fn` traits expect arguments to be tupled but due to special handling type-checking and trans, we do not actually tuple arguments and everything still checks out fine. So, after this PR we end up with MIR containing calls where function signature and arguments seemingly don't match:
```
call Fn::call(&self, args: (T1, T2, T3)) with arguments `f`, `a`, `b`, `c`
```
instead of
```
call Fn::call(&self, args: (T1, T2, T3)) with arguments `f`, (`a`, `b`, `c`)  //  <- args tupled!
```
It would be nice if the call traits could go without special handling in MIR and later on.
2016-01-06 09:00:57 +00:00
Nicholas Mazzuca
14e1e2aee8 Fix a breaking change in #30523
While this does fix a breaking change, it is also, technically, a
[breaking-change] to go back to our original way
2016-01-05 22:16:03 -08:00
Niko Matsakis
11c671b59c Workaround stage0 bug 2016-01-05 21:05:51 -05:00
Niko Matsakis
8b22ed8651 Add assert-dep-graph testing mechanism and tests 2016-01-05 21:05:51 -05:00
Niko Matsakis
d48f48f61f Refactor compiler to make use of dep-tracking-maps. Also, in cases where
we were using interior mutability (RefCells, TyIvar), add some reads/writes.
2016-01-05 21:05:51 -05:00
Niko Matsakis
5d9dd7cf33 Refactor overlap checker so that it walks the HIR instead of poking into
random tables. The old code was weird anyway because it would
potentially walk traits from other crates etc. The new code fits
seamlessly with the dependency tracking.
2016-01-05 21:05:51 -05:00
Niko Matsakis
75c4f395ac Strip the trait-def phase from collect, which has no function. 2016-01-05 21:05:50 -05:00
Niko Matsakis
005fa14358 Annotate the compiler with information about what it is doing when. 2016-01-05 21:05:50 -05:00
Niko Matsakis
aa265869ba Add DepGraph to tcx. 2016-01-05 21:05:50 -05:00
Niko Matsakis
c77cd480cf Introduce the DepGraph and DepTracking map abstractions,
along with a README explaining how they are to be used
2016-01-05 21:05:50 -05:00
bors
dc1f442634 Auto merge of #30492 - wesleywiser:fix_extra_drops, r=pnkfelix
Fixes #28159
2016-01-06 01:55:45 +00:00
Michael Woerister
e281509dce [MIR] Add test case for translation of closure calls. 2016-01-05 12:50:54 -05:00
Michael Woerister
7d357190ff [MIR] Implement calling of closures and add missing monomorphization when translating function references. 2016-01-05 12:50:46 -05:00
Michael Woerister
04b6c4939b [MIR] Handle overloaded call expressions during HIR -> HAIR translation. 2016-01-05 12:40:35 -05:00
bors
bd58fd8438 Auto merge of #30665 - zachpanz88:new-year, r=nrc
New copyright date

Happy new year!
2016-01-05 13:54:30 +00:00
bors
5253294d22 Auto merge of #30702 - tshepang:derives-not-needed, r=steveklabnik
Also sneak in a missing trailing comma
2016-01-05 10:24:37 +00:00
bors
3a6c6c8e01 Auto merge of #30680 - wesleywiser:rustdoc_image_max_width, r=steveklabnik
Fixes #24861
2016-01-05 08:37:06 +00:00
bors
dbacacda8a Auto merge of #30708 - GuillaumeGomez:malformed_macro, r=sanxiyn
Part of #30669
2016-01-05 05:20:27 +00:00
bors
803c3e2ee8 Auto merge of #30595 - steveklabnik:remove_learn_rust, r=gankro
Some history:

While getting Rust to 1.0, it was a struggle to keep the book in a
working state. I had always wanted a certain kind of TOC, but couldn't
quite get it there.

At the 11th hour, I wrote up "Rust inside other langauges" and "Dining
Philosophers" in an attempt to get the book in the direction I wanted to
go. They were fine, but not my best work. I wanted to further expand
this section, but it's just never going to end up happening. We're doing
the second draft of the book now, and these sections are basically gone
already.

Here's the issues with these two sections, and removing them just fixes
it all:

// Philosophers

There was always controversy over which ones were chosen, and why. This
is kind of a perpetual bikeshed, but it comes up every once in a while.

The implementation was originally supposed to show off channels, but
never did, due to time constraints. Months later, I still haven't
re-written it to use them.

People get different results and assume that means they're wrong, rather
than the non-determinism inherent in concurrency. Platform differences
aggrivate this, as does the exact amount of sleeping and printing.

// Rust Inside Other Languages

This section is wonderful, and shows off a strength of Rust. However,
it's not clear what qualifies a language to be in this section. And I'm
not sure how tracking a ton of other languages is gonna work, into the
future; we can't test _anything_ in this section, so it's prone to
bitrot.

By removing this section, and making the Guessing Game an initial
tutorial, we will move this version of the book closer to the future
version, and just eliminate all of these questions.

In addition, this also solves the 'split-brained'-ness of having two
paths, which has endlessly confused people in the past.

I'm sad to see these sections go, but I think it's for the best.

Fixes #30471
Fixes #30163
Fixes #30162
Fixes #25488
Fixes #30345
Fixes #29590
Fixes #28713
Fixes #28915

And probably others. This lengthy list alone is enough to show that
these should have been removed.

RIP.
2016-01-05 03:32:12 +00:00
bors
e2d649405a Auto merge of #30707 - tsion:mir-text, r=nikomatsakis
r? @nikomatsakis

Textual MIR can be dumped for a particular `fn` with `#![rustc_mir(pretty = "filename.mir")]`. Below is an example of the text output.

```rust
struct Point {
    x: i32,
    y: i32,
}

fn example() -> Point {
    let mut e = Point { x: 1, y: 2 };

    let num = 5;
    let plus_num = |x: i32| x + num;

    e.y = plus_num(e.x);
    e
}
```

```rust
fn() -> Point {
    let mut var0: Point; // e
    let var1: i32; // num
    let var2: [closure@test.rs:84:20: 84:36 num:&i32]; // plus_num
    let mut tmp0: ();
    let mut tmp1: &i32;
    let mut tmp2: ();
    let mut tmp3: i32;
    let mut tmp4: &[closure@test.rs:84:20: 84:36 num:&i32];
    let mut tmp5: i32;
    let mut tmp6: Point;

    bb0: {
        var0 = Point { x: 1, y: 2 };
        var1 = 5;
        tmp1 = &var1;
        var2 = [closure@test.rs:84:20: 84:36] { num: tmp1 };
        tmp4 = &var2;
        tmp5 = var0.0;
        tmp3 = tmp4(tmp5) -> [return: bb3, unwind: bb4];
    }

    bb1: {
        return;
    }

    bb2: {
        diverge;
    }

    bb3: {
        drop var0.1;
        var0.1 = tmp3;
        drop tmp2;
        drop var2;
        drop var0;
        tmp6 = var0;
        return = tmp6;
        drop tmp6;
        goto -> bb1;
    }

    bb4: {
        drop var2;
        goto -> bb5;
    }

    bb5: {
        drop var0;
        goto -> bb2;
    }
}
```

```rust
fn(arg0: &[closure@test.rs:84:20: 84:36 num:&i32], arg1: i32) -> i32 {
    let var0: i32; // x
    let mut tmp0: ();
    let mut tmp1: i32;
    let mut tmp2: i32;

    bb0: {
        var0 = arg1;
        tmp1 = var0;
        tmp2 = (*(*arg0).0);
        return = Add(tmp1, tmp2);
        goto -> bb1;
    }

    bb1: {
        return;
    }

    bb2: {
        diverge;
    }
}
```
2016-01-05 01:43:07 +00:00
bors
d5e229057c Auto merge of #30681 - Toby-S:master, r=bluss
Make `".".parse::<f32>()` and `".".parse::<f64>()` return Err

This fixes #30344.

This is a [breaking-change], which the libs team have classified as a
bug fix.
2016-01-04 23:57:46 +00:00
Scott Olson
080994a189 Add 'mut' to MIR temp variable debug output. 2016-01-04 16:11:33 -06:00
Scott Olson
c9a7171e10 Pretty-print ReturnPointer as 'return' in MIR. 2016-01-04 16:11:33 -06:00
Scott Olson
19a50e4f2a Pretty-print static lvalues in MIR as just their path. 2016-01-04 16:11:33 -06:00