Commit graph

14595 commits

Author SHA1 Message Date
Dylan DPC 291df97fae
Rollup merge of #98624 - davidtwco:translation-on-lints, r=compiler-errors
lints: mostly translatable diagnostics

As lints are created slightly differently than other diagnostics, intended to try make them translatable first and then look into the applicability of diagnostic structs but ended up just making most of the diagnostics in the crate translatable (which will still be useful if I do make a lot of them structs later anyway).

r? ``@compiler-errors``
2022-07-05 16:04:32 +05:30
bors 4045ce641a Auto merge of #98910 - Dylan-DPC:rollup-9x82wdg, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #97300 (Implement `FusedIterator` for `std::net::[Into]Incoming`)
 - #98761 (more `need_type_info` improvements)
 - #98811 (Interpret: AllocRange Debug impl, and use it more consistently)
 - #98847 (fix interpreter validity check on Box)
 - #98854 (clean up the borrowing in rustc_hir_pretty)
 - #98873 (Suggest `#[derive(Default)]` to enums with `#[default]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-05 06:44:49 +00:00
Dylan DPC 9a2274cf81
Rollup merge of #98873 - TaKO8Ki:suggest-default-derive-to-enum-with-default-attribute, r=fee1-dead
Suggest `#[derive(Default)]` to enums with `#[default]`

fixes #95226
2022-07-05 10:42:59 +05:30
Dylan DPC 6e5f1d491a
Rollup merge of #98854 - kadiwa4:rustc_hir_pretty_clean_up_borrowing, r=oli-obk
clean up the borrowing in rustc_hir_pretty

A whole lot of the `&`s and `ref`s were redundant. I hope doing this in one big commit is fine, because all of the changes are pretty self-contained.

`@rustbot` label: +C-cleanup
2022-07-05 10:42:58 +05:30
Dylan DPC 7702c50ea5
Rollup merge of #98847 - RalfJung:box-is-special, r=oli-obk
fix interpreter validity check on Box

Follow-up to https://github.com/rust-lang/rust/pull/98554: avoid walking over parts of the value twice.

And then move all that logic into the general visitor so not each visitor implementation has to deal with it...
2022-07-05 10:42:57 +05:30
Dylan DPC 522d52cef7
Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obk
Interpret: AllocRange Debug impl, and use it more consistently

The two commits are pretty independent but it did not seem worth having two PRs for them.
r? ``@oli-obk``
2022-07-05 10:42:55 +05:30
Dylan DPC 6a9db39f6c
Rollup merge of #98761 - lcnr:need_type_info-cont, r=estebank
more `need_type_info` improvements

this now deals with macros in suggestions and the source cost computation does what I want for `channel` 🎉

r? ``@estebank``
2022-07-05 10:42:54 +05:30
bors 880646ca9c Auto merge of #98872 - JakobDegen:no-invalidate, r=davidtwco
Add method to mutate MIR body without invalidating CFG caches.

In addition to adding this method, a handful of passes are updated to use it. There's still quite a few passes that could in principle make use of this as well, but do not at the moment because they use `VisitorMut` or `MirPatch`, which needs additional support for this.

The method name is slightly unwieldy, but I don't expect anyone to be writing it a lot, and at least it says what it does. If anyone has a suggestion for a better name though, would be happy to rename.

r? rust-lang/mir-opt
2022-07-05 04:04:04 +00:00
bors 4008dd8c6d Auto merge of #98846 - RalfJung:alignment-is-a-type-thing, r=oli-obk
interpret: track place alignment together with the type, not the value

