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

Extend library models to mark fields as nullable #878

Merged
merged 16 commits into from
Dec 15, 2023

Conversation

nimakarimipour
Copy link
Contributor

@nimakarimipour nimakarimipour commented Dec 12, 2023

This PR extends LibraryModels to add support for marking fields @Nullable. This feature is required to enable Annotator index impact of making fields @Nullable on downstream dependencies.

Please note, since this feature is mostly going to be used while indexing impacts on downstream dependencies, this PR does not focus on the optimality of the implementation. Also the working set in iterations is not expected to be large. We can optimize the implementation in a follow up PR if needed.

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5fbee1f) 87.03% compared to head (b16a3a5) 87.10%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #878      +/-   ##
============================================
+ Coverage     87.03%   87.10%   +0.06%     
- Complexity     1926     1940      +14     
============================================
  Files            77       77              
  Lines          6231     6264      +33     
  Branches       1212     1218       +6     
============================================
+ Hits           5423     5456      +33     
  Misses          405      405              
  Partials        403      403              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Overall looks really good! A few comments

@@ -244,4 +252,58 @@ public String toString() {
+ '}';
}
}

/** Representation of a field as a qualified class name + a field name */
final class FieldRef {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just use AutoValue for this class, since we already rely on it? Would get rid of a lot of boilerplate. See, e.g.:

https://github.com/uber/NullAway/blob/master/nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java#L318-L318

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@msridhar Sure. Used @AutoValue : f15b983

@nimakarimipour
Copy link
Contributor Author

@msridhar Thanks for the review, this is ready for another round. I think it might be better to not land this even after approvals, and land it once I can locally test it with the updates on Annotator.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

one more thing

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

One more thing

Comment on lines 279 to 286
// check presence. This is a bit inefficient, but it's only used while indexing impact of
// making fields @Nullable on downstream dependencies. Also, the set of nullable fields is not
// expected to be large. We can optimize in future if needed.
return libraryModels.nullableFields().stream()
.anyMatch(
fieldRef ->
fieldRef.getFieldName().equals(fieldName)
&& fieldRef.getEnclosingClassName().equals(enclosingClassName));
Copy link
Collaborator

Choose a reason for hiding this comment

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

One last question. Why not just do return libraryModels.nullableFields().contains(fieldRef(enclosingClassName,fieldName))? We don't care about performance too much, but that should be constant time assuming hashing, and also it seems clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, make sense. 1728198

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!!

@msridhar msridhar merged commit 3ee7072 into uber:master Dec 15, 2023
10 checks passed
msridhar added a commit to msridhar/NullAway that referenced this pull request Dec 16, 2023
@nimakarimipour nimakarimipour deleted the nimak/add-field-library-models branch December 17, 2023 20:15
nimakarimipour added a commit to ucr-riple/NullAwayAnnotator that referenced this pull request Dec 28, 2023
Followup on an update in NullAway recent change [#878](uber/NullAway#878) which enables NullAway to mark fields as `@Nullable`. This PR updates our `LibraryModelsLoader` to enable communication of Annotator and NullAway to mark fields `@Nullable` while analyzing downstream dependencies. This is required to prepare the code for the upcoming change which enables Annotator to be informed of impacts of making fields `@Nullable` on downstream dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants