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

7903132: Replace casts with type test pattern #5

Closed

Conversation

bowbahdoe
Copy link
Contributor

@bowbahdoe bowbahdoe commented Mar 24, 2022

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

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

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

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 24, 2022

👋 Welcome back bowbahdoe! 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.

@mcimadamore
Copy link
Contributor

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.

@bowbahdoe
Copy link
Contributor Author

bowbahdoe commented Mar 25, 2022

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.

@JornVernee
Copy link
Member

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);
Copy link
Member

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.

Suggested change
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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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).

Copy link
Contributor Author

@bowbahdoe bowbahdoe Mar 25, 2022

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

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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 bowbahdoe changed the title Replace casts with type test pattern 7903132: Replace casts with type test pattern Mar 25, 2022
@openjdk
Copy link

openjdk bot commented Mar 25, 2022

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

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

7903132: Replace casts with type test pattern

Reviewed-by: mcimadamore, jvernee

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 master branch:

  • 71d7eae: Drop JBS check from jextract repo
  • 60978d2: 7903129: jextract does not handle @argfile

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 (@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 ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 25, 2022
@mlbridge
Copy link

mlbridge bot commented Mar 25, 2022

Webrevs

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

@bowbahdoe
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Mar 25, 2022
@openjdk
Copy link

openjdk bot commented Mar 25, 2022

@bowbahdoe
Your change (at version 63e2aa7) is now ready to be sponsored by a Committer.

@mcimadamore
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Mar 28, 2022

Going to push as commit 4c0e547.
Since your change was applied there have been 4 commits pushed to the master branch:

  • fba7220: 7903133: add lp_solve sample
  • 6018d1e: 7903134: Improve error reporting in jextract gradle build
  • 71d7eae: Drop JBS check from jextract repo
  • 60978d2: 7903129: jextract does not handle @argfile

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 28, 2022
@openjdk openjdk bot closed this Mar 28, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Mar 28, 2022
@openjdk
Copy link

openjdk bot commented Mar 28, 2022

@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.

@bowbahdoe bowbahdoe deleted the replace-casts-with-type-test-pattern branch March 29, 2022 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
3 participants