Commit Graph

444 Commits

Author SHA1 Message Date
Eduard Burtescu
d1d16c94c5 rustc: rename ProjectionMode and its variant to be more memorable. 2016-08-12 06:43:34 +03:00
bors
8787a12334 Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner
Rollup of 23 pull requests

- Successful merges: #35279, #35331, #35358, #35375, #35445, #35448, #35482, #35486, #35505, #35528, #35530, #35532, #35536, #35537, #35541, #35552, #35554, #35555, #35557, #35562, #35565, #35569, #35576
- Failed merges: #35395, #35415, #35563
2016-08-11 13:14:28 -07:00
Scott A Carr
d77a136437 add SetDiscriminant StatementKind to enable deaggregation of enums 2016-08-11 11:51:20 -07:00
Jonathan Turner
d2e9573194 Rollup merge of #35445 - pcn:update-E0017-to-new-format, r=arielb1
Update e0017 to new format

Updated `span_err!` to use `struct_span_err!` and provide a `span_label` that describes the error in context.

Updated the test to look for the `span_label`s that are provided now.
2016-08-11 06:33:58 -07:00
bors
42001edc99 Auto merge of #35403 - scottcarr:lvalue_refactor, r=nikomatsakis
refactor lvalue_ty to be method of lvalue

Currently `Mir` (and `MirContext`) implement a method `lvalue_ty` (and actually many more `foo_ty`).  But this should be a method of `Lvalue`.

If you have an `lvalue` and you want to get its type, the natural thing to write is:

```
lvalue.ty()
```

Of course it needs context, but still:

```
lvalue.ty(mir, tcx)
```

Makes more sense than

```
mir.lvalue_ty(lvalue, tcx)
```

I actually think we should go a step farther and have traits so we could get the type of some value generically, but that's up for debate.  The thing I'm running into a lot in the compiler is I have a value of type `Foo` and I know that there is some related type `Bar` which I can get through some combination of method calls, but it's often not as direct as I would imagine.  Unless you already know the code, its not clear why you would look in `Mir` for a method to get the type of an `Lvalue`.
2016-08-11 05:04:41 -07:00
bors
e1d2bc2916 Auto merge of #35166 - nikomatsakis:incr-comp-ice-34991-2, r=mw
Address ICEs running w/ incremental compilation and building glium

Fixes for various ICEs I encountered trying to build glium with incremental compilation enabled. Building glium now works. Of the 4 ICEs, I have test cases for 3 of them -- I didn't isolate a test for the last commit and kind of want to go do other things -- most notably, figuring out why incremental isn't saving much *effort*.

But if it seems worthwhile and I can come back and try to narrow down the problem.

r? @michaelwoerister

Fixes #34991
Fixes #32015
2016-08-09 10:00:54 -07:00
Niko Matsakis
8fdc72f830 track MIR through the dep-graph
Per the discussion on #34765, we make one `DepNode::Mir` variant and use
it to represent both the MIR tracking map as well as passes that operate
on MIR. We also track loads of cached MIR (which naturally comes from
metadata).

Note that the "HAIR" pass adds a read of TypeckItemBody because it uses
a myriad of tables that are not individually tracked.
2016-08-08 18:44:24 -04:00
Scott A Carr
9f8093856d refactor other type methods 2016-08-08 13:35:10 -07:00
Peter C. Norton
ec1ef79ad9 Updated the messages for E0017
- Fix note message, fix tests.
2016-08-07 10:29:50 -04:00
Peter C. Norton
dfb66c3e2b Update E0010 to use the new format
For https://github.com/rust-lang/rust/issues/35194
2016-08-07 10:27:42 -04:00
Scott A Carr
28abc0a6aa refactor lvalue_ty to be method of lvalue 2016-08-05 15:59:51 -07:00
bors
e804a3cf25 Auto merge of #35168 - scottcarr:deaggregation, r=nikomatsakis
[MIR] Deaggregate structs to enable further optimizations

Currently, we generate MIR like:

```
tmp0 = ...;
tmp1 = ...;
tmp3 = Foo { a: ..., b: ... };
```

This PR implements "deaggregation," i.e.:

```
tmp3.0 = ...
tmp3.1 = ...
```

