Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace visibility test with reachability test in dead code detection #119552

Merged
merged 9 commits into from Mar 23, 2024

Conversation

krtab
Copy link
Contributor

@krtab krtab commented Jan 3, 2024

Fixes #119545

Also included is a fix for an error now flagged by the lint

@rustbot
Copy link
Collaborator

rustbot commented Jan 3, 2024

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 3, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@krtab
Copy link
Contributor Author

krtab commented Jan 4, 2024

Hm, my bad it took me some time to figure out why things were compiling on my side but not in the CI. I'll fix all the previously undetected dead code and you can review then.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 4, 2024
@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from 3e34b88 to e6d8c78 Compare January 4, 2024 15:54
@rust-log-analyzer

This comment has been minimized.

@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from e6d8c78 to 4521396 Compare January 4, 2024 16:34
@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from 4521396 to 549f08f Compare January 4, 2024 16:49
@rust-log-analyzer

This comment has been minimized.

@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from 549f08f to 73be48a Compare January 5, 2024 15:25
@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2024

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit fb75654 is kinda a 🥷 fix for Clippy and doesn't really belong in this PR. I definitely appreciate the fix, but would prefer to have it in a Clippy PR. What's the motivation in including it in this PR?

@krtab
Copy link
Contributor Author

krtab commented Jan 5, 2024

Commit fb75654 is kinda a 🥷 fix for Clippy and doesn't really belong in this PR. I definitely appreciate the fix, but would prefer to have it in a Clippy PR. What's the motivation in including it in this PR?

I hesitated and discussed with other contributors to Rust. My issue with having it in a clippy specific PR is that I don't have a good solution to pass the CI in this one. I can delete or mark as allow(dead_code) the unused fields here and make the more substantial fix in clippy itself, but then this requires a correct ordering between this PR merge and the update of the in-tree clippy.
Having the fix here avoids having to PR to synchronize.

@flip1995
Copy link
Member

flip1995 commented Jan 5, 2024

Ah, was the self.allow_one_hash_in_raw_strings field unused? Well then, let's keep it in this PR. Thanks for the explanation!

@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from 73be48a to 5be1860 Compare January 5, 2024 17:17
@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the O-unix Operating system: Unix-like label Jan 5, 2024
@rust-log-analyzer

This comment has been minimized.

@krtab
Copy link
Contributor Author

krtab commented Jan 8, 2024

Well it seems to finally pass the CI! Didn't expect it to end-up being a +120/-51 PR 😅
I expect that there will be breakage during bors try.

Anyway @rustbot review

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 22, 2024
@krtab
Copy link
Contributor Author

krtab commented Mar 22, 2024

@rustbot author

I need to find a way to compile src/bootstrap locally with the stage1 compiler to get rid of all errors befors re pushing.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2024
The dead_code lint was previously eroneously missing this dead code.
Since this lint bug has been fixed, the unused field need to be removed
or marked as `#[allow(dead_code)]`.

Given that this struct is deserialized without #[serde(deny_unknown_fields)]
it is ok to simply delete the never read fields.
@krtab krtab force-pushed the dead_code_priv_mod_pub_field branch from 843e79f to 7342cc4 Compare March 22, 2024 23:01
@krtab
Copy link
Contributor Author

krtab commented Mar 22, 2024

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 22, 2024
@saethlin
Copy link
Member

@bors r=cjgillot,saethlin

@bors
Copy link
Contributor

bors commented Mar 22, 2024

📌 Commit 7342cc4 has been approved by cjgillot,saethlin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2024
@workingjubilee
Copy link
Contributor

higher!
@bors p=2

@bors
Copy link
Contributor

bors commented Mar 23, 2024

⌛ Testing commit 7342cc4 with merge c308726...

@bors
Copy link
Contributor

bors commented Mar 23, 2024

