p4c
p4c copied to clipboard
Replace boost constructs with their C++17 STL equivalents
Inspired by https://github.com/ethereum/solidity/issues/7259. Now that we have C++17 support there is some boost code we can remove. The less boost we have, the better. For now, this can apply:
- [x] changing
boost::regex
tostd::regex
- [x] changing
boost::optional
tostd::optional
- [x] changing
boost::variant
tostd::variant
- [x] changing
boost::filesystem
tostd::filesystem
- [ ] using https://github.com/boostorg/random for P4Testgen
- [ ] using https://github.com/boostorg/multiprecision
- [ ] using https://github.com/boostorg/format
- [ ] replacing
boost::fmt
with fmt
changing boost::filesystem to std::filesystem
I assume we already require GCC 9 ...
I assume we already require GCC 9 ...
Not quite sure what you mean by that? GCC 9 should support std::filesystem, no?
I assume we already require GCC 9 ...
Not quite sure what you mean by that? GCC 9 should support std::filesystem, no?
Before GCC 9, std::filesystem was not included in libstdc++ but rather its own library.
Before GCC 9, std::filesystem was not included in libstdc++ but rather its own library.
I see, but here we should be good, right? The only problem I see is clang and MacOS, I do not know about the level of support there.
changing boost::regex to std::regex
I'm wondering if this is a good idea. The std::regex
implementation in libstdc++ is quite widely considered to be bad and slow with no chances of fixing it without an ABI break which is opposed by many in the C++ community. I wonder how does boost::regex
compare to std::regex
and if it is even worth replacing it. If we could get rid of all of boost
then yes, but we can't do that.
For the other cases I agree, the std::
versions are probably even better than boost once. I just hope there are no parts in boost that were not standardised and we use.
It looks like the open-source code does not even use boost::regex. So we may not have to worry about this particular replacement.
Some additional bits here sans boost::format
and boost::multiprecision
:
- [x] control-plane/p4RuntimeSymbolTable.cpp uses
boost::split
andboost::adaptors::reverse
. We can readily replace the latter withiterator_range
. And the first... well, if abseil would be a dependency, we can useStrSplit
from there. - [ ] graph backend uses boost::graph. Looks like a hard dependency to me
- [ ] backends/p4tools/common/lib/model.h uses
boost::container::flat_map
. Need to re-examine if this is needed. - [ ] backends/p4tools/common/lib/util.{cpp, h} uses
boost::random::mt19937
=> replace with<random>
- [ ] frontends/parsers/parserDriver.cpp uses
boost::iostreams
, but has an alternative implementation - [x] frontends/p4/def_use.cpp uses
boost::hash_range
=> replace withUtil::Hash
- [ ] ir/solver.h uses
boost::container::flat_map
- [x] test/gtest/ uses
boost::replace_first
- [x] frontends/p4/typeChecking/typeConstraints.h uses
boost::split
For boost::container::flat_map
dependency I'd rather pull small header-only thing into lib
. I believe I even had some implementation somewhere.
- We can replace the flat maps with custom maps or Abseil maps whatever direction we go.
- The random library may be required because the standard library does not have good support for arbitrary bit-width integers if I recall correctly. But it is also a module which we can make specific to P4Testgen: https://github.com/boostorg/random
- The hard dependency for graphs is okay since that back end is optional.
- iostreams we should get rid of, if we can. Not sure what that entails.
- It looks like some of the other dependencies could be substituted with helpers or equivalent Abseil helpers.
Feel free to edit the top-level comment todo list. I will also try to add your points later.
It looks like the open-source code does not even use boost::regex. So we may not have to worry about this particular replacement.
And for downstream you might try re2
@fruffy I might have some spare time today, do you want me to replace boost string stuff with their abseil equivalents?
That would be very welcome! Which boost string things concretely?
That would be very welcome! Which boost string things concretely?
I believe it's mostly split
. See https://github.com/p4lang/p4c/issues/3898#issuecomment-1961731053
Sounds good to me.
@fruffy abseil contains absl::BitGen
/ absl::InsecureBitGen
. Maybe worth exploring as a replacement for boost::random
See https://abseil.io/docs/cpp/guides/random and https://abseil.io/about/design/random