This matches how I handle alignment in [MiniRust](https://github.com/RalfJung/minirust). I think it makes conceptually a lot more sense.
Fixes https://github.com/rust-lang/rust/issues/63085

r? `@oli-obk`
2022-07-05 01:23:09 +00:00
bors e1d1848cc6 Auto merge of #98904 - matthiaskrgr:rollup-05owsx7, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #98738 (Clarify MIR semantics of checked binary operations)
 - #98782 (Improve spans for specialization error)
 - #98793 (Lint against executable files in the root directory)
 - #98814 (rustdoc: Censor certain complex unevaluated const exprs)
 - #98878 (add more `rustc_pass_by_value`)
 - #98879 (Fix "wrap closure in parenthesis" suggestion for `async` closure)
 - #98886 (incr.comp.: Make split-dwarf commandline options [TRACKED].)
 - #98898 (Add "no-div-regex" eslint rule)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-04 22:42:15 +00:00
Matthias Krüger adfcb74db0
Rollup merge of #98886 - michaelwoerister:tracked-split-dwarf-kind, r=davidtwco
incr.comp.: Make split-dwarf commandline options [TRACKED].

This commandline options have an influence on the contents of object files (and .dwo files), so they need to be `[TRACKED]`.

r? `@davidtwco`
2022-07-04 23:11:14 +02:00
Matthias Krüger accb41ef01
Rollup merge of #98879 - compiler-errors:async-closure-wrap-parens, r=oli-obk
Fix "wrap closure in parenthesis" suggestion for `async` closure

Fixes #98023
2022-07-04 23:11:13 +02:00
Matthias Krüger cb2d3bb198
Rollup merge of #98878 - lcnr:more-rustc_pass_by_value, r=oli-obk
add more `rustc_pass_by_value`

r? ```@oli-obk``` cc #98766
2022-07-04 23:11:12 +02:00
Matthias Krüger da630de3bd
Rollup merge of #98782 - compiler-errors:specialization-error-span, r=oli-obk
Improve spans for specialization error

Fixes #98777
2022-07-04 23:11:09 +02:00
Matthias Krüger 82660a2525
Rollup merge of #98738 - tmiasko:checked-binop, r=oli-obk
Clarify MIR semantics of checked binary operations
2022-07-04 23:11:07 +02:00
bors 27eb6d7018 Auto merge of #98627 - RalfJung:interpret-arith, r=lcnr
interpret: don't rely on ScalarPair for overflowed arithmetic

This is for https://github.com/rust-lang/rust/pull/97861.
Cc `@eddyb`

I would like to avoid making this depend on `dest.layout.abi` to avoid a branch that we are not usually covering both sides of. Though OTOH this seems like fairly straight-forward code. But let's benchmark this option first to see how bad that extra `force_allocation` really is.
2022-07-04 20:00:41 +00:00
Ralf Jung 0850bad94d extra assertion, extra sure 2022-07-04 09:12:22 -04:00
Ralf Jung b1568e6f34 clarify comment 2022-07-04 09:05:23 -04:00
Michael Woerister 822957f49c incr.comp.: Make split-dwarf commandline options [TRACKED]. 2022-07-04 14:11:28 +02:00
lcnr f475e880a4 InferSource::GenericArg, check for contains 2022-07-04 14:04:07 +02:00
lcnr 7952d2ed83 resolve vars in node substs 2022-07-04 13:58:29 +02:00
lcnr eef34a648b stop suggesting things inside of macros 2022-07-04 13:58:29 +02:00
lcnr f1836c453a update infer cost computation for types 2022-07-04 13:58:29 +02:00
lcnr c2ed08715b remove unused function argument 2022-07-04 13:58:28 +02:00
Takayuki Maeda eb80407d79 suggest #[derive(Default)] to enums with #[default] 2022-07-04 20:46:59 +09:00
bors a3beeaa84d Auto merge of #98641 - lcnr:mir-dropck, r=oli-obk
fully move dropck to mir

r? `@oli-obk`
2022-07-04 09:23:01 +00:00
lcnr 8deadfa271 fully move dropck to mir 2022-07-04 10:26:23 +02:00
Michael Goulet eef56306f0 Fix wrap parenthesis suggestion for async closure 2022-07-04 08:07:12 +00:00
lcnr 658b7f3652 more rustc_pass_by_value 2022-07-04 09:40:58 +02:00
Jakob Degen 26d153ac67 Add method to mutate MIR body without invalidating CFG caches.
In addition to adding this method, a handful of passes are updated to use it.
2022-07-03 23:26:39 -07:00
Matthias Krüger 79add33692
Rollup merge of #98823 - compiler-errors:rust-call-mir-inline, r=cjgillot
Fix rust-call ICE in mir-inliner

Fixes #98821
r? ``@cjgillot``
2022-07-04 06:08:10 +02:00
Matthias Krüger 7352c7b6cd
Rollup merge of #98501 - Enselic:err_if_attr_found, r=compiler-errors
rustc_passes/src/entry.rs: De-duplicate more code with `fn throw_attr_err()`

So we can more easily re-use the code for other attributes later. More specifically [`#[unix_sigpipe]`](https://github.com/rust-lang/rust/pull/97802). This refactoring is covered by this test:
8aab472d52/src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs (L120)
(Well, only `#[start]`, but the code for `#[rustc_main]` is identical.)
2022-07-04 06:08:07 +02:00
Ralf Jung d7edf66a5a move Box mess handling into general visitor 2022-07-03 22:55:25 -04:00
Ralf Jung 7fc77806d4 fix interpreter validity check on Box 2022-07-03 22:42:50 -04:00
bors d46c728bcd Auto merge of #98446 - nnethercote:derive-no-match-destructuring, r=scottmcm
Don't use match-destructuring for derived ops on structs.

r? `@scottmcm`
2022-07-04 01:06:54 +00:00
Nicholas Nethercote ecc6e95ed4 Don't use match-destructuring for derived ops on structs.
All derive ops currently use match-destructuring to access fields. This
is reasonable for enums, but sub-optimal for structs. E.g.:
```
fn eq(&self, other: &Point) -> bool {
    match *other {
	Self { x: ref __self_1_0, y: ref __self_1_1 } =>
	    match *self {
		Self { x: ref __self_0_0, y: ref __self_0_1 } =>
		    (*__self_0_0) == (*__self_1_0) &&
			(*__self_0_1) == (*__self_1_1),
	    },
    }
}
```
This commit changes derive ops on structs to use field access instead, e.g.:
```
fn eq(&self, other: &Point) -> bool {
    self.x == other.x && self.y == other.y
}
```
This is faster to compile, results in smaller binaries, and is simpler to
generate. Unfortunately, we have to keep the old pattern generating code around
for `repr(packed)` structs because something like `&self.x` (which doesn't show
up in `PartialEq` ops, but does show up in `Debug` and `Hash` ops) isn't
allowed. But this commit at least changes those cases to use let-destructuring
instead of match-destructuring, e.g.:
```
fn hash<__H: ::core:#️⃣:Hasher>(&self, state: &mut __H) -> () {
    {
	let Self(ref __self_0_0) = *self;
	{ ::core:#️⃣:Hash::hash(&(*__self_0_0), state) }
    }
}
```
There are some unnecessary blocks remaining in the generated code, but I
will fix them in a follow-up PR.
2022-07-04 10:48:15 +10:00
Nicholas Nethercote 528343f93b Comment fixes.
Remove an out-of-date sentence, and fix a typo.
2022-07-04 10:48:15 +10:00
Ralf Jung ce76d7312f
Rollup merge of #98799 - jyn514:rustdoc-lint-help, r=GuillaumeGomez
Fix bug in `rustdoc -Whelp`

Previously, this printed the debugging options, not the lint options,
and only handled `-Whelp`, not `-A/-D/-F`.

This also fixes a few other misc issues:
- Fix `// check-stdout` for UI tests; previously it only worked for run-fail and compile-fail tests
- Add lint headers for tool lints, not just builtin lints

https://github.com/rust-lang/rust/pull/98533#issuecomment-1172004197

r? ```@GuillaumeGomez```
2022-07-03 16:41:57 -04:00
KaDiWa 46ccde4408
clean up the borrowing in rustc_hir_pretty
a lot of the `&`s and `ref`s were redundant
2022-07-03 18:51:14 +02:00
Ralf Jung 8955686e05 interpret: track place alignment together with the type, not the value 2022-07-03 10:22:37 -04:00
Ralf Jung 595dd976bd interpret: don't rely on ScalarPair for overflowed arithmetic 2022-07-03 09:56:31 -04:00
bors ada8c80bed Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bump bootstrap compiler

r? `@Mark-Simulacrum`
2022-07-03 06:55:50 +00:00
bors 8c52a83c45 Auto merge of #98570 - SparrowLii:deadlock, r=cjgillot
get rid of `tcx` in deadlock handler when parallel compilation

This is a very obscure and hard-to-trace problem that affects thread scheduling. If we copy `tcx` to the deadlock handler thread, it will perform unpredictable behavior and cause very weird problems when executing `try_collect_active_jobs`(For example, the deadlock handler thread suddenly preempts the content of the blocked worker thread and executes the unknown judgment branch, like #94654).
Fortunately we can avoid this behavior by precomputing `query_map`. This change fixes the following ui tests failure on my environment when set `parallel-compiler = true`:
```
    [ui] src/test\ui\async-await\no-const-async.rs
    [ui] src/test\ui\infinite\infinite-struct.rs
    [ui] src/test\ui\infinite\infinite-tag-type-recursion.rs
    [ui] src/test\ui\issues\issue-3008-1.rs
    [ui] src/test\ui\issues\issue-3008-2.rs
    [ui] src/test\ui\issues\issue-32326.rs
    [ui] src/test\ui\issues\issue-57271.rs
    [ui] src/test\ui\issues\issue-72554.rs
    [ui] src/test\ui\parser\fn-header-semantic-fail.rs
    [ui] src/test\ui\union\union-nonrepresentable.rs
```

Updates #75760
Fixes #94654
2022-07-03 02:05:14 +00:00
bors 5f98537eb7 Auto merge of #98569 - nnethercote:finalize_resolutions_id, r=cjgillot
Avoid unnecessary work in `finalize_resolutions_in`.

If `module.opt_def_id()` returns `None`, we can skip most of the work.

r? `@lqd`
2022-07-02 23:38:08 +00:00
Michael Goulet 34063199d8 Fix rust-call ICE in mir-inliner 2022-07-02 21:40:33 +00:00
Ralf Jung 0832d1d022
more use of format! variable capture
Co-authored-by: Joe ST <joe@fbstj.net>
2022-07-02 13:37:24 -04:00
bors 750d6f8545 Auto merge of #97585 - lqd:const-alloc-intern, r=RalfJung
CTFE interning: don't walk allocations that don't need it

The interning of const allocations visits the mplace looking for references to intern. Walking big aggregates like big static arrays can be costly, so we only do it if the allocation we're interning contains references or interior mutability.

Walking ZSTs was avoided before, and this optimization is now applied to cases where there are no references/relocations either.

---

While initially looking at this in the context of #93215, I've been testing with smaller allocations than the 16GB one in that issue, and with different init/uninit patterns (esp. via padding).

In that example, by default, `eval_to_allocation_raw` is the heaviest query followed by `incr_comp_serialize_result_cache`. So I'll show numbers when incremental compilation is disabled, to focus on the const allocations themselves at 95% of the compilation time, at bigger array sizes on these minimal examples like `static ARRAY: [u64; LEN] = [0; LEN];`.

That is a close construction to parts of the `ctfe-stress-test-5` benchmark, which has const allocations in the megabytes, while most crates usually have way smaller ones. This PR will have the most impact in these situations, as the walk during the interning starts to dominate the runtime.

Unicode crates (some of which are present in our benchmarks) like `ucd`, `encoding_rs`, etc come to mind as having bigger than usual allocations as well, because of big tables of code points (in the hundreds of KB, so still an order of magnitude or 2 less than the stress test).

In a check build, for a single static array shown above, from 100 to 10^9 u64s (for lengths in powers of ten), the constant factors are lowered:

(log scales for easier comparisons)
![plot_log](https://user-images.githubusercontent.com/247183/171422958-16f1ea19-3ed4-4643-812c-1c7c60a97e19.png)

(linear scale for absolute diff at higher Ns)
![plot_linear](https://user-images.githubusercontent.com/247183/171401886-2a869a4d-5cd5-47d3-9a5f-8ce34b7a6917.png)

For one of the alternatives of that issue
```rust
const ROWS: usize = 100_000;
const COLS: usize = 10_000;

static TWODARRAY: [[u128; COLS]; ROWS] = [[0; COLS]; ROWS];
```

we can see a similar reduction of around 3x (from 38s to 12s or so).

For the same size, the slowest case IIRC is when there are uninitialized bytes e.g. via padding

```rust
const ROWS: usize = 100_000;
const COLS: usize = 10_000;

static TWODARRAY: [[(u64, u8); COLS]; ROWS] = [[(0, 0); COLS]; ROWS];
```
then interning/walking does not dominate anymore (but means there is likely still some interesting work left to do here).

Compile times in this case rise up quite a bit, and avoiding interning walks has less impact: around 23%, from 730s on master to 568s with this PR.
2022-07-02 17:05:13 +00:00
Ralf Jung d31cbb5150 make AllocRef APIs more consistent 2022-07-02 11:41:16 -04:00
Ralf Jung c36572c11e add AllocRange Debug impl; remove redundant AllocId Display impl 2022-07-02 11:41:16 -04:00
bors 6a10920564 Auto merge of #97235 - nbdd0121:unwind, r=Amanieu
Fix FFI-unwind unsoundness with mixed panic mode

UB maybe introduced when an FFI exception happens in a `C-unwind` foreign function and it propagates through a crate compiled with `-C panic=unwind` into a crate compiled with `-C panic=abort` (#96926).

To prevent this unsoundness from happening, we will disallow a crate compiled with `-C panic=unwind` to be linked into `panic-abort` *if* it contains a call to `C-unwind` foreign function or function pointer. If no such call exists, then we continue to allow such mixed panic mode linking because it's sound (and stable). In fact we still need the ability to do mixed panic mode linking for std, because we only compile std once with `-C panic=unwind` and link it regardless panic strategy.

For libraries that wish to remain compile-once-and-linkable-to-both-panic-runtimes, a `ffi_unwind_calls` lint is added (gated under `c_unwind` feature gate) to flag any FFI unwind calls that will cause the linkable panic runtime be restricted.

In summary:
```rust
#![warn(ffi_unwind_calls)]

mod foo {
    #[no_mangle]
    pub extern "C-unwind" fn foo() {}
}

extern "C-unwind" {
    fn foo();
}

fn main() {
    // Call to Rust function is fine regardless ABI.
    foo::foo();
    // Call to foreign function, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    unsafe { foo(); }
    //~^ WARNING call to foreign function with FFI-unwind ABI
    let ptr: extern "C-unwind" fn() = foo::foo;
    // Call to function pointer, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    ptr();
    //~^ WARNING call to function pointer with FFI-unwind ABI
}
```

Fix #96926

`@rustbot` label: T-compiler F-c_unwind
2022-07-02 14:06:27 +00:00