Skip to content

Commit

Permalink
Merge pull request #370 from bluescarni/pr/extern_inst
Browse files Browse the repository at this point in the history
Prevent implicit instantiations
  • Loading branch information
bluescarni authored Dec 8, 2023
2 parents 793d3a2 + a776963 commit 7d5ee8d
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 283 deletions.
8 changes: 4 additions & 4 deletions include/heyoka/detail/fwd_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class HEYOKA_DLL_PUBLIC param;
class HEYOKA_DLL_PUBLIC llvm_state;

template <typename>
class HEYOKA_DLL_PUBLIC taylor_adaptive;
class HEYOKA_DLL_PUBLIC_INLINE_CLASS taylor_adaptive;

template <typename>
class HEYOKA_DLL_PUBLIC taylor_adaptive_batch;
class HEYOKA_DLL_PUBLIC_INLINE_CLASS taylor_adaptive_batch;

namespace detail
{

template <typename, bool>
class HEYOKA_DLL_PUBLIC nt_event_impl;
class HEYOKA_DLL_PUBLIC_INLINE_CLASS nt_event_impl;

template <typename, bool>
class HEYOKA_DLL_PUBLIC t_event_impl;
class HEYOKA_DLL_PUBLIC_INLINE_CLASS t_event_impl;

} // namespace detail

Expand Down
108 changes: 93 additions & 15 deletions include/heyoka/ensemble_propagate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@

#endif

#if defined(HEYOKA_HAVE_REAL)

#include <mp++/real.hpp>

#endif

#include <heyoka/detail/type_traits.hpp>
#include <heyoka/detail/visibility.hpp>
#include <heyoka/step_callback.hpp>
#include <heyoka/taylor.hpp>

Expand All @@ -35,25 +40,60 @@ namespace detail
{

template <typename T>
HEYOKA_DLL_PUBLIC
std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>>
ensemble_propagate_until_impl(const taylor_adaptive<T> &, T, std::size_t,
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &,
std::size_t, T, step_callback<T> &, bool, bool);
std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>>
ensemble_propagate_until_impl(const taylor_adaptive<T> &, T, std::size_t,
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, std::size_t,
T, step_callback<T> &, bool, bool);

template <typename T>
HEYOKA_DLL_PUBLIC
std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>>
ensemble_propagate_for_impl(const taylor_adaptive<T> &, T, std::size_t,
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, std::size_t,
T, step_callback<T> &, bool, bool);
std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>>
ensemble_propagate_for_impl(const taylor_adaptive<T> &, T, std::size_t,
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, std::size_t, T,
step_callback<T> &, bool, bool);

template <typename T>
HEYOKA_DLL_PUBLIC std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::vector<T>>>
std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::vector<T>>>
ensemble_propagate_grid_impl(const taylor_adaptive<T> &, std::vector<T>, std::size_t,
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, std::size_t, T,
step_callback<T> &);

// Prevent implicit instantiations.
// NOLINTBEGIN
#define HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(T) \
extern template std::vector< \
std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>> \
ensemble_propagate_until_impl(const taylor_adaptive<T> &, T, std::size_t, \
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, \
std::size_t, T, step_callback<T> &, bool, bool); \
\
extern template std::vector< \
std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::optional<continuous_output<T>>>> \
ensemble_propagate_for_impl(const taylor_adaptive<T> &, T, std::size_t, \
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, \
std::size_t, T, step_callback<T> &, bool, bool); \
\
extern template std::vector<std::tuple<taylor_adaptive<T>, taylor_outcome, T, T, std::size_t, std::vector<T>>> \
ensemble_propagate_grid_impl(const taylor_adaptive<T> &, std::vector<T>, std::size_t, \
const std::function<taylor_adaptive<T>(taylor_adaptive<T>, std::size_t)> &, \
std::size_t, T, step_callback<T> &);
// NOLINTEND

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(float)
HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(double)
HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(long double)

#if defined(HEYOKA_HAVE_REAL128)

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(mppp::real128)

#endif

#if defined(HEYOKA_HAVE_REAL)

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_SCALAR_INST(mppp::real)

#endif

} // namespace detail