Currently, the code only deaggregates structs, not enums.  My understanding is that we do not have MIR to set the discriminant of an enum.
2016-08-04 03:01:37 -07:00
Scott A Carr
06acf16cdb reduce rightward drift, add precondition comment 2016-08-03 11:10:38 -07:00
Scott A Carr
d918c990de add hashtag to emphasis its a gh issue 2016-08-02 12:30:57 -07:00
Scott A Carr
e8bfba7dc8 fix field type, add test 2016-08-02 11:24:55 -07:00
Scott A Carr
bda46c21fe reduce rightward drift, add fixme 2016-08-02 10:46:26 -07:00
Scott A Carr
62cdbea8c9 deaggregate structs to enable further optimization 2016-08-01 15:57:10 -07:00
Michael Woerister
415fde498a intravisit: Fold functionality of IdVisitor into the regular Visitor. 2016-07-29 04:55:31 -04:00
bors
d46ed83e2e Auto merge of #34715 - scottcarr:mir-test, r=nikomatsakis
Add MIR Optimization Tests

I've starting working on the infrastructure for testing MIR optimizations.

The plan now is to have a set of test cases (written in Rust), compile them with -Z dump-mir, and check the MIR before and after each pass.
2016-07-21 19:44:59 -07:00
Scott A Carr
8f9844dd5c add mir optimization tests, dump-mir-dir option 2016-07-20 19:41:39 -07:00
Seo Sanghyeon
b91acc9f2a Remove extra newlines in MIR dump 2016-07-14 05:29:50 +09:00
bors
6871b3f240 Auto merge of #34657 - oli-obk:no_needless_const_eval, r=eddyb
don't const eval constants during MIR creation

this didn't work very well anyway, because const_eval can't eval all kinds of constants.
2016-07-10 06:43:47 -07:00
Vadim Petrochenkov
9c05fb29d2 Merge PatKind::QPath into PatKind::Path in HIR 2016-07-08 12:42:57 +03:00
Vadim Petrochenkov
ba419a78f3 Cleanup of some pattern related code 2016-07-08 12:36:45 +03:00
Oliver Schneider
e7b083aeae
don't const eval constants during MIR creation
this didn't work very well anyway, because const_eval can't eval all kinds of constants.
2016-07-05 08:20:02 +02:00
Jeffrey Seyfried
542ba8c5f7 Fix Cargo.tomls 2016-06-27 18:30:46 +00:00
Jonathan Turner
6ae3502134 Move errors from libsyntax to its own crate 2016-06-23 08:07:35 -04:00
bors
be203ac258 Auto merge of #34306 - arielb1:mir-dump-fixes, r=eddyb
Fixes for `-Z dump-mir`

Do not overwrite the parent MIR when dumping promoted MIR.

r? @eddyb
2016-06-16 21:57:06 -07:00
Simonas Kazlauskas
04d63ccf5a Cache drops for early scope exits
Previously we would rebuild all drops on every early exit from a scope, which for code like:

```rust
match x {
    a => return 1,
    b => return 2,
    ...
    z => return 27
}
```

would produce 27 exactly same chains of drops for each return, a O(n*m) explosion in drops.
2016-06-17 00:00:44 +03:00
Ariel Ben-Yehuda
a6d694ea00 fix MirSource::Promoted handling 2016-06-16 17:30:09 +03:00
Ariel Ben-Yehuda
5da8bf8402 stop having 'static in dump-mir names 2016-06-16 16:54:20 +03:00
Ariel Ben-Yehuda
63cdd7ab50 use a different filename for original and promoted MIRs 2016-06-16 16:54:20 +03:00
bors
f80ff7da39 Auto merge of #34174 - shepmaster:16-bit-mir, r=Aatch
Support 16-bit pointers in MIR
2016-06-10 19:50:42 -07:00
Vadim Petrochenkov
6d7b35bd98 Address review comments + fix rebase 2016-06-10 01:06:37 +03:00
Ariel Ben-Yehuda
e783a0a5e3 make all pattern bindings with the same name resolve to the first one
This simplifies the code considerably, removing one of the
last uses of hygienic matching out of resolution.
2016-06-10 01:06:37 +03:00
Vadim Petrochenkov
ee4e55398b Introduce TyCtxt::expect_def/expect_resolution helpers and use them where possible 2016-06-10 01:03:54 +03:00
Jake Goulding
e51958ba72 Support getting the minimum 16-bit isize value 2016-06-09 17:02:20 -04:00
Ariel Ben-Yehuda
ce4fdefbd8 fix issues 2016-06-09 21:47:58 +03:00
Ariel Ben-Yehuda
f5b1ba6e90 use the type name as the pass name 2016-06-09 15:24:46 +03:00
Ariel Ben-Yehuda
065a264976 refactor simplify_cfg and split off simplify_branches 2016-06-09 15:24:43 +03:00
Ariel Ben-Yehuda
2ee00e6d9d add hook infrastructure for automatically dumping MIR on every pass 2016-06-09 15:21:43 +03:00
Ariel Ben-Yehuda
798be90648 introduce an unreachable terminator
Use it instead of a `panic` for inexhaustive matches and correct the
comment. I think we trust our match-generation algorithm enough to
generate these blocks, and not generating an `unreachable` means that
LLVM won't optimize `match void() {}` to an `unreachable`.
2016-06-09 15:16:15 +03:00
Ariel Ben-Yehuda
6405527ded add a cache for MIR predecessors 2016-06-09 15:01:45 +03:00
Ariel Ben-Yehuda
e3af9fa490 make the basic_blocks field private 2016-06-09 14:55:19 +03:00
Ariel Ben-Yehuda
bc1eb67721 introduce the type-safe IdxVec and use it instead of loose indexes 2016-06-09 14:26:08 +03:00
Ariel Ben-Yehuda
e9003c5574 merge the RemoveDeadBlocks pass into the SimplifyCfg pass 2016-06-09 13:23:00 +03:00
Ariel Ben-Yehuda
b2100cc7b5 fix damage in librustc 2016-06-09 00:38:38 +03:00
Ariel Ben-Yehuda
5c717a6fc2 implement RFC495 semantics for slice patterns
non-MIR translation is still not supported for these and will happily ICE.

This is a [breaking-change] for many uses of slice_patterns.
2016-06-09 00:38:38 +03:00
Ariel Ben-Yehuda
70c25c848c remove the librustc_trans -> librustc_mir dependency 2016-06-08 23:58:53 +03:00
Eduard Burtescu
0c5930ef25 mir: group span + visibility scope under a new SourceInfo type. 2016-06-07 19:21:56 +03:00
Eduard Burtescu
719a591630 mir: distinguish between variable visibility scopes and SEME scopes. 2016-06-07 18:50:58 +03:00
Eduard Burtescu
f158a2f69d mir: remove unused float support from zero_literal. 2016-06-05 22:32:11 +03:00
bors
8cbffc5bcf Auto merge of #33905 - eddyb:mir-overflow, r=nikomatsakis
[MIR] Implement overflow checking

The initial set of changes is from @Aatch's #33255 PR, rebased on master, plus:

Added an `Assert` terminator to MIR, to simplify working with overflow and bounds checks.
With this terminator, error cases can be accounted for directly, instead of looking for lang item calls.
It also keeps the MIR slimmer, with no extra explicit blocks for the actual panic calls.

Warnings can be produced when the `Assert` is known to always panic at runtime, e.g.:
```rust
warning: index out of bounds: the len is 1 but the index is 3
 --> <anon>:1:14
1 |> fn main() { &[std::io::stdout()][3]; }
  |>              ^^^^^^^^^^^^^^^^^^^^^^
```

Generalized the `OperandValue::FatPtr` optimization to any aggregate pair of immediates.
This allows us to generate the same IR for overflow checks as old trans, not something worse.
For example, addition on `i16` calls `llvm.sadd.with.overflow.i16`, which returns `{i16, i1}`.
However, the Rust type `(i16, bool)`, has to be `{i16, i8}`, only an immediate `bool` is `i1`.
But if we split the pair into an `i16` and an `i1`, we can pass them around as such for free.

The latest addition is a rebase of #34054, updated to work for pairs too. Closes #34054, fixes #33873.

