grpc 1.57.0 → 1.58.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (402) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +534 -284
  3. data/include/grpc/event_engine/event_engine.h +0 -1
  4. data/include/grpc/event_engine/memory_allocator.h +2 -2
  5. data/include/grpc/impl/channel_arg_names.h +371 -0
  6. data/include/grpc/impl/grpc_types.h +1 -353
  7. data/include/grpc/module.modulemap +1 -0
  8. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -1
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +2 -1
  10. data/src/core/ext/filters/client_channel/client_channel.cc +7 -3
  11. data/src/core/ext/filters/client_channel/http_proxy.cc +1 -1
  12. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +10 -5
  13. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +1 -0
  15. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +5 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +4 -2
  17. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +115 -109
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.h +0 -5
  19. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +7 -2
  20. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +2 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +1 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +1 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +11 -3
  24. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +6 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +8 -5
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +102 -11
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +9 -4
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +4 -1
  30. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_plugin.cc +6 -0
  31. data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +41 -14
  32. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  33. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +3 -2
  34. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +1 -1
  35. data/src/core/ext/filters/client_channel/retry_filter.h +1 -0
  36. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
  37. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
  38. data/src/core/ext/filters/client_channel/subchannel.cc +9 -5
  39. data/src/core/ext/filters/client_channel/subchannel.h +8 -2
  40. data/src/core/ext/filters/deadline/deadline_filter.cc +1 -1
  41. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  43. data/src/core/ext/filters/http/message_compress/compression_filter.cc +1 -0
  44. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -1
  45. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -0
  46. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +4 -7
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -0
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +8 -12
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +357 -358
  50. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -18
  51. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +63 -4
  52. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +7 -2
  53. data/src/core/ext/transport/chttp2/transport/internal.h +30 -57
  54. data/src/core/ext/transport/chttp2/transport/parsing.cc +16 -7
  55. data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.cc +80 -0
  56. data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.h +55 -0
  57. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +98 -0
  58. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.h +73 -0
  59. data/src/core/ext/transport/chttp2/transport/writing.cc +81 -89
  60. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -0
  61. data/src/core/ext/xds/xds_client_grpc.cc +1 -0
  62. data/src/core/ext/xds/xds_http_fault_filter.cc +1 -2
  63. data/src/core/ext/xds/xds_http_fault_filter.h +1 -2
  64. data/src/core/ext/xds/xds_http_filters.h +2 -4
  65. data/src/core/ext/xds/xds_http_rbac_filter.cc +3 -8
  66. data/src/core/ext/xds/xds_http_rbac_filter.h +1 -2
  67. data/src/core/ext/xds/xds_http_stateful_session_filter.cc +1 -2
  68. data/src/core/ext/xds/xds_http_stateful_session_filter.h +1 -2
  69. data/src/core/ext/xds/xds_lb_policy_registry.cc +3 -6
  70. data/src/core/ext/xds/xds_routing.cc +2 -2
  71. data/src/core/ext/xds/xds_transport_grpc.cc +1 -0
  72. data/src/core/lib/avl/avl.h +10 -173
  73. data/src/core/lib/channel/call_tracer.cc +289 -0
  74. data/src/core/lib/channel/call_tracer.h +35 -0
  75. data/src/core/lib/channel/channel_args.cc +84 -79
  76. data/src/core/lib/channel/channel_args.h +29 -17
  77. data/src/core/lib/channel/connected_channel.cc +0 -1
  78. data/src/core/lib/channel/promise_based_filter.cc +4 -1
  79. data/src/core/lib/compression/compression_internal.cc +8 -4
  80. data/src/core/lib/debug/stats_data.cc +93 -21
  81. data/src/core/lib/debug/stats_data.h +41 -0
  82. data/src/core/lib/event_engine/ares_resolver.cc +712 -0
  83. data/src/core/lib/event_engine/ares_resolver.h +150 -0
  84. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -3
  85. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +2 -2
  86. data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +229 -0
  87. data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +117 -0
  88. data/src/core/lib/event_engine/forkable.cc +15 -1
  89. data/src/core/lib/event_engine/forkable.h +15 -0
  90. data/src/core/lib/event_engine/grpc_polled_fd.h +73 -0
  91. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +25 -3
  92. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +10 -1
  93. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +197 -0
  94. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +3 -3
  95. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +47 -1
  96. data/src/core/lib/event_engine/posix_engine/posix_engine.h +12 -1
  97. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +1 -0
  98. data/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +2 -0
  99. data/src/core/lib/event_engine/thread_pool/thread_count.cc +58 -0
  100. data/src/core/lib/event_engine/thread_pool/thread_count.h +161 -0
  101. data/src/core/lib/event_engine/thread_pool/thread_pool_factory.cc +7 -0
  102. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +86 -111
  103. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +15 -61
  104. data/src/core/lib/event_engine/windows/windows_endpoint.cc +3 -4
  105. data/src/core/lib/experiments/config.cc +14 -0
  106. data/src/core/lib/experiments/experiments.cc +141 -304
  107. data/src/core/lib/experiments/experiments.h +16 -17
  108. data/src/core/lib/gprpp/ref_counted.h +3 -1
  109. data/src/core/lib/gprpp/ref_counted_string.cc +44 -0
  110. data/src/core/lib/gprpp/ref_counted_string.h +146 -0
  111. data/src/core/lib/gprpp/time.h +2 -2
  112. data/src/core/lib/gprpp/work_serializer.cc +36 -0
  113. data/src/core/lib/gprpp/work_serializer.h +5 -0
  114. data/src/core/lib/http/httpcli_security_connector.cc +1 -0
  115. data/src/core/lib/iomgr/buffer_list.cc +2 -0
  116. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +7 -22
  117. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  118. data/src/core/lib/promise/detail/basic_seq.h +1 -372
  119. data/src/core/lib/promise/detail/seq_state.h +2076 -0
  120. data/src/core/lib/promise/seq.h +19 -2
  121. data/src/core/lib/promise/sleep.h +5 -10
  122. data/src/core/lib/promise/try_seq.h +34 -2
  123. data/src/core/lib/resource_quota/api.cc +1 -0
  124. data/src/core/lib/resource_quota/arena.cc +2 -0
  125. data/src/core/lib/resource_quota/arena.h +42 -8
  126. data/src/core/lib/resource_quota/memory_quota.cc +0 -1
  127. data/src/core/lib/resource_quota/resource_quota.h +1 -0
  128. data/src/core/lib/security/authorization/authorization_policy_provider.h +1 -1
  129. data/src/core/lib/security/authorization/rbac_policy.h +1 -1
  130. data/src/core/lib/security/credentials/external/aws_request_signer.cc +8 -0
  131. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +1 -0
  132. data/src/core/lib/security/credentials/jwt/json_token.cc +17 -0
  133. data/src/core/lib/security/credentials/jwt/json_token.h +4 -0
  134. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +42 -0
  135. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -0
  136. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -0
  137. data/src/core/lib/security/credentials/tls/tls_credentials.cc +1 -0
  138. data/src/core/lib/security/credentials/xds/xds_credentials.cc +1 -0
  139. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -0
  140. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -0
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +1 -0
  142. data/src/core/lib/security/transport/client_auth_filter.cc +8 -5
  143. data/src/core/lib/security/transport/security_handshaker.cc +1 -0
  144. data/src/core/lib/security/transport/server_auth_filter.cc +2 -0
  145. data/src/core/lib/surface/call.cc +32 -8
  146. data/src/core/lib/surface/channel.cc +1 -0
  147. data/src/core/lib/surface/completion_queue.cc +10 -0
  148. data/src/core/lib/surface/init.cc +1 -0
  149. data/src/core/lib/surface/server.cc +67 -64
  150. data/src/core/lib/surface/server.h +1 -15
  151. data/src/core/lib/surface/version.cc +2 -2
  152. data/src/core/tsi/alts/crypt/aes_gcm.cc +27 -2
  153. data/src/core/tsi/ssl_transport_security.cc +11 -0
  154. data/src/ruby/lib/grpc/generic/active_call.rb +9 -14
  155. data/src/ruby/lib/grpc/version.rb +1 -1
  156. data/src/ruby/pb/test/client.rb +16 -0
  157. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  158. data/third_party/abseil-cpp/absl/algorithm/container.h +3 -2
  159. data/third_party/abseil-cpp/absl/base/attributes.h +58 -5
  160. data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
  161. data/third_party/abseil-cpp/absl/base/casts.h +8 -8
  162. data/third_party/abseil-cpp/absl/base/config.h +89 -106
  163. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +26 -1
  164. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +2 -2
  165. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +50 -39
  166. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +2 -1
  167. data/third_party/abseil-cpp/absl/base/internal/prefetch.h +17 -18
  168. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +32 -3
  169. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +24 -4
  170. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +31 -73
  171. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +9 -8
  172. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +11 -11
  173. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +23 -32
  174. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +2 -3
  175. data/third_party/abseil-cpp/absl/base/options.h +1 -1
  176. data/third_party/abseil-cpp/absl/base/policy_checks.h +3 -3
  177. data/third_party/abseil-cpp/absl/base/prefetch.h +198 -0
  178. data/third_party/abseil-cpp/absl/container/fixed_array.h +54 -29
  179. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +5 -1
  180. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +6 -2
  181. data/third_party/abseil-cpp/absl/container/inlined_vector.h +167 -79
  182. data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -1
  183. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +3 -21
  184. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +1 -1
  185. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +46 -0
  186. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -0
  187. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +85 -26
  188. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +35 -18
  189. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +70 -29
  190. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +437 -236
  191. data/third_party/abseil-cpp/absl/crc/crc32c.h +8 -1
  192. data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +14 -8
  193. data/third_party/abseil-cpp/absl/crc/internal/crc.cc +4 -35
  194. data/third_party/abseil-cpp/absl/crc/internal/crc.h +2 -10
  195. data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +1 -1
  196. data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.cc +1 -1
  197. data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.h +4 -4
  198. data/third_party/abseil-cpp/absl/crc/internal/crc_internal.h +8 -10
  199. data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy_x86_64.cc +17 -19
  200. data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +8 -8
  201. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +2 -1
  202. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +59 -23
  203. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +1 -1
  204. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +1 -1
  205. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +1 -1
  206. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +43 -19
  207. data/third_party/abseil-cpp/absl/debugging/symbolize_emscripten.inc +3 -0
  208. data/third_party/abseil-cpp/absl/flags/commandlineflag.h +1 -1
  209. data/third_party/abseil-cpp/absl/flags/internal/commandlineflag.cc +1 -1
  210. data/third_party/abseil-cpp/absl/flags/internal/flag.cc +2 -2
  211. data/third_party/abseil-cpp/absl/flags/internal/flag.h +16 -15
  212. data/third_party/abseil-cpp/absl/flags/internal/flag_msvc.inc +1 -1
  213. data/third_party/abseil-cpp/absl/flags/marshalling.cc +43 -2
  214. data/third_party/abseil-cpp/absl/flags/marshalling.h +5 -0
  215. data/third_party/abseil-cpp/absl/functional/any_invocable.h +9 -1
  216. data/third_party/abseil-cpp/absl/functional/bind_front.h +1 -1
  217. data/third_party/abseil-cpp/absl/functional/function_ref.h +3 -3
  218. data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +37 -24
  219. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +19 -9
  220. data/third_party/abseil-cpp/absl/hash/hash.h +7 -4
  221. data/third_party/abseil-cpp/absl/hash/internal/hash.h +38 -15
  222. data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +6 -0
  223. data/third_party/abseil-cpp/absl/meta/type_traits.h +48 -373
  224. data/third_party/abseil-cpp/absl/numeric/bits.h +4 -4
  225. data/third_party/abseil-cpp/absl/numeric/int128.cc +20 -8
  226. data/third_party/abseil-cpp/absl/numeric/int128.h +36 -39
  227. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +0 -3
  228. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +47 -30
  229. data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +4 -3
  230. data/third_party/abseil-cpp/absl/random/internal/generate_real.h +1 -1
  231. data/third_party/abseil-cpp/absl/random/internal/platform.h +1 -1
  232. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +4 -0
  233. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +1 -1
  234. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +1 -1
  235. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +1 -1
  236. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +4 -0
  237. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +12 -24
  238. data/third_party/abseil-cpp/absl/status/status.cc +11 -7
  239. data/third_party/abseil-cpp/absl/status/status.h +11 -2
  240. data/third_party/abseil-cpp/absl/status/statusor.h +22 -8
  241. data/third_party/abseil-cpp/absl/strings/ascii.cc +54 -6
  242. data/third_party/abseil-cpp/absl/strings/charconv.cc +21 -4
  243. data/third_party/abseil-cpp/absl/strings/charconv.h +2 -2
  244. data/third_party/abseil-cpp/absl/strings/cord.cc +1 -2
  245. data/third_party/abseil-cpp/absl/strings/cord.h +32 -5
  246. data/third_party/abseil-cpp/absl/strings/cord_analysis.cc +23 -1
  247. data/third_party/abseil-cpp/absl/strings/cord_analysis.h +18 -0
  248. data/third_party/abseil-cpp/absl/strings/cord_buffer.h +2 -5
  249. data/third_party/abseil-cpp/absl/strings/escaping.cc +10 -32
  250. data/third_party/abseil-cpp/absl/strings/escaping.h +1 -1
  251. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +2 -4
  252. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +3 -3
  253. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +0 -1
  254. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +15 -13
  255. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.cc +13 -4
  256. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.h +8 -0
  257. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.cc +5 -3
  258. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.h +4 -7
  259. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +8 -0
  260. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +2 -2
  261. data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.cc +46 -20
  262. data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.h +1 -34
  263. data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +2 -1
  264. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +23 -0
  265. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +1 -0
  266. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +2 -77
  267. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +4 -112
  268. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +1 -1
  269. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +10 -31
  270. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +8 -8
  271. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +5 -20
  272. data/third_party/abseil-cpp/absl/strings/internal/str_format/constexpr_parser.h +1 -0
  273. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +1 -1
  274. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +9 -9
  275. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +56 -6
  276. data/third_party/abseil-cpp/absl/strings/match.cc +87 -0
  277. data/third_party/abseil-cpp/absl/strings/match.h +19 -0
  278. data/third_party/abseil-cpp/absl/strings/numbers.cc +154 -122
  279. data/third_party/abseil-cpp/absl/strings/numbers.h +1 -6
  280. data/third_party/abseil-cpp/absl/strings/str_cat.cc +7 -50
  281. data/third_party/abseil-cpp/absl/strings/str_cat.h +83 -15
  282. data/third_party/abseil-cpp/absl/strings/str_format.h +6 -3
  283. data/third_party/abseil-cpp/absl/strings/str_split.cc +9 -6
  284. data/third_party/abseil-cpp/absl/strings/string_view.cc +26 -4
  285. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +5 -0
  286. data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +63 -43
  287. data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.cc +111 -0
  288. data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.h +63 -0
  289. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +11 -7
  290. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.cc +225 -0
  291. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +122 -114
  292. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +12 -8
  293. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +10 -1
  294. data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.cc +167 -0
  295. data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.h +60 -0
  296. data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.cc +122 -0
  297. data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.h +65 -0
  298. data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.cc +91 -0
  299. data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.h +56 -0
  300. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +19 -113
  301. data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.cc +42 -0
  302. data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.h +90 -0
  303. data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.cc +151 -0
  304. data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.h +70 -0
  305. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +407 -411
  306. data/third_party/abseil-cpp/absl/synchronization/mutex.h +152 -118
  307. data/third_party/abseil-cpp/absl/time/clock.cc +6 -7
  308. data/third_party/abseil-cpp/absl/time/duration.cc +24 -26
  309. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +1 -0
  310. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +1 -1
  311. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +3 -3
  312. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +8 -6
  313. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +6 -3
  314. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +4 -2
  315. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +4 -0
  316. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +322 -295
  317. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +8 -17
  318. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +51 -33
  319. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +7 -2
  320. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +128 -2
  321. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +1 -1
  322. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +5 -1
  323. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +34 -34
  324. data/third_party/abseil-cpp/absl/time/time.cc +9 -2
  325. data/third_party/abseil-cpp/absl/time/time.h +115 -15
  326. data/third_party/abseil-cpp/absl/types/internal/optional.h +0 -52
  327. data/third_party/abseil-cpp/absl/types/internal/span.h +2 -2
  328. data/third_party/abseil-cpp/absl/types/internal/variant.h +2 -2
  329. data/third_party/abseil-cpp/absl/types/optional.h +15 -13
  330. data/third_party/abseil-cpp/absl/types/span.h +1 -2
  331. data/third_party/boringssl-with-bazel/err_data.c +15 -14
  332. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +7 -3
  333. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strex.c +7 -7
  334. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +7 -3
  335. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +5 -5
  336. data/third_party/boringssl-with-bazel/src/crypto/bio/errno.c +92 -0
  337. data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +4 -48
  338. data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +11 -6
  339. data/third_party/boringssl-with-bazel/src/crypto/bio/internal.h +16 -6
  340. data/third_party/boringssl-with-bazel/src/crypto/bio/socket.c +2 -2
  341. data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c +9 -0
  342. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.c +1 -1
  343. data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +3 -7
  344. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_apple.c +0 -2
  345. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_fuchsia.c +0 -1
  346. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_linux.c +0 -2
  347. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_openbsd.c +0 -1
  348. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_sysreg.c +93 -0
  349. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_win.c +1 -1
  350. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_freebsd.c +0 -1
  351. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.c +0 -2
  352. data/third_party/boringssl-with-bazel/src/crypto/dh_extra/dh_asn1.c +4 -0
  353. data/third_party/boringssl-with-bazel/src/crypto/dh_extra/params.c +5 -0
  354. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +9 -14
  355. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +4 -6
  356. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +10 -11
  357. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/check.c +37 -8
  358. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.c +38 -19
  359. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/internal.h +7 -0
  360. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +39 -16
  361. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/service_indicator/service_indicator.c +4 -7
  362. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +7 -0
  363. data/third_party/boringssl-with-bazel/src/crypto/internal.h +13 -21
  364. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +6 -23
  365. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/getentropy.c +4 -0
  366. data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +5 -0
  367. data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +1 -6
  368. data/third_party/boringssl-with-bazel/src/crypto/x509/by_file.c +0 -3
  369. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_d2.c +1 -3
  370. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +2 -3
  371. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +9 -1
  372. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +11 -1
  373. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +4 -1
  374. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +7 -9
  375. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +6 -2
  376. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +22 -20
  377. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +4 -0
  378. data/third_party/boringssl-with-bazel/src/include/openssl/stack.h +20 -12
  379. data/third_party/boringssl-with-bazel/src/include/openssl/target.h +50 -3
  380. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +0 -4
  381. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +2 -2
  382. data/third_party/boringssl-with-bazel/src/ssl/ssl_file.cc +4 -4
  383. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +2 -0
  384. metadata +41 -33
  385. data/src/core/lib/promise/detail/basic_join.h +0 -197
  386. data/src/core/lib/promise/detail/switch.h +0 -1455
  387. data/src/core/lib/promise/try_join.h +0 -82
  388. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +0 -403
  389. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_freebsd.c +0 -62
  390. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm.c +0 -38
  391. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_openbsd.c +0 -31
  392. data/third_party/re2/util/benchmark.h +0 -156
  393. data/third_party/re2/util/flags.h +0 -26
  394. data/third_party/re2/util/malloc_counter.h +0 -19
  395. data/third_party/re2/util/pcre.cc +0 -1025
  396. data/third_party/re2/util/pcre.h +0 -681
  397. data/third_party/re2/util/test.h +0 -50
  398. data/third_party/upb/upb/mini_table.h +0 -36
  399. data/third_party/zlib/gzclose.c +0 -25
  400. data/third_party/zlib/gzlib.c +0 -639
  401. data/third_party/zlib/gzread.c +0 -650
  402. data/third_party/zlib/gzwrite.c +0 -677
