Skip to content

Commit 316634f

Browse files
authored
[libc++] Remove <queue> and <stack> includes from <format> (#85520)
This reduces the include time of <format> from 691ms to 556ms.
1 parent a855692 commit 316634f

File tree

26 files changed

+187
-43
lines changed

26 files changed

+187
-43
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,22 +430,27 @@ set(files
430430
__fwd/array.h
431431
__fwd/bit_reference.h
432432
__fwd/complex.h
433+
__fwd/deque.h
433434
__fwd/format.h
434435
__fwd/fstream.h
435436
__fwd/functional.h
436437
__fwd/ios.h
437438
__fwd/istream.h
438439
__fwd/mdspan.h
440+
__fwd/memory.h
439441
__fwd/memory_resource.h
440442
__fwd/ostream.h
441443
__fwd/pair.h
444+
__fwd/queue.h
442445
__fwd/span.h
443446
__fwd/sstream.h
447+
__fwd/stack.h
444448
__fwd/streambuf.h
445449
__fwd/string.h
446450
__fwd/string_view.h
447451
__fwd/subrange.h
448452
__fwd/tuple.h
453+
__fwd/vector.h
449454
__hash_table
450455
__ios/fpos.h
451456
__iterator/access.h

libcxx/include/__format/container_adaptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include <__format/concepts.h>
1919
#include <__format/formatter.h>
2020
#include <__format/range_default_formatter.h>
21+
#include <__fwd/queue.h>
22+
#include <__fwd/stack.h>
2123
#include <__ranges/ref_view.h>
2224
#include <__type_traits/is_const.h>
2325
#include <__type_traits/maybe_const.h>
24-
#include <queue>
25-
#include <stack>
2626

2727
_LIBCPP_BEGIN_NAMESPACE_STD
2828

libcxx/include/__fwd/deque.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_DEQUE_H
10+
#define _LIBCPP___FWD_DEQUE_H
11+
12+
#include <__config>
13+
#include <__fwd/memory.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
template <class _Tp, class _Allocator = allocator<_Tp> >
22+
class _LIBCPP_TEMPLATE_VIS deque;
23+
24+
_LIBCPP_END_NAMESPACE_STD
25+
26+
#endif // _LIBCPP___FWD_DEQUE_H

libcxx/include/__fwd/memory.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_MEMORY_H
10+
#define _LIBCPP___FWD_MEMORY_H
11+
12+
#include <__config>
13+
14+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15+
# pragma GCC system_header
16+
#endif
17+
18+
_LIBCPP_BEGIN_NAMESPACE_STD
19+
20+
template <class _Tp>
21+
class _LIBCPP_TEMPLATE_VIS allocator;
22+
23+
_LIBCPP_END_NAMESPACE_STD
24+
25+
#endif // _LIBCPP___FWD_MEMORY_H

libcxx/include/__fwd/queue.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_QUEUE_H
10+
#define _LIBCPP___FWD_QUEUE_H
11+
12+
#include <__config>
13+
#include <__functional/operations.h>
14+
#include <__fwd/deque.h>
15+
#include <__fwd/vector.h>
16+
17+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18+
# pragma GCC system_header
19+
#endif
20+
21+
_LIBCPP_BEGIN_NAMESPACE_STD
22+
23+
template <class _Tp, class _Container = deque<_Tp> >
24+
class _LIBCPP_TEMPLATE_VIS queue;
25+
26+
template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
27+
class _LIBCPP_TEMPLATE_VIS priority_queue;
28+
29+
_LIBCPP_END_NAMESPACE_STD
30+
31+
#endif // _LIBCPP___FWD_QUEUE_H

libcxx/include/__fwd/sstream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _LIBCPP___FWD_SSTREAM_H
1111

1212
#include <__config>
13+
#include <__fwd/memory.h>
1314
#include <__fwd/string.h>
1415

1516
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/__fwd/stack.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_STACK_H
10+
#define _LIBCPP___FWD_STACK_H
11+
12+
#include <__config>
13+
#include <__fwd/deque.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
template <class _Tp, class _Container = deque<_Tp> >
22+
class _LIBCPP_TEMPLATE_VIS stack;
23+
24+
_LIBCPP_END_NAMESPACE_STD
25+
26+
#endif // _LIBCPP___FWD_STACK_H

libcxx/include/__fwd/string.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__availability>
1313
#include <__config>
14+
#include <__fwd/memory.h>
1415
#include <__fwd/memory_resource.h>
1516

1617
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -39,9 +40,6 @@ template <>
3940
struct char_traits<wchar_t>;
4041
#endif
4142

42-
template <class _Tp>
43-
class _LIBCPP_TEMPLATE_VIS allocator;
44-
4543
template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
4644
class _LIBCPP_TEMPLATE_VIS basic_string;
4745

libcxx/include/__fwd/vector.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===---------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_VECTOR_H
10+
#define _LIBCPP___FWD_VECTOR_H
11+
12+
#include <__config>
13+
#include <__fwd/memory.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
template <class _Tp, class _Alloc = allocator<_Tp> >
22+
class _LIBCPP_TEMPLATE_VIS vector;
23+
24+
_LIBCPP_END_NAMESPACE_STD
25+
26+
#endif // _LIBCPP___FWD_VECTOR_H

libcxx/include/deque

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ template <class T, class Allocator, class Predicate>
192192
#include <__availability>
193193
#include <__config>
194194
#include <__format/enable_insertable.h>
195+
#include <__fwd/deque.h>
195196
#include <__iterator/distance.h>
196197
#include <__iterator/iterator_traits.h>
197198
#include <__iterator/next.h>
@@ -244,9 +245,6 @@ _LIBCPP_PUSH_MACROS
244245

245246
_LIBCPP_BEGIN_NAMESPACE_STD
246247

247-
template <class _Tp, class _Allocator = allocator<_Tp> >
248-
class _LIBCPP_TEMPLATE_VIS deque;
249-
250248
template <class _ValueType, class _DiffType>
251249
struct __deque_block_size {
252250
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;

libcxx/include/format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ namespace std {
223223

224224
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
225225
# include <locale>
226+
# include <queue>
227+
# include <stack>
226228
#endif
227229

228230
#endif // _LIBCPP_FORMAT

libcxx/include/iosfwd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ using wosyncstream = basic_osyncstream<wchar_t>; // C++20
110110
#include <__fwd/fstream.h>
111111
#include <__fwd/ios.h>
112112
#include <__fwd/istream.h>
113+
#include <__fwd/memory.h>
113114
#include <__fwd/ostream.h>
114115
#include <__fwd/sstream.h>
115116
#include <__fwd/streambuf.h>
@@ -162,10 +163,6 @@ using wosyncstream = basic_osyncstream<wchar_t>;
162163

163164
#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
164165

165-
// Include other forward declarations here
166-
template <class _Tp, class _Alloc = allocator<_Tp> >
167-
class _LIBCPP_TEMPLATE_VIS vector;
168-
169166
template <class _CharT, class _Traits>
170167
class __save_flags {
171168
typedef basic_ios<_CharT, _Traits> __stream_type;

libcxx/include/libcxx.imp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,22 +425,27 @@
425425
{ include: [ "<__fwd/bit_reference.h>", "private", "<bitset>", "public" ] },
426426
{ include: [ "<__fwd/bit_reference.h>", "private", "<vector>", "public" ] },
427427
{ include: [ "<__fwd/complex.h>", "private", "<complex>", "public" ] },
428+
{ include: [ "<__fwd/deque.h>", "private", "<deque>", "public" ] },
428429
{ include: [ "<__fwd/format.h>", "private", "<format>", "public" ] },
429430
{ include: [ "<__fwd/fstream.h>", "private", "<iosfwd>", "public" ] },
430431
{ include: [ "<__fwd/functional.h>", "private", "<functional>", "public" ] },
431432
{ include: [ "<__fwd/ios.h>", "private", "<iosfwd>", "public" ] },
432433
{ include: [ "<__fwd/istream.h>", "private", "<iosfwd>", "public" ] },
433434
{ include: [ "<__fwd/mdspan.h>", "private", "<mdspan>", "public" ] },
435+
{ include: [ "<__fwd/memory.h>", "private", "<memory>", "public" ] },
434436
{ include: [ "<__fwd/memory_resource.h>", "private", "<memory_resource>", "public" ] },
435437
{ include: [ "<__fwd/ostream.h>", "private", "<iosfwd>", "public" ] },
436438
{ include: [ "<__fwd/pair.h>", "private", "<utility>", "public" ] },
439+
{ include: [ "<__fwd/queue.h>", "private", "<queue>", "public" ] },
437440
{ include: [ "<__fwd/span.h>", "private", "<span>", "public" ] },
438441
{ include: [ "<__fwd/sstream.h>", "private", "<iosfwd>", "public" ] },
442+
{ include: [ "<__fwd/stack.h>", "private", "<stack>", "public" ] },
439443
{ include: [ "<__fwd/streambuf.h>", "private", "<iosfwd>", "public" ] },
440444
{ include: [ "<__fwd/string.h>", "private", "<string>", "public" ] },
441445
{ include: [ "<__fwd/string_view.h>", "private", "<string_view>", "public" ] },
442446
{ include: [ "<__fwd/subrange.h>", "private", "<ranges>", "public" ] },
443447
{ include: [ "<__fwd/tuple.h>", "private", "<tuple>", "public" ] },
448+
{ include: [ "<__fwd/vector.h>", "private", "<vector>", "public" ] },
444449
{ include: [ "<__ios/fpos.h>", "private", "<ios>", "public" ] },
445450
{ include: [ "<__iterator/access.h>", "private", "<iterator>", "public" ] },
446451
{ include: [ "<__iterator/advance.h>", "private", "<iterator>", "public" ] },

libcxx/include/module.modulemap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,8 @@ module std_private_debug_utils_strict_weak_ordering_check [system] {
12551255
export std_private_type_traits_is_constant_evaluated
12561256
}
12571257

1258+
module std_private_deque_fwd [system] { header "__fwd/deque.h" }
1259+
12581260
module std_private_exception_exception [system] { header "__exception/exception.h" }
12591261
module std_private_exception_exception_ptr [system] {
12601262
header "__exception/exception_ptr.h"
@@ -1535,6 +1537,7 @@ module std_private_memory_concepts [system] {
15351537
}
15361538
module std_private_memory_construct_at [system] { header "__memory/construct_at.h" }
15371539
module std_private_memory_destruct_n [system] { header "__memory/destruct_n.h" }
1540+
module std_private_memory_fwd [system] { header "__fwd/memory.h" }
15381541
module std_private_memory_pointer_traits [system] { header "__memory/pointer_traits.h" }
15391542
module std_private_memory_ranges_construct_at [system] { header "__memory/ranges_construct_at.h" }
15401543
module std_private_memory_ranges_uninitialized_algorithms [system] {
@@ -1600,6 +1603,8 @@ module std_private_numeric_transform_exclusive_scan [system] { header "__numeric
16001603
module std_private_numeric_transform_inclusive_scan [system] { header "__numeric/transform_inclusive_scan.h" }
16011604
module std_private_numeric_transform_reduce [system] { header "__numeric/transform_reduce.h" }
16021605

1606+
module std_private_queue_fwd [system] { header "__fwd/queue.h" }
1607+
16031608
module std_private_random_bernoulli_distribution [system] { header "__random/bernoulli_distribution.h" }
16041609
module std_private_random_binomial_distribution [system] { header "__random/binomial_distribution.h" }
16051610
module std_private_random_cauchy_distribution [system] { header "__random/cauchy_distribution.h" }
@@ -1737,6 +1742,8 @@ module std_private_ranges_zip_view [system] { header "__ranges
17371742

17381743
module std_private_span_span_fwd [system] { header "__fwd/span.h" }
17391744

1745+
module std_private_stack_fwd [system] { header "__fwd/stack.h" }
1746+
17401747
module std_private_stop_token_atomic_unique_lock [system] { header "__stop_token/atomic_unique_lock.h" }
17411748
module std_private_stop_token_intrusive_list_view [system] { header "__stop_token/intrusive_list_view.h" }
17421749
module std_private_stop_token_intrusive_shared_ptr [system] { header "__stop_token/intrusive_shared_ptr.h" }
@@ -2085,3 +2092,5 @@ module std_private_utility_to_underlying [system] { header "__utility/t
20852092
module std_private_utility_unreachable [system] { header "__utility/unreachable.h" }
20862093

20872094
module std_private_variant_monostate [system] { header "__variant/monostate.h" }
2095+
2096+
module std_private_vector_fwd [system] { header "__fwd/vector.h" }

libcxx/include/queue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ template <class T, class Container, class Compare>
260260
#include <__algorithm/ranges_copy.h>
261261
#include <__config>
262262
#include <__functional/operations.h>
263+
#include <__fwd/deque.h>
264+
#include <__fwd/queue.h>
263265
#include <__iterator/back_insert_iterator.h>
264266
#include <__iterator/iterator_traits.h>
265267
#include <__memory/uses_allocator.h>
@@ -287,9 +289,6 @@ _LIBCPP_PUSH_MACROS
287289

288290
_LIBCPP_BEGIN_NAMESPACE_STD
289291

290-
template <class _Tp, class _Container = deque<_Tp> >
291-
class _LIBCPP_TEMPLATE_VIS queue;
292-
293292
template <class _Tp, class _Container>
294293
_LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
295294

@@ -511,7 +510,7 @@ template <class _Tp, class _Container, class _Alloc>
511510
struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
512511
};
513512

514-
template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
513+
template <class _Tp, class _Container, class _Compare>
515514
class _LIBCPP_TEMPLATE_VIS priority_queue {
516515
public:
517516
typedef _Container container_type;

libcxx/include/stack

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ template <class T, class Container>
115115

116116
#include <__algorithm/ranges_copy.h>
117117
#include <__config>
118+
#include <__fwd/stack.h>
118119
#include <__iterator/back_insert_iterator.h>
119120
#include <__iterator/iterator_traits.h>
120121
#include <__memory/uses_allocator.h>
@@ -142,9 +143,6 @@ _LIBCPP_PUSH_MACROS
142143

143144
_LIBCPP_BEGIN_NAMESPACE_STD
144145

145-
template <class _Tp, class _Container = deque<_Tp> >
146-
class _LIBCPP_TEMPLATE_VIS stack;
147-
148146
template <class _Tp, class _Container>
149147
_LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
150148

libcxx/include/vector

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
325325
#include <__format/formatter_bool.h>
326326
#include <__functional/hash.h>
327327
#include <__functional/unary_function.h>
328+
#include <__fwd/vector.h>
328329
#include <__iterator/advance.h>
329330
#include <__iterator/distance.h>
330331
#include <__iterator/iterator_traits.h>
@@ -357,7 +358,6 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
357358
#include <__utility/swap.h>
358359
#include <climits>
359360
#include <cstring>
360-
#include <iosfwd> // for forward declaration of vector
361361
#include <limits>
362362
#include <stdexcept>
363363
#include <version>
@@ -2989,6 +2989,7 @@ _LIBCPP_POP_MACROS
29892989
# include <atomic>
29902990
# include <concepts>
29912991
# include <cstdlib>
2992+
# include <iosfwd>
29922993
# include <locale>
29932994
# include <tuple>
29942995
# include <type_traits>

libcxx/test/libcxx/transitive_includes/cxx03.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ filesystem type_traits
267267
filesystem version
268268
format array
269269
format cctype
270+
format cerrno
270271
format clocale
271272
format cmath
272273
format cstddef

0 commit comments

Comments
 (0)