[libcxx-commits] [PATCH] D136538: [libcxx] Add test for checking progress on P0533R9

Evgeny Shulgin via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Oct 22 13:41:23 PDT 2022


Izaron added a comment.

This is a part of our work on implementing p0533r9:
https://discourse.llvm.org/t/how-do-we-plan-to-make-constexpr-cmath-and-cstdlib/65930

This patch introduces a test that serve as:

1. A reference list of functions that need to be declared `constexpr` to make p0533r9 implemented.
2. A progress checker, so that whenever a new function is declared `constexpr`, the programmer won't forget to switch the corresponding `ASSERT_NOT_CONSTEXPR_CXX23`s to `ASSERT_CONSTEXPR_CXX23`s and eventually confidently mark the paper as implemented.

With this test (and previous commits) we will have a nice automated workflow for working on this paper:

1. The **programmer** makes a new constexpr builtin, for example patch for __builtin_fmax <https://reviews.llvm.org/rG0edff6faa26664772c41fed8d7759bba703f4987>.
2. The **programmer** has to mark the builtin with the `E` attribute in `Builtins.def`, for example __builtins_def <https://github.com/llvm/llvm-project/blob/446981bdb64d0ae24ac77b8ba07f3ee3808c3936/clang/include/clang/Basic/Builtins.def#L262-L266> (otherwise the evaluator returns early).
3. Since the builtin `__builtin_fmax` is marked as constant evaluated (in `Builtins.def`), the `__has_constexpr_builtin(__builtin_fmax)` starts returning `true`.
4. Since `__has_constexpr_builtin(__builtin_fmax) == true`, the corresponding libcxx function `std::fmax` becomes constexpr, because our fellow @philnik is now refactoring cmath to using builtins unconditionally, and the functions will be conditionally constexpr, so it will soon look like this:

  inline _LIBCPP_CONSTEXPR_CXX23_IF_CONSTEXPR_BUILTIN(__builtin_fmax) _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT { return __builtin_fmax(__x, __y); }

5. The new test (that I added in this patch request) starts to fails, so the **programmer** has to switch `ASSERT_NOT_CONSTEXPR_CXX23` to `ASSERT_CONSTEXPR_CXX23`
6. GoTo 1, if there are any other non-constexpr function.
7. There are no non-constexpr functions anymore, so the new test (that I added in this patch request) congratulates you! The paper is implemented.

I hope this workflow is clear 😅 This is not an overengineering - only a clear adherence to the paper so that we clearly understand the current status.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136538/new/

https://reviews.llvm.org/D136538



More information about the libcxx-commits mailing list