Commit graph

149151 commits

Author SHA1 Message Date
bjorn3
e0e0cfa649 Update mir opt tests 2021-05-30 12:51:36 +02:00
bjorn3
c76b1b0317 Update tests 2021-05-30 12:51:36 +02:00
bjorn3
3abdebe79d Fix test 2021-05-30 12:51:36 +02:00
bjorn3
d0ec85d3fb Merge CrateDisambiguator into StableCrateId 2021-05-30 12:51:34 +02:00
bors
d93b6a4598 Auto merge of #85786 - GuillaumeGomez:error-code-checker-improvement, r=Mark-Simulacrum
Error code checker improvement

Just realized that some error codes shouldn't be ignored anymore. So I updated the script to ensure that if an error code is tested and ignored, it will trigger an error.
2021-05-30 07:25:38 +00:00
bors
bff138dbd9 Auto merge of #85754 - the8472:revert-83770, r=Mark-Simulacrum
Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"

Due to a performance regression that didn't show up in the original perf run
this reverts commit 9111b8ae97 (#83770), reversing
changes made to 9a700d2947.

Since since is expected to have the inverse impact it should probably be rollup=never.

r? `@Mark-Simulacrum`
2021-05-30 04:12:44 +00:00
bors
9a72afa7dd Auto merge of #83772 - jhpratt:revamp-step-trait, r=Mark-Simulacrum
Make `Step` trait safe to implement

This PR makes a few modifications to the `Step` trait that I believe better position it for stabilization in the short term. In particular,

1. `unsafe trait TrustedStep` is introduced, indicating that the implementation of `Step` for a given type upholds all stated invariants (which have remained unchanged). This is gated behind a new `trusted_step` feature, as stabilization is realistically blocked on min_specialization.
2. The `Step` trait is internally specialized on the `TrustedStep` trait, which avoids a serious performance regression.
3. `TrustedLen` is implemented for `T: TrustedStep` as the latter's invariants subsume the former's.
4. The `Step` trait is no longer `unsafe`, as the invariants must not be relied upon by unsafe code (unless the type implements `TrustedStep`).
5. `TrustedStep` is implemented for all types that implement `Step` in the standard library and compiler.
6. The `step_trait_ext` feature is merged into the `step_trait` feature. I was unable to find any reasoning for the features being split; the `_unchecked` methods need not necessarily be stabilized at the same time, but I think it is useful to have them under the same feature flag.

All existing implementations of `Step` will be broken, as it is not possible to `unsafe impl` a safe trait. Given this trait only exists on nightly, I feel this breakage is acceptable. The blanket `impl<T: Step> TrustedLen for T` will likely cause some minor breakage, but this should be covered by the equivalent impl for `TrustedStep`.

Hopefully these changes are sufficient to place `Step` in decent position for stabilization, which would allow user-defined types to be used with `a..b` syntax.
2021-05-30 01:21:39 +00:00
bors
84b1005bfd Auto merge of #85390 - Mark-Simulacrum:fast-bridge, r=petrochenkov
Optimize proc macro bridge

This optimizes the proc macro bridge code for a win of 0.7% instruction counts on the diesel-check benchmark (non-incr, full). These wins are small, but hopefully not limited to just the diesel benchmark; the code is also not seriously impacted by the changes here.
2021-05-29 22:55:40 +00:00
bors
b663c0f4f6 Auto merge of #85698 - ehuss:incremental-session-panic, r=estebank
Don't panic when failing to initialize incremental directory.

This removes a panic when rustc fails to initialize the incremental directory. This can commonly happen on various filesystems that don't support locking (often various network filesystems). Panics can be confusing and scary, and there are already plenty of issues reporting this.

This has been panicking since 1.22 due to I think #44502 which was a major rework of how things work. Previously, things were simpler and the [`load_dep_graph`](https://github.com/rust-lang/rust/blob/1.21.0/src/librustc_incremental/persist/load.rs#L43-L65) function would emit an error and then continue on without panicking. With 1.22, [`load_dep_graph`](https://github.com/rust-lang/rust/blob/1.22.0/src/librustc_incremental/persist/load.rs#L44) was changed so that it assumes it can load the data without errors. Today, the problem is that it calls [`prepare_session_directory`](fbf1b1a719/compiler/rustc_interface/src/passes.rs (L175-L179)) and then immediately calls `garbage_collect_session_directories` which will panic since the session is `IncrCompSession::NotInitialized`.

The solution here is to have `prepare_session_directory` return an error that must be handled so that compilation stops if it fails.

Some other options:

* Ignore directory lock failures.
* Print a warning on directory lock failure, but otherwise continue with incremental enabled.
* Print a warning on directory lock failure, and disable incremental.
* Provide a different locking mechanism.

Cargo ignores lock errors if locking is not supported, so that would be a precedent for the first option. These options would require quite a bit more changes, but I'm happy to entertain any of them, as I think they all have valid justifications.

There is more discussion on the many issues where this is reported: #49773, #59224, #66513, #76251. I'm not sure if this can be considered closing any of those, though, since I think there is some value in discussing if there is a way to avoid the error altogether. But I think it would make sense to at least close all but one to consolidate them.
2021-05-29 19:27:53 +00:00
Mark Rousskov
8c2080886f Write primitive types via array buffers
This allows a more efficient implementation (avoiding a fallback to memmove,
which is not optimal for short writes).

This saves 0.29% on diesel.
2021-05-29 12:52:06 -04:00
Mark Rousskov
92b2894d31 Switch to reserve over extend_from_slice
This is a 0.15% win on diesel.
2021-05-29 12:45:07 -04:00
Mark Rousskov
299ac75894 Specialize single-element writes to buffer
copy_from_slice generally falls back to memcpy/memmove, which is much more expensive
than we need to write a single element in.

This saves 0.26% instructions on the diesel benchmark.
2021-05-29 12:45:07 -04:00
bors
ff5522fc1a Auto merge of #85540 - GuillaumeGomez:better-result-dom-generation, r=jsha
Better result dom generation

First commit is from https://github.com/rust-lang/rust/pull/85506.

We realized in https://github.com/rust-lang/rust/pull/85506#issuecomment-844984162 thanks to `@dns2utf8` that in some cases, the generated search result DOM was invalid. This was not strict enough and the DOM was inserted as a big string, which wasn't great.

r? `@jsha`
2021-05-29 16:27:14 +00:00
Eric Huss
4c550bc014 Fix incremental-session-fail to work when run as root. 2021-05-29 08:54:51 -07:00
bors
9f75dbfa69 Auto merge of #85767 - lqd:stackless_span_stacks, r=oli-obk
A bit more polish on const eval errors

This PR adds a bit more polish to the const eval errors:
- a slight improvement to the PME messages from #85633: I mentioned there that the erroneous item's paths were dependent on the environment, and could be displayed fully qualified or not. This can obscure the items when they come from a dependency. This PR uses the pretty-printing code ensuring the items' paths are not trimmed.
- whenever there are generics involved in an item where const evaluation errors out, the error message now displays the instance and its const arguments, so that we can see which instantiated item and compile-time values lead to the error.

So we get this slight improvement for our beloved `stdarch` example, on nightly:
```
error[E0080]: evaluation of constant value failed
 --> ./stdarch/crates/core_arch/src/macros.rs:8:9
  |
8 |         assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range");
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'IMM value not in expected range', /rustc/9111b8ae9793f18179a1336417618fc07a9cac85/library/core/src/../../stdarch/crates/core_arch/src/macros.rs:8:9
  |
```

to this PR's:

```
error[E0080]: evaluation of `core::core_arch::macros::ValidateConstImm::<51_i32, 0_i32, 15_i32>::VALID` failed
 --> ./stdarch/crates/core_arch/src/macros.rs:8:9
  |
8 |         assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range");
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'IMM value not in expected range', ./stdarch/crates/core_arch/src/macros.rs:8:9
  |
```

with this PR.

Of course this is an idea from Oli, so maybe r? `@oli-obk` if they have the time.
2021-05-29 13:34:20 +00:00
bors
f77b1a5973 Auto merge of #85798 - hyd-dev:miri, r=RalfJung
Update Miri

Fixes #85780.
2021-05-29 09:07:33 +00:00
bors
6166929741 Auto merge of #85703 - clarfonthey:unchecked_shift, r=scottmcm
Add inherent unchecked_shl, unchecked_shr to integers

Tracking issue: #85122.

Adding more of these methods, since these are missing.
2021-05-29 05:16:09 +00:00
ltdk
2a40f2423a Add inherent unchecked_shl, unchecked_shr to integers 2021-05-28 22:54:39 -04:00
bors
4664725ae0 Auto merge of #85790 - ehuss:nvptx-no-std, r=nagisa
Fix typo on nvptx support

I made a minor mistake in https://github.com/rust-lang/rust-forge/pull/356 setting nvptx as std instead of no-std.
2021-05-29 01:01:13 +00:00
hyd-dev
fc6e4af963
Update Miri 2021-05-29 08:52:58 +08:00
Eric Huss
e7411a26e4 Add specific help for *how* to fix an incremental lock error. 2021-05-28 16:40:22 -07:00
bors
f58631b450 Auto merge of #85607 - LeSeulArtichaut:thir-unsafeck-closures, r=nikomatsakis
Make closures inherit their parent's "safety context"

Fixes rust-lang/project-thir-unsafeck#9, ~~blocked on #85273~~.
r? `@nikomatsakis`
2021-05-28 20:26:00 +00:00
bors
0e44ca6dba Auto merge of #85789 - ptrojahn:generator_typo, r=nagisa
Fix typo
2021-05-28 17:44:47 +00:00
Eric Huss
f882c9bc81
Fix typo on nvptx support 2021-05-28 10:14:56 -07:00
Guillaume Gomez
7602818a6e Clean up error codes from being ignored 2021-05-28 17:14:53 +02:00
Guillaume Gomez
c755bbb36c Add checks to ensure the error_codes checker is "clean" 2021-05-28 17:12:58 +02:00
bors
6f9df55a78 Auto merge of #85700 - Bobo1239:dso_local_ppc64, r=nagisa
Fix static relocation model for PowerPC64

We now also use `should_assume_dso_local()` for declarations and port two
additional cases from clang:
- Exclude PPC64 [1]
- Exclude thread-local variables [2]

[1]: 033138ea45/clang/lib/CodeGen/CodeGenModule.cpp (L1038-L1040)
[2]: 033138ea45/clang/lib/CodeGen/CodeGenModule.cpp (L1048-L1050)

Tbh I don't know enough about PowerPC(64) to explain why the TOC (table of contents; like the GOT in x86?) is still needed even with the static relocation model. But with these changes [Rust-For-Linux](https://github.com/Rust-for-Linux/linux) runs again on ppc64le. (instead of [getting loaded successfully but crashing](https://github.com/Bobo1239/linux/runs/2646478783?check_suite_focus=true#step:47:358))

r? `@nagisa`
2021-05-28 15:03:52 +00:00
bors
ce0d64e03e Auto merge of #85546 - hyd-dev:unwind, r=RalfJung
const-eval: disallow unwinding across functions that `!fn_can_unwind()`

Following https://github.com/rust-lang/miri/pull/1776#discussion_r633074343, so r? `@RalfJung`

This PR turns `unwind` in `StackPopCleanup::Goto` into a new enum `StackPopUnwind`, with a `NotAllowed` variant to indicate that unwinding is not allowed. This variant is chosen based on `rustc_middle::ty::layout::fn_can_unwind()` in `eval_fn_call()` when pushing the frame. A check is added in `unwind_to_block()` to report UB if unwinding happens across a `StackPopUnwind::NotAllowed` frame.

Tested with Miri `HEAD` with [minor changes](https://github.com/rust-lang/miri/compare/HEAD..9cf3c7f0d86325a586fbcbf2acdc9232b861f1d8) and the rust-lang/miri#1776 branch with [these changes](d866c1c52f..626638fbfe).
2021-05-28 08:49:48 +00:00
bors
18135ec85b Auto merge of #85745 - veber-alex:panic_any, r=m-ou-se
Add #[track_caller] to panic_any

Report the panic location from the user code.

```rust
use std::panic;
use std::panic::panic_any;

fn main() {
    panic::set_hook(Box::new(|panic_info| {
        if let Some(location) = panic_info.location() {
            println!(
                "panic occurred in file '{}' at line {}",
                location.file(),
                location.line(),
            );
        } else {
            println!("panic occurred but can't get location information...");
        }
    }));

    panic_any(42);
}
````

Before:
`panic occurred in file '/rustc/ff2c947c00f867b9f012e28ba88cecfbe556f904/library/std/src/panic.rs' at line 59`

After:
`panic occurred in file 'src/main.rs' at line 17`
2021-05-28 06:08:58 +00:00
bors
8eef79ca9a Auto merge of #84968 - FabianWolff:master, r=estebank
Fix incorrect suggestions for E0605

Fixes #84598. Here is a simplified version of the problem presented in issue #84598:

```Rust
#![allow(unused_variables)]
#![allow(dead_code)]

trait T { fn t(&self) -> i32; }

unsafe fn foo(t: *mut dyn T) {
    (t as &dyn T).t();
}

fn main() {}
```

The current output is:
```
error[E0605]: non-primitive cast: `*mut (dyn T + 'static)` as `&dyn T`
 --> src/main.rs:7:5
  |
7 |     (t as &dyn T).t();
  |     ^^^^^^^^^^^^^ invalid cast
  |
help: borrow the value for the cast to be valid
  |
7 |     (&t as &dyn T).t();
  |      ^
```

This is incorrect, though: The cast will _not_ be valid when writing `&t` instead of `t`:
```
error[E0277]: the trait bound `*mut (dyn T + 'static): T` is not satisfied
 --> t4.rs:7:6
  |
7 |     (&t as &dyn T).t();
  |      ^^ the trait `T` is not implemented for `*mut (dyn T + 'static)`
  |
  = note: required for the cast to the object type `dyn T`
```

The correct suggestion is `&*t`, which I have implemented in this pull request. Of course, this suggestion will always require an unsafe block, but arguably, that's what the user really wants if they're trying to cast a pointer to a reference.

In any case, claiming that the cast will be valid after implementing the suggestion is overly optimistic, as the coercion logic doesn't seem to resolve all nested obligations, i.e. the cast may still be invalid after implementing the suggestion. I have therefore rephrased the suggestion slightly ("consider borrowing the value" instead of "borrow the value for the cast to be valid").

Additionally, I have fixed another incorrect suggestion not mentioned in #84598, which relates to casting immutable references to mutable ones:

```rust
fn main() {
    let mut x = 0;
    let m = &x as &mut i32;
}
```
currently leads to
```
error[E0605]: non-primitive cast: `&i32` as `&mut i32`
 --> t5.rs:3:13
  |
3 |     let m = &x as &mut i32;
  |             ^^^^^^^^^^^^^^ invalid cast
  |
help: borrow the value for the cast to be valid
  |
3 |     let m = &mut &x as &mut i32;
  |             ^^^^
```
which is obviously incorrect:
```
error[E0596]: cannot borrow data in a `&` reference as mutable
 --> t5.rs:3:13
  |
3 |     let m = &mut &x as &mut i32;
  |             ^^^^^^^ cannot borrow as mutable
```
I've changed the suggestion to a note explaining the problem:
```
error[E0605]: non-primitive cast: `&i32` as `&mut i32`
 --> t5.rs:3:13
  |
3 |     let m = &x as &mut i32;
  |             ^^^^^^^^^^^^^^ invalid cast
  |
note: this reference is immutable
 --> t5.rs:3:13
  |
3 |     let m = &x as &mut i32;
  |             ^^
note: trying to cast to a mutable reference type
 --> t5.rs:3:19
  |
3 |     let m = &x as &mut i32;
  |                   ^^^^^^^^
```
In this example, it would have been even nicer to suggest replacing `&x` with `&mut x`, but this would be much more complex because we would have to take apart the expression to be cast (currently, we only look at its type), and `&x` could be stored in a variable, where such a suggestion would not even be directly applicable:
```rust
fn main() {
    let mut x = 0;
    let r = &x;
    let m = r as &mut i32;
}
```
My solution covers this case, too.
2021-05-28 03:38:28 +00:00
Boris-Chengbiao Zhou
4a76934aa7 Fix static relocation model for PowerPC64
We now also use `should_assume_dso_local()` for declarations and port two
additional cases from clang:
- Exclude PPC64 [1]
- Exclude thread-local variables [2]

[1]: 033138ea45/clang/lib/CodeGen/CodeGenModule.cpp (L1038-L1040)
[2]: 033138ea45/clang/lib/CodeGen/CodeGenModule.cpp (L1048-L1050)
2021-05-28 03:48:39 +02:00
hyd-dev
f6348f1924
Rewrite to a match 2021-05-28 09:20:43 +08:00
hyd-dev
4ad21c9a9d
"a frame" -> "a stack frame" 2021-05-28 09:18:18 +08:00
bors
df3d86b535 Auto merge of #85743 - bjorn3:sync_cg_clif-2021-05-27, r=bjorn3
Sync rustc_codegen_cranelift

The main highlight this sync is the removal of several dependencies, making compilation of cg_clif itself faster. There have also been a couple of new features like `#[link_section]` now supporting different segments for Mach-O binaries (thanks `@eggyal!)` and the `imported_main` feature, which is currently unstable.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2021-05-28 00:57:39 +00:00
Rémy Rakic
c31ca9a42c const eval errors: display the current item instance if there are generics involved 2021-05-28 00:17:47 +02:00
bors
1c6868aa21 Auto merge of #84568 - andoriyu:libtest/junit_formatter, r=yaahc
feat(libtest): Add JUnit formatter

tracking issue: https://github.com/rust-lang/rust/issues/85563

Add an alternative formatter to `libtest`. Formatter produces valid xml that later can be interpreted as JUnit report.

Caveats:

- `timestamp` is required by schema, but every viewer/parser ignores it. Attribute is not set to avoid depending on chrono;
- Running all "suits" (unit tests, doc-tests and integration tests) will produce a mess;
- I couldn't find a way to get integration test binary name, so it's just goes by "integration";

Sample output for unit tests (pretty printed by 3rd party tool):
```
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="test" package="test" id="0" errors="0" failures="0" tests="13" skipped="1">
    <testcase classname="results::tests" name="test_completed_bad" time="0"/>
    <testcase classname="results::tests" name="suite_started" time="0"/>
    <testcase classname="results::tests" name="suite_ended_ok" time="0"/>
    <testcase classname="results::tests" name="suite_ended_bad" time="0"/>
    <testcase classname="junit::tests" name="test_failed_output" time="0"/>
    <testcase classname="junit::tests" name="test_simple_output" time="0"/>
    <testcase classname="junit::tests" name="test_multiple_outputs" time="0"/>
    <testcase classname="results::tests" name="test_completed_ok" time="0"/>
    <testcase classname="results::tests" name="test_stared" time="0"/>
    <testcase classname="junit::tests" name="test_generate_xml_no_error_single_testsuite" time="0"/>
    <testcase classname="results::tests" name="test_simple_output" time="0"/>
    <testcase classname="test" name="should_panic" time="0"/>
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>
```

Sample output for integration tests (pretty printed by 3rd party tool):

```
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="test" package="test" id="0" errors="0" failures="0" tests="1" skipped="0">
    <testcase classname="integration" name="test_add" time="0"/>
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>
```

Sample output for Doc-tests (pretty printed by 3rd party tool):

```
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="test" package="test" id="0" errors="0" failures="0" tests="1" skipped="0">
    <testcase classname="src/lib.rs" name="(line 2)" time="0"/>
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>
```
2021-05-27 21:14:55 +00:00
Rémy Rakic
949aca6eeb don't trim paths in collector PME message 2021-05-27 22:28:04 +02:00
LeSeulArtichaut
d1f0e9f65c Test THIR unsafeck for unsafe ops in closures 2021-05-27 21:04:44 +02:00
bors
e51830b90a Auto merge of #85757 - GuillaumeGomez:rollup-k8hfhp8, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #85722 (Fix trait methods' toggle)
 - #85730 (Mention workaround for floats in Iterator::{min, max})
 - #85738 (Rename opensbd to openbsd)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-27 18:33:43 +00:00
Guillaume Gomez
48706edc56
Rollup merge of #85738 - 370417:opensbd, r=m-ou-se
Rename opensbd to openbsd

OpenBsd was sometimes spelled "opensbd" in the standard library.
2021-05-27 20:08:24 +02:00
Guillaume Gomez
e30192ac5c
Rollup merge of #85730 - Smittyvb:iter-min-max-floats, r=m-ou-se
Mention workaround for floats in Iterator::{min, max}

`Iterator::{min, max}` can't be used with iterators of floats due to NaN issues. This suggests a workaround in the documentation of those functions.
2021-05-27 20:08:21 +02:00
Guillaume Gomez
6ac83e1808
Rollup merge of #85722 - GuillaumeGomez:trait-toggle, r=jsha
Fix trait methods' toggle

A `<details>` tag wasn't closed on trait methods, which created broken DOM. I also used this occasion to only generate the toggle in case there is documentation on the method.

r? `@jsha`
2021-05-27 20:08:17 +02:00
The8472
f72c60a39a Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"
Due to a performance regression that didn't show up in the original perf run
this reverts commit 9111b8ae97, reversing
changes made to 9a700d2947.
2021-05-27 18:17:09 +02:00
bors
d854c3c0e9 Auto merge of #85729 - LeSeulArtichaut:thir-no-hash, r=nikomatsakis
Don't hash `thir_body`

Experiment to see if/how much this helps negate the perf impact of #85273.
r? `@ghost`
2021-05-27 15:46:48 +00:00
LeSeulArtichaut
6c4f40dee1 Make closures inherit their parent's "safety context" 2021-05-27 16:50:48 +02:00
Niko Matsakis
9385be7a0c
Update compiler/rustc_middle/src/query/mod.rs
Co-authored-by: Léo Lanteri Thauvin <leseulartichaut@gmail.com>
2021-05-27 10:31:47 -04:00
bors
ea78d1edf3 Auto merge of #85737 - scottmcm:vec-calloc-option-nonzero, r=m-ou-se
Enable Vec's calloc optimization for Option<NonZero>

Someone on discord noticed that `vec![None::<NonZeroU32>; N]` wasn't getting the optimization, so here's a PR 🙃

We can certainly do this in the standard library because we know for sure this is ok, but I think it's also a necessary consequence of documented guarantees like those in https://doc.rust-lang.org/std/option/#representation and https://doc.rust-lang.org/core/num/struct.NonZeroU32.html

It feels weird to do this without adding a test, but I wasn't sure where that would belong.  Is it worth adding codegen tests for these?
2021-05-27 13:05:57 +00:00
bjorn3
6487127a05 Remove unused tidy dep exceptions 2021-05-27 13:23:32 +02:00
Alex Veber
ef13f27bc7 Add #[track_caller] to panic_any 2021-05-27 14:19:47 +03:00
bjorn3
fa702d0d2b Merge commit '40dd3e2b7089b5e96714e064b731f6dbf17c61a9' into sync_cg_clif-2021-05-27 2021-05-27 13:08:14 +02:00