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
7903132: Replace casts with type test pattern #5
7903132: Replace casts with type test pattern #5
Conversation
👋 Welcome back bowbahdoe! A progress list of the required criteria for merging this PR into |
Are you in a position to file a JBS issue for this? We're happy to sponsor - the problem here is that the subject of the PR has to be in the form: NNNNNNN: For it to go through. If you are having issues, please let us know and we'll try to find an alternate arrangement. |
My understanding is that I can't file a JBS issue until I get an account, which only happens after having made two contributions and petitioning for becoming an author. I can do it the long way around certainly by filing a bug report via the oracle site, but I don't think this is the sort of thing that would make it past that filter. |
I've filed an issue for this PR here: https://bugs.openjdk.java.net/browse/CODETOOLS-7903132 Please update the PR title to include the issue number. |
return false; | ||
} | ||
return (Index_h.clang_equalCursors(cursor, ((Cursor)other).cursor) != 0); | ||
return (Index_h.clang_equalCursors(cursor, otherCursor.cursor) != 0); |
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 in these cases we can do better by merging the instanceof
check above this in the condition. i.e.
return (Index_h.clang_equalCursors(cursor, otherCursor.cursor) != 0); | |
return other instanceof Cursor otherCursor | |
&& (Index_h.clang_equalCursors(cursor, otherCursor.cursor) != 0); |
And similar for other places that are computing a boolean value, such as all the equals methods.
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.
Strictly speaking, the whole method body could be merged into one expression. Its the realm of infinite bikesheds though, and I did not / do not know if there is a set of implicit style choices there.
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.
Well, we're on the topic of style changes already, so let's pull the string. This is new territory, so I think this is where we decide this :)
Merging the instanceof
into the expression avoids having the pattern variable be carried over to outside of the if
block, which I think is better.
The this == other
check above that doesn't have the same problem.
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 don't have any particularly strong opinions there, so I made that as the change, leaving the this == other
checks alone
@@ -56,8 +56,7 @@ | |||
|
|||
ClassSourceBuilder(JavaSourceBuilder enclosing, Kind kind, String name) { | |||
this.enclosing = enclosing; | |||
this.align = (enclosing instanceof ClassSourceBuilder) ? | |||
((ClassSourceBuilder) enclosing).align : 0; | |||
this.align = (enclosing instanceof ClassSourceBuilder enclosing) ? enclosing.align : 0; |
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 is resulting in a compilation error:
jextract\src\main\java\org\openjdk\jextract\impl\ClassSourceBuilder.java:59: error: variable enclosing is already defined in constructor ClassSourceBuilder(JavaSourceBuilder,Kind,String)
this.align = (enclosing instanceof ClassSourceBuilder enclosing) ? enclosing.align : 0;
Please build and test the patch locally on your machine as well, if you haven't done so already. (This should be done before suggesting changes).
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.
So yes, 100% on me. But in my defense I am getting a particularly obtuse error before compilation and there isn't exactly someone to ask without pretense.
$ /usr/bin/clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Could not get unknown property 'libclang_home' for root project 'jextract' of type org.gradle.api.Project.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 297ms
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home -Plibclang_home=/usr/bin/clang clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Cannot invoke method getAt() on null object
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 287ms
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home -Plibclang_home=/usr/bin/ clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Cannot invoke method getAt() on null object
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 290ms
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 was counting on some CI/CD to be triggered on PR, which i suppose either isn't the case or isn't the case unless i get past the issue number check)
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.
Questions can be directed at the mailing list (either jextract-dev@openjdk.java.net or panama-dev@openjdk.java.net). You can send an email there without making an account as well (it will go through a moderation queue first).
I agree the error message is not great. In this case the issue seems to be this line in build.gradle:
def clang_version = new File("${libclang_home}/lib/clang/").list()[0]
i.e. the libclang_home
directory does not have the expected directory structure. It is looking for a directory like <libclang_home>/lib/clang/<VERSION>
. So please make sure that exists.
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.
On a stock mac install with XCode it ended up being located at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
- in case that is of use to anyone.
@bowbahdoe This change now passes all automated pre-integration checks. 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 2 new commits pushed to the Please see this link for an up-to-date comparison between the source branch of this pull request and the 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 |
Webrevs
|
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
/integrate |
@bowbahdoe |
/sponsor |
Going to push as commit 4c0e547.
Your commit was automatically rebased without conflicts. |
@mcimadamore @bowbahdoe Pushed as commit 4c0e547. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Replaces a handful of casts following type tests with the equivalent pattern syntax.
I cannot create a matching issue, as I do not have an account on the bug tracker.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jextract pull/5/head:pull/5
$ git checkout pull/5
Update a local copy of the PR:
$ git checkout pull/5
$ git pull https://git.openjdk.java.net/jextract pull/5/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5
View PR using the GUI difftool:
$ git pr show -t 5
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jextract/pull/5.diff