-
Notifications
You must be signed in to change notification settings - Fork 353
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
Second Phase of RLC inference #6278
Conversation
…amework into inference-phase-two
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.
Thanks for these enhancements. I have a few comments.
checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallInference.java
Outdated
Show resolved
Hide resolved
* inference. For example, if a field's must-call method is called, it is added to this set. If, | ||
* in a later statement in the same method, the same field is re-assigned, it will be removed from | ||
* this set (since the field assignment invalidated the previously-inferred closing of the | ||
* obligation). | ||
*/ | ||
private final Set<VariableElement> disposedFields = new HashSet<>(); |
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.
Does the use of a HashSet make the algorithm nondeterministic? (I'm not sure; don't make it a LinkedHashSet unless it needs to be.)
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.
This might cause nondeterministic ordering of fields in @EnsuresCalledMethods
annotations, and to prevent this, I've switched to using LinkedHashSet
.
* <li>the inferred owning fields in this analysis. | ||
* </ul> | ||
* | ||
* This set is a superset of the {@code disposedFields} set. | ||
*/ | ||
private final Set<VariableElement> owningFields = new HashSet<>(); |
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.
Does the use of a HashSet make the algorithm nondeterministic? (I'm not sure; don't make it a LinkedHashSet unless it needs to be.)
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.
Since we don't iterate over this field in our computation, I think using a HashSet should be fine.
* The owned fields. This includes: | ||
* | ||
* <ul> | ||
* <li>fields with written {@code @Owning} annotations at the entry point of the CFG currently |
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.
What does it mean to have an @Owning
annotation at the entry point? Does that mean @Owning
is written on a field or formal parameter?
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.
It's pointing to the fields, I removed "at the entry ..." to prevent future confusion.
* The keys are the obligation of return nodes, and the values are the index of current method | ||
* formal parameter (1-based) that is aliased with the return node. | ||
*/ | ||
private final Map<Obligation, Integer> returnNodeToParameter = new HashMap<>(); |
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.
Should this be named "returnObligationToParameter"?
More generally, please discuss the choice to use obligations rather than nodes as the keys. The documentation says that the map is from return nodes to method parameters, but the implementation is different. Why are obligations needed? Is it because they indicate resource aliasing relationships? Or is it for some other reason?
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.
They are needed to check aliasing relationships of return nodes with parameters.
checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallInference.java
Outdated
Show resolved
Hide resolved
// methods should be called. This map is used to create a single @EnsuresCalledMethods | ||
// annotation for fields that share the same must-call obligation. | ||
// methods should be called. This map is used to create a @EnsuresCalledMethods annotation for | ||
// each set of fields that share the same must-call obligation. | ||
Map<String, Set<String>> methodToFields = new LinkedHashMap<>(); | ||
for (VariableElement disposedField : disposedFields) { | ||
List<String> mustCallValues = resourceLeakAtf.getMustCallValues(disposedField); |
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.
The value of mustCallValues
was known when constructing disposedFields
. Would it make sense to record it it dispasedFields
so it does not need to be recomputed here?
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 changed the deposedFields
set to a map to keep the must-call
value and save some computation here. Thanks for the suggestion.
checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallInference.java
Outdated
Show resolved
Hide resolved
@@ -493,7 +610,7 @@ private void addOrUpdateClassMustCall() { | |||
} | |||
|
|||
/** | |||
* Computes ownership transfer at the method call to infer @Owning annotation for the arguments | |||
* Computes ownership transfer at the method call to infer @Owning annotations for the arguments |
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.
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.
It is correct, I updated the comment to what you suggested.
checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallInference.java
Show resolved
Hide resolved
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.
Thanks for the simplifictation!
Co-authored-by: Michael Ernst <mernst@cs.washington.edu> Co-authored-by: Manu Sridharan <msridhar@gmail.com> Co-authored-by: Martin Kellogg <martin.kellogg@njit.edu>
This PR infers:
@NotOwning
for return types@MustCallAlias
for both return types and parameter types@Owning
for constructor parameters when there are multiple owning fields.