Skip to content

[libc++][modules] Adds std.compat module. #71438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2023

Conversation

mordante
Copy link
Member

@mordante mordante commented Nov 6, 2023

This adds the std.compat module. The patch contains a bit of refactoring to avoid code duplication between the std and std.compat module.

Implements parts of

  • P2465R3 Standard Library Modules std and std.compat

@mordante mordante requested a review from a team as a code owner November 6, 2023 20:02
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

Changes

This adds the std.compat module. The patch contains a bit of refactoring to avoid code duplication between the std and std.compat module.

Implements parts of

  • P2465R3 Standard Library Modules std and std.compat

Patch is 80.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71438.diff

34 Files Affected:

  • (modified) libcxx/modules/CMakeLists.txt (+40-1)
  • (modified) libcxx/modules/CMakeLists.txt.in (+24)
  • (added) libcxx/modules/std.compat.cppm.in (+202)
  • (added) libcxx/modules/std.compat/cassert.inc (+12)
  • (added) libcxx/modules/std.compat/cctype.inc (+25)
  • (added) libcxx/modules/std.compat/cerrno.inc (+12)
  • (added) libcxx/modules/std.compat/cfenv.inc (+29)
  • (added) libcxx/modules/std.compat/cfloat.inc (+12)
  • (added) libcxx/modules/std.compat/cinttypes.inc (+25)
  • (added) libcxx/modules/std.compat/climits.inc (+12)
  • (added) libcxx/modules/std.compat/clocale.inc (+17)
  • (added) libcxx/modules/std.compat/cmath.inc (+268)
  • (added) libcxx/modules/std.compat/csetjmp.inc (+13)
  • (added) libcxx/modules/std.compat/csignal.inc (+17)
  • (added) libcxx/modules/std.compat/cstdarg.inc (+10)
  • (added) libcxx/modules/std.compat/cstddef.inc (+22)
  • (added) libcxx/modules/std.compat/cstdint.inc (+50)
  • (added) libcxx/modules/std.compat/cstdio.inc (+61)
  • (added) libcxx/modules/std.compat/cstdlib.inc (+72)
  • (added) libcxx/modules/std.compat/cstring.inc (+36)
  • (added) libcxx/modules/std.compat/ctime.inc (+28)
  • (added) libcxx/modules/std.compat/cuchar.inc (+28)
  • (added) libcxx/modules/std.compat/cwchar.inc (+80)
  • (added) libcxx/modules/std.compat/cwctype.inc (+35)
  • (modified) libcxx/modules/std.cppm.in (+21-21)
  • (modified) libcxx/test/libcxx/module_std.gen.py (+11-235)
  • (added) libcxx/test/libcxx/module_std_compat.gen.py (+62)
  • (modified) libcxx/test/lit.local.cfg (+14)
  • (added) libcxx/test/std/modules/std.compat.pass.cpp (+21)
  • (modified) libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp (+112-17)
  • (modified) libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.hpp (+33-1)
  • (modified) libcxx/utils/CMakeLists.txt (+12-1)
  • (renamed) libcxx/utils/generate_libcxx_cppm_in.py (+43-28)
  • (added) libcxx/utils/libcxx/test/modules.py (+307)
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 395226fb3728700..fae6448a7eec84b 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -118,6 +118,30 @@ set(LIBCXX_MODULE_STD_SOURCES
   std/version.inc
 )
 
+set(LIBCXX_MODULE_STD_COMPAT_SOURCES
+  std.compat/cassert.inc
+  std.compat/cctype.inc
+  std.compat/cerrno.inc
+  std.compat/cfenv.inc
+  std.compat/cfloat.inc
+  std.compat/cinttypes.inc
+  std.compat/climits.inc
+  std.compat/clocale.inc
+  std.compat/cmath.inc
+  std.compat/csetjmp.inc
+  std.compat/csignal.inc
+  std.compat/cstdarg.inc
+  std.compat/cstddef.inc
+  std.compat/cstdint.inc
+  std.compat/cstdio.inc
+  std.compat/cstdlib.inc
+  std.compat/cstring.inc
+  std.compat/ctime.inc
+  std.compat/cuchar.inc
+  std.compat/cwchar.inc
+  std.compat/cwctype.inc
+)
+
 # TODO MODULES the CMakeLists.txt in the install directory is only temporary
 # When that is removed the configured file can use the substitution
 # LIBCXX_GENERATED_INCLUDE_TARGET_DIR avoiding this set.
@@ -154,10 +178,25 @@ configure_file(
   @ONLY
 )
 