Last but not least, the `#[rustc_inherit_overflow_checks]` attribute was introduced to control the
overflow checking behavior of generic or `#[inline]` functions, when translated in another crate.

It is **not** intended to be used by crates other than `libcore`, which is in the unusual position of
being distributed as only an optimized build with no checks, even when used from debug mode.
Before MIR-based translation, this worked out fine, as the decision for overflow was made at
translation time, in the crate being compiled, but MIR stored in `rlib` has to contain the checks.

To avoid always generating the checks and slowing everything down, a decision was made to
use an attribute in the few spots of `libcore` that need it (see #33255 for previous discussion):
* `core::ops::{Add, Sub, Mul, Neg, Shl, Shr}` implementations for integers, which have `#[inline]` methods and can be used in generic abstractions from other crates
* `core::ops::{Add, Sub, Mul, Neg, Shl, Shr}Assign` same as above, for augmented assignment
* `pow` and `abs` methods on integers, which intentionally piggy-back on built-in multiplication and negation, respectively, to get overflow checks
* `core::iter::{Iterator, Chain, Peek}::count` and `core::iter::Enumerate::{next, nth}`, also documented as panicking on overflow, from addition, counting elements of an iterator in an `usize`
2016-06-05 06:08:37 -07:00
Eduard Burtescu
d8dddbf201 Respect #[rustc_inherit_overflow_checks] in mir::build and trans. 2016-06-05 14:41:03 +03:00
Eduard Burtescu
4adc967ed1 mir: report when overflow checks would be missing cross-crate. 2016-06-05 14:41:03 +03:00
Eduard Burtescu
156b1fb9e1 Add a new Assert terminator to MIR for bounds & arithmetic checks. 2016-06-05 14:41:02 +03:00
James Miller
7fbff36d01 Change with_cond to build_cond_br
This is simpler to work with than `with_cond`.
2016-06-05 14:02:24 +03:00
James Miller
f2c983b248 Add a with_cond method
Factors out the common pattern across the several places that do
arithmetic checks
2016-06-05 14:02:24 +03:00
James Miller
73f3054288 Check arithmetic in the MIR
Add, Sub, Mul, Shl, and Shr are checked using a new Rvalue:
CheckedBinaryOp, while Div, Rem and Neg are handled with explicit checks
in the MIR.
2016-06-05 14:02:24 +03:00
bors
22b36c70f9 Auto merge of #33999 - scottcarr:master, r=nikomatsakis
generate fewer basic blocks for variant switches

CC #33567
Adds a new field to TestKind::Switch that tracks the variants that are actually matched against.  The other candidates target a common "otherwise" block.
2016-06-05 03:12:38 -07:00
Ariel Ben-Yehuda
4106ab24d7 break critical edges only when needed
the *only* place where critical edges need to be broken is on Call
instructions, so only break them there.
2016-06-05 09:27:26 +03:00
Ariel Ben-Yehuda
148f8422f3 check for is_cleanup violations in MIR typeck
There weren't any in practice, but as these cause MSVC-only problems, the
check looks like a good idea.
2016-06-03 16:11:18 +03:00
Ariel Ben-Yehuda
de7cb0fdd6 introduce DropAndReplace for translating assignments
this introduces a DropAndReplace terminator as a fix to #30380. That terminator
is suppsoed to be translated by desugaring during drop elaboration, which is
not implemented in this commit, so this breaks `-Z orbit` temporarily.
2016-06-03 16:11:18 +03:00
Scott A Carr
d4551ece5f remove trailing whitespace 2016-06-02 15:40:03 -07:00
bors
12d165352c Auto merge of #33583 - luqmana:tri-bool-mir, r=arielb1
MIR: Don't generate 3-armed boolean switch from match.

Fixes #33540.

Snippet from issue:
```Rust
fn foo(x: bool, y: bool) -> u32 {
    match (x, y) {
         (false, _) => 0,
         (_, false) => 1,
         (true, true) => 2,
    }
}
```

Generated MIR:
```
fn foo(arg0: bool, arg1: bool) -> u32 {
    let var0: bool;                      // "x" in scope 1 at 3bbm.rs:17:8: 17:9
    let var1: bool;                      // "y" in scope 1 at 3bbm.rs:17:17: 17:18
    let mut tmp0: (bool, bool);
    let mut tmp1: bool;
    let mut tmp2: bool;
    let mut tmp3: (&'static str, &'static str, u32);
    let mut tmp4: &'static (&'static str, &'static str, u32);

    bb0: {
        var0 = arg0;                     // scope 1 at 3bbm.rs:17:8: 17:9
        var1 = arg1;                     // scope 1 at 3bbm.rs:17:17: 17:18
        tmp1 = var0;                     // scope 5 at 3bbm.rs:18:12: 18:13
        tmp2 = var1;                     // scope 6 at 3bbm.rs:18:15: 18:16
        tmp0 = (tmp1, tmp2);             // scope 4 at 3bbm.rs:18:11: 18:17
        if((tmp0.0: bool)) -> [true: bb4, false: bb1]; // scope 3 at 3bbm.rs:19:10: 19:15
    }

    bb1: {
        return = const 0u32;             // scope 10 at 3bbm.rs:19:23: 19:24
        goto -> bb7;                     // scope 3 at 3bbm.rs:18:5: 22:6
    }

    bb2: {
        return = const 1u32;             // scope 11 at 3bbm.rs:20:23: 20:24
        goto -> bb7;                     // scope 3 at 3bbm.rs:18:5: 22:6
    }

    bb3: {
        return = const 2u32;             // scope 12 at 3bbm.rs:21:25: 21:26
        goto -> bb7;                     // scope 3 at 3bbm.rs:18:5: 22:6
    }

    bb4: {
        if((tmp0.1: bool)) -> [true: bb5, false: bb2]; // scope 3 at 3bbm.rs:20:13: 20:18
    }

    bb5: {
        if((tmp0.0: bool)) -> [true: bb3, false: bb6]; // scope 3 at 3bbm.rs:21:10: 21:14
    }

    bb6: {
        tmp4 = promoted0;                // scope 3 at 3bbm.rs:18:5: 22:6
        core::panicking::panic(tmp4);    // scope 3 at 3bbm.rs:18:5: 22:6
    }

    bb7: {
        return;                          // scope 0 at 3bbm.rs:17:1: 23:2
    }
}
```

Not sure about this approach. I was also thinking maybe just a standalone pass?

cc @arielb1, @nagisa
2016-06-02 10:55:43 -07:00
Luqman Aden
a97f6b35ac [MIR] Use If terminator for switches on bools rather than SwitchInt. 2016-06-01 21:02:36 -04:00
Scott A Carr
79bf586d4b switch to BitVector, simplify target_block logic
clarify comments and panic message
2016-06-01 10:23:56 -07:00
Scott A Carr
9d34c280d9 generate fewer basic blocks for variant switches 2016-05-31 17:08:00 -07:00
Ariel Ben-Yehuda
e3cff797a7 normalize types in MIR typeck after erasing regions 2016-05-31 18:42:47 +03:00
Vadim Petrochenkov
cf46820694 Refactor away some functions from hir::pat_util 2016-05-28 17:37:58 +03:00
Vadim Petrochenkov
216f5fba04 Separate bindings from other patterns in HIR 2016-05-28 00:54:29 +03:00
Vadim Petrochenkov
35ef09c38b Replace pat_adjust_pos with an iterator adapter 2016-05-26 11:11:58 +03:00
Vadim Petrochenkov
d69aeaf662 Implement .. in tuple (struct) patterns 2016-05-26 11:11:58 +03:00
bors
34fd686681 Auto merge of #33667 - pnkfelix:fixes-to-mir-dataflow, r=arielb1
Fixes to mir dataflow

Fixes to mir dataflow

This collects a bunch of changes to `rustc_borrowck::borrowck::dataflow` (which others have pointed out should probably migrate to some crate that isn't tied to the borrow-checker -- but I have not attempted that here, especially since there are competing approaches to dataflow that we should also evaluate).

These changes:
 1. Provide a family of related analyses: MovingOutStatements (which is what the old AST-based dataflo computed), as well as MaybeInitialized, MaybeUninitalized, and DefinitelyInitialized.
   * (The last two are actually inverses of each other; we should pick one and drop the other.)
 2. Fix bugs in the pre-existing analysis implementation, which was untested and thus some obvious bugs went unnoticed, which brings us to the third point:
 3. Add a unit test infrastructure for the MIR dataflow analysis.
   * The tests work by adding a new intrinsic that is able to query the analysis state for a particular expression (technically, a particular L-value).
   * See the examples in compile-fail/mir-dataflow/inits-1.rs and compile-fail/mir-dataflow/uninits-1.rs
   * These tests are only checking the results for MaybeInitialized, MaybeUninitalized, and DefinitelyInitialized; I am not sure if it will be feasible to generalize this testing strategy to the MovingOutStatements dataflow operator.
2016-05-25 12:34:39 -07:00
Vadim Petrochenkov
aad347c4f7 Remove hir::Ident 2016-05-16 22:25:08 +03:00
Felix S. Klock II
129b371cae One-line doc clarification for representation of unit type (). 2016-05-16 09:13:42 +02:00
Felix S. Klock II
4446e793da Expose pretty print routines that accept just mir (no need for a NodeId). 2016-05-16 09:13:42 +02:00
Felix S. Klock II
90b7a86268 rustc_mir::pretty refactoring: break fn write_fn_intro into two routines.
(The crucial thing these changes are working toward (but are not yet
in this commit) is a way to pretty-print MIR without having the
`NodeId` for that MIR in hand.)
2016-05-16 09:13:42 +02:00
Felix S. Klock II
306ca4ca4f rustc_mir::pretty: factor out scope entry/exit annotation computation. 2016-05-16 09:13:42 +02:00
bors
e7420fbbae Auto merge of #33620 - eddyb:oops-static-is-not-fn, r=dotdash
mir: always allow &mut [...] in static mut regardless of the array length.
2016-05-15 11:01:03 -07:00
bors
1a26d2364f Auto merge of #33607 - jonas-schievink:prettier-mir, r=eddyb
Some simple improvements to MIR pretty printing

In short, this PR changes the MIR printer so that it:

* places an empty line between the MIR for each item
* does *not* write an empty line before the first BB when there are no
  var decls
* aligns the "// Scope" comments 50 chars in (makes the output more
  readable)
* prints the scope comments as "// scope N at ..." instead of "//
  Scope(N) at ..."
* prints a prettier scope tree:
 * no more unbalanced delimiters!
 * no more "Parent" entry (these convey no useful information)
 * drop the "Scope()" and just print scope IDs
 * no braces when the scope is empty

In action: https://gist.github.com/jonas-schievink/1c11226cbb112892a9470ce0f9870b65
2016-05-15 01:14:10 -07:00
Manish Goregaokar
ea68dd8def Rollup merge of #33552 - dotdash:scfg, r=luqmana
[MIR] Enhance the SimplifyCfg pass to merge consecutive blocks

Updated from #30238, including the changes suggested by @Aatch.
2016-05-14 11:57:47 +02:00
Manish Goregaokar
36c4c6d433 Rollup merge of #33544 - dotdash:baby_dont_break_me_no_more, r=Aatch
Only break critical edges where actually needed

Currently, to prepare for MIR trans, we break _all_ critical edges,
although we only actually need to do this for edges originating from a
call that gets translated to an invoke instruction in LLVM.

This has the unfortunate effect of undoing a bunch of the things that
SimplifyCfg has done. A particularly bad case arises when you have a
C-like enum with N variants and a derived PartialEq implementation.

In that case, the match on the (&lhs, &rhs) tuple gets translated into
nested matches with N arms each and a basic block each, resulting in N²
basic blocks. SimplifyCfg reduces that to roughly 2*N basic blocks, but
breaking the critical edges means that we go back to N².

In nickel.rs, there is such an enum with roughly N=800. So we get about
640K basic blocks or 2.5M lines of LLVM IR. LLVM takes a while to
reduce that to the final "disr_a == disr_b".

So before this patch, we had 2.5M lines of IR with 640K basic blocks,
which took about about 3.6s in LLVM to get optimized and translated.
After this patch, we get about 650K lines with about 1.6K basic blocks
and spent a little less than 0.2s in LLVM.

cc #33111

r? @Aatch
2016-05-14 11:57:47 +02:00
Jonas Schievink
2c7e398935 Indent comments less
40 chars is still enough indentation (most common MIR statements don't
take more than 40 chars), and fits more easily in 80-character
terminals.
2016-05-13 23:40:06 +02:00
Jonas Schievink
95a968c426 Much smaller scope tree printing 2016-05-13 23:36:50 +02:00
Eduard Burtescu
55aae6f48e mir: always allow &mut [...] in static mut regardless of the array length. 2016-05-13 22:27:09 +03:00
bors
a581c82bdc Auto merge of #33541 - eddyb:promote-only-temps, r=arielb1
mir: don't attempt to promote Unpromotable constant temps.

Fixes #33537. This was a non-problem in regular functions, but we also promote in `const fn`s.
There we always qualify temps so you can't depend on `Unpromotable` temps being `NOT_CONST`.
2016-05-13 03:10:46 -07:00
Björn Steinbrink
8ad6d27f87 [MIR] Enhance the SimplifyCfg pass to merge consecutive blocks 2016-05-13 01:46:52 +02:00
Jonas Schievink
96b178b131 Some simple improvements to MIR pretty printing
In short, this PR changes the MIR printer so that it:

* places an empty line between the MIR for each item
* does *not* write an empty line before the first BB when there are no
  var decls
* aligns the "// Scope" comments 50 chars in (makes the output more
  readable)
* prints the scope comments as "// scope N at ..." instead of "//
  Scope(N) at ..."
* prints a prettier scope tree:
 * no more unbalanced delimiters!
 * no more "Parent" entry (these convey no useful information)
 * drop the "Scope()" and just print scope IDs
 * no braces when the scope is empty
2016-05-13 00:20:59 +02:00
Björn Steinbrink
00f6513259 Only break critical edges where actually needed
Currently, to prepare for MIR trans, we break _all_ critical edges,
although we only actually need to do this for edges originating from a
call that gets translated to an invoke instruction in LLVM.

This has the unfortunate effect of undoing a bunch of the things that
SimplifyCfg has done. A particularly bad case arises when you have a
C-like enum with N variants and a derived PartialEq implementation.

In that case, the match on the (&lhs, &rhs) tuple gets translated into
nested matches with N arms each and a basic block each, resulting in N²
basic blocks. SimplifyCfg reduces that to roughly 2*N basic blocks, but
breaking the critical edges means that we go back to N².

In nickel.rs, there is such an enum with roughly N=800. So we get about
640K basic blocks or 2.5M lines of LLVM IR. LLVM takes a while to
reduce that to the final "disr_a == disr_b".

So before this patch, we had 2.5M lines of IR with 640K basic blocks,
which took about about 3.6s in LLVM to get optimized and translated.
After this patch, we get about 650K lines with about 1.6K basic blocks
and spent a little less than 0.2s in LLVM.

cc #33111
2016-05-11 18:35:12 +02:00
bors
c049541741 Auto merge of #33239 - eddyb:mir-temp-drops, r=arielb1
mir: drop temps outside-in by scheduling the drops inside-out.

It was backwards all along, but only noticeable with multiple drops in one rvalue scope. Fixes #32433.
2016-05-11 03:15:05 -07:00
Eduard Burtescu
e940de64ca mir: drop temps outside-in by scheduling the drops inside-out. 2016-05-11 10:46:36 +03:00
Eduard Burtescu
a1c170fc35 rustc: Split local type contexts interners from the global one. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
20652162ca rustc: More interning for data used in Ty<'tcx>. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
12e56ea56b rustc: Wrap users of InferCtxt in an anonymous scope. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
8a704f6dc7 rustc: Remove the TyCtxt field from ParameterEnvironment. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
76affa5d6f rustc: Split 'tcx into 'gcx and 'tcx for InferCtxt and its users. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
513d392f7e rustc: Replace &'a TyCtxt<'tcx> with a TyCtxt<'a, 'tcx> wrapper. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
f8ea24edc8 rustc: Avoid free functions taking &TyCtxt and &InferCtxt. 2016-05-11 04:14:58 +03:00
Eduard Burtescu
0907c198c4 infer: Use methods for creating an InferCtxt. 2016-05-11 04:14:58 +03:00