Commit graph

177 commits

Author SHA1 Message Date
bors
9d74efe32e Auto merge of #76844 - simonvandel:fix-76803, r=wesleywiser
Fix #76803 miscompilation

Fixes #76803
Seems like it was an oversight that the discriminant value being set was not compared to the target value from the SwitchInt, as a comment says this is a requirement for the optimization to be sound.

r? `@wesleywiser` since you are probably familiar with the optimization and made #76837 to workaround the bug
2020-09-25 04:17:03 +00:00
Jonas Schievink
8515efb193
Rollup merge of #77165 - simonvandel:do-not-fire-on-drop-and-replace, r=oli-obk
Followup to #76673

Resolves https://github.com/rust-lang/rust/pull/76673#discussion_r494426303
r? @tmiasko
2020-09-25 02:29:52 +02:00
Jonas Schievink
b8d158b0f8
Rollup merge of #77160 - ecstatic-morse:const-fn-transmute-suggestion, r=oli-obk
Suggest `const_fn_transmute`, not `const_fn`

More fallout from #76850 in the vein of #77134. The fix is the same. I looked through the structured errors file and didn't see any more of this kind of diagnostics bug.

r? @oli-obk
2020-09-25 02:29:49 +02:00
Jonas Schievink
473ae229f0
Rollup merge of #77136 - ecstatic-morse:issue-77134, r=oli-obk
Suggest `const_mut_refs`, not `const_fn` for mutable references in `const fn`

Resolves #77134.

Prior to #76850, most uses of `&mut` in `const fn` ~~required~~ involved two feature gates, `const_mut_refs` and `const_fn`. The first allowed all mutable borrows of locals. The second allowed only locals, arguments and return values whose types contained `&mut`. I switched the second check to the `const_mut_refs` gate. However, I forgot update the error message with the new suggestion.

Alternatively, we could revert to having two different feature gates for this. OP's code never borrows anything mutably, so it didn't need `const_mut_refs` in the past, only `const_fn`. I'd prefer to keep everything under a single gate, however.

r? @oli-obk
2020-09-25 02:29:47 +02:00
Jonas Schievink
d766c239bd
Rollup merge of #76724 - ecstatic-morse:dataflow-pass-names, r=lcnr
Allow a unique name to be assigned to dataflow graphviz output

Previously, if the same analysis were invoked multiple times in a single compilation session, the graphviz output for later runs would overwrite that of previous runs. Allow callers to add a unique identifier to each run so this can be avoided.
2020-09-25 02:29:31 +02:00
Dylan MacKenzie
ebf024bba8 Suggest const_fn_transmute instead of const_fn 2020-09-24 12:07:41 -07:00
Simon Vandel Sillesen
7dec440340 Resolve https://github.com/rust-lang/rust/pull/76673#discussion_r494426303 2020-09-24 21:02:53 +02:00
bors
5562bb6d74 Auto merge of #76748 - tmiasko:no-op-jumps, r=matthewjasper
Fix underflow when calculating the number of no-op jumps folded

When removing unwinds to no-op blocks and folding jumps to no-op blocks,
remove the unwind target first. Otherwise we cannot determine if target
has been already folded or not.

Previous implementation incorrectly assumed that all resume targets had
been folded already, occasionally resulting in an underflow:

```
remove_noop_landing_pads: removed 18446744073709551613 jumps and 3 landing pads
```
2020-09-24 05:57:06 +00:00
Dylan MacKenzie
a320ef751b Suggest const_mut_refs for mutable references in const fn 2020-09-23 21:04:07 -07:00
bors
c35177582b Auto merge of #77102 - Dylan-DPC:rollup-2jfrg3u, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #76898 (Record `tcx.def_span` instead of `item.span` in crate metadata)
 - #76939 (emit errors during AbstractConst building)
 - #76965 (Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.)
 - #76993 (Changing the alloc() to accept &self instead of &mut self)
 - #76994 (fix small typo in docs and comments)
 - #77017 (Add missing examples on Vec iter types)
 - #77042 (Improve documentation for ToSocketAddrs)
 - #77047 (Miri: more informative deallocation error messages)
 - #77055 (Add #[track_caller] to more panicking Cell functions)

Failed merges:

r? `@ghost`
2020-09-23 22:34:44 +00:00
bors
8b4085359a Auto merge of #76673 - simonvandel:remove-unneeded-drops, r=oli-obk
MIR pass to remove unneeded drops on types not needing drop

