[libcxx-commits] [libcxx] [libcxx] Configuration option to lower deque block size (PR #198348)
Prabhu Rajasekaran via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 10 10:51:36 PDT 2026
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/198348
>From 741b83a0dc3ca2307bf7a1ccbc77eb8355c79aa6 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 18 May 2026 10:24:58 -0700
Subject: [PATCH 01/16] [libcxx] Allow configuration of deque block size
Larger block size for deque is unsuitable for several environments with
severe memory pressures. Provide configuration option for lower deque
block size.
Please note the test files are generated using an LLM.
---
libcxx/include/__cxx03/deque | 4 +++
libcxx/include/deque | 4 +++
..._deque_block_size.default.compile.pass.cpp | 31 +++++++++++++++++
...er_deque_block_size.lower.compile.pass.cpp | 33 +++++++++++++++++++
4 files changed, 72 insertions(+)
create mode 100644 libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
create mode 100644 libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index 22b02af4ad60d..ade460d0ba2f2 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -232,7 +232,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
+#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+ static const _DiffType value = sizeof(_ValueType) < 256 ? 512 / sizeof(_ValueType) : 2;
+#else
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
+#endif
};
template <class _ValueType,
diff --git a/libcxx/include/deque b/libcxx/include/deque
index c8c6889f1a165..0a94e2cf163cc 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -265,7 +265,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
+#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+ static const _DiffType value = sizeof(_ValueType) < 256 ? 512 / sizeof(_ValueType) : 2;
+#else
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
+#endif
};
template <class _ValueType,
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
new file mode 100644
index 0000000000000..7803ffab38718
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// Test that std::__deque_block_size has default sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is not defined.
+
+#include <deque>
+#include <cstddef>
+
+template <std::size_t Size>
+struct TypeOfSize {
+ char data[Size];
+};
+
+static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 4096, "");
+static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 1024, "");
+static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 512, "");
+
+static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 16, "");
+static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 16, "");
+static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 16, "");
+
+int main(int, char**) {
+ return 0;
+}
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
new file mode 100644
index 0000000000000..b69bdccf8fb71
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// Test that std::__deque_block_size has lowered sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is defined.
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+
+#include <deque>
+#include <cstddef>
+
+template <std::size_t Size>
+struct TypeOfSize {
+ char data[Size];
+};
+
+static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
+static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
+static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 64, "");
+
+static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 2, "");
+static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 2, "");
+static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 2, "");
+
+int main(int, char**) {
+ return 0;
+}
>From 88aa39f31c3951949519329b18d93f5744c3b70f Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 18 May 2026 10:32:20 -0700
Subject: [PATCH 02/16] format
---
.../deque/lower_deque_block_size.default.compile.pass.cpp | 4 +---
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
index 7803ffab38718..f0568ead207da 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -26,6 +26,4 @@ static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value ==
static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 16, "");
static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 16, "");
-int main(int, char**) {
- return 0;
-}
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index b69bdccf8fb71..07a575bb0a513 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -28,6 +28,4 @@ static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value ==
static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 2, "");
static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 2, "");
-int main(int, char**) {
- return 0;
-}
+int main(int, char**) { return 0; }
>From b9655d4c44715df739afe6709d86cc50864756bb Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 18 May 2026 19:44:58 -0700
Subject: [PATCH 03/16] make the calculation generic.
---
libcxx/include/__cxx03/deque | 7 ++++++-
libcxx/include/deque | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index ade460d0ba2f2..7dd923e3605dc 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -233,7 +233,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static const _DiffType value = sizeof(_ValueType) < 256 ? 512 / sizeof(_ValueType) : 2;
+ static constexpr _DiffType kTargetBlockSizeBytes = 512;
+ static constexpr _DiffType kMinElementsPerBlock = 2;
+
+ static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
+ ? (kTargetBlockSizeBytes / sizeof(_ValueType))
+ : kMinElementsPerBlock;
#else
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
#endif
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 0a94e2cf163cc..139702115d64d 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -266,7 +266,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static const _DiffType value = sizeof(_ValueType) < 256 ? 512 / sizeof(_ValueType) : 2;
+ static constexpr _DiffType kTargetBlockSizeBytes = 512;
+ static constexpr _DiffType kMinElementsPerBlock = 2;
+
+ static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
+ ? (kTargetBlockSizeBytes / sizeof(_ValueType))
+ : kMinElementsPerBlock;
#else
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
#endif
>From 2055a1623362b7d11ccf0199e80f5c3c7be2a4c4 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 19 May 2026 10:08:28 -0700
Subject: [PATCH 04/16] Add default to __config and use const instead of
constexpr
---
libcxx/include/__config | 4 ++++
libcxx/include/__cxx03/__config | 4 ++++
libcxx/include/__cxx03/deque | 6 +++---
libcxx/include/deque | 6 +++---
.../deque/lower_deque_block_size.default.compile.pass.cpp | 2 ++
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 6 ++++--
6 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index a34c6ee502bb2..ef8d167ed368b 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -522,6 +522,10 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
+# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# endif
+
#endif // __cplusplus
#endif // _LIBCPP___CONFIG
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index d955429cc4ddc..c12e8b4e6b33c 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -1072,6 +1072,10 @@ typedef __char32_t char32_t;
# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
# endif
+# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# endif
+
#endif // __cplusplus
#endif // _LIBCPP___CXX03___CONFIG
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index 7dd923e3605dc..3df0209ea6823 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -232,9 +232,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
-#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static constexpr _DiffType kTargetBlockSizeBytes = 512;
- static constexpr _DiffType kMinElementsPerBlock = 2;
+#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+ static const _DiffType kTargetBlockSizeBytes = 512;
+ static const _DiffType kMinElementsPerBlock = 2;
static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
? (kTargetBlockSizeBytes / sizeof(_ValueType))
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 139702115d64d..509b4d7ce4bc3 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -265,9 +265,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
-#ifdef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static constexpr _DiffType kTargetBlockSizeBytes = 512;
- static constexpr _DiffType kMinElementsPerBlock = 2;
+#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+ static const _DiffType kTargetBlockSizeBytes = 512;
+ static const _DiffType kMinElementsPerBlock = 2;
static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
? (kTargetBlockSizeBytes / sizeof(_ValueType))
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
index f0568ead207da..e539741a33b42 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -18,6 +18,8 @@ struct TypeOfSize {
char data[Size];
};
+static_assert(_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE == 0, "");
+
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 4096, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 1024, "");
static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 512, "");
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index 07a575bb0a513..b29143ba85d5e 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -8,9 +8,9 @@
// <deque>
-// Test that std::__deque_block_size has lowered sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is defined.
+// Test that std::__deque_block_size has lowered sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is defined to 1.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE=1
#include <deque>
#include <cstddef>
@@ -20,6 +20,8 @@ struct TypeOfSize {
char data[Size];
};
+static_assert(_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE == 1, "");
+
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 64, "");
>From bd2df696ded2c4abcbd0429fe1f4c7732129d4f7 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 19 May 2026 10:25:11 -0700
Subject: [PATCH 05/16] Format
---
libcxx/include/__cxx03/deque | 4 ++--
libcxx/include/deque | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index 3df0209ea6823..cff50d7eba5d2 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -234,8 +234,8 @@ template <class _ValueType, class _DiffType>
struct __deque_block_size {
#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
static const _DiffType kTargetBlockSizeBytes = 512;
- static const _DiffType kMinElementsPerBlock = 2;
-
+ static const _DiffType kMinElementsPerBlock = 2;
+
static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
? (kTargetBlockSizeBytes / sizeof(_ValueType))
: kMinElementsPerBlock;
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 509b4d7ce4bc3..f488c20d8739d 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -267,14 +267,14 @@ template <class _ValueType, class _DiffType>
struct __deque_block_size {
#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
static const _DiffType kTargetBlockSizeBytes = 512;
- static const _DiffType kMinElementsPerBlock = 2;
-
+ static const _DiffType kMinElementsPerBlock = 2;
+
static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
? (kTargetBlockSizeBytes / sizeof(_ValueType))
: kMinElementsPerBlock;
#else
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
-#endif
+# endif
};
template <class _ValueType,
>From 0891a3092d5c001dfdb13a1197a7326e1e118b1c Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 19 May 2026 12:46:03 -0700
Subject: [PATCH 06/16] define default block size macro
---
libcxx/include/__config | 5 +++++
libcxx/include/__cxx03/__config | 5 +++++
libcxx/include/__cxx03/deque | 14 ++++----------
libcxx/include/deque | 14 ++++----------
4 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index ef8d167ed368b..d7e010a604208 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -524,6 +524,11 @@ typedef __char32_t char32_t;
# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
+# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
+# else
+# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 512
+# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 2
# endif
#endif // __cplusplus
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index c12e8b4e6b33c..93c0e6d39ac6d 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -1074,6 +1074,11 @@ typedef __char32_t char32_t;
# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
+# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
+# else
+# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 512
+# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 2
# endif
#endif // __cplusplus
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index cff50d7eba5d2..b860723cbc5ca 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -232,16 +232,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
-#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static const _DiffType kTargetBlockSizeBytes = 512;
- static const _DiffType kMinElementsPerBlock = 2;
-
- static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
- ? (kTargetBlockSizeBytes / sizeof(_ValueType))
- : kMinElementsPerBlock;
-#else
- static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
-#endif
+ static const _DiffType value =
+ (sizeof(_ValueType) * _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK < _LIBCPP_DEQUE_TARGET_BLOCK_SIZE)
+ ? (_LIBCPP_DEQUE_TARGET_BLOCK_SIZE / sizeof(_ValueType))
+ : _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK;
};
template <class _ValueType,
diff --git a/libcxx/include/deque b/libcxx/include/deque
index f488c20d8739d..8cce1f5069b2e 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -265,16 +265,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
-#if _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
- static const _DiffType kTargetBlockSizeBytes = 512;
- static const _DiffType kMinElementsPerBlock = 2;
-
- static const _DiffType value = (sizeof(_ValueType) * kMinElementsPerBlock < kTargetBlockSizeBytes)
- ? (kTargetBlockSizeBytes / sizeof(_ValueType))
- : kMinElementsPerBlock;
-#else
- static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
-# endif
+ static const _DiffType value =
+ (sizeof(_ValueType) * _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK < _LIBCPP_DEQUE_TARGET_BLOCK_SIZE)
+ ? (_LIBCPP_DEQUE_TARGET_BLOCK_SIZE / sizeof(_ValueType))
+ : _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK;
};
template <class _ValueType,
>From 212123da5885f835b3703cab112ec2bd1d28f58a Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 10:25:58 -0700
Subject: [PATCH 07/16] Address review comments
---
libcxx/docs/ABIGuarantees.rst | 4 ++++
libcxx/include/__config | 3 +--
libcxx/include/__configuration/abi.h | 1 +
libcxx/include/__cxx03/__config | 9 ---------
.../lower_deque_block_size.default.compile.pass.cpp | 4 ++--
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 4 ++--
6 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/libcxx/docs/ABIGuarantees.rst b/libcxx/docs/ABIGuarantees.rst
index 4bd9737542a43..4ce20656cb864 100644
--- a/libcxx/docs/ABIGuarantees.rst
+++ b/libcxx/docs/ABIGuarantees.rst
@@ -145,6 +145,10 @@ This flag adds ``[[clang::trivial_abi]]`` to ``shared_ptr``, which makes it triv
This flag makes ``__bit_iterator`` (a.k.a. ``vector<bool>::iterator``) trivially copyable as well as trivial for the
purpose of calls, since the copy constructor is made trivial.
+``_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE``
+---------------------------------------------
+This flag sets the default block size of ``deque`` to 512 bytes and the minimum number of elements per block to 2.
+
Types that public aliases reference
===================================
There are a lot of aliases that reference types with library internal names. For example, containers contain an
diff --git a/libcxx/include/__config b/libcxx/include/__config
index d7e010a604208..2dd045eb2d37b 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -522,8 +522,7 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
-# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# ifndef _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE
# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
# else
diff --git a/libcxx/include/__configuration/abi.h b/libcxx/include/__configuration/abi.h
index 8781cb11e22ef..04d62e538b1d1 100644
--- a/libcxx/include/__configuration/abi.h
+++ b/libcxx/include/__configuration/abi.h
@@ -76,6 +76,7 @@
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
+# define _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE
#elif _LIBCPP_ABI_VERSION == 1
// Feature macros for disabling pre ABI v1 features. All of these options
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index 93c0e6d39ac6d..d955429cc4ddc 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -1072,15 +1072,6 @@ typedef __char32_t char32_t;
# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
# endif
-# ifndef _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE
-# define _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE 0
-# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
-# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
-# else
-# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 512
-# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 2
-# endif
-
#endif // __cplusplus
#endif // _LIBCPP___CXX03___CONFIG
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
index e539741a33b42..89ea7c5b01c13 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -8,7 +8,7 @@
// <deque>
-// Test that std::__deque_block_size has default sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is not defined.
+// Test that std::__deque_block_size has default sizes when _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE is not defined.
#include <deque>
#include <cstddef>
@@ -18,7 +18,7 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE == 0, "");
+static_assert(_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE == 0, "");
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 4096, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 1024, "");
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index b29143ba85d5e..f8947b9e94204 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -8,7 +8,7 @@
// <deque>
-// Test that std::__deque_block_size has lowered sizes when _LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE is defined to 1.
+// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE is defined to 1.
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE=1
@@ -20,7 +20,7 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE == 1, "");
+static_assert(_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE == 1, "");
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
>From 237b10923fe56d41447f9b0a3a1920934338b907 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 10:34:56 -0700
Subject: [PATCH 08/16] Fix missed sed replace instance in test.
---
libcxx/docs/ABIGuarantees.rst | 2 +-
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/docs/ABIGuarantees.rst b/libcxx/docs/ABIGuarantees.rst
index 4ce20656cb864..76df8b6239d37 100644
--- a/libcxx/docs/ABIGuarantees.rst
+++ b/libcxx/docs/ABIGuarantees.rst
@@ -146,7 +146,7 @@ This flag makes ``__bit_iterator`` (a.k.a. ``vector<bool>::iterator``) trivially
purpose of calls, since the copy constructor is made trivial.
``_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE``
----------------------------------------------
+------------------------------------------
This flag sets the default block size of ``deque`` to 512 bytes and the minimum number of elements per block to 2.
Types that public aliases reference
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index f8947b9e94204..8cb361ee9ec5e 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -10,7 +10,7 @@
// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE is defined to 1.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_USE_LOWER_DEQUE_BLOCK_SIZE=1
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE=1
#include <deque>
#include <cstddef>
>From 8145a66b50fcce0e78b9a4a09a38807860856dd9 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 10:39:46 -0700
Subject: [PATCH 09/16] Remove changes from cxx03 deque header
---
libcxx/include/__cxx03/deque | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libcxx/include/__cxx03/deque b/libcxx/include/__cxx03/deque
index b860723cbc5ca..22b02af4ad60d 100644
--- a/libcxx/include/__cxx03/deque
+++ b/libcxx/include/__cxx03/deque
@@ -232,10 +232,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType, class _DiffType>
struct __deque_block_size {
- static const _DiffType value =
- (sizeof(_ValueType) * _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK < _LIBCPP_DEQUE_TARGET_BLOCK_SIZE)
- ? (_LIBCPP_DEQUE_TARGET_BLOCK_SIZE / sizeof(_ValueType))
- : _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK;
+ static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
};
template <class _ValueType,
>From 7873bb655464bd3d411341c6e17e664bb7f19d44 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 11:17:00 -0700
Subject: [PATCH 10/16] bring back define flag to 0 which is used in one of the
tests
---
libcxx/include/__config | 1 +
1 file changed, 1 insertion(+)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 2dd045eb2d37b..995b4c203fa1b 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -523,6 +523,7 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
# ifndef _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE
+# define _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE 0
# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
# else
>From 47c4685163fb214394f012b271a571d2bcbfd3fd Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 12:18:10 -0700
Subject: [PATCH 11/16] Do not define the flag in abi.h file
---
libcxx/include/__configuration/abi.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/libcxx/include/__configuration/abi.h b/libcxx/include/__configuration/abi.h
index 04d62e538b1d1..8781cb11e22ef 100644
--- a/libcxx/include/__configuration/abi.h
+++ b/libcxx/include/__configuration/abi.h
@@ -76,7 +76,6 @@
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
-# define _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE
#elif _LIBCPP_ABI_VERSION == 1
// Feature macros for disabling pre ABI v1 features. All of these options
>From dadd830873e58162298241cf0de0ae45e0db5e07 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 1 Jun 2026 13:24:21 -0700
Subject: [PATCH 12/16] Rename flag as suggested.
---
libcxx/docs/ABIGuarantees.rst | 2 +-
libcxx/include/__config | 4 ++--
.../deque/lower_deque_block_size.default.compile.pass.cpp | 4 ++--
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 6 +++---
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/libcxx/docs/ABIGuarantees.rst b/libcxx/docs/ABIGuarantees.rst
index 76df8b6239d37..cf87dd9526199 100644
--- a/libcxx/docs/ABIGuarantees.rst
+++ b/libcxx/docs/ABIGuarantees.rst
@@ -145,7 +145,7 @@ This flag adds ``[[clang::trivial_abi]]`` to ``shared_ptr``, which makes it triv
This flag makes ``__bit_iterator`` (a.k.a. ``vector<bool>::iterator``) trivially copyable as well as trivial for the
purpose of calls, since the copy constructor is made trivial.
-``_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE``
+``_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE``
------------------------------------------
This flag sets the default block size of ``deque`` to 512 bytes and the minimum number of elements per block to 2.
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 995b4c203fa1b..c8d6c5cedeb20 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -522,8 +522,8 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-# ifndef _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE
-# define _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE 0
+# ifndef _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
+# define _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE 0
# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
# else
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
index 89ea7c5b01c13..d66a3574df5d0 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -8,7 +8,7 @@
// <deque>
-// Test that std::__deque_block_size has default sizes when _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE is not defined.
+// Test that std::__deque_block_size has default sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is not defined.
#include <deque>
#include <cstddef>
@@ -18,7 +18,7 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE == 0, "");
+static_assert(_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE == 0, "");
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 4096, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 1024, "");
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index 8cb361ee9ec5e..1d49990eb0ac9 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -8,9 +8,9 @@
// <deque>
-// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE is defined to 1.
+// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is defined to 1.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE=1
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE=1
#include <deque>
#include <cstddef>
@@ -20,7 +20,7 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_ABI_USE_LOWER_DEQUE_BLOCK_SIZE == 1, "");
+static_assert(_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE == 1, "");
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
>From 8c01771b5e348f59571d214ca941d8cfe184f31a Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 3 Jun 2026 10:13:01 -0700
Subject: [PATCH 13/16] Update the tests to not explicitly define macros.
---
.../deque/lower_deque_block_size.default.compile.pass.cpp | 6 ++----
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 6 +-----
libcxx/utils/libcxx/test/features/libcxx_macros.py | 1 +
3 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
index d66a3574df5d0..888075bee7a08 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.default.compile.pass.cpp
@@ -10,6 +10,8 @@
// Test that std::__deque_block_size has default sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is not defined.
+// UNSUPPORTED: libcpp-abi-use-small-deque-block-size
+
#include <deque>
#include <cstddef>
@@ -18,8 +20,6 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE == 0, "");
-
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 4096, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 1024, "");
static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 512, "");
@@ -27,5 +27,3 @@ static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 512, "")
static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 16, "");
static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 16, "");
static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 16, "");
-
-int main(int, char**) { return 0; }
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index 1d49990eb0ac9..df13f39addafe 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -10,7 +10,7 @@
// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is defined to 1.
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE=1
+// REQUIRES: libcpp-abi-use-small-deque-block-size
#include <deque>
#include <cstddef>
@@ -20,8 +20,6 @@ struct TypeOfSize {
char data[Size];
};
-static_assert(_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE == 1, "");
-
static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 64, "");
@@ -29,5 +27,3 @@ static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 64, "");
static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 2, "");
static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 2, "");
static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 2, "");
-
-int main(int, char**) { return 0; }
diff --git a/libcxx/utils/libcxx/test/features/libcxx_macros.py b/libcxx/utils/libcxx/test/features/libcxx_macros.py
index aeb4696501a83..a3b32a9c88051 100644
--- a/libcxx/utils/libcxx/test/features/libcxx_macros.py
+++ b/libcxx/utils/libcxx/test/features/libcxx_macros.py
@@ -34,6 +34,7 @@
"_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR": "libcpp-deprecated-abi-disable-pair-trivial-copy-ctor",
"_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING": "libcpp-abi-no-compressed-pair-padding",
"_LIBCPP_PSTL_BACKEND_LIBDISPATCH": "libcpp-pstl-backend-libdispatch",
+ "_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE": "libcpp-abi-use-small-deque-block-size",
}
for macro, feature in macros.items():
features.append(
>From e29ee1750bcdb31dba602b11138fbb028e0e80ee Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 3 Jun 2026 10:14:09 -0700
Subject: [PATCH 14/16] Don't explicitly define deque small size macro to 0 for
default.
---
libcxx/include/__config | 1 -
1 file changed, 1 deletion(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index c8d6c5cedeb20..762f632a187ed 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -523,7 +523,6 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
# ifndef _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
-# define _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE 0
# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
# else
>From efe27eb63c74deec9f5b9505a2eba7cd6cae244c Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 3 Jun 2026 13:57:46 -0700
Subject: [PATCH 15/16] More test fixes WIP
---
.../deque/lower_deque_block_size.lower.compile.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index df13f39addafe..1704923489fb8 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -10,7 +10,7 @@
// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is defined to 1.
-// REQUIRES: libcpp-abi-use-small-deque-block-size
+// UNSUPPORTED: libcpp-abi-use-small-deque-block-size
#include <deque>
#include <cstddef>
>From f4df13a3c9824ec249033e0f31d36585ef4a405f Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 10 Jun 2026 10:50:47 -0700
Subject: [PATCH 16/16] Fix test. Remove additional macro definitions and
hardcode the values inside deque.
---
libcxx/include/__config | 8 --------
libcxx/include/deque | 12 ++++++++----
.../lower_deque_block_size.lower.compile.pass.cpp | 9 ++++-----
3 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 762f632a187ed..a34c6ee502bb2 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -522,14 +522,6 @@ typedef __char32_t char32_t;
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-# ifndef _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
-# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 4096
-# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 16
-# else
-# define _LIBCPP_DEQUE_TARGET_BLOCK_SIZE 512
-# define _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK 2
-# endif
-
#endif // __cplusplus
#endif // _LIBCPP___CONFIG
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 8cce1f5069b2e..c75016af0c665 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -263,13 +263,17 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
+#ifndef _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
template <class _ValueType, class _DiffType>
struct __deque_block_size {
- static const _DiffType value =
- (sizeof(_ValueType) * _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK < _LIBCPP_DEQUE_TARGET_BLOCK_SIZE)
- ? (_LIBCPP_DEQUE_TARGET_BLOCK_SIZE / sizeof(_ValueType))
- : _LIBCPP_DEQUE_MIN_ELEMENTS_PER_BLOCK;
+ static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
};
+#else
+template <class _ValueType, class _DiffType>
+struct __deque_block_size {
+ static const _DiffType value = sizeof(_ValueType) < 128 ? 512 / sizeof(_ValueType) : 4;
+};
+#endif
template <class _ValueType,
class _Pointer,
diff --git a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
index 1704923489fb8..251ae98a9c74d 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/lower_deque_block_size.lower.compile.pass.cpp
@@ -9,8 +9,7 @@
// <deque>
// Test that std::__deque_block_size has lowered sizes when _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE is defined to 1.
-
-// UNSUPPORTED: libcpp-abi-use-small-deque-block-size
+// REQUIRES: libcpp-abi-use-small-deque-block-size
#include <deque>
#include <cstddef>
@@ -24,6 +23,6 @@ static_assert(std::__deque_block_size<char, std::ptrdiff_t>::value == 512, "");
static_assert(std::__deque_block_size<int, std::ptrdiff_t>::value == 128, "");
static_assert(std::__deque_block_size<double, std::ptrdiff_t>::value == 64, "");
-static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 2, "");
-static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 2, "");
-static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 2, "");
+static_assert(std::__deque_block_size<TypeOfSize<255>, std::ptrdiff_t>::value == 4, "");
+static_assert(std::__deque_block_size<TypeOfSize<256>, std::ptrdiff_t>::value == 4, "");
+static_assert(std::__deque_block_size<TypeOfSize<512>, std::ptrdiff_t>::value == 4, "");
More information about the libcxx-commits
mailing list