[libc++] Remove <queue> and <stack> includes from <format> (#85520)

This reduces the include time of <format> from 691ms to 556ms.
This commit is contained in:
Nikolas Klauser
2024-03-29 12:06:09 +01:00
committed by GitHub
parent a85569242d
commit 316634ff59
26 changed files with 185 additions and 41 deletions

View File

@@ -430,22 +430,27 @@ set(files
__fwd/array.h
__fwd/bit_reference.h
__fwd/complex.h
__fwd/deque.h
__fwd/format.h
__fwd/fstream.h
__fwd/functional.h
__fwd/ios.h
__fwd/istream.h
__fwd/mdspan.h
__fwd/memory.h
__fwd/memory_resource.h
__fwd/ostream.h
__fwd/pair.h
__fwd/queue.h
__fwd/span.h
__fwd/sstream.h
__fwd/stack.h
__fwd/streambuf.h
__fwd/string.h
__fwd/string_view.h
__fwd/subrange.h
__fwd/tuple.h
__fwd/vector.h
__hash_table
__ios/fpos.h
__iterator/access.h

View File

@@ -18,11 +18,11 @@
#include <__format/concepts.h>
#include <__format/formatter.h>
#include <__format/range_default_formatter.h>
#include <__fwd/queue.h>
#include <__fwd/stack.h>
#include <__ranges/ref_view.h>
#include <__type_traits/is_const.h>
#include <__type_traits/maybe_const.h>
#include <queue>
#include <stack>
_LIBCPP_BEGIN_NAMESPACE_STD

View File

@@ -0,0 +1,26 @@
//===---------------------------------------------------------------------===//
//
// 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___FWD_DEQUE_H
#define _LIBCPP___FWD_DEQUE_H
#include <__config>
#include <__fwd/memory.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS deque;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_DEQUE_H

View File

@@ -0,0 +1,25 @@
//===---------------------------------------------------------------------===//
//
// 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___FWD_MEMORY_H
#define _LIBCPP___FWD_MEMORY_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS allocator;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_MEMORY_H

View File

@@ -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
//
//===---------------------------------------------------------------------===//
#ifndef _LIBCPP___FWD_QUEUE_H
#define _LIBCPP___FWD_QUEUE_H
#include <__config>
#include <__functional/operations.h>
#include <__fwd/deque.h>
#include <__fwd/vector.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Container = deque<_Tp> >
class _LIBCPP_TEMPLATE_VIS queue;
template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
class _LIBCPP_TEMPLATE_VIS priority_queue;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_QUEUE_H

View File

@@ -10,6 +10,7 @@
#define _LIBCPP___FWD_SSTREAM_H
#include <__config>
#include <__fwd/memory.h>
#include <__fwd/string.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@@ -0,0 +1,26 @@
//===---------------------------------------------------------------------===//
//
// 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___FWD_STACK_H
#define _LIBCPP___FWD_STACK_H
#include <__config>
#include <__fwd/deque.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Container = deque<_Tp> >
class _LIBCPP_TEMPLATE_VIS stack;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_STACK_H

View File

@@ -11,6 +11,7 @@
#include <__availability>
#include <__config>
#include <__fwd/memory.h>
#include <__fwd/memory_resource.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -39,9 +40,6 @@ template <>
struct char_traits<wchar_t>;
#endif
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS allocator;
template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_string;

View File

@@ -0,0 +1,26 @@
//===---------------------------------------------------------------------===//
//
// 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___FWD_VECTOR_H
#define _LIBCPP___FWD_VECTOR_H
#include <__config>
#include <__fwd/memory.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Alloc = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS vector;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_VECTOR_H

View File

@@ -192,6 +192,7 @@ template <class T, class Allocator, class Predicate>
#include <__availability>
#include <__config>
#include <__format/enable_insertable.h>
#include <__fwd/deque.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
@@ -244,9 +245,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS deque;
template <class _ValueType, class _DiffType>
struct __deque_block_size {
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;

View File

@@ -223,6 +223,8 @@ namespace std {
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <locale>
# include <queue>
# include <stack>
#endif
#endif // _LIBCPP_FORMAT

View File

@@ -110,6 +110,7 @@ using wosyncstream = basic_osyncstream<wchar_t>; // C++20
#include <__fwd/fstream.h>
#include <__fwd/ios.h>
#include <__fwd/istream.h>
#include <__fwd/memory.h>
#include <__fwd/ostream.h>
#include <__fwd/sstream.h>
#include <__fwd/streambuf.h>
@@ -162,10 +163,6 @@ using wosyncstream = basic_osyncstream<wchar_t>;
#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
// Include other forward declarations here
template <class _Tp, class _Alloc = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS vector;
template <class _CharT, class _Traits>
class __save_flags {
typedef basic_ios<_CharT, _Traits> __stream_type;

View File

@@ -425,22 +425,27 @@
{ include: [ "<__fwd/bit_reference.h>", "private", "<bitset>", "public" ] },
{ include: [ "<__fwd/bit_reference.h>", "private", "<vector>", "public" ] },
{ include: [ "<__fwd/complex.h>", "private", "<complex>", "public" ] },
{ include: [ "<__fwd/deque.h>", "private", "<deque>", "public" ] },
{ include: [ "<__fwd/format.h>", "private", "<format>", "public" ] },
{ include: [ "<__fwd/fstream.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/functional.h>", "private", "<functional>", "public" ] },
{ include: [ "<__fwd/ios.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/istream.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/mdspan.h>", "private", "<mdspan>", "public" ] },
{ include: [ "<__fwd/memory.h>", "private", "<memory>", "public" ] },
{ include: [ "<__fwd/memory_resource.h>", "private", "<memory_resource>", "public" ] },
{ include: [ "<__fwd/ostream.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/pair.h>", "private", "<utility>", "public" ] },
{ include: [ "<__fwd/queue.h>", "private", "<queue>", "public" ] },
{ include: [ "<__fwd/span.h>", "private", "<span>", "public" ] },
{ include: [ "<__fwd/sstream.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/stack.h>", "private", "<stack>", "public" ] },
{ include: [ "<__fwd/streambuf.h>", "private", "<iosfwd>", "public" ] },
{ include: [ "<__fwd/string.h>", "private", "<string>", "public" ] },
{ include: [ "<__fwd/string_view.h>", "private", "<string_view>", "public" ] },
{ include: [ "<__fwd/subrange.h>", "private", "<ranges>", "public" ] },
{ include: [ "<__fwd/tuple.h>", "private", "<tuple>", "public" ] },
{ include: [ "<__fwd/vector.h>", "private", "<vector>", "public" ] },
{ include: [ "<__ios/fpos.h>", "private", "<ios>", "public" ] },
{ include: [ "<__iterator/access.h>", "private", "<iterator>", "public" ] },
{ include: [ "<__iterator/advance.h>", "private", "<iterator>", "public" ] },

View File

@@ -1255,6 +1255,8 @@ module std_private_debug_utils_strict_weak_ordering_check [system] {
export std_private_type_traits_is_constant_evaluated
}
module std_private_deque_fwd [system] { header "__fwd/deque.h" }
module std_private_exception_exception [system] { header "__exception/exception.h" }
module std_private_exception_exception_ptr [system] {
header "__exception/exception_ptr.h"
@@ -1535,6 +1537,7 @@ module std_private_memory_concepts [system] {
}
module std_private_memory_construct_at [system] { header "__memory/construct_at.h" }
module std_private_memory_destruct_n [system] { header "__memory/destruct_n.h" }
module std_private_memory_fwd [system] { header "__fwd/memory.h" }
module std_private_memory_pointer_traits [system] { header "__memory/pointer_traits.h" }
module std_private_memory_ranges_construct_at [system] { header "__memory/ranges_construct_at.h" }
module std_private_memory_ranges_uninitialized_algorithms [system] {
@@ -1600,6 +1603,8 @@ module std_private_numeric_transform_exclusive_scan [system] { header "__numeric
module std_private_numeric_transform_inclusive_scan [system] { header "__numeric/transform_inclusive_scan.h" }
module std_private_numeric_transform_reduce [system] { header "__numeric/transform_reduce.h" }
module std_private_queue_fwd [system] { header "__fwd/queue.h" }
module std_private_random_bernoulli_distribution [system] { header "__random/bernoulli_distribution.h" }
module std_private_random_binomial_distribution [system] { header "__random/binomial_distribution.h" }
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
module std_private_span_span_fwd [system] { header "__fwd/span.h" }
module std_private_stack_fwd [system] { header "__fwd/stack.h" }
module std_private_stop_token_atomic_unique_lock [system] { header "__stop_token/atomic_unique_lock.h" }
module std_private_stop_token_intrusive_list_view [system] { header "__stop_token/intrusive_list_view.h" }
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
module std_private_utility_unreachable [system] { header "__utility/unreachable.h" }
module std_private_variant_monostate [system] { header "__variant/monostate.h" }
module std_private_vector_fwd [system] { header "__fwd/vector.h" }

View File

@@ -260,6 +260,8 @@ template <class T, class Container, class Compare>
#include <__algorithm/ranges_copy.h>
#include <__config>
#include <__functional/operations.h>
#include <__fwd/deque.h>
#include <__fwd/queue.h>
#include <__iterator/back_insert_iterator.h>
#include <__iterator/iterator_traits.h>
#include <__memory/uses_allocator.h>
@@ -287,9 +289,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Container = deque<_Tp> >
class _LIBCPP_TEMPLATE_VIS queue;
template <class _Tp, class _Container>
_LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
@@ -511,7 +510,7 @@ template <class _Tp, class _Container, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
};
template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
template <class _Tp, class _Container, class _Compare>
class _LIBCPP_TEMPLATE_VIS priority_queue {
public:
typedef _Container container_type;

View File

@@ -115,6 +115,7 @@ template <class T, class Container>
#include <__algorithm/ranges_copy.h>
#include <__config>
#include <__fwd/stack.h>
#include <__iterator/back_insert_iterator.h>
#include <__iterator/iterator_traits.h>
#include <__memory/uses_allocator.h>
@@ -142,9 +143,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Container = deque<_Tp> >
class _LIBCPP_TEMPLATE_VIS stack;
template <class _Tp, class _Container>
_LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);

View File

@@ -325,6 +325,7 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
#include <__format/formatter_bool.h>
#include <__functional/hash.h>
#include <__functional/unary_function.h>
#include <__fwd/vector.h>
#include <__iterator/advance.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
@@ -357,7 +358,6 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
#include <__utility/swap.h>
#include <climits>
#include <cstring>
#include <iosfwd> // for forward declaration of vector
#include <limits>
#include <stdexcept>
#include <version>
@@ -2989,6 +2989,7 @@ _LIBCPP_POP_MACROS
# include <atomic>
# include <concepts>
# include <cstdlib>
# include <iosfwd>
# include <locale>
# include <tuple>
# include <type_traits>

View File

@@ -267,6 +267,7 @@ filesystem type_traits
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
1 algorithm atomic
267 filesystem version
268 format array
269 format cctype
270 format cerrno
271 format clocale
272 format cmath
273 format cstddef

View File

@@ -268,6 +268,7 @@ filesystem type_traits
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
1 algorithm atomic
268 filesystem version
269 format array
270 format cctype
271 format cerrno
272 format clocale
273 format cmath
274 format cstddef

View File

@@ -270,6 +270,7 @@ filesystem type_traits
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
1 algorithm atomic
270 filesystem version
271 format array
272 format cctype
273 format cerrno
274 format clocale
275 format cmath
276 format cstddef

View File

@@ -270,6 +270,7 @@ filesystem type_traits
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
1 algorithm atomic
270 filesystem version
271 format array
272 format cctype
273 format cerrno
274 format clocale
275 format cmath
276 format cstddef

View File

@@ -281,6 +281,7 @@ filesystem type_traits
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
1 algorithm atomic
281 filesystem version
282 format array
283 format cctype
284 format cerrno
285 format clocale
286 format cmath
287 format cstddef

View File

@@ -190,6 +190,7 @@ filesystem string_view
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
@@ -201,8 +202,6 @@ format initializer_list
format limits
format new
format optional
format queue
format stack
format stdexcept
format string
format string_view
@@ -680,7 +679,6 @@ vector cstdlib
vector cstring
vector cwchar
vector initializer_list
vector iosfwd
vector limits
vector new
vector stdexcept
1 algorithm climits
190 filesystem version
191 format array
192 format cctype
193 format cerrno
194 format clocale
195 format cmath
196 format cstddef
202 format limits
203 format new
204 format optional
format queue
format stack
205 format stdexcept
206 format string
207 format string_view
679 vector cstring
680 vector cwchar
681 vector initializer_list
vector iosfwd
682 vector limits
683 vector new
684 vector stdexcept

View File

@@ -190,6 +190,7 @@ filesystem string_view
filesystem version
format array
format cctype
format cerrno
format clocale
format cmath
format cstddef
@@ -201,8 +202,6 @@ format initializer_list
format limits
format new
format optional
format queue
format stack
format stdexcept
format string
format string_view
@@ -680,7 +679,6 @@ vector cstdlib
vector cstring
vector cwchar
vector initializer_list
vector iosfwd
vector limits
vector new
vector stdexcept
1 algorithm climits
190 filesystem version
191 format array
192 format cctype
193 format cerrno
194 format clocale
195 format cmath
196 format cstddef
202 format limits
203 format new
204 format optional
format queue
format stack
205 format stdexcept
206 format string
207 format string_view
679 vector cstring
680 vector cwchar
681 vector initializer_list
vector iosfwd
682 vector limits
683 vector new
684 vector stdexcept

View File

@@ -14,25 +14,20 @@
// -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
//
#include <deque>
#include <iterator>
#include <cassert>
#include <cstddef>
#include <vector>
int main(int, char**) {
// Test the explicit deduction guides
// TODO: Should there be tests for explicit deduction guides?
int main(int, char**)
{
// Test the explicit deduction guides
// Test the implicit deduction guides
{
// vector (allocator &)
std::vector vec((std::allocator<int>())); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'vector'}}
// Note: The extra parens are necessary, since otherwise clang decides it is a function declaration.
// Also, we can't use {} instead of parens, because that constructs a
// deque<allocator<int>, allocator<allocator<int>>>
}
// Test the implicit deduction guides
{
// vector (allocator &)
// expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'vector'}}
std::vector vec(std::allocator< int>{});
}
return 0;
}

View File

@@ -16,6 +16,7 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "test_macros.h"
#if TEST_STD_VER >= 23