This is heavily dependent on MIR inlining running to actually see the drop statement.

Do we want to special case replacing a call to std::mem::drop with a goto aswell?
2020-09-23 20:13:47 +00:00
Dylan DPC
f8dec3d054
Rollup merge of #77047 - RalfJung:miri-dealloc, r=oli-obk
Miri: more informative deallocation error messages

Make sure we show the affected AllocId.

r? @oli-obk
2020-09-23 14:54:13 +02:00
Dylan DPC
bcdbe79f0c
Rollup merge of #76994 - yuk1ty:fix-small-typo, r=estebank
fix small typo in docs and comments

Fixed `the the` to `the`, as far as I found.
2020-09-23 14:54:07 +02:00
bors
feca2c229e Auto merge of #76659 - simonvandel:76432, r=oli-obk
SimplifyComparisonIntegral: fix miscompilation

Fixes #76432
Only insert StorageDeads if we actually removed one.
Fixes an issue where we added StorageDead to a place with no StorageLive

r? `@oli-obk`
2020-09-23 08:23:00 +00:00
Simon Vandel Sillesen
b6f51d6d6a cleanup cfg after optimization 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen
f472303a93 The optimization should also apply for DropAndReplace 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen
d3338dcf4d Get LocalDefId from source instead of passing in 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen
b4bdaa14f2 Suggestion from review
Co-authored-by: Andreas Jonson <andjo403@users.noreply.github.com>
2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen
290dca1781 MIR pass to remove unneeded drops on types not needing drop
This is heavily dependent on MIR inlining running to actually see the drop statement
2020-09-22 23:09:07 +02:00
Dylan MacKenzie
186d148b4c Use correct feature gate for unsizing casts 2020-09-22 10:22:50 -07:00
Dylan MacKenzie
08e3822d9a Replace missing comment 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
d60e204e0a Use the same name everywhere for is_const_stable_const_fn 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
3569bb6323 Update const-checker to replicate qualify_min_const_fn 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
5ee5429e00 Add structured errors for qualify_min_const_fn checks 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
bfc10a89c3 Allow errors to abort const checking when emitted
This is a hack for parity with `qualify_min_const_fn`, which only
emitted a single error.
2020-09-22 10:05:58 -07:00
Dylan MacKenzie
7fb9587a3c Return true if check_const emits an error 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
a173c5c1b3 Add const-stability helpers 2020-09-22 10:05:58 -07:00
Dylan MacKenzie
3dd28c78c3 Useful derives on ops::Status 2020-09-22 10:05:58 -07:00
Ralf Jung
731113b8ee Miri: more informative deallocation error messages 2020-09-22 09:05:12 +02:00
ecstatic-morse
dcf4d1f2be
Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPC
use if let instead of single match arm expressions

use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match)
2020-09-21 20:40:55 -07:00
ecstatic-morse
60b99015e9
Rollup merge of #76807 - ecstatic-morse:const-checking-staged-api, r=oli-obk
Use const-checking to forbid use of unstable features in const-stable functions

First step towards #76618.

Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass.

Also contains some unrelated refactoring, which is split into separate commits.

r? @oli-obk
2020-09-21 20:40:53 -07:00
ecstatic-morse
30f1bab7e6
Rollup merge of #76581 - lcnr:bound-too-generic, r=eddyb
do not ICE on bound variables, return `TooGeneric` instead

fixes #73260, fixes #74634, fixes #76595

r? @nikomatsakis
2020-09-21 20:40:47 -07:00
Simon Vandel Sillesen
2bb3844820 Add optimization to avoid load of address 2020-09-21 22:08:27 +02:00
bors
e0bf356f9e Auto merge of #74040 - lcnr:const-occurs-check, r=nikomatsakis
fix unification of const variables

r? `@nikomatsakis` `@varkor` `@eddyb` let's just ping everyone here 😅
2020-09-21 12:52:09 +00:00
Bastian Kauschke
39245400c5 fix InterpCx resolve 2020-09-21 12:09:08 +02:00
yuk1ty
16047d46a1 fix typo in docs and comments 2020-09-21 12:14:28 +09:00
Kornel Lesiński
34d3c7df80 Let user see the full type of type-length limit error 2020-09-21 00:39:58 +01:00
bors
2e0edc0f28 Auto merge of #75119 - simonvandel:early-otherwise, r=oli-obk
New MIR optimization pass to reduce branches on match of tuples of enums

