mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Revert "Make c10::string_view an alias of std::string_view (#130417)"
This reverts commit c48fe8901114aa2b0a9c2d77f915a2ad8ab2098b. Reverted https://github.com/pytorch/pytorch/pull/130417 on behalf of https://github.com/clee2000 due to breaking some internal tests, probably usages of string_view that need to be changed? ([comment](https://github.com/pytorch/pytorch/pull/130417#issuecomment-2414775064))
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -87,13 +87,13 @@ namespace detail {
|
||||
#error "You're running a too old version of Clang. We need Clang 4 or later."
|
||||
#endif
|
||||
|
||||
inline constexpr string_view_ext extract(
|
||||
string_view_ext prefix,
|
||||
string_view_ext suffix,
|
||||
string_view_ext str) {
|
||||
inline constexpr string_view extract(
|
||||
string_view prefix,
|
||||
string_view suffix,
|
||||
string_view str) {
|
||||
#if !defined(__CUDA_ARCH__) // CUDA doesn't like std::logic_error in device code
|
||||
return (!str.starts_with(prefix) || !str.ends_with(suffix))
|
||||
? (throw std::logic_error("Invalid pattern"), string_view_ext())
|
||||
? (throw std::logic_error("Invalid pattern"), string_view())
|
||||
: str.substr(prefix.size(), str.size() - prefix.size() - suffix.size());
|
||||
#else
|
||||
return str.substr(prefix.size(), str.size() - prefix.size() - suffix.size());
|
||||
@ -101,8 +101,7 @@ inline constexpr string_view_ext extract(
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline C10_TYPENAME_CONSTEXPR c10::string_view_ext
|
||||
fully_qualified_type_name_impl() {
|
||||
inline C10_TYPENAME_CONSTEXPR c10::string_view fully_qualified_type_name_impl() {
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#if defined(__NVCC__)
|
||||
return extract(
|
||||
@ -117,17 +116,17 @@ fully_qualified_type_name_impl() {
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
return extract(
|
||||
"c10::string_view_ext c10::util::detail::fully_qualified_type_name_impl() [T = ",
|
||||
"c10::string_view c10::util::detail::fully_qualified_type_name_impl() [T = ",
|
||||
"]",
|
||||
__PRETTY_FUNCTION__);
|
||||
#elif defined(__GNUC__)
|
||||
return extract(
|
||||
#if C10_TYPENAME_SUPPORTS_CONSTEXPR
|
||||
"constexpr c10::string_view_ext c10::util::detail::fully_qualified_type_name_impl() [with T = ",
|
||||
"constexpr c10::string_view c10::util::detail::fully_qualified_type_name_impl() [with T = ",
|
||||
#else
|
||||
"c10::string_view_ext c10::util::detail::fully_qualified_type_name_impl() [with T = ",
|
||||
"c10::string_view c10::util::detail::fully_qualified_type_name_impl() [with T = ",
|
||||
#endif
|
||||
"; c10::string_view_ext = c10::basic_string_view<char>]",
|
||||
"; c10::string_view = c10::basic_string_view<char>]",
|
||||
__PRETTY_FUNCTION__);
|
||||
#endif
|
||||
}
|
||||
@ -182,14 +181,14 @@ inline constexpr type_index get_type_index<std::string>() {
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline C10_TYPENAME_CONSTEXPR string_view_ext
|
||||
inline C10_TYPENAME_CONSTEXPR string_view
|
||||
get_fully_qualified_type_name() noexcept {
|
||||
#if C10_TYPENAME_SUPPORTS_CONSTEXPR
|
||||
constexpr
|
||||
#else
|
||||
static
|
||||
#endif
|
||||
auto name = detail::fully_qualified_type_name_impl<T>();
|
||||
string_view name = detail::fully_qualified_type_name_impl<T>();
|
||||
return name;
|
||||
}
|
||||
} // namespace c10::util
|
||||
|
@ -53,9 +53,6 @@ class basic_string_view final {
|
||||
/* implicit */ basic_string_view(const ::std::basic_string<CharT>& str)
|
||||
: basic_string_view(str.data(), str.size()) {}
|
||||
|
||||
/* implicit */ basic_string_view(const ::std::basic_string_view<CharT>& str)
|
||||
: basic_string_view(str.data(), str.size()) {}
|
||||
|
||||
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
||||
|
||||
constexpr basic_string_view& operator=(
|
||||
@ -65,10 +62,6 @@ class basic_string_view final {
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator ::std::basic_string_view<CharT>() const {
|
||||
return ::std::basic_string_view<CharT>(data(), size());
|
||||
}
|
||||
|
||||
explicit operator ::std::basic_string<CharT>() const {
|
||||
return ::std::basic_string<CharT>(data(), size());
|
||||
}
|
||||
@ -594,8 +587,8 @@ constexpr inline void swap(
|
||||
basic_string_view<CharT>& rhs) noexcept {
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
using std::string_view;
|
||||
using string_view_ext = basic_string_view<char>;
|
||||
|
||||
using string_view = basic_string_view<char>;
|
||||
|
||||
} // namespace c10
|
||||
|
||||
|
@ -135,7 +135,7 @@ struct TypeMetaData final {
|
||||
PlacementDelete* placementDelete,
|
||||
Delete* deleteFn,
|
||||
TypeIdentifier id,
|
||||
c10::string_view_ext name) noexcept
|
||||
c10::string_view name) noexcept
|
||||
: itemsize_(itemsize),
|
||||
new_(newFn),
|
||||
placementNew_(placementNew),
|
||||
@ -152,7 +152,7 @@ struct TypeMetaData final {
|
||||
PlacementDelete* placementDelete_;
|
||||
Delete* delete_;
|
||||
TypeIdentifier id_;
|
||||
c10::string_view_ext name_;
|
||||
c10::string_view name_;
|
||||
};
|
||||
|
||||
// Mechanism for throwing errors which can't be prevented at compile time
|
||||
@ -409,7 +409,7 @@ class C10_API TypeMeta final {
|
||||
/**
|
||||
* Returns a printable name for the type.
|
||||
*/
|
||||
c10::string_view_ext name() const noexcept {
|
||||
c10::string_view name() const noexcept {
|
||||
return data().name_;
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ class C10_API TypeMeta final {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static c10::string_view_ext TypeName() noexcept {
|
||||
static c10::string_view TypeName() noexcept {
|
||||
return c10::util::get_fully_qualified_type_name<T>();
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ size_t getPadding(
|
||||
bool PyTorchStreamReader::hasRecord(const std::string& name) {
|
||||
std::lock_guard<std::mutex> guard(reader_lock_);
|
||||
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
return false;
|
||||
}
|
||||
std::string ss = archive_name_plus_slash_ + name;
|
||||
@ -320,7 +320,7 @@ std::vector<std::string> PyTorchStreamReader::getAllRecords() {
|
||||
buf);
|
||||
}
|
||||
if ((load_debug_symbol_) ||
|
||||
(!c10::string_view_ext(buf + archive_name_plus_slash_.size()).ends_with(kDebugPklSuffix))) {
|
||||
(!c10::string_view(buf + archive_name_plus_slash_.size()).ends_with(kDebugPklSuffix))) {
|
||||
// NOLINTNEXTLINE(modernize-use-emplace)
|
||||
out.push_back(buf + archive_name_plus_slash_.size());
|
||||
}
|
||||
@ -343,7 +343,7 @@ size_t PyTorchStreamReader::getRecordID(const std::string& name) {
|
||||
// return dataptr, size
|
||||
std::tuple<at::DataPtr, size_t> PyTorchStreamReader::getRecord(const std::string& name) {
|
||||
std::lock_guard<std::mutex> guard(reader_lock_);
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
at::DataPtr retval;
|
||||
return std::make_tuple(std::move(retval), 0);
|
||||
}
|
||||
@ -424,7 +424,7 @@ PyTorchStreamReader::getRecord(const std::string& name,
|
||||
return getRecord(name);
|
||||
}
|
||||
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
at::DataPtr retval;
|
||||
return std::make_tuple(std::move(retval), 0);
|
||||
}
|
||||
@ -448,7 +448,7 @@ PyTorchStreamReader::getRecord(const std::string& name,
|
||||
size_t
|
||||
PyTorchStreamReader::getRecord(const std::string& name, void* dst, size_t n) {
|
||||
std::lock_guard<std::mutex> guard(reader_lock_);
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
return 0;
|
||||
}
|
||||
size_t key = getRecordID(name);
|
||||
@ -477,7 +477,7 @@ PyTorchStreamReader::getRecord(const std::string& name, void* dst, size_t n,
|
||||
return getRecord(name, dst, n);
|
||||
}
|
||||
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
return 0;
|
||||
}
|
||||
size_t key = getRecordID(name);
|
||||
@ -508,7 +508,7 @@ size_t PyTorchStreamReader::getRecord(
|
||||
void* buf,
|
||||
const std::function<void(void*, const void*, size_t)>& memcpy_func) {
|
||||
std::lock_guard<std::mutex> guard(reader_lock_);
|
||||
if ((!load_debug_symbol_) && c10::string_view_ext(name).ends_with(kDebugPklSuffix)) {
|
||||
if ((!load_debug_symbol_) && c10::string_view(name).ends_with(kDebugPklSuffix)) {
|
||||
return 0;
|
||||
}
|
||||
if (chunk_size <= 0) {
|
||||
|
@ -117,7 +117,7 @@ MobileDebugTable::MobileDebugTable(
|
||||
const std::vector<std::string>& record_names = reader->getAllRecords();
|
||||
const c10::string_view suffix(".debug_pkl");
|
||||
for (const auto& record_name : record_names) {
|
||||
if (c10::string_view_ext(record_name).ends_with(suffix)) {
|
||||
if (c10::string_view(record_name).ends_with(suffix)) {
|
||||
auto [debug_data, debug_size] = reader->getRecord(record_name);
|
||||
auto ivalueTuple = jit::unpickle(
|
||||
reinterpret_cast<const char*>(debug_data.get()),
|
||||
|
@ -188,7 +188,7 @@ TypePtr resolveType(
|
||||
const std::string& type_string,
|
||||
const std::shared_ptr<CompilationUnit>& cu) {
|
||||
TypePtr type;
|
||||
c10::string_view_ext type_str(type_string);
|
||||
c10::string_view type_str(type_string);
|
||||
if (type_str.starts_with(kCustomClassPrefix)) {
|
||||
type = getCustomClass(type_string);
|
||||
TORCH_CHECK(
|
||||
@ -607,7 +607,7 @@ ClassTypePtr FlatbufferLoader::getOrCreateClassTypeForObject(
|
||||
const mobile::serialization::ObjectType* obj_type =
|
||||
module_->object_types()->Get(object->type_index());
|
||||
if (cls == nullptr) {
|
||||
c10::string_view_ext qn_str(
|
||||
c10::string_view qn_str(
|
||||
obj_type->type_name()->c_str(), obj_type->type_name()->size());
|
||||
if (qn_str.starts_with(kTorchPrefix) || qn_str.starts_with(kJitPrefix)) {
|
||||
c10::QualifiedName qn(obj_type->type_name()->str());
|
||||
|
@ -149,6 +149,10 @@ static inline hash_t Hash(const std::string& value) {
|
||||
return DataHash(value.data(), value.size());
|
||||
}
|
||||
|
||||
static inline hash_t Hash(const c10::string_view& value) {
|
||||
return DataHash(value.data(), value.size());
|
||||
}
|
||||
|
||||
static inline hash_t Hash(const std::string_view& value) {
|
||||
return DataHash(value.data(), value.size());
|
||||
}
|
||||
|
Reference in New Issue
Block a user