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

Disabled clippy type complexity lints globally for all crates. #7050

Closed

Conversation

iiYese
Copy link
Contributor

@iiYese iiYese commented Dec 28, 2022

Objective

  • Disable clippy type complexity lints to improve DX.

Solution

  • Added #![allow(clippy::type_complexity)] to all lib.rs files in crates
  • Added .cargo/config.toml with the following as suggested here.
[target.'cfg(all())']
rustflags = ["-Aclippy::type_complexity"]

Rationale

  • Addressing the lint does not add any new information or make any information easier to digest.
    Addressing it just fragments already existing information.
  • Disabling the lint on a case by case basis has no merit as all of the reasoning would be the same and repetitive.
    When every deviation from a default is for the same reason that default is not a suitable default any more. This clippy defaults is not suitable for bevy as what would typically be considered "complex" in most rust projects is very common in bevy. This I think is a better default.

@iiYese
Copy link
Contributor Author

iiYese commented Dec 28, 2022

Note: I still get a few lints from examples but a much more tolerable amount. I'm not sure how people would feel about showing lint disabling in examples as it's boilerplate unrelated to what the example is demonstrating.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Meta About the project itself labels Dec 28, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I agree with this change: this is a rule that we've decided to ignore in CI that should be ignored for Bevy engine developers as well.

@mockersf
Copy link
Member

I would prefer to not just allow it everywhere.

It was decided to ignore this lint in CI to not slow down development by needing to think about this lint, but as Bevy reach a more stable state I would prefer ignoring the lint to be done on a case by case basis rather than just blanket it.

It may make sense to ignore it on some crates like bevy_ecs, but some other should not need to

@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label Dec 28, 2022
@alice-i-cecile
Copy link
Member

It was decided to ignore this lint in CI to not slow down development by needing to think about this lint, but as Bevy reach a more stable state I would prefer ignoring the lint to be done on a case by case basis rather than just blanket it.

In my experience, following the type complexity lint when writing Bevy code results in worse code. The only real way around it is judicious use of SystemParam and WorldQuery derives, which increase compile times and reduces clarity.

@iiYese
Copy link
Contributor Author

iiYese commented Dec 28, 2022

It may make sense to ignore it on some crates like bevy_ecs, but some other should not need to

I was of the opinion that ecs was a logical target but depending on your editor setup it will lint from the entire root crate.
Ie. you will get lints originating in reflect when you are editing ecs. Inspecting all of those lints quite often reveals Querys with 2-3 components.

It was decided to ignore this lint in CI to not slow down development by needing to think about this lint, but as Bevy reach a more stable state I would prefer ignoring the lint to be done on a case by case basis rather than just blanket it.

I can't foresee addressing/disabling it on a case by case basis ever becoming useful. Why try account for it now? Its a very premature action for a scenario I don't think anyone can see arising that results in a very annoying DX. But lets imagine for a second that this scenario arises. In the presence of those future additions the current crates having this lint globally disabled still makes sense because its only in those future additions that addressing that lint would make sense. Those future additions would likely be their own crates ie. they could not have the #![allow(clippy::type_complexity)].

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 30, 2022
Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

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

Generally on board for this global rule (as it is already our policy according to CI). However this feels "redundant". We currently don't use hard-coded clippy lints in each crate and consider the CI-script settings the source of truth.

This PR is attempting to solve the problem of "code editor clippy configuration not matching CI configuration", which feels like a problem we should be solving globally, not hacking around for a specific case. And I don't think the solution should be "mirror global settings into each library", as it creates the challenge of keeping everything in sync and bloats the codebase unnecessarily. And even if we agree that is the solution (and I hope not), then we should treat each library as the source of truth and remove the global CI config. Trying to keep both "in sync" with each other is nasty.

Ideally this would be solved with "global clippy config files" but the Clippy and Cargo teams have been designing / punting that for ages:
rust-lang/rust-clippy#1313
rust-lang/cargo#5034

The embark folks did find a workaround that we should consider:
EmbarkStudios/rust-ecosystem#22 (comment)

@iiYese
Copy link
Contributor Author

iiYese commented Jan 5, 2023

I've applied that. It's a much better alternative. Even stops the type complexity lints I was getting from the /examples.

@iiYese iiYese requested a review from cart January 5, 2023 01:02
@@ -0,0 +1,2 @@
[target.'cfg(all())']
rustflags = ["-Aclippy::type_complexity"]
Copy link
Member

Choose a reason for hiding this comment

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

This still forks the configuration we have in the CI script. We should have one source of truth for global lint configuration. Either it is all here, or it is all in the CI script.

Copy link
Member

Choose a reason for hiding this comment

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

If we're moving config here, we should also verify that the CI script is still picking up these flags.

@@ -0,0 +1,2 @@
[target.'cfg(all())']
rustflags = ["-Aclippy::type_complexity"]
Copy link
Member

Choose a reason for hiding this comment

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

The big downside to this approach is that config.toml is considered "local user configuration".
Notably, we encourage people to include platform specific linker optimizations here:

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-C", "link-arg=--ld-path=/usr/bin/mold"]

These linker settings will be per-system config and shouldn't be enabled by default. Currently we .gitignore this file. Checking this in is "controversial" and will almost certainly negatively affect these workflows.

cart pushed a commit that referenced this pull request Apr 6, 2023
# Objective

The clippy lint `type_complexity` is known not to play well with bevy.
It frequently triggers when writing complex queries, and taking the
lint's advice of using a type alias almost always just obfuscates the
code with no benefit. Because of this, this lint is currently ignored in
CI, but unfortunately it still shows up when viewing bevy code in an
IDE.

As someone who's made a fair amount of pull requests to this repo, I
will say that this issue has been a consistent thorn in my side. Since
bevy code is filled with spurious, ignorable warnings, it can be very
difficult to spot the *real* warnings that must be fixed -- most of the
time I just ignore all warnings, only to later find out that one of them
was real after I'm done when CI runs.

## Solution

Suppress this lint in all bevy crates. This was previously attempted in
#7050, but the review process ended up making it more complicated than
it needs to be and landed on a subpar solution.

The discussion in rust-lang/rust-clippy#10571
explores some better long-term solutions to this problem. Since there is
no timeline on when these solutions may land, we should resolve this
issue in the meantime by locally suppressing these lints.

### Unresolved issues

Currently, these lints are not suppressed in our examples, since that
would require suppressing the lint in every single source file. They are
still ignored in CI.
@JoJoJet
Copy link
Member

JoJoJet commented Sep 14, 2023

Gonna close this since the goal of this PR was implemented in #8313 and #9796. A solution similar to this one would be more ideal than what we have, but it seems like it's blocked by upstream changes to cargo.

@JoJoJet JoJoJet closed this Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Meta About the project itself C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants