Commit Graph

63724 Commits

Author SHA1 Message Date
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
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
bors
96e2c34286 Auto merge of #41547 - alexeyzab:41425-fix-mismatched-types-error-message, r=arielb1
Fix error message for mismatched types

This addresses #41425 by implementing the changes mentioned in the
following comment:
https://github.com/rust-lang/rust/issues/41425#issuecomment-296754508
2017-05-02 12:11:54 +00:00
bors
50517d58a2 Auto merge of #41488 - estebank:closure-args, r=arielb1
Clean up callable type mismatch errors

```rust
error[E0593]: closure takes 1 argument but 2 arguments are required here
  --> ../../src/test/ui/mismatched_types/closure-arg-count.rs:13:15
   |
13 |     [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
   |               ^^^^^^^ -------------------------- takes 1 argument
   |               |
   |               expected closure that takes 2 arguments
```

instead of

```rust
error[E0281]: type mismatch: the type `[closure@../../src/test/ui/mismatched_types/closure-arg-count.rs:13:23: 13:49]` implements the trait `for<'r> std::ops::FnMut<(&'r {integer},)>`, but the trait `for<'r, 'r> std::ops::FnMut<(&'r {integer}, &'r {integer})>` is required (expected a tuple with 2 elements, found one with 1 elements)
  --> ../../src/test/ui/mismatched_types/closure-arg-count.rs:13:15
   |
13 |     [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
   |               ^^^^^^^
```

Fix #21857, re #24680.
2017-05-02 09:41:39 +00:00
est31
14bbd0a5a3 Address review 2017-05-02 06:35:36 +02:00
est31
d290849a23 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.
2017-05-02 05:55:20 +02:00
est31
6cc765dcad Add a lint to disallow anonymous parameters 2017-05-02 05:15:26 +02:00
bors
33535afda4 Auto merge of #40851 - oli-obk:multisugg, r=jonathandturner
Minimize single span suggestions into a label

changes

```
14 |     println!("☃{}", tup[0]);
   |                     ^^^^^^
   |
help: to access tuple elements, use tuple indexing syntax as shown
   |     println!("☃{}", tup.0);
```

into

```
14 |     println!("☃{}", tup[0]);
   |                     ^^^^^^ to access tuple elements, use `tup.0`
```

Also makes suggestions explicit in the backend in preparation of adding multiple suggestions to a single diagnostic. Currently that's already possible, but results in a full help message + modified code snippet per suggestion, and has no rate limit (might show 100+ suggestions).
2017-05-02 01:04:27 +00:00
Corey Farwell
7423966714 Fix incorrect hex value in doc comment example. 2017-05-01 20:38:59 -04:00
Niko Matsakis
c008f0540e patch the librustc_driver unit tests 2017-05-01 20:11:36 -04:00
bors
de4bdd20f8 Auto merge of #41629 - Mark-Simulacrum:re-enable-tests, r=nikomatsakis
Unignore tests which work fine now.

As far as I can tell, these tests will now work fine. #13745 tracks the remaining tests which are ignored for various reasons.
2017-05-01 22:36:44 +00:00
bors
777ee20796 Auto merge of #41611 - cramertj:metadata-queries-1, r=nikomatsakis
Queryify crate metadata

Part of https://github.com/rust-lang/rust/issues/41417.

r? @nikomatsakis
2017-05-01 19:53:19 +00:00
Niko Matsakis
b393d64360 kill regr test using ad-hoc lint
This was a pretty narrow test to start with, and it's kind of a pain to
update it. Not worth the trouble IMO.
2017-05-01 13:24:25 -04:00
Taylor Cramer
daa0094eb7 Queryify is_item_mir_available 2017-05-01 10:24:10 -07:00
Taylor Cramer
fb4380b12d Queryify const_is_rvalue_promotable_to_static 2017-05-01 10:24:10 -07:00
Taylor Cramer
05b2081e23 Queryify item_body_nested_bodies 2017-05-01 10:24:04 -07:00
bors
4cb396c680 Auto merge of #41560 - alevy:rwpi-ropi, r=eddyb
Add RWPI/ROPI relocation model support

This PR adds support for using LLVM 4's ROPI and RWPI relocation models for ARM.

ROPI (Read-Only Position Independence) and RWPI (Read-Write Position Independence) are two new relocation models in LLVM for the ARM backend ([LLVM changset](https://reviews.llvm.org/rL278015)). The motivation is that these are the specific strategies we use in userspace [Tock](https://www.tockos.org) apps, so supporting this is an important step (perhaps the final step, but can't confirm yet) in enabling userspace Rust processes.

## Explanation

ROPI makes all code and immutable accesses PC relative, but not assumed to be overriden at runtime (so for example, jumps are always relative).

RWPI uses a base register (`r9`) that stores the addresses of the GOT in memory so the runtime (e.g. a kernel) only adjusts r9 tell running code where the GOT is.

## Complications adding support in Rust

While this landed in LLVM master back in August, the header files in `llvm-c` have not been updated yet to reflect it. Rust replicates that header file's version of the `LLVMRelocMode` enum as the Rust enum `llvm::RelocMode` and uses an implicit cast in the ffi to translate from Rust's notion of the relocation model to the LLVM library's notion.

My workaround for this currently is to replace the `LLVMRelocMode` argument to `LLVMTargetMachineRef` with an int and using the hardcoded int representation of the `RelocMode` enum. This is A Bad Idea(tm), but I think very nearly the right thing.

Would a better alternative be to patch rust-llvm to support these enum variants (also a fairly trivial change)?
2017-05-01 17:23:09 +00:00
Niko Matsakis
3438cda788 use closure_base_def_id rather than walking up HIR 2017-05-01 11:18:15 -04:00
Niko Matsakis
c0434e2bab pacify the mercilous tidy 2017-05-01 11:09:36 -04:00
Niko Matsakis
d4d74dafe8 remove unused is_fn 2017-05-01 11:05:40 -04:00
Cameron Hart
1dd082fb3e Add simple [repr(align)] codegen test.
Checks alloca and memcpy are aligned correctly.
2017-05-01 23:13:22 +10:00
bors
526d39948a Auto merge of #41632 - Mark-Simulacrum:test-16994, r=arielb1
Add test for issue #16994.

Fixes #16994.

Please check that this is the correct way to write this test.

r? @arielb1 (author of test case)
2017-05-01 12:13:27 +00:00
bors
8f74f951cf Auto merge of #41666 - nagisa:try-poking-bigendian-again, r=arielb1
Try fixing bigendian metadata serialisation

I compiled this on PPC to check and it seems to work, but not sure whether I didn't mess up
anything in a major way.

Maybe a good shot at #41443

The easiest way to *really* test this is to land the patch (a high priority would be good, since I quite literally am just twiddling my thumbs on this now), wait for nightly, and, if the nightly works, backport this to beta.
2017-05-01 09:48:09 +00:00
Simonas Kazlauskas
54de2749b0 Try fixing bigendian metadata serialisation
I compiled this on PPC to check and it seems to work, but not sure whether I didn't mess up
anything in a major way.

Maybe a good shot at #41443
2017-05-01 04:51:17 +03:00
Niko Matsakis
6c2f64bdd8 modify ExprUseVisitor and friends to take region-maps, not def-id 2017-04-30 17:03:32 -04:00
Taylor Cramer
73cd9bde37 introduce per-fn RegionMaps
Instead of requesting the region maps for the entire crate, request for
a given item etc. Several bits of code were modified to take
`&RegionMaps` as input (e.g., the `resolve_regions_and_report_errors()`
function). I am not totally happy with this setup -- I *think* I'd
rather have the region maps be part of typeck tables -- but at least the
`RegionMaps` works in a "parallel" way to `FreeRegionMap`, so it's not
too bad. Given that I expect a lot of this code to go away with NLL, I
didn't want to invest *too* much energy tweaking it.
2017-04-30 17:03:30 -04:00
Niko Matsakis
c7dc39dbf0 intern CodeExtents
Make a `CodeExtent<'tcx>` be something allocated in an arena
instead of an index into the `RegionMaps`.
2017-04-30 17:02:59 -04:00
Niko Matsakis
55d6066c05 remove ROOT_CODE_EXTENT and DUMMY_CODE_EXTENT
Instead, thread around `Option<CodeExtent>` where applicable.
2017-04-30 17:02:58 -04:00
Taylor Cramer
119c38ea91 Remove RefCells from RegionMaps 2017-04-30 17:02:58 -04:00