-
Notifications
You must be signed in to change notification settings - Fork 352
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
Handle while true (Fixes #3249) #3389
Conversation
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 this fix!
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.
These changes look good. I have two minor comments.
FYI, when a pull request fixes an issue, then the pull request description should say fixes #XXXX
or fixes #XXXX and fixes #XXXX
. That way those issues will be closed when the pull request is merge. You could use one of the other ways. I've updated this pull request description.
@@ -4913,15 +4915,30 @@ public Node visitWhileLoop(WhileLoopTree tree, Void p) { | |||
// Condition | |||
addLabelForNextNode(conditionStart); | |||
assert tree.getCondition() != null; | |||
// Determine whether loop condition is a constant true, according to the compiler logic. |
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.
true
is a literal not a constant. So this should say Determine whether loop condition is the boolean literal "true",
. You've used constant
instead of literal
in other places in this pull request. Please change all uses.
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.
More generally, a literal appears in source code, and a constant is an expression that can be evaluated at compile time. So, true
is both a literal and a constant. 4 > 3
is a constant.
Using these terms consistently will help to make the code easier to read. Thanks!
(I haven't read the code to determine whether it is checking for the literal true
or the constant true
.)
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.
@@ -4985,6 +5002,35 @@ public Node visitOther(Tree tree, Void p) { | |||
} | |||
} | |||
|
|||
/** | |||
* Determine whether loop condition {@link JCTree} is a constant true, according to the compiler |
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 method works for any tree, even if that tree is not a loop condition. We might find uses for this method outside of this class, would you please move it to TreeUtils
and rename it to isLiteralTrue
.
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.
Moving to TreeUtils
sounds good. As name I would use isExpressionConstantTrue
or isExprConstTrue
, or the current isCondConstTrue
.
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 Javadoc should say is a compile-time constant true
or as the JLS uses a condition expression has the constant value true
. (I clearly misunderstood the term constant true
, other might, too.)
What do you mean here? I renamed this issue 7 days ago an don't see a further edit. |
@wmdietl, you changed the title of the issue. I updated the pull request description which is the first comment. If you add |
Here do you mean "pull request" instead of "issue"? You're pointing out that even though the first sentence of the PR description is |
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 improvements!
This PR fixes both issue #3249 and issue #1727, by adapting the CFG in the following way:
If the loop condition is checked to be a constant true (according to the same logic in javac flow analysis), then the loop condition does not have an else-branch, i.e. the block holding the loop condition is directly followed by the one holding the loop entry, instead of followed by a conditional block.
Fixes #1727 and Fixes #3249`