Commit graph

143499 commits

Author SHA1 Message Date
Guillaume Gomez 8ea8252ca5
Rollup merge of #85329 - RalfJung:version, r=Mark-Simulacrum
fix version_str comment

This version string is ultimately generated here
87423fbc6a/src/bootstrap/channel.rs (L72)
and I don't think it includes the `rustc` prefix. That also matches its use here
ac923d94f8/compiler/rustc_driver/src/lib.rs (L758)
2021-05-15 17:56:50 +02:00
Guillaume Gomez 7a6a25eb2e
Rollup merge of #85324 - FabianWolff:issue-85255, r=varkor
Warn about unused `pub` fields in non-`pub` structs

This pull request fixes #85255. The current implementation of dead code analysis is too prudent because it marks all `pub` fields of structs as live, even though they cannot be accessed from outside of the current crate if the struct itself only has restricted or private visibility.

I have changed this behavior to take the containing struct's visibility into account when looking at field visibility and liveness. This also makes dead code warnings more consistent; consider the example given in #85255:
```rust
struct Foo {
    a: i32,
    pub b: i32,
}

struct Bar;

impl Bar {
    fn a(&self) -> i32 { 5 }
    pub fn b(&self) -> i32 { 6 }
}

fn main() {
    let _ = Foo { a: 1, b: 2 };
    let _ = Bar;
}
```
Current nightly already warns about `Bar::b()`, even though it is `pub` (but `Bar` is not). It should therefore also warn about `Foo::b`, which it does with the changes in this PR.
2021-05-15 17:56:49 +02:00
Guillaume Gomez f851f97e87
Rollup merge of #85185 - GuillaumeGomez:generate-not-more-docs-than-necessary, r=Mark-Simulacrum
Generate not more docs than necessary

This is something that `@Nemo157` was talking about: they wanted that when using `x.py doc std`, it only generated `std` (and the crates "before" it).

r? `@Mark-Simulacrum`
2021-05-15 17:56:48 +02:00
Guillaume Gomez 62b834fb9f
Rollup merge of #84751 - Soveu:is_char_boundary_opt, r=Amanieu
str::is_char_boundary - slight optimization