+set(LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES)
+foreach(file ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
+  set(
+    LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES
+    "${LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES}#include \"${file}\"\n"
+  )
+endforeach()
+
+configure_file(
+  "std.compat.cppm.in"
+  "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm"
+  @ONLY
+)
+
 set(_all_modules)
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
-foreach(file ${LIBCXX_MODULE_STD_SOURCES})
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
+foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
   set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
   set(dst "${LIBCXX_GENERATED_MODULE_DIR}/${file}")
   add_custom_command(OUTPUT ${dst}
diff --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
index dca3b25155a5af4..0ada1b165c99700 100644
--- a/libcxx/modules/CMakeLists.txt.in
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -29,6 +29,8 @@ macro(compile_define_if condition def)
   endif()
 endmacro()
 
+### STD
+
 add_library(std)
 target_sources(std
   PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
@@ -52,3 +54,25 @@ set_target_properties(std
   PROPERTIES
     OUTPUT_NAME   "c++std"
 )
+
+### STD.COMPAT
+
+add_library(std.compat)
+target_sources(std.compat
+  PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+    std.compat.cppm
+)
+
+target_include_directories(std.compat SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+target_compile_options(std.compat
+  PUBLIC
+    -nostdinc++
+    -Wno-reserved-module-identifier
+    -Wno-reserved-user-defined-literal
+    @LIBCXX_COMPILE_FLAGS@
+)
+set_target_properties(std.compat
+  PROPERTIES
+    OUTPUT_NAME   "c++std.compat"
+)
diff --git a/libcxx/modules/std.compat.cppm.in b/libcxx/modules/std.compat.cppm.in
new file mode 100644
index 000000000000000..2fc98b86df11e10
--- /dev/null
+++ b/libcxx/modules/std.compat.cppm.in
@@ -0,0 +1,202 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// WARNING, this entire header is generated by
+// utils/generate_libcxx_cppm_in.py
+// DO NOT MODIFY!
+
+module;
+
+#include <__config>
+
+// The headers of Table 24: C++ library headers [tab:headers.cpp]
+// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
+#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>
+#include <cctype>
+#include <cerrno>
+#include <cfenv>
+#include <cfloat>
+#include <charconv>
+#include <chrono>
+#include <cinttypes>
+#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>
+#include <concepts>
+#include <condition_variable>
+#include <coroutine>
+#include <csetjmp>
+#include <csignal>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#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 <exception>
+#include <execution>
+#include <expected>
+#include <filesystem>
+#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>
+#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>
+#include <list>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  include <locale>
+#endif
+#include <map>
+#include <mdspan>
+#include <memory>
+#include <memory_resource>
+#include <mutex>
+#include <new>
+#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>
+#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>
+#include <stdexcept>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+#  include <stop_token>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  include <streambuf>
+#endif
+#include <string>
+#include <string_view>
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  include <strstream>
+#endif
+#include <system_error>
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+#  include <thread>
+#endif
+#include <tuple>
+#include <type_traits>
+#include <typeindex>
+#include <typeinfo>
+#include <unordered_map>
+#include <unordered_set>
+#include <utility>
+#include <valarray>
+#include <variant>
+#include <vector>
+#include <version>
+
+// *** Headers not yet available ***
+#if __has_include(<flat_map>)
+#  error "update the header information for <flat_map> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<flat_map>)
+#if __has_include(<flat_set>)
+#  error "update the header information for <flat_set> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<flat_set>)
+#if __has_include(<generator>)
+#  error "update the header information for <generator> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<generator>)
+#if __has_include(<hazard_pointer>)
+#  error "update the header information for <hazard_pointer> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<hazard_pointer>)
+#if __has_include(<rcu>)
+#  error "update the header information for <rcu> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<rcu>)
+#if __has_include(<spanstream>)
+#  error "update the header information for <spanstream> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<spanstream>)
+#if __has_include(<stacktrace>)
+#  error "update the header information for <stacktrace> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<stacktrace>)
+#if __has_include(<stdfloat>)
+#  error "update the header information for <stdfloat> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<stdfloat>)
+#if __has_include(<syncstream>)
+#  error "update the header information for <syncstream> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<syncstream>)
+#if __has_include(<text_encoding>)
+#  error "update the header information for <text_encoding> in headers_not_available in utils/libcxx/header_information.py"
+#endif // __has_include(<text_encoding>)
+
+export module std.compat;
+
+@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
+@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
\ No newline at end of file
diff --git a/libcxx/modules/std.compat/cassert.inc b/libcxx/modules/std.compat/cassert.inc
new file mode 100644
index 000000000000000..ac0533d14e9a9a4
--- /dev/null
+++ b/libcxx/modules/std.compat/cassert.inc
@@ -0,0 +1,12 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  // This module exports nothing.
+} // export
diff --git a/libcxx/modules/std.compat/cctype.inc b/libcxx/modules/std.compat/cctype.inc
new file mode 100644
index 000000000000000..56fb45a374a510a
--- /dev/null
+++ b/libcxx/modules/std.compat/cctype.inc
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  using ::isalnum;
+  using ::isalpha;
+  using ::isblank;
+  using ::iscntrl;
+  using ::isdigit;
+  using ::isgraph;
+  using ::islower;
+  using ::isprint;
+  using ::ispunct;
+  using ::isspace;
+  using ::isupper;
+  using ::isxdigit;
+  using ::tolower;
+  using ::toupper;
+} // export
diff --git a/libcxx/modules/std.compat/cerrno.inc b/libcxx/modules/std.compat/cerrno.inc
new file mode 100644
index 000000000000000..ac0533d14e9a9a4
--- /dev/null
+++ b/libcxx/modules/std.compat/cerrno.inc
@@ -0,0 +1,12 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  // This module exports nothing.
+} // export
diff --git a/libcxx/modules/std.compat/cfenv.inc b/libcxx/modules/std.compat/cfenv.inc
new file mode 100644
index 000000000000000..50128463d6a9143
--- /dev/null
+++ b/libcxx/modules/std.compat/cfenv.inc
@@ -0,0 +1,29 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  // types
+  using ::fenv_t;
+  using ::fexcept_t;
+
+  // functions
+  using ::feclearexcept;
+  using ::fegetexceptflag;
+  using ::feraiseexcept;
+  using ::fesetexceptflag;
+  using ::fetestexcept;
+
+  using ::fegetround;
+  using ::fesetround;
+
+  using ::fegetenv;
+  using ::feholdexcept;
+  using ::fesetenv;
+  using ::feupdateenv;
+} // export
diff --git a/libcxx/modules/std.compat/cfloat.inc b/libcxx/modules/std.compat/cfloat.inc
new file mode 100644
index 000000000000000..ac0533d14e9a9a4
--- /dev/null
+++ b/libcxx/modules/std.compat/cfloat.inc
@@ -0,0 +1,12 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  // This module exports nothing.
+} // export
diff --git a/libcxx/modules/std.compat/cinttypes.inc b/libcxx/modules/std.compat/cinttypes.inc
new file mode 100644
index 000000000000000..a64c088d0d6f881
--- /dev/null
+++ b/libcxx/modules/std.compat/cinttypes.inc
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  using ::imaxdiv_t;
+
+  using ::imaxabs;
+  using ::imaxdiv;
+  using ::strtoimax;
+  using ::strtoumax;
+  using ::wcstoimax;
+  using ::wcstoumax;
+
+  // abs is conditionally here, but always present in cmath.cppm. To avoid
+  // conflicing declarations omit the using here.
+
+  // div is conditionally here, but always present in cstdlib.cppm. To avoid
+  // conflicing declarations omit the using here.
+} // export
diff --git a/libcxx/modules/std.compat/climits.inc b/libcxx/modules/std.compat/climits.inc
new file mode 100644
index 000000000000000..ac0533d14e9a9a4
--- /dev/null
+++ b/libcxx/modules/std.compat/climits.inc
@@ -0,0 +1,12 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  // This module exports nothing.
+} // export
diff --git a/libcxx/modules/std.compat/clocale.inc b/libcxx/modules/std.compat/clocale.inc
new file mode 100644
index 000000000000000..1a975c560a496d7
--- /dev/null
+++ b/libcxx/modules/std.compat/clocale.inc
@@ -0,0 +1,17 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+  using ::lconv _LIBCPP_USING_IF_EXISTS;
+
+  using ::localeconv _LIBCPP_USING_IF_EXISTS;
+  using ::setlocale _LIBCPP_USING_IF_EXISTS;
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
+} // export
diff --git a/libcxx/modules/std.compat/cmath.inc b/libcxx/modules/std.compat/cmath.inc
new file mode 100644
index 000000000000000..de5379275c5fae6
--- /dev/null
+++ b/libcxx/modules/std.compat/cmath.inc
@@ -0,0 +1,268 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+export {
+  using ::double_t;
+  using ::float_t;
+
+  using ::acos;
+  using ::acosf;
+  using ::acosl;
+
+  using ::asin;
+  using ::asinf;
+  using ::asinl;
+
+  using ::atan;
+  using ::atanf;
+  using ::atanl;
+
+  using ::atan2;
+  using ::atan2f;
+  using ::atan2l;
+
+  using ::cos;
+  using ::cosf;
+  using ::cosl;
+
+  using ::sin;
+  using ::sinf;
+  using ::sinl;
+
+  using ::tan;
+  using ::tanf;
+  using ::tanl;
+
+  using ::acosh;
+  using ::acoshf;
+  using ::acoshl;
+
+  using ::asinh;
+  using ::asinhf;
+  using ::asinhl;
+
+  using ::atanh;
+  using ::atanhf;
+  using ::atanhl;
+
+  using ::cosh;
+  using ::coshf;
+  using ::coshl;
+
+  using ::sinh;
+  using ::sinhf;
+  using ::sinhl;
+
+  using ::tanh;
+  using ::tanhf;
+  using ::tanhl;
+
+  using ::exp;
+  using ::expf;
+  using ::expl;
+
+  using ::exp2;
+  using ::exp2f;
+  using ::exp2l;
+
+  using ::expm1;
+  using ::expm1f;
+  using ::expm1l;
+
+  using ::frexp;
+  using ::frexpf;
+  using ::frexpl;
+
+  using ::ilogb;
+  using ::ilogbf;
+  using ::ilogbl;
+
+  using ::ldexp;
+  using ::ldexpf;
+  using ::ldexpl;
+
+  using ::log;
+  using ::logf;
+  using ::logl;
+
+  using ::log10;
+  using ::log10f;
+  using ::log10l;
+
+  using ::log1p;
+  using ::log1pf;
+  using ::log1pl;
+
+  using ::log2;
+  using ::log2f;
+  using ::log2l;
+
+  using ::logb;
+  using ::logbf;
+  using ::logbl;
+
+  using ::modf;
+  using ::modff;
+  using ::modfl;
+
+  using ::scalbn;
+  using ::scalbnf;
+  using ::scalbnl;
+
+  using ::scalbln;
+  using ::scalblnf;
+  using ::scalblnl;
+
+  using ::cbrt;
+  using ::cbrtf;
+  using ::cbrtl;
+
+  // [c.math.abs], absolute values
+  using ::abs;
+
+  using ::fabs;
+  using ::fabsf;
+  using ::fabsl;
+
+  using ::hypot;
+  using ::hypotf;
+  using ::hypotl;
+
+  // [c.math.hypot3], three-dimensional hypotenuse
+
+  using ::pow;
+  using ::powf;
+  using ::powl;
+
+  using ::sqrt;
+  using ::sqrtf;
+  using ::sqrtl;
+
+  using ::erf;
+  using ::erff;
+  using ::erfl;
+
+  using ::erfc;
+  using ::erfcf;
+  using ::erfcl;
+
+  using ::lgamma;
+  using ::lgammaf;
+  using ::lgammal;
+
+  using ::tgamma;
+  using ::tgammaf;
+  using ::tgammal;
+
+  using ::ceil;
+  using ::ceilf;
+  using ::ceill;
+
+  using ::floor;
+  using ::floorf;
+  using ::floorl;
+
+  using ::nearbyint;
+  using ::nearbyintf;
+  using ::nearbyintl;
+
+  using ::rint;
+  using ::rintf;
+  using ::rintl;
+
+  using ::lrint;
+  using ::lrintf;
+  using ::lrintl;
+
+  using ::llrint;
+  using ::llrintf;
+  using ::llrintl;
+
+  using ::round;
+  using ::roundf;
+  using ::roundl;
+
+  using ::lround;
+  using ::lroundf;
+  using ::lroundl;
+
+  using ::llround;
+  using ::llroundf;
+  using ::llroundl;
+
+  using ::trunc;
+  using ::truncf;
+  using ::truncl;
+
+  using ::fmod;
+  using ::fmodf;
+  using ::fmodl;
+
+  using ::remainder;
+  using ::remainderf;
+  using ::remainderl;
+
+  using ::remquo;
+  using ::remquof;
+  using ::remquol;
+
+  using ::copysign;
+  using ::copysignf;
+  using ::copysignl;
+
+  using ::nan;
+  using ::nanf;
+  using ::nanl;
+
+  using ::nextafter;
+  using ::nextafterf;
+  using ::nextafterl;
+
+  using ::nexttoward;
+  using ::nexttowardf;
+  using ::nexttowardl;
+
+  using ::fdim;
+  using ::fdimf;
+  using ::fdiml;
+
+  using ::fmax;
+  using ::fmaxf;
+  using ::fmaxl;
+
+  using ::fmin;
+  using ::fminf;
+  using ::fminl;
+
+  using ::fma;
+  using ::fmaf;
+  using ::fmal;
+
+  // [c.math.lerp], linear interpolation
+  // [support.c.headers.other]/1
+  // ...  placed within the global namespace scope, except for the functions
+  // described in [sf.cmath], the std::lerp function overloads ([c.math.lerp])
+  // ...
+
+  // [c.math.fpclass], classification / comparison functions
+  using ::fpclassify;
+  using ::isfinite;
+  using ::isgreater;
+  using ::isgreaterequal;
+  using ::isinf;
+  using ::isless;
+  using ::islessequal;
+  using ::islessgreater;
+  using ::isnan;
+  using ::isnormal;
+  using ::isunordered;
+  using ::signbit;
+
+  // [sf.cmath], mathematical special functions
+} // export
diff --git a/libcxx/modules/std.compat/csetjmp.inc b/libcxx/modules/std.compat/csetjmp.i...
[truncated]

