[libc++][Modules] Make module exports consistent with header includes

Some modules export modules that they don't import (i.e. that their header doesn't directly include). That sometimes works when the exported submodule is in the same module, but when the `std` mega module is broken up (D144322), some of the exports stop working. Make the exports and includes consistent, either by adding includes for the exports, or by removing exports for missing includes.

The `concepts.equality_comparable` export in `std.iterator.__iterator.concepts` isn't doing anything because 1) it's resolved as `std.iterator.__iterator.concepts.equality_comparable` and 2) there's a `__concepts` submodule in between `std.concepts` and `equality_comparable`. Fix it to be `std.concepts.__concepts.equality_comparable`.

<span> is listed in both `std.span` and `std.experimental.span`. Delete the latter module.
There is no `__errc` module or header, so remove that export from `std.system_error`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D153211

GitOrigin-RevId: 40cdb220f5af63160679def0aee23aa1cbd49b60
diff --git a/include/__filesystem/path.h b/include/__filesystem/path.h
index da349af..77699c5 100644
--- a/include/__filesystem/path.h
+++ b/include/__filesystem/path.h
@@ -14,6 +14,7 @@
 #include <__algorithm/replace_copy.h>
 #include <__availability>
 #include <__config>
+#include <__functional/hash.h>
 #include <__functional/unary_function.h>
 #include <__fwd/hash.h>
 #include <__iterator/back_insert_iterator.h>
diff --git a/include/__memory/concepts.h b/include/__memory/concepts.h
index 9517a8f..97cc358 100644
--- a/include/__memory/concepts.h
+++ b/include/__memory/concepts.h
@@ -19,6 +19,7 @@
 #include <__ranges/concepts.h>
 #include <__type_traits/is_reference.h>
 #include <__type_traits/remove_cvref.h>
+#include <__type_traits/remove_reference.h> // TODO(modules): This should not be required
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/include/__ranges/all.h b/include/__ranges/all.h
index ecf908d..2c88f51 100644
--- a/include/__ranges/all.h
+++ b/include/__ranges/all.h
@@ -11,6 +11,8 @@
 #define _LIBCPP___RANGES_ALL_H
 
 #include <__config>
+#include <__functional/compose.h>         // TODO(modules): Those should not be required
+#include <__functional/perfect_forward.h> //
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__ranges/access.h>
diff --git a/include/__ranges/transform_view.h b/include/__ranges/transform_view.h
index dd346fb..3678f9d 100644
--- a/include/__ranges/transform_view.h
+++ b/include/__ranges/transform_view.h
@@ -20,6 +20,7 @@
 #include <__config>
 #include <__functional/bind_back.h>
 #include <__functional/invoke.h>
+#include <__functional/perfect_forward.h>
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__memory/addressof.h>
diff --git a/include/__system_error/error_condition.h b/include/__system_error/error_condition.h
index 80f349c..a43a73c 100644
--- a/include/__system_error/error_condition.h
+++ b/include/__system_error/error_condition.h
@@ -12,6 +12,7 @@
 
 #include <__compare/ordering.h>
 #include <__config>
+#include <__functional/hash.h>
 #include <__functional/unary_function.h>
 #include <__system_error/errc.h>
 #include <__system_error/error_category.h>
diff --git a/include/module.modulemap.in b/include/module.modulemap.in
index 5e32995..a47e0ef 100644
--- a/include/module.modulemap.in
+++ b/include/module.modulemap.in
@@ -117,8 +117,6 @@
   }
   module tgmath_h {
     header "tgmath.h"
-    export ccomplex
-    export cmath
     export *
   }
 
@@ -226,7 +224,6 @@
     module cwchar {
       @requires_LIBCXX_ENABLE_WIDE_CHARACTERS@
       header "cwchar"
-      export depr.stdio_h
       export *
     }
     module cwctype {
@@ -502,12 +499,11 @@
       }
       module ranges_partial_sort {
         private header "__algorithm/ranges_partial_sort.h"
-        export algorithm.__algorithm.in_out_result
         export functional.__functional.ranges_operations
       }
       module ranges_partial_sort_copy {
         private header "__algorithm/ranges_partial_sort_copy.h"
-        export algorithm.__algorithm.in_out_out_result
+        export algorithm.__algorithm.in_out_result
         export functional.__functional.ranges_operations
       }
       module ranges_partition                { private header "__algorithm/ranges_partition.h" }
@@ -763,7 +759,6 @@
         private header "__chrono/high_resolution_clock.h"
         export steady_clock
         export system_clock
-        export time_point
       }
       module literals               { private header "__chrono/literals.h" }
       module month                  { private header "__chrono/month.h" }
@@ -778,8 +773,14 @@
         private header "__chrono/parser_std_format_spec.h"
       }
       module statically_widen       { private header "__chrono/statically_widen.h" }
-      module steady_clock           { private header "__chrono/steady_clock.h" }
-      module system_clock           { private header "__chrono/system_clock.h" }
+      module steady_clock           {
+        private header "__chrono/steady_clock.h"
+        export time_point
+      }
+      module system_clock           {
+        private header "__chrono/system_clock.h"
+        export time_point
+      }
       module time_point             { private header "__chrono/time_point.h" }
       module weekday                { private header "__chrono/weekday.h" }
       module year                   { private header "__chrono/year.h" }
