Commit Graph

63753 Commits

Author SHA1 Message Date
Corey Farwell
9e621c2da8 Rollup merge of #41640 - gaurikholkar:master, r=nikomatsakis
Consider changing to & for let bindings #40402

This is a fix for #40402

For the example
```
fn main() {
    let v = vec![String::from("oh no")];

    let e = v[0];
}
```

It gives
```
error[E0507]: cannot move out of indexed content
 --> ex1.rs:4:13
  |
4 |     let e = v[0];
  |             ^^^^ cannot move out of indexed content
  |
  = help: consider changing to `&v[0]`

error: aborting due to previous error
```

Another alternative is
```
error[E0507]: cannot move out of indexed content
 --> ex1.rs:4:13
  |
4 |     let e = v[0];
  |             ^^^^ consider changing to `&v[0]`

error: aborting due to previous error
```
Also refer to #41564 for more details.

r? @nikomatsakis
2017-05-02 21:21:19 -04:00
Corey Farwell
cfff3699aa Rollup merge of #41625 - nikomatsakis:incr-comp-dep-tracking-cell-mir, r=eddyb
rework the queries for the MIR pipeline

This PR refashions the MIR pipeline. There are a number of changes:

* We no longer have "MIR passes" and the pass manager is completely reworked. Unless we are doing the interprocedural optimization (meaning, right now, the inline pass), we will process a single MIR from beginning to finish in a completely on-demand fashion; i.e., when you request `optimized_mir(D)`, that will trigger the MIR for `D` to actually be built and optimized, but no other functions are built or touched.
* We no longer use `&'tcx RefCell<Mir<'tcx>>` as the result of queries, since that spoils the view of queries as "pure functions". To avoid however copying the MIR, we use a `&'tcx Steal<Mir<'tcx>>` -- this is something like a ref-cell, in that you can use `borrow()` to read it, but it has no `borrow_mut()`. Instead, it has `steal()`, which will take the contents and then panic if any further read attempt occurs.
* We now support `[multi]` queries, which can optionally yield not just one result but a sequence of (K, V) pairs. This is used for the inlining pass. If inlining is enabled, then when it is invoked on **any** def-id D, it will go and read the results for **all** def-ids and transform them, and then return the results for all of them at once. This isn't ideal, and we'll probably want to rework this further, but it seems ok for now (note that MIR inlining is not enabled by default).

**Tips for the reviewer:** The commits here are meant to build individually, but the path is a *bit* meandering. In some cases, for example, I introduce a trait in one commit, and then tweak it in a later commit as I actually try to put it to use. You may want to read the README in the final commit to get a sense of where the overall design is headed.

