[libcxx-commits] [libcxx] [libc++] Granularize <execution> (PR #229315)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 5 22:53:44 PDT 2026
https://github.com/emmett2020 created https://github.com/llvm/llvm-project/pull/229315
Move execution policies into `__execution/execution_policies.h`
to separate them from upcoming C++26 sender/receiver components.
This is a prerequisite for #229095.
>From 9934b8ea7a48b9e48b572f5abfd4659ab5f229a1 Mon Sep 17 00:00:00 2001
From: Emmett <emmettzhang2020 at outlook.com>
Date: Tue, 6 Oct 2026 13:41:09 +0800
Subject: [PATCH] [libc++] Granularize <execution>
---
libcxx/include/CMakeLists.txt | 1 +
.../include/__execution/execution_policies.h | 131 ++++++++++++++++++
libcxx/include/execution | 117 +---------------
libcxx/include/module.modulemap.in | 1 +
4 files changed, 139 insertions(+), 111 deletions(-)
create mode 100644 libcxx/include/__execution/execution_policies.h
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1ee2081561fd9..35a8b2a893cfd 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -367,6 +367,7 @@ set(files
__exception/nested_exception.h
__exception/operations.h
__exception/terminate.h
+ __execution/execution_policies.h
__expected/bad_expected_access.h
__expected/expected.h
__expected/unexpect.h
diff --git a/libcxx/include/__execution/execution_policies.h b/libcxx/include/__execution/execution_policies.h
new file mode 100644
index 0000000000000..c5112d18fcfd8
--- /dev/null
+++ b/libcxx/include/__execution/execution_policies.h
@@ -0,0 +1,131 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___EXECUTION_EXECUTION_POLICIES_H
+#define _LIBCPP___EXECUTION_EXECUTION_POLICIES_H
+
+#include <__config>
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_execution_policy.h>
+#include <__type_traits/is_same.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_EXPERIMENTAL_PSTL
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace execution {
+struct sequenced_policy {
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {}
+ sequenced_policy(const sequenced_policy&) = delete;
+ sequenced_policy& operator=(const sequenced_policy&) = delete;
+};
+
+inline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}};
+
+struct parallel_policy {
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {}
+ parallel_policy(const parallel_policy&) = delete;
+ parallel_policy& operator=(const parallel_policy&) = delete;
+};
+
+inline constexpr parallel_policy par{__disable_user_instantiations_tag{}};
+
+struct parallel_unsequenced_policy {
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {}
+ parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete;
+ parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete;
+};
+
+inline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}};
+
+struct __unsequenced_policy {
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {}
+ __unsequenced_policy(const __unsequenced_policy&) = delete;
+ __unsequenced_policy& operator=(const __unsequenced_policy&) = delete;
+};
+
+constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}};
+
+# if _LIBCPP_STD_VER >= 20
+
+struct unsequenced_policy {
+ _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {}
+ unsequenced_policy(const unsequenced_policy&) = delete;
+ unsequenced_policy& operator=(const unsequenced_policy&) = delete;
+};
+
+inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}};
+
+# endif // _LIBCPP_STD_VER >= 20
+
+} // namespace execution
+
+_LIBCPP_DIAGNOSTIC_PUSH
+# if __has_warning("-Winvalid-specialization")
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
+# endif
+template <>
+inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true;
+
+template <>
+inline constexpr bool is_execution_policy_v<execution::parallel_policy> = true;
+
+template <>
+inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true;
+
+template <>
+inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true;
+_LIBCPP_DIAGNOSTIC_POP
+
+template <>
+inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true;
+
+template <>
+inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
+
+template <>
+inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true;
+
+template <>
+inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
+
+# if _LIBCPP_STD_VER >= 20
+_LIBCPP_DIAGNOSTIC_PUSH
+# if __has_warning("-Winvalid-specialization")
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
+# endif
+template <>
+inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true;
+_LIBCPP_DIAGNOSTIC_POP
+
+template <>
+inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true;
+
+# endif
+
+template <class _Tp>
+struct _LIBCPP_NO_SPECIALIZATIONS is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
+
+template <class _ExecutionPolicy>
+_LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
+ if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) {
+ return execution::sequenced_policy(execution::__disable_user_instantiations_tag{});
+ } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) {
+ return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}};
+ }
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_EXPERIMENTAL_PSTL
+
+#endif // _LIBCPP___EXECUTION_EXECUTION_POLICIES_H
diff --git a/libcxx/include/execution b/libcxx/include/execution
index 49a901282fd9b..f42959db486c4 100644
--- a/libcxx/include/execution
+++ b/libcxx/include/execution
@@ -11,6 +11,8 @@
#define _LIBCPP_EXECUTION
/*
+ execution synopsis
+
namespace std::execution {
struct sequenced_policy;
struct parallel_policy;
@@ -30,6 +32,7 @@ namespace std {
template <class T>
inline constexpr bool is_execution_policy_v;
}
+
*/
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
@@ -37,123 +40,15 @@ namespace std {
#else
# include <__config>
# include <__type_traits/is_execution_policy.h>
-# include <__type_traits/is_same.h>
-# include <__type_traits/remove_cvref.h>
# include <version>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
-# if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace execution {
-struct sequenced_policy {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {}
- sequenced_policy(const sequenced_policy&) = delete;
- sequenced_policy& operator=(const sequenced_policy&) = delete;
-};
-
-inline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}};
-
-struct parallel_policy {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {}
- parallel_policy(const parallel_policy&) = delete;
- parallel_policy& operator=(const parallel_policy&) = delete;
-};
-
-inline constexpr parallel_policy par{__disable_user_instantiations_tag{}};
-
-struct parallel_unsequenced_policy {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {}
- parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete;
- parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete;
-};
-
-inline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}};
-
-struct __unsequenced_policy {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {}
- __unsequenced_policy(const __unsequenced_policy&) = delete;
- __unsequenced_policy& operator=(const __unsequenced_policy&) = delete;
-};
-
-constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}};
-
-# if _LIBCPP_STD_VER >= 20
-
-struct unsequenced_policy {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {}
- unsequenced_policy(const unsequenced_policy&) = delete;
- unsequenced_policy& operator=(const unsequenced_policy&) = delete;
-};
-
-inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}};
-
-# endif // _LIBCPP_STD_VER >= 20
-
-} // namespace execution
-
-_LIBCPP_DIAGNOSTIC_PUSH
-# if __has_warning("-Winvalid-specialization")
-_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
-# endif
-template <>
-inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true;
-
-template <>
-inline constexpr bool is_execution_policy_v<execution::parallel_policy> = true;
-
-template <>
-inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true;
-
-template <>
-inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true;
-_LIBCPP_DIAGNOSTIC_POP
-
-template <>
-inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true;
-
-template <>
-inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
-
-template <>
-inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true;
-
-template <>
-inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
-
-# if _LIBCPP_STD_VER >= 20
-_LIBCPP_DIAGNOSTIC_PUSH
-# if __has_warning("-Winvalid-specialization")
-_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
-# endif
-template <>
-inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true;
-_LIBCPP_DIAGNOSTIC_POP
-
-template <>
-inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true;
-
-# endif
-
-template <class _Tp>
-struct _LIBCPP_NO_SPECIALIZATIONS is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
-
-template <class _ExecutionPolicy>
-_LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
- if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) {
- return execution::sequenced_policy(execution::__disable_user_instantiations_tag{});
- } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) {
- return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}};
- }
-}
-
-_LIBCPP_END_NAMESPACE_STD
-
-# endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
+# if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_EXPERIMENTAL_PSTL
+# include <__execution/execution_policies.h>
+# endif
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 28ae9ee8de46a..4a54f69ea3b57 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1266,6 +1266,7 @@ module std {
module execution {
header "execution"
+ header "__execution/execution_policies.h"
export *
}
More information about the libcxx-commits
mailing list