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

8057543: Replace javac's Filter with Predicate (and lambdas) #1898

Closed
wants to merge 6 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Dec 27, 2020

Hi all,

This patch replaces javac's Filter with Predicate and sets Filter as Deprecated.
Two existing tests failed and I fixed it.
Currently, all the tests in test/langtools passed locally by using the following command.

make test CONF=linux-x86_64-server-release JOBS=4 TEST=test/langtools/

Thank you for taking the time to review.

Best Regards.


Progress

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

Issue

  • JDK-8057543: Replace javac's Filter with Predicate (and lambdas)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1898

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 27, 2020

👋 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 Dec 27, 2020
@openjdk
Copy link

openjdk bot commented Dec 27, 2020

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

  • compiler
  • kulla

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

@openjdk openjdk bot added compiler compiler-dev@openjdk.org kulla kulla-dev@openjdk.org labels Dec 27, 2020
@lgxbslgx
Copy link
Member Author

/label remove kulla

@openjdk openjdk bot removed the kulla kulla-dev@openjdk.org label Dec 27, 2020
@openjdk
Copy link

openjdk bot commented Dec 27, 2020

@lgxbslgx
The kulla label was successfully removed.

@mlbridge
Copy link

mlbridge bot commented Dec 27, 2020

Webrevs

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Dec 27, 2020

More information and some similar issues:

These four issues were fixed in this patch
JDK-8057542
JDK-8057545
JDK-8057546
JDK-8057547

This issue was fixed in this patch
JDK-8057544

But their status are still NEW. It should be revised to RESOLVED or CLOSED.

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 24, 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!

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 21, 2021

@lgxbslgx This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it!

@bridgekeeper bridgekeeper bot closed this Feb 21, 2021
Copy link
Contributor

@mcimadamore mcimadamore left a comment

Choose a reason for hiding this comment

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

This looks very good - sorry I missed it. If you reopen I will approve!

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Apr 6, 2021

@mcimadamore Thank you for your help. I will reopen it.

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Apr 6, 2021

I can't find the reopen button. Maybe it is my permission issue. Could anyone reopen it for me? Thanks a lot.

@mlbridge
Copy link

mlbridge bot commented Apr 6, 2021

Mailing list message from Maurizio Cimadamore on compiler-dev:

Not sure - I don't see it either - CC'ing Erik

Maurizio

On 06/04/2021 06:13, Guoxiong Li wrote:

@lgxbslgx
Copy link
Member Author

@mcimadamore Who should we ping to solve the reopen problem? I have several PRs which were closed by the robot and need to be reopen too.

@mcimadamore
Copy link
Contributor

@edvbld Can you please help?

@lgxbslgx
Copy link
Member Author

/open

@openjdk openjdk bot reopened this Apr 21, 2021
@openjdk
Copy link

openjdk bot commented Apr 21, 2021

@lgxbslgx @HostUserDetails{id=13688759, username='lgxbslgx', fullName='null'} this pull request is now open

@lgxbslgx
Copy link
Member Author

@mcimadamore The PR could be reopen by typing /open command. We can continue the work now. I would resolve the git conflicts later.

# Conflicts:
#	src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java
Copy link
Contributor

@mcimadamore mcimadamore 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 - left some comments

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

copyright in this (and other files need to be updated)

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.

@@ -90,7 +91,7 @@

final Symtab syms;
final JavacMessages messages;
final Names names;
private Names names;
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this change coming from?

Copy link
Member Author

Choose a reason for hiding this comment

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

When building the JDK, I got the following error:

jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java:950: error: variable names might not have been initialized
                    t.name != names.init &&
                              ^
1 error

Therefore I revised the modifier of the Names names.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see - honestly this seems like a bug in definite assignment? E.g. surely the instance field initializer for bridgeFilter must run after the final field names has been initialized? For now you might try using an anonymous inner class instead of a lambda instead, pretty sure that will take care of the issue. But this looks like a compiler bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually - doing more tests, I think javac is right. Fields with explicit initializers are initialized BEFORE other constructor statements. Which means that the error message is legitimate (e.g. the lambda is capturing a final value that is not initialized). I think reverting back to anon class would be better here.

Copy link
Member

Choose a reason for hiding this comment

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

It's not a bug, it's a dubious feature, the lambda EG discussed that at length, you can ask Brian about it.

Usually replacing

t.name != names.init

by

  t.name != this.names.init

is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

@forax Thank you for your reply. I tested t.name != this.names.init with final Names names; just now. The error also occurred. Same as t.name != names.init.

And I think that t.name != names.init and t.name != this.names.init are equal at this situation.

