-
Notifications
You must be signed in to change notification settings - Fork 29
Add isQuotable attribute to LambdaOp #545
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 mabbay! A progress list of the required criteria for merging this PR into |
@mabbay 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java
Outdated
Show resolved
Hide resolved
src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java
Outdated
Show resolved
Hide resolved
static LambdaOp create(ExternalizedOp def) { | ||
boolean isQuotable = def.extractAttributeValue(ATTRIBUTE_LAMBDA_IS_QUOTABLE, | ||
false, v -> switch (v) { | ||
case Boolean b -> b; |
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.
Can we use the boolean
primitive type?
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.
It's a preview feature
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 should be able to use preview features as the jdk.incubator.code
module is annotated with @ParticipatesInPreview
, unless there is some odd restriction when javac calls code in the incubating module?
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.
Paul, there is no real difference at runtime betwen case Boolean and case boolean when you switch on an Object, case boolean just bloat the bytecode a little more.
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 thinking more subjectively, more clearly indicating the pattern variable cannot be null (i realize the case null, default
is also present).
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.
Conceptually, a case Foo is like an instanceof Foo, it does not match 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.
I recall @ParticipatesInPreview
only works for preview APIs instead of language features that ClassFile API needed custom backdoors from the JDK. See https://bugs.openjdk.org/browse/JDK-8308093.
src/jdk.incubator.code/share/classes/jdk/incubator/code/bytecode/BytecodeLift.java
Outdated
Show resolved
Hide resolved
src/jdk.incubator.code/share/classes/jdk/incubator/code/bytecode/BytecodeLift.java
Show resolved
Hide resolved
The change in this PR looks good. But, I'd like to remind ourselves that we have probably several issues when it comes to dealing with lambda expressions. There are a bunch of reasons where javac wants to use the
An example of (3) is as follows:
In the above example javac will ask the While there's things we can do to detect (1) and (2), I think the kind of analysis required for (3) is rather difficult, and compile-dependent: And I'm quite skeptical we can reproduce this at runtime (as the runtime capabilities to detect overriding based on source-level types are rather limited). So, more generally, I think both |
I tried something like this:
This (surprisingly) seems to work. I believe the reason is that
So, this special "fallback overrides" end up saving the day in this case. However, a similar example using
The error I see is:
Which is kind of expected: the generated instance is missing a bridge (as it's generated via regular metafactory). |
@mcimadamore good points. Complete reverse engineering is hard. I also suspected that the bytecode generator does not produce correct bytecode behaviour for these cases, and i don't know if there is sufficient information held by the lambda op instance in these cases to generate the bytecode. Fixing both the generator and lifter together is important. |
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.
In a follow on PR we could adjust the lifter to throw a friendlier error for flags related to serialization and bridges.
So... one thing I was positively surprised about was that, even after some extensive poking, To me, this suggests that we might be able to do something similar in With respect to the other issues I enumerated, my feeling is that what's missing from |
/integrate |
Going to push as commit d276cba. |
In the
interpreter
andByteCodeGenerator
we detect if a lambda is quotable based on its functional interface. This approach will not work if intersection type is used e.g.Runnable r = (Runnable & Quotable) () -> {};
This PR adds a flag to LambdaOp that will be set by thejavac
for quotable lambdas.Progress
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/545/head:pull/545
$ git checkout pull/545
Update a local copy of the PR:
$ git checkout pull/545
$ git pull https://git.openjdk.org/babylon.git pull/545/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 545
View PR using the GUI difftool:
$ git pr show -t 545
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/545.diff
Using Webrev
Link to Webrev Comment