@eddyb I did not wind up adding support for queries that produce more than one *kind* of result. Instead, I decided to just insert judicious use of the `force()` command. In other words, we had talked about e.g. having a query that produced not only the MIR but also the `const_qualif` result for the MIR in one sweep. I realized you can also have the same effect by having a kind of meta-query that forces the const-qualif pass and then reads the result. See the README for a description. (We can still do these "multi-query results" later if we want, I'm not sure though if it is necessary.)

r? @eddyb

cc @michaelwoerister @matthewhammer @arielb1, who participated in the IRC discussion.
2017-05-02 21:21:18 -04:00
Corey Farwell
1a5284c32b Rollup merge of #41217 - topecongiro:docs/atomic-fence, r=steveklabnik
Update docs of 'fence'

This PR updates the docs for `std::sync::atomic::fence` with an example and a diagram.
Part of #29377.
r? @steveklabnik
2017-05-02 21:21:17 -04:00
bors
4d81b14b80 Auto merge of #41605 - tschottdorf:param-env, r=nikomatsakis
Store interned predicates in ParameterEnvironment

See #41444. As a first step towards untangling `ParameterEnvironment`, change
its `caller_bounds` field from a `Vec` into an interned slice of
`ty::Predicate`s.

This change is intentionally well-contained and doesn't pull on any of the
loose ends. In particular, you'll note that `normalize_param_env_or_error`
now interns twice.
2017-05-02 20:44:03 +00:00
Niko Matsakis
488b2a3e7b add FIXME to Steal 2017-05-02 16:21:58 -04:00
Niko Matsakis
25be7983e8 remove mir_passes from Session and add a FIXME 2017-05-02 16:21:58 -04:00
Niko Matsakis
afc5acd84b fix librustc_driver 2017-05-02 16:21:58 -04:00
Niko Matsakis
e6793ac452 have borrowck fetch MIR, which will perform some errors 2017-05-02 16:21:58 -04:00
Niko Matsakis
15bc2f4ca0 remove temporary variable 2017-05-02 16:21:57 -04:00
Niko Matsakis
0afcfce8d8 update comment about heuristics 2017-05-02 16:21:57 -04:00
Niko Matsakis
b0092e89e0 move queries code into transform 2017-05-02 16:21:57 -04:00
Niko Matsakis
393fa4f1b7 rename from item_mir to optimized_mir 2017-05-02 16:21:57 -04:00
Niko Matsakis
c7023d1c2f run MIR borrowck on the validated, not optimized, MIR 2017-05-02 16:21:57 -04:00
Niko Matsakis
74b2783877 delete dead code 2017-05-02 16:21:56 -04:00
Niko Matsakis
2fa1ba3e7e pacify the mercilous tidy 2017-05-02 16:21:56 -04:00
Niko Matsakis
851a880f52 remove irrelevant comments 2017-05-02 16:21:56 -04:00
Niko Matsakis
1dd9c3e52a support inlining by asking for optimizer mir for callees
I tested this with it enabled 100% of the time, and we were able to run
mir-opt tests successfully.
2017-05-02 16:21:56 -04:00
Niko Matsakis
669d31683f simplify down to one query per pass suite 2017-05-02 16:21:55 -04:00
Niko Matsakis
9c154a67bf rip out everything but MirPass, move the logic into suites 2017-05-02 16:21:55 -04:00
Niko Matsakis
c253df5249 remove Pass and (temporarily) drop Inline 2017-05-02 16:21:55 -04:00
Niko Matsakis
69c8f9dd25 move build_mir into build directory 2017-05-02 16:21:55 -04:00
Tobias Schottdorf
a6658d5ff1 Store interned predicates in ParameterEnvironment
See #41444. As a first step towards untangling `ParameterEnvironment`, change
its `caller_bounds` field from a `Vec` into an interned slice of
`ty::Predicate`s.

This change is intentionally well-contained and doesn't pull on any of the
loose ends. In particular, you'll note that `normalize_param_env_or_error`
now interns twice.
2017-05-02 14:37:00 -04:00
Niko Matsakis
c2cfdbbdf9 adjust privacy of various types in build 2017-05-02 14:01:37 -04:00
Niko Matsakis
c1ff10464d rename mir_map to queries and remove build_mir_for_crate 2017-05-02 14:01:37 -04:00
Niko Matsakis
532439faa1 add a README describing the whole design 2017-05-02 14:01:37 -04:00
Niko Matsakis
d9c8a2b54b use force to ensure const-qualif has been done, not read 2017-05-02 14:01:36 -04:00
Niko Matsakis
0d045d73a7 add comments to Steal and use bug! 2017-05-02 14:01:36 -04:00
Niko Matsakis
a26e966307 convert the inline pass to use the new multi result
This involves changing various details about that system,
though the basic shape remains the same.
2017-05-02 14:01:36 -04:00
Niko Matsakis
1d675ce0a3 adjust the macro to allow for multi modifier 2017-05-02 14:01:36 -04:00
Niko Matsakis
3d1095c5be introduce IntoKeyValues trait to prepare for multi-queries
The idea is that such queries will return `FxHashMap`
2017-05-02 14:01:36 -04:00
Niko Matsakis
ecc8ff9199 rework macro to prepare for more modifiers than just [pub] 2017-05-02 14:01:35 -04:00
Niko Matsakis
29263fdb54 introduce idea of "stealable" MIR
This is a more principled version of the `RefCell` we were using
before. We now allocate a `Steal<Mir<'tcx>>` for each intermediate MIR
pass; when the next pass steals the entry, any later attempts to use it
will panic (there is no way to *test* if MIR is stolen, you're just
supposed to *know*).
2017-05-02 14:01:34 -04:00
Niko Matsakis
e89a321dff rename MirPassSet to MirSuite
This seems like a better noun.
2017-05-02 14:01:01 -04:00
Niko Matsakis
2b32cb90c7 retool MIR passes completely
The new setup is as follows. There is a pipeline of MIR passes that each
run **per def-id** to optimize a particular function. You are intended
to request MIR at whatever stage you need it. At the moment, there is
only one stage you can request:

- `optimized_mir(def_id)`

This yields the final product. Internally, it pulls the MIR for the
given def-id through a series of steps. Right now, these are still using
an "interned ref-cell" but they are intended to "steal" from one
another:

- `mir_build` -- performs the initial construction for local MIR
- `mir_pass_set` -- performs a suite of optimizations and transformations
- `mir_pass` -- an individual optimization within a suite

So, to construct the optimized MIR, we invoke:

    mir_pass_set((MIR_OPTIMIZED, def_id))

which will build up the final MIR.
2017-05-02 14:01:01 -04:00
Niko Matsakis
f23a7bc98a move to only def-id passes
this temporary disables `inline`
2017-05-02 14:01:01 -04:00
Niko Matsakis
668886a6cc rewrite Passes to have sets of passes
Also, store the completed set of passes in the tcx.
2017-05-02 14:01:01 -04:00
Niko Matsakis
e9e6ccc042 introduce DefIdPass and remove all impls of Pass but Inline 2017-05-02 14:01:01 -04:00
Niko Matsakis
46b342fbc0 simplify the MirPass traits and passes dramatically
Overall goal: reduce the amount of context a mir pass needs so that it
resembles a query.

- The hooks are no longer "threaded down" to the pass, but rather run
  automatically from the top-level (we also thread down the current pass
  number, so that the files are sorted better).
  - The hook now receives a *single* callback, rather than a callback per-MIR.
- The traits are no longer lifetime parameters, which moved to the
  methods -- given that we required
  `for<'tcx>` objecs, there wasn't much point to that.
- Several passes now store a `String` instead of a `&'l str` (again, no
  point).
2017-05-02 14:01:01 -04:00
Niko Matsakis
11b6b0663a rework MirPass API to be stateless and extract helper fns 2017-05-02 14:01:00 -04:00
Niko Matsakis
0e5e2f3634 introduce mir_keys()
Each MIR key is a DefId that has MIR associated with it
2017-05-02 14:01:00 -04:00
bors
6a5fc9eece Auto merge of #41207 - sstewartgallus:spinpause, r=alexcrichton
Spin loop pause function redux

GitHub's interface is screwy.

This is the same PR as https://github.com/rust-lang/rust/pull/40537
2017-05-02 17:48:28 +00:00
bors
ed1f26ddda Auto merge of #41702 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #41661, #41662, #41673, #41688, #41692, #41693
- Failed merges:
2017-05-02 14:56:11 +00:00
Corey Farwell
e0bfd19add Rollup merge of #41693 - est31:anon_params_removal, r=eddyb
Removal pass for anonymous parameters

Removes occurences of anonymous parameters from the
rustc codebase, as they are to be deprecated.

See issue #41686 and RFC 1685.

r? @frewsxcv
2017-05-02 09:09:59 -04:00
Corey Farwell
4733ee7eb4 Rollup merge of #41692 - est31:anon_params, r=eddyb
Add a lint to disallow anonymous parameters

Adds a (allow by default) lint to disallow anonymous parameters, like it was decided in RFC 1685 (rust-lang/rfcs#1685).

cc tracking issue #41686
2017-05-02 09:09:58 -04:00
Corey Farwell
7dbb93a391 Rollup merge of #41688 - rust-lang:hex-value-process-exit, r=sfackler
Fix incorrect hex value in doc comment example.

Fixes https://github.com/rust-lang/rust/issues/41682.
2017-05-02 09:09:57 -04:00
Corey Farwell
b8fc516486 Rollup merge of #41673 - bitshifter:repr-align-codegen-test, r=arielb1
Add simple `[repr(align)]` codegen test.

Checks alloca and memcpy are aligned correctly.

Test added to as additional check for #33626.
2017-05-02 09:09:56 -04:00
Corey Farwell
137660763b Rollup merge of #41662 - nikomatsakis:on-demandify-region-mapping, r=eddyb
On demandify region mapping

This is an adaptation of @cramertj's PR. I am sort of tempted to keep simplifying it, but also tempted to land it so and we can refactor more in follow-up PRs. As is, it does the following things:

- makes the region-maps an on-demand query, per function `tcx.region_maps(def_id)`
- interns code extents instead of of having them be integers
- remove the "root region extent" and (to some extent) item extents; instead we use `Option<CodeExtent<'tcx>>` in a few places (no space inefficiency since `CodeExtent<'tcx>` is now a pointer).

I'm not entirely happy with the way I have it setup though. Here are some of the changes I was considering (I'm not sure if they would work out well):

1. Removing `item_extents` entirely -- they are rarely used now, because most of the relevant places now accept an `Option<Region<'tcx>>` or an `Option<CodeExtent<'tcx>>`, but I think still used in a few places.
2. Merging `RegionMaps` into the typeck tables, instead of having it be its own query.
3. Change `CodeExtent<'tcx>` to store the parent pointer. This would mean that fewer places in the code actually *need* a `RegionMaps` anyhow, since most of them just want to be able to walk "up the tree". On the other hand, you wouldn't be able to intern a `CodeExtent<'tcx>` for some random node-id, you'd need to look it up in the table (since there'd be more information).

Most of this code is semi-temporary -- I expect it to largely go away as we move to NLL -- so I'm also not *that* concerned with making it perfect.

r? @eddyb
2017-05-02 09:09:55 -04:00
Corey Farwell
5b4e8d0917 Rollup merge of #41661 - barik:master, r=alexcrichton
Under MinGW, x.py fails to run with UnboundLocalError.

Under MinGW, `x.py` will fail with the following errors:

```bash
$ ./x.py
Traceback (most recent call last):
  File "./x.py", line 20, in <module>
    bootstrap.main()
  File "C:/src/rust/src/bootstrap/bootstrap.py", line 620, in main
    bootstrap()
  File "C:/src/rust/src/bootstrap/bootstrap.py", line 601, in bootstrap
    rb.build = rb.build_triple()
  File "C:/src/rust/src/bootstrap/bootstrap.py", line 459, in build_triple
    if os.environ.get('MSYSTEM') == 'MINGW64':
UnboundLocalError: local variable 'os' referenced before assignment
```

The reason is due to the `build_triple` function in `src/bootstrap/bootstrap.py` (Line 416):

```python
if ostype == 'Linux':
    os = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding)

```

Here, the assignment to `os` is causing the `os` module to be shadowed.

Then, in (Line 459):

```python
if os.environ.get('MSYSTEM') == 'MINGW64':
    cputype = 'x86_64'
```

`os` now refers to the uninitialized local variable, not the `os` module.

Easiest fix is to simply rename the `os` variable to something like `os_from_sp`.

Also, there is a small typo fix in `x.py` referencing the wrong file name.
2017-05-02 09:09:54 -04:00
gaurikholkar
1c57bb4219 Using a span_suggestion to display use & hint 2017-05-02 05:44:55 -07:00
gaurikholkar
478b7d9a7a Adding consider changing to & suggestion for let bindings 2017-05-02 05:44:55 -07:00