-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8250625: Compiler implementation of Pattern Matching for instanceof (Final) #559
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
Conversation
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
/csr |
@lahodaj this pull request will not be integrated until the CSR request JDK-8254235 for issue JDK-8250625 has been approved. |
Webrevs
|
/label remove build |
@erikj79 |
@@ -25,8 +25,8 @@ | |||
* @test | |||
* @bug 8231827 | |||
* @summary Basic tests for bindings from instanceof | |||
* @compile --enable-preview -source ${jdk.version} BindingsTest1.java | |||
* @run main/othervm --enable-preview BindingsTest1 | |||
* @compile BindingsTest1.java |
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 @compile can be removed
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.
I guess I prefer to keep @compile for javac non-programatic tests. The reason is that, for these tests, we can expect we modify javac, but not the test. And if @build (implicit or explicit) is used, the test will not be re-compiled unless their timestamp changes. So we can actually execute an older (already built) version of the test's class file, instead of a newly built class file, which would reflect the changes in javac. So, for tests like this, I prefer to have an explicit @compile, as that ensures the file is compiled every time, regardless how the working directories are set-up, etc.
* @compile --enable-preview -source ${jdk.version} BindingsTest1.java | ||
* @run main/othervm --enable-preview BindingsTest1 | ||
* @compile BindingsTest1.java | ||
* @run main BindingsTest1 |
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.
and this line too
* @compile ExamplesFromProposal.java | ||
* @run main ExamplesFromProposal |
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 two lines can be removed now, there are other tests in this commit in which they can also be eliminated
* @modules jdk.jdeps/com.sun.tools.classfile | ||
* @compile -g --enable-preview -source ${jdk.version} LocalVariableTable.java | ||
* @run main/othervm --enable-preview LocalVariableTable | ||
* @compile -g LocalVariableTable.java |
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.
I believe all tests are always compiled with -g
option set, not related to your patch but we could probably remove that line as superfluous
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.
I believe plain jtreg invocations may not be always setting "-g". So probably better to be explicitly clear we need -g, as the test itself requires the debugging info/LocalVariableTable?
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.
sure I understand that the -g
option is necessary. I was just wondering if -g
is not passed always by jtreg. If the option is passed by default then it is superfluous, although just a comment, I understand that it is safer to pass it
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.
I tried with a plain jtreg invocation, and it didn't pass -g (and the test failed). But it depends on how jtreg is run, of course - some runs may have -g set.
@@ -105,7 +105,7 @@ private CompilationUnitTree parse(String code) throws IOException { | |||
|
|||
StringWriter out = new StringWriter(); | |||
JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors, | |||
List.of("--enable-preview", "-source", Integer.toString(Runtime.version().feature())), null, | |||
List.of(), null, |
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.
nit: what about passing null
instead of List.of()
?
*/ | ||
Tree getType(); | ||
@Deprecated |
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.
shouldn't we use @Deprecated(since=versionNumber)
* A tree node used as the base class for the different kinds of | ||
* statements. | ||
* | ||
* @since 14 | ||
* @since 16 | ||
*/ | ||
public interface PatternTree extends Tree {} |
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.
I think that this interface is there for forward compatibility, and I don't like empty interfaces but I found that we already did that with com.sun.source.tree.DirectiveTree
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.
We have multiple such interfaces - like StatementTree and ExpressionTree. It is a forward-looking interface, but I think necessary: InstanceofTree.getPattern() needs to return something, and having a PatternTree is (I think) better than returning generic Tree, or BindingPatternTree (the latter is likely to be insufficient sometime soon).
* feature of the Java language. Preview features | ||
* may be removed in a future release, or upgraded to permanent | ||
* features of the Java language.} | ||
* | ||
* A tree node used as the base class for the different kinds of |
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 seems to need an update, probably:
A tree node used as the base class for the different kinds of pattern matching expressions
?
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.
Patterns are not really expressions - they are a new kind of trees. Basically, before we had "statements" and "expressions" (+declarations, which are a bit special, ClassTree and VariableTree are "statements", but MethodTree, ModuleTree and PackageTree subtype Tree directly, so there is no common supertype). Now we have "patterns" in addition to that.
For example, having: o instanceof String s
, this is an expression, but String s
is not - it is a pattern. It cannot stand on its own as an expression, it is a special part of the expression.
Based on an offline feedback, I've removed the old, preview, deprecated methods from BindingPatternTree. |
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.
looks good!
@lahodaj 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:
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 15 new commits pushed to the
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. ➡️ To integrate this PR with the above commit message to the |
/integrate |
@lahodaj Since your change was applied there have been 15 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 18bc95b. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This is the current proposed patch for the upcoming JEP 394, for pattern matching for instanceof.
A summary of changes:
-making the feature permanent (non-preview)
-making the binding variables non-final (as per current specification proposal)
-producing a compile-time error for the case where the expression's type is a subtype of the type test pattern's type (as per current specification proposal)
-changing the AST structure so that the binding variable has a VariableTree in the AST. BindingPatternTree is preserved and encloses the VariableTree. The reason is better consistency in the API, with nodes like CatchTree, EnhancedForLoop Tree, etc.
This change will not be integrated until JEP 394 is targetted.
Progress
Testing
Failed test tasks
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/559/head:pull/559
$ git checkout pull/559