Fixes #68867 by adding a new pass that turns something like
```rust
let x: Option<()>;
let y: Option<()>;
match (x,y) {
    (Some(_), Some(_)) => {0},
    _ => {1}
}
```
into something like
```rust
let x: Option<()>;
let y: Option<()>;
let discriminant_x = // get discriminant of x
let discriminant_y = // get discriminant of x
if discriminant_x != discriminant_y {1} else {0}
```

The opt-diffs still have the old basic blocks like
```
bb3: {
          _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:21:21: 21:30
          switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:21:21: 21:30
      }

      bb4: {
          _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:22:23: 22:34
          switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:22:23: 22:34
      }

      bb5: {
          _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:23:23: 23:34
          switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:23:23: 23:34
      }
```

These do get removed on later passes. I'm not sure if I should include those passes in the test to make it clear?
2020-09-20 17:54:44 +00:00
Ralf Jung
8405d50e12
Rollup merge of #76890 - matthiaskrgr:matches_simpl, r=lcnr
use matches!() macro for simple if let conditions
2020-09-20 15:52:01 +02:00
Simon Vandel Sillesen
e25738f529 enable on mir-opt-level=1 to test perf 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen
27068cbfdc add cleanup of cfg 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen
118aae2af1 insert storageDead for not equal temp 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen
2530274023 correct comment 2020-09-20 14:45:46 +02:00
Simon Vandel Sillesen
5cc93950ac Update src/librustc_mir/transform/early_otherwise_branch.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-09-20 14:45:46 +02:00
Simon Vandel Sillesen
5fb32c2e33 New MIR optimization pass to reduce branches on match of tuples of enums 2020-09-20 14:45:46 +02:00
bors
41507ed0d5 Auto merge of #76964 - RalfJung:rollup-ybn06fs, r=RalfJung
Rollup of 15 pull requests

Successful merges:

 - #76722 (Test and fix Send and Sync traits of BTreeMap artefacts)
 - #76766 (Extract some intrinsics out of rustc_codegen_llvm)
 - #76800 (Don't generate bootstrap usage unless it's needed)
 - #76809 (simplfy condition in ItemLowerer::with_trait_impl_ref())
 - #76815 (Fix wording in mir doc)
 - #76818 (Don't compile regex at every function call.)
 - #76821 (Remove redundant nightly features)
 - #76823 (black_box: silence unused_mut warning when building with cfg(miri))
 - #76825 (use `array_windows` instead of `windows` in the compiler)
 - #76827 (fix array_windows docs)
 - #76828 (use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip))
 - #76840 (Move to intra doc links in core/src/future)
 - #76845 (Use intra docs links in core::{ascii, option, str, pattern, hash::map})
 - #76853 (Use intra-doc links in library/core/src/task/wake.rs)
 - #76871 (support panic=abort in Miri)

Failed merges:

r? `@ghost`
2020-09-20 11:02:36 +00:00
Ralf Jung
bfa1904765
Rollup merge of #76828 - matthiaskrgr:clippy_manual_strip, r=lcnr
use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip)
2020-09-20 12:08:29 +02:00
Ralf Jung
50d56bc774
Rollup merge of #76825 - lcnr:array-windows-apply, r=varkor
use `array_windows` instead of `windows` in the compiler

I do think these changes are beautiful, but do have to admit that using type inference for the window length
can easily be confusing. This seems like a general issue with const generics, where inferring constants adds an additional
complexity which users have to learn and keep in mind.
2020-09-20 12:08:26 +02:00
Ralf Jung
4322e1b92d
Rollup merge of #76821 - est31:remove_redundant_nightly_features, r=oli-obk,Mark-Simulacrum
Remove redundant nightly features

Removes a bunch of redundant/outdated nightly features. The first commit removes a `core_intrinsics` use for which a stable wrapper has been provided since. The second commit replaces the `const_generics` feature with `min_const_generics` which might get stabilized this year. The third commit is the result of a trial/error run of removing every single feature and then adding it back if compile failed. A bunch of unused features are the result that the third commit removes.
2020-09-20 12:08:22 +02:00
Ralf Jung
3268e33199
Rollup merge of #76818 - hbina:dont_compile_regex_all_the_time, r=ecstatic-morse
Don't compile regex at every function call.

Use `SyncOnceCell` to only compile it once.
I believe this still adds some kind of locking mechanism?

Related issue: https://github.com/rust-lang/rust/issues/76817
2020-09-20 12:08:20 +02:00