From 14723aa20ed854ce02edeeb08f3a95519048e4e3 Mon Sep 17 00:00:00 2001 From: Zac Mustin Date: Mon, 2 Feb 2026 14:42:25 -0800 Subject: [PATCH] Update TSL `FileExists` to use `absl::string_view`. Users passing `std::string` will not need updating, since `string_view` will perform an implicit conversion. PiperOrigin-RevId: 864529553 --- tsl/platform/BUILD | 4 +++- tsl/platform/null_file_system.h | 4 +++- tsl/platform/retrying_file_system.h | 4 ++-- tsl/platform/retrying_file_system_test.cc | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tsl/platform/BUILD b/tsl/platform/BUILD index d03395f32..da5d5c1f1 100644 --- a/tsl/platform/BUILD +++ b/tsl/platform/BUILD @@ -1215,6 +1215,8 @@ cc_library( name = "null_file_system", hdrs = ["null_file_system.h"], deps = [ + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings:string_view", "@xla//xla/tsl/platform:env", ], ) @@ -1441,6 +1443,7 @@ cc_library( deps = [ ":random", ":retrying_utils", + "@com_google_absl//absl/strings:string_view", "@xla//xla/tsl/platform:env", "@xla//xla/tsl/platform:errors", "@xla//xla/tsl/platform:status", @@ -1456,7 +1459,6 @@ tsl_cc_test( ":str_util", "@com_google_googletest//:gtest_main", "@xla//xla/tsl/lib/core:status_test_util", - "@xla//xla/tsl/platform:env_impl", "@xla//xla/tsl/platform:test", ], ) diff --git a/tsl/platform/null_file_system.h b/tsl/platform/null_file_system.h index 8c8829858..0eea480a6 100644 --- a/tsl/platform/null_file_system.h +++ b/tsl/platform/null_file_system.h @@ -20,6 +20,8 @@ limitations under the License. #include #include +#include "absl/status/status.h" +#include "absl/strings/string_view.h" #include "xla/tsl/platform/env.h" #include "xla/tsl/platform/file_system.h" #include "xla/tsl/platform/file_system_helper.h" @@ -62,7 +64,7 @@ class NullFileSystem : public FileSystem { "NewReadOnlyMemoryRegionFromFile unimplemented"); } - absl::Status FileExists(const string& fname, + absl::Status FileExists(absl::string_view fname, TransactionToken* token) override { return errors::Unimplemented("FileExists unimplemented"); } diff --git a/tsl/platform/retrying_file_system.h b/tsl/platform/retrying_file_system.h index 9bf86114d..144d50317 100644 --- a/tsl/platform/retrying_file_system.h +++ b/tsl/platform/retrying_file_system.h @@ -18,9 +18,9 @@ limitations under the License. #include #include -#include #include +#include "absl/strings/string_view.h" #include "xla/tsl/platform/env.h" #include "xla/tsl/platform/errors.h" #include "xla/tsl/platform/file_system.h" @@ -56,7 +56,7 @@ class RetryingFileSystem : public FileSystem { const string& filename, TransactionToken* token, std::unique_ptr* result) override; - absl::Status FileExists(const string& fname, + absl::Status FileExists(absl::string_view fname, TransactionToken* token) override { return RetryingUtils::CallWithRetries( [this, &fname, token]() { diff --git a/tsl/platform/retrying_file_system_test.cc b/tsl/platform/retrying_file_system_test.cc index d60a34445..569f24531 100644 --- a/tsl/platform/retrying_file_system_test.cc +++ b/tsl/platform/retrying_file_system_test.cc @@ -127,7 +127,7 @@ class MockFileSystem : public FileSystem { return calls_.ConsumeNextCall("NewReadOnlyMemoryRegionFromFile"); } - absl::Status FileExists(const string& fname, + absl::Status FileExists(absl::string_view fname, TransactionToken* token) override { return calls_.ConsumeNextCall("FileExists"); }