8344079: Minor fixes and cleanups to compiler lint-related code#22056
8344079: Minor fixes and cleanups to compiler lint-related code#22056archiecobbs wants to merge 11 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back acobbs! A progress list of the required criteria for merging this PR into |
|
@archiecobbs This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 6 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
|
@archiecobbs The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintSuppression.java
Outdated
Show resolved
Hide resolved
|
|
||
| if (!incubatingModules.isEmpty()) { | ||
| log.warning(Warnings.IncubatingModules(incubatingModules)); | ||
| log.warning(LintCategory.INCUBATING, null, Warnings.IncubatingModules(incubatingModules)); |
There was a problem hiding this comment.
Thanks for fixing all these. IMHO the fact we had so many bad usages points at the fact that the system we use to report warning is a bit too loose. I wonder if we should differentiate warning keys from lint warning keys, and have lint warnings be reported with a dedicated method in Log, so that there can be no confusion as to which is which (this is for a separate, possible, future PR)
There was a problem hiding this comment.
Agree... one of the best ways to ensure a policy is correctly followed is to make the build fail when it's not :)
There was a problem hiding this comment.
There was a problem hiding this comment.
Initial stab:
https://github.com/openjdk/jdk/compare/master...mcimadamore:jdk:lint_warning_strong_checks?expand=1
The idea is to mark in compiler.properties which keys are associated to which lint category, and track the association in the generated CompilerProperties file. Then we can just drop the additional LintCategory parameter from all the call sites.
There was a problem hiding this comment.
I like that a lot - very nice!
I have one comment in two parts...
(1) Even though the following current idiom is verbose and contains redundancy:
if (lint.isEnabled(LintCategory.DEP_ANN))
log.warn(LintCategory.DEP_ANN, pos, Warnings.MissingDeprecatedAnnotation));that redundancy has a nice side effect which is that it makes it easy to spot a mismatch between the lint category being tested and the lint category of the subsequent warning, where as your patch makes it easier to make a mistake like this:
if (lint.isEnabled(LintCategory.DEPRECATION))
log.warn(pos, Warnings.MissingDeprecatedAnnotation));Such a mismatch would result in a bug causing a very frustrating (dis)appearance of some warning, potentially failing builds, etc.
(2) The connection of a warning to a lint category, which is based on a properties file comment line, could easily get out of sync with the code without notice causing similar problems to (1). E.g., someone could put the wrong category in the comment (or change it later in the file but not the code), or accidentally forget to add the comment line, etc.
Both (1) and (2) could be addressed easily I think - for example, what if we baked the lint category more firmly into the property name, and used that to make it more visible in the code?
Example:
compiler.warn[dep-ann].missing.deprecated.annotation=\
deprecated item is not annotated with @Deprecated
if (lint.isEnabled(LintCategory.DEP_ANN))
log.warn(pos, Warnings.LintDepAnn.MissingDeprecatedAnnotation));That way it's more visually obvious that the warning is associated to the DEP_ANN lint category in both the code and the properties file, and so they hopefully would have a harder time getting out of sync.
There was a problem hiding this comment.
Not sure I buy your arguments :-)
While the mechanics of lint warning is a bit different, they are still warnings (e.g. the compiler still says warning: <text>, and it is still something that counts towards Werror. Making them completely separate seems like trying to make them more different than they really are.
And, if we have both log(Warning) and log(LintWarning) whether they are the same type or not becomes a mot question, because you can still use them in place of another. And, if you have subclassing and have only a single log(Warning) method which adds the category or not depending on the runtime type of the warning, then the problem you describe above cannot occur (I think).
So, while I see how one can argue this several ways, the advantage for going down the path you describe seems less clear to me. In terms of object-oriented hierarchy, saying that a lint warning is a warning with a category added on top seems to me like a good modelling of the situation we have.
There was a problem hiding this comment.
OK I think you're right and it will all work out - using the runtime type ensures the prefix always appears, and the other thing I was worried about, which is someone accidentally logging a lint warning without checking for enablement because they thought it was a generic warning, should be prevented now because the in the code you will see LintWarnings.FooBar instead of Warnings.FooBar so hopefully it will be very obvious.
There was a problem hiding this comment.
I've updated the branch in place. This adds LintWarnings in CompilerProperties but does not add the intermediate grouping based on the lint category. E.g. We have LintWarnings.DivZero but not LintWarnings.DivZero.DivZero. The reason is twofold:
- Implementation-wise, collecting different warnings associated with the same category starts to be some work in the build tool we use to generate CompilerProperties.
- More importantly, while converting the use cases to use the new
LintWarningclass it seems to me that either theisEnabledcheck is immediately preceding (in which case the newLint::logIfEnabledcan be used), or the check is typically far enough that we have no idea on which category we are handling. E.g. pattern likeif (lint) { log ... }is extremely common, wherelintis either a method parameter or a class field.
I think I'm fairly happy with where this has landed. Note that the new type LintWarning can be used to make the signature of some methods (notably those in MandatoryWarningHandler) tighter, so that we can detect more issues at compile-time (and at runtime). In fact, this has helped me fixing a couple of warning keys which were missing the lint category in the compiler.properties file.
I'm not 100% happy with Lint::logIfEnabled: the use sites look good, but having Lint keep track of a log seems a bit odd (given that Lint objects are duplicated on the fly).
There was a problem hiding this comment.
I'll probably issue a PR against that branch, so that we can discuss that there. Sorry for hijacking your PR :-)
There was a problem hiding this comment.
I think this sounds like a good plan and agree with your reasoning for not over-complicating the class hierarchy.
I'm sure I'll have some minor comments on the patch but will wait for you to create a new PR and comment there when it appears.
Thanks.
I'm not 100% happy with Lint::logIfEnabled: the use sites look good, but having Lint keep track of a log seems a bit odd (given that Lint objects are duplicated on the fly).
I was thinking that a log parameter would have to be passed as a parameter, because there is at least one subclass somewhere (ReusableLog extends Log), but maybe I was being too conservative.
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java
Outdated
Show resolved
Hide resolved
mcimadamore
left a comment
There was a problem hiding this comment.
Looks good, I've left some additional style-related comment
src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
Outdated
Show resolved
Hide resolved
|
@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
Thanks for the review. |
|
/integrate |
|
Going to push as commit dd81f8d.
Your commit was automatically rebased without conflicts. |
|
@archiecobbs Pushed as commit dd81f8d. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review these changes with some minor lint-related fixes and cleanups.
See JDK-8344079 for a more detailed description.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22056/head:pull/22056$ git checkout pull/22056Update a local copy of the PR:
$ git checkout pull/22056$ git pull https://git.openjdk.org/jdk.git pull/22056/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22056View PR using the GUI difftool:
$ git pr show -t 22056Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22056.diff
Using Webrev
Link to Webrev Comment