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

Apply clippy suggestions for rustc and core #89709

Merged
merged 3 commits into from
Oct 11, 2021

Conversation

clemenswasser
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

Changes rustc_apfloat. rustc_apfloat is currently in limbo and you almost certainly don't want to change it (see #55993).

cc @eddyb

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2021
@rust-log-analyzer

This comment has been minimized.

compiler/rustc_apfloat/src/ieee.rs Show resolved Hide resolved
@@ -14,7 +14,7 @@ const BASE_64: &[u8; MAX_BASE as usize] =

#[inline]
pub fn push_str(mut n: u128, base: usize, output: &mut String) {
debug_assert!(base >= 2 && base <= MAX_BASE);
debug_assert!((2..=MAX_BASE).contains(&base));
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we could use debug_assert_matches! (assuming it exists) for range checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

debug_assert_matches! is currently unstable

Copy link
Contributor

Choose a reason for hiding this comment

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

Compiler code can use unstable library features.

Copy link
Member

Choose a reason for hiding this comment

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

@clemenswasser If this PR is re-landed (after the #89905 revert), it would be good to fix this.

@@ -388,7 +388,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
let formatted_str = self.build_format(&s.value(), attr.span());
match name {
"message" => {
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
if type_matches_path(info.ty, &["rustc_span", "Span"]) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, removing redundant & should maybe be more forcefully handled (i.e. denyed in rustc crates) - and if you open a PR with just that lint being accounted for, I will r+ it immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a simple way I can deny the lints for all rustc crates, without copy pasting in all lib.rs?

Copy link
Member

Choose a reason for hiding this comment

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

In theory we could simply deny the lint via x.py clippy, but in reality it seems that --cap-lints warn prevents this from working 😆

diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 28e7f1fdca7..cf21a4dc857 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -44,6 +44,7 @@ fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
         }
         args.extend(strings(&["--", "--cap-lints", "warn"]));
         args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
+        args.push("-Dclippy::needless_borrow".into());
         args
     } else {
         vec![]

library/core/src/num/flt2dec/strategy/grisu.rs Outdated Show resolved Hide resolved
compiler/rustc_serialize/src/serialize.rs Outdated Show resolved Hide resolved
compiler/rustc_data_structures/src/stack.rs Show resolved Hide resolved
src/bootstrap/builder.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov 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 Oct 10, 2021
@petrochenkov
Copy link
Contributor

r=me with #89709 (comment) addressed.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 11, 2021

📌 Commit 14b6cf6 has been approved by petrochenkov

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 11, 2021
@matthiaskrgr
Copy link
Member

@bors rollup=iffy just in case this has some unforeseen perf implications

@bors
Copy link
Contributor

bors commented Oct 11, 2021

⌛ Testing commit 14b6cf6 with merge 6ae8912...

@bors
Copy link
Contributor

bors commented Oct 11, 2021

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 6ae8912 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 11, 2021
@bors bors merged commit 6ae8912 into rust-lang:master Oct 11, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 11, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6ae8912): comparison url.

Summary: This change led to large relevant regressions 😿 in compiler performance.

  • Large regression in instruction counts (up to 2.8% on full builds of keccak)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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

@rustbot rustbot added the perf-regression Performance regression. label Oct 11, 2021
@pnkfelix
Copy link
Member

@bors rollup=iffy just in case this has some unforeseen perf implications

I think its fair to say this had some unforeseen perf implications

We see instruction-count regressions in the 1.1% to 2.7% range in keccak and inflate

@petrochenkov
Copy link
Contributor

I suggest reverting.
The changes are non-critical, and I'm not sure whether @clemenswasser is going to investigate the regressions (I'm certainly not going to do that myself).

@matthiaskrgr
Copy link
Member

I reverted parts of the merge in #89855 can we get a perf run there to see if that fixes the regression?

} else {
None
}
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know other data structures have some instances of open coding map to reduce the amount of monomorphization bloat that needs to be compiled, so this is a potential perf culprit

Copy link
Member

Choose a reason for hiding this comment

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

I would worry less about bloat and more about that instance of Option::map having the closure inlined into it, but not being inlined itself (because of inlining swap_remove?).

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2021
…ggestions_2, r=petrochenkov"

The PR had some unforseen perf regressions that are not as easy to find.
Revert the PR for now.

This reverts commit 6ae8912, reversing
changes made to 86d6d2b.
for index in 0..orig_nodes_len {
for (index, node_rewrite) in node_rewrites.iter_mut().enumerate() {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible enumerate is less efficient than range iteration?

let words = &mut self.words[..];
for index in start..end {
words[index] = !0;
for word in self.words[start..end].iter_mut() {
Copy link
Member

Choose a reason for hiding this comment

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

I didn't get to this in time, but xs[range].iter_mut() should just be writen &mut xs[range] - surprised clippy doesn't have a lint for this.

Comment on lines -993 to 995
let words = &mut self.words[..];
for index in start..end {
words[index] = !0;
for word in self.words[start..end].iter_mut() {
*word = !0;
}
Copy link
Member

Choose a reason for hiding this comment

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

This entire thing can just be self.words[start..end].fill(!0), just realized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2021
…chaelwoerister

Revert "Auto merge of rust-lang#89709 - clemenswasser:apply_clippy_suggestions…

…_2, r=petrochenkov"

The PR had some unforseen perf regressions that are not as easy to find.
Revert the PR for now.

This reverts commit 6ae8912, reversing
changes made to 86d6d2b.
@rylev
Copy link
Member

rylev commented Oct 20, 2021

As noted many of these changes have been reverted, and the performance was regained. As such I'm going to mark this as triaged.

@rustbot label +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.