Current `str::is_char_boundary` implementation emits slightly more instructions, because it includes an additional branch for `index == s.len()`
```rust
pub fn is_char_boundary(s: &str, index: usize) -> bool {
    if index == 0 || index == s.len() {
        return true;
    }
    match s.as_bytes().get(index) {
        None => false,
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
Just changing the place of `index == s.len()` merges it with `index < s.len()` from `s.as_bytes().get(index)`
```rust
pub fn is_char_boundary2(s: &str, index: usize) -> bool {
    if index == 0 {
        return true;
    }

    match s.as_bytes().get(index) {
        // For some reason, LLVM likes this comparison here more
        None => index == s.len(),
        // This is bit magic equivalent to: b < 128 || b >= 192
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
This one has better codegen on every platform, except powerpc
<details><summary>x86 codegen</summary>
<p>

```nasm
example::is_char_boundary:
        mov     al, 1
        test    rdx, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        jbe     .LBB0_3
        cmp     byte ptr [rdi + rdx], -65
        setg    al
.LBB0_5:
        ret
.LBB0_3:
        xor     eax, eax
        ret

example::is_char_boundary2:
        test    rdx, rdx
        je      .LBB1_1
        cmp     rsi, rdx
        jbe     .LBB1_4
        cmp     byte ptr [rdi + rdx], -65
        setg    al
        ret
.LBB1_1:  ; technically this branch is the same as LBB1_4
        mov     al, 1
        ret
.LBB1_4:
        sete    al
        ret
 ```
</p>
</details>

<details><summary>aarch64 codegen</summary>
<p>

```as
example::is_char_boundary:
        mov     x8, x0
        mov     w0, #1
        cbz     x2, .LBB0_4
        cmp     x1, x2
        b.eq    .LBB0_4
        b.ls    .LBB0_5
        ldrsb   w8, [x8, x2]
        cmn     w8, #65
        cset    w0, gt
.LBB0_4:
        ret
.LBB0_5:
        mov     w0, wzr
        ret

example::is_char_boundary2:
        cbz     x2, .LBB1_3
        cmp     x1, x2
        b.ls    .LBB1_4
        ldrsb   w8, [x0, x2]
        cmn     w8, #65
        cset    w0, gt
        ret
.LBB1_3:
        mov     w0, #1
        ret
.LBB1_4:
        cset    w0, eq
        ret
```

</p>
</details>

<details><summary>riscv64gc codegen</summary>
<p>

example::is_char_boundary:
        seqz    a3, a2
        xor     a4, a1, a2
        seqz    a4, a4
        or      a4, a4, a3
        addi    a3, zero, 1
        bnez    a4, .LBB0_3
        bgeu    a2, a1, .LBB0_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a3, a1, a0
.LBB0_3:
        mv      a0, a3
        ret
.LBB0_4:
        mv      a0, zero
        ret

example::is_char_boundary2:
        beqz    a2, .LBB1_3
        bgeu    a2, a1, .LBB1_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a0, a1, a0
        ret
.LBB1_3:
        addi    a0, zero, 1
        ret
.LBB1_4:
        xor     a0, a1, a2
        seqz    a0, a0
        ret

</p>
</details>

[Link to godbolt](https://godbolt.org/z/K8avEz8Gr)

`@rustbot` label: A-codegen
2021-05-15 17:56:47 +02:00
Guillaume Gomez b9b67b7d5b Don't generate more docs than necessary 2021-05-15 17:21:12 +02:00
bors 2a245f40a1 Auto merge of #85328 - GuillaumeGomez:rollup-exe9nbj, r=GuillaumeGomez
Rollup of 12 pull requests

Successful merges:

 - #84461 (rustdoc: Remove unnecessary `StripItem` wrapper)
 - #85067 (Minimize amount of fake `DefId`s used in rustdoc)
 - #85207 (Fix typo in comment)
 - #85215 (coverage bug fixes and some refactoring)
 - #85221 (dbg macro: Discuss use in tests, and slightly clarify)
 - #85246 (Miner code formatting)
 - #85253 (swap function order for better read flow)
 - #85256 (Fix display for "implementors" section)
 - #85268 (Use my real name)
 - #85278 (Improve match statements)
 - #85289 (Fix toggle position on mobile)
 - #85323 (Fix eslint errors)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-15 12:41:28 +00:00
Ralf Jung c96d531a92 fix version_str comment 2021-05-15 14:22:29 +02:00
Guillaume Gomez 46bc5526db
Rollup merge of #85323 - GuillaumeGomez:fix-eslint-errors, r=jsha
Fix eslint errors

I cherry-picked the two non-CI commits from #85285.

r? ```@jsha```
2021-05-15 13:29:57 +02:00
Guillaume Gomez 2b5ef25744
Rollup merge of #85289 - GuillaumeGomez:fix-toggle-position-mobile, r=jsha
Fix toggle position on mobile

Before:

![Screenshot from 2021-05-14 14-21-27](https://user-images.githubusercontent.com/3050060/118276475-fe210300-b4c7-11eb-94f8-4e2a4e10d91e.png)
![Screenshot from 2021-05-14 14-21-30](https://user-images.githubusercontent.com/3050060/118276479-feb99980-b4c7-11eb-85db-40e9df6e9abd.png)

After:

![Screenshot from 2021-05-14 15-16-54](https://user-images.githubusercontent.com/3050060/118276494-0416e400-b4c8-11eb-9479-d447928cfa62.png)
![Screenshot from 2021-05-14 15-16-59](https://user-images.githubusercontent.com/3050060/118276498-0416e400-b4c8-11eb-99f6-894276c62dfc.png)

r? ```@jsha```
2021-05-15 13:29:56 +02:00
Guillaume Gomez cd3d166021
Rollup merge of #85278 - ayushmishra2005:code-refactoring, r=jackh726
Improve match statements
2021-05-15 13:29:55 +02:00
Guillaume Gomez 1a926bf3c5
Rollup merge of #85268 - camelid:real-name, r=Mark-Simulacrum
Use my real name
2021-05-15 13:29:54 +02:00
Guillaume Gomez 5bfbabc892
Rollup merge of #85256 - GuillaumeGomez:fix-implementors-display, r=notriddle
Fix display for "implementors" section

Just saw this problem when going through docs:

![Screenshot from 2021-05-13 15-20-52](https://user-images.githubusercontent.com/3050060/118131978-766fc180-b3ff-11eb-86a8-7f6d22afa675.png)

This fix puts it back to normal:

![Screenshot from 2021-05-13 15-23-29](https://user-images.githubusercontent.com/3050060/118132006-7e2f6600-b3ff-11eb-9985-025a7b7c5216.png)

You can see it on the `TryFrom` page for example.

r? ```@Nemo157```
2021-05-15 13:29:53 +02:00
Guillaume Gomez 36b3c28497
Rollup merge of #85253 - RafaelKr:patch-1, r=varkor
swap function order for better read flow

I was reading this error message for the first time.

I was a little bit confused when reading that part:
```
foo.bar(); // we can now use this method since i32 implements the Foo trait
```

At the time I was reading `// we can now use this method` I wasn't sure why. It only made sense when reading on. So swapping these parts results in a better read flow.
2021-05-15 13:29:52 +02:00
Guillaume Gomez 57aa0d812a
Rollup merge of #85246 - ayushmishra2005:minor-reactoring, r=petrochenkov
Miner code formatting
2021-05-15 13:29:51 +02:00
Guillaume Gomez 5a8619b435
Rollup merge of #85221 - ijackson:dbg-doc-re-tests, r=joshtriplett
dbg macro: Discuss use in tests, and slightly clarify

As discussed in a tangent in #82778.

I chose to use [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) in the source text but I don't mind reformatting it.
2021-05-15 13:29:50 +02:00
Guillaume Gomez e611e64e3a
Rollup merge of #85215 - richkadel:ice-fixes-minus-dead-blocks, r=tmandry
coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR #85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? ```@tmandry```
2021-05-15 13:29:49 +02:00
Guillaume Gomez c4f81c12ea
Rollup merge of #85207 - andrewhalle:typo-rootseparator, r=kennytm
Fix typo in comment

missing space in "rootseparator"
2021-05-15 13:29:48 +02:00
Guillaume Gomez b68d5433c9
Rollup merge of #85067 - Stupremee:minimize-amount-of-fake-defids, r=jyn514,GuillaumeGomez
Minimize amount of fake `DefId`s used in rustdoc

Follow up from #84707, which minimizes the amount of fake defids to the smallest amount possible. Every `FakeDefId` that is now used in the rustdoc library must be preserved and can not be replaced with a normal `DefId`.
2021-05-15 13:29:47 +02:00
Guillaume Gomez 9682fa9dc4
Rollup merge of #84461 - jyn514:remove-strip-item, r=GuillaumeGomez
rustdoc: Remove unnecessary `StripItem` wrapper
2021-05-15 13:29:47 +02:00
Justus K 67d8d18b23
Minimize amount of fake DefIds used in rustdoc 2021-05-15 13:21:35 +02:00
Guillaume Gomez 18b7c0a00e Update rustdoc-js tools 2021-05-15 13:09:55 +02:00
Guillaume Gomez ccabd4eedf Fix eslint errors 2021-05-15 13:09:28 +02:00
Fabian Wolff 46d55d6549 Warn about unused pub fields in non-pub structs 2021-05-15 13:06:17 +02:00
bors b439be03c9 Auto merge of #84152 - sexxi-goose:insignificant_dtor, r=nikomatsakis
Insignificant destructors rfc 2229

- Adds new attribute `rustc_insignificant_dtor` to annotate the drop method.
- Adds a query to check if a type has a significant drop.
- Updates closure analysis to check for significant drops rather than just drop.

A type marked with the attribute `rustc_insignificant_dtor` is considered to not be significant. A drop is significant if it is implemented by the user or does anything that will have any observable behavior (other than freeing up memory).

https://github.com/rust-lang/project-rfc-2229/issues/35
2021-05-15 10:00:39 +00:00
bors c6dd87a6b4 Auto merge of #85311 - camelid:box-blanket-impl, r=jyn514
Box `Impl.blanket_impl` to reduce size

Blanket impls are probably not super common, and `Type` is a fairly
large type, so this should reduce `Impl`'s size by a lot: `Option<Type>`
is around 96 bytes, and `Option<Box<Type>>` is 8 bytes, so it's a big
difference!
2021-05-15 07:44:21 +00:00
bors 428636f954 Auto merge of #84997 - pietroalbini:ci-verify-channel, r=Mark-Simulacrum
Error out if a PR is sent to the wrong channel

It happened multiple times that a PR meant to go on beta ends up being opened (and occasionally merged) to master. This PR does two things:

* Moves the definition of the channel in `src/ci/channel` so it's easier for tools to read it. I was not sure whether to move it to `src/channel` (like `src/version`): ended up with `src/ci` as it's currently only used for CI, but I'm open to moving it to `src`. We'll need to update the release process after this.
* Adds a check on **non-bors** builds that errors out if the base branch is not the expected one for the currently defined channel. This will not cause problems for promotion PRs, as those PRs are meant to also update the channel name.

r? `@Mark-Simulacrum`
2021-05-15 05:20:49 +00:00
Dhruv Jauhar a7e1cec621 add new attribute rustc_insignificant_dtor and a query to check if a type has a significant drop 2021-05-14 22:57:33 -04:00
Noah Lev f57537e5f3 Box Impl.blanket_impl to reduce size
Blanket impls are probably not super common, and `Type` is a fairly
large type, so this should reduce `Impl`'s size by a lot: `Option<Type>`
is around 96 bytes, and `Option<Box<Type>>` is 8 bytes, so it's a big
difference!
2021-05-14 17:45:41 -07:00
Guillaume Gomez dfc8b6094e Add test for toggle on mobile size 2021-05-14 22:25:50 +02:00
Guillaume Gomez 7eb95cd8e4 Unify toggle rules on smaller resolutions 2021-05-14 22:25:50 +02:00
Guillaume Gomez 0c02338a60 Move @media rules at the end so they override the other rules 2021-05-14 22:25:50 +02:00
bors 1025db84a6 Auto merge of #85211 - Aaron1011:metadata-invalid-span, r=michaelwoerister
Preserve `SyntaxContext` for invalid/dummy spans in crate metadata

Fixes #85197

We already preserved the `SyntaxContext` for invalid/dummy spans in the
incremental cache, but we weren't doing the same for crate metadata.
If an invalid (lo/hi from different files) span is written to the
incremental cache, we will decode it with a 'dummy' location, but keep
the original `SyntaxContext`. Since the crate metadata encoder was only
checking for `DUMMY_SP` (dummy location + root `SyntaxContext`),
the metadata encoder would treat it as a normal span, encoding the
`SyntaxContext`. As a result, the final span encoded to the metadata
would change across sessions, even if the crate itself was unchanged.

This could lead to an 'unstable fingerprint' ICE under the following conditions:
1. We compile a crate with an invalid span using incremental compilation. The metadata encoder discards the `SyntaxContext` since the span is invalid, while the incremental cache encoder preserves the `SyntaxContext`
2. From another crate, we execute a foreign query, decoding the invalid span from the metadata as `DUMMY_SP` (e.g. with `SyntaxContext::root()`). This span gets hashed into the query fingerprint. So far, this has always happened through the `optimized_mir` query.
3. We recompile the first crate using our populated incremental cache, without changing anything. We load the (previously) invalid span from our incremental cache - it gets converted to a span with a dummy (but valid) location, along with the original `SyntaxContext`. This span gets written out to the crate metadata - since it now has a valid location, we preserve its `SyntaxContext`.
4. We recompile the second crate, again using a populated incremental cache. We now re-run the foreign query `optimized_mir` - the foreign crate hash is unchanged, but we end up decoding a different span (it now ha a non-root `SyntaxContext`). This results in the fingerprint changing, resulting in an ICE.

This PR updates our encoding of spans in the crate metadata to mirror
the encoding of spans into the incremental cache. We now always encode a
`SyntaxContext`, and encode location information for spans with a
non-dummy location.
2021-05-14 16:58:30 +00:00
Guillaume Gomez 766de3a5e2 Fix toggle position on mobile 2021-05-14 15:16:29 +02:00
bors 75da570d78 Auto merge of #83640 - bjorn3:shared_metadata_reader, r=nagisa
Use the object crate for metadata reading

This allows sharing the metadata reader between cg_llvm, cg_clif and other codegen backends.

This is not currently useful for rlib reading with cg_spirv ([rust-gpu](https://github.com/EmbarkStudios/rust-gpu/)) as it uses tar rather than ar as .rlib format, but it is useful for dylib reading required for loading proc macros. (cc `@eddyb)`

The object crate is already trusted as dependency of libstd through backtrace. As far as I know it supports reading all object file formats used by targets for which we support rust dylibs with crate metadata, but I am not certain. If this happens to not be the case, I could keep using LLVM for reading dylib metadata.

Marked as WIP for a perf run and as it is based on #83637.
2021-05-14 12:58:58 +00:00
ayushmishra2005 27defcd14f Addressed PR coments 2021-05-14 17:30:26 +05:30
bors 36a4d14c7e Auto merge of #85236 - nikic:update-llvm-submodule, r=cuviper
Update LLVM submodule

This merges recent changes from the upstream LLVM 12 branch. One of them is intended to address #84958.
2021-05-14 09:10:11 +00:00
bors 69b352ef77 Auto merge of #85233 - FabianWolff:issue-85227, r=petrochenkov
Improve error message for non-exhaustive matches on non-exhaustive enums

This pull request fixes #85227. For an enum marked with `#[non_exhaustive]` and not defined in the current crate, the error message for non-exhaustive matches now mentions the fact that the enum is marked as non-exhaustive:
```
error[E0004]: non-exhaustive patterns: `_` not covered
  --> main.rs:12:11
   |
12 |     match e {
   |           ^ pattern `_` not covered
   |
   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
   = note: the matched value is of type `E`, which is marked as non-exhaustive
```
2021-05-14 06:53:45 +00:00
bors 91f2e2d218 Auto merge of #85190 - mati865:update-cc, r=Mark-Simulacrum
Update cc crate

To pull in this fix: 801a87bf2f
2021-05-14 04:12:40 +00:00
ayushmishra2005 34055a932b Improve match statements 2021-05-14 08:57:33 +05:30
bors 754d17121d Auto merge of #85195 - Mark-Simulacrum:variant-by-idx, r=petrochenkov
Store VariantIdx to distinguish enum variants

This saves ~24% of the instructions on the match-stress-enum benchmark, but I'm not 100% sure that this is OK - if we ever compare two constructors across enums (e.g., a Result and an Option), then this is obviously insufficient; I can experiment with continuing to store the DefId for comparison purposes in that case.
2021-05-14 00:59:01 +00:00
bors 17f30e5451 Auto merge of #84107 - Amanieu:global_asm2, r=nagisa
Add support for const operands and options to global_asm!

On x86, the default syntax is also switched to Intel to match asm!.

Currently `global_asm!` only supports `const` operands and the `att_syntax` option. In the future, `sym` operands will also be supported. However there is no plan to support any of the other operand types or options since they don't make sense in the context of `global_asm!`.

r? `@nagisa`
2021-05-13 22:17:43 +00:00
Amanieu d'Antras a7ed6a5196 Fix tests 2021-05-13 23:09:54 +01:00
Amanieu d'Antras d9cf2ce28f Update compiler_builtins to 0.1.43 2021-05-13 22:32:44 +01:00
Amanieu d'Antras 40d9da4d8c global_asm! consts do not depend on other items 2021-05-13 22:31:58 +01:00
Amanieu d'Antras bb6bec1d55 Clarify error message when both asm! and global_asm! are unsupported 2021-05-13 22:31:58 +01:00
Amanieu d'Antras 0df83f8e5e Update global_asm! documentation 2021-05-13 22:31:58 +01:00
Amanieu d'Antras 5a229e0e20 Add tests for global_asm! 2021-05-13 22:31:58 +01:00
Amanieu d'Antras 5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00
bors 6d395a1c29 Auto merge of #85186 - nikomatsakis:issue-83538-polluted-cache, r=jackh726
have on_completion record subcycles

have on_completion record subcycles

Rework `on_completion` method so that it removes all
provisional cache entries that are "below" a completed
node (while leaving those entries that are not below
the node).

This corrects an imprecise result that could in turn lead
to an incremental compilation failure. Under the old
scheme, if you had:

* A depends on...
   * B depends on A
   * C depends on...
       * D depends on C
 * T: 'static

then the provisional results for A, B, C, and D would all
be entangled. Thus, if A was `EvaluatedToOkModuloRegions`
(because of that final condition), then the result for C and
D would also be demoted to "ok modulo regions".

In reality, though, the result for C depends only on C and itself,
and is not dependent on regions. If we happen to evaluate the
cycle starting from C, we would never reach A, and hence the
result would be "ok".

Under the new scheme, the provisional results for C and D
are moved to the permanent cache immediately and are not affected
by the result of A.

Fixes #83538

r? `@Aaron1011`
2021-05-13 19:36:46 +00:00
Noah Lev 4672520e74 Use my real name 2021-05-13 10:34:30 -07:00