-
Notifications
You must be signed in to change notification settings - Fork 260
Implement and test consumption of Boost.Math as a module #1422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mborland
wants to merge
27
commits into
develop
Choose a base branch
from
module
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
348a583
Add C++20 module infrastructure and foundation components
mborland f9861a7
Guard std includes for module builds across all headers
mborland 2a1c7af
Export the special functions for the boost.math module
mborland 5ee0d77
Export the statistical distributions for the boost.math module
mborland 8a5dcf9
Export ccmath for the boost.math module
mborland cf76357
Export the public tools for the boost.math module
mborland 88d19ef
Export quadrature and the modern interpolators for the boost.math module
mborland 39b0970
Export statistics and optimization for the boost.math module
mborland 18f8fb7
Export differentiation and the algebra types for the boost.math module
mborland 0fd6b77
Add documentation of module support
mborland f431389
Clarify that the module is consumable from C++20
mborland ff56f1c
Remove accidental commit test folder
mborland 4014fa4
Silence the reserved module identifier warning in module builds
mborland 5e49f1c
Add a GCC module test to CI
mborland 5b18f2c
Fix doc inspection failure
mborland 74fc0c0
Keep cstdfloat out of the module purview
mborland 3986feb
Change module file extension and add extern "C++"
mborland e5b102e
Update references to file extension
mborland 70ec7a7
Add CPPM to allowable extensions
mborland d89dc67
Remove workaround that doesn't work with modules
mborland 3614727
Add MSVC modules testing
mborland f096e4a
Ignore clang warnings
mborland 03b38db
Remove anonymous namespace breaking module linkage
mborland 0246361
Attempt fix MSVC problem
mborland 0270056
Fix John's initial issue
mborland 2492498
Inline constexpr variable templates
mborland b76b7c4
Add tests for functions previously causing module linkage issues
mborland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| [section:cxx20_modules Support for C++20 Modules] | ||
|
|
||
| [h4 C++20 Modules Support] | ||
|
|
||
| Boost.Math can be consumed as the named module `boost.math`. | ||
| The module covers the public interface of the library: special functions, statistical distributions, constants, policies, ccmath, the public tools (root finding, minima, polynomials, rational and series evaluation, norms, condition numbers and friends), quadrature, the modern interpolators, statistics, optimization, differentiation (autodiff, finite differences and Lanczos smoothing), the complex inverse trigonometric functions, and the quaternion and octonion types. | ||
|
|
||
| import boost.math; | ||
|
|
||
| int main() | ||
| { | ||
| return boost::math::cdf(boost::math::normal_distribution<>(), 0.0) == 0.5 ? 0 : 1; | ||
| } | ||
|
|
||
| Module support is completely inert unless the module is built and consumed explicitly: nothing changes for existing header users. | ||
|
|
||
| [h4 How to build] | ||
|
|
||
| The module is consumable from C++20 onward. | ||
| The interface unit lives in `libs/math/module/math.cppm` and builds with any toolchain that provides the standard library module (`import std`); the standard library maintainers agreed to make `import std` available in C++20 mode as well as C++23, so a C++23 compilation mode is not required. | ||
| CI exercises two configurations, both with CMake 4.4, Ninja and the matching `CMAKE_EXPERIMENTAL_CXX_IMPORT_STD` UUID: clang 20 with libc++ runs the full module test suite, and GCC 15 with libstdc++ builds the module and runs the quick test (libstdc++ cannot yet mix the textual standard library includes used by the wider test sources with `import std` in the same translation unit). | ||
| From a Boost superproject checkout: | ||
|
|
||
| cmake -G Ninja -DBOOST_INCLUDE_LIBRARIES=math -DBUILD_TESTING=ON \ | ||
| -DBOOST_MATH_BUILD_MODULE=ON \ | ||
| -DCMAKE_CXX_COMPILER=clang++-20 \ | ||
| -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Wno-reserved-module-identifier" \ | ||
| -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=<uuid-for-your-cmake-version> \ | ||
| -DCMAKE_CXX_STDLIB_MODULES_JSON=/usr/lib/llvm-20/lib/libc++.modules.json .. | ||
| cmake --build . --target tests | ||
| ctest | ||
|
|
||
| The module test suite reuses a curated subset of the regular test files, which switch from textual inclusion to `import boost.math;` when `BOOST_MATH_BUILD_MODULE` is defined. | ||
| The `cmake-module-test` job in the library's CI runs this configuration on every commit. | ||
|
|
||
| [h4 Limitations] | ||
|
|
||
| * The module is always built in standalone mode, so it has no dependencies on other Boost libraries. | ||
| * Macros do not cross module boundaries. | ||
| The policy configuration macros (`BOOST_MATH_DOMAIN_ERROR_POLICY` and friends) and the convenience macros `BOOST_MATH_DECLARE_DISTRIBUTIONS` and `BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS` therefore have no effect on an importing translation unit. | ||
| Configure policies at the call site with `boost::math::policies::make_policy` or a `policy<...>` type instead; those interfaces are fully available through the import. | ||
| * The `user_error` policy is not supported through the module, because a user supplied `boost::math::policies::user_..._error` definition cannot attach to the module. | ||
| * A program should consume Boost.Math either through the module or through textual includes, not both. | ||
| The only headers that are safe to include textually alongside the import are `boost/math/tools/config.hpp` and `boost/math/tools/assert.hpp`, which the test support headers rely on. | ||
| * Excluded from the module: the TR1/C99 interfaces and `common_factor` headers, `boost/math/bindings`, `boost/math/concepts`, `boost/math/cstdfloat`, all deprecated headers, and the headers that require external non-Boost dependencies (`chebyshev_transform.hpp` and `interpolators/cardinal_trigonometric.hpp` need FFTW, `optimization/cma_es.hpp` needs Eigen). | ||
| These remain available as ordinary includes. | ||
| * `__float128` support (`BOOST_MATH_USE_FLOAT128`) is not enabled in the module build. | ||
| * On libc++ the parallel execution policy overloads in statistics compile out (no `<execution>` support), matching the ordinary header behavior on that standard library. | ||
|
|
||
| [endsect] [/section:cxx20_modules Support for C++20 Modules] | ||
|
|
||
| [/ | ||
| Copyright 2026 Matt Borland. | ||
| Distributed under the Boost Software License, Version 1.0. | ||
| (See accompanying file LICENSE_1_0.txt or copy at | ||
| http://www.boost.org/LICENSE_1_0.txt). | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.