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

8263642: javac emits duplicate checkcast for first bound of intersection type in cast #3399

Closed
wants to merge 5 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Apr 8, 2021

Hi all,

Before the phase desugar, the demo (C1 & I1) o has one type-cast sub-tree, JCTypeIntersection C1&I1, at the syntax tree. After the phase desugar, the (C1 & I1) o becomes three type-cast sub-trees: JCTypeIntersection C1&I1, I1, C1. So at phase Gen, javac generates three checkcast according to the three type-cast sub-trees which causes this bug.

This patch doesn't generate checkcast when the type is JCTypeIntersection so that the problem can be solved. And a corresponding test case is added.

Another way to solve this issue is that the TransTypes of the desugar should be modified and two type-cast sub-trees should be generated instead of three. But this way may change more code than my original patch and may cause other regression.

Thank you for taking the time to review.

Best Regards.
--Guoxiong


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263642: javac emits duplicate checkcast for first bound of intersection type in cast

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3399/head:pull/3399
$ git checkout pull/3399

Update a local copy of the PR:
$ git checkout pull/3399
$ git pull https://git.openjdk.java.net/jdk pull/3399/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3399

View PR using the GUI difftool:
$ git pr show -t 3399

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3399.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 8, 2021

👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 8, 2021
@openjdk
Copy link

openjdk bot commented Apr 8, 2021

@lgxbslgx The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Apr 8, 2021
@mlbridge
Copy link

mlbridge bot commented Apr 8, 2021

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented May 6, 2021

@lgxbslgx This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@lgxbslgx
Copy link
Member Author

Ping. Could I ask your help to review this patch? Thanks a lot.

Code_attribute code_attribute = (Code_attribute) method.attributes.get(Attribute.Code);
for (Instruction instruction : code_attribute.getInstructions()) {
if ("checkcast".equals(instruction.getMnemonic())) {
checkcastNumber++;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the test should check not only for the number of checkcast but also for the type the checkcast is checking against.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@@ -2221,7 +2221,8 @@ public void visitTypeCast(JCTypeCast tree) {
// the conversion.
if (!tree.clazz.type.isPrimitive() &&
!types.isSameType(tree.expr.type, tree.clazz.type) &&
types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null &&
tree.clazz.getTag() != TYPEINTERSECTION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if the right form of the AST is one that have only two type casts, then that's what the fix should be doing

Copy link
Member Author

Choose a reason for hiding this comment

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

I revised the patch to adjust the AST. Now it has only two type casts instead of three.

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Jun 2, 2021

@vicente-romero-oracle Thanks for your review. I updated the patch just now.

throw new AssertionError("The number of the instruction 'checkcast' is not right. " +
"Expected number: 2, actual number: " + checkCastList.size());
}
// first checkcast
Copy link
Contributor

Choose a reason for hiding this comment

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

hi, there is common code in the two sections of code that check for the checkcast I suggest creating a method for the common code

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

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

looks good

@openjdk
Copy link

openjdk bot commented Jun 2, 2021

@lgxbslgx This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8263642: javac emits duplicate checkcast for first bound of intersection type in cast

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 4 new commits pushed to the master branch:

  • e1462e7: 8267176: StandardDoclet should provide access to Reporter and Locale
  • 56b65e4: 8267569: java.io.File.equals contains misleading Javadoc
  • 508cec7: 8267521: Post JEP 411 refactoring: maximum covering > 50K
  • 40d23a0: 8267543: Post JEP 411 refactoring: security

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 2, 2021
@lgxbslgx
Copy link
Member Author

lgxbslgx commented Jun 2, 2021

@vicente-romero-oracle Thanks for your review. Could I get your help to sponsor this patch?

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 2, 2021
@openjdk
Copy link

openjdk bot commented Jun 2, 2021

@lgxbslgx
Your change (at version 5f4f5bb) is now ready to be sponsored by a Committer.

@vicente-romero-oracle
Copy link
Contributor

/sponsor

@vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle Thanks for your review. Could I get your help to sponsor this patch?

/integrate

sure, done

@openjdk openjdk bot closed this Jun 2, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 2, 2021
@openjdk
Copy link

openjdk bot commented Jun 2, 2021

@vicente-romero-oracle @lgxbslgx Since your change was applied there have been 4 commits pushed to the master branch:

  • e1462e7: 8267176: StandardDoclet should provide access to Reporter and Locale
  • 56b65e4: 8267569: java.io.File.equals contains misleading Javadoc
  • 508cec7: 8267521: Post JEP 411 refactoring: maximum covering > 50K
  • 40d23a0: 8267543: Post JEP 411 refactoring: security

Your commit was automatically rebased without conflicts.

Pushed as commit b7ac705.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@lgxbslgx lgxbslgx deleted the JDK-8263642 branch June 2, 2021 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants