Commit Graph

230040 Commits

Author SHA1 Message Date
Matthias Krüger
2734b5ada9
Rollup merge of #113723 - khei4:khei4/llvm-stats, r=oli-obk,nikic
Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.

This resurrects PR https://github.com/rust-lang/rust/pull/104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :).

I have applied the changes requested by `@oli-obk` and `@nagisa`  https://github.com/rust-lang/rust/pull/104000#discussion_r1014625377 and https://github.com/rust-lang/rust/pull/104000#discussion_r1014642482 in the latest commits.

r? `@oli-obk`

-----

LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too.

-----
(Edit: fix broken link
(Edit2: fix segmentation fault and use malloc

If `rustc` is built with
```toml
[llvm]
assertions = true
```
Then you can see like
```
rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
         3 aa                           - Number of MayAlias results
       193 aa                           - Number of MustAlias results
       531 aa                           - Number of NoAlias results
...
```

And the current default build emits only
```
$ rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
$
```
This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
2023-07-21 06:52:27 +02:00
Matthias Krüger
20ce7f17c7
Rollup merge of #113380 - joshtriplett:style-guide-cleanup-must-should-may, r=calebcartwright
style-guide: clean up "must"/"should"/"may"

Avoid using "should" or "may" for required parts of the default style.

The style guide inconsistently used language like "there should be a space" or
"it should be on its own line", or "may be written on a single line", for
things that are required components of the default Rust style. "should" and
especially "may" come across as optional. While the style guide overall now has
a statement at the top that the default style itself is a *recommendation*, the
*definition* of the default style should not be ambiguous about what's part of
the default style.

Rewrite language in the style guide to only use "should" and "may" and similar
for truly optional components of the style (e.g. things a tool cannot or should
not enforce in its default configuration).

In their place, either use "must", or rewrite in imperative style ("put a
space", "start it on the same line"). The latter also substantially reduces the
use of passive voice.

Looking for "should"s also flagged some recommendations the style guide made
for configurability of tools (e.g. a tool "should" have a given configuration
option). I've removed those recommendations, per discussion with the style
team; it's not the domain of the style guide to make such recommendations, only
to define the default Rust style.

In the process of making this change, I also fixed a typo, fixed a text structure
issue, fixed an example that didn't match the Rust style (missing a trailing
comma), and added an additional example for clarity. (Those changes would have
conflicted with this one.) Those changes appear in separate commits.

These are all purely editorial changes, and do not affect the semantic
definition of the Rust style.
2023-07-21 06:52:27 +02:00
bors
d26f0b79d5 Auto merge of #105571 - kadiwa4:remove_atomic_init_consts, r=Amanieu
remove the unstable `core::sync::atomic::ATOMIC_*_INIT` constants

Tracking issue: #99069

It would be weird to ever stabilise these as they are already deprecated.
2023-07-21 01:59:34 +00:00
Josh Triplett
77d09cb69e Clarify wording on breaking arrays across lines
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2023-07-20 17:57:21 -07:00
Josh Triplett
144e8a3866 style-guide: Fix example to match the rule it exemplifies (and match rustfmt)
An example immediately following "Put each bound on its own line." did
not put each bound on its own line.
2023-07-20 17:57:21 -07:00
Josh Triplett
69d29a70da style-guide: Fix typo: s/right-hand side/left-hand side/ 2023-07-20 17:57:21 -07:00
Josh Triplett
9ccc104d14 style-guide: Add an additional chaining example
Make it clear the rule for stacking the second line on the first applies
recursively, as long as the condition holds.
2023-07-20 17:57:21 -07:00
Josh Triplett
ce5aca9f5a style-guide: Avoid using "should" or "may" for required parts of the default style
The style guide inconsistently used language like "there should be a
space" or "it should be on its own line", or "may be written on a single
line", for things that are required components of the default Rust
style. "should" and especially "may" come across as optional. While the
style guide overall now has a statement at the top that the default
style itself is a *recommendation*, the *definition* of the default
style should not be ambiguous about what's part of the default style.

Rewrite language in the style guide to only use "should" and "may" and
similar for truly optional components of the style (e.g. things a tool
cannot or should not enforce in its default configuration).

In their place, either use "must", or rewrite in imperative style ("put
a space", "start it on the same line"). The latter also substantially
reduces the use of passive voice.

This is a purely editorial change, and does not affect the semantic
definition of the Rust style.
2023-07-20 17:57:18 -07:00
Josh Triplett
081e15a0d8 style-guide: Simplify the structure of a recommendation (no semantic change)
Avoid putting a sentence fragment after a list; integrate it with the
sentence before the list.
2023-07-20 17:54:51 -07:00
Josh Triplett
615b58b9f9 style-guide: Fix an example to match the style
The style guide requires a trailing comma on where clause components,
but then gives an example that doesn't include one. Add the missing
trailing comma.
2023-07-20 17:54:51 -07:00
Josh Triplett
cf4b20d7cc style-guide: Fix typo: s/forth/fourth/g 2023-07-20 17:54:51 -07:00
Josh Triplett
715efa418e style-guide: Remove material about tool configurability
The style guide discusses the default Rust style. Configurability of
Rust formatting tools are not the domain of the style guide.
2023-07-20 17:54:50 -07:00
bors
c720a9cd12 Auto merge of #113344 - scottmcm:alt-slice-zst-handing, r=the8472
Get `!nonnull` metadata on slice iterators, without `assume`s

This updates the non-ZST paths to read the end pointer through a pointer-to-`NonNull`, so that they all get `!nonnull` metadata.

That means that the last `assume(!ptr.is_null())` can be deleted, without impacting codegen -- the codegen tests confirm the LLVM-IR ends up exactly the same as before.
2023-07-21 00:11:41 +00:00
bors
e2a7ba2771 Auto merge of #113858 - cjgillot:const-prop-pairs, r=oli-obk
Always const-prop scalars and scalar pairs

This removes some complexity from the pass.

The limitation to propagate ScalarPairs only for tuple comes from https://github.com/rust-lang/rust/pull/67015, when ScalarPair constant were modeled using `Rvalue::Aggregate`. Nowadays, we use `ConstValue::ByRef`, which does not care about the underlying type.

The justification for not propagating in all cases was perf. This seems not to be a clear cut any more: https://github.com/rust-lang/rust/pull/113858#issuecomment-1642396746
2023-07-20 22:22:31 +00:00
Camille GILLOT
4a177406ee Inline should_const_prop. 2023-07-20 21:30:51 +00:00
Camille GILLOT
3f708add2f Remove visit_terminator. 2023-07-20 21:30:51 +00:00
Camille GILLOT
ccfa9af29d Propagate ScalarPair for any type. 2023-07-20 21:30:51 +00:00
Camille GILLOT
895e2159f8 Also propagate ScalarPair operands. 2023-07-20 21:30:51 +00:00
Camille GILLOT
12a2edd149 Always propagate into operands. 2023-07-20 21:30:51 +00:00
bors
399b068235 Auto merge of #113856 - WaffleLapkin:vtablin', r=oli-obk
Refactor vtable encoding and optimize it for the case of multiple marker traits

This PR does two things
- Refactor `prepare_vtable_segments` (this was motivated by the other change, `prepare_vtable_segments` was quite hard to understand and while trying to edit it I've refactored it)
  - Mostly remove `loop`s labeled `break`s/`continue`s whenever there is a simpler solution
  - Also use `?`
- Make vtable format a bit more efficient wrt to marker traits
  - See the tests for an example

Fixes https://github.com/rust-lang/rust/issues/113840
cc `@crlf0710`

----

Review wise it's probably best to review each commit individually, as then it's more clear why the refactoring is correct.

I can split the last two commits (which change behavior) into a separate PR if it makes reviewing easier
2023-07-20 20:34:06 +00:00
bors
1554942cdc Auto merge of #113546 - cjgillot:unused-query, r=compiler-errors
Querify unused trait check.

This code transitively loads information for all bodies, and from resolutions. As it does not return a value, it should be beneficial to have it as a query.
2023-07-20 18:45:09 +00:00
Scott McMurray
34732e8560 Get !nonnull metadata consistently in slice iterators, without needing assumes 2023-07-20 11:33:49 -07:00
bors
092e4f46be Auto merge of #113890 - matthiaskrgr:rollup-k1w2vii, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #110765 (rustdoc: fix position of `default` in method rendering)
 - #113529 (Permit pre-evaluated constants in simd_shuffle)
 - #113800 (Avoid another gha group nesting)
 - #113827 (Add Foreign, Never, FnDef, Closure and Generator tys to SMIR)
 - #113835 (new solver: don't consider blanket impls multiple times)
 - #113883 (Remove outdated Firefox-specific CSS for search's crate selector appearance)
 - #113884 (Don't translate compiler-internal bug messages)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-20 16:57:05 +00:00
Matthias Krüger
464e02a267
Rollup merge of #113884 - oli-obk:delay_span_bug_detrans_late, r=davidtwco
Don't translate compiler-internal bug messages

These are not very useful to be translated, as

* translators would get really weird and bad english versions to start out from,
* compiler devs have to do some work for what is supposed to be dead code and just a sanity check,
* the target audience is other compiler devs.

r? `@davidtwco`
2023-07-20 17:19:34 +02:00
Matthias Krüger
8ac957aa03
Rollup merge of #113883 - steffahn:rustdoc-search-crate-selector-padding, r=GuillaumeGomez
Remove outdated Firefox-specific CSS for search's crate selector appearance

Remove adjustments that used to be necessary for search's crate selector appearance (padding) to look identical on Firefox. New versions of Firefox appear to have changed behavior to agree with Chrome.

As briefly discussed in https://github.com/rust-lang/rust/pull/98855#issuecomment-1624098112

r? ``@GuillaumeGomez``
2023-07-20 17:19:34 +02:00
Matthias Krüger
add8298aff
Rollup merge of #113835 - lcnr:assemble-candidates-considering-self-ty, r=compiler-errors
new solver: don't consider blanket impls multiple times

only consider candidates which rely on the self type in `assemble_candidates_after_normalizing_self_ty`.

r? ``@compiler-errors``
2023-07-20 17:19:33 +02:00
Matthias Krüger
1a748f0460
Rollup merge of #113827 - spastorino:smir-types-4, r=oli-obk
Add Foreign, Never, FnDef, Closure and Generator tys to SMIR

r? ``@oli-obk``
2023-07-20 17:19:33 +02:00
Matthias Krüger
6102785a29
Rollup merge of #113800 - oli-obk:gha_ci_cycle, r=jyn514
Avoid another gha group nesting

fixes https://github.com/rust-lang/rust/issues/113798 (`x test error_index_generator` did not work locally anymore)

r? ``@jyn514``
2023-07-20 17:19:32 +02:00
Matthias Krüger
8c17e0701e
Rollup merge of #113529 - oli-obk:simd_shuffle_evaluated, r=wesleywiser
Permit pre-evaluated constants in simd_shuffle

fixes https://github.com/rust-lang/rust/issues/113500
2023-07-20 17:19:32 +02:00
Matthias Krüger
80f749dfa0
Rollup merge of #110765 - wackbyte:fix-defaultness-position, r=fmease,GuillaumeGomez
rustdoc: fix position of `default` in method rendering

With the following code:
```rs
#![feature(specialization)]

pub trait A {
    unsafe fn a();
}

impl A for () {
    default unsafe fn a() {}
}
```
rustdoc would render the `impl` of `a` as
```rs
unsafe default fn a()
```
which is inconsistent with the actual position of `default`.
This PR fixes this issue.
2023-07-20 17:19:32 +02:00
bors
06a53ddc0b Auto merge of #113758 - cjgillot:move-dse, r=JakobDegen,oli-obk
Turn copy into moves during DSE.

Dead store elimination computes whether removing a direct store to an unborrowed place is allowed.
Where removing a store is allowed, writing `uninit` is too.

This means that we can use this pass to transform `copy` operands into `move` operands. This is only interesting in call terminators, so we only handle those.

Special care is taken for the `use_both(_1, _1)` case:
- moving the second argument is ok, as `_1` is not live after the call;
- moving the first argument is not, as the second argument reads `_1`.

Fixes #75993
Fixes https://github.com/rust-lang/rust/issues/108068

r? `@RalfJung`
cc `@JakobDegen`
2023-07-20 15:05:39 +00:00
bors
6b53175b5d Auto merge of #113861 - ibraheemdev:mpsc-tls-bug, r=Mark-Simulacrum
Avoid tls access while iterating through mpsc thread entries

Upstream fix: https://github.com/crossbeam-rs/crossbeam/pull/802. Possibly fixes https://github.com/rust-lang/rust/issues/113726.
2023-07-20 12:30:12 +00:00
lcnr
5c75bc5317 update doc comments 2023-07-20 12:01:34 +02:00
lcnr
2062f2ca82 review 2023-07-20 12:01:34 +02:00
Oli Scherer
d97ec97b94 Don't translate compiler-internal bug messages 2023-07-20 09:51:47 +00:00
Oli Scherer
7de9b654b7 Avoid another gha group nesting 2023-07-20 09:42:53 +00:00
lcnr
7c97a76b76 re-add comment 2023-07-20 11:05:52 +02:00
lcnr
aa28b77b5a add FIXME 2023-07-20 11:05:52 +02:00
lcnr
2d99f40ec5 assembly: only consider blanket impls once 2023-07-20 11:05:52 +02:00
lcnr
fdaec57a28 XSimplifiedType to SimplifiedType::X 2023-07-20 11:05:52 +02:00
bors
b14fd2359f Auto merge of #113695 - bjorn3:fix_rlib_cdylib_metadata_handling, r=pnkfelix,petrochenkov
Verify that all crate sources are in sync

This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib.

Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons.

Fixes https://github.com/rust-lang/rust/issues/10786
Fixes https://github.com/rust-lang/rust/issues/82151
Fixes https://github.com/rust-lang/rust/issues/82972
Closes https://github.com/bevy-cheatbook/bevy-cheatbook/issues/114
2023-07-20 09:00:10 +00:00
Oli Scherer
c7428d5052 Monomorphize constants before inspecting them 2023-07-20 08:53:09 +00:00
Frank Steffahn
2009b4a5cc Remove adjustments that used to be necessary for search's crate selector appearance (padding)
to look identical on Firefox. New versions of Firefox appear to have changed behavior to agree with Chrome.
2023-07-20 17:46:32 +09:00
khei4
c7bf20dfdc address feedback from nikic and oli-obk https://github.com/rust-lang/rust/pull/113723/files
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2023-07-20 16:53:06 +09:00
bors
c67cb3e577 Auto merge of #113878 - matthiaskrgr:rollup-u0d3kzx, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #113710 (Fix rpath for libdir is specified)
 - #113787 (Update documentation for std::process::Command's new method)
 - #113795 (Properly document `lifetime_mapping` in `OpaqueTy`)
 - #113857 (Add tests for `--document-hidden-items` option)
 - #113871 (Use the correct span for displaying the line following a derive sugge…)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-20 07:12:22 +00:00
Matthias Krüger
770c8d0667
Rollup merge of #113871 - clubby789:derive-sugg-span, r=compiler-errors
Use the correct span for displaying the line following a derive sugge…

`span` here is the main span of the diagnostic. In the linked issue's case, this belongs to `main.rs`. However, the line numbers (and line we are trying to display) are in `name.rs`, so using `span_to_lines` gives us the wrong `FileLines`.

Use `parts[0].span` (the span of the suggestion) here like the rest of the code does to get the right file.

Not sure if this needs a dedicated test because this fixes an existing error in the UI suite

Fixes #113844
2023-07-20 07:08:43 +02:00
Matthias Krüger
53580da72d
Rollup merge of #113857 - GuillaumeGomez:document-hidden-items-test, r=notriddle
Add tests for `--document-hidden-items` option

Since `--document-hidden-items` was greatly fixed/improved in https://github.com/rust-lang/rust/pull/113574, thought it might be worth adding some more tests for it to prevent new regressions.

As for the first commit, it allows to go from:

```
Traceback (most recent call last):
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 706, in <module>
    check(sys.argv[1], get_commands(rust_test_path))
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 689, in check
    for c in commands:
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 274, in get_commands
    args = shlex.split(args)
  File "/usr/lib/python3.10/shlex.py", line 315, in split
    return list(lex)
  File "/usr/lib/python3.10/shlex.py", line 300, in __next__
    token = self.get_token()
  File "/usr/lib/python3.10/shlex.py", line 109, in get_token
    raw = self.read_token()
  File "/usr/lib/python3.10/shlex.py", line 191, in read_token
    raise ValueError("No closing quotation")
ValueError: No closing quotation
```

to:

```
Traceback (most recent call last):
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 708, in <module>
    check(sys.argv[1], get_commands(rust_test_path))
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 691, in check
    for c in commands:
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 278, in get_commands
    raise Exception("line {}: {}".format(lineno + 1, exc)) from None
Exception: line 57: No closing quotation
```

Having the line where the error occurred is quite useful.

r? `@notriddle`
2023-07-20 07:08:43 +02:00
Matthias Krüger
b128750bc4
Rollup merge of #113795 - compiler-errors:doc, r=spastorino
Properly document `lifetime_mapping` in `OpaqueTy`

Also use an `Option` to signify that the value is actually present, instead of just no captured lifetimes.
2023-07-20 07:08:42 +02:00
Matthias Krüger
538dcdad31
Rollup merge of #113787 - sanchopanca:process-command-windows-docs, r=ChrisDenton
Update documentation for std::process::Command's new method

In the current documentation, it's not specified that when creating a Command, the .exe extension can be omitted for Windows executables. However, for other types of executable files like .bat or .cmd, the complete filename including the extension must be provided.

I encountered it by noticing that `Command::new("wt").spawn().unwrap()` succeeds on my machine while `Command::new("code").spawn().unwrap()` panics. Turns out VS Code's entrypoint is .cmd file.

`resolve_exe` method mentions this behaviour in [a comment](e7fda447e7/library/std/src/sys/windows/process.rs (L425)), but it makes sense to mention it at a more visible place.

I've added this clarification to the documentation, which should make it more accurate and helpful for Rust developers working on the Windows platform.
2023-07-20 07:08:42 +02:00
Matthias Krüger
8027dd95cf
Rollup merge of #113710 - loongarch-rs:fix-rpath, r=clubby789
Fix rpath for libdir is specified

## What does this PR try to resolve?

When building the Rust toolchain with `--libdir=lib64`, the executable tools such as `rustc` cannot find shared libraries.

```bash
./configure --prefix=/ --libdir=lib64
DESTDIR=/tmp/rust ./x.py install
```

```
$ /tmp/rust/bin/rustc
rustc: error while loading shared libraries: librustc_driver-13f1fd1bc7f7000d.so: cannot open shared object file: No such file or directory
```

This issue is caused by the link args `-Wl,rpath` being different from `--libdir`.

```
$ readelf -d /tmp/rust/bin/rustc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib]
```

## How to resolve?

When setting the rpath, get it from sysroot libdir relative path.

After this patch:

```
$ readelf -d /tmp/rust/bin/rustc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib64]
```
2023-07-20 07:08:41 +02:00