-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8304283: Modernize the switch statements in jdk.internal.foreign #13047
Conversation
👋 Welcome back pminborg! A progress list of the required criteria for merging this PR into |
Webrevs
|
); | ||
static boolean isUnbox(Binding binding) { | ||
return switch (binding) { | ||
case Binding.VMStore unused -> true; |
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 wonder... here it might be better to capture the box/unbox nature of a binding in a virtual method in the binding class? E.g. isBox(), isUnbox() ?
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 prefer this approach, to be honest, since the logic for all the different binding operators is in one place. It gives an overview of which operators are expected in an unboxing recipe. Making them virtual methods would put quite a bit of visual distance between the different true
/false
values.
I've been through the Binding file quite a bit, and the amount of scrolling/searching needed to find a particular implementation is kind of annoying.
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.
To pull on that string some more. I think we should move the implementations of various Binding::verify methods here, or perhaps into a separate BindingVerifier class.
Ditto for the Binding::interpret implementations. They could be moved to BindingInterpreter. The Binding class would just be left as a simple bag of records + documentation for each operator.
The main motivation for this would be that, right now, if you're looking at e.g. interpretation in Binding
, there's a lot of noise that you have to filter through. I think it makes more sense to group these things into classes (for specialization/verification/interpretation), where all the code in a class is logically related.
return flatten(sequenceLayout.elementLayout()).mul(elementCount); | ||
} else { | ||
throw new IllegalStateException("Cannot get here: " + layout); | ||
case null, default -> throw new IllegalStateException("Cannot get here: " + layout); |
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.
Since the default throws, and the switch w/o a case null
also throws, do we need the case null
here?
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.
No. Null is not needed. I will remove it.
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.
Overall looks good. I've added a couple of optional comments for your consideration.
@minborg 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 10 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 ➡️ To integrate this PR with the above commit message to the |
); | ||
static boolean isUnbox(Binding binding) { | ||
return switch (binding) { | ||
case Binding.VMStore unused -> true; |
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 prefer this approach, to be honest, since the logic for all the different binding operators is in one place. It gives an overview of which operators are expected in an unboxing recipe. Making them virtual methods would put quite a bit of visual distance between the different true
/false
values.
I've been through the Binding file quite a bit, and the amount of scrolling/searching needed to find a particular implementation is kind of annoying.
static boolean isUnbox(Binding binding) { | ||
return switch (binding) { | ||
case Binding.VMStore unused -> true; | ||
case Binding.VMLoad unused -> false; | ||
case Binding.BufferStore unused -> false; | ||
case Binding.BufferLoad unused -> true; | ||
case Binding.Copy unused -> true; | ||
case Binding.Allocate unused -> false; | ||
case Binding.BoxAddress unused -> false; | ||
case Binding.UnboxAddress unused -> true; | ||
case Binding.Dup unused -> true; | ||
case Binding.Cast unused-> true; | ||
}; | ||
} |
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'd go a bit further here and visually organize the cases as well. Also, using a static import for Binding.*
:
static boolean isUnbox(Binding binding) { | |
return switch (binding) { | |
case Binding.VMStore unused -> true; | |
case Binding.VMLoad unused -> false; | |
case Binding.BufferStore unused -> false; | |
case Binding.BufferLoad unused -> true; | |
case Binding.Copy unused -> true; | |
case Binding.Allocate unused -> false; | |
case Binding.BoxAddress unused -> false; | |
case Binding.UnboxAddress unused -> true; | |
case Binding.Dup unused -> true; | |
case Binding.Cast unused-> true; | |
}; | |
} | |
static boolean isUnbox(Binding binding) { | |
return switch (binding) { | |
case VMStore unused -> true; | |
case BufferLoad unused -> true; | |
case Copy unused -> true; | |
case UnboxAddress unused -> true; | |
case Dup unused -> true; | |
case Cast unused -> true; | |
case VMLoad unused -> false; | |
case BufferStore unused -> false; | |
case Allocate unused -> false; | |
case BoxAddress unused -> false; | |
}; | |
} |
It's a bit unfortunate that we need variable names as well.
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.
While I agree that some "visitor" methods would be better dealt with using patterns, I remain unconvinced about the box/unbox classification being modeled as an "operation". That's because it's a static property of the binding - e.g. given a binding you know whether it can be used for box/unbox/both/none. If this was an enum, I would encode it as a boolean field and never look back. Also note how the javadoc for Binding itself makes quite a lot of comments on box/unbox nature of bindings, and how they can have different semantics depending on the direction. To me it feels like that distinction is a first class citizen in Binding.
Perhaps, pulling together the various strings, it would maybe possible to define very simple records for the various bindings, with no verification and interpretation code (e.g. leave that to some pattern-based visitor somewhere else). But I think I would still expect a binding class to know whether it's used for unbox or not w/o having to run a complex operation all the time (given that the property is a constant of the binding class). The fact that we're using records for bindings and we can't have an abstract class also biases the decision a bit (otherwise we could simply use a bunch of constructor parameters to encode the box/unbox properties).
That said, this is all subjective. I don't have super strong opinion on this. The code above looks a tad odd to me, but I can live with it.
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've spoken to the Amber persons and soon we will be able to do:
static boolean isBox(Binding binding) {
return switch (binding) {
case VMLoad _,
Copy _,
Allocate _,
BoxAddress _,
BufferStore _,
Dup _,
Cast _-> true;
case VMStore _,
BufferLoad _,
UnboxAddress _ -> false;
};
}
); | ||
static boolean isUnbox(Binding binding) { | ||
return switch (binding) { | ||
case Binding.VMStore unused -> true; |
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.
To pull on that string some more. I think we should move the implementations of various Binding::verify methods here, or perhaps into a separate BindingVerifier class.
Ditto for the Binding::interpret implementations. They could be moved to BindingInterpreter. The Binding class would just be left as a simple bag of records + documentation for each operator.
The main motivation for this would be that, right now, if you're looking at e.g. interpretation in Binding
, there's a lot of noise that you have to filter through. I think it makes more sense to group these things into classes (for specialization/verification/interpretation), where all the code in a class is logically related.
/integrate |
Going to push as commit dfc7214.
Your commit was automatically rebased without conflicts. |
This PR proposes changing old-type switch statements to newer forms of switch.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/13047/head:pull/13047
$ git checkout pull/13047
Update a local copy of the PR:
$ git checkout pull/13047
$ git pull https://git.openjdk.org/jdk pull/13047/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 13047
View PR using the GUI difftool:
$ git pr show -t 13047
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13047.diff