Skip to content

Add support on the dataflow CFG for visiting lambda result expressions - #1516

Merged
wmdietl merged 4 commits into
typetools:masterfrom
lazaroclapp:lazaro_dataflow_cfg_lambda_w_exp_body
Nov 6, 2017
Merged

wmdietl merged 4 commits into
typetools:masterfrom
lazaroclapp:lazaro_dataflow_cfg_lambda_w_exp_body

Conversation

@lazaroclapp

Copy link
Copy Markdown
Contributor

This adds a new node to the cfg, LambdaResultExpressionNode, which corresponds
to the result of a lambda expression with a single expression as its body, and
which is added at the end of the cfg when CFGBuilder is passed a CFGLambda of
this kind as the underlaying ast.

This is needed by some analyses to handle the result of a lambda expression in
the case where the body is a single ExpressionTree. The case where the body is
a block is already handled by matching ReturnNode.

@lazaroclapp

Copy link
Copy Markdown
Contributor Author

I am also not sure if there is any other code internally in the checkerframework that needs to be updated to treat LambdaResultExpressionNode in ways similar to how ReturnNode is currently handled.

@smillst
smillst requested a review from wmdietl September 14, 2017 15:04
lazaroclapp added a commit to uber/NullAway that referenced this pull request Sep 26, 2017
This commit:

- Adds https://github.com/msridhar/checker-framework
  (repository branch) as a maven repository for our build.gradle
- Forces the 2.1.14-nullaway checker framework dataflow jar
  (but uses upstream javacutil.jar for same version). Forcing
  needed, as 2.1.14-* < 2.1.14 for dependency resolution.
- Adds the shadow maven plug-in allowing us to create a semi-fat
  jar using `gradle shadowJar` which contains NullAway and the
  checker framework fork, but not, say, EP or javax.
- Removes our hack around a CF fix we backported into our fork:
  typetools/checker-framework#1516
lazaroclapp added a commit to uber/NullAway that referenced this pull request Sep 27, 2017
This commit:

- Adds https://github.com/msridhar/checker-framework
  (repository branch) as a maven repository for our build.gradle
- Forces the 2.1.14-nullaway checker framework dataflow jar
  (but uses upstream javacutil.jar for same version). Forcing
  needed, as 2.1.14-* < 2.1.14 for dependency resolution.
- Adds the shadow maven plug-in allowing us to create a semi-fat
  jar using `gradle shadowJar` which contains NullAway and the
  checker framework fork, but not, say, EP or javax.
- Removes our hack around a CF fix we backported into our fork:
  typetools/checker-framework#1516
lazaroclapp added a commit to uber/NullAway that referenced this pull request Sep 28, 2017
This commit:

- Adds https://github.com/msridhar/checker-framework
  (repository branch) as a maven repository for our build.gradle
- Forces the 2.1.14-nullaway checker framework dataflow jar
  (but uses upstream javacutil.jar for same version). Forcing
  needed, as 2.1.14-* < 2.1.14 for dependency resolution.
- Adds the shadow maven plug-in allowing us to create a semi-fat
  jar using `gradle shadowJar` which contains NullAway and the
  checker framework fork (shaded), but not, say, EP or javax.
- Removes our hack around a CF fix we backported into our fork:
  typetools/checker-framework#1516
- Pulls in some code from Error Prone that did not interact well 
  with the shaded checker-framework. Namely from:
  com.google.errorprone.dataflow.nullnesspropagation.*

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @lazaroclapp ,
sorry for being so late on this PR. I have a few small comments that would be nice to address before merging.
Thanks!
cu, WMD.


public LambdaResultExpressionNode(
ExpressionTree t, /*@Nullable*/ Node result, Types types /*,
LambdaExpressionTree lambda,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can these comments be removed?

*/
public class LambdaResultExpressionNode extends Node {

protected ExpressionTree tree;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add some documentation what the tree and result represent, either here or, maybe better, with the public getter methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding it to the methods, let me know if its clear enough (working on the code as I reply to the comments, will update the PR shortly).

super(InternalUtils.typeOf(t));
this.result = result;
tree = t;
//result.setAssignmentContext(new AssignmentContext.LambdaReturnContext(methodSymbol));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you run into any problems with the assignment context? Does this require more work or can this comment be removed?

@lazaroclapp lazaroclapp Nov 1, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No problems here of interest. Removing, this is left-over code from another approach at this.

LambdaResultExpressionNode other = (LambdaResultExpressionNode) obj;
if ((result == null) != (other.result == null)) {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a comment why the tree doesn't need to be compared?

@lazaroclapp lazaroclapp Nov 1, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment added. This code is inspired by ReturnNode. Basically if we are constructing LambdaResultExpressionNode's correctly, then result is supposed to be scan([path_to_tree], null), which means just checking result should be enough. If we decide this is not the case, then we need to change both this one and ReturnNode.


@Override
public int hashCode() {
return HashCodeUtils.hash(result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly, why does the hash only depend on the result, not on the tree? Maybe this is something to document with the fields, also.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See above.

@wmdietl wmdietl assigned lazaroclapp and unassigned wmdietl Oct 22, 2017
@wmdietl

wmdietl commented Oct 22, 2017

Copy link
Copy Markdown
Member

Regarding other code changes: I tested your changes a bit and everything seemed to work as expected - we already had test coverage for lambdas with single expressions.
I opened one issue for a possible follow-up, #1607, but that shouldn't block this PR.

@mernst mernst changed the title Add support on the dataflow cfg for visiting lambda result expressions Add support on the dataflow CFG for visiting lambda result expressions Oct 30, 2017
… a lambda.

This adds a new node to the cfg, LambdaResultExpressionNode, which corresponds
to the result of a lambda expression with a single expression as its body, and
which is added at the end of the cfg when CFGBuilder is passed a CFGLambda of
this kind as the underlaying ast.

This is needed by some analyses to handle the result of a lambda expression in
the case where the body is a single ExpressionTree. The case where the body is
a block is already handled by matching ReturnNode.
@lazaroclapp
lazaroclapp force-pushed the lazaro_dataflow_cfg_lambda_w_exp_body branch from 52d4c3a to 451f7c6 Compare November 1, 2017 02:02
@lazaroclapp

Copy link
Copy Markdown
Contributor Author

Rebased and addressed the above comments. Thanks!! :)

@mernst mernst assigned wmdietl and unassigned lazaroclapp Nov 4, 2017

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@wmdietl
wmdietl merged commit 9ae4880 into typetools:master Nov 6, 2017
cushon pushed a commit to cushon/checker-framework that referenced this pull request Feb 28, 2026
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