-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8367536: Change RBTree to use C++17 features #27260
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back cnorrbin! A progress list of the required criteria for merging this PR into |
@caspernorrbin 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 114 new commits pushed to the
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. ➡️ To integrate this PR with the above commit message to the |
@caspernorrbin The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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 good.
template <typename CMP> | ||
static constexpr bool HasKeyComparator = has_cmp_type<CMP, RBTreeOrdering, K, K>::value; | ||
static constexpr bool HasKeyComparator = | ||
std::is_invocable_r_v<RBTreeOrdering, decltype(&CMP::cmp), K, K>; |
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.
Note that these are static data member templates, which were not permitted by the style
guide until about an hour ago. :)
Thank you both for reviewing! There seems to be a bug in older versions of gcc with partial template specialization of constexpr inside classes. This makes GHA fail on linux since it uses that older version, but works fine on newer versions or other platforms. I think the correct solutions is to make some changes to I have turned that back into a struct with |
Well that's annoying. Good job tracking down the issue. This looks like a relatively narrow bug, only affecting static data member Sorry I seem to have not explicitly tested for this case when I proposed We could add a note to the style guide about it, though I'm reluctant to Maybe leave a comment with |
Thank you for the comment. It's unfortunate that such a bug exists, and that we had to encounter it almost immediately. I can definitely understand why it wasn't caught though. Seeing as it is pretty niche, I agree it shouldn't be added to the style guide at this time, perhaps in the future if it were to become a (somewhat) regular problem. Nevertheless, I pushed an update to document the issue (with the GCC PR ID) in the code along with changing the struct name to |
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 good.
struct has_less_than_type : std::false_type {}; | ||
template <typename CMP, typename RET, typename ARG1, typename ARG2> | ||
struct has_less_than_type<CMP, RET, ARG1, ARG2, decltype(static_cast<RET(*)(ARG1, ARG2)>(CMP::less), void())> : std::true_type {}; | ||
// Due to a bug in older GCC versions with static templeted constexpr data members (see GCC PR 71954), |
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.
templeted -> templated
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.
Still good.
Hi everyone,
C++17 lets us tidy up som of the ugly templating done in the red-black tree. We can replace the
std::false_type
/std::true_type
tricks used to discover comparator and verifier signatures with the newstd::is_invocable(_r_v)
, and most of the overload/SFINAE noise can disappear thanks toif constexpr
.We can now write one-liners such as:
and then select the right branch with
inside a single function instead of having several
ENABLE_IF
overloads.This results in fewer lines, clearer intent, and more readable errors, while keeping behaviour identical.
Testing:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27260/head:pull/27260
$ git checkout pull/27260
Update a local copy of the PR:
$ git checkout pull/27260
$ git pull https://git.openjdk.org/jdk.git pull/27260/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27260
View PR using the GUI difftool:
$ git pr show -t 27260
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27260.diff
Using Webrev
Link to Webrev Comment