Add constexpr support for dynamic allocated cpp_int#654
Add constexpr support for dynamic allocated cpp_int#654marcoffee wants to merge 20 commits intoboostorg:developfrom
Conversation
66564be to
e6cb783
Compare
e6cb783 to
2c0d0cd
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #654 +/- ##
=========================================
+ Coverage 96.2% 96.2% +0.1%
=========================================
Files 301 304 +3
Lines 29462 29492 +30
=========================================
+ Hits 28328 28365 +37
+ Misses 1134 1127 -7
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
2c0d0cd to
dd3be65
Compare
|
Hi @marcoffee I'm sorry this took so long. Your PR was waiting in the queue for a while. I've just approved the CI/CD run on this PR. In Multiprecision, first-time contributors need approval to even run CI/CD, and this can be a bit of a point where we lose some time. Sorry for that. There is renewed interest in Of course, @jzmaddock will need to look at this, and I will also. But let's see how CI/CD runs with the full battery of compilers running it. Cc: @jzmaddock and @mborland and @eisenwave |
|
Hi @marcoffee and @jzmaddock CI has run green. One thing, however, that I did not test is a simple code verifying the @marcoffee could you work up an example (post-C++20) that exercises this? Then we can put the test into CI/CD. Cc: @mborland |
|
The added missing lines in code coverage seem to be lines that aare never expected to run, using |
|
I can't merge this thing until we get a consensus from @jzmaddock and @mborland |
It's not that they are never used, it's that they never used at run-time so codecov can't pick them up. I normally just |
|
@ckormanyos thanks for your reply!
Please correct me if I'm wrong, but some of the tests (e.g., here) can only run during constexpr evaluation since they are called in a If there is need for more tests I can add them. Also, if there is need for adding some |
I looked through the tests this morning and yes, it looks like you're already exercising these dynamic allocation paths.
If you would add if (BOOST_MP_IS_CONST_EVALUATED(n))
{
// LCOV_EXCL_START
...
// LCOV_EXCL_STOP
}Or Codecov will erroneously mark these paths as never taken, but it doesn't support coverage of constant evaluated paths. |
|
|
||
| template <std::size_t MinBits, std::size_t MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates> | ||
| inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> | ||
| inline BOOST_MP_CXX20_DYNAMIC_ALLOC_CONSTEXPR_IF_DETECTION boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> |
There was a problem hiding this comment.
BOOST_MP_CXX20_DYNAMIC_ALLOC_CONSTEXPR_IF_DETECTION is a long name ;)
I assume it evaluates to just constexpr? If so we can probably just call it BOOST_MP_CXX20_CONSTEXPR and be consistent with the other constexpr macros?
There was a problem hiding this comment.
I agree. This name is a mix between the BOOST_MP_HAS_CONSTEXPR_DYNAMIC_ALLOC and BOOST_CXX14_CONSTEXPR_IF_DETECTION (used on the other overloads). I added it in case some compiler just implements the dynamic allocation without the constexpr if detection, but I think it might not happen. In this case, is it ok if I just remove this macro and replace it with BOOST_MP_HAS_CONSTEXPR_DYNAMIC_ALLOC?
There was a problem hiding this comment.
Does Boost.Config have BOOST_CXX20_CONSTEXPR? I guess I would associate that with __cpp_constexpr > 201907L since there was a huge expansion of constexpr in 20. I would go with BOOST_MP_CXX20_ALLOC_CONSTEXPR. A macro with _HAS_ in the name looks odd in the function signature, usually those are associated with some in body configuration or configuration of other macros.
There was a problem hiding this comment.
I will use the BOOST_MP_CXX20_DYNAMIC_ALLOC_CONSTEXPR then. I prefer using DYNAMIC_ALLOC instead of just ALLOC because it closer to the standard feature tests __cpp_constexpr_dynamic_alloc and __cpp_lib_constexpr_dynamic_alloc, but I can change it to BOOST_MP_CXX20_ALLOC_CONSTEXPR if required.
There is just the case for this check that may run at consteval time or not depending on the input types. In this case, should I:
|
In that case it looks like you could write tests that would cover both paths at runtime. One with same DestT and SrcT and one where they are different. |
I found out that this method is only called for copying limbs, so the types should always be the same. I just removed the possibility of passing two different types and ended up with just the |
…or BOOST_MP_NO_CXX20_DYNAMIC_ALLOC_CONSTEXPR
…type constructor overload
|
Just resolved the conflicts locally and started the tests. As soon as it is finished here I will push a new version with the changes. |
dd3be65 to
f1aeeb3
Compare
610f987 to
4e2a915
Compare
|
It seems like the Install Packages step is failing due to network errors. I'm trying to force push to the branch to trigger rerun. |
4e2a915 to
5957e7a
Compare
Added constexpr support for dynamic allocated
cpp_ints as long as compiler implements features__cpp_constexpr_dynamic_allocand__cpp_lib_constexpr_dynamic_allocfrom P0784R7.If those features are disabled, it behaves as the current implementation. Note that those features require C++20, so they will only work when passing
-std=c++2a(or beyond) flag during compilation through a supported compiler (tested here ong++-11+ andclang++-16+ using libstdc++ withg++-10+ toolset on ubuntu noble).It might work on
g++-10, but for some reason the b2 check forif constexprkeep returning "no" for it.Also fixed constexpr construction from strings and added some tests for construction/operations on dynamic allocated
cpp_ints.Had to make small changes to existing code to tackle some warnings given when compiled without the feature's support (such as uninitialized variables not being supported in constexpr methods before C++20).