Conversation
Adds gated C++20 named module support (module boost.math), inert unless BOOST_MATH_BUILD_MODULE is defined: * BOOST_MATH_EXPORT / BOOST_MATH_TEST_EXPORT macro block in tools/config.hpp * module/math.cxx interface unit covering constants and policies * module/CMakeLists.txt test harness requiring import std * module/quick_test.cpp smoke test and module/Jamfile for b2 * test/CMakeLists.txt branch for -DBOOST_MATH_BUILD_MODULE=ON * cmake-module-test CI job (clang-20 + libc++ + CMake 4.4.0) * Export annotations for constants, policies, error handling, and the tools support headers they pull in * std includes in those headers guarded for module builds * Namespace scope static constexpr variables converted to BOOST_MATH_INLINE_CONSTEXPR (float_constants and friends, max_string_digits) for module linkage
Mechanical sweep wrapping every standard library include in #ifndef BOOST_MATH_BUILD_MODULE so the module interface unit can provide them through the global module fragment or import std. Also converts the static constexpr color map data tables to BOOST_MATH_INLINE_CONSTEXPR for module linkage. No change in any existing configuration; validated against the full compile_test suite and the module build.
* BOOST_MATH_EXPORT on the public declarations in math_fwd.hpp, round_fwd.hpp, unchecked_factorial.hpp, unchecked_bernoulli.hpp and every special function header (declaration and definition sites) * Adds special_functions.hpp to the module interface unit * rsqrt.hpp, jacobi.hpp and cardinal_b_spline.hpp now include tools/config.hpp so the export macro is always defined * math_unit_test.hpp resolves math entities through the import in module mode * Module test harness gains test_digamma_simple, test_expm1_simple, test_log1p_simple, git_issue_1194 and git_issue_1255
* BOOST_MATH_EXPORT on the 38 distribution class templates (fwd.hpp and definition sites), every non-member accessor overload, the convenience typedefs, the complement machinery and find_location/find_scale * distributions/fwd.hpp now includes tools/config.hpp so the export macro is always defined * Adds distributions.hpp to the module interface unit * Module test harness gains git_issue_1294, git_issue_800, git_issue_1120 and scipy_issue_17146
* BOOST_MATH_EXPORT on the constexpr cmath function set * Adds ccmath/ccmath.hpp to the module interface unit * Module test harness gains ccmath_isinf_test and ccmath_isnan_test
* BOOST_MATH_EXPORT on the root finders, minima, polynomial and its operators, rational/polynomial evaluators, series and continued fraction machinery, recurrences, norms, condition numbers, color maps, expansions, agm and toms748 * Adds the curated tools headers to the module interface unit * Module test harness gains git_issue_1139, cubic_roots_test and quartic_roots_test
* BOOST_MATH_EXPORT on the integrator class templates, trapezoidal and the wavelet transform, plus the interpolator class templates and their stream operators * Adds the quadrature and interpolator headers to the module interface unit (cardinal_trigonometric and the deprecated boost::math namespace shims stay textual only) * Module test harness gains git_issue_898, cardinal_quadratic_b_spline_test and whittaker_shannon_test
* BOOST_MATH_EXPORT on the statistics free functions (univariate, bivariate, tests, regression, signal) and the optimization algorithms, parameter structs and constraint/convergence policies * BOOST_MATH_TEST_EXPORT on the optimization detail helpers the differential evolution test exercises directly * Adds the statistics and optimization headers to the module interface unit; cma_es is excluded because it requires Eigen * test_functions_for_optimization.hpp resolves constants through the import in module mode * Module test harness gains test_runs_test, linear_regression_test, ljung_box_test, differential_evolution_test and random_search_test
* BOOST_MATH_EXPORT on autodiff (make_fvar, make_ftuple, promote, real_cast), finite differences, lanczos smoothing, the complex inverse trigonometric functions, quaternion and octonion including their macro generated operator sets, and the boost/math_fwd.hpp forward declarations * Fixes a pre-existing ambiguity: autodiff's fully qualified differentiation::detail::fvar references are ambiguous whenever finite_difference.hpp is visible in the same translation unit, so they now name the autodiff_v1 inline namespace explicitly * Adds differentiation, complex.hpp, quaternion.hpp and octonion.hpp to the module interface unit (finite_difference and lanczos_smoothing precede autodiff by necessity) * Module test harness gains quaternion_constexpr_test and octonion_test_simple; both tests now include what they use
The standard library maintainers agreed to provide import std in C++20 mode as well as C++23, so the docs no longer claim a C++23 requirement. The library sources never gated on C++23: the only floor is the C++17 inline variable check in tools/config.hpp.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1422 +/- ##
===========================================
- Coverage 95.40% 95.40% -0.01%
===========================================
Files 828 828
Lines 69072 69071 -1
===========================================
- Hits 65896 65895 -1
Misses 3176 3176
... and 30 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
This is green in general and with both GCC and Clang as a module |
|
Wow! Looks like good work to me, time will tell what if any consequences there are? I notice it's not yet tested with msvc which has really rather good module support, has this been tried yet? Also any word on compile times? |
I expect so. I think the ecosystem is still feeling it out.
I have not tried with MSVC, but I can add that to the CI.
Clang takes 33 seconds to build the module plus compile and run the 25 tests. I can slice the module build into a separate CI step to measure it directly. |
|
The MSVC module is in CI and works. Build times for just the boost.math module: MSVC - 15 seconds The other Boost libraries that support modules all use |
Generally we prefer to test the time for using/import the modules. As the story modules builds on everything was built once and we can avoid duplications. e.g., the blog (https://anarthal.github.io/cppblog/modules3) says:
This reads very good. |
|
Anything else you'd like to see for this one @jzmaddock? If not I can merge this PR and close the old one. |
|
Looking good. However, when trying to get some concept checks working with modules I see: These are all defined in lambert_w_lookup_table.hpp and there are some tricky ones here, because I don't think we can make the tables |
|
BOOST_MATH_INLINE_CONSTEXPR should fix these. It expands to static constexpr in C++14 mode and inline constexpr for 17 and up. |
This implements module support for a large subset of the library as well as testing with associated infrastructure. Since we don't control our dependencies, consumption of the module only supports standalone mode. A modules.qbk files was added that explicitly lays out limitations that we can't circumvent such as policy configuration macros will not work.
Please let me know what you think @jzmaddock, @NAThompson, @ckormanyos, @ChuanqiXu9