From 0521244b24745ecbd098a8b0e02786f177dcb539 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Wed, 16 Aug 2023 17:02:41 -0700 Subject: [PATCH] [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 --- libcxx/include/__std_clang_module | 118 ++++++++++++++++------- libcxx/utils/generate_std_clang_module_header.py | 34 ++----- libcxx/utils/libcxx/header_information.py | 86 ++++++++--------- 3 files changed, 129 insertions(+), 109 deletions(-) diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module index 46f50e8..4d02336 100644 --- a/libcxx/include/__std_clang_module +++ b/libcxx/include/__std_clang_module @@ -30,6 +30,12 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include #include @@ -43,7 +49,13 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include #include @@ -63,6 +75,12 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# include +#endif #include #include #include @@ -75,6 +93,9 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include #include @@ -88,14 +109,41 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include #include @@ -106,28 +154,58 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +# include +#endif #include #include #include #include #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include +#endif #include #include #include @@ -140,43 +218,9 @@ #include #include #include - -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER -# include -# include -#endif - -#ifndef _LIBCPP_HAS_NO_LOCALIZATION -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#ifndef _LIBCPP_HAS_NO_THREADS -# include -# include -# include -# include -# include -# include -# include -#endif - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include -# include +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) # include +#endif +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) # include #endif diff --git a/libcxx/utils/generate_std_clang_module_header.py b/libcxx/utils/generate_std_clang_module_header.py index bcf0c22..afdc9f6 100644 --- a/libcxx/utils/generate_std_clang_module_header.py +++ b/libcxx/utils/generate_std_clang_module_header.py @@ -11,11 +11,7 @@ import os.path 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).difference( - *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 @@ with open( ) # Include the angle brackets in sorting so that sorts before # 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 3c04f01..169638d 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", @@ -59,52 +99,6 @@ lit_header_restrictions = { "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", - ), -} - private_headers_still_public_in_modules = [ "__assert", "__config", -- 2.7.4