Commit Graph

74 Commits

Author SHA1 Message Date
bors
e9ac44026d Auto merge of #29383 - petrochenkov:empstr, r=pnkfelix
Fixes https://github.com/rust-lang/rust/issues/28692
Fixes https://github.com/rust-lang/rust/issues/28992
Fixes some other similar issues (see the tests)

[breaking-change], needs crater run (cc @brson or @alexcrichton )

The pattern with parens `UnitVariant(..)` for unit variants seems to be popular in rustc (see the second commit), but mostly used by one person (@nikomatsakis), according to git blame. If it causes breakage on crates.io I'll add an exceptional case for it.
2015-11-28 00:45:34 +00:00
Niko Matsakis
1fe7525180 Rewrite stmt processing not to recurse to avoid stack overflow if there
are tons of let statements. Fixes #29466.
2015-11-24 19:31:48 -05:00
Niko Matsakis
6c10d74a32 Remove the GraphExtents, the design of which seems bogus. They carried
the right information, but it's hard to maintain in the face of
optimizations, and in the form that the analyses probably actually want.
2015-11-24 17:30:13 -05:00
Niko Matsakis
29a3fe32eb Add some comments to Mir struct. 2015-11-24 17:30:13 -05:00
Vadim Petrochenkov
35749923ee Fix the fallout 2015-11-19 11:41:09 +03:00
Vadim Petrochenkov
0f8519c341 Fix various bugs around empty structs and patterns 2015-11-19 11:39:18 +03:00
Niko Matsakis
e4ff9f71db Port a bunch of code new-visitor; all of these ports were
straightforward uses of `visit_all_items`. In some cases I had to remove
empty `visit_item` calls that were just to suppress visiting nested
items.
2015-11-18 19:22:18 -05:00
Michael Woerister
c533902285 MIR: Add pass that erases all regions right before trans 2015-11-18 17:26:24 +01:00
Oliver Schneider
e36872da5b ImplItem_ -> ImplItemKind rename 2015-11-16 10:35:30 +01:00
Oliver Schneider
eaaa60dbea rename ImplItem_::*ImplItem to ImplItem_::*
[breaking change]
2015-11-16 10:34:45 +01:00
bors
45087f36ce Auto merge of #29817 - michaelwoerister:mir-ty-closure-fields, r=nikomatsakis
Add a missing case in LvalueTy::projection_ty() that popped up earlier today.

cc @rust-lang/compiler @nikomatsakis
2015-11-14 06:08:09 +00:00
Ariel Ben-Yehuda
b9b45a0e96 address review comments 2015-11-14 00:09:36 +02:00
Ariel Ben-Yehuda
e82f5d4f54 implement coercions in MIR 2015-11-14 00:09:36 +02:00
Ariel Ben-Yehuda
cd1585ffb3 rustc_mir: don't miss the autoref when doing an unsize 2015-11-13 22:47:02 +02:00
Michael Woerister
9211883e54 MIR: Support closure up-vars in LvalueTy::projection_ty() 2015-11-13 17:01:37 +01:00
bors
098ea17556 Auto merge of #29757 - dotdash:mir_simplify_cfg, r=nikomatsakis
For now, this pass does some easy transformations, like eliminating
empty blocks that just jump to another block, some trivial
conversion of If terminators into Gotos and removal of dead blocks.

r? @nikomatsakis
2015-11-12 15:48:34 +00:00
Björn Steinbrink
a4e5c0fe84 Add a MIR pass to simplify the control flow graph
For now, this pass does some easy transformations, like eliminating
empty blocks that just jump to another block, some trivial
conversion of If terminators into Gotos and removal of dead blocks.
2015-11-12 14:39:23 +01:00
Manish Goregaokar
b7f6d7239b Rollup merge of #29776 - nikomatsakis:mir-29740, r=nrc
In previous PRs, I changed the match desugaring to generate more efficient code for ints/chars and the like. But this doesn't help when you're matching strings, ranges, or other crazy complex things (leading to #29740). This commit restructures match desugaring *yet again* to handle that case better -- basically we now degenerate to an if-else-if chain in such cases.

~~Note that this builds on https://github.com/rust-lang/rust/pull/29763 which will hopefully land soon. So ignore the first few commits.~~ landed now

r? @Aatch since he's been reviewing the other commits in this series
2015-11-12 13:18:51 +05:30
bors
35decad781 Auto merge of #29616 - nagisa:mir-repeat, r=nikomatsakis
r? @nikomatsakis

I went ahead and replaced repeat count with a `Constant`, because it cannot be non-constant to the best of my knowledge.
2015-11-12 02:24:06 +00:00
Simonas Kazlauskas
e4e880df37 Const-eval array element repetition count 2015-11-12 01:30:17 +02:00
Vadim Petrochenkov
fba1926a2f Fix hygiene regression in patterns 2015-11-12 01:49:23 +03:00
Niko Matsakis
662232c8f6 Rewrite match algorithm to avoid massive blowup in generated code for
large matches that fallback to Eq. When we encounter a case where the
test being performed does not inform the candidate at all, we just stop
testing the candidates at that point, rather than adding the candidate
to both outcomes. The former behavior was not WRONG, but it generated a
lot of code, whereas this new behavior degenerates to an if-else-if
tree.

Fixes #29740.
2015-11-11 16:38:58 -05:00
Niko Matsakis
3b903a7d10 Change from &mut Vec<Vec<_>> to &mut [Vec<_>], since the outer
`Vec` should not be resized.
2015-11-11 06:18:50 -05:00
Niko Matsakis
0471b3247d Reorganize match construction to be O(n) instead of O(n^2). Whereas
before we iterated over the test and each outcome thereof, and then
checked processed every candidate against this outcome, we now organize
the walk differently. Instead, we visit each candidate and say "Here is
the test being performed. Figure out the resulting candidates for each
possible outcome and add yourself into the appropriate places."
2015-11-10 22:18:06 -05:00
Niko Matsakis
61884e5543 Clone the candidates and match-pairs lazilly, instead of eagerly. 2015-11-10 22:18:06 -05:00
Niko Matsakis
87358728a4 Remove the mirroring for patterns and just convert them eagerly; then,
pass around references instead of boxed values to save on clone costs.
2015-11-10 22:18:06 -05:00
Simonas Kazlauskas
db89a75a80 use Constant for repetition count in mir::Repeat 2015-11-10 23:52:23 +02:00
bors
2f59977d96 Auto merge of #29615 - steveklabnik:lol_strings, r=alexcrichton
&format!("...") is the same as "" if we're not doing any interpolation,
and doesn't allocate an intermediate String.
2015-11-06 11:28:07 +00:00
bors
98fa2ac1bc Auto merge of #29588 - nikomatsakis:mir-switch, r=aatch
Introduce a `SwitchInt` and restructure pattern matching to collect integers and characters into one master switch. This is aimed at #29227, but is not a complete fix. Whereas before we generated an if-else-if chain and, at least on my machine, just failed to compile, we now spend ~9sec compiling `rustc_abuse`. AFAICT this is basically just due to a need for more micro-optimization of the matching process: perf shows a fair amount of time just spent iterating over the candidate list. Still, it seemed worth opening a PR with this step alone, since it's a big step forward.
2015-11-06 06:13:59 +00:00
Niko Matsakis
dcf323e586 Convert TODO into FIXME 2015-11-05 11:54:24 -05:00
Steve Klabnik
63576c23e4 remove excess string allocation
&format!("...") is the same as "" if we're not doing any interpolation,
and doesn't allocate an intermediate String.
2015-11-05 15:30:34 +01:00
Jonathan S
b1788ef8e1 Remove use of RefCell<DefMap> in the simpler parts of pat_util 2015-11-04 20:38:03 -06:00
Niko Matsakis
3e6b4545f9 Introduce a SwitchInt and restructure pattern matching to collect
integers and characters into one master switch.
2015-11-04 15:38:43 -05:00
Niko Matsakis
544b06d455 Add a MIR visitor 2015-11-03 06:34:23 -05:00
Niko Matsakis
0a62158a4e Add helper methods that require tcx; these compute types of
lvalues and operands
2015-11-03 04:35:00 -05:00
Niko Matsakis
044096b3e9 Change Call operands to be, well, Operands 2015-11-03 04:35:00 -05:00
Niko Matsakis
3ab29d3378 Add adt_def into Switch, since it's convenient to have in trans 2015-11-03 04:35:00 -05:00
Niko Matsakis
b5d3580843 Move the "HAIR" code that reads the tcx tables etc out of the tcx
module and into `hair/cx`, now that we don't have a trait defining
the interface
2015-11-03 04:35:00 -05:00
Niko Matsakis
15c1da4e27 Convert from using named fields to always using indices 2015-11-03 04:34:59 -05:00
Niko Matsakis
1e30f3e52b Change ShallowDrop to Free, so that it matches what trans will do 2015-11-03 04:34:59 -05:00
Niko Matsakis
88a9c3e764 Build the MIR using the liberated fn sigs, and track the return type 2015-11-03 04:34:59 -05:00
Vadim Petrochenkov
3468b8d42c Remove PatWildMulti 2015-10-31 03:44:43 +03:00
bors
540fd3aa71 Auto merge of #26848 - oli-obk:const_fn_const_eval, r=pnkfelix
this has the funky side-effect of also allowing constant evaluation of function calls to functions that are not `const fn` as long as `check_const` didn't mark that function `NOT_CONST`

It's still not possible to call a normal function from a `const fn`, but let statements' initialization value can get const evaluated (this caused the fallout in the overflowing tests)

we can now do this:

```rust
const fn add(x: usize, y: usize) -> usize { x + y }
const ARR: [i32; add(1, 2)] = [5, 6, 7];
```

also added a test for destructuring in const fn args
```rust
const fn i((a, b): (u32, u32)) -> u32 { a + b } //~ ERROR: E0022
```

This is a **[breaking change]**, since it turns some runtime panics into compile-time errors. This statement is true for ANY improvement to the const evaluator.
2015-10-27 17:11:13 +00:00
Alex Crichton
ff49733274 std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:

Stabilized APIs:

* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
   is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
  but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`

Deprecated APIs

* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`

Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-25 09:36:32 -07:00
Oliver Schneider
b4e30bd2a3 allow constant evaluation of function calls 2015-10-19 13:13:02 +02:00
Ms2ger
c73e78ce64 Partially format librustc_mir with rustfmt.
This commit contains some of the changes proposed by a rustfmt invocation,
chosen based on the fairly non-deterministic metric of how much I liked the
change. I expect we will run rustfmt on this crate again later, probably
accepting more of its changes. For now, this is already an improvement over
the status-quo.
2015-10-07 14:37:45 +02:00
Niko Matsakis
50c83a9061 remove now unnecessary trait impls 2015-10-06 17:15:54 -04:00
Niko Matsakis
0d51e80b6d fix some tidy complaints 2015-10-06 14:58:15 -04:00
Niko Matsakis
24ee4b1f6c rename dump to mir_map, which seems more suitable 2015-10-06 12:37:43 -04:00
Niko Matsakis
810cf71a3c make mir map available to later passes (currently unused) 2015-10-06 12:35:53 -04:00