Skip to content

Commit 0521244

Browse files
ian-twilightcodertru
authored andcommitted
[libc++][Modules] Simplify the __std_clang_module header generation
Post review feedback on D157364. Don't section the __std_clang_module header by macro, put the headers in alphabetical order and repeat the macro guards. Restore header_information.header_restrictions. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D158133 # Conflicts: # libcxx/utils/libcxx/header_information.py
1 parent 5e2c522 commit 0521244

File tree

3 files changed

+129
-109
lines changed

3 files changed

+129
-109
lines changed

libcxx/include/__std_clang_module

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
#include <algorithm>
3131
#include <any>
3232
#include <array>
33+
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
34+
# include <atomic>
35+
#endif
36+
#if !defined(_LIBCPP_HAS_NO_THREADS)
37+
# include <barrier>
38+
#endif
3339
#include <bit>
3440
#include <bitset>
3541
#include <cassert>
@@ -43,7 +49,13 @@
4349
#include <cinttypes>
4450
#include <ciso646>
4551
#include <climits>
52+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
53+
# include <clocale>
54+
#endif
4655
#include <cmath>
56+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
57+
# include <codecvt>
58+
#endif
4759
#include <compare>
4860
#include <complex.h>
4961
#include <complex>
@@ -63,6 +75,12 @@
6375
#include <ctime>
6476
#include <ctype.h>
6577
#include <cuchar>
78+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
79+
# include <cwchar>
80+
#endif
81+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
82+
# include <cwctype>
83+
#endif
6684
#include <deque>
6785
#include <errno.h>
6886
#include <exception>
@@ -75,6 +93,9 @@
7593
#include <experimental/map>
7694
#include <experimental/memory_resource>
7795
#include <experimental/propagate_const>
96+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
97+
# include <experimental/regex>
98+
#endif
7899
#include <experimental/set>
79100
#include <experimental/simd>
80101
#include <experimental/string>
@@ -88,14 +109,41 @@
88109
#include <float.h>
89110
#include <format>
90111
#include <forward_list>
112+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
113+
# include <fstream>
114+
#endif
91115
#include <functional>
116+
#if !defined(_LIBCPP_HAS_NO_THREADS)
117+
# include <future>
118+
#endif
92119
#include <initializer_list>
93120
#include <inttypes.h>
121+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
122+
# include <iomanip>
123+
#endif
124+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
125+
# include <ios>
126+
#endif
94127
#include <iosfwd>
128+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
129+
# include <iostream>
130+
#endif
131+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
132+
# include <istream>
133+
#endif
95134
#include <iterator>
135+
#if !defined(_LIBCPP_HAS_NO_THREADS)
136+
# include <latch>
137+
#endif
96138
#include <limits.h>
97139
#include <limits>
98140
#include <list>
141+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
142+
# include <locale.h>
143+
#endif
144+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
145+
# include <locale>
146+
#endif
99147
#include <map>
100148
#include <math.h>
101149
#include <mdspan>
@@ -106,28 +154,58 @@
106154
#include <numbers>
107155
#include <numeric>
108156
#include <optional>
157+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
158+
# include <ostream>
159+
#endif
109160
#include <print>
110161
#include <queue>
111162
#include <random>
112163
#include <ranges>
113164
#include <ratio>
165+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
166+
# include <regex>
167+
#endif
114168
#include <scoped_allocator>
169+
#if !defined(_LIBCPP_HAS_NO_THREADS)
170+
# include <semaphore>
171+
#endif
115172
#include <set>
116173
#include <setjmp.h>
174+
#if !defined(_LIBCPP_HAS_NO_THREADS)
175+
# include <shared_mutex>
176+
#endif
117177
#include <source_location>
118178
#include <span>
179+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
180+
# include <sstream>
181+
#endif
119182
#include <stack>
183+
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
184+
# include <stdatomic.h>
185+
#endif
120186
#include <stdbool.h>
121187
#include <stddef.h>
122188
#include <stdexcept>
123189
#include <stdint.h>
124190
#include <stdio.h>
125191
#include <stdlib.h>
192+
#if !defined(_LIBCPP_HAS_NO_THREADS)
193+
# include <stop_token>
194+
#endif
195+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
196+
# include <streambuf>
197+
#endif
126198
#include <string.h>
127199
#include <string>
128200
#include <string_view>
201+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
202+
# include <strstream>
203+
#endif
129204
#include <system_error>
130205
#include <tgmath.h>
206+
#if !defined(_LIBCPP_HAS_NO_THREADS)
207+
# include <thread>
208+
#endif
131209
#include <tuple>
132210
#include <type_traits>
133211
#include <typeindex>
@@ -140,43 +218,9 @@
140218
#include <variant>
141219
#include <vector>
142220
#include <version>
143-
144-
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
145-
# include <atomic>
146-
# include <stdatomic.h>
147-
#endif
148-
149-
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
150-
# include <clocale>
151-
# include <codecvt>
152-
# include <experimental/regex>
153-
# include <fstream>
154-
# include <iomanip>
155-
# include <ios>
156-
# include <iostream>
157-
# include <istream>
158-
# include <locale.h>
159-
# include <locale>
160-
# include <ostream>
161-
# include <regex>
162-
# include <sstream>
163-
# include <streambuf>
164-
# include <strstream>
165-
#endif
166-
167-
#ifndef _LIBCPP_HAS_NO_THREADS
168-
# include <barrier>
169-
# include <future>
170-
# include <latch>
171-
# include <semaphore>
172-
# include <shared_mutex>
173-
# include <stop_token>
174-
# include <thread>
175-
#endif
176-
177-
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
178-
# include <cwchar>
179-
# include <cwctype>
221+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
180222
# include <wchar.h>
223+
#endif
224+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
181225
# include <wctype.h>
182226
#endif

