-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Rewrite expressions module with Java 24 classfile API #14597
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
Rewrite expressions module with Java 24 classfile API #14597
Conversation
dweiss
left a comment
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.
Pretty cool.
rjernst
left a comment
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 great! It seems like ASM translated relatively well (in this case) to the ClassFile API (much of it was just changing imports/methods to call but looks very similar).
…od describeConstable(). For normal types the optional can never be empty
jdconrad
left a comment
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.
LGTM! I appreciate the fairly direct replacement as the first step since it made it so easy to review.
rmuir
left a comment
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 great! also, I trust the tests here have good coverage. Thank you for doing this.
…; wrap ParseExceptions using helper method
The hard part was more to understand and figure out how it works. After that transforming the Antlr visitor to Classfile API was trivial. Very hard was that I was unable to figure out how to get a lucene/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java Line 436 in 938be2a
There are still some nice goodies missing in Classfile API:
|
For the fun of it, I asked chatgpt to do it. Uwe - you're still much, much better. :) |
|
lol the day we have an army of Uwe AIs, I feel like I've already seen this movie |
|
Uncanny resemblance! |
…fficial documentation of classfile API recommends (#14597)
|
I made a small followup commit to make usage more like recommended by Classfile API docs: e2d0685 |
|
Finally here is an example Classfile output with this PR for this code: public void testNamespacesWithoutDirectMH() throws Exception {
Map<String, MethodHandle> functions =
Map.of(
"foo.bar",
MethodHandles.constant(double.class, 9),
"bar.foo",
MethodHandles.identity(double.class));
Expression expr = compile("foo.bar() + bar.foo(7)", functions);
assertEquals(16, expr.evaluate(null), DELTA);
}The previous version as generated by the old code in branch_10x is: This is the same code, all operators are identical. Only differences in constant pool. The changes here are only the class flags no longer having obsolete Theres a slight difference in the try/catch. The old version was a bit incorrect, because the |
|
I made some followup changes here: #14602 |

First step in getting rid of ASM dependency:
Java 24 added the classfile API (https://openjdk.org/jeps/484) in non-preview mode. This allows to generate class files with a builder-based API (unfurtunately its is not the usual ASM visitor desaster, it is more a lambda-inside-lambda desaster).
This PR removes the license files and all ASM dependencies from runtime code (and module descriptors). The code was rewritten. The rewrite may not yet be the most elegant lambda-way to make it, but the PR is easier to review with not so many changes and reshuffled code.
We still have ASM core as a dependncy for Gradle's APIJAR generator, but this one can also be removed soon.