Skip to content

Commit

Permalink
Merge pull request #350 from bluescarni/pr/new_anomalies
Browse files Browse the repository at this point in the history
Several misc fixes/cleanups
  • Loading branch information
bluescarni authored Oct 6, 2023
2 parents 13afeb6 + c048aaf commit 092a508
Show file tree
Hide file tree
Showing 25 changed files with 868 additions and 791 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka VERSION 2.0.1 LANGUAGES CXX C)
project(heyoka VERSION 3.0.0 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -174,6 +174,7 @@ set(HEYOKA_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/cm_utils.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/event_detection.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/llvm_helpers.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/llvm_helpers_celmec.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/dfloat.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/num_utils.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/num_identity.cpp"
Expand Down Expand Up @@ -301,7 +302,7 @@ if(HEYOKA_WITH_SLEEF)
endif()

# Setup the heyoka ABI version number.
set(HEYOKA_ABI_VERSION 23)
set(HEYOKA_ABI_VERSION 24)

if(HEYOKA_BUILD_STATIC_LIBRARY)
# Setup of the heyoka static library.
Expand Down Expand Up @@ -348,6 +349,9 @@ if(HEYOKA_ENABLE_IPO)
unset(_HEYOKA_IPO_OUTPUT)
endif()

# Add a define to signal that we are building the library.
target_compile_definitions(heyoka PRIVATE HEYOKA_BUILD_LIBRARY)

message(STATUS "LLVM definitions: ${LLVM_DEFINITIONS}")
message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")

Expand Down Expand Up @@ -539,7 +543,10 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/heyoka-config.cmake"
install(EXPORT heyoka_export NAMESPACE heyoka:: DESTINATION "${HEYOKA_INSTALL_LIBDIR}/cmake/heyoka")
# Take care of versioning.
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/heyoka-config-version.cmake" COMPATIBILITY SameMinorVersion)
# NOTE: since we use semantic versioning, the correct setting here is SameMajorVersion: it requires equality
# in the major version, but higher minor versions will be considered compatible. So, if heyoka 2.0.0 is requested
# and 2.1.0 is found, then all is good. However, the reverse will lead to a failure.
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/heyoka-config-version.cmake" COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/heyoka-config-version.cmake" DESTINATION "${HEYOKA_INSTALL_LIBDIR}/cmake/heyoka")

# Cleanup.
Expand Down
9 changes: 8 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
Changelog
=========

2.0.1 (unreleased)
3.0.0 (unreleased)
------------------

Fix
~~~

- Prevent accidental leaking in the public headers of
serialisation implementation details
(`#350 <https://github.com/bluescarni/heyoka/pull/350>`__).
- Fix wrong version compatibility setting in the CMake config-file package
(`#350 <https://github.com/bluescarni/heyoka/pull/350>`__).
- Work around test failure on ARM + LLVM 17
(`#350 <https://github.com/bluescarni/heyoka/pull/350>`__).
- Fix orbital elements singularity when using the VSOP2013
theory at low precision
(`#348 <https://github.com/bluescarni/heyoka/pull/348>`__).
Expand Down
5 changes: 2 additions & 3 deletions include/heyoka/callable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef HEYOKA_CALLABLE_HPP
#define HEYOKA_CALLABLE_HPP

#include <cassert>
#include <functional>
#include <memory>
#include <type_traits>
Expand Down Expand Up @@ -100,7 +99,7 @@ struct HEYOKA_DLL_PUBLIC_INLINE_CLASS callable_inner final : callable_inner_base
void serialize(Archive &ar, unsigned)
{
ar &boost::serialization::base_object<callable_inner_base<R, Args...>>(*this);
ar &m_value;
ar & m_value;
}
};

Expand All @@ -122,7 +121,7 @@ class HEYOKA_DLL_PUBLIC_INLINE_CLASS callable<R(Args...)>
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &m_ptr;
ar & m_ptr;
}

// Dispatching of the generic constructor with specialisation
Expand Down
2 changes: 1 addition & 1 deletion include/heyoka/detail/binomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdint>

#include <boost/math/special_functions/binomial.hpp>
#include <boost/math/tools/config.hpp>
Expand Down
10 changes: 5 additions & 5 deletions include/heyoka/detail/dfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <cassert>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>

Expand All @@ -39,6 +38,7 @@ struct dfloat {

dfloat() : hi(0), lo(0) {}
explicit dfloat(F x) : hi(x), lo(0) {}
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
explicit dfloat(F h, F l) : hi(h), lo(l) {}

explicit operator F() const
Expand All @@ -52,8 +52,8 @@ struct dfloat {
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &hi;
ar &lo;
ar & hi;
ar & lo;
}
};

Expand All @@ -79,8 +79,8 @@ struct HEYOKA_DLL_PUBLIC dfloat<mppp::real> {
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &hi;
ar &lo;
ar & hi;
ar & lo;
}
};

Expand Down
1 change: 0 additions & 1 deletion include/heyoka/detail/event_detection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <heyoka/config.hpp>

#include <cstdint>
#include <type_traits>

#if defined(HEYOKA_HAVE_REAL128)

Expand Down
3 changes: 1 addition & 2 deletions include/heyoka/detail/llvm_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#ifndef HEYOKA_DETAIL_LLVM_HELPERS_HPP
#define HEYOKA_DETAIL_LLVM_HELPERS_HPP

#include <cstddef>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <map>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -128,6 +126,7 @@ HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_ult(llvm_state &, llvm::Value *, llvm::
HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_oge(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_ole(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_olt(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_ogt(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_fcmp_oeq(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_min(llvm_state &, llvm::Value *, llvm::Value *);
HEYOKA_DLL_PUBLIC llvm::Value *llvm_max(llvm_state &, llvm::Value *, llvm::Value *);
Expand Down
72 changes: 72 additions & 0 deletions include/heyoka/detail/optional_s11n.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2020, 2021, 2022, 2023 Francesco Biscani ([email protected]), Dario Izzo ([email protected])
//
// This file is part of the heyoka library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef HEYOKA_DETAIL_OPTIONAL_S11N_HPP
#define HEYOKA_DETAIL_OPTIONAL_S11N_HPP

#if !defined(HEYOKA_BUILD_LIBRARY)

#error This header can be included only when building heyoka.

#endif

#include <optional>

#include <heyoka/s11n.hpp>

namespace boost::serialization
{

// NOTE: inspired by the boost::optional implementation.
template <typename Archive, typename T>
void save(Archive &ar, const std::optional<T> &opt, unsigned)
{
// First check if opt contains something.
const auto flag = static_cast<bool>(opt);
ar << flag;

if (flag) {
// Save the contained value.
ar << *opt;
}
}

template <typename Archive, typename T>
void load(Archive &ar, std::optional<T> &opt, unsigned)
{
// Recover the flag.
bool flag{};
ar >> flag;

if (!flag) {
// No value in the archive,
// reset opt and return.
opt.reset();

return;
}

if (!opt) {
// opt is currently empty, reset it
// to the def-cted value.
opt = T{};
}

// Deserialise the value.
ar >> *opt;
}

template <typename Archive, typename T>
void serialize(Archive &ar, std::optional<T> &opt, unsigned v)
{
split_free(ar, opt, v);
}

} // namespace boost::serialization

#endif
1 change: 0 additions & 1 deletion include/heyoka/detail/taylor_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down
109 changes: 109 additions & 0 deletions include/heyoka/detail/variant_s11n.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2020, 2021, 2022, 2023 Francesco Biscani ([email protected]), Dario Izzo ([email protected])
//
// This file is part of the heyoka library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef HEYOKA_DETAIL_VARIANT_S11N_HPP
#define HEYOKA_DETAIL_VARIANT_S11N_HPP

#if !defined(HEYOKA_BUILD_LIBRARY)

#error This header can be included only when building heyoka.

#endif

#include <cassert>
#include <cstddef>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <variant>

#include <heyoka/config.hpp>
#include <heyoka/s11n.hpp>

HEYOKA_BEGIN_NAMESPACE

namespace detail
{

// Implementation detail for loading a std::variant.
template <typename Archive, typename... Args, std::size_t... Is>
void s11n_variant_load_impl(Archive &ar, std::variant<Args...> &var, std::size_t idx, std::index_sequence<Is...>)
{
auto loader = [&ar, &var, idx](auto val) {
constexpr auto N = decltype(val)::value;

if (N == idx) {
// NOTE: deserialise into a temporary, then move
// it into the variant.
std::variant_alternative_t<N, std::variant<Args...>> x;
ar >> x;
var = std::move(x);

// Inform the archive of the new address
// of the object we just deserialised.
ar.reset_object_address(&std::get<N>(var), &x);

return true;
} else {
assert(N < idx);

return false;
}
};

// LCOV_EXCL_START
[[maybe_unused]] auto ret = (loader(std::integral_constant<std::size_t, Is>{}) || ...);

assert(ret);
assert(var.index() == idx);
// LCOV_EXCL_STOP
}

} // namespace detail

HEYOKA_END_NAMESPACE

namespace boost::serialization
{

// NOTE: inspired by the boost::variant implementation.
template <typename Archive, typename... Args>
void save(Archive &ar, const std::variant<Args...> &var, unsigned)
{
const auto idx = var.index();

ar << idx;

std::visit([&ar](const auto &x) { ar << x; }, var);
}

template <typename Archive, typename... Args>
void load(Archive &ar, std::variant<Args...> &var, unsigned)
{
// Recover the variant index.
std::size_t idx{};
ar >> idx;

// LCOV_EXCL_START
if (idx >= sizeof...(Args)) {
throw std::invalid_argument("Invalid index loaded during the deserialisation of a variant");
}
// LCOV_EXCL_STOP

heyoka::detail::s11n_variant_load_impl(ar, var, idx, std::make_index_sequence<sizeof...(Args)>{});
}

template <typename Archive, typename... Args>
void serialize(Archive &ar, std::variant<Args...> &var, unsigned v)
{
split_free(ar, var, v);
}

} // namespace boost::serialization

#endif
8 changes: 3 additions & 5 deletions include/heyoka/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ class HEYOKA_DLL_PUBLIC expression

// Serialization.
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar & m_value;
}
void save(boost::archive::binary_oarchive &, unsigned) const;
void load(boost::archive::binary_iarchive &, unsigned);
BOOST_SERIALIZATION_SPLIT_MEMBER()

public:
expression();
Expand Down
Loading

0 comments on commit 092a508

Please sign in to comment.