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

Support record inside JandexUtil #28229

Merged
merged 2 commits into from
Oct 3, 2022

Conversation

loicmathieu
Copy link
Contributor

@loicmathieu loicmathieu commented Sep 27, 2022

Improve Java records support.

The only place where I tested it is with MongoDB with Panache, thanks to this PR MongoDB entity can now be declared as records. Other places should require more work.

There is no test as there is no facility in Quarkus yet to test functionalities provided by java version different than the one we build with.

@gastaldi gastaldi requested a review from Ladicek September 27, 2022 17:15
@quarkus-bot

This comment has been minimized.

Ladicek
Ladicek previously approved these changes Sep 29, 2022
Copy link
Contributor

@Ladicek Ladicek left a comment

Choose a reason for hiding this comment

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

This change LGTM, but I've got 2 notes:

  1. The isSubclassOf method didn't work correctly when parentName was java.lang.Object. Now, it won't work correclty if parentName is also java.lang.Record. I guess that's not too big of an issue by now?
  2. RESTEasy Reactive carries a copy of JandexUtil that has already drifted a little. Maybe we should do this change there as well? CC @geoand

@Ladicek Ladicek dismissed their stale review September 29, 2022 11:54

I'm rescinding my approval here, because I don't really understand how Quarkus uses Jandex internally. I also think that using the "computing" index (which indexes classes on demand) is probably a better choice.

@geoand
Copy link
Contributor

geoand commented Sep 29, 2022

Maybe we should do this change there as well

Sounds like a good idea to me

@loicmathieu
Copy link
Contributor Author

@Ladicek I added your commit to the branch so we have now an almost fully functionning JandexUtil for records.

@loicmathieu loicmathieu requested a review from Ladicek September 29, 2022 14:46
@Ladicek
Copy link
Contributor

Ladicek commented Sep 29, 2022

I would agree with the original form of this PR, as an optimization. (Also done in the RESTEasy Reactive copy of JandexUtil.) I don't agree with exposing an isClassTerminal operation, because it introduces but not properly defines a new concept, one that I doubt is useful.

@loicmathieu
Copy link
Contributor Author

Ok I'll change it tomorrow. I did it thus way because there is a bunch of places in Panache code where the same if is made.

@Ladicek
Copy link
Contributor

Ladicek commented Sep 29, 2022

Can you please try using the computed index and see if those ifs can disappear from Panache code?

@quarkus-bot

This comment has been minimized.

@loicmathieu
Copy link
Contributor Author

@Ladicek using the computing index didn't change anything, I can do it if you prefere (I prepare a PR for some changes that must be done at MongoDB with Panache side but I need to do more test).

I propose to revert to my previous changes without the new method and also impact the resteasy reactive JandexUtil, by the way, some methods are not used (at least it's what IntelliJ said), can I remove them?

@Ladicek
Copy link
Contributor

Ladicek commented Sep 30, 2022

I think I'd prefer to keep the 2 JandexUtil classes as much in sync as possible. There's a drift already, but let's not make it bigger.

@Ladicek
Copy link
Contributor

Ladicek commented Sep 30, 2022

BTW if there's a need to special-case for records, you can always check ClassInfo.isRecord(). But the computing index should provide a ClassInfo for java.lang.Record and hence no special-casing should be necessary, at least not the kind we do in this PR. If not, I suspect my lack of understanding is bigger than I thought :-)

@loicmathieu
Copy link
Contributor Author

Sooooo, @Ladicek your undertanding of records is OK, I was hit by a testing issue by the CLI not recompiling ...

Yes, using the computing index inside the processor fix the issue. Should I dismiss this PR ?
Can you quickly explain to me what is the difference between the two index ? All Panache code using the index not the computing one since 3 years now so I prefer understanding the impact of changing it.

@Ladicek
Copy link
Contributor

Ladicek commented Sep 30, 2022

You can see the difference here: https://github.com/quarkusio/quarkus/blob/main/core/deployment/src/main/java/io/quarkus/deployment/steps/CombinedIndexBuildStep.java In short, the computing index is a composite of the original index (that you currently use) and a mutable index that produces ClassInfo objects on-demand, if they were not indexed yet. This is used on multiple places for this exact case -- classes from the JDK referred to by previously indexed classes (because the original index contains no JDK classes).

@Ladicek
Copy link
Contributor

Ladicek commented Sep 30, 2022

And we don't have to dismiss the PR. Your commit works as an optimization, and my commit actually fixes a method that previously wasn't aware of records.

@loicmathieu
Copy link
Contributor Author

OK, great.

I'll prepare a PR that switch to the computing index for Panache and make some test (this will be the hard part). I wonder if I should create an integration test running Java 17 with some records in it. I'll open a discussion in Zulip about this.

@Ladicek Ladicek added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Sep 30, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 30, 2022

Failing Jobs - Building 2453904

Status Name Step Failures Logs Raw logs
✔️ JVM Tests - JDK 11
✔️ JVM Tests - JDK 17
JVM Tests - JDK 17 MacOS M1 Set up runner ⚠️ Check → Logs Raw logs
✔️ JVM Tests - JDK 18

@loicmathieu
Copy link
Contributor Author

@holly-cummins this PR fails on the MacOS build very ealry, you may want to have a look.

As CI failres seems unrelated, I merge this one.

@loicmathieu loicmathieu removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Oct 3, 2022
@loicmathieu loicmathieu added this to the 2.14 - main milestone Oct 3, 2022
@loicmathieu loicmathieu merged commit 332843e into quarkusio:main Oct 3, 2022
@loicmathieu loicmathieu deleted the record-support branch October 3, 2022 10:42
@gsmet gsmet modified the milestones: 2.14 - main, 2.13.1.Final Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants