mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[Reland] [11/N] Enable clang-tidy warnings on c10/util/*.h (#116751)
Reland of #116353 with C++ diagnostic macros restored. Pull Request resolved: https://github.com/pytorch/pytorch/pull/116751 Approved by: https://github.com/albanD
This commit is contained in:
parent
e780213340
commit
ad507789d1
|
|
@ -245,6 +245,7 @@ include_patterns = [
|
||||||
'aten/src/ATen/core/*.cpp',
|
'aten/src/ATen/core/*.cpp',
|
||||||
'c10/**/*.cpp',
|
'c10/**/*.cpp',
|
||||||
'c10/core/**/*.h',
|
'c10/core/**/*.h',
|
||||||
|
'c10/util/**/*.h',
|
||||||
'torch/csrc/**/*.cpp',
|
'torch/csrc/**/*.cpp',
|
||||||
]
|
]
|
||||||
exclude_patterns = [
|
exclude_patterns = [
|
||||||
|
|
@ -255,6 +256,16 @@ exclude_patterns = [
|
||||||
'**/*pb.h',
|
'**/*pb.h',
|
||||||
'**/*CUDA*',
|
'**/*CUDA*',
|
||||||
'**/cuda/*pp',
|
'**/cuda/*pp',
|
||||||
|
'c10/util/complex_math.h',
|
||||||
|
'c10/util/complex_utils.h',
|
||||||
|
'c10/util/flat_hash_map.h',
|
||||||
|
'c10/util/Float8*.h',
|
||||||
|
'c10/util/logging*.h',
|
||||||
|
'c10/util/hash.h',
|
||||||
|
'c10/util/strong_type.h',
|
||||||
|
'c10/util/SmallVector.h',
|
||||||
|
'c10/util/win32-headers.h',
|
||||||
|
'c10/util/*inl.h',
|
||||||
'aten/src/ATen/core/TensorImpl_test.cpp',
|
'aten/src/ATen/core/TensorImpl_test.cpp',
|
||||||
'third_party/**/*',
|
'third_party/**/*',
|
||||||
'torch/csrc/api/**',
|
'torch/csrc/api/**',
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,10 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <ctime>
|
|
||||||
#endif
|
|
||||||
#if defined(C10_IOS) && defined(C10_MOBILE)
|
#if defined(C10_IOS) && defined(C10_MOBILE)
|
||||||
#include <sys/time.h> // for gettimeofday()
|
#include <sys/time.h> // for gettimeofday()
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ class ArrayRef final {
|
||||||
|
|
||||||
/// Construct an ArrayRef from a C array.
|
/// Construct an ArrayRef from a C array.
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
/* implicit */ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
|
/* implicit */ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
|
||||||
|
|
||||||
/// Construct an ArrayRef from a std::initializer_list.
|
/// Construct an ArrayRef from a std::initializer_list.
|
||||||
|
|
@ -238,6 +239,7 @@ class ArrayRef final {
|
||||||
/// continues to select the move assignment operator.
|
/// continues to select the move assignment operator.
|
||||||
template <typename U>
|
template <typename U>
|
||||||
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>>& operator=(
|
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>>& operator=(
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
|
||||||
U&& Temporary) = delete;
|
U&& Temporary) = delete;
|
||||||
|
|
||||||
/// Disallow accidental assignment from a temporary.
|
/// Disallow accidental assignment from a temporary.
|
||||||
|
|
@ -330,6 +332,7 @@ ArrayRef<T>& makeArrayRef(ArrayRef<T>& Vec) {
|
||||||
|
|
||||||
/// Construct an ArrayRef from a C array.
|
/// Construct an ArrayRef from a C array.
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
ArrayRef<T> makeArrayRef(const T (&Arr)[N]) {
|
ArrayRef<T> makeArrayRef(const T (&Arr)[N]) {
|
||||||
return ArrayRef<T>(Arr);
|
return ArrayRef<T>(Arr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
namespace c10::util {
|
namespace c10::util {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
constexpr uint64_t crc64_table[] = {
|
constexpr uint64_t crc64_table[] = {
|
||||||
0x0000000000000000, 0x7ad870c830358979, 0xf5b0e190606b12f2,
|
0x0000000000000000, 0x7ad870c830358979, 0xf5b0e190606b12f2,
|
||||||
0x8f689158505e9b8b, 0xc038e5739841b68f, 0xbae095bba8743ff6,
|
0x8f689158505e9b8b, 0xc038e5739841b68f, 0xbae095bba8743ff6,
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,7 @@ struct ExclusivelyOwnedTraits;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class ExclusivelyOwned {
|
class ExclusivelyOwned {
|
||||||
using EOT = ExclusivelyOwnedTraits<T>;
|
using EOT = ExclusivelyOwnedTraits<T>;
|
||||||
union {
|
typename ExclusivelyOwnedTraits<T>::repr_type repr_;
|
||||||
char dummy_;
|
|
||||||
typename ExclusivelyOwnedTraits<T>::repr_type repr_;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExclusivelyOwned() : repr_(EOT::nullRepr()) {}
|
ExclusivelyOwned() : repr_(EOT::nullRepr()) {}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,8 @@
|
||||||
|
|
||||||
#if defined(__cplusplus) && (__cplusplus >= 201103L)
|
#if defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
|
||||||
#elif !defined(__OPENCL_VERSION__)
|
#elif !defined(__OPENCL_VERSION__)
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c10/macros/Macros.h>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class MaybeOwned final {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeOwned(MaybeOwned&& rhs) noexcept(
|
MaybeOwned(MaybeOwned&& rhs) noexcept(
|
||||||
|
// NOLINTNEXTLINE(*-noexcept-move-*)
|
||||||
std::is_nothrow_move_constructible_v<T> &&
|
std::is_nothrow_move_constructible_v<T> &&
|
||||||
std::is_nothrow_move_assignable_v<borrow_type>)
|
std::is_nothrow_move_assignable_v<borrow_type>)
|
||||||
: isBorrowed_(rhs.isBorrowed_) {
|
: isBorrowed_(rhs.isBorrowed_) {
|
||||||
|
|
@ -140,6 +141,7 @@ class MaybeOwned final {
|
||||||
std::is_nothrow_move_assignable_v<T> &&
|
std::is_nothrow_move_assignable_v<T> &&
|
||||||
std::is_nothrow_move_assignable_v<borrow_type> &&
|
std::is_nothrow_move_assignable_v<borrow_type> &&
|
||||||
std::is_nothrow_move_constructible_v<T> &&
|
std::is_nothrow_move_constructible_v<T> &&
|
||||||
|
// NOLINTNEXTLINE(*-noexcept-move-*)
|
||||||
std::is_nothrow_destructible_v<T> &&
|
std::is_nothrow_destructible_v<T> &&
|
||||||
std::is_nothrow_destructible_v<borrow_type>) {
|
std::is_nothrow_destructible_v<borrow_type>) {
|
||||||
if (this == &rhs) {
|
if (this == &rhs) {
|
||||||
|
|
@ -180,6 +182,7 @@ class MaybeOwned final {
|
||||||
}
|
}
|
||||||
|
|
||||||
~MaybeOwned() noexcept(
|
~MaybeOwned() noexcept(
|
||||||
|
// NOLINTNEXTLINE(*-noexcept-destructor)
|
||||||
std::is_nothrow_destructible_v<T> &&
|
std::is_nothrow_destructible_v<T> &&
|
||||||
std::is_nothrow_destructible_v<borrow_type>) {
|
std::is_nothrow_destructible_v<borrow_type>) {
|
||||||
if (C10_UNLIKELY(!isBorrowed_)) {
|
if (C10_UNLIKELY(!isBorrowed_)) {
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,17 @@
|
||||||
// Macros.h is not needed, but it does namespace shenanigans that lots
|
// Macros.h is not needed, but it does namespace shenanigans that lots
|
||||||
// of downstream code seems to rely on. Feel free to remove it and fix
|
// of downstream code seems to rely on. Feel free to remove it and fix
|
||||||
// up builds.
|
// up builds.
|
||||||
#include <c10/macros/Macros.h>
|
|
||||||
#include <c10/util/Metaprogramming.h>
|
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::bad_optional_access;
|
using std::bad_optional_access;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::make_optional;
|
using std::make_optional;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::nullopt;
|
using std::nullopt;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::nullopt_t;
|
using std::nullopt_t;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::optional;
|
using std::optional;
|
||||||
|
|
||||||
namespace detail_ {
|
namespace detail_ {
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,13 @@ class OptionalArrayRef final {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = ArrayRef<T>>
|
template <
|
||||||
constexpr std::enable_if_t<
|
typename U = ArrayRef<T>,
|
||||||
!std::is_same_v<std::decay_t<U>, OptionalArrayRef> &&
|
typename = std::enable_if_t<
|
||||||
|
!std::is_same_v<std::decay_t<U>, OptionalArrayRef> &&
|
||||||
std::is_constructible_v<ArrayRef<T>, U&&> &&
|
std::is_constructible_v<ArrayRef<T>, U&&> &&
|
||||||
std::is_assignable_v<ArrayRef<T>&, U&&>,
|
std::is_assignable_v<ArrayRef<T>&, U&&>>>
|
||||||
OptionalArrayRef&>
|
constexpr OptionalArrayRef& operator=(U&& value) noexcept(
|
||||||
operator=(U&& value) noexcept(
|
|
||||||
std::is_nothrow_constructible_v<ArrayRef<T>, U&&> &&
|
std::is_nothrow_constructible_v<ArrayRef<T>, U&&> &&
|
||||||
std::is_nothrow_assignable_v<ArrayRef<T>&, U&&>) {
|
std::is_nothrow_assignable_v<ArrayRef<T>&, U&&>) {
|
||||||
wrapped_opt_array_ref = std::forward<U>(value);
|
wrapped_opt_array_ref = std::forward<U>(value);
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ class scope_exit {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename Fp>
|
template <typename Fp>
|
||||||
// constructor accepting a forwarding reference can hide the
|
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
|
||||||
// move constructor
|
|
||||||
// @lint-ignore CLANGTIDY
|
|
||||||
explicit scope_exit(Fp&& F) : ExitFunction(std::forward<Fp>(F)) {}
|
explicit scope_exit(Fp&& F) : ExitFunction(std::forward<Fp>(F)) {}
|
||||||
|
|
||||||
scope_exit(scope_exit&& Rhs) noexcept
|
scope_exit(scope_exit&& Rhs) noexcept
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
C10_CLANG_DIAGNOSTIC_PUSH()
|
C10_CLANG_DIAGNOSTIC_PUSH()
|
||||||
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
|
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
|
||||||
|
|
@ -41,6 +40,7 @@ struct CanonicalizeStrTypes {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
struct CanonicalizeStrTypes<char[N]> {
|
struct CanonicalizeStrTypes<char[N]> {
|
||||||
using type = const char*;
|
using type = const char*;
|
||||||
};
|
};
|
||||||
|
|
@ -181,11 +181,15 @@ inline void printQuotedString(std::ostream& stmt, const string_view str) {
|
||||||
} else {
|
} else {
|
||||||
// C++ io has stateful formatting settings. Messing with
|
// C++ io has stateful formatting settings. Messing with
|
||||||
// them is probably worse than doing this manually.
|
// them is probably worse than doing this manually.
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
char buf[4] = "000";
|
char buf[4] = "000";
|
||||||
|
// NOLINTNEXTLINE(*narrowing-conversions)
|
||||||
buf[2] += s % 8;
|
buf[2] += s % 8;
|
||||||
s /= 8;
|
s /= 8;
|
||||||
|
// NOLINTNEXTLINE(*narrowing-conversions)
|
||||||
buf[1] += s % 8;
|
buf[1] += s % 8;
|
||||||
s /= 8;
|
s /= 8;
|
||||||
|
// NOLINTNEXTLINE(*narrowing-conversions)
|
||||||
buf[0] += s;
|
buf[0] += s;
|
||||||
stmt << "\\" << buf;
|
stmt << "\\" << buf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <c10/util/Float8_e5m2.h>
|
#include <c10/util/Float8_e5m2.h>
|
||||||
#include <c10/util/Float8_e5m2fnuz.h>
|
#include <c10/util/Float8_e5m2fnuz.h>
|
||||||
#include <c10/util/Half.h>
|
#include <c10/util/Half.h>
|
||||||
|
#include <c10/util/complex.h>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c10/util/ArrayRef.h>
|
#include <c10/util/Exception.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
|
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
|
||||||
// to have issues with it otherwise
|
// to have issues with it otherwise
|
||||||
// - fix compiler warnings in operator templated_iterator<const value_type>
|
// - fix compiler warnings in operator templated_iterator<const value_type>
|
||||||
|
// - make use of 'if constexpr' and eliminate AssignIfTrue template
|
||||||
|
|
||||||
// Copyright Malte Skarupke 2017.
|
// Copyright Malte Skarupke 2017.
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
|
@ -176,6 +177,7 @@ struct sherwood_v3_entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int8_t log2(uint64_t value) {
|
inline int8_t log2(uint64_t value) {
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
static constexpr int8_t table[64] = {
|
static constexpr int8_t table[64] = {
|
||||||
63, 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3,
|
63, 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3,
|
||||||
61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4,
|
61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4,
|
||||||
|
|
@ -190,21 +192,6 @@ inline int8_t log2(uint64_t value) {
|
||||||
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
|
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, bool>
|
|
||||||
struct AssignIfTrue {
|
|
||||||
void operator()(T& lhs, const T& rhs) {
|
|
||||||
lhs = rhs;
|
|
||||||
}
|
|
||||||
void operator()(T& lhs, T&& rhs) {
|
|
||||||
lhs = std::move(rhs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
struct AssignIfTrue<T, false> {
|
|
||||||
void operator()(T&, const T&) {}
|
|
||||||
void operator()(T&, T&&) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline uint64_t next_power_of_two(uint64_t i) {
|
inline uint64_t next_power_of_two(uint64_t i) {
|
||||||
--i;
|
--i;
|
||||||
i |= i >> 1;
|
i |= i >> 1;
|
||||||
|
|
@ -389,15 +376,13 @@ class sherwood_v3_table : private EntryAlloc,
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
|
if constexpr (AllocatorTraits::propagate_on_container_copy_assignment::
|
||||||
|
value) {
|
||||||
if (static_cast<EntryAlloc&>(*this) !=
|
if (static_cast<EntryAlloc&>(*this) !=
|
||||||
static_cast<const EntryAlloc&>(other)) {
|
static_cast<const EntryAlloc&>(other)) {
|
||||||
reset_to_empty_state();
|
reset_to_empty_state();
|
||||||
}
|
}
|
||||||
AssignIfTrue<
|
static_cast<EntryAlloc&>(*this) = other;
|
||||||
EntryAlloc,
|
|
||||||
AllocatorTraits::propagate_on_container_copy_assignment::value>()(
|
|
||||||
*this, other);
|
|
||||||
}
|
}
|
||||||
_max_load_factor = other._max_load_factor;
|
_max_load_factor = other._max_load_factor;
|
||||||
static_cast<DetailHasher&>(*this) = other;
|
static_cast<DetailHasher&>(*this) = other;
|
||||||
|
|
@ -409,13 +394,11 @@ class sherwood_v3_table : private EntryAlloc,
|
||||||
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
|
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
|
||||||
if (this == std::addressof(other))
|
if (this == std::addressof(other))
|
||||||
return *this;
|
return *this;
|
||||||
else if (AllocatorTraits::propagate_on_container_move_assignment::value) {
|
else if constexpr (AllocatorTraits::propagate_on_container_move_assignment::
|
||||||
|
value) {
|
||||||
clear();
|
clear();
|
||||||
reset_to_empty_state();
|
reset_to_empty_state();
|
||||||
AssignIfTrue<
|
static_cast<EntryAlloc&>(*this) = std::move(other);
|
||||||
EntryAlloc,
|
|
||||||
AllocatorTraits::propagate_on_container_move_assignment::value>()(
|
|
||||||
*this, std::move(other));
|
|
||||||
swap_pointers(other);
|
swap_pointers(other);
|
||||||
} else if (
|
} else if (
|
||||||
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {
|
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {
|
||||||
|
|
@ -543,6 +526,7 @@ class sherwood_v3_table : private EntryAlloc,
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
const_iterator find(const FindKey& key) const {
|
const_iterator find(const FindKey& key) const {
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
|
||||||
return const_cast<sherwood_v3_table*>(this)->find(key);
|
return const_cast<sherwood_v3_table*>(this)->find(key);
|
||||||
}
|
}
|
||||||
uint64_t count(const FindKey& key) const {
|
uint64_t count(const FindKey& key) const {
|
||||||
|
|
@ -795,7 +779,8 @@ class sherwood_v3_table : private EntryAlloc,
|
||||||
|
|
||||||
uint64_t num_buckets_for_reserve(uint64_t num_elements_) const {
|
uint64_t num_buckets_for_reserve(uint64_t num_elements_) const {
|
||||||
return static_cast<uint64_t>(std::ceil(
|
return static_cast<uint64_t>(std::ceil(
|
||||||
num_elements_ / std::min(0.5, static_cast<double>(_max_load_factor))));
|
static_cast<double>(num_elements_) /
|
||||||
|
std::min(0.5, static_cast<double>(_max_load_factor))));
|
||||||
}
|
}
|
||||||
void rehash_for_other_container(const sherwood_v3_table& other) {
|
void rehash_for_other_container(const sherwood_v3_table& other) {
|
||||||
rehash(
|
rehash(
|
||||||
|
|
@ -1486,6 +1471,7 @@ struct prime_number_hash_policy {
|
||||||
// ClosestPrime(p * 2^(1/3)) and ClosestPrime(p * 2^(2/3)) and put those in
|
// ClosestPrime(p * 2^(1/3)) and ClosestPrime(p * 2^(2/3)) and put those in
|
||||||
// the gaps
|
// the gaps
|
||||||
// 5. get PrevPrime(2^64) and put it at the end
|
// 5. get PrevPrime(2^64) and put it at the end
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
static constexpr const uint64_t prime_list[] = {
|
static constexpr const uint64_t prime_list[] = {
|
||||||
2llu,
|
2llu,
|
||||||
3llu,
|
3llu,
|
||||||
|
|
@ -1673,6 +1659,7 @@ struct prime_number_hash_policy {
|
||||||
11493228998133068689llu,
|
11493228998133068689llu,
|
||||||
14480561146010017169llu,
|
14480561146010017169llu,
|
||||||
18446744073709551557llu};
|
18446744073709551557llu};
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
static constexpr uint64_t (*const mod_functions[])(uint64_t) = {
|
static constexpr uint64_t (*const mod_functions[])(uint64_t) = {
|
||||||
&mod0,
|
&mod0,
|
||||||
&mod2,
|
&mod2,
|
||||||
|
|
@ -1911,7 +1898,7 @@ struct fibonacci_hash_policy {
|
||||||
|
|
||||||
int8_t next_size_over(uint64_t& size) const {
|
int8_t next_size_over(uint64_t& size) const {
|
||||||
size = std::max(uint64_t(2), detailv3::next_power_of_two(size));
|
size = std::max(uint64_t(2), detailv3::next_power_of_two(size));
|
||||||
return 64 - detailv3::log2(size);
|
return static_cast<int8_t>(64 - detailv3::log2(size));
|
||||||
}
|
}
|
||||||
void commit(int8_t shift_) {
|
void commit(int8_t shift_) {
|
||||||
shift = shift_;
|
shift = shift_;
|
||||||
|
|
@ -2020,9 +2007,7 @@ class flat_hash_map
|
||||||
return false;
|
return false;
|
||||||
for (const typename Table::value_type& value : lhs) {
|
for (const typename Table::value_type& value : lhs) {
|
||||||
auto found = rhs.find(value.first);
|
auto found = rhs.find(value.first);
|
||||||
if (found == rhs.end())
|
if (found == rhs.end() || value.second != found->second)
|
||||||
return false;
|
|
||||||
else if (value.second != found->second)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -388,8 +388,7 @@ class intrusive_ptr final {
|
||||||
if (this == &rhs) {
|
if (this == &rhs) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// NOLINTNEXTLINE(misc-unconventional-assign-operator,
|
// NOLINTNEXTLINE(*assign-operator, *assignment-signature)
|
||||||
// cppcoreguidelines-c-copy-assignment-signature)
|
|
||||||
return operator= <TTarget, NullType>(rhs);
|
return operator= <TTarget, NullType>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,8 @@ T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
|
||||||
/// Macro compressed bit reversal table for 256 bits.
|
/// Macro compressed bit reversal table for 256 bits.
|
||||||
///
|
///
|
||||||
/// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
|
/// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
|
||||||
static const unsigned char BitReverseTable256[256] = {
|
/// NOLINTNEXTLINE(*c-arrays*)
|
||||||
|
static constexpr unsigned char BitReverseTable256[256] = {
|
||||||
#define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64
|
#define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64
|
||||||
#define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16)
|
#define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16)
|
||||||
#define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4)
|
#define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4)
|
||||||
|
|
@ -299,7 +300,9 @@ static const unsigned char BitReverseTable256[256] = {
|
||||||
/// Reverse the bits in \p Val.
|
/// Reverse the bits in \p Val.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T reverseBits(T Val) {
|
T reverseBits(T Val) {
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
unsigned char in[sizeof(Val)];
|
unsigned char in[sizeof(Val)];
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
unsigned char out[sizeof(Val)];
|
unsigned char out[sizeof(Val)];
|
||||||
std::memcpy(in, &Val, sizeof(Val));
|
std::memcpy(in, &Val, sizeof(Val));
|
||||||
for (unsigned i = 0; i < sizeof(Val); ++i)
|
for (unsigned i = 0; i < sizeof(Val); ++i)
|
||||||
|
|
@ -420,7 +423,7 @@ inline uint64_t maxUIntN(uint64_t N) {
|
||||||
/// Gets the minimum value for a N-bit signed integer.
|
/// Gets the minimum value for a N-bit signed integer.
|
||||||
inline int64_t minIntN(int64_t N) {
|
inline int64_t minIntN(int64_t N) {
|
||||||
assert(N > 0 && N <= 64 && "integer width out of range");
|
assert(N > 0 && N <= 64 && "integer width out of range");
|
||||||
|
// NOLINTNEXTLINE(*-narrowing-conversions)
|
||||||
return -(UINT64_C(1) << (N - 1));
|
return -(UINT64_C(1) << (N - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,6 +437,7 @@ inline int64_t maxIntN(int64_t N) {
|
||||||
|
|
||||||
// This relies on two's complement wraparound when N == 64, so we convert to
|
// This relies on two's complement wraparound when N == 64, so we convert to
|
||||||
// int64_t only at the very end to avoid UB.
|
// int64_t only at the very end to avoid UB.
|
||||||
|
// NOLINTNEXTLINE(*-narrowing-conversions)
|
||||||
return (UINT64_C(1) << (N - 1)) - 1;
|
return (UINT64_C(1) << (N - 1)) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
|
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
|
||||||
// to have issues with it otherwise
|
// to have issues with it otherwise
|
||||||
// - fix compiler warnings in operator templated_iterator<const value_type>
|
// - fix compiler warnings in operator templated_iterator<const value_type>
|
||||||
|
// - make use of 'if constexpr' and eliminate AssignIfTrue template
|
||||||
|
|
||||||
// Copyright Malte Skarupke 2017.
|
// Copyright Malte Skarupke 2017.
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
|
@ -139,9 +140,11 @@ struct KeyOrValueEquality : functor_storage<bool, key_equal> {
|
||||||
static constexpr int8_t min_lookups = 4;
|
static constexpr int8_t min_lookups = 4;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct sherwood_v3_entry {
|
struct sherwood_v3_entry {
|
||||||
|
// NOLINTNEXTLINE(modernize-use-equals-default)
|
||||||
sherwood_v3_entry() {}
|
sherwood_v3_entry() {}
|
||||||
sherwood_v3_entry(int8_t distance_from_desired)
|
sherwood_v3_entry(int8_t distance_from_desired)
|
||||||
: distance_from_desired(distance_from_desired) {}
|
: distance_from_desired(distance_from_desired) {}
|
||||||
|
// NOLINTNEXTLINE(modernize-use-equals-default)
|
||||||
~sherwood_v3_entry() {}
|
~sherwood_v3_entry() {}
|
||||||
|
|
||||||
bool has_value() const {
|
bool has_value() const {
|
||||||
|
|
@ -188,21 +191,6 @@ inline int8_t log2(uint64_t value) {
|
||||||
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
|
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, bool>
|
|
||||||
struct AssignIfTrue {
|
|
||||||
void operator()(T& lhs, const T& rhs) {
|
|
||||||
lhs = rhs;
|
|
||||||
}
|
|
||||||
void operator()(T& lhs, T&& rhs) {
|
|
||||||
lhs = std::move(rhs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
struct AssignIfTrue<T, false> {
|
|
||||||
void operator()(T&, const T&) {}
|
|
||||||
void operator()(T&, T&&) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline uint64_t next_power_of_two(uint64_t i) {
|
inline uint64_t next_power_of_two(uint64_t i) {
|
||||||
--i;
|
--i;
|
||||||
i |= i >> 1;
|
i |= i >> 1;
|
||||||
|
|
@ -383,15 +371,13 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal {
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
|
if constexpr (AllocatorTraits::propagate_on_container_copy_assignment::
|
||||||
|
value) {
|
||||||
if (static_cast<EntryAlloc&>(*this) !=
|
if (static_cast<EntryAlloc&>(*this) !=
|
||||||
static_cast<const EntryAlloc&>(other)) {
|
static_cast<const EntryAlloc&>(other)) {
|
||||||
reset_to_empty_state();
|
reset_to_empty_state();
|
||||||
}
|
}
|
||||||
AssignIfTrue<
|
static_cast<EntryAlloc&>(*this) = other;
|
||||||
EntryAlloc,
|
|
||||||
AllocatorTraits::propagate_on_container_copy_assignment::value>()(
|
|
||||||
*this, other);
|
|
||||||
}
|
}
|
||||||
_max_load_factor = other._max_load_factor;
|
_max_load_factor = other._max_load_factor;
|
||||||
static_cast<Hasher&>(*this) = other;
|
static_cast<Hasher&>(*this) = other;
|
||||||
|
|
@ -403,13 +389,11 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal {
|
||||||
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
|
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
|
||||||
if (this == std::addressof(other))
|
if (this == std::addressof(other))
|
||||||
return *this;
|
return *this;
|
||||||
else if (AllocatorTraits::propagate_on_container_move_assignment::value) {
|
else if constexpr (AllocatorTraits::propagate_on_container_move_assignment::
|
||||||
|
value) {
|
||||||
clear();
|
clear();
|
||||||
reset_to_empty_state();
|
reset_to_empty_state();
|
||||||
AssignIfTrue<
|
static_cast<EntryAlloc&>(*this) = std::move(other);
|
||||||
EntryAlloc,
|
|
||||||
AllocatorTraits::propagate_on_container_move_assignment::value>()(
|
|
||||||
*this, std::move(other));
|
|
||||||
swap_pointers(other);
|
swap_pointers(other);
|
||||||
} else if (
|
} else if (
|
||||||
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {
|
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ class C10_API FatalSignalHandler {
|
||||||
struct sigaction previous;
|
struct sigaction previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(*c-arrays*)
|
||||||
static signal_handler kSignalHandlers[];
|
static signal_handler kSignalHandlers[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,15 @@
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::stod;
|
using std::stod;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::stoi;
|
using std::stoi;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::stoll;
|
using std::stoll;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::stoull;
|
using std::stoull;
|
||||||
|
// NOLINTNEXTLINE(misc-unused-using-decls)
|
||||||
using std::to_string;
|
using std::to_string;
|
||||||
|
|
||||||
} // namespace c10
|
} // namespace c10
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c10/util/Optional.h>
|
#include <c10/macros/Macros.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user