@@ -62,6 +62,8 @@
62
62
  // pseudo-struct:
63
63
  //
64
64
  // struct BackingArray {
65
+ // // The number of elements we can insert before growing the capacity.
66
+ // size_t growth_left;
65
67
  // // Control bytes for the "real" slots.
66
68
  // ctrl_t ctrl[capacity];
67
69
  // // Always `ctrl_t::kSentinel`. This is used by iterators to find when to
@@ -115,7 +117,7 @@
115
117
  // starting with that index and extract potential candidates: occupied slots
116
118
  // with a control byte equal to `H2(hash(x))`. If we find an empty slot in the
117
119
  // group, we stop and return an error. Each candidate slot `y` is compared with
118
- // `x`; if `x == y`, we are done and return `&y`; otherwise we contine to the
120
+ // `x`; if `x == y`, we are done and return `&y`; otherwise we continue to the
119
121
  // next probe index. Tombstones effectively behave like full slots that never
120
122
  // match the value we're looking for.
121
123
  //
@@ -174,21 +176,23 @@
174
176
 
175
177
  #include <algorithm>
176
178
  #include <cmath>
179
+ #include <cstddef>
177
180
  #include <cstdint>
178
181
  #include <cstring>
179
182
  #include <iterator>
180
183
  #include <limits>
181
184
  #include <memory>
185
+ #include <string>
182
186
  #include <tuple>
183
187
  #include <type_traits>
184
188
  #include <utility>
185
189
 
186
190
  #include "absl/base/config.h"
187
191
  #include "absl/base/internal/endian.h"
188
- #include "absl/base/internal/prefetch.h"
189
192
  #include "absl/base/internal/raw_logging.h"
190
193
  #include "absl/base/optimization.h"
191
194
  #include "absl/base/port.h"
195
+ #include "absl/base/prefetch.h"
192
196
  #include "absl/container/internal/common.h"
193
197
  #include "absl/container/internal/compressed_tuple.h"
194
198
  #include "absl/container/internal/container_memory.h"
