Skip to content

Commit

Permalink
Ditch abseil, use Boost instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Oct 13, 2024
1 parent 313b271 commit 24e7209
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 241 deletions.
17 changes: 2 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,9 @@ if(${mp++_VERSION} VERSION_LESS ${_OBAKE_MIN_MPPP_VERSION})
message(FATAL_ERROR "The minimum mp++ version required by obake is ${_OBAKE_MIN_MPPP_VERSION}, but version ${mp++_VERSION} was found instead.")
endif()

# abseil.
find_package(absl REQUIRED)

# Boost setup.
# NOTE: stacktrace available since 1.65.0.
set(_OBAKE_MIN_BOOST_VERSION "1.69")
# NOTE: need 1.81 for unordered_flat_set.
set(_OBAKE_MIN_BOOST_VERSION "1.81")
# NOTE: we look for Boost in CONFIG mode first, as that has become the official supported way
# of locating Boost in recent Boost/CMake versions. If we fail, we try again in
# MODULE mode as last resort.
Expand Down Expand Up @@ -307,7 +304,6 @@ if(YACMA_COMPILER_IS_MSVC)
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_tex_stream_insert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_trim.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_trim_identify.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/abseil.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/atomic_flag_array.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/atomic_lock_guard.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/fcast.hpp"
Expand Down Expand Up @@ -360,13 +356,6 @@ target_compile_options(obake PRIVATE
target_compile_features(obake PUBLIC cxx_std_20)
# Ensure vanilla C++ is being used.
set_property(TARGET obake PROPERTY CXX_EXTENSIONS NO)
if(YACMA_COMPILER_IS_MSVC)
# NOTE: older abseil versions have a problem on MSVC
# when using C++20:
# https://github.com/abseil/abseil-cpp/issues/649
# Hopefully we can eventually remove this.
target_compile_definitions(obake PUBLIC -D_HAS_DEPRECATED_RESULT_OF=1)
endif()
if(YACMA_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10")
# GCC < 10 still needs the -fconcepts flag, even if C++20 is in use.
message(STATUS "Activating the '-fconcepts' flag for GCC < 10.")
Expand All @@ -383,8 +372,6 @@ target_include_directories(obake PUBLIC
target_link_libraries(obake PUBLIC
Threads::Threads
mp++::mp++
absl::flat_hash_map
absl::flat_hash_set
Boost::boost
Boost::serialization
Boost::disable_autolinking
Expand Down
3 changes: 1 addition & 2 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Requirements
Currently, obake has the following mandatory dependencies:

* the `mp++ <https://bluescarni.github.io/mppp/>`_ multiprecision library (at least version 0.27),
* the `Boost <https://www.boost.org/>`_ C++ libraries (at least version 1.65),
* the `Abseil <https://abseil.io/>`_ C++ libraries,
* the `Boost <https://www.boost.org/>`_ C++ libraries (at least version 1.81),
* the `Intel TBB <https://github.com/oneapi-src/oneTBB>`__ library,
* the `{fmt} <https://fmt.dev/latest/index.html>`__ library.

Expand Down
37 changes: 0 additions & 37 deletions include/obake/detail/abseil.hpp

This file was deleted.

253 changes: 117 additions & 136 deletions include/obake/polynomials/polynomial.hpp

Large diffs are not rendered by default.

57 changes: 11 additions & 46 deletions include/obake/series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <boost/iterator/transform_iterator.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/unordered/unordered_flat_map.hpp>

#include <fmt/core.h>

Expand All @@ -50,7 +51,6 @@
#include <obake/cf/cf_stream_insert.hpp>
#include <obake/cf/cf_tex_stream_insert.hpp>
#include <obake/config.hpp>
#include <obake/detail/abseil.hpp>
#include <obake/detail/fcast.hpp>
#include <obake/detail/fmt_compat.hpp>
#include <obake/detail/ignore.hpp>
Expand Down Expand Up @@ -483,39 +483,12 @@ concept SeriesConvertible = is_series_convertible_v<T, C>;
namespace detail
{

// A small hashing wrapper for keys. It accomplishes two tasks:
// - force the evaluation of a key through const reference,
// so that, in the Key requirements, we can request hashability
// through const lvalue ref;
// - provide additional mixing.
// Wrapper to force key hashing via const lvalue refs.
struct series_key_hasher {
// NOTE: here we are duplicating a bit of internal
// abseil code for integral hash mixing, with the intent
// of avoiding the per-process seeding that abseil does.
// See here for the original code:
// https://github.com/abseil/abseil-cpp/blob/37dd2562ec830d547a1524bb306be313ac3f2556/absl/hash/internal/hash.h#L754
// If/when abseil starts supporting DLL builds, we can
// remove this code and switch back to using abseil's
// own hash machinery for mixing.
static constexpr ::std::uint64_t kMul
= sizeof(::std::size_t) == 4u ? ::std::uint64_t{0xcc9e2d51ull} : ::std::uint64_t{0x9ddfea08eb382d69ull};
ABSL_ATTRIBUTE_ALWAYS_INLINE static ::std::uint64_t Mix(::std::uint64_t state, ::std::uint64_t v)
{
using MultType = ::std::conditional_t<sizeof(::std::size_t) == 4u, ::std::uint64_t, ::absl::uint128>;
// We do the addition in 64-bit space to make sure the 128-bit
// multiplication is fast. If we were to do it as MultType the compiler has
// to assume that the high word is non-zero and needs to perform 2
// multiplications instead of one.
MultType m = state + v;
m *= kMul;
return static_cast<::std::uint64_t>(m ^ (m >> (sizeof(m) * 8 / 2)));
}
template <typename K>
::std::size_t operator()(const K &k) const noexcept(noexcept(::obake::hash(k)))
{
// NOTE: mix with a compile-time seed.
return static_cast<::std::size_t>(
series_key_hasher::Mix(15124392053943080205ull, static_cast<::std::uint64_t>(::obake::hash(k))));
return ::obake::hash(k);
}
};

Expand Down Expand Up @@ -661,7 +634,8 @@ class series

public:
// Define the table type, and the type holding the set of tables (i.e., the segmented table).
using table_type = ::absl::flat_hash_map<K, C, detail::series_key_hasher, detail::series_key_comparer>;
using table_type
= ::boost::unordered::unordered_flat_map<K, C, detail::series_key_hasher, detail::series_key_comparer>;
using s_table_type = ::boost::container::small_vector<table_type, 1>;

// Shortcut for the segmented table size type.
Expand Down Expand Up @@ -1518,11 +1492,6 @@ class series
// - the original table had no incompatible keys,
// - the original table did not overflow the max size,
// - the original table had only unique keys.
// Note that deserialisation of a series that was saved
// in a previous program execution will result in a term
// order different from the original one due to abseil's salting,
// but the number of terms in a specific table will be the same
// because the first level hash is not salted.
// NOTE: this is essentially identical to a straight emplace_back()
// on the table, just with some added assertions.
detail::series_add_term_table<true, detail::sat_check_zero::off, detail::sat_check_compat_key::off,
Expand Down Expand Up @@ -1954,10 +1923,8 @@ struct series_default_byte_size_impl {
ret += ::obake::byte_size(k) + ::obake::byte_size(c) + (sizeof(series_term_t<T>) - (sizeof(k) + sizeof(c)));
}

// Add the space occupied by the unused slots.
assert(tab.capacity() >= tab.size());
ret += (tab.capacity() - tab.size()) * sizeof(series_term_t<T>);

// NOTE: here we are not accounting for the empty slots in the table.
// Hopefully we do not end up very far from the true memory utilisation.
return ret;
}
template <typename T>
Expand Down Expand Up @@ -3346,8 +3313,7 @@ inline series_default_div_ret_t<T &&, U &&> series_default_div_impl(T &&x, U &&y
c /= ::std::as_const(y);

if (obake_unlikely(::obake::is_zero(::std::as_const(c)))) {
// NOTE: abseil's flat_hash_map returns void on erase(),
// thus we need to increase 'it' before possibly erasing.
// NOTE: increase 'it' before erasing.
// erase() does not cause rehash and thus will not invalidate
// any other iterator apart from the one being erased.
t.erase(it++);
Expand Down Expand Up @@ -4288,13 +4254,12 @@ inline void filter_impl(series<K, C, Tag> &s, const F &f)
const auto it_f = table.end();

for (auto it = table.begin(); it != it_f;) {
// NOTE: abseil's flat_hash_map returns void on erase(),
// thus we need to increase 'it' before possibly erasing.
// erase() does not cause rehash and thus will not invalidate
// any other iterator apart from the one being erased.
if (f(::std::as_const(*it))) {
++it;
} else {
// NOTE: increase 'it' before erasing.
// erase() does not cause rehash and thus will not invalidate
// any other iterator apart from the one being erased.
table.erase(it++);
}
}
Expand Down
1 change: 0 additions & 1 deletion obake-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ find_package(mp++ REQUIRED)
if(${mp++_VERSION} VERSION_LESS @_OBAKE_MIN_MPPP_VERSION@)
message(FATAL_ERROR "The minimum mp++ version required by obake is @_OBAKE_MIN_MPPP_VERSION@, but version ${mp++_VERSION} was found instead.")
endif()
find_package(absl REQUIRED)
# TBB. Try to find it first in config mode (supported
# since version 2021 after the oneTBB rename), and, if this
# fails, fall back to our own FindTBB.cmake. This is of course
Expand Down
2 changes: 1 addition & 1 deletion tools/conda_asan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export deps_dir=$HOME/local
export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
conda create -y -p $deps_dir cmake c-compiler cxx-compiler fmt backtrace mppp \
libboost-devel libabseil tbb-devel ninja
libboost-devel tbb-devel ninja
source activate $deps_dir

# Create the build dir and cd into it.
Expand Down
2 changes: 1 addition & 1 deletion tools/conda_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
conda config --add channels conda-forge
conda config --set channel_priority strict
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel abseil-cpp backtrace fmt"
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel backtrace fmt"
conda create -q -p $deps_dir -y $conda_pkgs
source activate $deps_dir

Expand Down
2 changes: 1 addition & 1 deletion tools/conda_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
conda config --add channels conda-forge
conda config --set channel_priority strict
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel abseil-cpp fmt backtrace sphinx pip"
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel fmt backtrace sphinx pip"
conda create -q -p $deps_dir -y $conda_pkgs
source activate $deps_dir

Expand Down
2 changes: 1 addition & 1 deletion tools/conda_ubsan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
conda config --add channels conda-forge
conda config --set channel_priority strict
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel abseil-cpp fmt backtrace"
conda_pkgs="cmake mppp boost-cpp tbb tbb-devel fmt backtrace"
conda create -q -p $deps_dir -y $conda_pkgs
source activate $deps_dir

Expand Down

0 comments on commit 24e7209

Please sign in to comment.