P0533R9 constexpr For <cmath> And <cstdlib> - #6413
P0533R9 constexpr For <cmath> And <cstdlib>#6413Stephan T. Lavavej (StephanTLavavej) merged 85 commits into
constexpr For <cmath> And <cstdlib>#6413Conversation
…handling in lgamma and tgamma.
…_BEGIN_C_HEADER`.
…s to reduce divergence.
…th `_CONSTEXPR_CMATH26_NYI`.
…e predicates within extern "C++".
…aded classification/comparison functions need this.
…constexpr and always-runtime functions.
This comment was marked as resolved.
This comment was marked as resolved.
…NSITION comments.
…6_NYI, add test coverage.
fbb868b
into
microsoft:main
David Justo (davidmrdavid)
left a comment
There was a problem hiding this comment.
Great to see this in. I'm leaving partial comments as I was mid-review as it got merged. NOTE: I only made it as far as this commit: 177ed2a .
| // * Changed code to support the MSVC frontend intercepting inclusions of <stdlib.h>. | ||
| // * Changed code for C++23's P0533R9 "constexpr For <cmath> And <cstdlib>". |
There was a problem hiding this comment.
non blocking nit: these 2 bullet points are summarizing what could be really large changes. It would be neat if we could summarize in a bit more details what these changes are, in case someone needs to reconstruct them in the future.
This is different from the preceding bullet points, which are a lot more mechanical and easier to understand: formatting, code is removed under macros, etc.
There was a problem hiding this comment.
This is really "diff the two files and this describes what you're seeing". A more detailed description would just repeat the code, and would be harder to keep in sync.
Fixes #2530 (C++23's Final Boss) and works towards #3789 (C++26's Miniboss) for MSVC. I've filed #6412 to track implementing this for Clang and EDG.
Mirrors internal MSVC-PR-767459. Thanks to Cody Miller (@Codiferous) for figuring out how to do this without UCRT changes, implementing this in the compiler, and writing the initial library changes.
The trick here is that a new compiler option (
/experimental:mathlibin the current MSVC Build Tools Preview,/Zc:cmathvery soon) enables what Cody calls "header duplexing", where inclusions of<math.h>and<stdlib.h>are replaced with inclusions of the new<__msvc_math.hpp>and<__msvc_stdlib.hpp>here, allowing us to light them up for C++23/26 without requiring UCRT header changes which are a big headache (and would be WinSDK-dependent). We may be able to eliminate this trickery in the future, but it would be good to completely finalize what we need for C++23/26 and MSVC/Clang/EDG before attempting to push changes into the UCRT.Cody's new builtins are powered by LLVM libc, which provides highly accurate implementations. This avoids baking the notorious accuracy issues present in the UCRT, into the compiler's new constexpr builtins, and also avoids divergence between compiletime and runtime behavior. LLVM libc provides everything we need for C++23, but some functions needed for C++26 are not yet implemented by LLVM libc, so we have workarounds to continue using the UCRT there.
The test I'm adding exercises everything at compiletime and runtime where possible, but does not attempt to be a careful precision test.
For the first time, we are adding exports to a satellite DLL, specifically adding Boost.Math's implementations of
lgammaandtgammato the Special Math satellite, because LLVM libc currently lacks them. We have refrained from doing so in the past, but this is permitted by our binary compatibility requirements (which were somewhat recently exercised by theconstexpr mutexconstructor change).