-
Notifications
You must be signed in to change notification settings - Fork 291
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
refactor LibraryModelsHandler.onOverrideMayBeNullExpr #754
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the odd
nullnessFromDataflow
being run, even without consideration the current value ofexprMayBeNull
.the comment above suggests this is intentional and important, however no test is failing without this dataflow call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, from the point of view of code calling this Handler extension point in NullAway.java, with this as the only relevant handler, the change is:
Before:
true
only if dataflow saidtrue
or ifexprMayBeNull == true
false
out of the full handlers pipeline, we are done, the expression is non-nullAfter:
true
from the handler unconditionally in this case (meaning if we have either of the above library models)true
from the full handlers pipeline.Either way, the expression is only consider
@Nullable
if both the if condition logic in this handler matches and dataflow returns@Nullable
and non-null otherwise. So they seem equivalent from the point of view of NullAway.java.There is a small subtlety here, though, which is that other handlers in the chain will observe the result of
LibraryModelsHandler
before any call to dataflow on NullAway.java. They will observe different values before/after this change.I don't think we are relying on dataflow being run here for the correctness of other handlers implementing
onOverrideMayBeNullExpr
, so this is probably fine? But it's worth pointing that small change in semantics.One thing I do see possibly happening is that after this change, this handler will set
exprMayBeNull == true
a lot more often for handlers further down the chain, which could cause some handlers that are checking for reasons to transitionnullable -> non-null
to do extra work. At the same time, the double call to dataflow is not particularly expensive, because we cache the results of the dataflow analysis.That said, taking a look at the handlers we currently have, the above concern is theoretical for now. All other handlers implementing this method (
RestrictiveAnnotationHandler
,InferredJARModelsHandler
, andOptionalEmptinessHandler
) do strictly less work whenexprMayBeNull == true
.Long digression, but basically convinced that this change is a good idea. Worth internal/performance testing, but I'd expect it to be mostly the same, just clearer code! (for which: thank you!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this analysis is correct. Since the new code structure is significantly clearer and easier to understand, I think we would probably want benchmarks showing some measurable performance difference before (re-)introducing an early call to dataflow in a handler. As it stands, I don't expect this change to have a measurable impact