grpc 1.31.0.pre1 → 1.33.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (614) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +693 -16022
  3. data/include/grpc/grpc.h +0 -5
  4. data/include/grpc/grpc_security.h +47 -14
  5. data/include/grpc/impl/codegen/README.md +22 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +0 -5
  7. data/include/grpc/impl/codegen/port_platform.h +6 -1
  8. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +264 -186
  10. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  12. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  13. data/src/core/ext/filters/client_channel/config_selector.h +34 -5
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -1
  15. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -3
  16. data/src/core/ext/filters/client_channel/lb_policy.h +3 -1
  17. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  18. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  19. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +9 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +126 -119
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  24. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +21 -15
  25. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +32 -13
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -7
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -32
  28. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +26 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +207 -129
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +453 -255
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +571 -0
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +727 -0
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +3 -3
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  39. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  40. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +602 -58
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -39
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +4 -3
  44. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +49 -47
  45. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +5 -9
  46. data/src/core/ext/filters/client_channel/server_address.cc +120 -7
  47. data/src/core/ext/filters/client_channel/server_address.h +48 -21
  48. data/src/core/ext/filters/client_channel/service_config.cc +16 -13
  49. data/src/core/ext/filters/client_channel/service_config.h +7 -4
  50. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  51. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  52. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  53. data/src/core/ext/filters/client_channel/subchannel.cc +64 -23
  54. data/src/core/ext/filters/client_channel/subchannel.h +16 -4
  55. data/src/core/ext/filters/client_channel/subchannel_interface.h +44 -0
  56. data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
  57. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -1
  58. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  59. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  60. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
  61. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
  62. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +19 -25
  63. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  64. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  65. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +6 -6
  66. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +256 -287
  68. data/src/core/ext/transport/chttp2/transport/flow_control.cc +11 -3
  69. data/src/core/ext/transport/chttp2/transport/flow_control.h +10 -0
  70. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  71. data/src/core/ext/transport/chttp2/transport/internal.h +10 -1
  72. data/src/core/ext/transport/chttp2/transport/parsing.cc +17 -30
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -5
  74. data/src/core/ext/transport/inproc/inproc_transport.cc +12 -12
  75. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +244 -0
  76. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +766 -0
  77. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  78. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
  79. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +458 -0
  80. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1635 -0
  81. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
  82. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
  83. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
  84. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
  85. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +124 -0
  86. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +379 -0
  87. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
  88. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
  89. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +310 -0
  90. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
  91. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +103 -0
  92. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +351 -0
  93. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  94. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
  95. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  96. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +133 -0
  97. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +241 -0
  98. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +752 -0
  99. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  100. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
  101. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
  102. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
  103. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +176 -0
  104. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +645 -0
  105. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  106. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
  107. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
  108. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
  109. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  110. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +85 -0
  111. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  112. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
  113. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  114. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
  115. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  116. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
  117. data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
  118. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
  119. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +128 -0
  120. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +467 -0
  121. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +155 -0
  122. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +539 -0
  123. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  124. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
  125. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +178 -0
  126. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +616 -0
  127. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  128. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
  129. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +900 -0
  130. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +3290 -0
  131. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +60 -0
  132. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +139 -0
  133. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  134. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
  135. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +364 -0
  136. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1336 -0
  137. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  138. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
  139. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +110 -0
  140. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +387 -0
  141. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +76 -0
  142. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +214 -0
  143. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +147 -0
  144. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +570 -0
  145. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
  146. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
  147. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
  148. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
  149. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +139 -0
  150. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +449 -0
  151. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
  152. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
  153. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
  154. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
  155. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  156. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
  157. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
  158. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
  159. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
  160. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
  161. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  162. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
  163. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  164. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
  165. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  166. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  168. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
  169. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +54 -0
  170. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +133 -0
  171. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  172. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
  173. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  174. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
  175. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  176. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
  177. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  178. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -8
  179. data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
  180. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
  181. data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
  182. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
  183. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
  184. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
  185. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  186. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +753 -0
  187. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  188. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
  189. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +36 -36
  190. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +1 -1
  191. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  192. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +57 -0
  193. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  194. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
  195. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  196. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +53 -0
  197. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  198. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +129 -0
  199. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  200. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +77 -0
  201. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  202. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +85 -0
  203. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  204. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +160 -0
  205. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  206. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +84 -0
  207. data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
  208. data/src/core/ext/upb-generated/validate/validate.upb.h +1 -1
  209. data/src/core/ext/xds/certificate_provider_factory.h +59 -0
  210. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  211. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  212. data/src/core/ext/xds/certificate_provider_store.h +50 -0
  213. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +377 -0
  214. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +102 -0
  215. data/src/core/ext/xds/xds_api.cc +2596 -0
  216. data/src/core/ext/xds/xds_api.h +397 -0
  217. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +44 -2
  218. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
  219. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +9 -6
  220. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +541 -785
  221. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +114 -93
  222. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +20 -14
  223. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +36 -8
  224. data/src/core/lib/channel/channel_args.h +0 -1
  225. data/src/core/lib/channel/channelz.cc +24 -60
  226. data/src/core/lib/channel/channelz.h +12 -20
  227. data/src/core/lib/channel/channelz_registry.cc +15 -12
  228. data/src/core/lib/channel/channelz_registry.h +3 -0
  229. data/src/core/lib/gpr/sync_posix.cc +2 -8
  230. data/src/core/lib/gpr/time_precise.cc +2 -0
  231. data/src/core/lib/gpr/time_precise.h +6 -2
  232. data/src/core/lib/gprpp/dual_ref_counted.h +336 -0
  233. data/src/core/lib/gprpp/ref_counted.h +51 -22
  234. data/src/core/lib/gprpp/ref_counted_ptr.h +153 -0
  235. data/src/core/lib/iomgr/endpoint.cc +5 -1
  236. data/src/core/lib/iomgr/endpoint.h +7 -3
  237. data/src/core/lib/iomgr/endpoint_cfstream.cc +36 -11
  238. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  239. data/src/core/lib/iomgr/exec_ctx.h +10 -8
  240. data/src/core/lib/iomgr/iomgr.cc +0 -10
  241. data/src/core/lib/iomgr/iomgr.h +0 -10
  242. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
  243. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
  244. data/src/core/lib/iomgr/sockaddr_utils.cc +2 -1
  245. data/src/core/lib/iomgr/sockaddr_utils.h +2 -1
  246. data/src/core/lib/iomgr/tcp_custom.cc +32 -16
  247. data/src/core/lib/iomgr/tcp_posix.cc +31 -13
  248. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  249. data/src/core/lib/json/json_util.cc +58 -0
  250. data/src/core/lib/json/json_util.h +37 -0
  251. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  252. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  253. data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
  254. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  255. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  256. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
  257. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
  258. data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
  259. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  260. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
  261. data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
  262. data/src/core/lib/security/certificate_provider.h +60 -0
  263. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +56 -38
  264. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +321 -0
  265. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +214 -0
  266. data/src/core/lib/security/credentials/xds/xds_credentials.cc +45 -0
  267. data/src/core/lib/security/credentials/xds/xds_credentials.h +51 -0
  268. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -12
  269. data/src/core/lib/security/security_connector/ssl_utils.h +5 -0
  270. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  271. data/src/core/lib/surface/call.cc +12 -12
  272. data/src/core/lib/surface/call.h +2 -1
  273. data/src/core/lib/surface/channel.cc +37 -51
  274. data/src/core/lib/surface/channel.h +18 -3
  275. data/src/core/lib/surface/completion_queue.cc +10 -272
  276. data/src/core/lib/surface/completion_queue.h +0 -8
  277. data/src/core/lib/surface/init.cc +27 -12
  278. data/src/core/lib/surface/server.cc +1066 -1244
  279. data/src/core/lib/surface/server.h +363 -87
  280. data/src/core/lib/surface/version.cc +2 -2
  281. data/src/core/lib/transport/authority_override.cc +38 -0
  282. data/src/core/lib/transport/authority_override.h +32 -0
  283. data/src/core/lib/transport/bdp_estimator.h +2 -1
  284. data/src/core/lib/transport/connectivity_state.cc +18 -13
  285. data/src/core/lib/transport/connectivity_state.h +20 -8
  286. data/src/core/lib/transport/error_utils.cc +13 -0
  287. data/src/core/lib/transport/error_utils.h +6 -0
  288. data/src/core/lib/transport/metadata.cc +11 -1
  289. data/src/core/lib/transport/static_metadata.cc +295 -276
  290. data/src/core/lib/transport/static_metadata.h +80 -73
  291. data/src/core/lib/transport/transport.h +7 -0
  292. data/src/core/lib/uri/uri_parser.cc +23 -21
  293. data/src/core/lib/uri/uri_parser.h +3 -1
  294. data/src/core/plugin_registry/grpc_plugin_registry.cc +35 -20
  295. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +22 -0
  296. data/src/core/tsi/ssl_transport_security.cc +2 -2
  297. data/src/ruby/bin/math_services_pb.rb +4 -4
  298. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  299. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -4
  300. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +7 -7
  301. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  302. data/src/ruby/lib/grpc/version.rb +1 -1
  303. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +2 -2
  304. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +5 -0
  305. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +28 -12
  306. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  307. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  308. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  309. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  310. data/src/ruby/spec/pb/codegen/package_option_spec.rb +20 -0
  311. data/src/ruby/spec/user_agent_spec.rb +74 -0
  312. data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
  313. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
  314. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  315. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  316. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  317. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  318. data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
  319. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
  320. data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
  321. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
  322. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
  323. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
  324. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  325. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
  326. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
  327. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  328. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
  329. data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
  330. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  331. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
  332. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
  333. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  334. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
  335. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  336. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  337. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  338. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
  339. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
  340. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
  341. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
  342. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  343. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  344. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
  345. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  346. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
  347. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
  348. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  349. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  350. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  351. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
  352. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  353. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
  354. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  355. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  356. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  357. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  358. data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
  359. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  360. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  361. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  362. data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
  363. data/third_party/abseil-cpp/absl/status/status.cc +447 -0
  364. data/third_party/abseil-cpp/absl/status/status.h +428 -0
  365. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
  366. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  367. data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
  368. data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
  369. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
  370. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  371. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  372. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  373. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  374. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  375. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  376. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  377. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  378. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  379. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
  380. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  381. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  382. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
  383. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  384. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
  385. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
  386. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  387. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  388. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  389. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  390. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  391. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  392. data/third_party/boringssl-with-bazel/err_data.c +475 -467
  393. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  394. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  395. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  396. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  397. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  398. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  399. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  400. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  401. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  402. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  403. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -15
  404. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +543 -0
  405. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +237 -0
  406. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +44 -2
  407. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +221 -49
  408. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +64 -20
  409. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  410. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +0 -8
  411. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  412. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  413. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  414. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  415. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  416. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  417. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  418. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  419. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  420. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  421. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  422. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  423. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  424. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  425. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  426. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  427. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  428. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  429. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  430. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  431. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  432. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  433. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  434. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
  435. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  436. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +2 -2
  437. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  438. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  439. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  440. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  441. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  442. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +48 -9
  443. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
  444. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +26 -6
  445. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +199 -78
  446. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +52 -43
  447. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  448. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  449. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  450. data/third_party/boringssl-with-bazel/src/ssl/internal.h +13 -9
  451. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  452. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  453. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +10 -0
  454. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
  455. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  456. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +4 -8
  457. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +7 -2
  458. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  459. data/third_party/re2/re2/bitmap256.h +117 -0
  460. data/third_party/re2/re2/bitstate.cc +385 -0
  461. data/third_party/re2/re2/compile.cc +1279 -0
  462. data/third_party/re2/re2/dfa.cc +2130 -0
  463. data/third_party/re2/re2/filtered_re2.cc +121 -0
  464. data/third_party/re2/re2/filtered_re2.h +109 -0
  465. data/third_party/re2/re2/mimics_pcre.cc +197 -0
  466. data/third_party/re2/re2/nfa.cc +713 -0
  467. data/third_party/re2/re2/onepass.cc +623 -0
  468. data/third_party/re2/re2/parse.cc +2464 -0
  469. data/third_party/re2/re2/perl_groups.cc +119 -0
  470. data/third_party/re2/re2/pod_array.h +55 -0
  471. data/third_party/re2/re2/prefilter.cc +710 -0
  472. data/third_party/re2/re2/prefilter.h +108 -0
  473. data/third_party/re2/re2/prefilter_tree.cc +407 -0
  474. data/third_party/re2/re2/prefilter_tree.h +139 -0
  475. data/third_party/re2/re2/prog.cc +988 -0
  476. data/third_party/re2/re2/prog.h +436 -0
  477. data/third_party/re2/re2/re2.cc +1362 -0
  478. data/third_party/re2/re2/re2.h +1002 -0
  479. data/third_party/re2/re2/regexp.cc +980 -0
  480. data/third_party/re2/re2/regexp.h +659 -0
  481. data/third_party/re2/re2/set.cc +154 -0
  482. data/third_party/re2/re2/set.h +80 -0
  483. data/third_party/re2/re2/simplify.cc +657 -0
  484. data/third_party/re2/re2/sparse_array.h +392 -0
  485. data/third_party/re2/re2/sparse_set.h +264 -0
  486. data/third_party/re2/re2/stringpiece.cc +65 -0
  487. data/third_party/re2/re2/stringpiece.h +210 -0
  488. data/third_party/re2/re2/tostring.cc +351 -0
  489. data/third_party/re2/re2/unicode_casefold.cc +582 -0
  490. data/third_party/re2/re2/unicode_casefold.h +78 -0
  491. data/third_party/re2/re2/unicode_groups.cc +6269 -0
  492. data/third_party/re2/re2/unicode_groups.h +67 -0
  493. data/third_party/re2/re2/walker-inl.h +246 -0
  494. data/third_party/re2/util/benchmark.h +156 -0
  495. data/third_party/re2/util/flags.h +26 -0
  496. data/third_party/re2/util/logging.h +109 -0
  497. data/third_party/re2/util/malloc_counter.h +19 -0
  498. data/third_party/re2/util/mix.h +41 -0
  499. data/third_party/re2/util/mutex.h +148 -0
  500. data/third_party/re2/util/pcre.cc +1025 -0
  501. data/third_party/re2/util/pcre.h +681 -0
  502. data/third_party/re2/util/rune.cc +260 -0
  503. data/third_party/re2/util/strutil.cc +149 -0
  504. data/third_party/re2/util/strutil.h +21 -0
  505. data/third_party/re2/util/test.h +50 -0
  506. data/third_party/re2/util/utf.h +44 -0
  507. data/third_party/re2/util/util.h +42 -0
  508. data/third_party/upb/upb/decode.c +64 -15
  509. data/third_party/upb/upb/encode.c +2 -2
  510. data/third_party/upb/upb/msg.h +2 -2
  511. data/third_party/upb/upb/port_def.inc +1 -1
  512. data/third_party/upb/upb/table.c +0 -11
  513. data/third_party/upb/upb/table.int.h +0 -9
  514. data/third_party/upb/upb/upb.c +16 -14
  515. data/third_party/upb/upb/upb.h +26 -0
  516. data/third_party/upb/upb/upb.hpp +2 -0
  517. metadata +340 -153
  518. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -528
  519. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1142
  520. data/src/core/ext/filters/client_channel/xds/xds_api.cc +0 -2110
  521. data/src/core/ext/filters/client_channel/xds/xds_api.h +0 -345
  522. data/src/core/ext/filters/client_channel/xds/xds_channel.h +0 -46
  523. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +0 -106
  524. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  525. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  526. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  527. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  528. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  529. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  530. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  531. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  532. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  533. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  534. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  535. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  536. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  537. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  538. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  539. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  540. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  541. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  542. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  543. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  544. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  545. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  546. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  547. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  548. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  549. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  550. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  551. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  552. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  553. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  554. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  555. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  556. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  557. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  558. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  559. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  560. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  561. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  562. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  563. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  564. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  565. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  566. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  567. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  568. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  569. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  570. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  571. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  572. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  573. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  574. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  575. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  576. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  577. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  578. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  579. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  580. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  581. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  582. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  583. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  584. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  585. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  586. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  587. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  588. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  589. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  590. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  591. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  592. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  593. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  594. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  595. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  596. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  597. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  598. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  599. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  600. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  601. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  602. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  603. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  604. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  605. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  606. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  607. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  608. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -29
  609. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  610. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  611. data/src/core/lib/slice/slice_hash_table.h +0 -199
  612. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
  613. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  614. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
