From e4f5975c426af236ce2b23866f86ee11eabd7652 Mon Sep 17 00:00:00 2001 From: David Dunleavy Date: Fri, 20 Feb 2026 13:47:26 -0800 Subject: [PATCH] Remove `tsl/platform/types.h` includes from `tsl/platform/path` No longer needed and severs a dependency on CUDA internally Also fixup unnecessary/missing headers and targets where needed PiperOrigin-RevId: 873058789 --- tsl/platform/BUILD | 12 +++------- tsl/platform/cuda_root_path.h | 1 + tsl/platform/fingerprint.h | 1 - tsl/platform/numbers.cc | 3 +-- tsl/platform/numbers.h | 3 +-- tsl/platform/path.cc | 43 +++++++++++++++++++---------------- tsl/platform/path.h | 3 ++- tsl/platform/str_util.cc | 17 +++++++------- tsl/platform/str_util.h | 24 ++++++++++--------- tsl/platform/strcat.h | 1 - 10 files changed, 53 insertions(+), 55 deletions(-) diff --git a/tsl/platform/BUILD b/tsl/platform/BUILD index 112b740de..37ccb6525 100644 --- a/tsl/platform/BUILD +++ b/tsl/platform/BUILD @@ -161,13 +161,10 @@ cc_library( hdrs = ["numbers.h"], deps = [ ":stringpiece", - ":stringprintf", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@xla//xla/tsl/platform:logging", - "@xla//xla/tsl/platform:macros", - "@xla//xla/tsl/platform:types", ], ) @@ -177,13 +174,15 @@ cc_library( hdrs = ["path.h"], deps = [ ":mutex", + ":platform", ":scanner", ":str_util", ":strcat", ":stringpiece", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/strings:string_view", + "@com_google_absl//absl/types:span", "@xla//xla/tsl/platform:logging", - "@xla//xla/tsl/platform:types", ], alwayslink = True, ) @@ -770,7 +769,6 @@ cc_library( "@com_google_absl//absl/strings", "@xla//xla/tsl/platform:logging", "@xla//xla/tsl/platform:macros", - "@xla//xla/tsl/platform:types", ], ) @@ -781,11 +779,8 @@ cc_library( ":numbers", ":stringpiece", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/strings", - "@xla//xla/tsl/platform:logging", "@xla//xla/tsl/platform:macros", - "@xla//xla/tsl/platform:types", ], ) @@ -1017,7 +1012,6 @@ cc_library( deps = [ ":platform", ":stringpiece", - "@xla//xla/tsl/platform:types", ] + tf_fingerprint_deps(), ) diff --git a/tsl/platform/cuda_root_path.h b/tsl/platform/cuda_root_path.h index 65a9ca5a7..3b617e0f4 100644 --- a/tsl/platform/cuda_root_path.h +++ b/tsl/platform/cuda_root_path.h @@ -16,6 +16,7 @@ limitations under the License. #ifndef TENSORFLOW_TSL_PLATFORM_CUDA_ROOT_PATH_H_ #define TENSORFLOW_TSL_PLATFORM_CUDA_ROOT_PATH_H_ +#include #include #include diff --git a/tsl/platform/fingerprint.h b/tsl/platform/fingerprint.h index 9f25d7cdf..47c494085 100644 --- a/tsl/platform/fingerprint.h +++ b/tsl/platform/fingerprint.h @@ -20,7 +20,6 @@ limitations under the License. #include #include -#include "xla/tsl/platform/types.h" #include "tsl/platform/platform.h" #include "tsl/platform/stringpiece.h" diff --git a/tsl/platform/numbers.cc b/tsl/platform/numbers.cc index 708de7097..99fc4c457 100644 --- a/tsl/platform/numbers.cc +++ b/tsl/platform/numbers.cc @@ -29,7 +29,6 @@ limitations under the License. #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "xla/tsl/platform/logging.h" -#include "xla/tsl/platform/types.h" namespace tsl { @@ -177,7 +176,7 @@ strings_internal::AlphaNumBuffer LegacyPrecision(float f) { return result; } -std::string FpToString(Fprint fp) { +std::string FpToString(uint64_t fp) { return absl::StrCat(absl::Hex(fp, absl::kZeroPad16)); } diff --git a/tsl/platform/numbers.h b/tsl/platform/numbers.h index 43b4ac864..34ba2a629 100644 --- a/tsl/platform/numbers.h +++ b/tsl/platform/numbers.h @@ -25,7 +25,6 @@ limitations under the License. #include "absl/base/macros.h" #include "absl/strings/numbers.h" #include "absl/strings/string_view.h" -#include "xla/tsl/platform/types.h" #include "tsl/platform/stringpiece.h" namespace tsl { @@ -76,7 +75,7 @@ strings_internal::AlphaNumBuffer LegacyPrecision(float f); strings_internal::AlphaNumBuffer LegacyPrecision(double d); // Convert a 64-bit fingerprint value to an ASCII representation. -std::string FpToString(Fprint fp); +std::string FpToString(uint64_t fp); // Attempt to parse a `uint64_t` in the form encoded by // `absl::StrCat(absl::Hex(*result))`. If successful, stores the value in diff --git a/tsl/platform/path.cc b/tsl/platform/path.cc index 65c1405a0..b64d9b7ec 100644 --- a/tsl/platform/path.cc +++ b/tsl/platform/path.cc @@ -28,12 +28,14 @@ limitations under the License. #include #endif +#include #include #include #include "absl/algorithm/container.h" +#include "absl/strings/string_view.h" +#include "absl/types/span.h" #include "xla/tsl/platform/logging.h" -#include "xla/tsl/platform/types.h" #include "tsl/platform/mutex.h" #include "tsl/platform/scanner.h" #include "tsl/platform/str_util.h" @@ -48,14 +50,14 @@ namespace { const char kPathSep[] = "/"; } // namespace -string JoinPathImpl(std::initializer_list paths) { - string result; +std::string JoinPathImpl(std::initializer_list paths) { + std::string result; for (absl::string_view path : paths) { if (path.empty()) continue; if (result.empty()) { - result = string(path); + result = std::string(path); continue; } @@ -138,10 +140,10 @@ absl::string_view BasenamePrefix(absl::string_view path) { return internal::SplitBasename(path).first; } -string CleanPath(absl::string_view unclean_path) { - string path(unclean_path); +std::string CleanPath(absl::string_view unclean_path) { + std::string path(unclean_path); const char* src = path.c_str(); - string::iterator dst = path.begin(); + std::string::iterator dst = path.begin(); // Check for absolute path and determine initial backtrack limit. const bool is_absolute_path = *src == '/'; @@ -149,7 +151,7 @@ string CleanPath(absl::string_view unclean_path) { *dst++ = *src++; while (*src == '/') ++src; } - string::const_iterator backtrack_limit = dst; + std::string::const_iterator backtrack_limit = dst; // Process all parts while (*src) { @@ -205,7 +207,7 @@ string CleanPath(absl::string_view unclean_path) { } // Calculate and check the length of the cleaned path. - string::difference_type path_length = dst - path.begin(); + std::string::difference_type path_length = dst - path.begin(); if (path_length != 0) { // Remove trailing '/' except if it is root path ("/" ==> path_length := 1) if (path_length > 1 && path[path_length - 1] == '/') { @@ -251,10 +253,10 @@ void ParseURI(absl::string_view uri, absl::string_view* scheme, *path = uri; } -string CreateURI(absl::string_view scheme, absl::string_view host, - absl::string_view path) { +std::string CreateURI(absl::string_view scheme, absl::string_view host, + absl::string_view path) { if (scheme.empty()) { - return string(path); + return std::string(path); } return absl::StrCat(scheme, "://", host, path); } @@ -267,10 +269,11 @@ int64_t UniqueId() { return ++id; } -string CommonPathPrefix(absl::Span paths) { +std::string CommonPathPrefix(absl::Span paths) { if (paths.empty()) return ""; size_t min_filename_size = - absl::c_min_element(paths, [](const string& a, const string& b) { + absl::c_min_element(paths, [](const std::string& a, + const std::string& b) { return a.size() < b.size(); })->size(); if (min_filename_size == 0) return ""; @@ -296,7 +299,7 @@ string CommonPathPrefix(absl::Span paths) { : std::string(absl::string_view(paths[0]).substr(0, rpos + 1)); } -string GetTempFilename(const string& extension) { +std::string GetTempFilename(const std::string& extension) { #if defined(__ANDROID__) LOG(FATAL) << "GetTempFilename is not implemented in this platform."; #elif defined(PLATFORM_WINDOWS) @@ -313,7 +316,7 @@ string GetTempFilename(const string& extension) { LOG(FATAL) << "Cannot get a temporary file in: " << temp_dir; } - string full_tmp_file_name(temp_file_name); + std::string full_tmp_file_name(temp_file_name); full_tmp_file_name.append(extension); return full_tmp_file_name; #else @@ -327,7 +330,7 @@ string GetTempFilename(const string& extension) { // UniqueId is added here because mkstemps is not as thread safe as it // looks. https://github.com/tensorflow/tensorflow/issues/5804 shows // the problem. - string tmp_filepath; + std::string tmp_filepath; int fd; if (extension.length()) { tmp_filepath = @@ -365,7 +368,7 @@ bool StartsWithSegment(absl::string_view path, absl::string_view segment) { } } // namespace -bool GetTestWorkspaceDir(string* dir) { +bool GetTestWorkspaceDir(std::string* dir) { const char* srcdir = getenv("TEST_SRCDIR"); if (srcdir == nullptr) { return false; @@ -380,7 +383,7 @@ bool GetTestWorkspaceDir(string* dir) { return true; } -bool GetTestUndeclaredOutputsDir(string* dir) { +bool GetTestUndeclaredOutputsDir(std::string* dir) { const char* outputs_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); if (outputs_dir == nullptr) { return false; @@ -391,7 +394,7 @@ bool GetTestUndeclaredOutputsDir(string* dir) { return true; } -bool ResolveTestPrefixes(absl::string_view path, string& resolved_path) { +bool ResolveTestPrefixes(absl::string_view path, std::string& resolved_path) { constexpr absl::string_view kTestWorkspaceSegment = "TEST_WORKSPACE"; constexpr absl::string_view kOutputDirSegment = "TEST_UNDECLARED_OUTPUTS_DIR"; diff --git a/tsl/platform/path.h b/tsl/platform/path.h index bf9537c0e..4d07c3886 100644 --- a/tsl/platform/path.h +++ b/tsl/platform/path.h @@ -18,7 +18,8 @@ limitations under the License. #include -#include "xla/tsl/platform/types.h" +#include "absl/types/span.h" +#include "tsl/platform/platform.h" #include "tsl/platform/stringpiece.h" namespace tsl { diff --git a/tsl/platform/str_util.cc b/tsl/platform/str_util.cc index 9a275de74..df9ceb89c 100644 --- a/tsl/platform/str_util.cc +++ b/tsl/platform/str_util.cc @@ -83,9 +83,9 @@ bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val) { } } -void TitlecaseString(string* s, absl::string_view delimiters) { +void TitlecaseString(std::string* s, absl::string_view delimiters) { bool upper = true; - for (string::iterator ss = s->begin(); ss != s->end(); ++ss) { + for (std::string::iterator ss = s->begin(); ss != s->end(); ++ss) { if (upper) { *ss = absl::ascii_toupper(*ss); } @@ -93,13 +93,14 @@ void TitlecaseString(string* s, absl::string_view delimiters) { } } -string StringReplace(absl::string_view s, absl::string_view oldsub, - absl::string_view newsub, bool replace_all) { +std::string StringReplace(absl::string_view s, absl::string_view oldsub, + absl::string_view newsub, bool replace_all) { // TODO(jlebar): We could avoid having to shift data around in the string if // we had a StringPiece::find() overload that searched for a StringPiece. - string res(s); + std::string res(s); size_t pos = 0; - while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != string::npos) { + while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != + std::string::npos) { res.replace(pos, oldsub.size(), newsub.data(), newsub.size()); pos += newsub.size(); if (oldsub.empty()) { @@ -112,7 +113,7 @@ string StringReplace(absl::string_view s, absl::string_view oldsub, return res; } -string ArgDefCase(absl::string_view s) { +std::string ArgDefCase(absl::string_view s) { const size_t n = s.size(); // Compute the size of resulting string. @@ -139,7 +140,7 @@ string ArgDefCase(absl::string_view s) { // Initialize result with all '_'s. There is no string // constructor that does not initialize memory. - string result(n + extra_us - to_skip, '_'); + std::string result(n + extra_us - to_skip, '_'); // i - index into s // j - index into result for (size_t i = to_skip, j = 0; i < n; ++i, ++j) { diff --git a/tsl/platform/str_util.h b/tsl/platform/str_util.h index 89a3fe55d..b27e06803 100644 --- a/tsl/platform/str_util.h +++ b/tsl/platform/str_util.h @@ -29,7 +29,6 @@ limitations under the License. #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "xla/tsl/platform/macros.h" -#include "xla/tsl/platform/types.h" #include "tsl/platform/stringpiece.h" // Basic string utility routines @@ -152,26 +151,29 @@ struct SkipWhitespace { // Split strings using any of the supplied delimiters. For example: // Split("a,b.c,d", ".,") would return {"a", "b", "c", "d"}. -inline std::vector Split(absl::string_view text, - absl::string_view delims) { - return text.empty() ? std::vector() +inline std::vector Split(absl::string_view text, + absl::string_view delims) { + return text.empty() ? std::vector() : absl::StrSplit(text, absl::ByAnyChar(delims)); } template -std::vector Split(absl::string_view text, absl::string_view delims, - Predicate p) { - return text.empty() ? std::vector() +std::vector Split(absl::string_view text, absl::string_view delims, + Predicate p) { + return text.empty() ? std::vector() : absl::StrSplit(text, absl::ByAnyChar(delims), p); } -inline std::vector Split(absl::string_view text, char delim) { - return text.empty() ? std::vector() : absl::StrSplit(text, delim); +inline std::vector Split(absl::string_view text, char delim) { + return text.empty() ? std::vector() + : absl::StrSplit(text, delim); } template -std::vector Split(absl::string_view text, char delim, Predicate p) { - return text.empty() ? std::vector() : absl::StrSplit(text, delim, p); +std::vector Split(absl::string_view text, char delim, + Predicate p) { + return text.empty() ? std::vector() + : absl::StrSplit(text, delim, p); } // StartsWith() diff --git a/tsl/platform/strcat.h b/tsl/platform/strcat.h index f82190957..a0d3bba31 100644 --- a/tsl/platform/strcat.h +++ b/tsl/platform/strcat.h @@ -26,7 +26,6 @@ limitations under the License. #include "absl/base/macros.h" #include "absl/strings/str_cat.h" #include "xla/tsl/platform/macros.h" -#include "xla/tsl/platform/types.h" #include "tsl/platform/numbers.h" #include "tsl/platform/stringpiece.h"