@@ -939,7 +940,6 @@
         private header "__format/format_context.h"
         export optional
         export locale
-        export __locale
       }
       module format_error                    { private header "__format/format_error.h" }
       module format_functions                {
@@ -1085,7 +1085,7 @@
       module cpp17_iterator_concepts { private header "__iterator/cpp17_iterator_concepts.h" }
       module concepts {
         private header "__iterator/concepts.h"
-        export concepts.equality_comparable
+        export std.concepts.__concepts.equality_comparable
         export type_traits.common_reference
       }
       module counted_iterator      { private header "__iterator/counted_iterator.h" }
@@ -1120,10 +1120,7 @@
       module permutable            { private header "__iterator/permutable.h" }
       module prev                  { private header "__iterator/prev.h" }
       module projected             { private header "__iterator/projected.h" }
-      module readable_traits       {
-        private header "__iterator/readable_traits.h"
-        export __iterator.iterator_traits
-      }
+      module readable_traits       { private header "__iterator/readable_traits.h" }
       module reverse_access        { private header "__iterator/reverse_access.h" }
       module reverse_iterator      { private header "__iterator/reverse_iterator.h" }
       module segmented_iterator    { private header "__iterator/segmented_iterator.h" }
@@ -1168,12 +1165,14 @@
   }
   module mdspan {
     header "mdspan"
-    export array
-    export span
     export *
 
     module __mdspan {
-      module extents                         { private header "__mdspan/extents.h" }
+      module extents                         {
+        private header "__mdspan/extents.h"
+        export array
+        export span
+      }
       module layout_left                     { private header "__mdspan/layout_left.h" }
       module layout_right                    { private header "__mdspan/layout_right.h" }
       module mdspan_fwd                      { private header "__fwd/mdspan.h" }
@@ -1500,7 +1499,6 @@
   }
   module string_view {
     header "string_view"
-    export initializer_list
     export *
     module string_view_fwd { private header "__fwd/string_view.h" }
   }
@@ -1511,7 +1509,6 @@
   }
   module system_error {
     header "system_error"
-    export __errc
     export *
     module __system_error {
       module errc           { private header "__system_error/errc.h" }
@@ -1876,10 +1873,6 @@
       header "experimental/set"
       export *
     }
-    module span {
-      header "span"
-      export *
-    }
     module string {
       header "experimental/string"
       export *
diff --git a/test/libcxx/transitive_includes/cxx03.csv b/test/libcxx/transitive_includes/cxx03.csv
index 4f761f1..9f555fb 100644
--- a/test/libcxx/transitive_includes/cxx03.csv
+++ b/test/libcxx/transitive_includes/cxx03.csv
@@ -285,6 +285,7 @@
 filesystem cstddef
 filesystem cstdint
 filesystem cstdlib
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx11.csv b/test/libcxx/transitive_includes/cxx11.csv
index 7e93630..0f00c22 100644
--- a/test/libcxx/transitive_includes/cxx11.csv
+++ b/test/libcxx/transitive_includes/cxx11.csv
@@ -285,6 +285,7 @@
 filesystem cstddef
 filesystem cstdint
 filesystem cstdlib
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx14.csv b/test/libcxx/transitive_includes/cxx14.csv
index 8c6fadd..596ea36 100644
--- a/test/libcxx/transitive_includes/cxx14.csv
+++ b/test/libcxx/transitive_includes/cxx14.csv
@@ -287,6 +287,7 @@
 filesystem cstddef
 filesystem cstdint
 filesystem cstdlib
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx17.csv b/test/libcxx/transitive_includes/cxx17.csv
index 8c6fadd..596ea36 100644
--- a/test/libcxx/transitive_includes/cxx17.csv
+++ b/test/libcxx/transitive_includes/cxx17.csv
@@ -287,6 +287,7 @@
 filesystem cstddef
 filesystem cstdint
 filesystem cstdlib
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx20.csv b/test/libcxx/transitive_includes/cxx20.csv
index 8fd381c..e80b9a0 100644
--- a/test/libcxx/transitive_includes/cxx20.csv
+++ b/test/libcxx/transitive_includes/cxx20.csv
@@ -294,6 +294,7 @@
 filesystem cstddef
 filesystem cstdint
 filesystem cstdlib
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx23.csv b/test/libcxx/transitive_includes/cxx23.csv
index 812bf3b..27e9acf 100644
--- a/test/libcxx/transitive_includes/cxx23.csv
+++ b/test/libcxx/transitive_includes/cxx23.csv
@@ -191,6 +191,7 @@
 filesystem compare
 filesystem cstddef
 filesystem cstdint
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd
diff --git a/test/libcxx/transitive_includes/cxx26.csv b/test/libcxx/transitive_includes/cxx26.csv
index 812bf3b..27e9acf 100644
--- a/test/libcxx/transitive_includes/cxx26.csv
+++ b/test/libcxx/transitive_includes/cxx26.csv
@@ -191,6 +191,7 @@
 filesystem compare
 filesystem cstddef
 filesystem cstdint
+filesystem cstring
 filesystem ctime
 filesystem iomanip
 filesystem iosfwd