libcxx/utils/generate_std_clang_module_header.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111

1212
import libcxx.header_information
1313

14-
public_headers = libcxx.header_information.public_headers
15-
header_include_requirements = libcxx.header_information.header_include_requirements
16-
always_available_headers = frozenset(public_headers).difference(
17-
*header_include_requirements.values()
18-
)
14+
header_restrictions = libcxx.header_information.header_restrictions
1915

2016
libcxx_include_directory = os.path.join(
2117
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "include"
@@ -58,25 +54,11 @@
5854
)
5955
# Include the angle brackets in sorting so that <a.h> sorts before <a>
6056
# like check-format wants.
61-
for include in sorted([f"<{header}>" for header in always_available_headers]):
62-
std_clang_module_header.write(f"#include {include}\n")
63-
64-
for requirements, headers in sorted(
65-
header_include_requirements.items(), key=operator.itemgetter(0)
66-
):
67-
std_clang_module_header.write("\n")
68-
if len(requirements) == 1:
69-
std_clang_module_header.write("#ifndef ")
70-
std_clang_module_header.write(requirements[0])
71-
else:
72-
std_clang_module_header.write("#if")
73-
for index, requirement in enumerate(requirements):
74-
if index > 0:
75-
std_clang_module_header.write(" &&")
76-
std_clang_module_header.write(f" !defined({requirement})")
77-
std_clang_module_header.write("\n")
78-
79-
for include in sorted([f"<{header}>" for header in headers]):
57+
for include, header in sorted([(f"<{header}>", header) for header in libcxx.header_information.public_headers]):
58+
header_restriction = header_restrictions.get(header)
59+
if header_restriction:
60+
std_clang_module_header.write(f"#if {header_restriction}\n")
8061
std_clang_module_header.write(f"# include {include}\n")
81-
82-
std_clang_module_header.write("#endif\n")
62+
std_clang_module_header.write(f"#endif\n")
63+
else:
64+
std_clang_module_header.write(f"#include {include}\n")

libcxx/utils/libcxx/header_information.py

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@
88

99
import os, pathlib
1010

11+
header_restrictions = {
12+
# headers with #error directives
13+
"atomic": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)",
14+
"stdatomic.h": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)",
15+
16+
# headers with #error directives
17+
"ios": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
18+
"locale.h": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
19+
# transitive includers of the above headers
20+
"clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
21+
"codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
22+
"experimental/regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
23+
"fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
24+
"iomanip": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
25+
"iostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
26+
"istream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
27+
"locale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
28+
"ostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
29+
"regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
30+
"sstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
31+
"streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
32+
"strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
33+
34+
# headers with #error directives
35+
"barrier": "!defined(_LIBCPP_HAS_NO_THREADS)",
36+
"future": "!defined(_LIBCPP_HAS_NO_THREADS)",
37+
"latch": "!defined(_LIBCPP_HAS_NO_THREADS)",
38+
"semaphore": "!defined(_LIBCPP_HAS_NO_THREADS)",
39+
"shared_mutex": "!defined(_LIBCPP_HAS_NO_THREADS)",
40+
"stop_token": "!defined(_LIBCPP_HAS_NO_THREADS)",
41+
"thread": "!defined(_LIBCPP_HAS_NO_THREADS)",
42+
43+
# headers with #error directives
44+
"wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
45+
"wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
46+
# transitive includers of the above headers
47+
"cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
48+
"cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
49+
}
50+
1151
lit_header_restrictions = {
1252
"barrier": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17",
1353
"clocale": "// UNSUPPORTED: no-localization",
@@ -59,52 +99,6 @@
5999
"wctype.h": "// UNSUPPORTED: no-wide-characters",
60100
}
61101

62-
header_include_requirements = {
63-
("_LIBCPP_HAS_NO_ATOMIC_HEADER",): (
64-
# headers with #error directives
65-
"atomic",
66-
# transitive includers of the above headers
67-
"stdatomic.h",
68-
),
69-
("_LIBCPP_HAS_NO_LOCALIZATION",): (
70-
# headers with #error directives
71-
"ios",
72-
"locale.h",
73-
# transitive includers of the above headers
74-
"clocale",
75-
"codecvt",
76-
"experimental/regex",
77-
"fstream",
78-
"iomanip",
79-
"iostream",
80-
"istream",
81-
"locale",
82-
"ostream",
83-
"regex",
84-
"sstream",
85-
"streambuf",
86-
"strstream",
87-
),
88-
("_LIBCPP_HAS_NO_THREADS",): (
89-
# headers with #error directives
90-
"barrier",
91-
"future",
92-
"latch",
93-
"semaphore",
94-
"shared_mutex",
95-
"stop_token",
96-
"thread",
97-
),
98-
("_LIBCPP_HAS_NO_WIDE_CHARACTERS",): (
99-
# headers with #error directives
100-
"wchar.h",
101-
"wctype.h",
102-
# transitive includers of the above headers
103-
"cwchar",
104-
"cwctype",
105-
),
106-
}
107-
108102
private_headers_still_public_in_modules = [
109103
"__assert",
110104
"__config",

0 commit comments

Comments
 (0)