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

Turned "unnecessary value" and "move of const" lints to errors on mac #36910

Merged
merged 4 commits into from
Oct 22, 2022

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Oct 20, 2022

Fixed up some new violations to the "move const values" lint and the "unnecessary value" lint and made it an error on CI for host_debug on mac.

If this fails in Post submit checks let me know, it's possible a violation was introduced between authoring and landing the check

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gaaclarke gaaclarke force-pushed the unnecessary-value-error branch 2 times, most recently from 510654c to 814d8f9 Compare October 21, 2022 04:55
@flutter-dashboard flutter-dashboard bot added the embedder Related to the embedder API label Oct 21, 2022
@gaaclarke gaaclarke changed the title Turned unnecessary value and move of const to errors. Turned "unnecessary value" and "move of const" lints to errors on mac Oct 21, 2022
@gaaclarke
Copy link
Member Author

@zanderso @jmagman

Re: #36885

Here we can turn this on selectively as an error and I think we should keep the check in .clang-tidy so that clang-tidy aware tools still work (analyzers and clang tidy fix). I'm not going to sit and watch this finish but works locally, I'll check on it tomorrow. Here's the gist anyway.

@gaaclarke gaaclarke marked this pull request as ready for review October 21, 2022 17:50
/// Adds warnings as errors for only specific runs. This is helpful if migrating one platform at a time.
String? _platformSpecificWarningsAsErrors(String targetVariant) {
if (targetVariant == 'host_debug' && io.Platform.isMacOS) {
return 'performance-move-const-arg,performance-unnecessary-value-param';
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 do in fact need this, I'd prefer hoisting this logic out into the lint.sh script to make it more visible.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason I didn't do that is because it's really ugly doing the same logic in sh. The thought being that having dart code is easier to get right and maintain instead of sh.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could make another flag --mac-host-warnings-as-errors=foobar.

Copy link
Member

@zanderso zanderso Oct 21, 2022

Choose a reason for hiding this comment

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

With this PR, these lints are added, like, three layers deep (.clang-tidy -> lint.sh -> options.dart), so I'm more concerned that people are going to get confused about how/why they're enabled than I am about adding logic to the shell script. --mac-host-warnings-as-errors is kind of oddly specific, but at least makes the additional lints easier to find.

Copy link
Member

Choose a reason for hiding this comment

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

I agree this is really buried. I think I should merge #36885 and then either

  1. Add these two lints back to the checks when all the platforms issues are resolved, as was done with the other linters.
    or
  2. Create override .clang-tidy files in the different embedder directories so we can add linter checks to different platforms without needing to fix them everywhere. I believe clang-tidy will prefer the .clang-tidy file closest to the file being linted.

Copy link
Member Author

Choose a reason for hiding this comment

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

--mac-host-warnings-as-errors is kind of oddly specific, but at least makes the additional lints easier to find.

Yea it's weird. Once we get a solid foothold it should be easier to land the other platforms in another PR while this one holds the line for the most part. I'll make that change.

I think I should merge #36885 and then either

I just don't understand how that is helping anyone. The thesis for removing it was that it was confusing and it wasn't benefiting anyone. I've shown that it is doing what I expected and it is beneficial in limited cases (albeit not as many as I had hoped). I agree we need to make it better by turning it into an error on ci.

Add these two lints back to the checks when all the platforms issues are resolved, as was done with the other linters.

That needlessly makes the task hard for no reason. In order to do it all at once I need to run clang-tidy-fix 5 times on 3 different platforms, hand fix the automated fix since it isn't 100% perfect, get it all reviewed and landed all within the span of no one introducing another violation. Otherwise have to start the process all over again.

Having multiple .clang-tidy files also has it's own problems where managing multiple files is a pain and the hope is that this is a special case and a transitory one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, moved the warnings-as-errors declaration to lint.sh. Leaving the thread unresolved since there was some other comments.

Copy link
Member

Choose a reason for hiding this comment

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

I just don't understand how that is helping anyone.

It helps because the expected behavior that adding a check to the .clang-tidy file will surface regressions to that lint... somewhere. Without needing to set up an IDE with clang-tidy, if anyone does this, and without needing to know to run --fix. If we don't merge #36885 then also need to move modernize-use-default-member-init to WarningsAsErrors as that's a pretty clear example of the confusion. Generally when we add new lints, errors or warnings, in other linter systems, it also involves fixing the existing violations of that lint. I know these two lints aren't totally cleaned up though on all platforms, and that's the issue here.

However we obviously disagree here, so I hope people notice the behavior of --mac-host-warnings-as-errors and any similar platform-specific lints going forward.

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm w/ issue to track cleanup.

@@ -32,6 +32,7 @@ SRC_DIR="$(cd "$SCRIPT_DIR/../.."; pwd -P)"
FLUTTER_DIR="$(cd "$SCRIPT_DIR/.."; pwd -P)"
DART_BIN="${SRC_DIR}/third_party/dart/tools/sdks/dart-sdk/bin"
DART="${DART_BIN}/dart"
MAC_HOST_WARNINGS_AS_ERRORS="performance-move-const-arg,performance-unnecessary-value-param"
Copy link
Member

Choose a reason for hiding this comment

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

Please add a TODO and file an issue to clean this up when done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2022
@zanderso
Copy link
Member

@gaaclarke These migrations are difficult, so it makes sense to me that we're having this discussion. Another way to slice up the work, rather than platform-by-platform, is to use the NOLINTBEGIN/END annotations (there might also be a single annotation that applies to a whole file) to instead work file-by-file. After you're done with enabling the lints that you're currently working on. I'd like us to land #36885, and use the file-by-file approach next time.

@gaaclarke
Copy link
Member Author

@zanderso that makes sense. What we've done in the past with the formatter is print out the patch that will fix the issue so you don't have to recalculate it on your own machine. I think that's what we should do since here too since it's unreasonable to make people run N instances of clang tidy on 3 different machines to duplicate work that's being done on a bot already.

@jmagman
Copy link
Member

jmagman commented Oct 21, 2022

I'd like us to land #36885, and use the file-by-file approach next time.

That will not work in conjunction with this PR, as @gaaclarke pointed out in #36885 (review). Either all warnings are errors, or we prefer this pattern where only checks in WarningsAsErrors + whatever exceptions like this are added to lint.sh.

@jmagman
Copy link
Member

jmagman commented Oct 21, 2022

After you're done with enabling the lints that you're currently working on. I'd like us to land #36885, and use the file-by-file approach next time.

Or you meant land that PR after these two lint can be turned on for all platforms?

@zanderso
Copy link
Member

Or you meant land that PR after these two lint can be turned on for all platforms?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App embedder Related to the embedder API
Projects
None yet
3 participants