@@ -235,6 +239,14 @@ namespace container_internal {
235
239
  // We use uint8_t so we don't need to worry about padding.
236
240
  using GenerationType = uint8_t;
237
241
 
242
+ // A sentinel value for empty generations. Using 0 makes it easy to constexpr
243
+ // initialize an array of this value.
244
+ constexpr GenerationType SentinelEmptyGeneration() { return 0; }
245
+
246
+ constexpr GenerationType NextGeneration(GenerationType generation) {
247
+ return ++generation == SentinelEmptyGeneration() ? ++generation : generation;
248
+ }
249
+
238
250
  #ifdef ABSL_SWISSTABLE_ENABLE_GENERATIONS
239
251
  constexpr bool SwisstableGenerationsEnabled() { return true; }
240
252
  constexpr size_t NumGenerationBytes() { return sizeof(GenerationType); }
@@ -367,12 +379,12 @@ class NonIterableBitMask {
367
379
  return static_cast<uint32_t>((bit_width(mask_) - 1) >> Shift);
368
380
  }
369
381
 
370
- // Return the number of trailing zero *abstract* bits.
382
+ // Returns the number of trailing zero *abstract* bits.
371
383
  uint32_t TrailingZeros() const {
372
384
  return container_internal::TrailingZeros(mask_) >> Shift;
373
385
  }
374
386
 
375
- // Return the number of leading zero *abstract* bits.
387
+ // Returns the number of leading zero *abstract* bits.
376
388
  uint32_t LeadingZeros() const {
377
389
  constexpr int total_significant_bits = SignificantBits << Shift;
378
390
  constexpr int extra_bits = sizeof(T) * 8 - total_significant_bits;
@@ -475,19 +487,23 @@ static_assert(ctrl_t::kDeleted == static_cast<ctrl_t>(-2),
475
487
  "ctrl_t::kDeleted must be -2 to make the implementation of "
476
488
  "ConvertSpecialToEmptyAndFullToDeleted efficient");
477
489
 
478
- ABSL_DLL extern const ctrl_t kEmptyGroup[17];
490
+ // See definition comment for why this is size 32.
491
+ ABSL_DLL extern const ctrl_t kEmptyGroup[32];
479
492
 
480
493
  // Returns a pointer to a control byte group that can be used by empty tables.
481
494
  inline ctrl_t* EmptyGroup() {
482
495
  // Const must be cast away here; no uses of this function will actually write
483
496
  // to it, because it is only used for empty tables.
484
- return const_cast<ctrl_t*>(kEmptyGroup);
497
+ return const_cast<ctrl_t*>(kEmptyGroup + 16);
485
498
  }
486
499
 
487
- // Returns a pointer to the generation byte at the end of the empty group, if it
488
- // exists.
489
- inline GenerationType* EmptyGeneration() {
490
- return reinterpret_cast<GenerationType*>(EmptyGroup() + 16);
500
+ // Returns a pointer to a generation to use for an empty hashtable.
501
+ GenerationType* EmptyGeneration();
502
+
503
+ // Returns whether `generation` is a generation for an empty hashtable that
504
+ // could be returned by EmptyGeneration().
505
+ inline bool IsEmptyGeneration(const GenerationType* generation) {
506
+ return *generation == SentinelEmptyGeneration();
491
507
  }
492
508
 
493
509
  // Mixes a randomly generated per-process seed with `hash` and `ctrl` to
@@ -674,9 +690,10 @@ struct GroupAArch64Impl {
674
690
  void ConvertSpecialToEmptyAndFullToDeleted(ctrl_t* dst) const {
675
691
  uint64_t mask = vget_lane_u64(vreinterpret_u64_u8(ctrl), 0);
676
692
  constexpr uint64_t msbs = 0x8080808080808080ULL;
677
- constexpr uint64_t lsbs = 0x0101010101010101ULL;
678
- auto x = mask & msbs;
679
- auto res = (~x + (x >> 7)) & ~lsbs;
693
+ constexpr uint64_t slsbs = 0x0202020202020202ULL;
694
+ constexpr uint64_t midbs = 0x7e7e7e7e7e7e7e7eULL;
695
+ auto x = slsbs & (mask >> 6);
696
+ auto res = (x + midbs) | msbs;
680
697
  little_endian::Store64(dst, res);
681
698
  }
682
699
 
@@ -749,6 +766,15 @@ using Group = GroupAArch64Impl;
749
766
  using Group = GroupPortableImpl;
750
767
  #endif
751
768
 
769
+ // When there is an insertion with no reserved growth, we rehash with
770
+ // probability `min(1, RehashProbabilityConstant() / capacity())`. Using a
771
+ // constant divided by capacity ensures that inserting N elements is still O(N)
772
+ // in the average case. Using the constant 16 means that we expect to rehash ~8
773
+ // times more often than when generations are disabled. We are adding expected
774
+ // rehash_probability * #insertions/capacity_growth = 16/capacity * ((7/8 -
775
+ // 7/16) * capacity)/capacity_growth = ~7 extra rehashes per capacity growth.
776
+ inline size_t RehashProbabilityConstant() { return 16; }
777
+
752
778
  class CommonFieldsGenerationInfoEnabled {
753
779
  // A sentinel value for reserved_growth_ indicating that we just ran out of
754
780
  // reserved growth on the last insertion. When reserve is called and then
@@ -760,8 +786,11 @@ class CommonFieldsGenerationInfoEnabled {
760
786
  public:
761
787
  CommonFieldsGenerationInfoEnabled() = default;
762
788
  CommonFieldsGenerationInfoEnabled(CommonFieldsGenerationInfoEnabled&& that)
763
- : reserved_growth_(that.reserved_growth_), generation_(that.generation_) {
789
+ : reserved_growth_(that.reserved_growth_),
790
+ reservation_size_(that.reservation_size_),
791
+ generation_(that.generation_) {
764
792
  that.reserved_growth_ = 0;
793
+ that.reservation_size_ = 0;
765
794
  that.generation_ = EmptyGeneration();
766
795
  }
767
796
  CommonFieldsGenerationInfoEnabled& operator=(
@@ -769,19 +798,17 @@ class CommonFieldsGenerationInfoEnabled {
769
798
 
770
799
  // Whether we should rehash on insert in order to detect bugs of using invalid
771
800
  // references. We rehash on the first insertion after reserved_growth_ reaches
772
- // 0 after a call to reserve.
773
- // TODO(b/254649633): we could potentially do a rehash with low probability
801
+ // 0 after a call to reserve. We also do a rehash with low probability
774
802
  // whenever reserved_growth_ is zero.
775
- bool should_rehash_for_bug_detection_on_insert() const {
776
- return reserved_growth_ == kReservedGrowthJustRanOut;
777
- }
803
+ bool should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl,
804
+ size_t capacity) const;
778
805
  void maybe_increment_generation_on_insert() {
779
806
  if (reserved_growth_ == kReservedGrowthJustRanOut) reserved_growth_ = 0;
780
807
 
781
808
  if (reserved_growth_ > 0) {
782
809
  if (--reserved_growth_ == 0) reserved_growth_ = kReservedGrowthJustRanOut;
783
810
  } else {
784
- ++*generation_;
811
+ *generation_ = NextGeneration(*generation_);
785
812
  }
786
813
  }
787
814
  void reset_reserved_growth(size_t reservation, size_t size) {
@@ -789,6 +816,8 @@ class CommonFieldsGenerationInfoEnabled {
789
816
  }
790
817
  size_t reserved_growth() const { return reserved_growth_; }
791
818
  void set_reserved_growth(size_t r) { reserved_growth_ = r; }
819
+ size_t reservation_size() const { return reservation_size_; }
820
+ void set_reservation_size(size_t r) { reservation_size_ = r; }
792
821
  GenerationType generation() const { return *generation_; }
793
822
  void set_generation(GenerationType g) { *generation_ = g; }
794
823
  GenerationType* generation_ptr() const { return generation_; }
@@ -796,10 +825,14 @@ class CommonFieldsGenerationInfoEnabled {
796
825
 
797
826
  private:
798
827
  // The number of insertions remaining that are guaranteed to not rehash due to
799
- // a prior call to reserve. Note: we store reserved growth rather than
828
+ // a prior call to reserve. Note: we store reserved growth in addition to
800
829
  // reservation size because calls to erase() decrease size_ but don't decrease
801
830
  // reserved growth.
802
831
  size_t reserved_growth_ = 0;
832
+ // The maximum argument to reserve() since the container was cleared. We need
833
+ // to keep track of this, in addition to reserved growth, because we reset
834
+ // reserved growth to this when erase(begin(), end()) is called.
835
+ size_t reservation_size_ = 0;
803
836
  // Pointer to the generation counter, which is used to validate iterators and
804
837
  // is stored in the backing array between the control bytes and the slots.
805
838
  // Note that we can't store the generation inside the container itself and
@@ -820,11 +853,15 @@ class CommonFieldsGenerationInfoDisabled {
820
853
  CommonFieldsGenerationInfoDisabled& operator=(
821
854
  CommonFieldsGenerationInfoDisabled&&) = default;
822
855
 
823
- bool should_rehash_for_bug_detection_on_insert() const { return false; }
856
+ bool should_rehash_for_bug_detection_on_insert(const ctrl_t*, size_t) const {
857
+ return false;
858
+ }
824
859
  void maybe_increment_generation_on_insert() {}
825
860
  void reset_reserved_growth(size_t, size_t) {}
826
861
  size_t reserved_growth() const { return 0; }
827
862
  void set_reserved_growth(size_t) {}
863
+ size_t reservation_size() const { return 0; }
864
+ void set_reservation_size(size_t) {}
828
865
  GenerationType generation() const { return 0; }
829
866
  void set_generation(GenerationType) {}
830
867
  GenerationType* generation_ptr() const { return nullptr; }
@@ -867,6 +904,44 @@ using CommonFieldsGenerationInfo = CommonFieldsGenerationInfoDisabled;
867
904
  using HashSetIteratorGenerationInfo = HashSetIteratorGenerationInfoDisabled;
868
905
  #endif
869
906
 
907
+ // Returns whether `n` is a valid capacity (i.e., number of slots).
908
+ //
909
+ // A valid capacity is a non-zero integer `2^m - 1`.
910
+ inline bool IsValidCapacity(size_t n) { return ((n + 1) & n) == 0 && n > 0; }
911
+
912
+ // Computes the offset from the start of the backing allocation of the control
913
+ // bytes. growth_left is stored at the beginning of the backing array.
914
+ inline size_t ControlOffset() { return sizeof(size_t); }
915
+
916
+ // Returns the number of "cloned control bytes".
917
+ //
918
+ // This is the number of control bytes that are present both at the beginning
919
+ // of the control byte array and at the end, such that we can create a
920
+ // `Group::kWidth`-width probe window starting from any control byte.
921
+ constexpr size_t NumClonedBytes() { return Group::kWidth - 1; }
922
+
923
+ // Given the capacity of a table, computes the offset (from the start of the
924
+ // backing allocation) of the generation counter (if it exists).
925
+ inline size_t GenerationOffset(size_t capacity) {
926
+ assert(IsValidCapacity(capacity));
927
+ const size_t num_control_bytes = capacity + 1 + NumClonedBytes();
928
+ return ControlOffset() + num_control_bytes;
929
+ }
930
+
931
+ // Given the capacity of a table, computes the offset (from the start of the
932
+ // backing allocation) at which the slots begin.
933
+ inline size_t SlotOffset(size_t capacity, size_t slot_align) {
934
+ assert(IsValidCapacity(capacity));
935
+ return (GenerationOffset(capacity) + NumGenerationBytes() + slot_align - 1) &
936
+ (~slot_align + 1);
937
+ }
938
+
939
+ // Given the capacity of a table, computes the total size of the backing
940
+ // array.
941
+ inline size_t AllocSize(size_t capacity, size_t slot_size, size_t slot_align) {
942
+ return SlotOffset(capacity, slot_align) + capacity * slot_size;
943
+ }
944
+
870
945
  // CommonFields hold the fields in raw_hash_set that do not depend
871
946
  // on template parameters. This allows us to conveniently pass all
872
947
  // of this state to helper functions as a single argument.
@@ -884,72 +959,102 @@ class CommonFields : public CommonFieldsGenerationInfo {
884
959
  std::move(static_cast<CommonFieldsGenerationInfo&&>(that))),
885
960
  // Explicitly copying fields into "this" and then resetting "that"
886
961
  // fields generates less code then calling absl::exchange per field.
887
- control_(that.control_),
888
- slots_(that.slots_),
889
- size_(that.size_),
890
- capacity_(that.capacity_),
891
- compressed_tuple_(that.growth_left(), std::move(that.infoz())) {
892
- that.control_ = EmptyGroup();
893
- that.slots_ = nullptr;
894
- that.size_ = 0;
895
- that.capacity_ = 0;
896
- that.growth_left() = 0;
962
+ control_(that.control()),
963
+ slots_(that.slot_array()),
964
+ capacity_(that.capacity()),
965
+ compressed_tuple_(that.size(), std::move(that.infoz())) {
966
+ that.set_control(EmptyGroup());
967
+ that.set_slots(nullptr);
968
+ that.set_capacity(0);
969
+ that.set_size(0);
897
970
  }
898
971
  CommonFields& operator=(CommonFields&&) = default;
899
972
 
973
+ ctrl_t* control() const { return control_; }
974
+ void set_control(ctrl_t* c) { control_ = c; }
975
+ void* backing_array_start() const {
976
+ // growth_left is stored before control bytes.
977
+ assert(reinterpret_cast<uintptr_t>(control()) % alignof(size_t) == 0);
978
+ return control() - sizeof(size_t);
979
+ }
980
+
981
+ // Note: we can't use slots() because Qt defines "slots" as a macro.
982
+ void* slot_array() const { return slots_; }
983
+ void set_slots(void* s) { slots_ = s; }
984
+
985
+ // The number of filled slots.
986
+ size_t size() const { return compressed_tuple_.template get<0>(); }
987
+ void set_size(size_t s) { compressed_tuple_.template get<0>() = s; }
988
+
989
+ // The total number of available slots.
990
+ size_t capacity() const { return capacity_; }
991
+ void set_capacity(size_t c) {
992
+ assert(c == 0 || IsValidCapacity(c));
993
+ capacity_ = c;
994
+ }
995
+
900
996
  // The number of slots we can still fill without needing to rehash.
901
- size_t& growth_left() { return compressed_tuple_.template get<0>(); }
997
+ // This is stored in the heap allocation before the control bytes.
998
+ size_t growth_left() const {
999
+ return *reinterpret_cast<size_t*>(backing_array_start());
1000
+ }
1001
+ void set_growth_left(size_t gl) {
1002
+ *reinterpret_cast<size_t*>(backing_array_start()) = gl;
1003
+ }
902
1004
 
903
1005
  HashtablezInfoHandle& infoz() { return compressed_tuple_.template get<1>(); }
904
1006
  const HashtablezInfoHandle& infoz() const {
905
1007
  return compressed_tuple_.template get<1>();
906
1008
  }
907
1009
 
1010
+ bool should_rehash_for_bug_detection_on_insert() const {
1011
+ return CommonFieldsGenerationInfo::
1012
+ should_rehash_for_bug_detection_on_insert(control(), capacity());
1013
+ }
908
1014
  void reset_reserved_growth(size_t reservation) {
909
- CommonFieldsGenerationInfo::reset_reserved_growth(reservation, size_);
1015
+ CommonFieldsGenerationInfo::reset_reserved_growth(reservation, size());
1016
+ }
1017
+
1018
+ // The size of the backing array allocation.
1019
+ size_t alloc_size(size_t slot_size, size_t slot_align) const {
1020
+ return AllocSize(capacity(), slot_size, slot_align);
910
1021
  }
911
1022
 
1023
+ // Returns the number of control bytes set to kDeleted. For testing only.
1024
+ size_t TombstonesCount() const {
1025
+ return static_cast<size_t>(
1026
+ std::count(control(), control() + capacity(), ctrl_t::kDeleted));
1027
+ }
1028
+
1029
+ private:
912
1030
  // TODO(b/259599413): Investigate removing some of these fields:
913
1031
  // - control/slots can be derived from each other
914
- // - size can be moved into the slot array
1032
+ // - we can use 6 bits for capacity since it's always a power of two minus 1
915
1033
 
916
- // The control bytes (and, also, a pointer to the base of the backing array).
1034
+ // The control bytes (and, also, a pointer near to the base of the backing
1035
+ // array).
917
1036
  //
918
1037
  // This contains `capacity + 1 + NumClonedBytes()` entries, even
919
1038
  // when the table is empty (hence EmptyGroup).
1039
+ //
1040
+ // Note that growth_left is stored immediately before this pointer.
920
1041
  ctrl_t* control_ = EmptyGroup();
921
1042
 
922
1043
  // The beginning of the slots, located at `SlotOffset()` bytes after
923
1044
  // `control`. May be null for empty tables.
924
1045
  void* slots_ = nullptr;
925
1046
 
926
- // The number of filled slots.
927
- size_t size_ = 0;
928
-
929
- // The total number of available slots.
930
1047
  size_t capacity_ = 0;
931
1048
 
932
- // Bundle together growth_left and HashtablezInfoHandle to ensure EBO for
1049
+ // Bundle together size and HashtablezInfoHandle to ensure EBO for
933
1050
  // HashtablezInfoHandle when sampling is turned off.
934
1051
  absl::container_internal::CompressedTuple<size_t, HashtablezInfoHandle>
935
1052
  compressed_tuple_{0u, HashtablezInfoHandle{}};
936
1053
  };
937
1054
 
938
- // Returns he number of "cloned control bytes".
939
- //
940
- // This is the number of control bytes that are present both at the beginning
941
- // of the control byte array and at the end, such that we can create a
942
- // `Group::kWidth`-width probe window starting from any control byte.
943
- constexpr size_t NumClonedBytes() { return Group::kWidth - 1; }
944
-
945
1055
  template <class Policy, class Hash, class Eq, class Alloc>
946
1056
  class raw_hash_set;
947
1057
 
948
- // Returns whether `n` is a valid capacity (i.e., number of slots).
949
- //
950
- // A valid capacity is a non-zero integer `2^m - 1`.
951
- inline bool IsValidCapacity(size_t n) { return ((n + 1) & n) == 0 && n > 0; }
952
-
953
1058
  // Returns the next valid capacity after `n`.
954
1059
  inline size_t NextCapacity(size_t n) {
955
1060
  assert(IsValidCapacity(n) || n == 0);
@@ -1021,34 +1126,75 @@ size_t SelectBucketCountForIterRange(InputIter first, InputIter last,
1021
1126
  return 0;
1022
1127
  }
1023
1128
 
1024
- #define ABSL_INTERNAL_ASSERT_IS_FULL(ctrl, generation, generation_ptr, \
1025
- operation) \
1026
- do { \
1027
- ABSL_HARDENING_ASSERT( \
1028
- (ctrl != nullptr) && operation \
1029
- " called on invalid iterator. The iterator might be an end() " \
1030
- "iterator or may have been default constructed."); \
1031
- if (SwisstableGenerationsEnabled() && generation != *generation_ptr) \
1032
- ABSL_INTERNAL_LOG(FATAL, operation \
1033
- " called on invalidated iterator. The table could " \
1034
- "have rehashed since this iterator was initialized."); \
1035
- ABSL_HARDENING_ASSERT( \
1036
- (IsFull(*ctrl)) && operation \
1037
- " called on invalid iterator. The element might have been erased or " \
1038
- "the table might have rehashed."); \
1039
- } while (0)
1129
+ constexpr bool SwisstableDebugEnabled() {
1130
+ #if defined(ABSL_SWISSTABLE_ENABLE_GENERATIONS) || \
1131
+ ABSL_OPTION_HARDENED == 1 || !defined(NDEBUG)
1132
+ return true;
1133
+ #else
1134
+ return false;
1135
+ #endif
1136
+ }
1137
+
1138
+ inline void AssertIsFull(const ctrl_t* ctrl, GenerationType generation,
1139
+ const GenerationType* generation_ptr,
1140
+ const char* operation) {
1141
+ if (!SwisstableDebugEnabled()) return;
1142
+ if (ctrl == nullptr) {
1143
+ ABSL_INTERNAL_LOG(FATAL,
1144
+ std::string(operation) + " called on end() iterator.");
1145
+ }
1146
+ if (ctrl == EmptyGroup()) {
1147
+ ABSL_INTERNAL_LOG(FATAL, std::string(operation) +
1148
+ " called on default-constructed iterator.");
1149
+ }
1150
+ if (SwisstableGenerationsEnabled()) {
1151
+ if (generation != *generation_ptr) {
1152
+ ABSL_INTERNAL_LOG(FATAL,
1153
+ std::string(operation) +
1154
+ " called on invalid iterator. The table could have "
1155
+ "rehashed since this iterator was initialized.");
1156
+ }
1157
+ if (!IsFull(*ctrl)) {
1158
+ ABSL_INTERNAL_LOG(
1159
+ FATAL,
1160
+ std::string(operation) +
1161
+ " called on invalid iterator. The element was likely erased.");
1162
+ }
1163
+ } else {
1164
+ if (!IsFull(*ctrl)) {
1165
+ ABSL_INTERNAL_LOG(
1166
+ FATAL,
1167
+ std::string(operation) +
1168
+ " called on invalid iterator. The element might have been erased "
1169
+ "or the table might have rehashed. Consider running with "
1170
+ "--config=asan to diagnose rehashing issues.");
1171
+ }
1172
+ }
1173
+ }
1040
1174
 
1041
1175
  // Note that for comparisons, null/end iterators are valid.
1042
1176
  inline void AssertIsValidForComparison(const ctrl_t* ctrl,
1043
1177
  GenerationType generation,
1044
1178
  const GenerationType* generation_ptr) {
1045
- ABSL_HARDENING_ASSERT((ctrl == nullptr || IsFull(*ctrl)) &&
1046
- "Invalid iterator comparison. The element might have "
1047
- "been erased or the table might have rehashed.");
1048
- if (SwisstableGenerationsEnabled() && generation != *generation_ptr) {
1049
- ABSL_INTERNAL_LOG(FATAL,
1050
- "Invalid iterator comparison. The table could have "
1051
- "rehashed since this iterator was initialized.");
1179
+ if (!SwisstableDebugEnabled()) return;
1180
+ const bool ctrl_is_valid_for_comparison =
1181
+ ctrl == nullptr || ctrl == EmptyGroup() || IsFull(*ctrl);
1182
+ if (SwisstableGenerationsEnabled()) {
1183
+ if (generation != *generation_ptr) {
1184
+ ABSL_INTERNAL_LOG(FATAL,
1185
+ "Invalid iterator comparison. The table could have "
1186
+ "rehashed since this iterator was initialized.");
1187
+ }
1188
+ if (!ctrl_is_valid_for_comparison) {
1189
+ ABSL_INTERNAL_LOG(
1190
+ FATAL, "Invalid iterator comparison. The element was likely erased.");
1191
+ }
1192
+ } else {
1193
+ ABSL_HARDENING_ASSERT(
1194
+ ctrl_is_valid_for_comparison &&
1195
+ "Invalid iterator comparison. The element might have been erased or "
1196
+ "the table might have rehashed. Consider running with --config=asan to "
1197
+ "diagnose rehashing issues.");
1052
1198
  }
1053
1199
  }
1054
1200
 
@@ -1074,16 +1220,54 @@ inline bool AreItersFromSameContainer(const ctrl_t* ctrl_a,
1074
1220
  // Asserts that two iterators come from the same container.
1075
1221
  // Note: we take slots by reference so that it's not UB if they're uninitialized
1076
1222
  // as long as we don't read them (when ctrl is null).
1077
- // TODO(b/254649633): when generations are enabled, we can detect more cases of
1078
- // different containers by comparing the pointers to the generations - this
1079
- // can cover cases of end iterators that we would otherwise miss.
1080
1223
  inline void AssertSameContainer(const ctrl_t* ctrl_a, const ctrl_t* ctrl_b,
1081
1224
  const void* const& slot_a,
1082
- const void* const& slot_b) {
1083
- ABSL_HARDENING_ASSERT(
1084
- AreItersFromSameContainer(ctrl_a, ctrl_b, slot_a, slot_b) &&
1085
- "Invalid iterator comparison. The iterators may be from different "
1086
- "containers or the container might have rehashed.");
1225
+ const void* const& slot_b,
1226
+ const GenerationType* generation_ptr_a,
1227
+ const GenerationType* generation_ptr_b) {
1228
+ if (!SwisstableDebugEnabled()) return;
1229
+ const bool a_is_default = ctrl_a == EmptyGroup();
1230
+ const bool b_is_default = ctrl_b == EmptyGroup();
1231
+ if (a_is_default != b_is_default) {
1232
+ ABSL_INTERNAL_LOG(
1233
+ FATAL,
1234
+ "Invalid iterator comparison. Comparing default-constructed iterator "
1235
+ "with non-default-constructed iterator.");
1236
+ }
1237
+ if (a_is_default && b_is_default) return;
1238
+
1239
+ if (SwisstableGenerationsEnabled()) {
1240
+ if (generation_ptr_a == generation_ptr_b) return;
1241
+ const bool a_is_empty = IsEmptyGeneration(generation_ptr_a);
1242
+ const bool b_is_empty = IsEmptyGeneration(generation_ptr_b);
1243
+ if (a_is_empty != b_is_empty) {
1244
+ ABSL_INTERNAL_LOG(FATAL,
1245
+ "Invalid iterator comparison. Comparing iterator from "
1246
+ "a non-empty hashtable with an iterator from an empty "
1247
+ "hashtable.");
1248
+ }
1249
+ if (a_is_empty && b_is_empty) {
1250
+ ABSL_INTERNAL_LOG(FATAL,
1251
+ "Invalid iterator comparison. Comparing iterators from "
1252
+ "different empty hashtables.");
1253
+ }
1254
+ const bool a_is_end = ctrl_a == nullptr;
1255
+ const bool b_is_end = ctrl_b == nullptr;
1256
+ if (a_is_end || b_is_end) {
1257
+ ABSL_INTERNAL_LOG(FATAL,
1258
+ "Invalid iterator comparison. Comparing iterator with "
1259
+ "an end() iterator from a different hashtable.");
1260
+ }
1261
+ ABSL_INTERNAL_LOG(FATAL,
1262
+ "Invalid iterator comparison. Comparing non-end() "
1263
+ "iterators from different hashtables.");
1264
+ } else {
1265
+ ABSL_HARDENING_ASSERT(
1266
+ AreItersFromSameContainer(ctrl_a, ctrl_b, slot_a, slot_b) &&
1267
+ "Invalid iterator comparison. The iterators may be from different "
1268
+ "containers or the container might have rehashed. Consider running "
1269
+ "with --config=asan to diagnose rehashing issues.");
1270
+ }
1087
1271
  }
1088
1272
 
1089
1273
  struct FindInfo {
@@ -1106,11 +1290,13 @@ struct FindInfo {
1106
1290
  inline bool is_small(size_t capacity) { return capacity < Group::kWidth - 1; }
1107
1291
 
1108
1292
  // Begins a probing operation on `common.control`, using `hash`.
1109
- inline probe_seq<Group::kWidth> probe(const CommonFields& common, size_t hash) {
1110
- const ctrl_t* ctrl = common.control_;
1111
- const size_t capacity = common.capacity_;
1293
+ inline probe_seq<Group::kWidth> probe(const ctrl_t* ctrl, const size_t capacity,
1294
+ size_t hash) {
1112
1295
  return probe_seq<Group::kWidth>(H1(hash, ctrl), capacity);
1113
1296
  }
1297
+ inline probe_seq<Group::kWidth> probe(const CommonFields& common, size_t hash) {
1298
+ return probe(common.control(), common.capacity(), hash);
1299
+ }
1114
1300
 
1115
1301
  // Probes an array of control bits using a probe sequence derived from `hash`,
1116
1302
  // and returns the offset corresponding to the first deleted or empty slot.
@@ -1122,7 +1308,7 @@ inline probe_seq<Group::kWidth> probe(const CommonFields& common, size_t hash) {
1122
1308
  template <typename = void>
1123
1309
  inline FindInfo find_first_non_full(const CommonFields& common, size_t hash) {
1124
1310
  auto seq = probe(common, hash);
1125
- const ctrl_t* ctrl = common.control_;
1311
+ const ctrl_t* ctrl = common.control();
1126
1312
  while (true) {
1127
1313
  Group g{ctrl + seq.offset()};
1128
1314
  auto mask = g.MaskEmptyOrDeleted();
@@ -1132,14 +1318,14 @@ inline FindInfo find_first_non_full(const CommonFields& common, size_t hash) {
1132
1318
  // In debug build we will randomly insert in either the front or back of
1133
1319
  // the group.
1134
1320
  // TODO(kfm,sbenza): revisit after we do unconditional mixing
1135
- if (!is_small(common.capacity_) && ShouldInsertBackwards(hash, ctrl)) {
1321
+ if (!is_small(common.capacity()) && ShouldInsertBackwards(hash, ctrl)) {
1136
1322
  return {seq.offset(mask.HighestBitSet()), seq.index()};
1137
1323
  }
1138
1324
  #endif
1139
1325
  return {seq.offset(mask.LowestBitSet()), seq.index()};
1140
1326
  }
1141
1327
  seq.next();
1142
- assert(seq.index() <= common.capacity_ && "full table!");
1328
+ assert(seq.index() <= common.capacity() && "full table!");
1143
1329
  }
1144
1330
  }
1145
1331
 
@@ -1153,18 +1339,18 @@ extern template FindInfo find_first_non_full(const CommonFields&, size_t);
1153
1339
  FindInfo find_first_non_full_outofline(const CommonFields&, size_t);
1154
1340
 
1155
1341
  inline void ResetGrowthLeft(CommonFields& common) {
1156
- common.growth_left() = CapacityToGrowth(common.capacity_) - common.size_;
1342
+ common.set_growth_left(CapacityToGrowth(common.capacity()) - common.size());
1157
1343
  }
1158
1344
 
1159
1345
  // Sets `ctrl` to `{kEmpty, kSentinel, ..., kEmpty}`, marking the entire
1160
1346
  // array as marked as empty.
1161
1347
  inline void ResetCtrl(CommonFields& common, size_t slot_size) {
1162
- const size_t capacity = common.capacity_;
1163
- ctrl_t* ctrl = common.control_;
1348
+ const size_t capacity = common.capacity();
1349
+ ctrl_t* ctrl = common.control();
1164
1350
  std::memset(ctrl, static_cast<int8_t>(ctrl_t::kEmpty),
1165
1351
  capacity + 1 + NumClonedBytes());
1166
1352
  ctrl[capacity] = ctrl_t::kSentinel;
1167
- SanitizerPoisonMemoryRegion(common.slots_, slot_size * capacity);
1353
+ SanitizerPoisonMemoryRegion(common.slot_array(), slot_size * capacity);
1168
1354
  ResetGrowthLeft(common);
1169
1355
  }
1170
1356
 
@@ -1174,17 +1360,17 @@ inline void ResetCtrl(CommonFields& common, size_t slot_size) {
1174
1360
  // mirror the value to the cloned tail if necessary.
1175
1361
  inline void SetCtrl(const CommonFields& common, size_t i, ctrl_t h,
1176
1362
  size_t slot_size) {
1177
- const size_t capacity = common.capacity_;
1363
+ const size_t capacity = common.capacity();
1178
1364
  assert(i < capacity);
1179
1365
 
1180
- auto* slot_i = static_cast<const char*>(common.slots_) + i * slot_size;
1366
+ auto* slot_i = static_cast<const char*>(common.slot_array()) + i * slot_size;
1181
1367
  if (IsFull(h)) {
1182
1368
  SanitizerUnpoisonMemoryRegion(slot_i, slot_size);
1183
1369
  } else {
1184
1370
  SanitizerPoisonMemoryRegion(slot_i, slot_size);
1185
1371
  }
1186
1372
 
1187
- ctrl_t* ctrl = common.control_;
1373
+ ctrl_t* ctrl = common.control();
1188
1374
  ctrl[i] = h;
1189
1375
  ctrl[((i - NumClonedBytes()) & capacity) + (NumClonedBytes() & capacity)] = h;
1190
1376
  }
@@ -1195,56 +1381,41 @@ inline void SetCtrl(const CommonFields& common, size_t i, h2_t h,
1195
1381
  SetCtrl(common, i, static_cast<ctrl_t>(h), slot_size);
1196
1382
  }
1197
1383
 
1198
- // Given the capacity of a table, computes the offset (from the start of the
1199
- // backing allocation) of the generation counter (if it exists).
1200
- inline size_t GenerationOffset(size_t capacity) {
1201
- assert(IsValidCapacity(capacity));
1202
- const size_t num_control_bytes = capacity + 1 + NumClonedBytes();
1203
- return num_control_bytes;
1204
- }
1205
-
1206
- // Given the capacity of a table, computes the offset (from the start of the
1207
- // backing allocation) at which the slots begin.
1208
- inline size_t SlotOffset(size_t capacity, size_t slot_align) {
1209
- assert(IsValidCapacity(capacity));
1210
- const size_t num_control_bytes = capacity + 1 + NumClonedBytes();
1211
- return (num_control_bytes + NumGenerationBytes() + slot_align - 1) &
1212
- (~slot_align + 1);
1213
- }
1214
-
1215
- // Given the capacity of a table, computes the total size of the backing
1216
- // array.
1217
- inline size_t AllocSize(size_t capacity, size_t slot_size, size_t slot_align) {
1218
- return SlotOffset(capacity, slot_align) + capacity * slot_size;
1384
+ // growth_left (which is a size_t) is stored with the backing array.
1385
+ constexpr size_t BackingArrayAlignment(size_t align_of_slot) {
1386
+ return (std::max)(align_of_slot, alignof(size_t));
1219
1387
  }
1220
1388
 
1221
1389
  template <typename Alloc, size_t SizeOfSlot, size_t AlignOfSlot>
1222
1390
  ABSL_ATTRIBUTE_NOINLINE void InitializeSlots(CommonFields& c, Alloc alloc) {
1223
- assert(c.capacity_);
1391
+ assert(c.capacity());
1224
1392
  // Folks with custom allocators often make unwarranted assumptions about the
1225
1393
  // behavior of their classes vis-a-vis trivial destructability and what
1226
1394
  // calls they will or won't make. Avoid sampling for people with custom
1227
1395
  // allocators to get us out of this mess. This is not a hard guarantee but
1228
1396
  // a workaround while we plan the exact guarantee we want to provide.
1229
1397
  const size_t sample_size =
1230
- (std::is_same<Alloc, std::allocator<char>>::value && c.slots_ == nullptr)
1398
+ (std::is_same<Alloc, std::allocator<char>>::value &&
1399
+ c.slot_array() == nullptr)
1231
1400
  ? SizeOfSlot
1232
1401
  : 0;
1233
1402
 
1234
- const size_t cap = c.capacity_;
1403
+ const size_t cap = c.capacity();
1404
+ const size_t alloc_size = AllocSize(cap, SizeOfSlot, AlignOfSlot);
1405
+ // growth_left (which is a size_t) is stored with the backing array.
1235
1406
  char* mem = static_cast<char*>(
1236
- Allocate<AlignOfSlot>(&alloc, AllocSize(cap, SizeOfSlot, AlignOfSlot)));
1407
+ Allocate<BackingArrayAlignment(AlignOfSlot)>(&alloc, alloc_size));
1237
1408
  const GenerationType old_generation = c.generation();
1238
1409
  c.set_generation_ptr(
1239
1410
  reinterpret_cast<GenerationType*>(mem + GenerationOffset(cap)));
1240
- c.set_generation(old_generation + 1);
1241
- c.control_ = reinterpret_cast<ctrl_t*>(mem);
1242
- c.slots_ = mem + SlotOffset(cap, AlignOfSlot);
1411
+ c.set_generation(NextGeneration(old_generation));
1412
+ c.set_control(reinterpret_cast<ctrl_t*>(mem + ControlOffset()));
1413
+ c.set_slots(mem + SlotOffset(cap, AlignOfSlot));
1243
1414
  ResetCtrl(c, SizeOfSlot);
1244
1415
  if (sample_size) {
1245
1416
  c.infoz() = Sample(sample_size);
1246
1417
  }
1247
- c.infoz().RecordStorageChanged(c.size_, cap);
1418
+ c.infoz().RecordStorageChanged(c.size(), cap);
1248
1419
  }
1249
1420
 
1250
1421
  // PolicyFunctions bundles together some information for a particular
@@ -1254,15 +1425,14 @@ ABSL_ATTRIBUTE_NOINLINE void InitializeSlots(CommonFields& c, Alloc alloc) {
1254
1425
  struct PolicyFunctions {
1255
1426
  size_t slot_size;
1256
1427
 
1257
- // Return the hash of the pointed-to slot.
1428
+ // Returns the hash of the pointed-to slot.
1258
1429
  size_t (*hash_slot)(void* set, void* slot);
1259
1430
 
1260
1431
  // Transfer the contents of src_slot to dst_slot.
1261
1432
  void (*transfer)(void* set, void* dst_slot, void* src_slot);
1262
1433
 
1263
- // Deallocate the specified backing store which is sized for n slots.
1264
- void (*dealloc)(void* set, const PolicyFunctions& policy, ctrl_t* ctrl,
1265
- void* slot_array, size_t n);
1434
+ // Deallocate the backing store from common.
1435
+ void (*dealloc)(CommonFields& common, const PolicyFunctions& policy);
1266
1436
  };
1267
1437
 
1268
1438
  // ClearBackingArray clears the backing array, either modifying it in place,
@@ -1279,16 +1449,16 @@ void EraseMetaOnly(CommonFields& c, ctrl_t* it, size_t slot_size);
1279
1449
  // function body for raw_hash_set instantiations that have the
1280
1450
  // same slot alignment.
1281
1451
  template <size_t AlignOfSlot>
1282
- ABSL_ATTRIBUTE_NOINLINE void DeallocateStandard(void*,
1283
- const PolicyFunctions& policy,
1284
- ctrl_t* ctrl, void* slot_array,
1285
- size_t n) {
1452
+ ABSL_ATTRIBUTE_NOINLINE void DeallocateStandard(CommonFields& common,
1453
+ const PolicyFunctions& policy) {
1286
1454
  // Unpoison before returning the memory to the allocator.
1287
- SanitizerUnpoisonMemoryRegion(slot_array, policy.slot_size * n);
1455
+ SanitizerUnpoisonMemoryRegion(common.slot_array(),
1456
+ policy.slot_size * common.capacity());
1288
1457
 
1289
1458
  std::allocator<char> alloc;
1290
- Deallocate<AlignOfSlot>(&alloc, ctrl,
1291
- AllocSize(n, policy.slot_size, AlignOfSlot));
1459
+ Deallocate<BackingArrayAlignment(AlignOfSlot)>(
1460
+ &alloc, common.backing_array_start(),
1461
+ common.alloc_size(policy.slot_size, AlignOfSlot));
1292
1462
  }
1293
1463
 
1294
1464
  // For trivially relocatable types we use memcpy directly. This allows us to
@@ -1419,22 +1589,19 @@ class raw_hash_set {
1419
1589
 
1420
1590
  // PRECONDITION: not an end() iterator.
1421
1591
  reference operator*() const {
1422
- ABSL_INTERNAL_ASSERT_IS_FULL(ctrl_, generation(), generation_ptr(),
1423
- "operator*()");
1592
+ AssertIsFull(ctrl_, generation(), generation_ptr(), "operator*()");
1424
1593
  return PolicyTraits::element(slot_);
1425
1594
  }
1426
1595
 
1427
1596
  // PRECONDITION: not an end() iterator.
1428
1597
  pointer operator->() const {
1429
- ABSL_INTERNAL_ASSERT_IS_FULL(ctrl_, generation(), generation_ptr(),
1430
- "operator->");
1598
+ AssertIsFull(ctrl_, generation(), generation_ptr(), "operator->");
1431
1599
  return &operator*();
1432
1600
  }
1433
1601
 
1434
1602
  // PRECONDITION: not an end() iterator.
1435
1603
  iterator& operator++() {
1436
- ABSL_INTERNAL_ASSERT_IS_FULL(ctrl_, generation(), generation_ptr(),
1437
- "operator++");
1604
+ AssertIsFull(ctrl_, generation(), generation_ptr(), "operator++");
1438
1605
  ++ctrl_;
1439
1606
  ++slot_;
1440
1607
  skip_empty_or_deleted();
@@ -1448,9 +1615,10 @@ class raw_hash_set {
1448
1615
  }
1449
1616
 
1450
1617
  friend bool operator==(const iterator& a, const iterator& b) {
1451
- AssertSameContainer(a.ctrl_, b.ctrl_, a.slot_, b.slot_);
1452
1618
  AssertIsValidForComparison(a.ctrl_, a.generation(), a.generation_ptr());
1453
1619
  AssertIsValidForComparison(b.ctrl_, b.generation(), b.generation_ptr());
1620
+ AssertSameContainer(a.ctrl_, b.ctrl_, a.slot_, b.slot_,
1621
+ a.generation_ptr(), b.generation_ptr());
1454
1622
  return a.ctrl_ == b.ctrl_;
1455
1623
  }
1456
1624
  friend bool operator!=(const iterator& a, const iterator& b) {
@@ -1469,7 +1637,7 @@ class raw_hash_set {
1469
1637
  }
1470
1638
  // For end() iterators.
1471
1639
  explicit iterator(const GenerationType* generation_ptr)
1472
- : HashSetIteratorGenerationInfo(generation_ptr) {}
1640
+ : HashSetIteratorGenerationInfo(generation_ptr), ctrl_(nullptr) {}
1473
1641
 
1474
1642
  // Fixes up `ctrl_` to point to a full by advancing it and `slot_` until
1475
1643
  // they reach one.
@@ -1484,7 +1652,9 @@ class raw_hash_set {
1484
1652
  if (ABSL_PREDICT_FALSE(*ctrl_ == ctrl_t::kSentinel)) ctrl_ = nullptr;
1485
1653
  }
1486
1654
 
1487
- ctrl_t* ctrl_ = nullptr;
1655
+ // We use EmptyGroup() for default-constructed iterators so that they can
1656
+ // be distinguished from end iterators, which have nullptr ctrl_.
1657
+ ctrl_t* ctrl_ = EmptyGroup();
1488
1658
  // To avoid uninitialized member warnings, put slot_ in an anonymous union.
1489
1659
  // The member is not initialized on singleton and end iterators.
1490
1660
  union {
@@ -1537,9 +1707,9 @@ class raw_hash_set {
1537
1707
  // Note: can't use `= default` due to non-default noexcept (causes
1538
1708
  // problems for some compilers). NOLINTNEXTLINE
1539
1709
  raw_hash_set() noexcept(
1540
- std::is_nothrow_default_constructible<hasher>::value&&
1541
- std::is_nothrow_default_constructible<key_equal>::value&&
1542
- std::is_nothrow_default_constructible<allocator_type>::value) {}
1710
+ std::is_nothrow_default_constructible<hasher>::value &&
1711
+ std::is_nothrow_default_constructible<key_equal>::value &&
1712
+ std::is_nothrow_default_constructible<allocator_type>::value) {}
1543
1713
 
1544
1714
  ABSL_ATTRIBUTE_NOINLINE explicit raw_hash_set(
1545
1715
  size_t bucket_count, const hasher& hash = hasher(),
@@ -1547,7 +1717,7 @@ class raw_hash_set {
1547
1717
  const allocator_type& alloc = allocator_type())
1548
1718
  : settings_(CommonFields{}, hash, eq, alloc) {
1549
1719
  if (bucket_count) {
1550
- common().capacity_ = NormalizeCapacity(bucket_count);
1720
+ common().set_capacity(NormalizeCapacity(bucket_count));
1551
1721
  initialize_slots();
1552
1722
  }
1553
1723
  }
@@ -1649,7 +1819,9 @@ class raw_hash_set {
1649
1819
 
1650
1820
  raw_hash_set(const raw_hash_set& that, const allocator_type& a)
1651
1821
  : raw_hash_set(0, that.hash_ref(), that.eq_ref(), a) {
1652
- reserve(that.size());
1822
+ const size_t size = that.size();
1823
+ if (size == 0) return;
1824
+ reserve(size);
1653
1825
  // Because the table is guaranteed to be empty, we can do something faster
1654
1826
  // than a full `insert`.
1655
1827
  for (const auto& v : that) {
@@ -1660,14 +1832,14 @@ class raw_hash_set {
1660
1832
  common().maybe_increment_generation_on_insert();
1661
1833
  infoz().RecordInsert(hash, target.probe_length);
1662
1834
  }
1663
- common().size_ = that.size();
1664
- growth_left() -= that.size();
1835
+ common().set_size(size);
1836
+ set_growth_left(growth_left() - size);
1665
1837
  }
1666
1838
 
1667
1839
  ABSL_ATTRIBUTE_NOINLINE raw_hash_set(raw_hash_set&& that) noexcept(
1668
- std::is_nothrow_copy_constructible<hasher>::value&&
1669
- std::is_nothrow_copy_constructible<key_equal>::value&&
1670
- std::is_nothrow_copy_constructible<allocator_type>::value)
1840
+ std::is_nothrow_copy_constructible<hasher>::value &&
1841
+ std::is_nothrow_copy_constructible<key_equal>::value &&
1842
+ std::is_nothrow_copy_constructible<allocator_type>::value)
1671
1843
  : // Hash, equality and allocator are copied instead of moved because
1672
1844
  // `that` must be left valid. If Hash is std::function<Key>, moving it
1673
1845
  // would create a nullptr functor that cannot be called.
@@ -1696,9 +1868,9 @@ class raw_hash_set {
1696
1868
  }
1697
1869
 
1698
1870
  raw_hash_set& operator=(raw_hash_set&& that) noexcept(
1699
- absl::allocator_traits<allocator_type>::is_always_equal::value&&
1700
- std::is_nothrow_move_assignable<hasher>::value&&
1701
- std::is_nothrow_move_assignable<key_equal>::value) {
1871
+ absl::allocator_traits<allocator_type>::is_always_equal::value &&
1872
+ std::is_nothrow_move_assignable<hasher>::value &&
1873
+ std::is_nothrow_move_assignable<key_equal>::value) {
1702
1874
  // TODO(sbenza): We should only use the operations from the noexcept clause
1703
1875
  // to make sure we actually adhere to that contract.
1704
1876
  // NOLINTNEXTLINE: not returning *this for performance.
@@ -1714,30 +1886,36 @@ class raw_hash_set {
1714
1886
 
1715
1887
  // Unpoison before returning the memory to the allocator.
1716
1888
  SanitizerUnpoisonMemoryRegion(slot_array(), sizeof(slot_type) * cap);
1717
- Deallocate<alignof(slot_type)>(
1718
- &alloc_ref(), control(),
1889
+ Deallocate<BackingArrayAlignment(alignof(slot_type))>(
1890
+ &alloc_ref(), common().backing_array_start(),
1719
1891
  AllocSize(cap, sizeof(slot_type), alignof(slot_type)));
1720
1892
 
1721
1893
  infoz().Unregister();
1722
1894
  }
1723
1895
 
1724
- iterator begin() {
1896
+ iterator begin() ABSL_ATTRIBUTE_LIFETIME_BOUND {
1725
1897
  auto it = iterator_at(0);
1726
1898
  it.skip_empty_or_deleted();
1727
1899
  return it;
1728
1900
  }
1729
- iterator end() { return iterator(common().generation_ptr()); }
1901
+ iterator end() ABSL_ATTRIBUTE_LIFETIME_BOUND {
1902
+ return iterator(common().generation_ptr());
1903
+ }
1730
1904
 
1731
- const_iterator begin() const {
1905
+ const_iterator begin() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
1732
1906
  return const_cast<raw_hash_set*>(this)->begin();
1733
1907
  }
1734
- const_iterator end() const { return iterator(common().generation_ptr()); }
1735
- const_iterator cbegin() const { return begin(); }
1736
- const_iterator cend() const { return end(); }
1908
+ const_iterator end() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
1909
+ return iterator(common().generation_ptr());
1910
+ }
1911
+ const_iterator cbegin() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
1912
+ return begin();
1913
+ }
1914
+ const_iterator cend() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return end(); }
1737
1915
 
1738
1916
  bool empty() const { return !size(); }
1739
- size_t size() const { return common().size_; }
1740
- size_t capacity() const { return common().capacity_; }
1917
+ size_t size() const { return common().size(); }
1918
+ size_t capacity() const { return common().capacity(); }
1741
1919
  size_t max_size() const { return (std::numeric_limits<size_t>::max)(); }
1742
1920
 
1743
1921
  ABSL_ATTRIBUTE_REINITIALIZES void clear() {
@@ -1753,10 +1931,10 @@ class raw_hash_set {
1753
1931
  // Already guaranteed to be empty; so nothing to do.
1754
1932
  } else {
1755
1933
  destroy_slots();
1756
- ClearBackingArray(common(), GetPolicyFunctions(),
1757
- /*reuse=*/cap < 128);
1934
+ ClearBackingArray(common(), GetPolicyFunctions(), /*reuse=*/cap < 128);
1758
1935
  }
1759
1936
  common().set_reserved_growth(0);
1937
+ common().set_reservation_size(0);
1760
1938
  }
1761
1939
 
1762
1940
  inline void destroy_slots() {
@@ -1780,7 +1958,7 @@ class raw_hash_set {
1780
1958
  template <class T, RequiresInsertable<T> = 0, class T2 = T,
1781
1959
  typename std::enable_if<IsDecomposable<T2>::value, int>::type = 0,
1782
1960
  T* = nullptr>
1783
- std::pair<iterator, bool> insert(T&& value) {
1961
+ std::pair<iterator, bool> insert(T&& value) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1784
1962
  return emplace(std::forward<T>(value));
1785
1963
  }
1786
1964
 
@@ -1795,13 +1973,11 @@ class raw_hash_set {
1795
1973
  // const char* p = "hello";
1796
1974
  // s.insert(p);
1797
1975
  //
1798
- // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace
1799
- // RequiresInsertable<T> with RequiresInsertable<const T&>.
1800
- // We are hitting this bug: https://godbolt.org/g/1Vht4f.
1801
1976
  template <
1802
- class T, RequiresInsertable<T> = 0,
1977
+ class T, RequiresInsertable<const T&> = 0,
1803
1978
  typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>
1804
- std::pair<iterator, bool> insert(const T& value) {
1979
+ std::pair<iterator, bool> insert(const T& value)
1980
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
1805
1981
  return emplace(value);
1806
1982
  }
1807
1983
 
@@ -1810,7 +1986,8 @@ class raw_hash_set {
1810
1986
  //
1811
1987
  // flat_hash_map<std::string, int> s;
1812
1988
  // s.insert({"abc", 42});
1813
- std::pair<iterator, bool> insert(init_type&& value) {
1989
+ std::pair<iterator, bool> insert(init_type&& value)
1990
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
1814
1991
  return emplace(std::move(value));
1815
1992
  }
1816
1993
 
@@ -1819,21 +1996,20 @@ class raw_hash_set {
1819
1996
  template <class T, RequiresInsertable<T> = 0, class T2 = T,
1820
1997
  typename std::enable_if<IsDecomposable<T2>::value, int>::type = 0,
1821
1998
  T* = nullptr>
1822
- iterator insert(const_iterator, T&& value) {
1999
+ iterator insert(const_iterator, T&& value) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1823
2000
  return insert(std::forward<T>(value)).first;
1824
2001
  }
1825
2002
 
1826
- // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace
1827
- // RequiresInsertable<T> with RequiresInsertable<const T&>.
1828
- // We are hitting this bug: https://godbolt.org/g/1Vht4f.
1829
2003
  template <
1830
- class T, RequiresInsertable<T> = 0,
2004
+ class T, RequiresInsertable<const T&> = 0,
1831
2005
  typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>
1832
- iterator insert(const_iterator, const T& value) {
2006
+ iterator insert(const_iterator,
2007
+ const T& value) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1833
2008
  return insert(value).first;
1834
2009
  }
1835
2010
 
1836
- iterator insert(const_iterator, init_type&& value) {
2011
+ iterator insert(const_iterator,
2012
+ init_type&& value) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1837
2013
  return insert(std::move(value)).first;
1838
2014
  }
1839
2015
 
@@ -1851,7 +2027,7 @@ class raw_hash_set {
1851
2027
  insert(ilist.begin(), ilist.end());
1852
2028
  }
1853
2029
 
1854
- insert_return_type insert(node_type&& node) {
2030
+ insert_return_type insert(node_type&& node) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1855
2031
  if (!node) return {end(), false, node_type()};
1856
2032
  const auto& elem = PolicyTraits::element(CommonAccess::GetSlot(node));
1857
2033
  auto res = PolicyTraits::apply(
@@ -1865,7 +2041,8 @@ class raw_hash_set {
1865
2041
  }
1866
2042
  }
1867
2043
 
1868
- iterator insert(const_iterator, node_type&& node) {
2044
+ iterator insert(const_iterator,
2045
+ node_type&& node) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1869
2046
  auto res = insert(std::move(node));
1870
2047
  node = std::move(res.node);
1871
2048
  return res.position;
@@ -1882,7 +2059,8 @@ class raw_hash_set {
1882
2059
  // m.emplace("abc", "xyz");
1883
2060
  template <class... Args, typename std::enable_if<
1884
2061
  IsDecomposable<Args...>::value, int>::type = 0>
1885
- std::pair<iterator, bool> emplace(Args&&... args) {
2062
+ std::pair<iterator, bool> emplace(Args&&... args)
2063
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
1886
2064
  return PolicyTraits::apply(EmplaceDecomposable{*this},
1887
2065
  std::forward<Args>(args)...);
1888
2066
  }
@@ -1892,7 +2070,8 @@ class raw_hash_set {
1892
2070
  // destroys.
1893
2071
  template <class... Args, typename std::enable_if<
1894
2072
  !IsDecomposable<Args...>::value, int>::type = 0>
1895
- std::pair<iterator, bool> emplace(Args&&... args) {
2073
+ std::pair<iterator, bool> emplace(Args&&... args)
2074
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
1896
2075
  alignas(slot_type) unsigned char raw[sizeof(slot_type)];
1897
2076
  slot_type* slot = reinterpret_cast<slot_type*>(&raw);
1898
2077
 
@@ -1902,14 +2081,16 @@ class raw_hash_set {
1902
2081
  }
1903
2082
 
1904
2083
  template <class... Args>
1905
- iterator emplace_hint(const_iterator, Args&&... args) {
2084
+ iterator emplace_hint(const_iterator,
2085
+ Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1906
2086
  return emplace(std::forward<Args>(args)...).first;
1907
2087
  }
1908
2088
 
1909
2089
  // Extension API: support for lazy emplace.
1910
2090
  //
1911
2091
  // Looks up key in the table. If found, returns the iterator to the element.
1912
- // Otherwise calls `f` with one argument of type `raw_hash_set::constructor`.
2092
+ // Otherwise calls `f` with one argument of type `raw_hash_set::constructor`,
2093
+ // and returns an iterator to the new element.
1913
2094
  //
1914
2095
  // `f` must abide by several restrictions:
1915
2096
  // - it MUST call `raw_hash_set::constructor` with arguments as if a
@@ -1952,7 +2133,8 @@ class raw_hash_set {
1952
2133
  };
1953
2134
 
1954
2135
  template <class K = key_type, class F>
1955
- iterator lazy_emplace(const key_arg<K>& key, F&& f) {
2136
+ iterator lazy_emplace(const key_arg<K>& key,
2137
+ F&& f) ABSL_ATTRIBUTE_LIFETIME_BOUND {
1956
2138
  auto res = find_or_prepare_insert(key);
1957
2139
  if (res.second) {
1958
2140
  slot_type* slot = slot_array() + res.first;
@@ -1997,13 +2179,25 @@ class raw_hash_set {
1997
2179
  // This overload is necessary because otherwise erase<K>(const K&) would be
1998
2180
  // a better match if non-const iterator is passed as an argument.
1999
2181
  void erase(iterator it) {
2000
- ABSL_INTERNAL_ASSERT_IS_FULL(it.ctrl_, it.generation(), it.generation_ptr(),
2001
- "erase()");
2182
+ AssertIsFull(it.ctrl_, it.generation(), it.generation_ptr(), "erase()");
2002
2183
  PolicyTraits::destroy(&alloc_ref(), it.slot_);
2003
2184
  erase_meta_only(it);
2004
2185
  }
2005
2186
 
2006
- iterator erase(const_iterator first, const_iterator last) {
2187
+ iterator erase(const_iterator first,
2188
+ const_iterator last) ABSL_ATTRIBUTE_LIFETIME_BOUND {
2189
+ // We check for empty first because ClearBackingArray requires that
2190
+ // capacity() > 0 as a precondition.
2191
+ if (empty()) return end();
2192
+ if (first == begin() && last == end()) {
2193
+ // TODO(ezb): we access control bytes in destroy_slots so it could make
2194
+ // sense to combine destroy_slots and ClearBackingArray to avoid cache
2195
+ // misses when the table is large. Note that we also do this in clear().
2196
+ destroy_slots();
2197
+ ClearBackingArray(common(), GetPolicyFunctions(), /*reuse=*/true);
2198
+ common().set_reserved_growth(common().reservation_size());
2199
+ return end();
2200
+ }
2007
2201
  while (first != last) {
2008
2202
  erase(first++);
2009
2203
  }
@@ -2032,9 +2226,8 @@ class raw_hash_set {
2032
2226
  }
2033
2227
 
2034
2228
  node_type extract(const_iterator position) {
2035
- ABSL_INTERNAL_ASSERT_IS_FULL(position.inner_.ctrl_,
2036
- position.inner_.generation(),
2037
- position.inner_.generation_ptr(), "extract()");
2229
+ AssertIsFull(position.inner_.ctrl_, position.inner_.generation(),
2230
+ position.inner_.generation_ptr(), "extract()");
2038
2231
  auto node =
2039
2232
  CommonAccess::Transfer<node_type>(alloc_ref(), position.inner_.slot_);
2040
2233
  erase_meta_only(position);
@@ -2064,8 +2257,7 @@ class raw_hash_set {
2064
2257
  void rehash(size_t n) {
2065
2258
  if (n == 0 && capacity() == 0) return;
2066
2259
  if (n == 0 && size() == 0) {
2067
- ClearBackingArray(common(), GetPolicyFunctions(),
2068
- /*reuse=*/false);
2260
+ ClearBackingArray(common(), GetPolicyFunctions(), /*reuse=*/false);
2069
2261
  return;
2070
2262
  }
2071
2263
 
@@ -2092,6 +2284,7 @@ class raw_hash_set {
2092
2284
  infoz().RecordReservation(n);
2093
2285
  }
2094
2286
  common().reset_reserved_growth(n);
2287
+ common().set_reservation_size(n);
2095
2288
  }
2096
2289
 
2097
2290
  // Extension API: support for heterogeneous keys.
@@ -2117,12 +2310,12 @@ class raw_hash_set {
2117
2310
  void prefetch(const key_arg<K>& key) const {
2118
2311
  (void)key;
2119
2312
  // Avoid probing if we won't be able to prefetch the addresses received.
2120
- #ifdef ABSL_INTERNAL_HAVE_PREFETCH
2313
+ #ifdef ABSL_HAVE_PREFETCH
2121
2314
  prefetch_heap_block();
2122
2315
  auto seq = probe(common(), hash_ref()(key));
2123
- base_internal::PrefetchT0(control() + seq.offset());
2124
- base_internal::PrefetchT0(slot_array() + seq.offset());
2125
- #endif // ABSL_INTERNAL_HAVE_PREFETCH
2316
+ PrefetchToLocalCache(control() + seq.offset());
2317
+ PrefetchToLocalCache(slot_array() + seq.offset());
2318
+ #endif // ABSL_HAVE_PREFETCH
2126
2319
  }
2127
2320
 
2128
2321
  // The API of find() has two extensions.
@@ -2133,7 +2326,8 @@ class raw_hash_set {
2133
2326
  // 2. The type of the key argument doesn't have to be key_type. This is so
2134
2327
  // called heterogeneous key support.
2135
2328
  template <class K = key_type>
2136
- iterator find(const key_arg<K>& key, size_t hash) {
2329
+ iterator find(const key_arg<K>& key,
2330
+ size_t hash) ABSL_ATTRIBUTE_LIFETIME_BOUND {
2137
2331
  auto seq = probe(common(), hash);
2138
2332
  slot_type* slot_ptr = slot_array();
2139
2333
  const ctrl_t* ctrl = control();
@@ -2151,17 +2345,19 @@ class raw_hash_set {
2151
2345
  }
2152
2346
  }
2153
2347
  template <class K = key_type>
2154
- iterator find(const key_arg<K>& key) {
2348
+ iterator find(const key_arg<K>& key) ABSL_ATTRIBUTE_LIFETIME_BOUND {
2155
2349
  prefetch_heap_block();
2156
2350
  return find(key, hash_ref()(key));
2157
2351
  }
2158
2352
 
2159
2353
  template <class K = key_type>
2160
- const_iterator find(const key_arg<K>& key, size_t hash) const {
2354
+ const_iterator find(const key_arg<K>& key,
2355
+ size_t hash) const ABSL_ATTRIBUTE_LIFETIME_BOUND {
2161
2356
  return const_cast<raw_hash_set*>(this)->find(key, hash);
2162
2357
  }
2163
2358
  template <class K = key_type>
2164
- const_iterator find(const key_arg<K>& key) const {
2359
+ const_iterator find(const key_arg<K>& key) const
2360
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
2165
2361
  prefetch_heap_block();
2166
2362
  return find(key, hash_ref()(key));
2167
2363
  }
@@ -2172,14 +2368,15 @@ class raw_hash_set {
2172
2368
  }
2173
2369
 
2174
2370
  template <class K = key_type>
2175
- std::pair<iterator, iterator> equal_range(const key_arg<K>& key) {
2371
+ std::pair<iterator, iterator> equal_range(const key_arg<K>& key)
2372
+ ABSL_ATTRIBUTE_LIFETIME_BOUND {
2176
2373
  auto it = find(key);
2177
2374
  if (it != end()) return {it, std::next(it)};
2178
2375
  return {it, it};
2179
2376
  }
2180
2377
  template <class K = key_type>
2181
2378
  std::pair<const_iterator, const_iterator> equal_range(
2182
- const key_arg<K>& key) const {
2379
+ const key_arg<K>& key) const ABSL_ATTRIBUTE_LIFETIME_BOUND {
2183
2380
  auto it = find(key);
2184
2381
  if (it != end()) return {it, std::next(it)};
2185
2382
  return {it, it};
@@ -2313,8 +2510,8 @@ class raw_hash_set {
2313
2510
  assert(IsValidCapacity(new_capacity));
2314
2511
  auto* old_ctrl = control();
2315
2512
  auto* old_slots = slot_array();
2316
- const size_t old_capacity = common().capacity_;
2317
- common().capacity_ = new_capacity;
2513
+ const size_t old_capacity = common().capacity();
2514
+ common().set_capacity(new_capacity);
2318
2515
  initialize_slots();
2319
2516
 
2320
2517
  auto* new_slots = slot_array();
@@ -2333,8 +2530,8 @@ class raw_hash_set {
2333
2530
  if (old_capacity) {
2334
2531
  SanitizerUnpoisonMemoryRegion(old_slots,
2335
2532
  sizeof(slot_type) * old_capacity);
2336
- Deallocate<alignof(slot_type)>(
2337
- &alloc_ref(), old_ctrl,
2533
+ Deallocate<BackingArrayAlignment(alignof(slot_type))>(
2534
+ &alloc_ref(), old_ctrl - ControlOffset(),
2338
2535
  AllocSize(old_capacity, sizeof(slot_type), alignof(slot_type)));
2339
2536
  }
2340
2537
  infoz().RecordRehash(total_probe_length);
@@ -2357,8 +2554,8 @@ class raw_hash_set {
2357
2554
  void rehash_and_grow_if_necessary() {
2358
2555
  const size_t cap = capacity();
2359
2556
  if (cap > Group::kWidth &&
2360
- // Do these calcuations in 64-bit to avoid overflow.
2361
- size() * uint64_t{32} <= cap* uint64_t{25}) {
2557
+ // Do these calculations in 64-bit to avoid overflow.
2558
+ size() * uint64_t{32} <= cap * uint64_t{25}) {
2362
2559
  // Squash DELETED without growing if there is enough capacity.
2363
2560
  //
2364
2561
  // Rehash in place if the current size is <= 25/32 of capacity.
@@ -2481,8 +2678,8 @@ class raw_hash_set {
2481
2678
  rehash_and_grow_if_necessary();
2482
2679
  target = find_first_non_full(common(), hash);
2483
2680
  }
2484
- ++common().size_;
2485
- growth_left() -= IsEmpty(control()[target.offset]);
2681
+ common().set_size(common().size() + 1);
2682
+ set_growth_left(growth_left() - IsEmpty(control()[target.offset]));
2486
2683
  SetCtrl(common(), target.offset, H2(hash), sizeof(slot_type));
2487
2684
  common().maybe_increment_generation_on_insert();
2488
2685
  infoz().RecordInsert(hash, target.probe_length);
@@ -2507,10 +2704,10 @@ class raw_hash_set {
2507
2704
  "constructed value does not match the lookup key");
2508
2705
  }
2509
2706
 
2510
- iterator iterator_at(size_t i) {
2707
+ iterator iterator_at(size_t i) ABSL_ATTRIBUTE_LIFETIME_BOUND {
2511
2708
  return {control() + i, slot_array() + i, common().generation_ptr()};
2512
2709
  }
2513
- const_iterator iterator_at(size_t i) const {
2710
+ const_iterator iterator_at(size_t i) const ABSL_ATTRIBUTE_LIFETIME_BOUND {
2514
2711
  return {control() + i, slot_array() + i, common().generation_ptr()};
2515
2712
  }
2516
2713
 
@@ -2527,19 +2724,24 @@ class raw_hash_set {
2527
2724
  // side-effect.
2528
2725
  //
2529
2726
  // See `CapacityToGrowth()`.
2530
- size_t& growth_left() { return common().growth_left(); }
2531
-
2532
- // Prefetch the heap-allocated memory region to resolve potential TLB misses.
2533
- // This is intended to overlap with execution of calculating the hash for a
2534
- // key.
2535
- void prefetch_heap_block() const { base_internal::PrefetchT2(control()); }
2727
+ size_t growth_left() const { return common().growth_left(); }
2728
+ void set_growth_left(size_t gl) { return common().set_growth_left(gl); }
2729
+
2730
+ // Prefetch the heap-allocated memory region to resolve potential TLB and
2731
+ // cache misses. This is intended to overlap with execution of calculating the
2732
+ // hash for a key.
2733
+ void prefetch_heap_block() const {
2734
+ #if ABSL_HAVE_BUILTIN(__builtin_prefetch) || defined(__GNUC__)
2735
+ __builtin_prefetch(control(), 0, 1);
2736
+ #endif
2737
+ }
2536
2738
 
2537
2739
  CommonFields& common() { return settings_.template get<0>(); }
2538
2740
  const CommonFields& common() const { return settings_.template get<0>(); }
2539
2741
 
2540
- ctrl_t* control() const { return common().control_; }
2742
+ ctrl_t* control() const { return common().control(); }
2541
2743
  slot_type* slot_array() const {
2542
- return static_cast<slot_type*>(common().slots_);
2744
+ return static_cast<slot_type*>(common().slot_array());
2543
2745
  }
2544
2746
  HashtablezInfoHandle& infoz() { return common().infoz(); }
2545
2747
 
@@ -2565,16 +2767,16 @@ class raw_hash_set {
2565
2767
  static_cast<slot_type*>(src));
2566
2768
  }
2567
2769
  // Note: dealloc_fn will only be used if we have a non-standard allocator.
2568
- static void dealloc_fn(void* set, const PolicyFunctions&, ctrl_t* ctrl,
2569
- void* slot_mem, size_t n) {
2570
- auto* h = static_cast<raw_hash_set*>(set);
2770
+ static void dealloc_fn(CommonFields& common, const PolicyFunctions&) {
2771
+ auto* set = reinterpret_cast<raw_hash_set*>(&common);
2571
2772
 
2572
2773
  // Unpoison before returning the memory to the allocator.
2573
- SanitizerUnpoisonMemoryRegion(slot_mem, sizeof(slot_type) * n);
2774
+ SanitizerUnpoisonMemoryRegion(common.slot_array(),
2775
+ sizeof(slot_type) * common.capacity());
2574
2776
 
2575
- Deallocate<alignof(slot_type)>(
2576
- &h->alloc_ref(), ctrl,
2577
- AllocSize(n, sizeof(slot_type), alignof(slot_type)));
2777
+ Deallocate<BackingArrayAlignment(alignof(slot_type))>(
2778
+ &set->alloc_ref(), common.backing_array_start(),
2779
+ common.alloc_size(sizeof(slot_type), alignof(slot_type)));
2578
2780
  }
2579
2781
 
2580
2782
  static const PolicyFunctions& GetPolicyFunctions() {
@@ -2680,6 +2882,5 @@ ABSL_NAMESPACE_END
2680
2882
  } // namespace absl
2681
2883
 
2682
2884
  #undef ABSL_SWISSTABLE_ENABLE_GENERATIONS
2683
- #undef ABSL_INTERNAL_ASSERT_IS_FULL
2684
2885
 
2685
2886
  #endif // ABSL_CONTAINER_INTERNAL_RAW_HASH_SET_H_