@@ -0,0 +1,78 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "absl/synchronization/notification.h"
16
+
17
+ #include <atomic>
18
+
19
+ #include "absl/base/attributes.h"
20
+ #include "absl/base/internal/raw_logging.h"
21
+ #include "absl/synchronization/mutex.h"
22
+ #include "absl/time/time.h"
23
+
24
+ namespace absl {
25
+ ABSL_NAMESPACE_BEGIN
26
+
27
+ void Notification::Notify() {
28
+ MutexLock l(&this->mutex_);
29
+
30
+ #ifndef NDEBUG
31
+ if (ABSL_PREDICT_FALSE(notified_yet_.load(std::memory_order_relaxed))) {
32
+ ABSL_RAW_LOG(
33
+ FATAL,
34
+ "Notify() method called more than once for Notification object %p",
35
+ static_cast<void *>(this));
36
+ }
37
+ #endif
38
+
39
+ notified_yet_.store(true, std::memory_order_release);
40
+ }
41
+
42
+ Notification::~Notification() {
43
+ // Make sure that the thread running Notify() exits before the object is
44
+ // destructed.
45
+ MutexLock l(&this->mutex_);
46
+ }
47
+
48
+ void Notification::WaitForNotification() const {
49
+ if (!HasBeenNotifiedInternal(&this->notified_yet_)) {
50
+ this->mutex_.LockWhen(Condition(&HasBeenNotifiedInternal,
51
+ &this->notified_yet_));
52
+ this->mutex_.Unlock();
53
+ }
54
+ }
55
+
56
+ bool Notification::WaitForNotificationWithTimeout(
57
+ absl::Duration timeout) const {
58
+ bool notified = HasBeenNotifiedInternal(&this->notified_yet_);
59
+ if (!notified) {
60
+ notified = this->mutex_.LockWhenWithTimeout(
61
+ Condition(&HasBeenNotifiedInternal, &this->notified_yet_), timeout);
62
+ this->mutex_.Unlock();
63
+ }
64
+ return notified;
65
+ }
66
+
67
+ bool Notification::WaitForNotificationWithDeadline(absl::Time deadline) const {
68
+ bool notified = HasBeenNotifiedInternal(&this->notified_yet_);
69
+ if (!notified) {
70
+ notified = this->mutex_.LockWhenWithDeadline(
71
+ Condition(&HasBeenNotifiedInternal, &this->notified_yet_), deadline);
72
+ this->mutex_.Unlock();
73
+ }
74
+ return notified;
75
+ }
76
+
77
+ ABSL_NAMESPACE_END
78
+ } // namespace absl
@@ -0,0 +1,123 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // notification.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file defines a `Notification` abstraction, which allows threads
20
+ // to receive notification of a single occurrence of a single event.
21
+ //
22
+ // The `Notification` object maintains a private boolean "notified" state that
23
+ // transitions to `true` at most once. The `Notification` class provides the
24
+ // following primary member functions:
25
+ // * `HasBeenNotified() `to query its state
26
+ // * `WaitForNotification*()` to have threads wait until the "notified" state
27
+ // is `true`.
28
+ // * `Notify()` to set the notification's "notified" state to `true` and
29
+ // notify all waiting threads that the event has occurred.
30
+ // This method may only be called once.
31
+ //
32
+ // Note that while `Notify()` may only be called once, it is perfectly valid to
33
+ // call any of the `WaitForNotification*()` methods multiple times, from
34
+ // multiple threads -- even after the notification's "notified" state has been
35
+ // set -- in which case those methods will immediately return.
36
+ //
37
+ // Note that the lifetime of a `Notification` requires careful consideration;
38
+ // it might not be safe to destroy a notification after calling `Notify()` since
39
+ // it is still legal for other threads to call `WaitForNotification*()` methods
40
+ // on the notification. However, observers responding to a "notified" state of
41
+ // `true` can safely delete the notification without interfering with the call
42
+ // to `Notify()` in the other thread.
43
+ //
44
+ // Memory ordering: For any threads X and Y, if X calls `Notify()`, then any
45
+ // action taken by X before it calls `Notify()` is visible to thread Y after:
46
+ // * Y returns from `WaitForNotification()`, or
47
+ // * Y receives a `true` return value from either `HasBeenNotified()` or
48
+ // `WaitForNotificationWithTimeout()`.
49
+
50
+ #ifndef ABSL_SYNCHRONIZATION_NOTIFICATION_H_
51
+ #define ABSL_SYNCHRONIZATION_NOTIFICATION_H_
52
+
53
+ #include <atomic>
54
+
55
+ #include "absl/base/macros.h"
56
+ #include "absl/synchronization/mutex.h"
57
+ #include "absl/time/time.h"
58
+
59
+ namespace absl {
60
+ ABSL_NAMESPACE_BEGIN
61
+
62
+ // -----------------------------------------------------------------------------
63
+ // Notification
64
+ // -----------------------------------------------------------------------------
65
+ class Notification {
66
+ public:
67
+ // Initializes the "notified" state to unnotified.
68
+ Notification() : notified_yet_(false) {}
69
+ explicit Notification(bool prenotify) : notified_yet_(prenotify) {}
70
+ Notification(const Notification&) = delete;
71
+ Notification& operator=(const Notification&) = delete;
72
+ ~Notification();
73
+
74
+ // Notification::HasBeenNotified()
75
+ //
76
+ // Returns the value of the notification's internal "notified" state.
77
+ bool HasBeenNotified() const {
78
+ return HasBeenNotifiedInternal(&this->notified_yet_);
79
+ }
80
+
81
+ // Notification::WaitForNotification()
82
+ //
83
+ // Blocks the calling thread until the notification's "notified" state is
84
+ // `true`. Note that if `Notify()` has been previously called on this
85
+ // notification, this function will immediately return.
86
+ void WaitForNotification() const;
87
+
88
+ // Notification::WaitForNotificationWithTimeout()
89
+ //
90
+ // Blocks until either the notification's "notified" state is `true` (which
91
+ // may occur immediately) or the timeout has elapsed, returning the value of
92
+ // its "notified" state in either case.
93
+ bool WaitForNotificationWithTimeout(absl::Duration timeout) const;
94
+
95
+ // Notification::WaitForNotificationWithDeadline()
96
+ //
97
+ // Blocks until either the notification's "notified" state is `true` (which
98
+ // may occur immediately) or the deadline has expired, returning the value of
99
+ // its "notified" state in either case.
100
+ bool WaitForNotificationWithDeadline(absl::Time deadline) const;
101
+
102
+ // Notification::Notify()
103
+ //
104
+ // Sets the "notified" state of this notification to `true` and wakes waiting
105
+ // threads. Note: do not call `Notify()` multiple times on the same
106
+ // `Notification`; calling `Notify()` more than once on the same notification
107
+ // results in undefined behavior.
108
+ void Notify();
109
+
110
+ private:
111
+ static inline bool HasBeenNotifiedInternal(
112
+ const std::atomic<bool>* notified_yet) {
113
+ return notified_yet->load(std::memory_order_acquire);
114
+ }
115
+
116
+ mutable Mutex mutex_;
117
+ std::atomic<bool> notified_yet_; // written under mutex_
118
+ };
119
+
120
+ ABSL_NAMESPACE_END
121
+ } // namespace absl
122
+
123
+ #endif // ABSL_SYNCHRONIZATION_NOTIFICATION_H_
@@ -0,0 +1,64 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "absl/types/bad_variant_access.h"
16
+
17
+ #ifndef ABSL_USES_STD_VARIANT
18
+
19
+ #include <cstdlib>
20
+ #include <stdexcept>
21
+
22
+ #include "absl/base/config.h"
23
+ #include "absl/base/internal/raw_logging.h"
24
+
25
+ namespace absl {
26
+ ABSL_NAMESPACE_BEGIN
27
+
28
+ //////////////////////////
29
+ // [variant.bad.access] //
30
+ //////////////////////////
31
+
32
+ bad_variant_access::~bad_variant_access() = default;
33
+
34
+ const char* bad_variant_access::what() const noexcept {
35
+ return "Bad variant access";
36
+ }
37
+
38
+ namespace variant_internal {
39
+
40
+ void ThrowBadVariantAccess() {
41
+ #ifdef ABSL_HAVE_EXCEPTIONS
42
+ throw bad_variant_access();
43
+ #else
44
+ ABSL_RAW_LOG(FATAL, "Bad variant access");
45
+ abort(); // TODO(calabrese) Remove once RAW_LOG FATAL is noreturn.
46
+ #endif
47
+ }
48
+
49
+ void Rethrow() {
50
+ #ifdef ABSL_HAVE_EXCEPTIONS
51
+ throw;
52
+ #else
53
+ ABSL_RAW_LOG(FATAL,
54
+ "Internal error in absl::variant implementation. Attempted to "
55
+ "rethrow an exception when building with exceptions disabled.");
56
+ abort(); // TODO(calabrese) Remove once RAW_LOG FATAL is noreturn.
57
+ #endif
58
+ }
59
+
60
+ } // namespace variant_internal
61
+ ABSL_NAMESPACE_END
62
+ } // namespace absl
63
+
64
+ #endif // ABSL_USES_STD_VARIANT
@@ -0,0 +1,82 @@
1
+ // Copyright 2018 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // bad_variant_access.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file defines the `absl::bad_variant_access` type.
20
+
21
+ #ifndef ABSL_TYPES_BAD_VARIANT_ACCESS_H_
22
+ #define ABSL_TYPES_BAD_VARIANT_ACCESS_H_
23
+
24
+ #include <stdexcept>
25
+
26
+ #include "absl/base/config.h"
27
+
28
+ #ifdef ABSL_USES_STD_VARIANT
29
+
30
+ #include <variant>
31
+
32
+ namespace absl {
33
+ ABSL_NAMESPACE_BEGIN
34
+ using std::bad_variant_access;
35
+ ABSL_NAMESPACE_END
36
+ } // namespace absl
37
+
38
+ #else // ABSL_USES_STD_VARIANT
39
+
40
+ namespace absl {
41
+ ABSL_NAMESPACE_BEGIN
42
+
43
+ // -----------------------------------------------------------------------------
44
+ // bad_variant_access
45
+ // -----------------------------------------------------------------------------
46
+ //
47
+ // An `absl::bad_variant_access` type is an exception type that is thrown in
48
+ // the following cases:
49
+ //
50
+ // * Calling `absl::get(absl::variant) with an index or type that does not
51
+ // match the currently selected alternative type
52
+ // * Calling `absl::visit on an `absl::variant` that is in the
53
+ // `variant::valueless_by_exception` state.
54
+ //
55
+ // Example:
56
+ //
57
+ // absl::variant<int, std::string> v;
58
+ // v = 1;
59
+ // try {
60
+ // absl::get<std::string>(v);
61
+ // } catch(const absl::bad_variant_access& e) {
62
+ // std::cout << "Bad variant access: " << e.what() << '\n';
63
+ // }
64
+ class bad_variant_access : public std::exception {
65
+ public:
66
+ bad_variant_access() noexcept = default;
67
+ ~bad_variant_access() override;
68
+ const char* what() const noexcept override;
69
+ };
70
+
71
+ namespace variant_internal {
72
+
73
+ [[noreturn]] void ThrowBadVariantAccess();
74
+ [[noreturn]] void Rethrow();
75
+
76
+ } // namespace variant_internal
77
+ ABSL_NAMESPACE_END
78
+ } // namespace absl
79
+
80
+ #endif // ABSL_USES_STD_VARIANT
81
+
82
+ #endif // ABSL_TYPES_BAD_VARIANT_ACCESS_H_
@@ -0,0 +1,1646 @@
1
+ // Copyright 2018 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // Implementation details of absl/types/variant.h, pulled into a
16
+ // separate file to avoid cluttering the top of the API header with
17
+ // implementation details.
18
+
19
+ #ifndef ABSL_TYPES_variant_internal_H_
20
+ #define ABSL_TYPES_variant_internal_H_
21
+
22
+ #include <cassert>
23
+ #include <cstddef>
24
+ #include <cstdlib>
25
+ #include <memory>
26
+ #include <stdexcept>
27
+ #include <tuple>
28
+ #include <type_traits>
29
+
30
+ #include "absl/base/config.h"
31
+ #include "absl/base/internal/identity.h"
32
+ #include "absl/base/internal/inline_variable.h"
33
+ #include "absl/base/internal/invoke.h"
34
+ #include "absl/base/macros.h"
35
+ #include "absl/base/optimization.h"
36
+ #include "absl/meta/type_traits.h"
37
+ #include "absl/types/bad_variant_access.h"
38
+ #include "absl/utility/utility.h"
39
+
40
+ #if !defined(ABSL_USES_STD_VARIANT)
41
+
42
+ namespace absl {
43
+ ABSL_NAMESPACE_BEGIN
44
+
45
+ template <class... Types>
46
+ class variant;
47
+
48
+ ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, -1);
49
+
50
+ template <class T>
51
+ struct variant_size;
52
+
53
+ template <std::size_t I, class T>
54
+ struct variant_alternative;
55
+
56
+ namespace variant_internal {
57
+
58
+ // NOTE: See specializations below for details.
59
+ template <std::size_t I, class T>
60
+ struct VariantAlternativeSfinae {};
61
+
62
+ // Requires: I < variant_size_v<T>.
63
+ //
64
+ // Value: The Ith type of Types...
65
+ template <std::size_t I, class T0, class... Tn>
66
+ struct VariantAlternativeSfinae<I, variant<T0, Tn...>>
67
+ : VariantAlternativeSfinae<I - 1, variant<Tn...>> {};
68
+
69
+ // Value: T0
70
+ template <class T0, class... Ts>
71
+ struct VariantAlternativeSfinae<0, variant<T0, Ts...>> {
72
+ using type = T0;
73
+ };
74
+
75
+ template <std::size_t I, class T>
76
+ using VariantAlternativeSfinaeT = typename VariantAlternativeSfinae<I, T>::type;
77
+
78
+ // NOTE: Requires T to be a reference type.
79
+ template <class T, class U>
80
+ struct GiveQualsTo;
81
+
82
+ template <class T, class U>
83
+ struct GiveQualsTo<T&, U> {
84
+ using type = U&;
85
+ };
86
+
87
+ template <class T, class U>
88
+ struct GiveQualsTo<T&&, U> {
89
+ using type = U&&;
90
+ };
91
+
92
+ template <class T, class U>
93
+ struct GiveQualsTo<const T&, U> {
94
+ using type = const U&;
95
+ };
96
+
97
+ template <class T, class U>
98
+ struct GiveQualsTo<const T&&, U> {
99
+ using type = const U&&;
100
+ };
101
+
102
+ template <class T, class U>
103
+ struct GiveQualsTo<volatile T&, U> {
104
+ using type = volatile U&;
105
+ };
106
+
107
+ template <class T, class U>
108
+ struct GiveQualsTo<volatile T&&, U> {
109
+ using type = volatile U&&;
110
+ };
111
+
112
+ template <class T, class U>
113
+ struct GiveQualsTo<volatile const T&, U> {
114
+ using type = volatile const U&;
115
+ };
116
+
117
+ template <class T, class U>
118
+ struct GiveQualsTo<volatile const T&&, U> {
119
+ using type = volatile const U&&;
120
+ };
121
+
122
+ template <class T, class U>
123
+ using GiveQualsToT = typename GiveQualsTo<T, U>::type;
124
+
125
+ // Convenience alias, since size_t integral_constant is used a lot in this file.
126
+ template <std::size_t I>
127
+ using SizeT = std::integral_constant<std::size_t, I>;
128
+
129
+ using NPos = SizeT<variant_npos>;
130
+
131
+ template <class Variant, class T, class = void>
132
+ struct IndexOfConstructedType {};
133
+
134
+ template <std::size_t I, class Variant>
135
+ struct VariantAccessResultImpl;
136
+
137
+ template <std::size_t I, template <class...> class Variantemplate, class... T>
138
+ struct VariantAccessResultImpl<I, Variantemplate<T...>&> {
139
+ using type = typename absl::variant_alternative<I, variant<T...>>::type&;
140
+ };
141
+
142
+ template <std::size_t I, template <class...> class Variantemplate, class... T>
143
+ struct VariantAccessResultImpl<I, const Variantemplate<T...>&> {
144
+ using type =
145
+ const typename absl::variant_alternative<I, variant<T...>>::type&;
146
+ };
147
+
148
+ template <std::size_t I, template <class...> class Variantemplate, class... T>
149
+ struct VariantAccessResultImpl<I, Variantemplate<T...>&&> {
150
+ using type = typename absl::variant_alternative<I, variant<T...>>::type&&;
151
+ };
152
+
153
+ template <std::size_t I, template <class...> class Variantemplate, class... T>
154
+ struct VariantAccessResultImpl<I, const Variantemplate<T...>&&> {
155
+ using type =
156
+ const typename absl::variant_alternative<I, variant<T...>>::type&&;
157
+ };
158
+
159
+ template <std::size_t I, class Variant>
160
+ using VariantAccessResult =
161
+ typename VariantAccessResultImpl<I, Variant&&>::type;
162
+
163
+ // NOTE: This is used instead of std::array to reduce instantiation overhead.
164
+ template <class T, std::size_t Size>
165
+ struct SimpleArray {
166
+ static_assert(Size != 0, "");
167
+ T value[Size];
168
+ };
169
+
170
+ template <class T>
171
+ struct AccessedType {
172
+ using type = T;
173
+ };
174
+
175
+ template <class T>
176
+ using AccessedTypeT = typename AccessedType<T>::type;
177
+
178
+ template <class T, std::size_t Size>
179
+ struct AccessedType<SimpleArray<T, Size>> {
180
+ using type = AccessedTypeT<T>;
181
+ };
182
+
183
+ template <class T>
184
+ constexpr T AccessSimpleArray(const T& value) {
185
+ return value;
186
+ }
187
+
188
+ template <class T, std::size_t Size, class... SizeT>
189
+ constexpr AccessedTypeT<T> AccessSimpleArray(const SimpleArray<T, Size>& table,
190
+ std::size_t head_index,
191
+ SizeT... tail_indices) {
192
+ return AccessSimpleArray(table.value[head_index], tail_indices...);
193
+ }
194
+
195
+ // Note: Intentionally is an alias.
196
+ template <class T>
197
+ using AlwaysZero = SizeT<0>;
198
+
199
+ template <class Op, class... Vs>
200
+ struct VisitIndicesResultImpl {
201
+ using type = absl::result_of_t<Op(AlwaysZero<Vs>...)>;
202
+ };
203
+
204
+ template <class Op, class... Vs>
205
+ using VisitIndicesResultT = typename VisitIndicesResultImpl<Op, Vs...>::type;
206
+
207
+ template <class ReturnType, class FunctionObject, class EndIndices,
208
+ class BoundIndices>
209
+ struct MakeVisitationMatrix;
210
+
211
+ template <class ReturnType, class FunctionObject, std::size_t... Indices>
212
+ constexpr ReturnType call_with_indices(FunctionObject&& function) {
213
+ static_assert(
214
+ std::is_same<ReturnType, decltype(std::declval<FunctionObject>()(
215
+ SizeT<Indices>()...))>::value,
216
+ "Not all visitation overloads have the same return type.");
217
+ return absl::forward<FunctionObject>(function)(SizeT<Indices>()...);
218
+ }
219
+
220
+ template <class ReturnType, class FunctionObject, std::size_t... BoundIndices>
221
+ struct MakeVisitationMatrix<ReturnType, FunctionObject, index_sequence<>,
222
+ index_sequence<BoundIndices...>> {
223
+ using ResultType = ReturnType (*)(FunctionObject&&);
224
+ static constexpr ResultType Run() {
225
+ return &call_with_indices<ReturnType, FunctionObject,
226
+ (BoundIndices - 1)...>;
227
+ }
228
+ };
229
+
230
+ template <typename Is, std::size_t J>
231
+ struct AppendToIndexSequence;
232
+
233
+ template <typename Is, std::size_t J>
234
+ using AppendToIndexSequenceT = typename AppendToIndexSequence<Is, J>::type;
235
+
236
+ template <std::size_t... Is, std::size_t J>
237
+ struct AppendToIndexSequence<index_sequence<Is...>, J> {
238
+ using type = index_sequence<Is..., J>;
239
+ };
240
+
241
+ template <class ReturnType, class FunctionObject, class EndIndices,
242
+ class CurrIndices, class BoundIndices>
243
+ struct MakeVisitationMatrixImpl;
244
+
245
+ template <class ReturnType, class FunctionObject, class EndIndices,
246
+ std::size_t... CurrIndices, class BoundIndices>
247
+ struct MakeVisitationMatrixImpl<ReturnType, FunctionObject, EndIndices,
248
+ index_sequence<CurrIndices...>, BoundIndices> {
249
+ using ResultType = SimpleArray<
250
+ typename MakeVisitationMatrix<ReturnType, FunctionObject, EndIndices,
251
+ index_sequence<>>::ResultType,
252
+ sizeof...(CurrIndices)>;
253
+
254
+ static constexpr ResultType Run() {
255
+ return {{MakeVisitationMatrix<
256
+ ReturnType, FunctionObject, EndIndices,
257
+ AppendToIndexSequenceT<BoundIndices, CurrIndices>>::Run()...}};
258
+ }
259
+ };
260
+
261
+ template <class ReturnType, class FunctionObject, std::size_t HeadEndIndex,
262
+ std::size_t... TailEndIndices, std::size_t... BoundIndices>
263
+ struct MakeVisitationMatrix<ReturnType, FunctionObject,
264
+ index_sequence<HeadEndIndex, TailEndIndices...>,
265
+ index_sequence<BoundIndices...>>
266
+ : MakeVisitationMatrixImpl<ReturnType, FunctionObject,
267
+ index_sequence<TailEndIndices...>,
268
+ absl::make_index_sequence<HeadEndIndex>,
269
+ index_sequence<BoundIndices...>> {};
270
+
271
+ struct UnreachableSwitchCase {
272
+ template <class Op>
273
+ [[noreturn]] static VisitIndicesResultT<Op, std::size_t> Run(
274
+ Op&& /*ignored*/) {
275
+ #if ABSL_HAVE_BUILTIN(__builtin_unreachable) || \
276
+ (defined(__GNUC__) && !defined(__clang__))
277
+ __builtin_unreachable();
278
+ #elif defined(_MSC_VER)
279
+ __assume(false);
280
+ #else
281
+ // Try to use assert of false being identified as an unreachable intrinsic.
282
+ // NOTE: We use assert directly to increase chances of exploiting an assume
283
+ // intrinsic.
284
+ assert(false); // NOLINT
285
+
286
+ // Hack to silence potential no return warning -- cause an infinite loop.
287
+ return Run(absl::forward<Op>(op));
288
+ #endif // Checks for __builtin_unreachable
289
+ }
290
+ };
291
+
292
+ template <class Op, std::size_t I>
293
+ struct ReachableSwitchCase {
294
+ static VisitIndicesResultT<Op, std::size_t> Run(Op&& op) {
295
+ return absl::base_internal::Invoke(absl::forward<Op>(op), SizeT<I>());
296
+ }
297
+ };
298
+
299
+ // The number 33 is just a guess at a reasonable maximum to our switch. It is
300
+ // not based on any analysis. The reason it is a power of 2 plus 1 instead of a
301
+ // power of 2 is because the number was picked to correspond to a power of 2
302
+ // amount of "normal" alternatives, plus one for the possibility of the user
303
+ // providing "monostate" in addition to the more natural alternatives.
304
+ ABSL_INTERNAL_INLINE_CONSTEXPR(std::size_t, MaxUnrolledVisitCases, 33);
305
+
306
+ // Note: The default-definition is for unreachable cases.
307
+ template <bool IsReachable>
308
+ struct PickCaseImpl {
309
+ template <class Op, std::size_t I>
310
+ using Apply = UnreachableSwitchCase;
311
+ };
312
+
313
+ template <>
314
+ struct PickCaseImpl</*IsReachable =*/true> {
315
+ template <class Op, std::size_t I>
316
+ using Apply = ReachableSwitchCase<Op, I>;
317
+ };
318
+
319
+ // Note: This form of dance with template aliases is to make sure that we
320
+ // instantiate a number of templates proportional to the number of variant
321
+ // alternatives rather than a number of templates proportional to our
322
+ // maximum unrolled amount of visitation cases (aliases are effectively
323
+ // "free" whereas other template instantiations are costly).
324
+ template <class Op, std::size_t I, std::size_t EndIndex>
325
+ using PickCase = typename PickCaseImpl<(I < EndIndex)>::template Apply<Op, I>;
326
+
327
+ template <class ReturnType>
328
+ [[noreturn]] ReturnType TypedThrowBadVariantAccess() {
329
+ absl::variant_internal::ThrowBadVariantAccess();
330
+ }
331
+
332
+ // Given N variant sizes, determine the number of cases there would need to be
333
+ // in a single switch-statement that would cover every possibility in the
334
+ // corresponding N-ary visit operation.
335
+ template <std::size_t... NumAlternatives>
336
+ struct NumCasesOfSwitch;
337
+
338
+ template <std::size_t HeadNumAlternatives, std::size_t... TailNumAlternatives>
339
+ struct NumCasesOfSwitch<HeadNumAlternatives, TailNumAlternatives...> {
340
+ static constexpr std::size_t value =
341
+ (HeadNumAlternatives + 1) *
342
+ NumCasesOfSwitch<TailNumAlternatives...>::value;
343
+ };
344
+
345
+ template <>
346
+ struct NumCasesOfSwitch<> {
347
+ static constexpr std::size_t value = 1;
348
+ };
349
+
350
+ // A switch statement optimizes better than the table of function pointers.
351
+ template <std::size_t EndIndex>
352
+ struct VisitIndicesSwitch {
353
+ static_assert(EndIndex <= MaxUnrolledVisitCases,
354
+ "Maximum unrolled switch size exceeded.");
355
+
356
+ template <class Op>
357
+ static VisitIndicesResultT<Op, std::size_t> Run(Op&& op, std::size_t i) {
358
+ switch (i) {
359
+ case 0:
360
+ return PickCase<Op, 0, EndIndex>::Run(absl::forward<Op>(op));
361
+ case 1:
362
+ return PickCase<Op, 1, EndIndex>::Run(absl::forward<Op>(op));
363
+ case 2:
364
+ return PickCase<Op, 2, EndIndex>::Run(absl::forward<Op>(op));
365
+ case 3:
366
+ return PickCase<Op, 3, EndIndex>::Run(absl::forward<Op>(op));
367
+ case 4:
368
+ return PickCase<Op, 4, EndIndex>::Run(absl::forward<Op>(op));
369
+ case 5:
370
+ return PickCase<Op, 5, EndIndex>::Run(absl::forward<Op>(op));
371
+ case 6:
372
+ return PickCase<Op, 6, EndIndex>::Run(absl::forward<Op>(op));
373
+ case 7:
374
+ return PickCase<Op, 7, EndIndex>::Run(absl::forward<Op>(op));
375
+ case 8:
376
+ return PickCase<Op, 8, EndIndex>::Run(absl::forward<Op>(op));
377
+ case 9:
378
+ return PickCase<Op, 9, EndIndex>::Run(absl::forward<Op>(op));
379
+ case 10:
380
+ return PickCase<Op, 10, EndIndex>::Run(absl::forward<Op>(op));
381
+ case 11:
382
+ return PickCase<Op, 11, EndIndex>::Run(absl::forward<Op>(op));
383
+ case 12:
384
+ return PickCase<Op, 12, EndIndex>::Run(absl::forward<Op>(op));
385
+ case 13:
386
+ return PickCase<Op, 13, EndIndex>::Run(absl::forward<Op>(op));
387
+ case 14:
388
+ return PickCase<Op, 14, EndIndex>::Run(absl::forward<Op>(op));
389
+ case 15:
390
+ return PickCase<Op, 15, EndIndex>::Run(absl::forward<Op>(op));
391
+ case 16:
392
+ return PickCase<Op, 16, EndIndex>::Run(absl::forward<Op>(op));
393
+ case 17:
394
+ return PickCase<Op, 17, EndIndex>::Run(absl::forward<Op>(op));
395
+ case 18:
396
+ return PickCase<Op, 18, EndIndex>::Run(absl::forward<Op>(op));
397
+ case 19:
398
+ return PickCase<Op, 19, EndIndex>::Run(absl::forward<Op>(op));
399
+ case 20:
400
+ return PickCase<Op, 20, EndIndex>::Run(absl::forward<Op>(op));
401
+ case 21:
402
+ return PickCase<Op, 21, EndIndex>::Run(absl::forward<Op>(op));
403
+ case 22:
404
+ return PickCase<Op, 22, EndIndex>::Run(absl::forward<Op>(op));
405
+ case 23:
406
+ return PickCase<Op, 23, EndIndex>::Run(absl::forward<Op>(op));
407
+ case 24:
408
+ return PickCase<Op, 24, EndIndex>::Run(absl::forward<Op>(op));
409
+ case 25:
410
+ return PickCase<Op, 25, EndIndex>::Run(absl::forward<Op>(op));
411
+ case 26:
412
+ return PickCase<Op, 26, EndIndex>::Run(absl::forward<Op>(op));
413
+ case 27:
414
+ return PickCase<Op, 27, EndIndex>::Run(absl::forward<Op>(op));
415
+ case 28:
416
+ return PickCase<Op, 28, EndIndex>::Run(absl::forward<Op>(op));
417
+ case 29:
418
+ return PickCase<Op, 29, EndIndex>::Run(absl::forward<Op>(op));
419
+ case 30:
420
+ return PickCase<Op, 30, EndIndex>::Run(absl::forward<Op>(op));
421
+ case 31:
422
+ return PickCase<Op, 31, EndIndex>::Run(absl::forward<Op>(op));
423
+ case 32:
424
+ return PickCase<Op, 32, EndIndex>::Run(absl::forward<Op>(op));
425
+ default:
426
+ ABSL_ASSERT(i == variant_npos);
427
+ return absl::base_internal::Invoke(absl::forward<Op>(op), NPos());
428
+ }
429
+ }
430
+ };
431
+
432
+ template <std::size_t... EndIndices>
433
+ struct VisitIndicesFallback {
434
+ template <class Op, class... SizeT>
435
+ static VisitIndicesResultT<Op, SizeT...> Run(Op&& op, SizeT... indices) {
436
+ return AccessSimpleArray(
437
+ MakeVisitationMatrix<VisitIndicesResultT<Op, SizeT...>, Op,
438
+ index_sequence<(EndIndices + 1)...>,
439
+ index_sequence<>>::Run(),
440
+ (indices + 1)...)(absl::forward<Op>(op));
441
+ }
442
+ };
443
+
444
+ // Take an N-dimensional series of indices and convert them into a single index
445
+ // without loss of information. The purpose of this is to be able to convert an
446
+ // N-ary visit operation into a single switch statement.
447
+ template <std::size_t...>
448
+ struct FlattenIndices;
449
+
450
+ template <std::size_t HeadSize, std::size_t... TailSize>
451
+ struct FlattenIndices<HeadSize, TailSize...> {
452
+ template<class... SizeType>
453
+ static constexpr std::size_t Run(std::size_t head, SizeType... tail) {
454
+ return head + HeadSize * FlattenIndices<TailSize...>::Run(tail...);
455
+ }
456
+ };
457
+
458
+ template <>
459
+ struct FlattenIndices<> {
460
+ static constexpr std::size_t Run() { return 0; }
461
+ };
462
+
463
+ // Take a single "flattened" index (flattened by FlattenIndices) and determine
464
+ // the value of the index of one of the logically represented dimensions.
465
+ template <std::size_t I, std::size_t IndexToGet, std::size_t HeadSize,
466
+ std::size_t... TailSize>
467
+ struct UnflattenIndex {
468
+ static constexpr std::size_t value =
469
+ UnflattenIndex<I / HeadSize, IndexToGet - 1, TailSize...>::value;
470
+ };
471
+
472
+ template <std::size_t I, std::size_t HeadSize, std::size_t... TailSize>
473
+ struct UnflattenIndex<I, 0, HeadSize, TailSize...> {
474
+ static constexpr std::size_t value = (I % HeadSize);
475
+ };
476
+
477
+ // The backend for converting an N-ary visit operation into a unary visit.
478
+ template <class IndexSequence, std::size_t... EndIndices>
479
+ struct VisitIndicesVariadicImpl;
480
+
481
+ template <std::size_t... N, std::size_t... EndIndices>
482
+ struct VisitIndicesVariadicImpl<absl::index_sequence<N...>, EndIndices...> {
483
+ // A type that can take an N-ary function object and converts it to a unary
484
+ // function object that takes a single, flattened index, and "unflattens" it
485
+ // into its individual dimensions when forwarding to the wrapped object.
486
+ template <class Op>
487
+ struct FlattenedOp {
488
+ template <std::size_t I>
489
+ VisitIndicesResultT<Op, decltype(EndIndices)...> operator()(
490
+ SizeT<I> /*index*/) && {
491
+ return base_internal::Invoke(
492
+ absl::forward<Op>(op),
493
+ SizeT<UnflattenIndex<I, N, (EndIndices + 1)...>::value -
494
+ std::size_t{1}>()...);
495
+ }
496
+
497
+ Op&& op;
498
+ };
499
+
500
+ template <class Op, class... SizeType>
501
+ static VisitIndicesResultT<Op, decltype(EndIndices)...> Run(
502
+ Op&& op, SizeType... i) {
503
+ return VisitIndicesSwitch<NumCasesOfSwitch<EndIndices...>::value>::Run(
504
+ FlattenedOp<Op>{absl::forward<Op>(op)},
505
+ FlattenIndices<(EndIndices + std::size_t{1})...>::Run(
506
+ (i + std::size_t{1})...));
507
+ }
508
+ };
509
+
510
+ template <std::size_t... EndIndices>
511
+ struct VisitIndicesVariadic
512
+ : VisitIndicesVariadicImpl<absl::make_index_sequence<sizeof...(EndIndices)>,
513
+ EndIndices...> {};
514
+
515
+ // This implementation will flatten N-ary visit operations into a single switch
516
+ // statement when the number of cases would be less than our maximum specified
517
+ // switch-statement size.
518
+ // TODO(calabrese)
519
+ // Based on benchmarks, determine whether the function table approach actually
520
+ // does optimize better than a chain of switch statements and possibly update
521
+ // the implementation accordingly. Also consider increasing the maximum switch
522
+ // size.
523
+ template <std::size_t... EndIndices>
524
+ struct VisitIndices
525
+ : absl::conditional_t<(NumCasesOfSwitch<EndIndices...>::value <=
526
+ MaxUnrolledVisitCases),
527
+ VisitIndicesVariadic<EndIndices...>,
528
+ VisitIndicesFallback<EndIndices...>> {};
529
+
530
+ template <std::size_t EndIndex>
531
+ struct VisitIndices<EndIndex>
532
+ : absl::conditional_t<(EndIndex <= MaxUnrolledVisitCases),
533
+ VisitIndicesSwitch<EndIndex>,
534
+ VisitIndicesFallback<EndIndex>> {};
535
+
536
+ // Suppress bogus warning on MSVC: MSVC complains that the `reinterpret_cast`
537
+ // below is returning the address of a temporary or local object.
538
+ #ifdef _MSC_VER
539
+ #pragma warning(push)
540
+ #pragma warning(disable : 4172)
541
+ #endif // _MSC_VER
542
+
543
+ // TODO(calabrese) std::launder
544
+ // TODO(calabrese) constexpr
545
+ // NOTE: DO NOT REMOVE the `inline` keyword as it is necessary to work around a
546
+ // MSVC bug. See https://github.com/abseil/abseil-cpp/issues/129 for details.
547
+ template <class Self, std::size_t I>
548
+ inline VariantAccessResult<I, Self> AccessUnion(Self&& self, SizeT<I> /*i*/) {
549
+ return reinterpret_cast<VariantAccessResult<I, Self>>(self);
550
+ }
551
+
552
+ #ifdef _MSC_VER
553
+ #pragma warning(pop)
554
+ #endif // _MSC_VER
555
+
556
+ template <class T>
557
+ void DeducedDestroy(T& self) { // NOLINT
558
+ self.~T();
559
+ }
560
+
561
+ // NOTE: This type exists as a single entity for variant and its bases to
562
+ // befriend. It contains helper functionality that manipulates the state of the
563
+ // variant, such as the implementation of things like assignment and emplace
564
+ // operations.
565
+ struct VariantCoreAccess {
566
+ template <class VariantType>
567
+ static typename VariantType::Variant& Derived(VariantType& self) { // NOLINT
568
+ return static_cast<typename VariantType::Variant&>(self);
569
+ }
570
+
571
+ template <class VariantType>
572
+ static const typename VariantType::Variant& Derived(
573
+ const VariantType& self) { // NOLINT
574
+ return static_cast<const typename VariantType::Variant&>(self);
575
+ }
576
+
577
+ template <class VariantType>
578
+ static void Destroy(VariantType& self) { // NOLINT
579
+ Derived(self).destroy();
580
+ self.index_ = absl::variant_npos;
581
+ }
582
+
583
+ template <class Variant>
584
+ static void SetIndex(Variant& self, std::size_t i) { // NOLINT
585
+ self.index_ = i;
586
+ }
587
+
588
+ template <class Variant>
589
+ static void InitFrom(Variant& self, Variant&& other) { // NOLINT
590
+ VisitIndices<absl::variant_size<Variant>::value>::Run(
591
+ InitFromVisitor<Variant, Variant&&>{&self,
592
+ std::forward<Variant>(other)},
593
+ other.index());
594
+ self.index_ = other.index();
595
+ }
596
+
597
+ // Access a variant alternative, assuming the index is correct.
598
+ template <std::size_t I, class Variant>
599
+ static VariantAccessResult<I, Variant> Access(Variant&& self) {
600
+ // This cast instead of invocation of AccessUnion with an rvalue is a
601
+ // workaround for msvc. Without this there is a runtime failure when dealing
602
+ // with rvalues.
603
+ // TODO(calabrese) Reduce test case and find a simpler workaround.
604
+ return static_cast<VariantAccessResult<I, Variant>>(
605
+ variant_internal::AccessUnion(self.state_, SizeT<I>()));
606
+ }
607
+
608
+ // Access a variant alternative, throwing if the index is incorrect.
609
+ template <std::size_t I, class Variant>
610
+ static VariantAccessResult<I, Variant> CheckedAccess(Variant&& self) {
611
+ if (ABSL_PREDICT_FALSE(self.index_ != I)) {
612
+ TypedThrowBadVariantAccess<VariantAccessResult<I, Variant>>();
613
+ }
614
+
615
+ return Access<I>(absl::forward<Variant>(self));
616
+ }
617
+
618
+ // The implementation of the move-assignment operation for a variant.
619
+ template <class VType>
620
+ struct MoveAssignVisitor {
621
+ using DerivedType = typename VType::Variant;
622
+ template <std::size_t NewIndex>
623
+ void operator()(SizeT<NewIndex> /*new_i*/) const {
624
+ if (left->index_ == NewIndex) {
625
+ Access<NewIndex>(*left) = std::move(Access<NewIndex>(*right));
626
+ } else {
627
+ Derived(*left).template emplace<NewIndex>(
628
+ std::move(Access<NewIndex>(*right)));
629
+ }
630
+ }
631
+
632
+ void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
633
+ Destroy(*left);
634
+ }
635
+
636
+ VType* left;
637
+ VType* right;
638
+ };
639
+
640
+ template <class VType>
641
+ static MoveAssignVisitor<VType> MakeMoveAssignVisitor(VType* left,
642
+ VType* other) {
643
+ return {left, other};
644
+ }
645
+
646
+ // The implementation of the assignment operation for a variant.
647
+ template <class VType>
648
+ struct CopyAssignVisitor {
649
+ using DerivedType = typename VType::Variant;
650
+ template <std::size_t NewIndex>
651
+ void operator()(SizeT<NewIndex> /*new_i*/) const {
652
+ using New =
653
+ typename absl::variant_alternative<NewIndex, DerivedType>::type;
654
+
655
+ if (left->index_ == NewIndex) {
656
+ Access<NewIndex>(*left) = Access<NewIndex>(*right);
657
+ } else if (std::is_nothrow_copy_constructible<New>::value ||
658
+ !std::is_nothrow_move_constructible<New>::value) {
659
+ Derived(*left).template emplace<NewIndex>(Access<NewIndex>(*right));
660
+ } else {
661
+ Derived(*left) = DerivedType(Derived(*right));
662
+ }
663
+ }
664
+
665
+ void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
666
+ Destroy(*left);
667
+ }
668
+
669
+ VType* left;
670
+ const VType* right;
671
+ };
672
+
673
+ template <class VType>
674
+ static CopyAssignVisitor<VType> MakeCopyAssignVisitor(VType* left,
675
+ const VType& other) {
676
+ return {left, &other};
677
+ }
678
+
679
+ // The implementation of conversion-assignment operations for variant.
680
+ template <class Left, class QualifiedNew>
681
+ struct ConversionAssignVisitor {
682
+ using NewIndex =
683
+ variant_internal::IndexOfConstructedType<Left, QualifiedNew>;
684
+
685
+ void operator()(SizeT<NewIndex::value> /*old_i*/
686
+ ) const {
687
+ Access<NewIndex::value>(*left) = absl::forward<QualifiedNew>(other);
688
+ }
689
+
690
+ template <std::size_t OldIndex>
691
+ void operator()(SizeT<OldIndex> /*old_i*/
692
+ ) const {
693
+ using New =
694
+ typename absl::variant_alternative<NewIndex::value, Left>::type;
695
+ if (std::is_nothrow_constructible<New, QualifiedNew>::value ||
696
+ !std::is_nothrow_move_constructible<New>::value) {
697
+ left->template emplace<NewIndex::value>(
698
+ absl::forward<QualifiedNew>(other));
699
+ } else {
700
+ // the standard says "equivalent to
701
+ // operator=(variant(std::forward<T>(t)))", but we use `emplace` here
702
+ // because the variant's move assignment operator could be deleted.
703
+ left->template emplace<NewIndex::value>(
704
+ New(absl::forward<QualifiedNew>(other)));
705
+ }
706
+ }
707
+
708
+ Left* left;
709
+ QualifiedNew&& other;
710
+ };
711
+
712
+ template <class Left, class QualifiedNew>
713
+ static ConversionAssignVisitor<Left, QualifiedNew>
714
+ MakeConversionAssignVisitor(Left* left, QualifiedNew&& qual) {
715
+ return {left, absl::forward<QualifiedNew>(qual)};
716
+ }
717
+
718
+ // Backend for operations for `emplace()` which destructs `*self` then
719
+ // construct a new alternative with `Args...`.
720
+ template <std::size_t NewIndex, class Self, class... Args>
721
+ static typename absl::variant_alternative<NewIndex, Self>::type& Replace(
722
+ Self* self, Args&&... args) {
723
+ Destroy(*self);
724
+ using New = typename absl::variant_alternative<NewIndex, Self>::type;
725
+ New* const result = ::new (static_cast<void*>(&self->state_))
726
+ New(absl::forward<Args>(args)...);
727
+ self->index_ = NewIndex;
728
+ return *result;
729
+ }
730
+
731
+ template <class LeftVariant, class QualifiedRightVariant>
732
+ struct InitFromVisitor {
733
+ template <std::size_t NewIndex>
734
+ void operator()(SizeT<NewIndex> /*new_i*/) const {
735
+ using Alternative =
736
+ typename variant_alternative<NewIndex, LeftVariant>::type;
737
+ ::new (static_cast<void*>(&left->state_)) Alternative(
738
+ Access<NewIndex>(std::forward<QualifiedRightVariant>(right)));
739
+ }
740
+
741
+ void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
742
+ // This space intentionally left blank.
743
+ }
744
+ LeftVariant* left;
745
+ QualifiedRightVariant&& right;
746
+ };
747
+ };
748
+
749
+ template <class Expected, class... T>
750
+ struct IndexOfImpl;
751
+
752
+ template <class Expected>
753
+ struct IndexOfImpl<Expected> {
754
+ using IndexFromEnd = SizeT<0>;
755
+ using MatchedIndexFromEnd = IndexFromEnd;
756
+ using MultipleMatches = std::false_type;
757
+ };
758
+
759
+ template <class Expected, class Head, class... Tail>
760
+ struct IndexOfImpl<Expected, Head, Tail...> : IndexOfImpl<Expected, Tail...> {
761
+ using IndexFromEnd =
762
+ SizeT<IndexOfImpl<Expected, Tail...>::IndexFromEnd::value + 1>;
763
+ };
764
+
765
+ template <class Expected, class... Tail>
766
+ struct IndexOfImpl<Expected, Expected, Tail...>
767
+ : IndexOfImpl<Expected, Tail...> {
768
+ using IndexFromEnd =
769
+ SizeT<IndexOfImpl<Expected, Tail...>::IndexFromEnd::value + 1>;
770
+ using MatchedIndexFromEnd = IndexFromEnd;
771
+ using MultipleMatches = std::integral_constant<
772
+ bool, IndexOfImpl<Expected, Tail...>::MatchedIndexFromEnd::value != 0>;
773
+ };
774
+
775
+ template <class Expected, class... Types>
776
+ struct IndexOfMeta {
777
+ using Results = IndexOfImpl<Expected, Types...>;
778
+ static_assert(!Results::MultipleMatches::value,
779
+ "Attempted to access a variant by specifying a type that "
780
+ "matches more than one alternative.");
781
+ static_assert(Results::MatchedIndexFromEnd::value != 0,
782
+ "Attempted to access a variant by specifying a type that does "
783
+ "not match any alternative.");
784
+ using type = SizeT<sizeof...(Types) - Results::MatchedIndexFromEnd::value>;
785
+ };
786
+
787
+ template <class Expected, class... Types>
788
+ using IndexOf = typename IndexOfMeta<Expected, Types...>::type;
789
+
790
+ template <class Variant, class T, std::size_t CurrIndex>
791
+ struct UnambiguousIndexOfImpl;
792
+
793
+ // Terminating case encountered once we've checked all of the alternatives
794
+ template <class T, std::size_t CurrIndex>
795
+ struct UnambiguousIndexOfImpl<variant<>, T, CurrIndex> : SizeT<CurrIndex> {};
796
+
797
+ // Case where T is not Head
798
+ template <class Head, class... Tail, class T, std::size_t CurrIndex>
799
+ struct UnambiguousIndexOfImpl<variant<Head, Tail...>, T, CurrIndex>
800
+ : UnambiguousIndexOfImpl<variant<Tail...>, T, CurrIndex + 1>::type {};
801
+
802
+ // Case where T is Head
803
+ template <class Head, class... Tail, std::size_t CurrIndex>
804
+ struct UnambiguousIndexOfImpl<variant<Head, Tail...>, Head, CurrIndex>
805
+ : SizeT<UnambiguousIndexOfImpl<variant<Tail...>, Head, 0>::value ==
806
+ sizeof...(Tail)
807
+ ? CurrIndex
808
+ : CurrIndex + sizeof...(Tail) + 1> {};
809
+
810
+ template <class Variant, class T>
811
+ struct UnambiguousIndexOf;
812
+
813
+ struct NoMatch {
814
+ struct type {};
815
+ };
816
+
817
+ template <class... Alts, class T>
818
+ struct UnambiguousIndexOf<variant<Alts...>, T>
819
+ : std::conditional<UnambiguousIndexOfImpl<variant<Alts...>, T, 0>::value !=
820
+ sizeof...(Alts),
821
+ UnambiguousIndexOfImpl<variant<Alts...>, T, 0>,
822
+ NoMatch>::type::type {};
823
+
824
+ template <class T, std::size_t /*Dummy*/>
825
+ using UnambiguousTypeOfImpl = T;
826
+
827
+ template <class Variant, class T>
828
+ using UnambiguousTypeOfT =
829
+ UnambiguousTypeOfImpl<T, UnambiguousIndexOf<Variant, T>::value>;
830
+
831
+ template <class H, class... T>
832
+ class VariantStateBase;
833
+
834
+ // This is an implementation of the "imaginary function" that is described in
835
+ // [variant.ctor]
836
+ // It is used in order to determine which alternative to construct during
837
+ // initialization from some type T.
838
+ template <class Variant, std::size_t I = 0>
839
+ struct ImaginaryFun;
840
+
841
+ template <std::size_t I>
842
+ struct ImaginaryFun<variant<>, I> {
843
+ static void Run() = delete;
844
+ };
845
+
846
+ template <class H, class... T, std::size_t I>
847
+ struct ImaginaryFun<variant<H, T...>, I> : ImaginaryFun<variant<T...>, I + 1> {
848
+ using ImaginaryFun<variant<T...>, I + 1>::Run;
849
+
850
+ // NOTE: const& and && are used instead of by-value due to lack of guaranteed
851
+ // move elision of C++17. This may have other minor differences, but tests
852
+ // pass.
853
+ static SizeT<I> Run(const H&, SizeT<I>);
854
+ static SizeT<I> Run(H&&, SizeT<I>);
855
+ };
856
+
857
+ // The following metafunctions are used in constructor and assignment
858
+ // constraints.
859
+ template <class Self, class T>
860
+ struct IsNeitherSelfNorInPlace : std::true_type {};
861
+
862
+ template <class Self>
863
+ struct IsNeitherSelfNorInPlace<Self, Self> : std::false_type {};
864
+
865
+ template <class Self, class T>
866
+ struct IsNeitherSelfNorInPlace<Self, in_place_type_t<T>> : std::false_type {};
867
+
868
+ template <class Self, std::size_t I>
869
+ struct IsNeitherSelfNorInPlace<Self, in_place_index_t<I>> : std::false_type {};
870
+
871
+ template <class Variant, class T, class = void>
872
+ struct ConversionIsPossibleImpl : std::false_type {};
873
+
874
+ template <class Variant, class T>
875
+ struct ConversionIsPossibleImpl<
876
+ Variant, T,
877
+ void_t<decltype(ImaginaryFun<Variant>::Run(std::declval<T>(), {}))>>
878
+ : std::true_type {};
879
+
880
+ template <class Variant, class T>
881
+ struct ConversionIsPossible : ConversionIsPossibleImpl<Variant, T>::type {};
882
+
883
+ template <class Variant, class T>
884
+ struct IndexOfConstructedType<
885
+ Variant, T,
886
+ void_t<decltype(ImaginaryFun<Variant>::Run(std::declval<T>(), {}))>>
887
+ : decltype(ImaginaryFun<Variant>::Run(std::declval<T>(), {})) {};
888
+
889
+ template <std::size_t... Is>
890
+ struct ContainsVariantNPos
891
+ : absl::negation<std::is_same< // NOLINT
892
+ absl::integer_sequence<bool, 0 <= Is...>,
893
+ absl::integer_sequence<bool, Is != absl::variant_npos...>>> {};
894
+
895
+ template <class Op, class... QualifiedVariants>
896
+ using RawVisitResult =
897
+ absl::result_of_t<Op(VariantAccessResult<0, QualifiedVariants>...)>;
898
+
899
+ // NOTE: The spec requires that all return-paths yield the same type and is not
900
+ // SFINAE-friendly, so we can deduce the return type by examining the first
901
+ // result. If it's not callable, then we get an error, but are compliant and
902
+ // fast to compile.
903
+ // TODO(calabrese) Possibly rewrite in a way that yields better compile errors
904
+ // at the cost of longer compile-times.
905
+ template <class Op, class... QualifiedVariants>
906
+ struct VisitResultImpl {
907
+ using type =
908
+ absl::result_of_t<Op(VariantAccessResult<0, QualifiedVariants>...)>;
909
+ };
910
+
911
+ // Done in two steps intentionally so that we don't cause substitution to fail.
912
+ template <class Op, class... QualifiedVariants>
913
+ using VisitResult = typename VisitResultImpl<Op, QualifiedVariants...>::type;
914
+
915
+ template <class Op, class... QualifiedVariants>
916
+ struct PerformVisitation {
917
+ using ReturnType = VisitResult<Op, QualifiedVariants...>;
918
+
919
+ template <std::size_t... Is>
920
+ constexpr ReturnType operator()(SizeT<Is>... indices) const {
921
+ return Run(typename ContainsVariantNPos<Is...>::type{},
922
+ absl::index_sequence_for<QualifiedVariants...>(), indices...);
923
+ }
924
+
925
+ template <std::size_t... TupIs, std::size_t... Is>
926
+ constexpr ReturnType Run(std::false_type /*has_valueless*/,
927
+ index_sequence<TupIs...>, SizeT<Is>...) const {
928
+ static_assert(
929
+ std::is_same<ReturnType,
930
+ absl::result_of_t<Op(VariantAccessResult<
931
+ Is, QualifiedVariants>...)>>::value,
932
+ "All visitation overloads must have the same return type.");
933
+ return absl::base_internal::Invoke(
934
+ absl::forward<Op>(op),
935
+ VariantCoreAccess::Access<Is>(
936
+ absl::forward<QualifiedVariants>(std::get<TupIs>(variant_tup)))...);
937
+ }
938
+
939
+ template <std::size_t... TupIs, std::size_t... Is>
940
+ [[noreturn]] ReturnType Run(std::true_type /*has_valueless*/,
941
+ index_sequence<TupIs...>, SizeT<Is>...) const {
942
+ absl::variant_internal::ThrowBadVariantAccess();
943
+ }
944
+
945
+ // TODO(calabrese) Avoid using a tuple, which causes lots of instantiations
946
+ // Attempts using lambda variadic captures fail on current GCC.
947
+ std::tuple<QualifiedVariants&&...> variant_tup;
948
+ Op&& op;
949
+ };
950
+
951
+ template <class... T>
952
+ union Union;
953
+
954
+ // We want to allow for variant<> to be trivial. For that, we need the default
955
+ // constructor to be trivial, which means we can't define it ourselves.
956
+ // Instead, we use a non-default constructor that takes NoopConstructorTag
957
+ // that doesn't affect the triviality of the types.
958
+ struct NoopConstructorTag {};
959
+
960
+ template <std::size_t I>
961
+ struct EmplaceTag {};
962
+
963
+ template <>
964
+ union Union<> {
965
+ constexpr explicit Union(NoopConstructorTag) noexcept {}
966
+ };
967
+
968
+ // Suppress bogus warning on MSVC: MSVC complains that Union<T...> has a defined
969
+ // deleted destructor from the `std::is_destructible` check below.
970
+ #ifdef _MSC_VER
971
+ #pragma warning(push)
972
+ #pragma warning(disable : 4624)
973
+ #endif // _MSC_VER
974
+
975
+ template <class Head, class... Tail>
976
+ union Union<Head, Tail...> {
977
+ using TailUnion = Union<Tail...>;
978
+
979
+ explicit constexpr Union(NoopConstructorTag /*tag*/) noexcept
980
+ : tail(NoopConstructorTag()) {}
981
+
982
+ template <class... P>
983
+ explicit constexpr Union(EmplaceTag<0>, P&&... args)
984
+ : head(absl::forward<P>(args)...) {}
985
+
986
+ template <std::size_t I, class... P>
987
+ explicit constexpr Union(EmplaceTag<I>, P&&... args)
988
+ : tail(EmplaceTag<I - 1>{}, absl::forward<P>(args)...) {}
989
+
990
+ Head head;
991
+ TailUnion tail;
992
+ };
993
+
994
+ #ifdef _MSC_VER
995
+ #pragma warning(pop)
996
+ #endif // _MSC_VER
997
+
998
+ // TODO(calabrese) Just contain a Union in this union (certain configs fail).
999
+ template <class... T>
1000
+ union DestructibleUnionImpl;
1001
+
1002
+ template <>
1003
+ union DestructibleUnionImpl<> {
1004
+ constexpr explicit DestructibleUnionImpl(NoopConstructorTag) noexcept {}
1005
+ };
1006
+
1007
+ template <class Head, class... Tail>
1008
+ union DestructibleUnionImpl<Head, Tail...> {
1009
+ using TailUnion = DestructibleUnionImpl<Tail...>;
1010
+
1011
+ explicit constexpr DestructibleUnionImpl(NoopConstructorTag /*tag*/) noexcept
1012
+ : tail(NoopConstructorTag()) {}
1013
+
1014
+ template <class... P>
1015
+ explicit constexpr DestructibleUnionImpl(EmplaceTag<0>, P&&... args)
1016
+ : head(absl::forward<P>(args)...) {}
1017
+
1018
+ template <std::size_t I, class... P>
1019
+ explicit constexpr DestructibleUnionImpl(EmplaceTag<I>, P&&... args)
1020
+ : tail(EmplaceTag<I - 1>{}, absl::forward<P>(args)...) {}
1021
+
1022
+ ~DestructibleUnionImpl() {}
1023
+
1024
+ Head head;
1025
+ TailUnion tail;
1026
+ };
1027
+
1028
+ // This union type is destructible even if one or more T are not trivially
1029
+ // destructible. In the case that all T are trivially destructible, then so is
1030
+ // this resultant type.
1031
+ template <class... T>
1032
+ using DestructibleUnion =
1033
+ absl::conditional_t<std::is_destructible<Union<T...>>::value, Union<T...>,
1034
+ DestructibleUnionImpl<T...>>;
1035
+
1036
+ // Deepest base, containing the actual union and the discriminator
1037
+ template <class H, class... T>
1038
+ class VariantStateBase {
1039
+ protected:
1040
+ using Variant = variant<H, T...>;
1041
+
1042
+ template <class LazyH = H,
1043
+ class ConstructibleH = absl::enable_if_t<
1044
+ std::is_default_constructible<LazyH>::value, LazyH>>
1045
+ constexpr VariantStateBase() noexcept(
1046
+ std::is_nothrow_default_constructible<ConstructibleH>::value)
1047
+ : state_(EmplaceTag<0>()), index_(0) {}
1048
+
1049
+ template <std::size_t I, class... P>
1050
+ explicit constexpr VariantStateBase(EmplaceTag<I> tag, P&&... args)
1051
+ : state_(tag, absl::forward<P>(args)...), index_(I) {}
1052
+
1053
+ explicit constexpr VariantStateBase(NoopConstructorTag)
1054
+ : state_(NoopConstructorTag()), index_(variant_npos) {}
1055
+
1056
+ void destroy() {} // Does nothing (shadowed in child if non-trivial)
1057
+
1058
+ DestructibleUnion<H, T...> state_;
1059
+ std::size_t index_;
1060
+ };
1061
+
1062
+ using absl::internal::identity;
1063
+
1064
+ // OverloadSet::Overload() is a unary function which is overloaded to
1065
+ // take any of the element types of the variant, by reference-to-const.
1066
+ // The return type of the overload on T is identity<T>, so that you
1067
+ // can statically determine which overload was called.
1068
+ //
1069
+ // Overload() is not defined, so it can only be called in unevaluated
1070
+ // contexts.
1071
+ template <typename... Ts>
1072
+ struct OverloadSet;
1073
+
1074
+ template <typename T, typename... Ts>
1075
+ struct OverloadSet<T, Ts...> : OverloadSet<Ts...> {
1076
+ using Base = OverloadSet<Ts...>;
1077
+ static identity<T> Overload(const T&);
1078
+ using Base::Overload;
1079
+ };
1080
+
1081
+ template <>
1082
+ struct OverloadSet<> {
1083
+ // For any case not handled above.
1084
+ static void Overload(...);
1085
+ };
1086
+
1087
+ template <class T>
1088
+ using LessThanResult = decltype(std::declval<T>() < std::declval<T>());
1089
+
1090
+ template <class T>
1091
+ using GreaterThanResult = decltype(std::declval<T>() > std::declval<T>());
1092
+
1093
+ template <class T>
1094
+ using LessThanOrEqualResult = decltype(std::declval<T>() <= std::declval<T>());
1095
+
1096
+ template <class T>
1097
+ using GreaterThanOrEqualResult =
1098
+ decltype(std::declval<T>() >= std::declval<T>());
1099
+
1100
+ template <class T>
1101
+ using EqualResult = decltype(std::declval<T>() == std::declval<T>());
1102
+
1103
+ template <class T>
1104
+ using NotEqualResult = decltype(std::declval<T>() != std::declval<T>());
1105
+
1106
+ using type_traits_internal::is_detected_convertible;
1107
+
1108
+ template <class... T>
1109
+ using RequireAllHaveEqualT = absl::enable_if_t<
1110
+ absl::conjunction<is_detected_convertible<bool, EqualResult, T>...>::value,
1111
+ bool>;
1112
+
1113
+ template <class... T>
1114
+ using RequireAllHaveNotEqualT =
1115
+ absl::enable_if_t<absl::conjunction<is_detected_convertible<
1116
+ bool, NotEqualResult, T>...>::value,
1117
+ bool>;
1118
+
1119
+ template <class... T>
1120
+ using RequireAllHaveLessThanT =
1121
+ absl::enable_if_t<absl::conjunction<is_detected_convertible<
1122
+ bool, LessThanResult, T>...>::value,
1123
+ bool>;
1124
+
1125
+ template <class... T>
1126
+ using RequireAllHaveLessThanOrEqualT =
1127
+ absl::enable_if_t<absl::conjunction<is_detected_convertible<
1128
+ bool, LessThanOrEqualResult, T>...>::value,
1129
+ bool>;
1130
+
1131
+ template <class... T>
1132
+ using RequireAllHaveGreaterThanOrEqualT =
1133
+ absl::enable_if_t<absl::conjunction<is_detected_convertible<
1134
+ bool, GreaterThanOrEqualResult, T>...>::value,
1135
+ bool>;
1136
+
1137
+ template <class... T>
1138
+ using RequireAllHaveGreaterThanT =
1139
+ absl::enable_if_t<absl::conjunction<is_detected_convertible<
1140
+ bool, GreaterThanResult, T>...>::value,
1141
+ bool>;
1142
+
1143
+ // Helper template containing implementations details of variant that can't go
1144
+ // in the private section. For convenience, this takes the variant type as a
1145
+ // single template parameter.
1146
+ template <typename T>
1147
+ struct VariantHelper;
1148
+
1149
+ template <typename... Ts>
1150
+ struct VariantHelper<variant<Ts...>> {
1151
+ // Type metafunction which returns the element type selected if
1152
+ // OverloadSet::Overload() is well-formed when called with argument type U.
1153
+ template <typename U>
1154
+ using BestMatch = decltype(
1155
+ variant_internal::OverloadSet<Ts...>::Overload(std::declval<U>()));
1156
+
1157
+ // Type metafunction which returns true if OverloadSet::Overload() is
1158
+ // well-formed when called with argument type U.
1159
+ // CanAccept can't be just an alias because there is a MSVC bug on parameter
1160
+ // pack expansion involving decltype.
1161
+ template <typename U>
1162
+ struct CanAccept :
1163
+ std::integral_constant<bool, !std::is_void<BestMatch<U>>::value> {};
1164
+
1165
+ // Type metafunction which returns true if Other is an instantiation of
1166
+ // variant, and variants's converting constructor from Other will be
1167
+ // well-formed. We will use this to remove constructors that would be
1168
+ // ill-formed from the overload set.
1169
+ template <typename Other>
1170
+ struct CanConvertFrom;
1171
+
1172
+ template <typename... Us>
1173
+ struct CanConvertFrom<variant<Us...>>
1174
+ : public absl::conjunction<CanAccept<Us>...> {};
1175
+ };
1176
+
1177
+ // A type with nontrivial copy ctor and trivial move ctor.
1178
+ struct TrivialMoveOnly {
1179
+ TrivialMoveOnly(TrivialMoveOnly&&) = default;
1180
+ };
1181
+
1182
+ // Trait class to detect whether a type is trivially move constructible.
1183
+ // A union's defaulted copy/move constructor is deleted if any variant member's
1184
+ // copy/move constructor is nontrivial.
1185
+ template <typename T>
1186
+ struct IsTriviallyMoveConstructible:
1187
+ std::is_move_constructible<Union<T, TrivialMoveOnly>> {};
1188
+
1189
+ // To guarantee triviality of all special-member functions that can be trivial,
1190
+ // we use a chain of conditional bases for each one.
1191
+ // The order of inheritance of bases from child to base are logically:
1192
+ //
1193
+ // variant
1194
+ // VariantCopyAssignBase
1195
+ // VariantMoveAssignBase
1196
+ // VariantCopyBase
1197
+ // VariantMoveBase
1198
+ // VariantStateBaseDestructor
1199
+ // VariantStateBase
1200
+ //
1201
+ // Note that there is a separate branch at each base that is dependent on
1202
+ // whether or not that corresponding special-member-function can be trivial in
1203
+ // the resultant variant type.
1204
+
1205
+ template <class... T>
1206
+ class VariantStateBaseDestructorNontrivial;
1207
+
1208
+ template <class... T>
1209
+ class VariantMoveBaseNontrivial;
1210
+
1211
+ template <class... T>
1212
+ class VariantCopyBaseNontrivial;
1213
+
1214
+ template <class... T>
1215
+ class VariantMoveAssignBaseNontrivial;
1216
+
1217
+ template <class... T>
1218
+ class VariantCopyAssignBaseNontrivial;
1219
+
1220
+ // Base that is dependent on whether or not the destructor can be trivial.
1221
+ template <class... T>
1222
+ using VariantStateBaseDestructor =
1223
+ absl::conditional_t<std::is_destructible<Union<T...>>::value,
1224
+ VariantStateBase<T...>,
1225
+ VariantStateBaseDestructorNontrivial<T...>>;
1226
+
1227
+ // Base that is dependent on whether or not the move-constructor can be
1228
+ // implicitly generated by the compiler (trivial or deleted).
1229
+ // Previously we were using `std::is_move_constructible<Union<T...>>` to check
1230
+ // whether all Ts have trivial move constructor, but it ran into a GCC bug:
1231
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84866
1232
+ // So we have to use a different approach (i.e. `HasTrivialMoveConstructor`) to
1233
+ // work around the bug.
1234
+ template <class... T>
1235
+ using VariantMoveBase = absl::conditional_t<
1236
+ absl::disjunction<
1237
+ absl::negation<absl::conjunction<std::is_move_constructible<T>...>>,
1238
+ absl::conjunction<IsTriviallyMoveConstructible<T>...>>::value,
1239
+ VariantStateBaseDestructor<T...>, VariantMoveBaseNontrivial<T...>>;
1240
+
1241
+ // Base that is dependent on whether or not the copy-constructor can be trivial.
1242
+ template <class... T>
1243
+ using VariantCopyBase = absl::conditional_t<
1244
+ absl::disjunction<
1245
+ absl::negation<absl::conjunction<std::is_copy_constructible<T>...>>,
1246
+ std::is_copy_constructible<Union<T...>>>::value,
1247
+ VariantMoveBase<T...>, VariantCopyBaseNontrivial<T...>>;
1248
+
1249
+ // Base that is dependent on whether or not the move-assign can be trivial.
1250
+ template <class... T>
1251
+ using VariantMoveAssignBase = absl::conditional_t<
1252
+ absl::disjunction<
1253
+ absl::conjunction<absl::is_move_assignable<Union<T...>>,
1254
+ std::is_move_constructible<Union<T...>>,
1255
+ std::is_destructible<Union<T...>>>,
1256
+ absl::negation<absl::conjunction<std::is_move_constructible<T>...,
1257
+ // Note: We're not qualifying this with
1258
+ // absl:: because it doesn't compile
1259
+ // under MSVC.
1260
+ is_move_assignable<T>...>>>::value,
1261
+ VariantCopyBase<T...>, VariantMoveAssignBaseNontrivial<T...>>;
1262
+
1263
+ // Base that is dependent on whether or not the copy-assign can be trivial.
1264
+ template <class... T>
1265
+ using VariantCopyAssignBase = absl::conditional_t<
1266
+ absl::disjunction<
1267
+ absl::conjunction<absl::is_copy_assignable<Union<T...>>,
1268
+ std::is_copy_constructible<Union<T...>>,
1269
+ std::is_destructible<Union<T...>>>,
1270
+ absl::negation<absl::conjunction<std::is_copy_constructible<T>...,
1271
+ // Note: We're not qualifying this with
1272
+ // absl:: because it doesn't compile
1273
+ // under MSVC.
1274
+ is_copy_assignable<T>...>>>::value,
1275
+ VariantMoveAssignBase<T...>, VariantCopyAssignBaseNontrivial<T...>>;
1276
+
1277
+ template <class... T>
1278
+ using VariantBase = VariantCopyAssignBase<T...>;
1279
+
1280
+ template <class... T>
1281
+ class VariantStateBaseDestructorNontrivial : protected VariantStateBase<T...> {
1282
+ private:
1283
+ using Base = VariantStateBase<T...>;
1284
+
1285
+ protected:
1286
+ using Base::Base;
1287
+
1288
+ VariantStateBaseDestructorNontrivial() = default;
1289
+ VariantStateBaseDestructorNontrivial(VariantStateBaseDestructorNontrivial&&) =
1290
+ default;
1291
+ VariantStateBaseDestructorNontrivial(
1292
+ const VariantStateBaseDestructorNontrivial&) = default;
1293
+ VariantStateBaseDestructorNontrivial& operator=(
1294
+ VariantStateBaseDestructorNontrivial&&) = default;
1295
+ VariantStateBaseDestructorNontrivial& operator=(
1296
+ const VariantStateBaseDestructorNontrivial&) = default;
1297
+
1298
+ struct Destroyer {
1299
+ template <std::size_t I>
1300
+ void operator()(SizeT<I> i) const {
1301
+ using Alternative =
1302
+ typename absl::variant_alternative<I, variant<T...>>::type;
1303
+ variant_internal::AccessUnion(self->state_, i).~Alternative();
1304
+ }
1305
+
1306
+ void operator()(SizeT<absl::variant_npos> /*i*/) const {
1307
+ // This space intentionally left blank
1308
+ }
1309
+
1310
+ VariantStateBaseDestructorNontrivial* self;
1311
+ };
1312
+
1313
+ void destroy() { VisitIndices<sizeof...(T)>::Run(Destroyer{this}, index_); }
1314
+
1315
+ ~VariantStateBaseDestructorNontrivial() { destroy(); }
1316
+
1317
+ protected:
1318
+ using Base::index_;
1319
+ using Base::state_;
1320
+ };
1321
+
1322
+ template <class... T>
1323
+ class VariantMoveBaseNontrivial : protected VariantStateBaseDestructor<T...> {
1324
+ private:
1325
+ using Base = VariantStateBaseDestructor<T...>;
1326
+
1327
+ protected:
1328
+ using Base::Base;
1329
+
1330
+ struct Construct {
1331
+ template <std::size_t I>
1332
+ void operator()(SizeT<I> i) const {
1333
+ using Alternative =
1334
+ typename absl::variant_alternative<I, variant<T...>>::type;
1335
+ ::new (static_cast<void*>(&self->state_)) Alternative(
1336
+ variant_internal::AccessUnion(absl::move(other->state_), i));
1337
+ }
1338
+
1339
+ void operator()(SizeT<absl::variant_npos> /*i*/) const {}
1340
+
1341
+ VariantMoveBaseNontrivial* self;
1342
+ VariantMoveBaseNontrivial* other;
1343
+ };
1344
+
1345
+ VariantMoveBaseNontrivial() = default;
1346
+ VariantMoveBaseNontrivial(VariantMoveBaseNontrivial&& other) noexcept(
1347
+ absl::conjunction<std::is_nothrow_move_constructible<T>...>::value)
1348
+ : Base(NoopConstructorTag()) {
1349
+ VisitIndices<sizeof...(T)>::Run(Construct{this, &other}, other.index_);
1350
+ index_ = other.index_;
1351
+ }
1352
+
1353
+ VariantMoveBaseNontrivial(VariantMoveBaseNontrivial const&) = default;
1354
+
1355
+ VariantMoveBaseNontrivial& operator=(VariantMoveBaseNontrivial&&) = default;
1356
+ VariantMoveBaseNontrivial& operator=(VariantMoveBaseNontrivial const&) =
1357
+ default;
1358
+
1359
+ protected:
1360
+ using Base::index_;
1361
+ using Base::state_;
1362
+ };
1363
+
1364
+ template <class... T>
1365
+ class VariantCopyBaseNontrivial : protected VariantMoveBase<T...> {
1366
+ private:
1367
+ using Base = VariantMoveBase<T...>;
1368
+
1369
+ protected:
1370
+ using Base::Base;
1371
+
1372
+ VariantCopyBaseNontrivial() = default;
1373
+ VariantCopyBaseNontrivial(VariantCopyBaseNontrivial&&) = default;
1374
+
1375
+ struct Construct {
1376
+ template <std::size_t I>
1377
+ void operator()(SizeT<I> i) const {
1378
+ using Alternative =
1379
+ typename absl::variant_alternative<I, variant<T...>>::type;
1380
+ ::new (static_cast<void*>(&self->state_))
1381
+ Alternative(variant_internal::AccessUnion(other->state_, i));
1382
+ }
1383
+
1384
+ void operator()(SizeT<absl::variant_npos> /*i*/) const {}
1385
+
1386
+ VariantCopyBaseNontrivial* self;
1387
+ const VariantCopyBaseNontrivial* other;
1388
+ };
1389
+
1390
+ VariantCopyBaseNontrivial(VariantCopyBaseNontrivial const& other)
1391
+ : Base(NoopConstructorTag()) {
1392
+ VisitIndices<sizeof...(T)>::Run(Construct{this, &other}, other.index_);
1393
+ index_ = other.index_;
1394
+ }
1395
+
1396
+ VariantCopyBaseNontrivial& operator=(VariantCopyBaseNontrivial&&) = default;
1397
+ VariantCopyBaseNontrivial& operator=(VariantCopyBaseNontrivial const&) =
1398
+ default;
1399
+
1400
+ protected:
1401
+ using Base::index_;
1402
+ using Base::state_;
1403
+ };
1404
+
1405
+ template <class... T>
1406
+ class VariantMoveAssignBaseNontrivial : protected VariantCopyBase<T...> {
1407
+ friend struct VariantCoreAccess;
1408
+
1409
+ private:
1410
+ using Base = VariantCopyBase<T...>;
1411
+
1412
+ protected:
1413
+ using Base::Base;
1414
+
1415
+ VariantMoveAssignBaseNontrivial() = default;
1416
+ VariantMoveAssignBaseNontrivial(VariantMoveAssignBaseNontrivial&&) = default;
1417
+ VariantMoveAssignBaseNontrivial(const VariantMoveAssignBaseNontrivial&) =
1418
+ default;
1419
+ VariantMoveAssignBaseNontrivial& operator=(
1420
+ VariantMoveAssignBaseNontrivial const&) = default;
1421
+
1422
+ VariantMoveAssignBaseNontrivial&
1423
+ operator=(VariantMoveAssignBaseNontrivial&& other) noexcept(
1424
+ absl::conjunction<std::is_nothrow_move_constructible<T>...,
1425
+ std::is_nothrow_move_assignable<T>...>::value) {
1426
+ VisitIndices<sizeof...(T)>::Run(
1427
+ VariantCoreAccess::MakeMoveAssignVisitor(this, &other), other.index_);
1428
+ return *this;
1429
+ }
1430
+
1431
+ protected:
1432
+ using Base::index_;
1433
+ using Base::state_;
1434
+ };
1435
+
1436
+ template <class... T>
1437
+ class VariantCopyAssignBaseNontrivial : protected VariantMoveAssignBase<T...> {
1438
+ friend struct VariantCoreAccess;
1439
+
1440
+ private:
1441
+ using Base = VariantMoveAssignBase<T...>;
1442
+
1443
+ protected:
1444
+ using Base::Base;
1445
+
1446
+ VariantCopyAssignBaseNontrivial() = default;
1447
+ VariantCopyAssignBaseNontrivial(VariantCopyAssignBaseNontrivial&&) = default;
1448
+ VariantCopyAssignBaseNontrivial(const VariantCopyAssignBaseNontrivial&) =
1449
+ default;
1450
+ VariantCopyAssignBaseNontrivial& operator=(
1451
+ VariantCopyAssignBaseNontrivial&&) = default;
1452
+
1453
+ VariantCopyAssignBaseNontrivial& operator=(
1454
+ const VariantCopyAssignBaseNontrivial& other) {
1455
+ VisitIndices<sizeof...(T)>::Run(
1456
+ VariantCoreAccess::MakeCopyAssignVisitor(this, other), other.index_);
1457
+ return *this;
1458
+ }
1459
+
1460
+ protected:
1461
+ using Base::index_;
1462
+ using Base::state_;
1463
+ };
1464
+
1465
+ ////////////////////////////////////////
1466
+ // Visitors for Comparison Operations //
1467
+ ////////////////////////////////////////
1468
+
1469
+ template <class... Types>
1470
+ struct EqualsOp {
1471
+ const variant<Types...>* v;
1472
+ const variant<Types...>* w;
1473
+
1474
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1475
+ return true;
1476
+ }
1477
+
1478
+ template <std::size_t I>
1479
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1480
+ return VariantCoreAccess::Access<I>(*v) == VariantCoreAccess::Access<I>(*w);
1481
+ }
1482
+ };
1483
+
1484
+ template <class... Types>
1485
+ struct NotEqualsOp {
1486
+ const variant<Types...>* v;
1487
+ const variant<Types...>* w;
1488
+
1489
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1490
+ return false;
1491
+ }
1492
+
1493
+ template <std::size_t I>
1494
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1495
+ return VariantCoreAccess::Access<I>(*v) != VariantCoreAccess::Access<I>(*w);
1496
+ }
1497
+ };
1498
+
1499
+ template <class... Types>
1500
+ struct LessThanOp {
1501
+ const variant<Types...>* v;
1502
+ const variant<Types...>* w;
1503
+
1504
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1505
+ return false;
1506
+ }
1507
+
1508
+ template <std::size_t I>
1509
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1510
+ return VariantCoreAccess::Access<I>(*v) < VariantCoreAccess::Access<I>(*w);
1511
+ }
1512
+ };
1513
+
1514
+ template <class... Types>
1515
+ struct GreaterThanOp {
1516
+ const variant<Types...>* v;
1517
+ const variant<Types...>* w;
1518
+
1519
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1520
+ return false;
1521
+ }
1522
+
1523
+ template <std::size_t I>
1524
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1525
+ return VariantCoreAccess::Access<I>(*v) > VariantCoreAccess::Access<I>(*w);
1526
+ }
1527
+ };
1528
+
1529
+ template <class... Types>
1530
+ struct LessThanOrEqualsOp {
1531
+ const variant<Types...>* v;
1532
+ const variant<Types...>* w;
1533
+
1534
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1535
+ return true;
1536
+ }
1537
+
1538
+ template <std::size_t I>
1539
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1540
+ return VariantCoreAccess::Access<I>(*v) <= VariantCoreAccess::Access<I>(*w);
1541
+ }
1542
+ };
1543
+
1544
+ template <class... Types>
1545
+ struct GreaterThanOrEqualsOp {
1546
+ const variant<Types...>* v;
1547
+ const variant<Types...>* w;
1548
+
1549
+ constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
1550
+ return true;
1551
+ }
1552
+
1553
+ template <std::size_t I>
1554
+ constexpr bool operator()(SizeT<I> /*v_i*/) const {
1555
+ return VariantCoreAccess::Access<I>(*v) >= VariantCoreAccess::Access<I>(*w);
1556
+ }
1557
+ };
1558
+
1559
+ // Precondition: v.index() == w.index();
1560
+ template <class... Types>
1561
+ struct SwapSameIndex {
1562
+ variant<Types...>* v;
1563
+ variant<Types...>* w;
1564
+ template <std::size_t I>
1565
+ void operator()(SizeT<I>) const {
1566
+ type_traits_internal::Swap(VariantCoreAccess::Access<I>(*v),
1567
+ VariantCoreAccess::Access<I>(*w));
1568
+ }
1569
+
1570
+ void operator()(SizeT<variant_npos>) const {}
1571
+ };
1572
+
1573
+ // TODO(calabrese) do this from a different namespace for proper adl usage
1574
+ template <class... Types>
1575
+ struct Swap {
1576
+ variant<Types...>* v;
1577
+ variant<Types...>* w;
1578
+
1579
+ void generic_swap() const {
1580
+ variant<Types...> tmp(std::move(*w));
1581
+ VariantCoreAccess::Destroy(*w);
1582
+ VariantCoreAccess::InitFrom(*w, std::move(*v));
1583
+ VariantCoreAccess::Destroy(*v);
1584
+ VariantCoreAccess::InitFrom(*v, std::move(tmp));
1585
+ }
1586
+
1587
+ void operator()(SizeT<absl::variant_npos> /*w_i*/) const {
1588
+ if (!v->valueless_by_exception()) {
1589
+ generic_swap();
1590
+ }
1591
+ }
1592
+
1593
+ template <std::size_t Wi>
1594
+ void operator()(SizeT<Wi> /*w_i*/) {
1595
+ if (v->index() == Wi) {
1596
+ VisitIndices<sizeof...(Types)>::Run(SwapSameIndex<Types...>{v, w}, Wi);
1597
+ } else {
1598
+ generic_swap();
1599
+ }
1600
+ }
1601
+ };
1602
+
1603
+ template <typename Variant, typename = void, typename... Ts>
1604
+ struct VariantHashBase {
1605
+ VariantHashBase() = delete;
1606
+ VariantHashBase(const VariantHashBase&) = delete;
1607
+ VariantHashBase(VariantHashBase&&) = delete;
1608
+ VariantHashBase& operator=(const VariantHashBase&) = delete;
1609
+ VariantHashBase& operator=(VariantHashBase&&) = delete;
1610
+ };
1611
+
1612
+ struct VariantHashVisitor {
1613
+ template <typename T>
1614
+ size_t operator()(const T& t) {
1615
+ return std::hash<T>{}(t);
1616
+ }
1617
+ };
1618
+
1619
+ template <typename Variant, typename... Ts>
1620
+ struct VariantHashBase<Variant,
1621
+ absl::enable_if_t<absl::conjunction<
1622
+ type_traits_internal::IsHashable<Ts>...>::value>,
1623
+ Ts...> {
1624
+ using argument_type = Variant;
1625
+ using result_type = size_t;
1626
+ size_t operator()(const Variant& var) const {
1627
+ type_traits_internal::AssertHashEnabled<Ts...>();
1628
+ if (var.valueless_by_exception()) {
1629
+ return 239799884;
1630
+ }
1631
+ size_t result = VisitIndices<variant_size<Variant>::value>::Run(
1632
+ PerformVisitation<VariantHashVisitor, const Variant&>{
1633
+ std::forward_as_tuple(var), VariantHashVisitor{}},
1634
+ var.index());
1635
+ // Combine the index and the hash result in order to distinguish
1636
+ // std::variant<int, int> holding the same value as different alternative.
1637
+ return result ^ var.index();
1638
+ }
1639
+ };
1640
+
1641
+ } // namespace variant_internal
1642
+ ABSL_NAMESPACE_END
1643
+ } // namespace absl
1644
+
1645
+ #endif // !defined(ABSL_USES_STD_VARIANT)
1646
+ #endif // ABSL_TYPES_variant_internal_H_