@mordante mordante force-pushed the GH-module_std_compat branch from a061bda to e6aec5f Compare November 7, 2023 16:30
config.substitutions = appendToSubstitution(
config.substitutions,
"%{link_flags}",
os.path.join(build, "libc++std.compat.a"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a simple follow-up: I think we should really rename those .a libraries. I know they're just implementation details, but the names are too close to libstdc++ which could create confusion. I would suggest instead: libc++.std.a and libc++.std.compat.a? Or maybe something else but it's worth thinking about a name that is less easily confused with libstdc++.a.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#76083 removes this code and its replacement #76246 only creates pcm files and not libraries. So that would resolve this issue.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ rebase and green CI, thanks!

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts about the compile time performance. I didn't run it actually. So some experiments will be good.

Comment on lines +199 to +208
export module std.compat;

@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export module std.compat;
@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
export module std.compat;
export import std;
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@

I feel this may have better compile-time performance when users write:

import std;
import std.compat;

In this case, the compiler needs to handle the redeclarations in module std and module std.compat. Then it may have the same problem as we discussed before.

While the example itself looks ridiculous, I feel it is highly possible in real worlds:

// a.cppm
export module a;
import std;

// b.cppm
export module b;
import std.compat;

// some_user.cc
import a;
import b;

Then the compiler needs to handle the redeclarations.

Comment on lines +20 to +22
#include <algorithm>
#include <any>
#include <array>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel better to not include C++ headers in std.compat.cppm. See the following comments for details.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I'll not address this now but in a follow-up PR. I really like to get this code in and unblock some other WIP patches.

This adds the std.compat module. The patch contains a bit of refactoring
to avoid code duplication between the std and std.compat module.

Implements parts of
- P2465R3 Standard Library Modules std and std.compat
@mordante mordante force-pushed the GH-module_std_compat branch from 4358bbf to b9a3b0b Compare December 8, 2023 16:42
@mordante mordante merged commit 600462a into llvm:main Dec 9, 2023
@mordante mordante deleted the GH-module_std_compat branch December 9, 2023 12:52
mordante added a commit to mordante/llvm-project that referenced this pull request Dec 10, 2023
mordante added a commit that referenced this pull request Dec 22, 2023
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
mordante added a commit that referenced this pull request Dec 23, 2023
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
mordante added a commit that referenced this pull request Dec 23, 2023
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records,
adding them to the global namespace. Clang correctly, does not export
these it's and issue in the declaration filtering. Declarations in
function or record context are not considered a global named
declaration.
mordante added a commit that referenced this pull request Dec 24, 2023
Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
mordante added a commit that referenced this pull request Jan 12, 2024
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
mordante added a commit that referenced this pull request Jan 17, 2024
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
mordante added a commit that referenced this pull request Jan 17, 2024
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17 plugin.
The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
mordante added a commit that referenced this pull request Jan 17, 2024
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records,
adding them to the global namespace. Clang correctly, does not export
these it's and issue in the declaration filtering. Declarations in
function or record context are not considered a global named
declaration.
mordante added a commit that referenced this pull request Jan 17, 2024
As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records,
adding them to the global namespace. Clang correctly does not export
these and it's an issue in the declaration filtering. Declarations in
function or record context are not considered a global named
declaration.
mordante added a commit that referenced this pull request Jan 17, 2024
Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
mordante added a commit that referenced this pull request Jan 17, 2024
Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
mordante added a commit that referenced this pull request Jan 18, 2024
Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
mordante added a commit that referenced this pull request Jan 21, 2024
Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants