From e8920e2d3e1f02762f8a996fed7bfeb08ec7cd75 Mon Sep 17 00:00:00 2001 From: TensorFlow Federated Team Date: Mon, 9 Dec 2024 18:13:32 -0800 Subject: [PATCH] Replace std::string_view with absl::string_view PiperOrigin-RevId: 704489605 --- .../cc/core/impl/executors/BUILD | 26 +++++++++++++++++++ .../cc/core/impl/executors/array_test_utils.h | 4 +-- .../cc/core/impl/executors/cardinalities.h | 6 ++--- .../core/impl/executors/composing_executor.cc | 10 +++---- .../cc/core/impl/executors/data_executor.cc | 6 ++--- .../dataset_from_tensor_structures.cc | 6 ++--- .../cc/core/impl/executors/executor.h | 6 ++--- .../core/impl/executors/executor_service.cc | 4 +-- .../cc/core/impl/executors/executor_service.h | 4 +-- .../impl/executors/executor_service_test.cc | 10 +++---- .../impl/executors/federated_intrinsics.cc | 5 ++-- .../impl/executors/federated_intrinsics.h | 20 +++++++------- .../impl/executors/federating_executor.cc | 10 +++---- .../executors/reference_resolving_executor.cc | 10 +++---- .../cc/core/impl/executors/remote_executor.cc | 6 ++--- .../impl/executors/remote_executor_test.cc | 6 ++--- .../core/impl/executors/sequence_executor.cc | 10 +++---- .../impl/executors/sequence_intrinsics.cc | 7 +++-- .../core/impl/executors/sequence_intrinsics.h | 11 ++++---- .../core/impl/executors/session_provider.cc | 10 +++---- .../cc/core/impl/executors/status_macros.h | 4 +-- .../executors/streaming_remote_executor.cc | 6 ++--- .../streaming_remote_executor_test.cc | 18 ++++++------- .../impl/executors/tensorflow_executor.cc | 26 +++++++++---------- .../impl/executors/tensorflow_utils_test.cc | 6 ++--- .../cc/core/impl/executors/threading.cc | 4 +-- .../cc/core/impl/executors/threading.h | 4 +-- .../cc/core/impl/executors/value_test_utils.h | 14 +++++----- .../core/impl/executors/value_validation.cc | 5 ++-- .../cc/core/impl/executors/xla_executor.cc | 8 +++--- .../cc/core/impl/executors/xla_executor.h | 4 +-- 31 files changed, 150 insertions(+), 126 deletions(-) diff --git a/tensorflow_federated/cc/core/impl/executors/BUILD b/tensorflow_federated/cc/core/impl/executors/BUILD index 5f5e698eaf..41fab8236f 100644 --- a/tensorflow_federated/cc/core/impl/executors/BUILD +++ b/tensorflow_federated/cc/core/impl/executors/BUILD @@ -42,6 +42,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@eigen_archive//:eigen3", "@federated_language//federated_language/proto:array_cc_proto", "@federated_language//federated_language/proto:data_type_cc_proto", @@ -57,6 +58,7 @@ cc_library( "@com_google_absl//absl/container:btree", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", ], ) @@ -80,6 +82,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", @@ -140,6 +143,7 @@ cc_library( ":threading", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", ], ) @@ -171,6 +175,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/types:span", "@org_tensorflow//tensorflow/cc:array_ops", "@org_tensorflow//tensorflow/cc:cc_ops", @@ -319,6 +324,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@com_google_absl//absl/utility", @@ -379,6 +385,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@federated_language//federated_language/proto:computation_cc_proto", ], @@ -401,6 +408,7 @@ cc_test( "@com_github_grpc_grpc//:grpc++", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", ], @@ -439,6 +447,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", ], ) @@ -462,6 +471,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", @@ -584,6 +594,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@federated_language//federated_language/proto:computation_cc_proto", "@org_tensorflow//tensorflow/core:tensorflow", ], @@ -608,6 +619,7 @@ cc_test( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", "@federated_language//federated_language/proto:data_type_cc_proto", @@ -638,6 +650,7 @@ cc_library( "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@federated_language//federated_language/proto:computation_cc_proto", ], @@ -662,6 +675,7 @@ cc_test( "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", "@org_tensorflow//tensorflow/cc:array_ops", @@ -686,6 +700,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", @@ -726,6 +741,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", ], ) @@ -741,6 +757,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@org_tensorflow//tensorflow/core:framework", "@org_tensorflow//tensorflow/core:protos_all_cc", @@ -780,6 +797,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", ], ) @@ -803,6 +821,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@federated_language//federated_language/proto:computation_cc_proto", ], @@ -832,6 +851,7 @@ cc_test( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", "@com_google_absl//absl/types:span", @@ -907,6 +927,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", @@ -997,6 +1018,7 @@ cc_test( "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", "@eigen_archive//:eigen3", "@federated_language//federated_language/proto:array_cc_proto", "@federated_language//federated_language/proto:computation_cc_proto", @@ -1018,6 +1040,7 @@ cc_library( "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/types:span", "@com_google_absl//absl/utility", @@ -1082,6 +1105,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest", "@federated_language//federated_language/proto:array_cc_proto", @@ -1106,6 +1130,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@federated_language//federated_language/proto:computation_cc_proto", ], ) @@ -1140,6 +1165,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", "@com_google_absl//absl/types:span", "@federated_language//federated_language/proto:computation_cc_proto", "@org_tensorflow//tensorflow/compiler/jit:xla_cpu_jit", # buildcleaner: keep # Linking in this dependency ensures that XLA can compile its code for the CPU host. diff --git a/tensorflow_federated/cc/core/impl/executors/array_test_utils.h b/tensorflow_federated/cc/core/impl/executors/array_test_utils.h index 062ea168f3..051b79f20d 100644 --- a/tensorflow_federated/cc/core/impl/executors/array_test_utils.h +++ b/tensorflow_federated/cc/core/impl/executors/array_test_utils.h @@ -20,11 +20,11 @@ limitations under the License #include #include #include -#include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "third_party/eigen3/Eigen/Core" #include "federated_language/proto/array.pb.h" #include "federated_language/proto/data_type.pb.h" @@ -199,7 +199,7 @@ inline absl::StatusOr CreateArray( inline absl::StatusOr CreateArrayContent( federated_language::DataType dtype, federated_language::ArrayShape shape_pb, - std::string_view content) { + absl::string_view content) { federated_language::Array array_pb; array_pb.set_dtype(dtype); array_pb.mutable_shape()->Swap(&shape_pb); diff --git a/tensorflow_federated/cc/core/impl/executors/cardinalities.h b/tensorflow_federated/cc/core/impl/executors/cardinalities.h index 7010776d00..5b4f51cc4d 100644 --- a/tensorflow_federated/cc/core/impl/executors/cardinalities.h +++ b/tensorflow_federated/cc/core/impl/executors/cardinalities.h @@ -17,10 +17,10 @@ limitations under the License #define THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_CARDINALITIES_H_ #include -#include #include "absl/container/btree_map.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" namespace tensorflow_federated { @@ -31,8 +31,8 @@ namespace tensorflow_federated { // ordering. the `ExecutorService` uses this as an optimization to provide // per-cardinality `ExecutorId`s. using CardinalityMap = absl::btree_map; -const std::string_view kClientsUri = "clients"; -const std::string_view kServerUri = "server"; +const absl::string_view kClientsUri = "clients"; +const absl::string_view kServerUri = "server"; // Returns the number of clients specified by the provided `cardinalities`. absl::StatusOr NumClientsFromCardinalities( diff --git a/tensorflow_federated/cc/core/impl/executors/composing_executor.cc b/tensorflow_federated/cc/core/impl/executors/composing_executor.cc index d6d5f976d5..dd9a7f1a1a 100644 --- a/tensorflow_federated/cc/core/impl/executors/composing_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/composing_executor.cc @@ -22,7 +22,6 @@ limitations under the License #include #include #include -#include #include // NOLINT #include #include @@ -35,6 +34,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "federated_language/proto/computation.pb.h" @@ -241,7 +241,7 @@ class ExecutorValue { return std::get(value_); } - absl::Status CheckLenForUseAsArgument(std::string_view function_name, + absl::Status CheckLenForUseAsArgument(absl::string_view function_name, size_t len) const { if (type() != ExecutorValue::ValueType::STRUCTURE) { return absl::InvalidArgumentError(absl::StrCat( @@ -259,7 +259,7 @@ class ExecutorValue { // Fetches an unplaced functional value as a proto, ensuring that no // underlying `Materialize` call occurs. absl::StatusOr> GetUnplacedFunctionProto( - std::string_view name) const { + absl::string_view name) const { if (type() != ExecutorValue::ValueType::UNPLACED) { return absl::InvalidArgumentError( absl::StrCat("`", name, "` must be an unplaced functional value, ", @@ -383,8 +383,8 @@ class ComposingExecutor : public ExecutorBase { } protected: - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "ComposingExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "ComposingExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/data_executor.cc b/tensorflow_federated/cc/core/impl/executors/data_executor.cc index 5623f26cbd..74841db95b 100644 --- a/tensorflow_federated/cc/core/impl/executors/data_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/data_executor.cc @@ -19,12 +19,12 @@ limitations under the License #include // NOLINT #include #include -#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "tensorflow_federated/cc/core/impl/executors/data_backend.h" #include "tensorflow_federated/cc/core/impl/executors/executor.h" #include "tensorflow_federated/cc/core/impl/executors/status_macros.h" @@ -44,8 +44,8 @@ class DataExecutor : public ExecutorBase { : child_(std::move(child)), data_backend_(std::move(data_backend)) {} protected: - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "DataExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "DataExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/dataset_from_tensor_structures.cc b/tensorflow_federated/cc/core/impl/executors/dataset_from_tensor_structures.cc index 577ac584c5..8f45e1ec3a 100644 --- a/tensorflow_federated/cc/core/impl/executors/dataset_from_tensor_structures.cc +++ b/tensorflow_federated/cc/core/impl/executors/dataset_from_tensor_structures.cc @@ -18,13 +18,13 @@ limitations under the License #include #include #include -#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "tensorflow/cc/framework/ops.h" #include "tensorflow/cc/framework/scope.h" @@ -53,7 +53,7 @@ std::string InputTensorName(size_t i, size_t element_index) { } template -std::string MismatchedElementsMessage(std::string_view property, +std::string MismatchedElementsMessage(absl::string_view property, size_t element_index, const T& first_value, const T& second_value, @@ -188,7 +188,7 @@ absl::StatusOr DatasetFromTensorStructuresGraph( tf::Node* ds_from_slice; scope.UpdateStatus( ds_from_slice_builder.Finalize(scope.graph(), &ds_from_slice)); - static constexpr std::string_view output_tensor_name = "serialized_dataset"; + static constexpr absl::string_view output_tensor_name = "serialized_dataset"; tf::NodeBuilder ds_to_graph_builder(output_tensor_name, "DatasetToGraphV2"); ds_to_graph_builder.Input(ds_from_slice, 0) .Attr("external_state_policy", 0) diff --git a/tensorflow_federated/cc/core/impl/executors/executor.h b/tensorflow_federated/cc/core/impl/executors/executor.h index d557cb924c..9e5adffa5b 100644 --- a/tensorflow_federated/cc/core/impl/executors/executor.h +++ b/tensorflow_federated/cc/core/impl/executors/executor.h @@ -21,7 +21,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "absl/utility/utility.h" @@ -271,7 +271,7 @@ class ExecutorBase : public Executor, return std::nullopt; } std::string path = absl::StrCat(ExecutorName(), "::", method_name); - std::string_view path_view(path); + absl::string_view path_view(path); VLOG(1) << path_view; // Safe to pass in a view here: `TraceMe` internally copies to an owned // `std::string`. @@ -288,7 +288,7 @@ class ExecutorBase : public Executor, } // Returns the string name of the current executor. - virtual std::string_view ExecutorName() = 0; + virtual absl::string_view ExecutorName() = 0; virtual absl::StatusOr CreateExecutorValue( const v0::Value& value_pb) = 0; virtual absl::StatusOr CreateCall( diff --git a/tensorflow_federated/cc/core/impl/executors/executor_service.cc b/tensorflow_federated/cc/core/impl/executors/executor_service.cc index 089fe1e4b0..12fb260786 100644 --- a/tensorflow_federated/cc/core/impl/executors/executor_service.cc +++ b/tensorflow_federated/cc/core/impl/executors/executor_service.cc @@ -18,7 +18,6 @@ limitations under the License #include #include #include -#include #include #include @@ -28,6 +27,7 @@ limitations under the License #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "include/grpcpp/server_context.h" #include "include/grpcpp/support/status.h" @@ -208,7 +208,7 @@ grpc::Status ExecutorService::GetExecutor(grpc::ServerContext* context, } grpc::Status ExecutorService::RequireExecutor( - std::string_view method_name, const v0::ExecutorId& executor, + absl::string_view method_name, const v0::ExecutorId& executor, std::shared_ptr& executor_out) { absl::StatusOr ex = executor_resolver_.ExecutorForId({executor.id()}); diff --git a/tensorflow_federated/cc/core/impl/executors/executor_service.h b/tensorflow_federated/cc/core/impl/executors/executor_service.h index f8d936300e..29b35be4a2 100644 --- a/tensorflow_federated/cc/core/impl/executors/executor_service.h +++ b/tensorflow_federated/cc/core/impl/executors/executor_service.h @@ -20,13 +20,13 @@ limitations under the License #include #include #include -#include #include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" #include "absl/random/random.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "include/grpcpp/grpcpp.h" #include "include/grpcpp/support/status.h" @@ -134,7 +134,7 @@ class ExecutorService : public v0::ExecutorGroup::Service { // Writes the `std::shared_ptr` corresponding to `executor_id` into // `executor_out`. `method name` is the name of the caller that requested // access to this executor, and is used for debug purposes only. - grpc::Status RequireExecutor(std::string_view method_name, + grpc::Status RequireExecutor(absl::string_view method_name, const v0::ExecutorId& executor_id, std::shared_ptr& executor_out); diff --git a/tensorflow_federated/cc/core/impl/executors/executor_service_test.cc b/tensorflow_federated/cc/core/impl/executors/executor_service_test.cc index 3cdb86c348..d5259823ef 100644 --- a/tensorflow_federated/cc/core/impl/executors/executor_service_test.cc +++ b/tensorflow_federated/cc/core/impl/executors/executor_service_test.cc @@ -19,7 +19,6 @@ limitations under the License #include #include #include -#include #include #include @@ -27,6 +26,7 @@ limitations under the License #include "googletest/include/gtest/gtest.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "include/grpcpp/grpcpp.h" #include "include/grpcpp/support/status.h" @@ -140,10 +140,10 @@ class ExecutorServiceTest : public ::testing::Test { } v0::CreateStructRequest CreateStructForIds( - const absl::Span ids_for_struct) { + const absl::Span ids_for_struct) { v0::CreateStructRequest create_struct_request_pb; *create_struct_request_pb.mutable_executor() = executor_pb_; - for (std::string_view id : ids_for_struct) { + for (absl::string_view id : ids_for_struct) { v0::CreateStructRequest::Element elem; elem.mutable_value_ref()->mutable_id()->append(id.data(), id.size()); create_struct_request_pb.mutable_element()->Add(std::move(elem)); @@ -152,13 +152,13 @@ class ExecutorServiceTest : public ::testing::Test { } v0::CreateStructRequest CreateNamedStructForIds( - const absl::Span ids_for_struct) { + const absl::Span ids_for_struct) { v0::CreateStructRequest create_struct_request_pb; *create_struct_request_pb.mutable_executor() = executor_pb_; // Assign an integer index as name internally. Names are dropped on the C++ // side, but a caller may supply them. int idx = 0; - for (const std::string_view& id : ids_for_struct) { + for (const absl::string_view& id : ids_for_struct) { v0::CreateStructRequest::Element elem; elem.mutable_value_ref()->mutable_id()->assign(id.data(), id.size()); elem.mutable_name()->assign(std::to_string(idx)); diff --git a/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.cc b/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.cc index 44dd5394db..19df548fb1 100644 --- a/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.cc +++ b/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.cc @@ -15,16 +15,15 @@ limitations under the License #include "tensorflow_federated/cc/core/impl/executors/federated_intrinsics.h" -#include - #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" namespace tensorflow_federated { absl::StatusOr FederatedIntrinsicFromUri( - const std::string_view uri) { + const absl::string_view uri) { if (uri == kFederatedMapAtClientsUri || uri == "federated_apply" || uri == "federated_map_all_equal") { return FederatedIntrinsic::MAP; diff --git a/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.h b/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.h index e4e07e1faf..c3e741c6a1 100644 --- a/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.h +++ b/tensorflow_federated/cc/core/impl/executors/federated_intrinsics.h @@ -16,19 +16,19 @@ limitations under the License #ifndef THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_FEDERATING_INTRINSICS_H_ #define THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_FEDERATING_INTRINSICS_H_ -#include - #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" namespace tensorflow_federated { -const std::string_view kFederatedMapAtClientsUri = "federated_map"; -const std::string_view kFederatedMapAtServerUri = "federated_apply"; -const std::string_view kFederatedEvalAtClientsUri = "federated_eval_at_clients"; -const std::string_view kFederatedZipAtClientsUri = "federated_zip_at_clients"; -const std::string_view kFederatedZipAtServerUri = "federated_zip_at_server"; -const std::string_view kFederatedAggregateUri = "federated_aggregate"; -const std::string_view kFederatedSelectUri = "federated_select"; +const absl::string_view kFederatedMapAtClientsUri = "federated_map"; +const absl::string_view kFederatedMapAtServerUri = "federated_apply"; +const absl::string_view kFederatedEvalAtClientsUri = + "federated_eval_at_clients"; +const absl::string_view kFederatedZipAtClientsUri = "federated_zip_at_clients"; +const absl::string_view kFederatedZipAtServerUri = "federated_zip_at_server"; +const absl::string_view kFederatedAggregateUri = "federated_aggregate"; +const absl::string_view kFederatedSelectUri = "federated_select"; enum class FederatedIntrinsic { MAP, @@ -44,7 +44,7 @@ enum class FederatedIntrinsic { }; absl::StatusOr FederatedIntrinsicFromUri( - const std::string_view uri); + const absl::string_view uri); } // namespace tensorflow_federated diff --git a/tensorflow_federated/cc/core/impl/executors/federating_executor.cc b/tensorflow_federated/cc/core/impl/executors/federating_executor.cc index cfd253e1d6..32d71c2a7b 100644 --- a/tensorflow_federated/cc/core/impl/executors/federating_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/federating_executor.cc @@ -19,7 +19,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "federated_language/proto/computation.pb.h" @@ -229,7 +229,7 @@ class ExecutorValue { inline ValueType type() const { return type_; } absl::Status CheckArgumentType(ValueType expected_type, - std::string_view argument_identifier) const { + absl::string_view argument_identifier) const { if (type() == expected_type) { return absl::OkStatus(); } else { @@ -250,7 +250,7 @@ class ExecutorValue { }; absl::Status CheckLenForUseAsArgument(const ExecutorValue& value, - std::string_view function_name, + absl::string_view function_name, size_t len) { TFF_TRY(value.CheckArgumentType(ExecutorValue::ValueType::STRUCTURE, function_name)); @@ -281,8 +281,8 @@ class FederatingExecutor : public ExecutorBase { std::shared_ptr client_child_; uint32_t num_clients_; - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "FederatingExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "FederatingExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/reference_resolving_executor.cc b/tensorflow_federated/cc/core/impl/executors/reference_resolving_executor.cc index a8d9a97886..083155446e 100644 --- a/tensorflow_federated/cc/core/impl/executors/reference_resolving_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/reference_resolving_executor.cc @@ -19,7 +19,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ limitations under the License #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "federated_language/proto/computation.pb.h" #include "tensorflow_federated/cc/core/impl/executors/executor.h" #include "tensorflow_federated/cc/core/impl/executors/status_macros.h" @@ -97,7 +97,7 @@ class Scope { // Otherwise, returns a `NotFound` error if the `name` is not present in any // ancestor scope. absl::StatusOr> Resolve( - std::string_view name) const; + absl::string_view name) const; // Returns a human readable string for debugging the current scope. // @@ -202,8 +202,8 @@ class ReferenceResolvingExecutor const std::shared_ptr& scope) const; protected: - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "ReferenceResolvingExecutor"; return kExecutorName; } @@ -313,7 +313,7 @@ absl::StatusOr> ScopedLambda::Call( } absl::StatusOr> Scope::Resolve( - std::string_view name) const { + absl::string_view name) const { if (binding_.has_value()) { if (std::get<0>(*binding_) == name) { return std::get<1>(*binding_); diff --git a/tensorflow_federated/cc/core/impl/executors/remote_executor.cc b/tensorflow_federated/cc/core/impl/executors/remote_executor.cc index 1e8fca8e16..3ebd1ac679 100644 --- a/tensorflow_federated/cc/core/impl/executors/remote_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/remote_executor.cc @@ -19,7 +19,6 @@ limitations under the License #include // NOLINT #include #include -#include #include #include @@ -27,6 +26,7 @@ limitations under the License #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "include/grpcpp/grpcpp.h" #include "include/grpcpp/support/status.h" @@ -93,8 +93,8 @@ class RemoteExecutor : public ExecutorBase { ~RemoteExecutor() override = default; - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "RemoteExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "RemoteExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/remote_executor_test.cc b/tensorflow_federated/cc/core/impl/executors/remote_executor_test.cc index f0f210f2b2..c1b36be708 100644 --- a/tensorflow_federated/cc/core/impl/executors/remote_executor_test.cc +++ b/tensorflow_federated/cc/core/impl/executors/remote_executor_test.cc @@ -19,7 +19,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ limitations under the License #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/notification.h" #include "absl/time/time.h" #include "include/grpcpp/channel.h" @@ -87,10 +87,10 @@ v0::CreateValueRequest CreateValueRequestForValue( } v0::CreateStructRequest CreateStructRequestForValues( - const std::vector& ref_names) { + const std::vector& ref_names) { v0::CreateStructRequest create_struct_request; create_struct_request.mutable_executor()->set_id(kExecutorId); - for (std::string_view ref_name : ref_names) { + for (absl::string_view ref_name : ref_names) { create_struct_request.add_element()->mutable_value_ref()->set_id( std::string(ref_name)); } diff --git a/tensorflow_federated/cc/core/impl/executors/sequence_executor.cc b/tensorflow_federated/cc/core/impl/executors/sequence_executor.cc index b3ed8a9e5f..3d31e379b5 100644 --- a/tensorflow_federated/cc/core/impl/executors/sequence_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/sequence_executor.cc @@ -21,7 +21,6 @@ limitations under the License #include // NOLINT #include #include -#include #include #include #include @@ -31,6 +30,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "federated_language/proto/computation.pb.h" @@ -322,7 +322,7 @@ class SequenceExecutorValue { } } absl::Status CheckTypeForArgument(ValueType expected_type, - std::string_view fn_name, + absl::string_view fn_name, std::optional position_in_struct) { if (type() != expected_type) { if (position_in_struct.has_value()) { @@ -361,7 +361,7 @@ class SequenceExecutorValue { }; absl::Status CheckLenForUseAsArgument(const SequenceExecutorValue& value, - std::string_view function_name, + absl::string_view function_name, size_t len) { if (value.type() != SequenceExecutorValue::ValueType::STRUCT) { return absl::InvalidArgumentError( @@ -387,7 +387,7 @@ class SequenceExecutor : public ExecutorBase { : target_executor_(target_executor) {} ~SequenceExecutor() override = default; - std::string_view ExecutorName() final { return "SequenceExecutor"; } + absl::string_view ExecutorName() final { return "SequenceExecutor"; } absl::StatusOr CreateExecutorValue( const v0::Value& value_pb) final { @@ -402,7 +402,7 @@ class SequenceExecutor : public ExecutorBase { } case v0::Value::kComputation: { if (value_pb.computation().has_intrinsic()) { - std::string_view intrinsic_uri = + absl::string_view intrinsic_uri = value_pb.computation().intrinsic().uri(); absl::StatusOr intrinsic_or_status = SequenceIntrinsicFromUri(intrinsic_uri); diff --git a/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.cc b/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.cc index 17af103788..bd4013cccd 100644 --- a/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.cc +++ b/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.cc @@ -15,16 +15,15 @@ limitations under the License #include "tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.h" -#include - #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" namespace tensorflow_federated { absl::StatusOr SequenceIntrinsicFromUri( - const std::string_view uri) { + const absl::string_view uri) { if (uri == kSequenceMapUri) { return SequenceIntrinsic::MAP; } else if (uri == kSequenceReduceUri) { @@ -34,7 +33,7 @@ absl::StatusOr SequenceIntrinsicFromUri( absl::StrCat("Unsupported sequence intrinsic URI: ", uri)); } } -std::string_view SequenceIntrinsicToUri(const SequenceIntrinsic& intrinsic) { +absl::string_view SequenceIntrinsicToUri(const SequenceIntrinsic& intrinsic) { switch (intrinsic) { case SequenceIntrinsic::MAP: return kSequenceMapUri; diff --git a/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.h b/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.h index c433025cfd..5fdb77f37e 100644 --- a/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.h +++ b/tensorflow_federated/cc/core/impl/executors/sequence_intrinsics.h @@ -16,13 +16,12 @@ limitations under the License #ifndef THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_SEQUENCE_INTRINSICS_H_ #define THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_SEQUENCE_INTRINSICS_H_ -#include - #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" namespace tensorflow_federated { -const std::string_view kSequenceReduceUri = "sequence_reduce"; -const std::string_view kSequenceMapUri = "sequence_map"; +const absl::string_view kSequenceReduceUri = "sequence_reduce"; +const absl::string_view kSequenceMapUri = "sequence_map"; enum class SequenceIntrinsic { MAP, @@ -30,9 +29,9 @@ enum class SequenceIntrinsic { }; absl::StatusOr SequenceIntrinsicFromUri( - const std::string_view uri); + const absl::string_view uri); -std::string_view SequenceIntrinsicToUri(const SequenceIntrinsic& intrinsic); +absl::string_view SequenceIntrinsicToUri(const SequenceIntrinsic& intrinsic); } // namespace tensorflow_federated diff --git a/tensorflow_federated/cc/core/impl/executors/session_provider.cc b/tensorflow_federated/cc/core/impl/executors/session_provider.cc index 73701006bb..cd143d6313 100644 --- a/tensorflow_federated/cc/core/impl/executors/session_provider.cc +++ b/tensorflow_federated/cc/core/impl/executors/session_provider.cc @@ -19,7 +19,6 @@ limitations under the License #include #include #include -#include #include #include @@ -32,6 +31,7 @@ limitations under the License #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/device_factory.h" @@ -107,8 +107,8 @@ const AcceleratorDevices& GetAcceleratorDevices() { } LOG_FIRST_N(INFO, 1) << "Found devices: [" << absl::StrJoin(devices, ",") << "]"; - for (std::string_view device : devices) { - std::vector device_parts = absl::StrSplit(device, ':'); + for (absl::string_view device : devices) { + std::vector device_parts = absl::StrSplit(device, ':'); if (device_parts.size() != 3) { LOG(ERROR) << "Unknown device name format: [" << device << "]"; continue; @@ -131,7 +131,7 @@ const AcceleratorDevices& GetAcceleratorDevices() { return *accelerator_devices; } -void SetDevice(std::string_view device, tensorflow::GraphDef* graph_def, +void SetDevice(absl::string_view device, tensorflow::GraphDef* graph_def, const char* device_type) { for (tensorflow::NodeDef& node_pb : *graph_def->mutable_node()) { // Annotating ReduceDataset with _xla_compile_device_type will denote to @@ -275,7 +275,7 @@ SessionProvider::CreateSession(const int16_t session_id) { auto status = session->Create(graph_def); if (!status.ok()) { LOG(ERROR) << status; - for (std::string_view line : + for (absl::string_view line : absl::StrSplit(graph_def.Utf8DebugString(), '\n')) { LOG(ERROR) << line; } diff --git a/tensorflow_federated/cc/core/impl/executors/status_macros.h b/tensorflow_federated/cc/core/impl/executors/status_macros.h index 9b5dbbb69e..ba79cd56fb 100644 --- a/tensorflow_federated/cc/core/impl/executors/status_macros.h +++ b/tensorflow_federated/cc/core/impl/executors/status_macros.h @@ -31,7 +31,7 @@ inline absl::Status __get_status(absl::Status&& status) { // Internal-only helper for TFF_TRY // Appends `suffix` to the message of the original status. inline absl::Status __get_status(absl::Status&& status, - const std::string_view& suffix) { + const absl::string_view& suffix) { return absl::Status(status.code(), absl::StrCat(status.message(), " ", suffix)); } @@ -58,7 +58,7 @@ inline T __void_or_result(absl::StatusOr&& res) { // an expression of type `T` (in the case of `absl::StatusOr`) or `void` // (in the case of `absl::Status`). // -// The macro accepts an optional last argument for a `const std::string_view&` +// The macro accepts an optional last argument for a `const absl::string_view&` // to append to the error message. #define TFF_TRY(expr, ...) \ ({ \ diff --git a/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor.cc b/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor.cc index fcdc59dc85..29627ee07b 100644 --- a/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor.cc @@ -22,7 +22,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -343,8 +342,9 @@ class StreamingRemoteExecutor : public ExecutorBase { ~StreamingRemoteExecutor() override = default; - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "StreamingRemoteExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = + "StreamingRemoteExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor_test.cc b/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor_test.cc index 436cb80c1f..d09f03a225 100644 --- a/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor_test.cc +++ b/tensorflow_federated/cc/core/impl/executors/streaming_remote_executor_test.cc @@ -20,7 +20,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ limitations under the License #include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "absl/synchronization/notification.h" #include "absl/time/time.h" @@ -120,10 +120,10 @@ v0::CreateValueRequest CreateValueRequestForValue( } v0::CreateStructRequest CreateStructRequestForValues( - const std::vector& ref_names) { + const std::vector& ref_names) { v0::CreateStructRequest create_struct_request; create_struct_request.mutable_executor()->set_id(kExecutorId); - for (std::string_view ref_name : ref_names) { + for (absl::string_view ref_name : ref_names) { create_struct_request.add_element()->mutable_value_ref()->set_id( std::string(ref_name)); } @@ -873,7 +873,7 @@ struct FederatedStructTestCase { std::function)> FederatedV; std::function FederatedZipIntrinsicV; - std::string_view placement_uri; + absl::string_view placement_uri; bool all_equal; }; @@ -981,7 +981,7 @@ TEST_P(StreamingRemoteExecutorFederatedStructsTest, RoundTripFederatedStruct) { // Add expectations for the sequence of calls that result from a // Materialize. { - std::string_view intrinsic_name = + absl::string_view intrinsic_name = (test_case.placement_uri == kServerUri ? kFederatedMapAtServerUri : kFederatedMapAtClientsUri); v0::CreateValueRequest create_map_comp_request; @@ -1183,7 +1183,7 @@ TEST_P(StreamingRemoteExecutorFederatedStructsTest, // Add expectations for the sequence of calls that result from a // CreateValue. { - absl::flat_hash_map + absl::flat_hash_map struct_ref_by_struct_elem_ref = { {"inner_federated_struct", "federated_elem"}, {"outer_federated_struct", "zipped_inner_federated_struct"}, @@ -1199,8 +1199,8 @@ TEST_P(StreamingRemoteExecutorFederatedStructsTest, // We expect two create struct, and two zip calls, as the executor // traverse the nested structure. for (const auto& item : struct_ref_by_struct_elem_ref) { - std::string_view struct_ref = item.first; - std::string_view elem_ref = item.second; + absl::string_view struct_ref = item.first; + absl::string_view elem_ref = item.second; EXPECT_CALL( *mock_executor_service_, CreateStruct( @@ -1270,7 +1270,7 @@ TEST_P(StreamingRemoteExecutorFederatedStructsTest, // Add expectations for the sequence of calls that result from a // Materialize. { - std::string_view intrinsic_name = + absl::string_view intrinsic_name = (test_case.placement_uri == kServerUri ? kFederatedMapAtServerUri : kFederatedMapAtClientsUri); v0::CreateValueRequest create_map_comp_request; diff --git a/tensorflow_federated/cc/core/impl/executors/tensorflow_executor.cc b/tensorflow_federated/cc/core/impl/executors/tensorflow_executor.cc index 1ac8fe84df..366d7acdc5 100644 --- a/tensorflow_federated/cc/core/impl/executors/tensorflow_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/tensorflow_executor.cc @@ -21,7 +21,6 @@ limitations under the License #include #include #include -#include #include // NOLINT #include #include @@ -36,6 +35,7 @@ limitations under the License #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "tensorflow/core/data/standalone.h" @@ -79,9 +79,9 @@ constexpr char kDatasetToGraphOp[] = "DatasetToGraphV2"; constexpr char kDatasetFromGraphOp[] = "DatasetFromGraph"; constexpr char kArgsIntoSequenceUri[] = "args_into_sequence"; -std::string GetNodeName(std::string_view tensor_name) { - std::string_view::size_type pos = tensor_name.find(':'); - if (pos == std::string_view::npos) { +std::string GetNodeName(absl::string_view tensor_name) { + absl::string_view::size_type pos = tensor_name.find(':'); + if (pos == absl::string_view::npos) { return std::string(tensor_name); } else { return std::string(tensor_name.substr(0, pos)); @@ -102,8 +102,8 @@ struct NamesForBindingRewrite { // Computes the names for the nodes and tensors we will add to the graph when // wrapping sequence bindings in dataset serialization ops. NamesForBindingRewrite GetVariantTensorNodeNameAndReplacement( - std::string_view variant_tensor_name, std::string_view replace_node_suffix, - std::string_view node_prefix) { + absl::string_view variant_tensor_name, + absl::string_view replace_node_suffix, absl::string_view node_prefix) { NamesForBindingRewrite names; names.variant_node_name = GetNodeName(variant_tensor_name); names.graph_def_node_name = absl::StrCat( @@ -172,7 +172,7 @@ void AddDatasetToGraphOp(tensorflow::GraphDef& graphdef_pb, absl::Status AddDeserializationOpsForParameters( tensorflow::GraphDef& graphdef_pb, federated_language::TensorFlow::Binding& binding, - std::string_view prefix = "root") { + absl::string_view prefix = "root") { switch (binding.binding_case()) { case federated_language::TensorFlow::Binding::kSequence: { // Get a copy of the name of the placeholder we're operating on. We're @@ -269,7 +269,7 @@ absl::Status AddDeserializationOpsForParameters( absl::Status AddSerializationOpsForResults( tensorflow::GraphDef& graphdef_pb, federated_language::TensorFlow::Binding& binding, - std::string_view prefix = "root") { + absl::string_view prefix = "root") { switch (binding.binding_case()) { case federated_language::TensorFlow::Binding::kSequence: { if (binding.sequence().binding_case() == @@ -422,7 +422,7 @@ class SequenceTensor { enum class Intrinsic { kArgsIntoSequence }; -absl::StatusOr IntrinsicFromUri(std::string_view uri) { +absl::StatusOr IntrinsicFromUri(absl::string_view uri) { if (uri == kArgsIntoSequenceUri) { return Intrinsic::kArgsIntoSequence; } else { @@ -431,7 +431,7 @@ absl::StatusOr IntrinsicFromUri(std::string_view uri) { } } -std::string_view IntrinsicToUri(Intrinsic intrinsic) { +absl::string_view IntrinsicToUri(Intrinsic intrinsic) { switch (intrinsic) { case Intrinsic::kArgsIntoSequence: { return kArgsIntoSequenceUri; @@ -664,7 +664,7 @@ class ExecutorValue { value_; static absl::Status BindKindMismatch( - const std::string_view value_kind, + const absl::string_view value_kind, const federated_language::TensorFlow::Binding& shape) { return absl::InvalidArgumentError( absl::StrCat("Attempted to bind ", value_kind, @@ -956,8 +956,8 @@ class TensorFlowExecutor : public ExecutorBase { } protected: - std::string_view ExecutorName() final { - static constexpr std::string_view kExecutorName = "TensorFlowExecutor"; + absl::string_view ExecutorName() final { + static constexpr absl::string_view kExecutorName = "TensorFlowExecutor"; return kExecutorName; } diff --git a/tensorflow_federated/cc/core/impl/executors/tensorflow_utils_test.cc b/tensorflow_federated/cc/core/impl/executors/tensorflow_utils_test.cc index 5b13a6d61c..833b808189 100644 --- a/tensorflow_federated/cc/core/impl/executors/tensorflow_utils_test.cc +++ b/tensorflow_federated/cc/core/impl/executors/tensorflow_utils_test.cc @@ -18,13 +18,13 @@ limitations under the License #include #include #include -#include #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "third_party/eigen3/Eigen/Core" #include "federated_language/proto/array.pb.h" #include "federated_language/proto/computation.pb.h" @@ -453,7 +453,7 @@ TEST_P(ArrayContentFromTensorTest, TestReturnsTensor) { testing::EqualsProto(test_case.expected_array_pb)); } -#define CONTENT(s) std::string_view(s, sizeof(s) - 1) +#define CONTENT(s) absl::string_view(s, sizeof(s) - 1) INSTANTIATE_TEST_SUITE_P( ArrayContentFromTensorTestSuiteInstantiation, ArrayContentFromTensorTest, @@ -617,7 +617,7 @@ TEST_P(TensorFromArrayContentTest, TestReturnsTensor) { tensorflow::test::ExpectEqual(actual_tensor, test_case.expected_tensor); } -#define CONTENT(s) std::string_view(s, sizeof(s) - 1) +#define CONTENT(s) absl::string_view(s, sizeof(s) - 1) INSTANTIATE_TEST_SUITE_P( TensorFromArrayContentTestSuiteInstantiation, TensorFromArrayContentTest, diff --git a/tensorflow_federated/cc/core/impl/executors/threading.cc b/tensorflow_federated/cc/core/impl/executors/threading.cc index c14d2f4ff5..1b2f6319ae 100644 --- a/tensorflow_federated/cc/core/impl/executors/threading.cc +++ b/tensorflow_federated/cc/core/impl/executors/threading.cc @@ -17,18 +17,18 @@ limitations under the License #include #include -#include #include // NOLINT #include #include "absl/base/thread_annotations.h" #include "absl/log/log.h" #include "absl/status/status.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" namespace tensorflow_federated { -ThreadPool::ThreadPool(int32_t num_threads, std::string_view name) +ThreadPool::ThreadPool(int32_t num_threads, absl::string_view name) : pool_name_(name) { if (num_threads < 1) { LOG(QFATAL) << "num_threads must be positive"; diff --git a/tensorflow_federated/cc/core/impl/executors/threading.h b/tensorflow_federated/cc/core/impl/executors/threading.h index f7efc6bfa2..28e81d45f6 100644 --- a/tensorflow_federated/cc/core/impl/executors/threading.h +++ b/tensorflow_federated/cc/core/impl/executors/threading.h @@ -23,7 +23,6 @@ limitations under the License #include // NOLINT #include #include -#include #include // NOLINT #include #include @@ -32,6 +31,7 @@ limitations under the License #include "absl/base/thread_annotations.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" #include "absl/utility/utility.h" @@ -48,7 +48,7 @@ namespace tensorflow_federated { // in such cases. class ThreadPool { public: - ThreadPool(int32_t num_threads, std::string_view name); + ThreadPool(int32_t num_threads, absl::string_view name); ~ThreadPool(); // Restrict copying and moving. diff --git a/tensorflow_federated/cc/core/impl/executors/value_test_utils.h b/tensorflow_federated/cc/core/impl/executors/value_test_utils.h index 35fcc12531..e87aa2c1c5 100644 --- a/tensorflow_federated/cc/core/impl/executors/value_test_utils.h +++ b/tensorflow_federated/cc/core/impl/executors/value_test_utils.h @@ -23,7 +23,6 @@ limitations under the License #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "federated_language/proto/array.pb.h" #include "federated_language/proto/computation.pb.h" @@ -53,7 +53,7 @@ namespace tensorflow_federated { namespace testing { inline v0::Value IntrinsicV( - std::string_view uri, + absl::string_view uri, std::optional type_spec = std::nullopt) { v0::Value value_proto; federated_language::Computation* computation_pb = @@ -278,7 +278,7 @@ inline federated_language::Computation StructComputation( } inline federated_language::Computation LambdaComputation( - std::optional parameter_name, + std::optional parameter_name, federated_language::Computation result_computation_value) { federated_language::Computation computation_pb; federated_language::Lambda* lambda_pb = computation_pb.mutable_lambda(); @@ -306,7 +306,7 @@ inline federated_language::Computation BlockComputation( } inline federated_language::Computation ReferenceComputation( - std::string_view reference_name) { + absl::string_view reference_name) { federated_language::Computation computation_pb; computation_pb.mutable_reference()->mutable_name()->assign( reference_name.data(), reference_name.size()); @@ -314,21 +314,21 @@ inline federated_language::Computation ReferenceComputation( } inline federated_language::Computation IntrinsicComputation( - std::string_view uri) { + absl::string_view uri) { federated_language::Computation computation_pb; computation_pb.mutable_intrinsic()->mutable_uri()->assign(uri.data(), uri.size()); return computation_pb; } -inline federated_language::Computation DataComputation(std::string_view uri) { +inline federated_language::Computation DataComputation(absl::string_view uri) { federated_language::Computation computation_pb; computation_pb.mutable_data()->mutable_uri()->assign(uri.data(), uri.size()); return computation_pb; } inline federated_language::Computation PlacementComputation( - std::string_view uri) { + absl::string_view uri) { federated_language::Computation computation_pb; computation_pb.mutable_placement()->mutable_uri()->assign(uri.data(), uri.size()); diff --git a/tensorflow_federated/cc/core/impl/executors/value_validation.cc b/tensorflow_federated/cc/core/impl/executors/value_validation.cc index f1300742fb..fe62d5f38b 100644 --- a/tensorflow_federated/cc/core/impl/executors/value_validation.cc +++ b/tensorflow_federated/cc/core/impl/executors/value_validation.cc @@ -16,11 +16,11 @@ limitations under the License #include "tensorflow_federated/cc/core/impl/executors/value_validation.h" #include -#include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "federated_language/proto/computation.pb.h" #include "tensorflow_federated/cc/core/impl/executors/cardinalities.h" #include "tensorflow_federated/proto/v0/executor.pb.h" @@ -29,7 +29,8 @@ namespace tensorflow_federated { absl::StatusOr ValidateFederated( uint32_t num_clients, const v0::Value_Federated& federated) { - const std::string_view placement = federated.type().placement().value().uri(); + const absl::string_view placement = + federated.type().placement().value().uri(); bool all_equal = federated.type().all_equal(); if (all_equal) { if (federated.value_size() != 1) { diff --git a/tensorflow_federated/cc/core/impl/executors/xla_executor.cc b/tensorflow_federated/cc/core/impl/executors/xla_executor.cc index dccc9a46c6..175999340e 100644 --- a/tensorflow_federated/cc/core/impl/executors/xla_executor.cc +++ b/tensorflow_federated/cc/core/impl/executors/xla_executor.cc @@ -19,7 +19,6 @@ limitations under the License #include // NOLINT #include #include -#include #include #include #include @@ -30,6 +29,7 @@ limitations under the License #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "federated_language/proto/computation.pb.h" #include "tensorflow/compiler/tf2xla/literal_util.h" @@ -374,7 +374,7 @@ class XLAExecutor : public ExecutorBase { public: explicit XLAExecutor(xla::Client* xla_client) : xla_client_(xla_client) {} - std::string_view ExecutorName() final { return "XLAExecutor"; } + absl::string_view ExecutorName() final { return "XLAExecutor"; } absl::StatusOr CreateExecutorValue( const v0::Value& value_pb) final { return ThreadRun([value_pb, this_shared = shared_from_this()]() { @@ -706,7 +706,7 @@ class XLAExecutor : public ExecutorBase { } }; -absl::StatusOr GetXLAClient(std::string_view platform_name) { +absl::StatusOr GetXLAClient(absl::string_view platform_name) { absl::StatusOr platform = xla::se::PlatformManager::PlatformWithName(platform_name); if (!platform.ok()) { @@ -731,7 +731,7 @@ absl::StatusOr GetXLAClient(std::string_view platform_name) { } // namespace absl::StatusOr> CreateXLAExecutor( - std::string_view platform_name) { + absl::string_view platform_name) { LOG(INFO) << "Creating XLAExecutor for platform: " << platform_name; xla::Client* client = TFF_TRY(GetXLAClient(platform_name)); return std::make_shared(client); diff --git a/tensorflow_federated/cc/core/impl/executors/xla_executor.h b/tensorflow_federated/cc/core/impl/executors/xla_executor.h index 7db10b424e..ee2c5df0ea 100644 --- a/tensorflow_federated/cc/core/impl/executors/xla_executor.h +++ b/tensorflow_federated/cc/core/impl/executors/xla_executor.h @@ -17,9 +17,9 @@ limitations under the License #define THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_XLA_EXECUTOR_H_ #include -#include #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "tensorflow_federated/cc/core/impl/executors/executor.h" namespace tensorflow_federated { @@ -31,7 +31,7 @@ namespace tensorflow_federated { // e.g. by including appropriate build dependencies. This string is // case-insensitive. The default value of "Host" is guaranteed to be valid. absl::StatusOr> CreateXLAExecutor( - std::string_view platform_name = "Host"); + absl::string_view platform_name = "Host"); } // namespace tensorflow_federated