☀️ Test successful - checks-actions
Approved by: cjgillot,saethlin
Pushing c308726 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 23, 2024
@bors bors merged commit c308726 into rust-lang:master Mar 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 23, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c308726): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.1% [1.0%, 3.2%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.1% [1.0%, 3.2%] 4

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.8% [2.1%, 3.7%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.8% [2.1%, 3.7%] 4

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.6% [1.4%, 3.7%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [1.4%, 3.7%] 3

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 671.121s -> 671.167s (0.01%)
Artifact size: 315.04 MiB -> 315.03 MiB (-0.00%)

@krtab
Copy link
Contributor Author

krtab commented Mar 23, 2024

Thanks everyone, especially @cjgillot and @saethlin :)

@Kobzol
Copy link
Contributor

Kobzol commented Mar 23, 2024

More warnings are now emitted for ripgrep (analyzed here).

@rustbot label: +perf-regression-triaged

dtolnay added a commit to dtolnay/serde-yaml that referenced this pull request Mar 24, 2024
New in nightly-2024-03-24 from rust-lang/rust#119552.

    warning: field `b` is never read
      --> tests/test_error.rs:53:13
       |
    52 |     pub struct A {
       |                - field in this struct
    53 |         pub b: Vec<B>,
       |             ^
       |
       = note: `A` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
       = note: `#[warn(dead_code)]` on by default

    warning: field `0` is never read
      --> tests/test_error.rs:57:11
       |
    57 |         C(C),
       |         - ^
       |         |
       |         field in this variant
       |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
       |
    57 |         C(()),
       |           ~~

    warning: field `d` is never read
      --> tests/test_error.rs:61:13
       |
    60 |     pub struct C {
       |                - field in this struct
    61 |         pub d: bool,
       |             ^
       |
       = note: `C` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: fields `v` and `w` are never read
      --> tests/test_error.rs:82:13
       |
    81 |     pub struct Basic {
       |                ----- fields in this struct
    82 |         pub v: bool,
       |             ^
    83 |         pub w: bool,
       |             ^
       |
       = note: `Basic` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: field `c` is never read
       --> tests/test_error.rs:107:13
        |
    106 |     pub struct Wrapper {
        |                ------- field in this struct
    107 |         pub c: (),
        |             ^
        |
        = note: `Wrapper` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: field `0` is never read
       --> tests/test_error.rs:160:11
        |
    160 |         V(usize),
        |         - ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    160 |         V(()),
        |           ~~

    warning: field `0` is never read
       --> tests/test_error.rs:212:15
        |
    212 |         Inner(Inner),
        |         ----- ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    212 |         Inner(()),
        |               ~~

    warning: field `0` is never read
       --> tests/test_error.rs:216:17
        |
    216 |         Variant(Vec<usize>),
        |         ------- ^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    216 |         Variant(()),
        |                 ~~

    warning: field `0` is never read
       --> tests/test_error.rs:245:11
        |
    245 |         V(usize),
        |         - ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    245 |         V(()),
        |           ~~

    warning: fields `x` and `y` are never read
       --> tests/test_error.rs:260:13
        |
    259 |     pub struct Struct {
        |                ------ fields in this struct
    260 |         pub x: usize,
        |             ^
    261 |         pub y: usize,
        |             ^
        |
        = note: `Struct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: field `x` is never read
       --> tests/test_error.rs:334:13
        |
    333 |     pub struct S {
        |                - field in this struct
    334 |         pub x: [i32; 1],
        |             ^
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: field `x` is never read
       --> tests/test_error.rs:347:13
        |
    346 |     pub struct S {
        |                - field in this struct
    347 |         pub x: Option<Box<S>>,
        |             ^
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: fields `0` and `1` are never read
       --> tests/test_error.rs:359:18
        |
    359 |     pub struct S(pub usize, pub Option<Box<S>>);
        |                - ^^^^^^^^^  ^^^^^^^^^^^^^^^^^^
        |                |
        |                fields in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the fields to be of unit type to suppress this warning while preserving the field numbering, or remove the fields
        |
    359 |     pub struct S((), ());
        |                  ~~  ~~

    warning: field `0` is never read
       --> tests/test_error.rs:370:18
        |
    370 |     pub struct S(pub Option<Box<S>>);
        |                - ^^^^^^^^^^^^^^^^^^
        |                |
        |                field in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    370 |     pub struct S(());
        |                  ~~

    warning: field `x` is never read
       --> tests/test_error.rs:382:13
        |
    381 |     pub struct S {
        |                - field in this struct
    382 |         pub x: Option<Box<S>>,
        |             ^
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

    warning: fields `0` and `1` are never read
       --> tests/test_error.rs:394:18
        |
    394 |     pub struct S(pub usize, pub Option<Box<S>>);
        |                - ^^^^^^^^^  ^^^^^^^^^^^^^^^^^^
        |                |
        |                fields in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the fields to be of unit type to suppress this warning while preserving the field numbering, or remove the fields
        |
    394 |     pub struct S((), ());
        |                  ~~  ~~
dtolnay added a commit to dtolnay/paste that referenced this pull request Mar 24, 2024
New in nightly-2024-03-24 from rust-lang/rust#119552.

    warning: field `0` is never read
      --> tests/test_item.rs:64:37
       |
    64 |                 pub struct S<$life>(pub &$life ());
       |                            -        ^^^^^^^^^^^^^
       |                            |
       |                            field in this struct
    ...
    72 |     m!('a);
       |     ------ in this macro invocation
       |
       = note: `#[warn(dead_code)]` on by default
       = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
       |
    64 |                 pub struct S<$life>(());
       |                                     ~~
dtolnay added a commit to serde-rs/json that referenced this pull request Mar 24, 2024
New in nightly-2024-03-24 from rust-lang/rust#119552.

    warning: field `x` is never read
      --> tests/regression/issue795.rs:11:15
       |
    11 |     Variant { x: u8 },
       |     -------   ^
       |     |
       |     field in this variant
       |
       = note: `#[warn(dead_code)]` on by default

    warning: field `i` is never read
      --> tests/regression/issue845.rs:63:9
       |
    61 | pub struct Struct {
       |            ------ field in this struct
    62 |     #[serde(deserialize_with = "deserialize_integer_or_string")]
    63 |     pub i: i64,
       |         ^
       |
       = note: `Struct` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
dtolnay added a commit to serde-rs/serde that referenced this pull request Mar 24, 2024
New in nightly-2024-03-24 from rust-lang/rust#119552.

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:10:9
       |
    8  |     Flatten {
       |     ------- fields in this variant
    9  |         #[serde(flatten)]
    10 |         nested: Nested,
       |         ^^^^^^
    11 |         string: &'static str,
       |         ^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:20:9
       |
    18 |     Flatten {
       |     ------- fields in this variant
    19 |         #[serde(flatten)]
    20 |         nested: Nested,
       |         ^^^^^^
    21 |         string: &'static str,
       |         ^^^^^^

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:30:9
       |
    28 |     Flatten {
       |     ------- fields in this variant
    29 |         #[serde(flatten)]
    30 |         nested: Nested,
       |         ^^^^^^
    31 |         string: &'static str,
       |         ^^^^^^

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:40:9
       |
    38 |     Flatten {
       |     ------- fields in this variant
    39 |         #[serde(flatten)]
    40 |         nested: Nested,
       |         ^^^^^^
    41 |         string: &'static str,
       |         ^^^^^^

    warning: field `0` is never read
       --> test_suite/tests/test_gen.rs:690:33
        |
    690 |         Single(#[serde(borrow)] RelObject<'a>),
        |         ------                  ^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
        = note: `#[warn(dead_code)]` on by default
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    690 |         Single(#[serde(borrow)] ()),
        |                                 ~~

    warning: field `0` is never read
       --> test_suite/tests/test_gen.rs:691:31
        |
    691 |         Many(#[serde(borrow)] Vec<RelObject<'a>>),
        |         ----                  ^^^^^^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    691 |         Many(#[serde(borrow)] ()),
        |                               ~~
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 4, 2024
…r=cjgillot,saethlin

Replace visibility test with reachability test in dead code detection

Fixes rust-lang#119545

Also included is a fix for an error now flagged by the lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. O-SGX Target: SGX O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No warning for unread pub struct field in private module