Skip to content

Commit

Permalink
Remove any mention of spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sparus committed Aug 28, 2024
1 parent 864aafa commit 6b47b15
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 70 deletions.
16 changes: 16 additions & 0 deletions doc/persist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ This library enables the application of the transformation function directly on
sharing. Additionally, regardless of how many times a node is reused, the transformation needs to be performed only
once.


Dependencies
------------

In addition to the `dependencies <introduction.html#dependencies>`_ of ``immer``, this library makes use of **C++20**,
`Boost.Hana <https://boostorg.github.io/hana/>`_, `fmt <https://fmt.dev/>`_ and `cereal <https://uscilab.github.io/cereal/>`_.


.. _first-example:

First example
Expand All @@ -46,6 +54,14 @@ For this example, we'll use a `document` type that contains two ``immer`` vector
:start-after: intro/start-types
:end-before: intro/end-types

Let's make the ``document`` struct compatible with ``boost::hana``. This way, the ``persist`` library can determine what
pool types are needed and to name the pools.

.. literalinclude:: ../test/extra/persist/test_for_docs.cpp
:language: c++
:start-after: intro/start-adapt-document-for-hana
:end-before: intro/end-adapt-document-for-hana

Let's say we have two vectors ``v1`` and ``v2``, where ``v2`` is derived from ``v1`` so that it shares data with it:

.. literalinclude:: ../test/extra/persist/test_for_docs.cpp
Expand Down
5 changes: 2 additions & 3 deletions extra/fuzzer/persist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)

file(GLOB_RECURSE immer_fuzzers "*.cpp")
foreach(_file IN LISTS immer_fuzzers)
Expand All @@ -7,8 +7,7 @@ foreach(_file IN LISTS immer_fuzzers)
set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_output})
target_compile_options(${_target} PUBLIC ${immer_fuzzing_engine})
target_include_directories(${_target} PRIVATE ../..)
target_link_libraries(${_target} PUBLIC ${immer_fuzzing_engine} immer-dev
spdlog::spdlog)
target_link_libraries(${_target} PUBLIC ${immer_fuzzing_engine} immer-dev)
add_dependencies(fuzzers ${_target})
if(CHECK_FUZZERS)
add_test("fuzzer/${_output}" ${_output} -max_total_time=1)
Expand Down
1 change: 0 additions & 1 deletion extra/fuzzer/persist/flex-vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
auto src = read<char>(in, is_valid_var);
auto dst = read<char>(in, is_valid_var);
const auto op = read<char>(in);
SPDLOG_DEBUG("op = {}", static_cast<int>(op));
switch (op) {
case op_push_back: {
vars[dst] = vars[src].push_back(42);
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
arximboldi-cereal = pkgs.callPackage ./nix/cereal.nix {inherit arximboldi-cereal-src;};

persist-inputs = with pkgs; [
spdlog
fmt
arximboldi-cereal
xxHash
nlohmann_json
Expand Down
2 changes: 0 additions & 2 deletions immer/extra/persist/detail/champ/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <boost/hana/functional/id.hpp>
#include <boost/range/adaptor/indexed.hpp>

#include <spdlog/spdlog.h>

namespace immer::persist::champ {

class children_count_corrupted_exception : public pool_exception
Expand Down
2 changes: 0 additions & 2 deletions immer/extra/persist/detail/champ/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <immer/extra/persist/detail/champ/pool.hpp>

#include <spdlog/spdlog.h>

namespace immer::persist::champ {

template <class T, immer::detail::hamts::bits_t B>
Expand Down
14 changes: 1 addition & 13 deletions immer/extra/persist/detail/node_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <immer/vector.hpp>

#include <spdlog/spdlog.h>

namespace immer::persist::detail {

template <typename Node>
Expand All @@ -27,7 +25,6 @@ struct ptr_with_deleter
void dec() const
{
if (ptr && ptr->dec()) {
SPDLOG_TRACE("calling deleter for {}", (void*) ptr);
deleter(ptr);
}
}
Expand All @@ -49,15 +46,13 @@ class node_ptr
node_ptr(Node* ptr_, std::function<void(Node* ptr)> deleter_)
: ptr{ptr_, std::move(deleter_)}
{
SPDLOG_TRACE("ctor {} with ptr {}", (void*) this, (void*) ptr.ptr);
// Assuming the node has just been created and not calling inc() on
// it.
}

node_ptr(const node_ptr& other)
: ptr{other.ptr}
{
SPDLOG_TRACE("copy ctor {} from {}", (void*) this, (void*) &other);
if (ptr.ptr) {
ptr.ptr->inc();
}
Expand All @@ -66,31 +61,24 @@ class node_ptr
node_ptr(node_ptr&& other)
: node_ptr{}
{
SPDLOG_TRACE("move ctor {} from {}", (void*) this, (void*) &other);
swap(*this, other);
}

node_ptr& operator=(const node_ptr& other)
{
SPDLOG_TRACE("copy assign {} = {}", (void*) this, (void*) &other);
auto temp = other;
swap(*this, temp);
return *this;
}

node_ptr& operator=(node_ptr&& other)
{
SPDLOG_TRACE("move assign {} = {}", (void*) this, (void*) &other);
auto temp = node_ptr{std::move(other)};
swap(*this, temp);
return *this;
}

~node_ptr()
{
SPDLOG_TRACE("dtor {}", (void*) this);
ptr.dec();
}
~node_ptr() { ptr.dec(); }

explicit operator bool() const { return ptr.ptr; }

Expand Down
5 changes: 0 additions & 5 deletions immer/extra/persist/detail/rbts/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <immer/vector.hpp>
#include <optional>

#include <spdlog/spdlog.h>

namespace immer::persist::rbts {

inline constexpr auto get_shift_for_depth(immer::detail::rbts::bits_t b,
Expand Down Expand Up @@ -476,17 +474,14 @@ class loader
detail::visitor_helper{},
boost::hana::overload(
[&](detail::regular_pos_tag, auto&& pos, auto&& visit) {
// SPDLOG_INFO("regular_pos_tag");
const bool visiting_relaxed = false;
check_inner(pos, visit, visiting_relaxed);
},
[&](detail::relaxed_pos_tag, auto&& pos, auto&& visit) {
// SPDLOG_INFO("relaxed_pos_tag");
const bool visiting_relaxed = true;
check_inner(pos, visit, visiting_relaxed);
},
[&](detail::leaf_pos_tag, auto&& pos, auto&& visit) {
// SPDLOG_INFO("leaf_pos_tag");
const auto* id = loaded_leaves_.find(pos.node());
assert(id);
if (!id) {
Expand Down
10 changes: 4 additions & 6 deletions test/extra/persist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)
find_package(cereal REQUIRED)
find_package(xxHash 0.8 CONFIG REQUIRED)

Expand Down Expand Up @@ -27,8 +27,8 @@ target_precompile_headers(persist-tests PRIVATE
add_dependencies(tests persist-tests)
add_test("test/persist-tests" persist-tests)
target_include_directories(persist-tests PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(
persist-tests PRIVATE spdlog::spdlog Catch2::Catch2WithMain xxHash::xxhash)
target_link_libraries(persist-tests PRIVATE fmt::fmt Catch2::Catch2WithMain
xxHash::xxhash)

target_compile_options(persist-tests PRIVATE -O1 -fno-optimize-sibling-calls -g
-fno-omit-frame-pointer)
Expand All @@ -40,9 +40,7 @@ if(ENABLE_ASAN)
target_link_options(persist-tests PRIVATE -fsanitize=address)
endif()
target_compile_definitions(persist-tests PRIVATE BOOST_USE_ASAN=1)
target_compile_definitions(
persist-tests PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE
IMMER_NO_FREE_LIST=1)
target_compile_definitions(persist-tests PRIVATE IMMER_NO_FREE_LIST=1)

install(TARGETS persist-tests DESTINATION bin)
install(FILES valgrind.supp DESTINATION bin)
45 changes: 23 additions & 22 deletions test/extra/persist/test_for_docs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ using vector_one =

struct document
{
// Make it a boost::hana Struct.
// This allows the persist library to determine what pool types are needed
// and also to name the pools.
BOOST_HANA_DEFINE_STRUCT(document,
(vector_one, ints),
(vector_one, ints2) //
);
vector_one ints;
vector_one ints2;

friend bool operator==(const document&, const document&) = default;

Expand All @@ -41,6 +36,13 @@ using json_t = nlohmann::json;

} // namespace

// Make it a boost::hana Struct.
// This allows the persist library to determine what pool types are needed
// and also to name the pools.
// include:intro/start-adapt-document-for-hana
BOOST_HANA_ADAPT_STRUCT(document, ints, ints2);
// include:intro/end-adapt-document-for-hana

TEST_CASE("Docs save with immer-persist", "[docs]")
{
// include:intro/start-prepare-value
Expand Down Expand Up @@ -252,14 +254,12 @@ TEST_CASE("Custom policy", "[docs]")
REQUIRE(value == loaded_value);
}

namespace {
// include:start-document_str
namespace {
struct document_str
{
BOOST_HANA_DEFINE_STRUCT(document_str,
(vector_str, str),
(vector_str, str2) //
);
vector_str str;
vector_str str2;

friend bool operator==(const document_str&, const document_str&) = default;

Expand All @@ -269,8 +269,9 @@ struct document_str
ar(CEREAL_NVP(str), CEREAL_NVP(str2));
}
};
// include:end-document_str
} // namespace
BOOST_HANA_ADAPT_STRUCT(document_str, str, str2);
// include:end-document_str

TEST_CASE("Transformations", "[docs]")
{
Expand Down Expand Up @@ -594,8 +595,7 @@ namespace {
// include:start-define-nested-types
struct nested_t
{
BOOST_HANA_DEFINE_STRUCT(nested_t, //
(vector_one, ints));
vector_one ints;

friend bool operator==(const nested_t&, const nested_t&) = default;

Expand All @@ -608,8 +608,7 @@ struct nested_t

struct with_nested_t
{
BOOST_HANA_DEFINE_STRUCT(with_nested_t, //
(immer::vector<nested_t>, nested));
immer::vector<nested_t> nested;

friend bool operator==(const with_nested_t&,
const with_nested_t&) = default;
Expand All @@ -624,8 +623,7 @@ struct with_nested_t

struct new_nested_t
{
BOOST_HANA_DEFINE_STRUCT(new_nested_t, //
(vector_str, str));
vector_str str;

friend bool operator==(const new_nested_t&, const new_nested_t&) = default;

Expand All @@ -638,9 +636,7 @@ struct new_nested_t

struct with_new_nested_t
{
BOOST_HANA_DEFINE_STRUCT(with_new_nested_t,
(immer::vector<new_nested_t>, nested) //
);
immer::vector<new_nested_t> nested;

friend bool operator==(const with_new_nested_t&,
const with_new_nested_t&) = default;
Expand All @@ -653,6 +649,11 @@ struct with_new_nested_t
};
} // namespace

BOOST_HANA_ADAPT_STRUCT(nested_t, ints);
BOOST_HANA_ADAPT_STRUCT(with_nested_t, nested);
BOOST_HANA_ADAPT_STRUCT(new_nested_t, str);
BOOST_HANA_ADAPT_STRUCT(with_new_nested_t, nested);

TEST_CASE("Transform nested containers", "[docs]")
{
// include:start-prepare-nested-value
Expand Down
2 changes: 0 additions & 2 deletions test/extra/persist/test_special_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ TEST_CASE("Special pool minimal test")

TEST_CASE("Save with a special pool")
{
spdlog::set_level(spdlog::level::debug);

const auto ints1 = test::gen(test::example_vector{}, 3);
const auto test1 = test_data{
.ints = ints1,
Expand Down
Loading

0 comments on commit 6b47b15

Please sign in to comment.