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

Fix #657 by splitting field initialization region into smaller regions #658

Merged
merged 13 commits into from
Nov 8, 2022

Conversation

nimakarimipour
Copy link
Contributor

Note: This PR can wait until the next release of NullAway (0.10.2).

This PR resolves #657 by splitting the field initialization region into smaller regions. We currently only consider the value "null", for all errors/fixes reported in this regions. In large classes which they have many number of field, this can easily create a lot builds as they all have the value "null" for enclosing method causing conflicts in regions.

This PR generalizes the concept of enclosing method to enclosing member, and breaks a single regions of field initialization regions into a separate region for each field declaration and reduce the conflicts in regions dramatically.

The equivalent for enclosing member is described:
The enclosing member for fix or error is:

  • If it is triggered inside a method, the enclosing member will be the enclosing method.
  • If it is enclosed by a field declaration statement, the enclosing member will be the declared field.
  • If none of the above, the enclosing member will be "null" (used for static initialization region).

With the current approach the following errors will have the values below:

class C {
    Field foo1 = Field(null); // Passing nullable, enclMethod = "null"
    Field foo2 = null; // assigning nullable, enclMethod = "null"
    static Field foo3 3 = null; // assigning nullable, enclMethod = "null"
    {
          foo3 = null; // assigning nullable, enclMethod = "null"
    }

   void bar(){
         this.foo1 = null; // assigning nullable, enclMethod = "bar()"
   }
}

From the point of view of Annotator, that is 4 conflicts in regions as they all have enclMethod = "null".

This can be greatly improved with the new approach suggested and changed to below:

class C {
    Field foo1 = Field(null); // Passing nullable, enclMember = "foo1"
    Field foo2 = null; // assigning nullable, enclMember = "foo2"
    static Field foo3 = null; // assigning nullable, enclMember = "foo3"
    {
          Field3 = null; // assigning nullable, enclMember = "null"
    }

   void bar(){
         this.foo1 = null; // assigning nullable, enclMember = "bar()"
   }
}

None of the error reported above have any conflicts and can be allocated to separate regions.

@msridhar
Copy link
Collaborator

Note: This PR can wait until the next release of NullAway (0.10.2).

Do you mean until after that release?

@lazaroclapp
Copy link
Collaborator

Note: This PR can wait until the next release of NullAway (0.10.2).

Do you mean until after that release?

For context, we want to have a NullAway release with #656 (probably NullAway 0.10.2) and a NullAwayAutoAnnotator release with some version of ucr-riple/NullAwayAnnotator#72, then test them internally and upgrade them in lockstep.

@nimakarimipour , question, does having this change in NullAway require a corresponding change in NullAwayAutoAnnotator?

I think, long term, if need to keep upgrading the two in lockstep, we might either need them to be on the same repo with tight coupling and integration tests between the two components, or we need to make all these file formats versioned and keep compatibility within the NullAwayAutoAnnotator for multiple NullAway releases, it's becoming a bit of an issue that we need to coordinate releases between the two projects.

@nimakarimipour
Copy link
Contributor Author

Note: This PR can wait until the next release of NullAway (0.10.2).

Do you mean until after that release?

Yes, the reason is that it requires a change in Annotator and I think we should make pipeline internally stable to work with NullAway 0.10.2 and Annotator 1.3.3 for now, and then apply both changes in NullAway 0.10.3 and Annotator 1.3.4.

@nimakarimipour
Copy link
Contributor Author

nimakarimipour commented Sep 19, 2022

Note: This PR can wait until the next release of NullAway (0.10.2).

Do you mean until after that release?

For context, we want to have a NullAway release with #656 (probably NullAway 0.10.2) and a NullAwayAutoAnnotator release with some version of nimakarimipour/NullAwayAnnotator#72, then test them internally and upgrade them in lockstep.

@nimakarimipour , question, does having this change in NullAway require a corresponding change in NullAwayAutoAnnotator?

I think, long term, if need to keep upgrading the two in lockstep, we might either need them to be on the same repo with tight coupling and integration tests between the two components, or we need to make all these file formats versioned and keep compatibility within the NullAwayAutoAnnotator for multiple NullAway releases, it's becoming a bit of an issue that we need to coordinate releases between the two projects.

Yes it requires a change in Annotator, actually I thought about making NullAway output its current version in a file and Annotator either try to be compatible with that or terminate with a message informing what NullAway/Annotator version should be used.

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

LGTM, except for a minor nit about comment styles 🙂

/** Path to the program point of the reported error */
/** Class and member corresponding to a program point at which an error / fix was reported. */
public class ClassAndMemberInfo {
/** Path to the program point of the reported error / fix */
public final TreePath path;

/**
* Finding values for these properties is costly and are not needed by default, hence, they are
* not {@code final} and are only initialized at request.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment format (starting with /**) indicates that this is the javadoc documentation for method. I think this is just an unrelated comment about both of the fields below, so I would just have it as:

// Finding values for these properties is costly and are not needed by default, hence, they are
// not final and are only initialized at request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for noticing this :) 9e6f062

@lazaroclapp
Copy link
Collaborator

Yes it requires a change in Annotator, actually I thought about making NullAway output its current version in a file and Annotator either try to be compatible with that or terminate with a message informing what NullAway/Annotator version should be used.

I think it's worth doing this as a follow up PR before the next NullAway release, at least the compatibility check. Would save us some surprises in the future...

@lazaroclapp lazaroclapp merged commit eb62d57 into uber:master Nov 8, 2022
@nimakarimipour nimakarimipour deleted the nimak/issue-657 branch November 9, 2022 01:19
nimakarimipour added a commit to ucr-riple/NullAwayAnnotator that referenced this pull request Nov 23, 2022
This PR updates the region computation in `Type-Annotator-Scanner` according to latest changes in NullAway following [PR658](uber/NullAway#658). 

Also in this PR the infrastructure for keeping compatibility with older versions of NullAway (`0.10.4` or less) is implemented.
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 18, 2023
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.

Break field initialization region into multiple regions
3 participants