*/
@Deprecated(forRemoval = true, since = "17")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a public API - we're in a JDK internal class - if this class is no longer needed (as is the goal of this change) simply remove it :-)

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.

@lgxbslgx
Copy link
Member Author

More information and some similar issues:

These four issues were fixed in this patch
JDK-8057542
JDK-8057545
JDK-8057546
JDK-8057547

This issue was fixed in this patch
JDK-8057544

But their status are still NEW. It should be revised to RESOLVED or CLOSED.

@mcimadamore I want to set these issues to CLOSED or RESOLVED. What's your opinion?

@mlbridge
Copy link

mlbridge bot commented Apr 22, 2021

Mailing list message from Maurizio Cimadamore on compiler-dev:

Not sure - it doesn't seem to me that the patch for JDK-8057547 converts
other stuff to use standard functional interface. Only TypeMapping is
changed - so it affects (8057544, which can be closed).

Maurizio

On 21/04/2021 16:36, Guoxiong Li wrote:

1 similar comment
@mlbridge
Copy link

mlbridge bot commented Apr 22, 2021

Mailing list message from Maurizio Cimadamore on compiler-dev:

Not sure - it doesn't seem to me that the patch for JDK-8057547 converts
other stuff to use standard functional interface. Only TypeMapping is
changed - so it affects (8057544, which can be closed).

Maurizio

On 21/04/2021 16:36, Guoxiong Li wrote:

@lgxbslgx
Copy link
Member Author

@mcimadamore Thank you for your reply about these issues.

For JDK-8057542 FreeTypeListener, I search the words new FreeTypeListener at the PATCH. I can get 6 places which are like the following code.

-                inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() {
-                    @Override
-                    public void typesInferred(InferenceContext inferenceContext) {
-                        checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts));
-                    }
-                });
+                inferenceContext.addFreeTypeListener(ts,
+                        solvedContext -> checkAccessibleTypes(pos, env, solvedContext, solvedContext.asInstTypes(ts)));

For JDK-8057545 Factory, I search the words new Context.Factory at the PATCH. I can get 14 places which are like the following code.

-        context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
-            @Override
-            public JavaFileManager make(Context c) {
-                return new JavacFileManager(c, true, null);
-            }
-        });
+        context.put(JavaFileManager.class,
+                (Factory<JavaFileManager>)c -> new JavacFileManager(c, true, null));

For JDK-8057546 LintLogger, I search the words new DeferredLintHandler.LintLogger at the PATCH. I can get 4 places which are like the following code.

-            deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
-                @Override
-                public void report() {
-                    warnDeprecated(pos, s);
-                }
-            });
+            deferredLintHandler.report(() -> warnDeprecated(pos, s));

For JDK-8057547 TreeBuilder, I search the words new TreeBuilder at the PATCH. I can get 7 places which are like the following code.

-            return abstractRval(s.selected, new TreeBuilder() {
-                    public JCExpression build(final JCExpression selected) {
-                        return builder.build(make.Select(selected, s.sym));
-                    }
-                });
+            return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));

On the other hand, I search new FreeTypeListener, new Context.Factory, new DeferredLintHandler.LintLogger and new TreeBuilder at current JDK main line code base. I can't get any result. So I think these four issues are solved by this PATCH or other patches.

@mcimadamore
Copy link
Contributor

I agree that all these issues have been fixed - sorry - I thought these issues wanted to replace the various interfaces with interfaces from j.u.function (as done in this patch) - but these were about using lambda expressions more where possible - yeah I fixed that long ago.

@lgxbslgx
Copy link
Member Author

@mcimadamore OK, I closed them just now.

Copy link
Contributor

@mcimadamore mcimadamore 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 Apr 22, 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:

8057543: Replace javac's Filter with Predicate (and lambdas)

Reviewed-by: mcimadamore

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 24 new commits pushed to 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 (@mcimadamore) 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 Apr 22, 2021
@lgxbslgx
Copy link
Member Author

@mcimadamore Thank you for your review. Could I get your help to sponsor this patch?
Although the Pre-submit tests don't finish, the tests on tools/javac passed locally.

/integrate

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

openjdk bot commented Apr 22, 2021

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

@mcimadamore
Copy link
Contributor

/sponsor

@openjdk openjdk bot closed this Apr 22, 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 Apr 22, 2021
@openjdk
Copy link

openjdk bot commented Apr 22, 2021

@mcimadamore @lgxbslgx Since your change was applied there have been 25 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit 657f103.

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

@lgxbslgx lgxbslgx deleted the JDK-8057543 branch April 22, 2021 17:11
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
3 participants