template <typename T, typename... KwArgs>
Expand Down Expand Up @@ -101,25 +141,63 @@ namespace detail
{

template <typename T>
HEYOKA_DLL_PUBLIC std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>>
std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>>
ensemble_propagate_until_batch_impl(
const taylor_adaptive_batch<T> &, T, std::size_t,
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t,
const std::vector<T> &, step_callback_batch<T> &, bool, bool);

template <typename T>
HEYOKA_DLL_PUBLIC std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>>
std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>>
ensemble_propagate_for_batch_impl(
const taylor_adaptive_batch<T> &, T, std::size_t,
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t,
const std::vector<T> &, step_callback_batch<T> &, bool, bool);

template <typename T>
HEYOKA_DLL_PUBLIC std::vector<std::tuple<taylor_adaptive_batch<T>, std::vector<T>>> ensemble_propagate_grid_batch_impl(
std::vector<std::tuple<taylor_adaptive_batch<T>, std::vector<T>>> ensemble_propagate_grid_batch_impl(
const taylor_adaptive_batch<T> &, const std::vector<T> &, std::size_t,
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t,
const std::vector<T> &, step_callback_batch<T> &);

// Prevent implicit instantiations.
// NOLINTBEGIN
#define HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(T) \
extern template std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>> \
ensemble_propagate_until_batch_impl( \
const taylor_adaptive_batch<T> &, T, std::size_t, \
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t, \
const std::vector<T> &, step_callback_batch<T> &, bool, bool); \
\
extern template std::vector<std::tuple<taylor_adaptive_batch<T>, std::optional<continuous_output_batch<T>>>> \
ensemble_propagate_for_batch_impl( \
const taylor_adaptive_batch<T> &, T, std::size_t, \
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t, \
const std::vector<T> &, step_callback_batch<T> &, bool, bool); \
\
extern template std::vector<std::tuple<taylor_adaptive_batch<T>, std::vector<T>>> \
ensemble_propagate_grid_batch_impl( \
const taylor_adaptive_batch<T> &, const std::vector<T> &, std::size_t, \
const std::function<taylor_adaptive_batch<T>(taylor_adaptive_batch<T>, std::size_t)> &, std::size_t, \
const std::vector<T> &, step_callback_batch<T> &);
// NOLINTEND

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(float)
HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(double)
HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(long double)

#if defined(HEYOKA_HAVE_REAL128)

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(mppp::real128)

#endif

#if defined(HEYOKA_HAVE_REAL)

HEYOKA_ENSEMBLE_PROPAGATE_EXTERN_BATCH_INST(mppp::real)

#endif

} // namespace detail

template <typename T, typename... KwArgs>
Expand Down
36 changes: 31 additions & 5 deletions include/heyoka/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,39 @@ namespace detail
{

template <typename>
HEYOKA_DLL_PUBLIC std::vector<expression> add_cfunc(llvm_state &, const std::string &, const std::vector<expression> &,
std::uint32_t, bool, bool, bool, long long);
std::vector<expression> add_cfunc(llvm_state &, const std::string &, const std::vector<expression> &, std::uint32_t,
bool, bool, bool, long long);

template <typename>
HEYOKA_DLL_PUBLIC std::vector<expression> add_cfunc(llvm_state &, const std::string &, const std::vector<expression> &,
const std::vector<expression> &, std::uint32_t, bool, bool, bool,
long long);
std::vector<expression> add_cfunc(llvm_state &, const std::string &, const std::vector<expression> &,
const std::vector<expression> &, std::uint32_t, bool, bool, bool, long long);

// Prevent implicit instantiations.
#define HEYOKA_CFUNC_EXTERN_INST(T) \
extern template std::vector<expression> add_cfunc<T>(llvm_state &, const std::string &, \
const std::vector<expression> &, std::uint32_t, bool, bool, \
bool, long long); \
extern template std::vector<expression> add_cfunc<T>( \
llvm_state &, const std::string &, const std::vector<expression> &, const std::vector<expression> &, \
std::uint32_t, bool, bool, bool, long long);

HEYOKA_CFUNC_EXTERN_INST(float)
HEYOKA_CFUNC_EXTERN_INST(double)
HEYOKA_CFUNC_EXTERN_INST(long double)

#if defined(HEYOKA_HAVE_REAL128)

HEYOKA_CFUNC_EXTERN_INST(mppp::real128)

#endif

#if defined(HEYOKA_HAVE_REAL)

HEYOKA_CFUNC_EXTERN_INST(mppp::real)

#endif

#undef HEYOKA_CFUNC_EXTERN_INST

} // namespace detail

Expand Down
Loading

0 comments on commit 7d5ee8d

Please sign in to comment.