-
Notifications
You must be signed in to change notification settings - Fork 37.7k
C++20 std::views::reverse #28687
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
C++20 std::views::reverse #28687
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
cc @sipa you might have some insight here in regards to prevector. |
1cf6617
to
8ed1c24
Compare
8ed1c24
to
4eec99d
Compare
That is also required by |
4eec99d
to
95f9af8
Compare
Thx, rebased to include #28349 & updated PR description |
https://github.com/bitcoin/bitcoin/pull/28687/checks?check_run_id=19528202548 /usr/bin/ccache clang++-13 -stdlib=libc++ -std=c++20 -DHAVE_CONFIG_H -I. -I../src/config -fmacro-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu=. -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -DHAVE_BUILD_INFO -DPROVIDE_FUZZ_MAIN_FUNCTION -I. -I./minisketch/include -I./secp256k1/include -I./univalue/include -I./leveldb/include -isystem /ci_container_base/depends/x86_64-pc-linux-gnu/include -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_NO_CXX98_FUNCTION_BASE -isystem /ci_container_base/depends/x86_64-pc-linux-gnu/include -pthread -I/ci_container_base/depends/x86_64-pc-linux-gnu/include -I/ci_container_base/depends/x86_64-pc-linux-gnu/include/ -fdebug-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Werror -fvisibility=hidden -fPIE -pipe -std=c++20 -O2 -c -o libbitcoin_node_a-net_processing.o `test -f 'net_processing.cpp' || echo './'`net_processing.cpp
net_processing.cpp:2074:62: error: no member named 'reverse' in namespace 'std::views'
for (const uint256& hash : vHashes | std::views::reverse) {
~~~~~~~~~~~~^
net_processing.cpp:2760:69: error: no member named 'reverse' in namespace 'std::views'
for (const CBlockIndex *pindex : vToFetch | std::views::reverse) {
~~~~~~~~~~~~^
2 errors generated. Looks like ranges didn't become complete / non-experimental in LLVM until version 16: https://releases.llvm.org/16.0.0/projects/libcxx/docs/ReleaseNotes.html
Note that prior versions of LLVM required distros/venders to compile with special flags, so I assume it's just not going to be generally available until 16? i.e from the LLVM 14 release notes:
|
Hmm, there's no clang-16 in the current LTS release of Ubuntu, so I guess this will have to wait for some time. https://packages.ubuntu.com/jammy/clang-16 I wonder whether std::span will be usable, given that it internally assumes ranges? |
Interesting that the guix macOS build passed, given that it is on clang-15, no? |
I'd guess this is because our macOS SDK (libc++) is from Xcode 15, which is based on LLVM ~16, and includes support for ranges. So as long as clang-15 can compile it, which it should given vanilla LLVM supports the use of ranges (experimentally) in 15, it probably works. |
Oh, I guess clang-15 can use libc++-16, but not libstdc++, according to https://godbolt.org/z/dbKWeE8Te and llvm/llvm-project@babdef2 ? |
Though, on GHA it says XCode 14.3, see https://github.com/bitcoin/bitcoin/actions/runs/7171999335/job/19528203033?pr=28687#step:3:14
|
According to https://developer.apple.com/xcode/cpp/#c++20, "Ranges" have been available on macOS since Xcode 14.3. |
(Possibly?) fixed in #29275 |
Looks like it does, this compiles for me locally atleast: https://github.com/fanquake/bitcoin/tree/28687_29275. @stickies-v can you rebase this branch on top of #29275. |
de52629
to
f81565f
Compare
a7911f6
to
2d493d8
Compare
2d493d8
to
47539d3
Compare
With #30263 merged, this PR is now ready for review 🥳 |
Use std::ranges::views::reverse instead of the implementation in reverse_iterator.h, and remove it as it is no longer used.
47539d3
to
2925bd5
Compare
Force pushed to address merge conflict from #28052 |
ACK 2925bd5 |
ACK 2925bd5 🎷 Show signatureSignature:
|
Post-merge ACK 2925bd5 |
…ammy`) 1592a0f ci: update containers and CI to use Ubuntu 22.04 LTS (`jammy`) (Kittywhiskers Van Gogh) decbd05 ci: stop running `check-symbols` during builds (Kittywhiskers Van Gogh) Pull request description: ## Motivation While some aspects of C++20 are supported by GCC 9.3 (the version shipped with `focal`, [source](https://packages.ubuntu.com/focal/g++)), P0896R4 ("The One Ranges Proposal") is not ([source](https://en.cppreference.com/w/cpp/compiler_support)), required for moving away from [dash#4622](#4622) to adopt `std::ranges` and for backporting PRs like [bitcoin#28687](bitcoin#28687). They're supported from GCC 10.1 onwards ([source](https://stackoverflow.com/questions/56118941/do-we-have-c20-ranges-library-in-gcc-9/56118997#56118997)) and the next available LTS, `jammy`, currently ships with GCC 11.2 ([source](https://packages.ubuntu.com/jammy/g++)). As we're now using Guix to build our releases, there shouldn't be any adverse effects from our containers having a higher version of `glibc`. Additionally, upstream uses 24.04 (`noble`) for their build images ([source](https://github.com/bitcoin/bitcoin/blob/a2317e27b7fb86df4e32cd1674c06e09cb808248/ci/test/00_setup_env_native_tsan.sh#L10)) and `jammy` to determine the minimum version to CMake ([source](https://github.com/bitcoin/bitcoin/blob/a2317e27b7fb86df4e32cd1674c06e09cb808248/CMakeLists.txt#L5-L6)) (for reference, `focal` ships with CMake 3.16, [source](https://packages.ubuntu.com/focal/cmake)). ## Additional Information * Builds will no longer run `check-symbols` (and the option to do so, `RUN_SYMBOL_TESTS` has been removed) as portable builds (builds expected for distributions) are built with Guix, which pins its version of `glibc` ([source](https://github.com/dashpay/dash/blob/396573d09cff5c65b2e3b4ba965185ac532b8b5c/contrib/guix/manifest.scm#L152), currently 2.28), runs `check-symbols` ([source](https://github.com/dashpay/dash/blob/396573d09cff5c65b2e3b4ba965185ac532b8b5c/contrib/guix/libexec/build.sh#L304-L305)), which in turn make sure that it doesn't contain symbols expected in versions higher than `glibc` 2.31 ([source](https://github.com/dashpay/dash/blob/396573d09cff5c65b2e3b4ba965185ac532b8b5c/contrib/devtools/symbol-check.py#L38-L42)). Upstream does not use `check-symbols` during their builds nor do we have a reason to (as we no longer using Gitian). * CI build failures w.r.t. `pthread_yield` ([build](https://github.com/dashpay/dash/actions/runs/11645989968/job/32437272177?pr=6379#step:7:3136), [build](https://github.com/dashpay/dash/actions/runs/11645989968/job/32430165640#step:7:3157)) should be resolved by rebuilding `bdb4` (see [bitcoin#26423](bitcoin#26423 (comment))). This problem has only been observed on GitHub CI and locally (the latter resolved by rebuilding depends, I use a separate target triple for testing, `x86_64-jammy-linux-gnu`), GitLab CI has not observed such failures ([build](https://gitlab.com/dashpay/dash/-/jobs/8253943710)). ## Breaking changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)** - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 1592a0f knst: utACK 1592a0f PastaPastaPasta: utACK 1592a0f Tree-SHA512: cbe6505211246c711dc0fd8645b8a4c6123b5ac163341dca4c686f8905a630c57d483a91a6e29bd9e23bac79d774e339181d2cb17bb3affeb5902e5f548ffa54
, bitcoin#29181, bitcoin#29085, bitcoin#29484, bitcoin#29577, bitcoin#29081, bitcoin#29815, bitcoin#28687, bitcoin#31502, partial bitcoin#26707, bitcoin#28894 (c++20 backports: part 2) 2867107 merge bitcoin#31502: Fix CXXFLAGS on NetBSD (Kittywhiskers Van Gogh) 83e8ff0 merge bitcoin#28687: std::views::reverse (Kittywhiskers Van Gogh) 525bf6f merge bitcoin#29815: always use our fallback timingsafe_bcmp rather than libc's (Kittywhiskers Van Gogh) 42aa57a merge bitcoin#29081: Remove gmtime* (Kittywhiskers Van Gogh) d5179ec refactor: move away from `gmtime` (Kittywhiskers Van Gogh) 3a71354 merge bitcoin#29577: ignore deprecated-declarations warnings in objc++ macOS code (Kittywhiskers Van Gogh) 74bcdf0 merge bitcoin#29484: replace char-is-int8_t autoconf detection with c++20 concept (Kittywhiskers Van Gogh) e317a5c merge bitcoin#29085: Use std::rotl (Kittywhiskers Van Gogh) 9f2c278 merge bitcoin#29181: remove systemtap variadic patch (Kittywhiskers Van Gogh) 209488d merge bitcoin#29040: Remove pre-C++20 code, fs::path cleanup (Kittywhiskers Van Gogh) e2eb625 partial bitcoin#28894: batch all individual spkms setup db writes in a single db txn (Kittywhiskers Van Gogh) f29610b partial bitcoin#26707: Fix `performance-*move*` warnings in headers (Kittywhiskers Van Gogh) ee63d4b merge bitcoin#24470: Disallow more unsafe string->path conversions allowed by path append operators (Kittywhiskers Van Gogh) abfd303 merge bitcoin#24469: Correctly decode UTF-8 literal string paths (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Depends on #6378 ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 2867107 UdjinM6: utACK 2867107 Tree-SHA512: 9ade297d5078063229c297036c36ba2fd82eb0ffc15124d746564844315b6ed9d86f38ddc0f4e9f00e12f8d5eeeb6248c2a86b65a7bee856a234071e1546cf40
C++20 introduces
std::ranges::views::reverse
, which allows us to drop our ownreverse_iterator.h
implementation and also makes it easier to chain views (even though I think we currently don't use this).