clean up the build targets for collections, mem, reflection

PiperOrigin-RevId: 488226166
diff --git a/BUILD b/BUILD
index 81b5192..de6165b 100644
--- a/BUILD
+++ b/BUILD
@@ -130,6 +130,7 @@
         "upb/decode.h",
         "upb/encode.h",
         "upb/extension_registry.h",
+        "upb/map.h",
         "upb/mem/alloc.h",
         "upb/mem/arena.h",
         "upb/msg.h",
@@ -237,7 +238,6 @@
     copts = UPB_DEFAULT_COPTS,
     visibility = ["//visibility:public"],
     deps = [
-        ":collections",
         ":collections_internal",
         ":mini_table",
         ":mini_table_internal",
@@ -387,7 +387,6 @@
     visibility = ["//visibility:public"],
     deps = [
         ":descriptor_upb_proto",
-        ":reflection",
         ":reflection_internal",
         ":table_internal",
     ],
@@ -407,28 +406,43 @@
 
 cc_library(
     name = "collections",
-    srcs = [
-        "upb/collections/array.c",
-        "upb/collections/array_internal.h",
-        "upb/collections/map.c",
-        "upb/collections/map_internal.h",
-        "upb/collections/map_sorter.c",
-        "upb/collections/message_value.h",
-        "upb/extension_registry.h",
-        "upb/msg.h",
-        "upb/msg_internal.h",
-    ],
     hdrs = [
-        "upb/array.h",
-        "upb/collections.h",
         "upb/collections/array.h",
         "upb/collections/map.h",
-        "upb/collections/map_sorter_internal.h",
-        "upb/map.h",
     ],
     copts = UPB_DEFAULT_COPTS,
     visibility = ["//visibility:public"],
     deps = [
+        ":collections_internal",
+        ":port",
+    ],
+)
+
+cc_library(
+    name = "collections_internal",
+    srcs = [
+        "upb/collections/array.c",
+        "upb/collections/map.c",
+        "upb/collections/map_sorter.c",
+        "upb/extension_registry.h",
+        "upb/msg.h",
+        "upb/msg_internal.h",
+        "upb/status.h",
+        "upb/string_view.h",
+    ],
+    hdrs = [
+        "upb/collections/array.h",
+        "upb/collections/array_internal.h",
+        "upb/collections/map.h",
+        "upb/collections/map_gencode_util.h",
+        "upb/collections/map_internal.h",
+        "upb/collections/map_sorter_internal.h",
+        "upb/collections/message_value.h",
+    ],
+    copts = UPB_DEFAULT_COPTS,
+    visibility = ["//:__subpackages__"],
+    deps = [
+        ":mem",
         ":port",
         ":table_internal",
     ],
@@ -438,46 +452,6 @@
 # (= everything in upb/) we can move this build target down into reflection/
 cc_library(
     name = "reflection",
-    srcs = [
-        "upb/reflection/common.h",
-        "upb/reflection/def_builder.c",
-        "upb/reflection/def_builder_internal.h",
-        "upb/reflection/def_pool.c",
-        "upb/reflection/def_pool.h",
-        "upb/reflection/def_pool_internal.h",
-        "upb/reflection/def_type.c",
-        "upb/reflection/def_type.h",
-        "upb/reflection/desc_state.c",
-        "upb/reflection/desc_state_internal.h",
-        "upb/reflection/enum_def.c",
-        "upb/reflection/enum_def.h",
-        "upb/reflection/enum_def_internal.h",
-        "upb/reflection/enum_value_def.c",
-        "upb/reflection/enum_value_def.h",
-        "upb/reflection/enum_value_def_internal.h",
-        "upb/reflection/extension_range.c",
-        "upb/reflection/extension_range.h",
-        "upb/reflection/extension_range_internal.h",
-        "upb/reflection/field_def.c",
-        "upb/reflection/field_def.h",
-        "upb/reflection/field_def_internal.h",
-        "upb/reflection/file_def.c",
-        "upb/reflection/file_def.h",
-        "upb/reflection/file_def_internal.h",
-        "upb/reflection/message.c",
-        "upb/reflection/message_def.c",
-        "upb/reflection/message_def.h",
-        "upb/reflection/message_def_internal.h",
-        "upb/reflection/method_def.c",
-        "upb/reflection/method_def.h",
-        "upb/reflection/method_def_internal.h",
-        "upb/reflection/oneof_def.c",
-        "upb/reflection/oneof_def.h",
-        "upb/reflection/oneof_def_internal.h",
-        "upb/reflection/service_def.c",
-        "upb/reflection/service_def.h",
-        "upb/reflection/service_def_internal.h",
-    ],
     hdrs = [
         "upb/def.h",
         "upb/def.hpp",
@@ -492,11 +466,8 @@
     visibility = ["//visibility:public"],
     deps = [
         ":collections",
-        ":descriptor_upb_proto",
-        ":mini_table",
-        ":mini_table_internal",
         ":port",
-        ":table_internal",
+        ":reflection_internal",
         ":upb",
     ],
 )
@@ -504,32 +475,49 @@
 cc_library(
     name = "reflection_internal",
     srcs = [
+        "upb/reflection/def_builder.c",
+        "upb/reflection/def_pool.c",
+        "upb/reflection/def_type.c",
+        "upb/reflection/desc_state.c",
+        "upb/reflection/enum_def.c",
+        "upb/reflection/enum_value_def.c",
+        "upb/reflection/extension_range.c",
+        "upb/reflection/field_def.c",
+        "upb/reflection/file_def.c",
+        "upb/reflection/message.c",
+        "upb/reflection/message_def.c",
+        "upb/reflection/method_def.c",
+        "upb/reflection/oneof_def.c",
+        "upb/reflection/service_def.c",
+    ],
+    hdrs = [
         "upb/reflection/common.h",
+        "upb/reflection/def.h",
+        "upb/reflection/def.hpp",
         "upb/reflection/def_builder_internal.h",
         "upb/reflection/def_pool.h",
+        "upb/reflection/def_pool_internal.h",
         "upb/reflection/def_type.h",
         "upb/reflection/desc_state_internal.h",
         "upb/reflection/enum_def.h",
-        "upb/reflection/enum_value_def.h",
-        "upb/reflection/extension_range.h",
-        "upb/reflection/field_def.h",
-        "upb/reflection/file_def.h",
-        "upb/reflection/message.h",
-        "upb/reflection/message_def.h",
-        "upb/reflection/method_def.h",
-        "upb/reflection/oneof_def.h",
-        "upb/reflection/service_def.h",
-    ],
-    hdrs = [
-        "upb/reflection/def_pool_internal.h",
         "upb/reflection/enum_def_internal.h",
+        "upb/reflection/enum_value_def.h",
         "upb/reflection/enum_value_def_internal.h",
+        "upb/reflection/extension_range.h",
         "upb/reflection/extension_range_internal.h",
+        "upb/reflection/field_def.h",
         "upb/reflection/field_def_internal.h",
+        "upb/reflection/file_def.h",
         "upb/reflection/file_def_internal.h",
+        "upb/reflection/message.h",
+        "upb/reflection/message.hpp",
+        "upb/reflection/message_def.h",
         "upb/reflection/message_def_internal.h",
+        "upb/reflection/method_def.h",
         "upb/reflection/method_def_internal.h",
+        "upb/reflection/oneof_def.h",
         "upb/reflection/oneof_def_internal.h",
+        "upb/reflection/service_def.h",
         "upb/reflection/service_def_internal.h",
     ],
     copts = UPB_DEFAULT_COPTS,
@@ -540,7 +528,6 @@
         ":mini_table",
         ":mini_table_internal",
         ":port",
-        ":reflection",
         ":table_internal",
         ":upb",
     ],
@@ -558,7 +545,7 @@
     copts = UPB_DEFAULT_COPTS,
     visibility = ["//visibility:public"],
     deps = [
-        ":collections",
+        ":collections_internal",
         ":port",
         ":reflection",
         ":wire_internal",
@@ -964,55 +951,33 @@
 # Internal C/C++ libraries #####################################################
 
 cc_library(
-    name = "collections_internal",
-    srcs = [
-        "upb/collections/array.h",
-        "upb/collections/map_gencode_util.h",
-        "upb/collections/message_value.h",
-        "upb/msg.h",
-        "upb/status.h",
-        "upb/string_view.h",
-        "upb/upb.h",
-    ],
-    hdrs = [
-        "upb/collections/array_internal.h",
-        "upb/collections/map_internal.h",
-    ],
-    copts = UPB_DEFAULT_COPTS,
-    visibility = ["//:__subpackages__"],
-    deps = [
-        ":collections",
-        ":mem",
-        ":port",
-        ":table_internal",
-    ],
-)
-
-cc_library(
     name = "mem",
-    srcs = [
-        "upb/mem/alloc.c",
-        "upb/mem/arena.c",
-        "upb/mem/arena_internal.h",
-    ],
     hdrs = [
         "upb/mem/alloc.h",
         "upb/mem/arena.h",
     ],
     copts = UPB_DEFAULT_COPTS,
     visibility = ["//:__subpackages__"],
-    deps = [":port"],
+    deps = [
+        ":mem_internal",
+        ":port",
+    ],
 )
 
 cc_library(
     name = "mem_internal",
-    hdrs = ["upb/mem/arena_internal.h"],
+    srcs = [
+        "upb/mem/alloc.c",
+        "upb/mem/arena.c",
+    ],
+    hdrs = [
+        "upb/mem/alloc.h",
+        "upb/mem/arena.h",
+        "upb/mem/arena_internal.h",
+    ],
     copts = UPB_DEFAULT_COPTS,
     visibility = ["//:__subpackages__"],
-    deps = [
-        ":mem",
-        ":port",
-    ],
+    deps = [":port"],
 )
 
 cc_library(
@@ -1104,12 +1069,10 @@
     ],
     libs = [
         ":atoi_internal",
-        ":collections",
         ":collections_internal",
         ":descriptor_upb_proto",
         ":extension_registry",
         ":fastdecode",
-        ":mem",
         ":mem_internal",
         ":mini_table",
         ":mini_table_accessors",
@@ -1139,14 +1102,12 @@
     ],
     libs = [
         ":atoi_internal",
-        ":collections",
         ":collections_internal",
         ":descriptor_upb_proto",
         ":descriptor_upb_proto_reflection",
         ":extension_registry",
         ":fastdecode",
         ":json",
-        ":mem",
         ":mem_internal",
         ":mini_table",
         ":mini_table_accessors",
@@ -1180,13 +1141,11 @@
     ],
     libs = [
         ":atoi_internal",
-        ":collections",
         ":collections_internal",
         ":descriptor_upb_proto",
         ":extension_registry",
         ":fastdecode",
         ":json",
-        ":mem",
         ":mem_internal",
         ":mini_table",
         ":mini_table_accessors",