Skip to content
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

C++20 module support #255

Draft
wants to merge 85 commits into
base: develop
Choose a base branch
from

Conversation

anarthal
Copy link
Contributor

Adds support for import boost.charconv.
This pull request is intended to get feedback and support discussion in the ML. It depends on changes in Boost.CMake, Boost.Core, Boost.ThrowException and Boost.Assert that aren't in develop.
Any feedback is welcome.

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.85%. Comparing base (dacb62a) to head (65e5356).

Files with missing lines Patch % Lines
...st/charconv/detail/fast_float/digit_comparison.hpp 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #255   +/-   ##
========================================
  Coverage    94.85%   94.85%           
========================================
  Files           69       69           
  Lines         9077     9077           
========================================
  Hits          8610     8610           
  Misses         467      467           
Files with missing lines Coverage Δ
include/boost/charconv/detail/apply_sign.hpp 100.00% <ø> (ø)
include/boost/charconv/detail/buffer_sizing.hpp 100.00% <ø> (ø)
include/boost/charconv/detail/compute_float32.hpp 100.00% <ø> (ø)
include/boost/charconv/detail/compute_float64.hpp 74.07% <ø> (ø)
include/boost/charconv/detail/compute_float80.hpp 91.30% <ø> (ø)
...lude/boost/charconv/detail/dragonbox/dragonbox.hpp 97.68% <ø> (ø)
...ost/charconv/detail/dragonbox/dragonbox_common.hpp 100.00% <ø> (ø)
include/boost/charconv/detail/dragonbox/floff.hpp 87.10% <ø> (ø)
include/boost/charconv/detail/emulated128.hpp 100.00% <100.00%> (ø)
...nclude/boost/charconv/detail/fallback_routines.hpp 84.61% <ø> (ø)
... and 51 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dacb62a...65e5356. Read the comment docs.

target_sources(boost_charconv PUBLIC FILE_SET CXX_MODULES BASE_DIRS modules FILES modules/boost_charconv.cppm)

# Enable and propagate C++23, import std, and the modules macro
target_compile_features(boost_charconv PUBLIC cxx_std_23)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this with C++20 instead of 23? I know officially import std and import std.compat are C++23, but all of the compiler implementors have said they'll allow it at 20.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there's a use to it? My understanding was that using C++20 over C++23 is about being able to use older compilers that might not support C++23. Such compilers won't have proper module implementations, likely, since modules are quite behind everything else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standards like MISRA are pinned to language standards not toolchains. Theoretically someone could have a modern compiler but be stuck at C++20. Probably best to have someone in the real world complain before changing it.


namespace boost { namespace charconv { namespace detail {

static constexpr unsigned char uchar_values[] =
BOOST_INLINE_CONSTEXPR unsigned char uchar_values[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my understanding that the macros from other modules are not visible. Do we need to just copy and paste the logic we need from config into charconv/detail/config.hpp for this to work properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can access macros via #include. This is the purpose of detail/global_module_fragment.hpp: all macros inside that file are made available to all headers in the library when building in module mode.

I'll apply the suggestions that Peter made on the ML that might change how this works and will PR the changes if something better comes out.

#include <cerrno>
#include <boost/config.hpp>
#include <boost/assert.hpp>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better instead of adding #ifdef BOOST_USE_MODULES in every file to move every include into this file and only include this file and other charconv files in the charconv files?

eg

#include <boost/charconv/detail/global_module_fragement.hpp>
#include <boost/charconv/detail/emulated128.hpp>
ETC

In the top of a file? Then you could write some kind of code scanner that will error in your CI if a new contributor adds a STL header in a regular file which would break your module. Boost.Math has a CI run with Circle that does this to check for some of the boost guidelines (min/max, non-ascii characters, copyright, etc)

@mborland
Copy link
Member

This is cool progress. Thanks for continuing to plug away on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants