Skip to content

Commit

Permalink
Replace std::string_view with absl::string_view
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 704489605
  • Loading branch information
TensorFlow Federated Team authored and copybara-github committed Dec 10, 2024
1 parent 9c5b3fe commit e8920e2
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 126 deletions.
26 changes: 26 additions & 0 deletions tensorflow_federated/cc/core/impl/executors/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)

Expand All @@ -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",
Expand Down Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
],
Expand All @@ -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",
],
Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
Expand Down Expand Up @@ -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",
],
Expand All @@ -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",
Expand Down Expand Up @@ -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",
],
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
],
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
],
)
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ limitations under the License
#include <cstdint>
#include <initializer_list>
#include <string>
#include <string_view>

#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"
Expand Down Expand Up @@ -199,7 +199,7 @@ inline absl::StatusOr<federated_language::Array> CreateArray(

inline absl::StatusOr<federated_language::Array> 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);
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_federated/cc/core/impl/executors/cardinalities.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License
#define THIRD_PARTY_TENSORFLOW_FEDERATED_CC_CORE_IMPL_EXECUTORS_CARDINALITIES_H_

#include <string>
#include <string_view>

#include "absl/container/btree_map.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"

namespace tensorflow_federated {

Expand All @@ -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<std::string, int>;
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<int> NumClientsFromCardinalities(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ limitations under the License
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <thread> // NOLINT
#include <tuple>
#include <utility>
Expand All @@ -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"
Expand Down Expand Up @@ -241,7 +241,7 @@ class ExecutorValue {
return std::get<TypedFederatedIntrinsic>(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(
Expand All @@ -259,7 +259,7 @@ class ExecutorValue {
// Fetches an unplaced functional value as a proto, ensuring that no
// underlying `Materialize` call occurs.
absl::StatusOr<std::shared_ptr<v0::Value>> 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, ",
Expand Down Expand Up @@ -383,8 +383,8 @@ class ComposingExecutor : public ExecutorBase<ValueFuture> {
}

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;
}

Expand Down
6 changes: 3 additions & 3 deletions tensorflow_federated/cc/core/impl/executors/data_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ limitations under the License
#include <future> // NOLINT
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>

#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"
Expand All @@ -44,8 +44,8 @@ class DataExecutor : public ExecutorBase<ValueFuture> {
: 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ limitations under the License
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#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"
Expand Down Expand Up @@ -53,7 +53,7 @@ std::string InputTensorName(size_t i, size_t element_index) {
}

template <typename T>
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,
Expand Down Expand Up @@ -188,7 +188,7 @@ absl::StatusOr<GraphWithOutput> 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)
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_federated/cc/core/impl/executors/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
Expand All @@ -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"
Expand Down Expand Up @@ -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`.
Expand All @@ -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<ExecutorValue> CreateExecutorValue(
const v0::Value& value_pb) = 0;
virtual absl::StatusOr<ExecutorValue> CreateCall(
Expand Down
Loading

0 comments on commit e8920e2

Please sign in to comment.