Commit Graph

106502 Commits

Author SHA1 Message Date
Jonas Schievink
f66793757f Don't run coherence twice for future-compat lints 2020-02-11 00:17:47 +01:00
bors
e6ec0d125e Auto merge of - CAD97:sound-range-inclusive, r=Mark-Simulacrum
Remove problematic specialization from RangeInclusive

Fixes  using the approach [outlined by Mark-Simulacrum](https://github.com/rust-lang/rust/issues/67194#issuecomment-581669549).

> I believe the property we want is that if `PartialEq(&self, &other) == true`, then `self.next() == other.next()`. It is true that this is satisfied by removing the specialization and always doing `is_empty.unwrap_or_default()`; the "wrong" behavior there arises from calling `next()` having an effect on initially empty ranges, as we should be in `is_empty = true` but are not (yet) there. It might be possible to detect that the current state is always empty (i.e., `start > end`) and then not fill in the empty slot. I think this might solve the problem without regressing tests; however, this could have performance implications.

> That approach essentially states that we only use the `is_empty` slot for cases where `start <= end`. That means that `Idx: !Step` and `start > end` would both behave the same, and correctly -- we do not need the boolean if we're not ever going to emit any values from the iterator.

This is implemented here by replacing the `is_empty: Option<bool>` slot with an `exhausted: bool` slot. This flag is

- `false` upon construction,
- `false` when iteration has not yielded an element -- importantly, this means it is always `false` for an iterator empty by construction,
- `false` when iteration has yielded an element and the iterator is not exhausted, and
- only `true` when iteration has been used to exhaust the iterator.

For completeness, this also adds a note to the `Debug` representation to note when the range is exhausted.
2020-02-10 15:24:59 +00:00
bors
4d1241f515 Auto merge of - Dylan-DPC:rollup-13qn0fq, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 -  (Reduce the number of `RefCell`s in `InferCtxt`.)
 -  (Improve performance of coherence checks)
 -  (Make `num::NonZeroX::new` an unstable `const fn`)
 -  (Correctly parse `mut a @ b`)
 -  (Small graphviz improvements for the new dataflow framework)
 -  (parser: Keep current and previous tokens precisely)

Failed merges:

r? @ghost
2020-02-10 10:47:39 +00:00
Dylan DPC
18c6d39b55
Rollup merge of - petrochenkov:prevspan2, r=Centril
parser: Keep current and previous tokens precisely

...including their unnormalized forms.
Add more documentation for them.

Hopefully, this will help to eliminate footguns like https://github.com/rust-lang/rust/pull/68728#discussion_r373787486.

I'll try to address the FIXMEs in separate PRs during the next week.

r? @Centril
2020-02-10 01:54:23 +01:00
Dylan DPC
a8d4ccf907
Rollup merge of - ecstatic-morse:unified-dataflow-graphviz, r=wesleywiser
Small graphviz improvements for the new dataflow framework

Split out from . This prints the correct effect diff for each line (the before-effect and the after-effect) and makes marginal improvements to the graphviz output for the new dataflow framework including using monospaced font and better line breaking. This will only be useful when  is merged and the graphviz output changes from this:

![image](https://user-images.githubusercontent.com/29463364/74107776-5e3c3300-4b28-11ea-9d33-4862228b5e87.png)

to this:

![image](https://user-images.githubusercontent.com/29463364/74107751-20d7a580-4b28-11ea-99ca-24f749386601.png)

r? @wesleywiser
2020-02-10 01:54:21 +01:00
Dylan DPC
64d2d04eb9 Rollup merge of - matthewjasper:imm-binding-after-at, r=Centril
Correctly parse `mut a @ b`

r? @Centril

Closes 
Closes 
2020-02-10 01:54:20 +01:00
Dylan DPC
e3315f6742
Rollup merge of - ecstatic-morse:const-non-zero, r=dtolnay
Make `num::NonZeroX::new` an unstable `const fn`

cc 

These require `#[feature(const_if_match)]`, meaning they must remain unstable for the time being.
2020-02-10 01:54:18 +01:00
Dylan DPC
b3cfb97d5c Rollup merge of - jonas-schievink:coherence-perf, r=varkor
Improve performance of coherence checks

The biggest perf improvement in here is expected to come from the removal of the remaining  warning code since that effectively runs the expensive parts of coherence *twice*, which can even be visualized by obtaining a flamegraph:

![image](https://user-images.githubusercontent.com/5047365/74091959-e1f41200-4a8b-11ea-969d-2849d3f86c63.png)
2020-02-10 01:54:17 +01:00
Dylan DPC
8007f8468b
Rollup merge of - nnethercote:reduce-RefCells-in-InferCtxt, r=varkor
Reduce the number of `RefCell`s in `InferCtxt`.

`InferCtxt` contains six structures within `RefCell`s. Every time we
create and dispose of (commit or rollback) a snapshot we have to
`borrow_mut` each one of them.

This commit moves the six structures under a single `RefCell`, which
gives significant speed-ups by reducing the number of `borrow_mut`
calls. To avoid runtime errors I had to reduce the lifetimes of dynamic
borrows in a couple of places.

r? @varkor
2020-02-10 01:54:15 +01:00
Jonas Schievink
23095928a7 Remove vestigial #43355-compat code
This was previously a future-compat warning that has since been turned into
hard error, but without actually removing all the code.

Avoids a call to `traits::overlapping_impls`, which is expensive.
2020-02-09 23:18:02 +01:00
Jonas Schievink
8f468ee114 Defer error span calculation until needed
This was showing up in profiles. Also deduplicates the code to get just
the impl header span.
2020-02-09 23:17:09 +01:00
Jonas Schievink
82d6e79cfe Add desc to specialization_graph_of query 2020-02-09 23:17:09 +01:00
Jonas Schievink
5ab1ab4959 Reduce queries/map lookups done by coherence
This has negligible perf impact, but it does improve the code a bit.

* Only query the specialization graph of any trait once instead of once per
  impl
* Loop over impls only once, precomputing impl DefId and TraitRef
2020-02-09 23:17:09 +01:00
bors
840bdc349d Auto merge of - Patryk27:master, r=zackmdavis
Improve reporting errors and suggestions for trait bounds

Fix 

- When printing errors for unsized function parameter, properly point at the parameter instead of function's body.
- Improve `consider further restricting this bound` (and related) messages by separating human-oriented hints from the machine-oriented ones.
2020-02-09 22:13:05 +00:00
Nicholas Nethercote
7426853ba2 Reduce the number of RefCells in InferCtxt.
`InferCtxt` contains six structures within `RefCell`s. Every time we
create and dispose of (commit or rollback) a snapshot we have to
`borrow_mut` each one of them.

This commit moves the six structures under a single `RefCell`, which
gives significant speed-ups by reducing the number of `borrow_mut`
calls. To avoid runtime errors I had to reduce the lifetimes of dynamic
borrows in a couple of places.
2020-02-10 08:55:34 +11:00
Vadim Petrochenkov
cd7a428b5e parser: Keep current and previous tokens precisely
including their unnormalized forms.
Add more documentation for them.
2020-02-10 00:08:53 +03:00
bors
71c7e149e4 Auto merge of - jonas-schievink:rollup-z2ymler, r=jonas-schievink
Rollup of 5 pull requests

Successful merges:

 -  (Derive Clone + Eq for std::string::FromUtf8Error)
 -  (implement AsMut<str> for String)
 -  (rustc_codegen_llvm: always set AlwaysPreserve on all debuginfo variables)
 -  (Speed up the inherent impl overlap check)
 -  (Pretty-print generic params and where clauses on associated types)

Failed merges:

r? @ghost
2020-02-09 18:44:39 +00:00
Dylan MacKenzie
8d6208c39b Use nicer alignment when printing state vectors 2020-02-09 10:33:07 -08:00
Dylan MacKenzie
83dfb422fe Don't break first line 2020-02-09 10:33:06 -08:00
Dylan MacKenzie
fb14386de3 Remove unnecessary allows 2020-02-09 10:33:06 -08:00
Dylan MacKenzie
852afa2e88 Add option to dot::render for monospace font 2020-02-09 10:33:06 -08:00
Dylan MacKenzie
effd52078c Print after effect in default graphviz formatter
Now the line for each statement will show the diff resulting from the
combination of `before_statement_effect` and `statement_effect`. It's
still possible to observe each in isolation via
`borrowck_graphviz_format = "two_phase"`.
2020-02-09 10:33:06 -08:00
Jonas Schievink
da005822ce
Rollup merge of - Areredify:gat_pretty, r=cramertj
Pretty-print generic params and where clauses on associated types

closes 
2020-02-09 18:23:34 +01:00
Jonas Schievink
f6b8281d34
Rollup merge of - jonas-schievink:inherent-overlap, r=petrochenkov
Speed up the inherent impl overlap check

This gives a ~7% improvement in compile times for the stm32f0(x2) crate.

Also addresses @eddyb's comment in https://github.com/rust-lang/rust/pull/68837#discussion_r375701767.
2020-02-09 18:23:33 +01:00
Jonas Schievink
0e23d3681e
Rollup merge of - eddyb:always-preserve-dbg-vars, r=nagisa
rustc_codegen_llvm: always set AlwaysPreserve on all debuginfo variables

Making this depend on the optimization level appears to have been a copy-paste mistake (other LLVM functions called in this module also take a `bool` argument, but there it means something unrelated).
Also see https://github.com/rust-lang/rust/pull/8855#discussion_r374392128.

I don't believe we have any reason to let LLVM omit user variables from DWARF, and we were already setting this to `true` when LLVM *could* optimize them away, so this PR should have no effect anyway.

r? @michaelwoerister or @nagisa cc @hanna-kruppe @nikomatsakis
2020-02-09 18:23:31 +01:00
Jonas Schievink
3516df3ecb
Rollup merge of - tspiteri:string-as-mut, r=sfackler
implement AsMut<str> for String

Closes .
2020-02-09 18:23:30 +01:00
Jonas Schievink
0b50319af6
Rollup merge of - kennytm:derive-clone-eq-for-fromutf8error, r=sfackler
Derive Clone + Eq for std::string::FromUtf8Error

Implement `Clone` and `Eq` for `std::string::FromUtf8Error`.

Both the inner `Vec<u8>` and `std::str::Utf8Error` are also `Clone + Eq`, so I don't see why we shouldn't derive them on `FromUtf8Error` as well.

(impl are insta-stable, requiring FCP from T-libs.)
2020-02-09 18:23:28 +01:00
bors
1ad6b5e1e6 Auto merge of - Zoxc:lld, r=Mark-Simulacrum
Add an option to use LLD to link the compiler on Windows platforms

Based on https://github.com/rust-lang/rust/pull/68609.

Using LLD is good way to improve compile times on Windows since `link.exe` is quite slow. The time for `x.py build --stage 1 src/libtest` goes from 0:12:00 to 0:08:29. Compile time for `rustc_driver` goes from 226.34s to 18.5s. `rustc_macros` goes from 28.69s to 7.7s. The size of `rustc_driver` is also reduced from 83.3 MB to 78.7 MB.

r? @Mark-Simulacrum
2020-02-09 15:24:50 +00:00
John Kåre Alsaker
d304cd0c55 More comments 2020-02-09 14:35:50 +01:00
John Kåre Alsaker
e763ddc6b9 Add some comments 2020-02-09 14:26:13 +01:00
Matthew Jasper
fa5a3c35dc Don't parse mut a @ b as mut a @ mut b 2020-02-09 13:19:06 +00:00
bors
6dff769e37 Auto merge of - Dylan-DPC:rollup-jzab8oh, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 -  (Move `rustc_hir::def_id` to `rustc_span::def_id`)
 -  (Fix and test implementation of BTreeMap's first/last_entry, pop_first/last)
 -  (perf: Reduce Vec allocations in normalization by passing &mut Vec)
 -  (Don't use the word "unwrap" to describe "unwrap" methods)
 -  (Mark several functions and methods in core::cmp as #[must_use])
 -  (Clean up E0277 and E0282 explanations)
 -  (codegen: misc cleanups around debuginfo scopes and locations.)

Failed merges:

r? @ghost
2020-02-09 10:20:46 +00:00
Patryk Wychowaniec
a8d34c1062
Improve reporting errors and suggestions for trait bounds 2020-02-09 10:33:47 +01:00
bors
64ea639c12 Auto merge of - estebank:where-clause-sugg-missing-fn, r=varkor
When suggesting associated fn with type parameters, include in the structured suggestion

Address .

```
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `baz`
  --> file.rs:14:1
   |
14 | impl TraitA<()> for S {
   | ^^^^^^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `baz` in implementation
   |
   = help: implement the missing item: `fn foo<T>(_: T) -> Self where T: TraitB, TraitB::Item = A { unimplemented!() }`
   = help: implement the missing item: `fn bar<T>(_: T) -> Self { unimplemented!() }`
   = help: implement the missing item: `fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: std::marker::Copy { unimplemented!() }`
```

It doesn't work well for associated types with `ty::Predicate::Projection`s as we need to resugar `T: Trait, Trait::Assoc = K` → `T: Trait<Assoc = K>`.
2020-02-09 07:11:56 +00:00
Esteban Küber
3cdd7ae59e review comment 2020-02-08 21:08:59 -08:00
bors
f8d830b4de Auto merge of - Centril:move-ref-patterns, r=matthewjasper
Initial implementation of `#![feature(move_ref_pattern)]`

Following up on , under the gate `#![feature(move_ref_pattern)]`, `(ref x, mut y)` is allowed subject to restrictions necessary for soundness. The match checking implementation and tests for `#![feature(bindings_after_at)]` is also adjusted as necessary.

Closes .
Tracking issue: .

r? @matthewjasper
2020-02-09 04:01:28 +00:00
Dylan MacKenzie
0755c41ae2 Test NonZeroU8::new in a const context 2020-02-08 16:06:42 -08:00
Dylan MacKenzie
0b20ce97f7 Make num::NonZeroX::new an unstable const fn 2020-02-08 16:02:20 -08:00
Dylan DPC
9dabf80d55
Rollup merge of - eddyb:llvm-dbg-cleanup, r=nagisa
codegen: misc cleanups around debuginfo scopes and locations.

See each commit message. Most of these seem to be leftovers from the transition to MIR codegen.

r? @nagisa cc @bjorn3
2020-02-09 00:54:00 +01:00
Dylan DPC
8333115100
Rollup merge of - GuillaumeGomez:clean-up-e0277-e0282, r=Dylan-DPC
Clean up E0277 and E0282 explanations

r? @Dylan-DPC
2020-02-09 00:53:58 +01:00
Dylan DPC
d6087b91db
Rollup merge of - mjbshaw:must_use, r=mjbshaw
Mark several functions and methods in core::cmp as #[must_use]

These functions and methods aren't mutating functions and ignoring the result of them is likely a bug in the user's code.
2020-02-09 00:53:56 +01:00
Dylan DPC
2be062a4b0
Rollup merge of - brson:unwrapdoc, r=Dylan-DPC
Don't use the word "unwrap" to describe "unwrap" methods

It's tautological, and "unwrap" is essentially Rust-specific jargon.

I was teaching a newbie some Rust, and doing the usual hand-waving about error handling using unwrap. They asked what 'unwrap' means. I said look it up in the docs. The docs read (paraphrased) "unwrap unwraps". I was embarrassed.

This changes all the Option/Result functions with unwrapping behavior to use a variation on a single description:

> "Returns the contained `Some/Ok` value [or ...]."

It also renames the closure of `Result::unwrap_or_else` to `default` for consistency with `Option`, and perhaps makes a few other small tweaks.

Previous: https://github.com/rust-lang/rust/pull/68849
2020-02-09 00:53:55 +01:00
Dylan DPC
664d87f9b1
Rollup merge of - Marwes:allocations, r=matthewjasper
perf: Reduce Vec allocations in normalization by passing &mut Vec

Complicates the code a bit but allocation/freeing were a few percent of the overall runtime in trait heavy code.
2020-02-09 00:53:53 +01:00
Dylan DPC
cb87c958ef
Rollup merge of - ssomers:btree_first_last_fix68829, r=KodrAus
Fix and test implementation of BTreeMap's first/last_entry, pop_first/last

Properly implement and test `first_entry` & `last_entry` to fix problem report 
2020-02-09 00:53:52 +01:00
Dylan DPC
d17bc9f061 Rollup merge of - Aaron1011:move-def-hir-span, r=petrochenkov
Move `rustc_hir::def_id` to `rustc_span::def_id`

This will allow `HygieneData` to refer to `DefId` and `DefIndex`, which
will enable proper serialization of Span hygiene information.

This also reduces the number of things imported from `rustc_hir`, which
might make it easier to remove dependencies on it.
2020-02-09 00:53:50 +01:00
CAD97
136008c15b Disable failing codegen test 2020-02-08 18:47:41 -05:00
CAD97
3e115b6c9d Remove problematic specialization from RangeInclusive 2020-02-08 18:47:41 -05:00
Aaron Hill
619051e4f0
Move librustc_hir/def_id.rs to librustc_span/def_id.rs
For noww, librustc_hir re-exports the `def_id` module from
librustc_span, so the rest of rustc can continue to reference
rustc_hir::def_id
2020-02-08 16:48:01 -05:00
bors
a19edd6b16 Auto merge of - eddyb:debuginfo-there-can-only-be-one-arg, r=nagisa
rustc_codegen_ssa: don't treat inlined variables as debuginfo arguments.

Fixes  by limiting `ArgumentVariable` special-casing to `VarDebugInfo` entries that are in `OUTERMOST_SOURCE_SCOPE`, i.e. the function's own argument scope.
That excludes `VarDebugInfo` from inlined callees, which can also point to the caller's argument locals.

This is a snippet from the optimized MIR (including inlining) of the testcase:
```rust
fn  foo(_1: usize) -> usize {
    debug bar => _1;                     // in scope 0 at ./example.rs:2:12: 2:15
    let mut _0: usize;                   // return place in scope 0 at ./example.rs:2:27: 2:32
    scope 1 {
        debug x => _1;                   // in scope 1 at /rustc/9ed29b6ff6aa2e048b09c27af8f62ee3040bdb37/src/libcore/convert/mod.rs:106:26: 106:27
    }
```
`scope 1` is from inlining the `identity` call, and `debug x => _1;` comes from the body of `core::convert::identity`, so they are now ignored for the purposes of determining the `ArgumentVariable` debuginfo associated to `_1`.
2020-02-08 21:28:05 +00:00
Markus Westerlind
51b891ae2c Reduce Vec allocations in normalization by passing &mut Vec 2020-02-08 20:52:22 +01:00