[libcxx-commits] [libcxx] a9167c2 - [libc++][Modules] Simplify the __std_clang_module header generation
Ian Anderson via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 17 22:35:00 PDT 2023
Author: Ian Anderson
Date: 2023-08-17T22:34:54-07:00
New Revision: a9167c2e475a60198bb673d9cc22ea8c701e0d91
URL: https://github.com/llvm/llvm-project/commit/a9167c2e475a60198bb673d9cc22ea8c701e0d91
DIFF: https://github.com/llvm/llvm-project/commit/a9167c2e475a60198bb673d9cc22ea8c701e0d91.diff
LOG: [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
Added:
Modified:
libcxx/include/__std_clang_module
libcxx/utils/generate_std_clang_module_header.py
libcxx/utils/libcxx/header_information.py
Removed:
################################################################################
diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module
index 46f50e87515b56..4d02336d30b064 100644
--- a/libcxx/include/__std_clang_module
+++ b/libcxx/include/__std_clang_module
@@ -30,6 +30,12 @@
#include <algorithm>
#include <any>
#include <array>
+#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+# include <atomic>
+#endif
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <barrier>
+#endif
#include <bit>
#include <bitset>
#include <cassert>
@@ -43,7 +49,13 @@
#include <cinttypes>
#include <ciso646>
#include <climits>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <clocale>
+#endif
#include <cmath>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <codecvt>
+#endif
#include <compare>
#include <complex.h>
#include <complex>
@@ -63,6 +75,12 @@
#include <ctime>
#include <ctype.h>
#include <cuchar>
+#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+# include <cwchar>
+#endif
+#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+# include <cwctype>
+#endif
#include <deque>
#include <errno.h>
#include <exception>
@@ -75,6 +93,9 @@
#include <experimental/map>
#include <experimental/memory_resource>
#include <experimental/propagate_const>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <experimental/regex>
+#endif
#include <experimental/set>
#include <experimental/simd>
#include <experimental/string>
@@ -88,14 +109,41 @@
#include <float.h>
#include <format>
#include <forward_list>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <fstream>
+#endif
#include <functional>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <future>
+#endif
#include <initializer_list>
#include <inttypes.h>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <iomanip>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <ios>
+#endif
#include <iosfwd>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <iostream>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <istream>
+#endif
#include <iterator>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <latch>
+#endif
#include <limits.h>
#include <limits>
#include <list>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <locale.h>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <locale>
+#endif
#include <map>
#include <math.h>
#include <mdspan>
@@ -106,28 +154,58 @@
#include <numbers>
#include <numeric>
#include <optional>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <ostream>
+#endif
#include <print>
#include <queue>
#include <random>
#include <ranges>
#include <ratio>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <regex>
+#endif
#include <scoped_allocator>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <semaphore>
+#endif
#include <set>
#include <setjmp.h>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <shared_mutex>
+#endif
#include <source_location>
#include <span>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <sstream>
+#endif
#include <stack>
+#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+# include <stdatomic.h>
+#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdexcept>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <stop_token>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <streambuf>
+#endif
#include <string.h>
#include <string>
#include <string_view>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <strstream>
+#endif
#include <system_error>
#include <tgmath.h>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+# include <thread>
+#endif
#include <tuple>
#include <type_traits>
#include <typeindex>
@@ -140,43 +218,9 @@
#include <variant>
#include <vector>
#include <version>
-
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
-# include <atomic>
-# include <stdatomic.h>
-#endif
-
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-# include <clocale>
-# include <codecvt>
-# include <experimental/regex>
-# include <fstream>
-# include <iomanip>
-# include <ios>
-# include <iostream>
-# include <istream>
-# include <locale.h>
-# include <locale>
-# include <ostream>
-# include <regex>
-# include <sstream>
-# include <streambuf>
-# include <strstream>
-#endif
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-# include <barrier>
-# include <future>
-# include <latch>
-# include <semaphore>
-# include <shared_mutex>
-# include <stop_token>
-# include <thread>
-#endif
-
-#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-# include <cwchar>
-# include <cwctype>
+#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
# include <wchar.h>
+#endif
+#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
# include <wctype.h>
#endif
diff --git a/libcxx/utils/generate_std_clang_module_header.py b/libcxx/utils/generate_std_clang_module_header.py
index bcf0c220b7c59d..afdc9f653c2a25 100644
--- a/libcxx/utils/generate_std_clang_module_header.py
+++ b/libcxx/utils/generate_std_clang_module_header.py
@@ -11,11 +11,7 @@
import libcxx.header_information
-public_headers = libcxx.header_information.public_headers
-header_include_requirements = libcxx.header_information.header_include_requirements
-always_available_headers = frozenset(public_headers).
diff erence(
- *header_include_requirements.values()
-)
+header_restrictions = libcxx.header_information.header_restrictions
libcxx_include_directory = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "include"
@@ -58,25 +54,11 @@
)
# Include the angle brackets in sorting so that <a.h> sorts before <a>
# like check-format wants.
- for include in sorted([f"<{header}>" for header in always_available_headers]):
- std_clang_module_header.write(f"#include {include}\n")
-
- for requirements, headers in sorted(
- header_include_requirements.items(), key=operator.itemgetter(0)
- ):
- std_clang_module_header.write("\n")
- if len(requirements) == 1:
- std_clang_module_header.write("#ifndef ")
- std_clang_module_header.write(requirements[0])
- else:
- std_clang_module_header.write("#if")
- for index, requirement in enumerate(requirements):
- if index > 0:
- std_clang_module_header.write(" &&")
- std_clang_module_header.write(f" !defined({requirement})")
- std_clang_module_header.write("\n")
-
- for include in sorted([f"<{header}>" for header in headers]):
+ for include, header in sorted([(f"<{header}>", header) for header in libcxx.header_information.public_headers]):
+ header_restriction = header_restrictions.get(header)
+ if header_restriction:
+ std_clang_module_header.write(f"#if {header_restriction}\n")
std_clang_module_header.write(f"# include {include}\n")
-
- std_clang_module_header.write("#endif\n")
+ std_clang_module_header.write(f"#endif\n")
+ else:
+ std_clang_module_header.write(f"#include {include}\n")
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index cfeadc90eb4c4e..683fe23638e17c 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -8,6 +8,46 @@
import os, pathlib
+header_restrictions = {
+ # headers with #error directives
+ "atomic": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)",
+ "stdatomic.h": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)",
+
+ # headers with #error directives
+ "ios": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "locale.h": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ # transitive includers of the above headers
+ "clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "experimental/regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "iomanip": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "iostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "istream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "locale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "ostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "sstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+
+ # headers with #error directives
+ "barrier": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "future": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "latch": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "semaphore": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "shared_mutex": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "stop_token": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "thread": "!defined(_LIBCPP_HAS_NO_THREADS)",
+
+ # headers with #error directives
+ "wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ "wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ # transitive includers of the above headers
+ "cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ "cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+}
+
lit_header_restrictions = {
"barrier": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17",
"clocale": "// UNSUPPORTED: no-localization",
@@ -57,52 +97,6 @@
"wctype.h": "// UNSUPPORTED: no-wide-characters",
}
-header_include_requirements = {
- ("_LIBCPP_HAS_NO_ATOMIC_HEADER",): (
- # headers with #error directives
- "atomic",
- # transitive includers of the above headers
- "stdatomic.h",
- ),
- ("_LIBCPP_HAS_NO_LOCALIZATION",): (
- # headers with #error directives
- "ios",
- "locale.h",
- # transitive includers of the above headers
- "clocale",
- "codecvt",
- "experimental/regex",
- "fstream",
- "iomanip",
- "iostream",
- "istream",
- "locale",
- "ostream",
- "regex",
- "sstream",
- "streambuf",
- "strstream",
- ),
- ("_LIBCPP_HAS_NO_THREADS",): (
- # headers with #error directives
- "barrier",
- "future",
- "latch",
- "semaphore",
- "shared_mutex",
- "stop_token",
- "thread",
- ),
- ("_LIBCPP_HAS_NO_WIDE_CHARACTERS",): (
- # headers with #error directives
- "wchar.h",
- "wctype.h",
- # transitive includers of the above headers
- "cwchar",
- "cwctype",
- ),
-}
-
# This table was produced manually, by grepping the TeX source of the Standard's
# library clauses for the string "#include". Each header's synopsis contains
# explicit "#include" directives for its mandatory inclusions.
More information about the libcxx-commits
mailing list