Modernize Codebase Using C++20 Features#5127
Modernize Codebase Using C++20 Features#5127drebelsky wants to merge 6 commits intostellar:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the codebase to use C++20 features, replacing older C++ patterns with cleaner modern equivalents. The changes include migrating from SFINAE to concepts, adopting __VA_OPT__ for variadic macros, and leveraging C++20's heterogeneous lookup capabilities. Several third-party dependencies and the build system have been updated to support C++20.
Changes:
- Replaced SFINAE
std::enable_ifwith C++20 concepts throughout the codebase - Replaced
BUCKET_TYPE_ASSERTmacro withIsBucketTypeconcept - Simplified
InternalContractDataMapimplementation using heterogeneous lookup - Updated logging macros to use
__VA_OPT__instead of##__VA_ARGS__
Reviewed changes
Copilot reviewed 70 out of 70 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| configure.ac, README.md, INSTALL.md | Updated to require C++20 |
| src/util/Logging.h | Replaced ##__VA_ARGS__ with __VA_OPT__ in logging macros |
| src/bucket/BucketUtils.h | Replaced BUCKET_TYPE_ASSERT macro with IsBucketType concept |
| src/bucket/BucketBase.h | Removed IndexT template parameter from BucketBase |
| src/ledger/InMemorySorobanState.h | Simplified to use std::unordered_set with heterogeneous lookup |
| src/util/XDROperators.h | Replaced operator< with operator<=> |
| src/herder/test/HerderTests.cpp | Fixed typo in function name and added test cases |
| lib/xdrpp, lib/spdlog, lib/fmt | Updated submodule commits |
Comments suppressed due to low confidence (1)
src/util/Logging.cpp:1
- The change from
fmt::localtime(time)to*std::localtime(&time)should be documented. The latter uses raw pointers and direct dereferencing which could be problematic ifstd::localtimereturns nullptr (which can happen). Consider adding a comment explaining why this change was necessary or add a null check.
7027ae2 to
9eb56b9
Compare
bboston7
left a comment
There was a problem hiding this comment.
I think this is close. Just a few small things I noticed.
|
|
||
| template <class BucketT> void count(typename BucketT::EntryT const& be); | ||
| template <IsBucketType BucketT> | ||
| void count(typename BucketT::EntryT const& be); |
There was a problem hiding this comment.
This is as close as I could get this comment to the real thing I'd like to comment on: Should isBucketMetaEntry and bucketEntryToLedgerEntryAndDurabilityType also use IsBucketType? Looks like they're the only two places left that use class BucketT.
| // We use a template on this to avoid needing SecretKey's declaration to be | ||
| // visible in this file | ||
| template <IsKeyType T> | ||
| requires std::same_as<T, SecretKey> | ||
| SecretValue |
There was a problem hiding this comment.
I found this pretty confusing on first glance. I suspect it will become more obvious as we get more used to C++20, but could you please add a comment explaining that C++20s subsumption rules mean that this function will be called when T is a SecretKey because C++20 always picks the most specific matching constraint? That is, there is no ambiguity even though the other toStrKey's constraint also technically matches. The same goes for toShortString.
| // which map it could belong in, so check both. | ||
| auto dataIt = | ||
| mContractDataEntries.find(InternalContractDataMapEntry(ledgerKey)); | ||
| auto dataIt = mContractDataEntries.find(ledgerKey); |
There was a problem hiding this comment.
Another comment for an unrelated spot in the code: Line 339 has a comment that says "InternalContractDataMapEntry has an explicit copy constructor that deep-copies via clone(), so we can just use emplace," but I don't think that's true anymore. Is it OK that we're no longer making a deep copy there?
| } | ||
|
|
||
| // This messy template makes is such that this function is only defined | ||
| // This concept template makes is such that this function is only defined |
There was a problem hiding this comment.
| // This concept template makes is such that this function is only defined | |
| // This concept template makes it such that this function is only defined |
Based on #5091. Clean up codebase using C++20 features, resolves #4673.
BUCKET_TYPE_ASSERTwithIsBucketTypeconcept__VA_OPT__instead of##__VA_ARGS__IndexTtemplate parameter fromBucketBaseInternalContractDataMapimplementation withstd::unordered_setheterogenous lookupThis doesn't actually check for POD types (trivial + standard-layout), so the concept retains a
std::is_arithmeticcheck.Footnotes
There were some places that I left.
src/test/Catch2.h:47:
struct StringMaker<T, std::enable_if_t<xdr::xdr_traits<T>::valid>>because Catch2 still uses SFINAE
Leaving
XDRCereal.h/XDRCereal.cppbecause I'm working on a separate PR to update it.Leaving
FuzzerImpl.cppalone since iirc Graydon was working on fuzzing. ↩Note on the update to
src/util/BufferedAsioCerealOutputArchive.h↩