Revert "Revert "[c++14] Remove Capture type (#29327)" (#29748)" (#29749)

This reverts commit d4aed9e615.
pull/29763/head
Craig Tiller 3 years ago committed by GitHub
parent 2f6277c1fb
commit 9a46171833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      BUILD
  2. 37
      CMakeLists.txt
  3. 15
      build_autogenerated.yaml
  4. 2
      gRPC-C++.podspec
  5. 2
      gRPC-Core.podspec
  6. 1
      grpc.gemspec
  7. 1
      package.xml
  8. 7
      src/core/ext/filters/channel_idle/channel_idle_filter.cc
  9. 5
      src/core/ext/filters/fault_injection/fault_injection_filter.cc
  10. 76
      src/core/lib/gprpp/capture.h
  11. 1
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  12. 14
      src/core/lib/security/transport/client_auth_filter.cc
  13. 13
      test/core/gprpp/BUILD
  14. 39
      test/core/gprpp/capture_test.cc
  15. 1
      test/core/promise/BUILD
  16. 7
      test/core/promise/promise_factory_test.cc
  17. 1
      tools/doxygen/Doxyfile.c++.internal
  18. 1
      tools/doxygen/Doxyfile.core.internal
  19. 24
      tools/run_tests/generated/tests.json

12
BUILD

@ -941,14 +941,6 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "capture",
external_deps = ["absl/utility"],
language = "c++",
public_hdrs = ["src/core/lib/gprpp/capture.h"],
deps = ["gpr_platform"],
)
grpc_cc_library(
name = "construct_destruct",
language = "c++",
@ -2994,7 +2986,6 @@ grpc_cc_library(
"src/core/ext/filters/channel_idle/channel_idle_filter.h",
],
deps = [
"capture",
"config",
"exec_ctx_wakeup_scheduler",
"gpr_base",
@ -3079,7 +3070,6 @@ grpc_cc_library(
external_deps = ["absl/strings"],
language = "c++",
deps = [
"capture",
"gpr_base",
"grpc_base",
"grpc_service_config",
@ -4754,7 +4744,6 @@ grpc_cc_library(
],
language = "c++",
deps = [
"capture",
"gpr_base",
"grpc_base",
"grpc_codegen",
@ -4919,7 +4908,6 @@ grpc_cc_library(
deps = [
"arena",
"arena_promise",
"capture",
"config",
"gpr_base",
"grpc_base",

37
CMakeLists.txt generated

@ -943,7 +943,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx call_finalization_test)
add_dependencies(buildtests_cxx call_push_pull_test)
add_dependencies(buildtests_cxx cancel_ares_query_test)
add_dependencies(buildtests_cxx capture_test)
add_dependencies(buildtests_cxx cel_authorization_engine_test)
add_dependencies(buildtests_cxx certificate_provider_registry_test)
add_dependencies(buildtests_cxx certificate_provider_store_test)
@ -8466,41 +8465,6 @@ target_link_libraries(cancel_ares_query_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(capture_test
test/core/gprpp/capture_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(capture_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(capture_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
absl::utility
)
endif()
if(gRPC_BUILD_TESTS)
@ -13909,7 +13873,6 @@ target_link_libraries(promise_factory_test
absl::status
absl::optional
absl::variant
absl::utility
)

@ -733,7 +733,6 @@ libs:
- src/core/lib/event_engine/trace.h
- src/core/lib/gprpp/atomic_utils.h
- src/core/lib/gprpp/bitset.h
- src/core/lib/gprpp/capture.h
- src/core/lib/gprpp/chunked_vector.h
- src/core/lib/gprpp/cpp_impl_of.h
- src/core/lib/gprpp/dual_ref_counted.h
@ -1917,7 +1916,6 @@ libs:
- src/core/lib/event_engine/trace.h
- src/core/lib/gprpp/atomic_utils.h
- src/core/lib/gprpp/bitset.h
- src/core/lib/gprpp/capture.h
- src/core/lib/gprpp/chunked_vector.h
- src/core/lib/gprpp/cpp_impl_of.h
- src/core/lib/gprpp/dual_ref_counted.h
@ -4921,17 +4919,6 @@ targets:
deps:
- grpc++_test_config
- grpc++_test_util
- name: capture_test
gtest: true
build: test
language: c++
headers:
- src/core/lib/gprpp/capture.h
src:
- test/core/gprpp/capture_test.cc
deps:
- absl/utility:utility
uses_polling: false
- name: cel_authorization_engine_test
gtest: true
build: test
@ -7177,7 +7164,6 @@ targets:
build: test
language: c++
headers:
- src/core/lib/gprpp/capture.h
- src/core/lib/promise/detail/promise_factory.h
- src/core/lib/promise/detail/promise_like.h
- src/core/lib/promise/poll.h
@ -7190,7 +7176,6 @@ targets:
- absl/status:status
- absl/types:optional
- absl/types:variant
- absl/utility:utility
uses_polling: false
- name: promise_map_test
gtest: true

2
gRPC-C++.podspec generated

@ -685,7 +685,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/atomic_utils.h',
'src/core/lib/gprpp/bitset.h',
'src/core/lib/gprpp/capture.h',
'src/core/lib/gprpp/chunked_vector.h',
'src/core/lib/gprpp/construct_destruct.h',
'src/core/lib/gprpp/cpp_impl_of.h',
@ -1501,7 +1500,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/atomic_utils.h',
'src/core/lib/gprpp/bitset.h',
'src/core/lib/gprpp/capture.h',
'src/core/lib/gprpp/chunked_vector.h',
'src/core/lib/gprpp/construct_destruct.h',
'src/core/lib/gprpp/cpp_impl_of.h',

2
gRPC-Core.podspec generated

@ -1084,7 +1084,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/atomic_utils.h',
'src/core/lib/gprpp/bitset.h',
'src/core/lib/gprpp/capture.h',
'src/core/lib/gprpp/chunked_vector.h',
'src/core/lib/gprpp/construct_destruct.h',
'src/core/lib/gprpp/cpp_impl_of.h',
@ -2100,7 +2099,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/atomic_utils.h',
'src/core/lib/gprpp/bitset.h',
'src/core/lib/gprpp/capture.h',
'src/core/lib/gprpp/chunked_vector.h',
'src/core/lib/gprpp/construct_destruct.h',
'src/core/lib/gprpp/cpp_impl_of.h',

1
grpc.gemspec generated

@ -997,7 +997,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/wrap_memcpy.cc )
s.files += %w( src/core/lib/gprpp/atomic_utils.h )
s.files += %w( src/core/lib/gprpp/bitset.h )
s.files += %w( src/core/lib/gprpp/capture.h )
s.files += %w( src/core/lib/gprpp/chunked_vector.h )
s.files += %w( src/core/lib/gprpp/construct_destruct.h )
s.files += %w( src/core/lib/gprpp/cpp_impl_of.h )

1
package.xml generated

@ -979,7 +979,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/wrap_memcpy.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic_utils.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/bitset.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/capture.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/chunked_vector.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/construct_destruct.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/cpp_impl_of.h" role="src" />

@ -29,7 +29,6 @@
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/channel/promise_based_filter.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/capture.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h"
#include "src/core/lib/promise/loop.h"
@ -198,9 +197,9 @@ ArenaPromise<ServerMetadataHandle> ChannelIdleFilter::MakeCallPromise(
using Decrementer = std::unique_ptr<ChannelIdleFilter, CallCountDecreaser>;
IncreaseCallCount();
return ArenaPromise<ServerMetadataHandle>(
Capture([](Decrementer*, ArenaPromise<ServerMetadataHandle>* next)
-> Poll<ServerMetadataHandle> { return (*next)(); },
Decrementer(this), next_promise_factory(std::move(call_args))));
[decrementer = Decrementer(this),
next = next_promise_factory(std::move(call_args))]() mutable
-> Poll<ServerMetadataHandle> { return next(); });
}
bool ChannelIdleFilter::StartTransportOp(grpc_transport_op* op) {

@ -29,7 +29,6 @@
#include "src/core/ext/filters/fault_injection/service_config_parser.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/status_util.h"
#include "src/core/lib/gprpp/capture.h"
#include "src/core/lib/promise/sleep.h"
#include "src/core/lib/promise/try_seq.h"
#include "src/core/lib/service_config/service_config_call_data.h"
@ -136,9 +135,7 @@ ArenaPromise<ServerMetadataHandle> FaultInjectionFilter::MakeCallPromise(
auto delay = decision.DelayUntil();
return TrySeq(
Sleep(delay),
Capture(
[](InjectionDecision* decision) { return decision->MaybeAbort(); },
std::move(decision)),
[decision = std::move(decision)]() { return decision.MaybeAbort(); },
next_promise_factory(std::move(call_args)));
}

@ -1,76 +0,0 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_CORE_LIB_GPRPP_CAPTURE_H
#define GRPC_CORE_LIB_GPRPP_CAPTURE_H
#include <grpc/support/port_platform.h>
#include <tuple>
#include <type_traits>
#include "absl/utility/utility.h"
namespace grpc_core {
namespace detail {
template <typename F, typename... Captures>
class Capture {
public:
explicit Capture(F f, Captures... captures)
: f_(std::move(f)), captures_(std::move(captures)...) {}
template <typename... Args>
decltype(std::declval<F>()(static_cast<Captures*>(nullptr)...,
std::declval<Args>()...))
operator()(Args... args) {
auto f = &f_;
return absl::apply(
[f, &args...](Captures&... captures) {
return (*f)(&captures..., std::move(args)...);
},
captures_);
}
private:
GPR_NO_UNIQUE_ADDRESS F f_;
GPR_NO_UNIQUE_ADDRESS std::tuple<Captures...> captures_;
};
} // namespace detail
// C++11 helper - best explained by usage:
//
// BigThing big_thing;
// auto f = Capture(
// [](BigThing* c, int a, int b) { /*...*/ },
// std::move(big_thing));
//
// results in: f being a callable that takes arguments (int a, int b), and
// captures the original value of big_thing by move. Each call, a pointer to
// each captured thing is inserted into the argument list at the beginning so it
// can be manipulated.
//
// Captured values are mutable, and it's the users responsibility to ensure,
// should this callable be invoked from different threads, that proper locking
// is implemented.
template <typename F, typename... Captures>
detail::Capture<F, Captures...> Capture(F f, Captures... captures) {
return detail::Capture<F, Captures...>(std::move(f), std::move(captures)...);
}
} // namespace grpc_core
#endif // GRPC_CORE_LIB_GPRPP_CAPTURE_H

@ -38,7 +38,6 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/capture.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/http/httpcli_ssl_credentials.h"
#include "src/core/lib/iomgr/error.h"

@ -31,7 +31,6 @@
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/promise_based_filter.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/capture.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/promise/promise.h"
@ -151,13 +150,12 @@ ArenaPromise<absl::StatusOr<CallArgs>> ClientAuthFilter::GetCallCredsMetadata(
auto client_initial_metadata = std::move(call_args.client_initial_metadata);
return TrySeq(
creds->GetRequestMetadata(std::move(client_initial_metadata), &args_),
Capture(
[](CallArgs* rest_of_args, ClientMetadataHandle new_metadata) {
rest_of_args->client_initial_metadata = std::move(new_metadata);
return Immediate<absl::StatusOr<CallArgs>>(
absl::StatusOr<CallArgs>(std::move(*rest_of_args)));
},
std::move(call_args)));
[call_args =
std::move(call_args)](ClientMetadataHandle new_metadata) mutable {
call_args.client_initial_metadata = std::move(new_metadata);
return Immediate<absl::StatusOr<CallArgs>>(
absl::StatusOr<CallArgs>(std::move(call_args)));
});
}
ArenaPromise<ServerMetadataHandle> ClientAuthFilter::MakeCallPromise(

@ -289,19 +289,6 @@ grpc_cc_test(
],
)
grpc_cc_test(
name = "capture_test",
srcs = ["capture_test.cc"],
external_deps = ["gtest"],
language = "c++",
uses_event_engine = False,
uses_polling = False,
deps = [
"//:capture",
"//test/core/util:grpc_suppressions",
],
)
grpc_cc_test(
name = "cpp_impl_of_test",
srcs = ["cpp_impl_of_test.cc"],

@ -1,39 +0,0 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/core/lib/gprpp/capture.h"
#include <gtest/gtest.h>
namespace grpc_core {
TEST(CaptureTest, Capture) {
auto f = Capture([](int* p) { EXPECT_EQ(*p, 42); }, 42);
f();
}
TEST(CaptureTest, WithArgsAndReturn) {
int captured = 1;
auto f =
Capture([captured](int* p, int arg) { return (captured + *p) * arg; }, 2);
EXPECT_EQ(f(2), 6);
EXPECT_EQ(f(3), 9);
}
} // namespace grpc_core
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -140,7 +140,6 @@ grpc_cc_test(
uses_event_engine = False,
uses_polling = False,
deps = [
"//:capture",
"//:promise",
"//:promise_factory",
"//test/core/util:grpc_suppressions",

@ -18,7 +18,6 @@
#include "absl/functional/bind_front.h"
#include "src/core/lib/gprpp/capture.h"
#include "src/core/lib/promise/promise.h"
namespace grpc_core {
@ -54,12 +53,6 @@ TEST(AdaptorTest, FactoryFromBindFrontPromise) {
Poll<int>(42));
}
TEST(AdaptorTest, FactoryFromCapturePromise) {
EXPECT_EQ(MakeFactory<void>(Capture([](int* i) { return Poll<int>(*i); }, 42))
.Once()(),
Poll<int>(42));
}
} // namespace testing
} // namespace promise_detail

@ -1980,7 +1980,6 @@ src/core/lib/gpr/useful.h \
src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/atomic_utils.h \
src/core/lib/gprpp/bitset.h \
src/core/lib/gprpp/capture.h \
src/core/lib/gprpp/chunked_vector.h \
src/core/lib/gprpp/construct_destruct.h \
src/core/lib/gprpp/cpp_impl_of.h \

@ -1773,7 +1773,6 @@ src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/README.md \
src/core/lib/gprpp/atomic_utils.h \
src/core/lib/gprpp/bitset.h \
src/core/lib/gprpp/capture.h \
src/core/lib/gprpp/chunked_vector.h \
src/core/lib/gprpp/construct_destruct.h \
src/core/lib/gprpp/cpp_impl_of.h \

@ -3161,30 +3161,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "capture_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save