Skip to content

Commit

Permalink
Roll abseil_revision 1a38beaaaf..dcaed1a05a
Browse files Browse the repository at this point in the history
Change Log:
https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+log/1a38beaaaf..dcaed1a05a
Full diff:
https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+/1a38beaaaf..dcaed1a05a

Bug: None
Change-Id: I854ff6ccfc41c9dc7ca41194559504a6a386e5d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4236271
Commit-Queue: Danil Chapovalov <danilchap@chromium.org>
Reviewed-by: Danil Chapovalov <danilchap@chromium.org>
Auto-Submit: Mirko Bonadei <mbonadei@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1103487}
  • Loading branch information
Mirko Bonadei authored and Chromium LUCI CQ committed Feb 9, 2023
1 parent c6a0cea commit 8df7862
Show file tree
Hide file tree
Showing 33 changed files with 230 additions and 116 deletions.
2 changes: 1 addition & 1 deletion third_party/abseil-cpp/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ URL: https://github.com/abseil/abseil-cpp
License: Apache 2.0
License File: LICENSE
Version: 0
Revision: 1a38beaaaf4cbdcc61a03e07a1212be17a5cd5c8
Revision: dcaed1a05a813e95b65219e0d1f6a2a684e13028
Security Critical: yes

Description:
Expand Down
4 changes: 2 additions & 2 deletions third_party/abseil-cpp/absl/base/prefetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void PrefetchToLocalCacheNta(const void* addr);
// return ptr;
// }
//
void PrefetchToLocalCacheforWrite(const void* addr);
void PrefetchToLocalCacheForWrite(const void* addr);

#if ABSL_HAVE_BUILTIN(__builtin_prefetch) || defined(__GNUC__)

Expand All @@ -156,7 +156,7 @@ inline void PrefetchToLocalCacheForWrite(const void* addr) {
#if defined(__x86_64__)
asm("prefetchw (%0)" : : "r"(addr));
#else
__builtin_prefetch(addr, 1, 0);
__builtin_prefetch(addr, 1, 3);
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions third_party/abseil-cpp/absl/container/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,13 @@ cc_library(
"//absl/base",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:raw_logging_internal",
"//absl/debugging:stacktrace",
"//absl/memory",
"//absl/profiling:exponential_biased",
"//absl/profiling:sample_recorder",
"//absl/synchronization",
"//absl/time",
"//absl/utility",
],
)
Expand Down Expand Up @@ -623,6 +625,7 @@ cc_library(
"//absl/base:endian",
"//absl/base:prefetch",
"//absl/base:raw_logging_internal",
"//absl/hash",
"//absl/memory",
"//absl/meta:type_traits",
"//absl/numeric:bits",
Expand Down
3 changes: 3 additions & 0 deletions third_party/abseil-cpp/absl/container/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ absl_source_set("hashtablez_sampler") {
"//third_party/abseil-cpp/absl/base",
"//third_party/abseil-cpp/absl/base:config",
"//third_party/abseil-cpp/absl/base:core_headers",
"//third_party/abseil-cpp/absl/base:raw_logging_internal",
"//third_party/abseil-cpp/absl/debugging:stacktrace",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/profiling:exponential_biased",
"//third_party/abseil-cpp/absl/profiling:sample_recorder",
"//third_party/abseil-cpp/absl/synchronization",
"//third_party/abseil-cpp/absl/time",
"//third_party/abseil-cpp/absl/utility",
]
}
Expand Down Expand Up @@ -245,6 +247,7 @@ absl_source_set("raw_hash_set") {
"//third_party/abseil-cpp/absl/base:endian",
"//third_party/abseil-cpp/absl/base:prefetch",
"//third_party/abseil-cpp/absl/base:raw_logging_internal",
"//third_party/abseil-cpp/absl/hash",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/meta:type_traits",
"//third_party/abseil-cpp/absl/numeric:bits",
Expand Down
3 changes: 3 additions & 0 deletions third_party/abseil-cpp/absl/container/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,10 @@ absl_cc_library(
absl::base
absl::config
absl::exponential_biased
absl::raw_logging_internal
absl::sample_recorder
absl::synchronization
absl::time
)

absl_cc_test(
Expand Down Expand Up @@ -705,6 +707,7 @@ absl_cc_library(
absl::container_memory
absl::core_headers
absl::endian
absl::hash
absl::hash_policy_traits
absl::hashtable_debug_hooks
absl::hashtablez_sampler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/debugging/stacktrace.h"
#include "absl/memory/memory.h"
#include "absl/profiling/internal/exponential_biased.h"
#include "absl/profiling/internal/sample_recorder.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/utility/utility.h"

namespace absl {
Expand Down
15 changes: 15 additions & 0 deletions third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstring>

#include "absl/base/config.h"
#include "absl/hash/hash.h"

namespace absl {
ABSL_NAMESPACE_BEGIN
Expand Down Expand Up @@ -51,6 +52,20 @@ inline size_t RandomSeed() {
return value ^ static_cast<size_t>(reinterpret_cast<uintptr_t>(&counter));
}

bool CommonFieldsGenerationInfoEnabled::
should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl,
size_t capacity) const {
if (reserved_growth_ == kReservedGrowthJustRanOut) return true;
if (reserved_growth_ > 0) return false;
// Note: we can't use the abseil-random library because abseil-random
// depends on swisstable. We want to return true with probability
// `min(1, RehashProbabilityConstant() / capacity())`. In order to do this,
// we probe based on a random hash and see if the offset is less than
// RehashProbabilityConstant().
return probe(ctrl, capacity, absl::HashOf(RandomSeed())).offset() <
RehashProbabilityConstant();
}

bool ShouldInsertBackwards(size_t hash, const ctrl_t* ctrl) {
// To avoid problems with weak hashes and single bit tests, we use % 13.
// TODO(kfm,sbenza): revisit after we do unconditional mixing
Expand Down
33 changes: 24 additions & 9 deletions third_party/abseil-cpp/absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ using Group = GroupAArch64Impl;
using Group = GroupPortableImpl;
#endif

// When there is an insertion with no reserved growth, we rehash with
// probability `min(1, RehashProbabilityConstant() / capacity())`. Using a
// constant divided by capacity ensures that inserting N elements is still O(N)
// in the average case. Using the constant 16 means that we expect to rehash ~8
// times more often than when generations are disabled. We are adding expected
// rehash_probability * #insertions/capacity_growth = 16/capacity * ((7/8 -
// 7/16) * capacity)/capacity_growth = ~7 extra rehashes per capacity growth.
inline size_t RehashProbabilityConstant() { return 16; }

class CommonFieldsGenerationInfoEnabled {
// A sentinel value for reserved_growth_ indicating that we just ran out of
// reserved growth on the last insertion. When reserve is called and then
Expand All @@ -769,12 +778,10 @@ class CommonFieldsGenerationInfoEnabled {

// Whether we should rehash on insert in order to detect bugs of using invalid
// references. We rehash on the first insertion after reserved_growth_ reaches
// 0 after a call to reserve.
// TODO(b/254649633): we could potentially do a rehash with low probability
// 0 after a call to reserve. We also do a rehash with low probability
// whenever reserved_growth_ is zero.
bool should_rehash_for_bug_detection_on_insert() const {
return reserved_growth_ == kReservedGrowthJustRanOut;
}
bool should_rehash_for_bug_detection_on_insert(const ctrl_t* ctrl,
size_t capacity) const;
void maybe_increment_generation_on_insert() {
if (reserved_growth_ == kReservedGrowthJustRanOut) reserved_growth_ = 0;

Expand Down Expand Up @@ -820,7 +827,9 @@ class CommonFieldsGenerationInfoDisabled {
CommonFieldsGenerationInfoDisabled& operator=(
CommonFieldsGenerationInfoDisabled&&) = default;

bool should_rehash_for_bug_detection_on_insert() const { return false; }
bool should_rehash_for_bug_detection_on_insert(const ctrl_t*, size_t) const {
return false;
}
void maybe_increment_generation_on_insert() {}
void reset_reserved_growth(size_t, size_t) {}
size_t reserved_growth() const { return 0; }
Expand Down Expand Up @@ -905,6 +914,10 @@ class CommonFields : public CommonFieldsGenerationInfo {
return compressed_tuple_.template get<1>();
}

bool should_rehash_for_bug_detection_on_insert() const {
return CommonFieldsGenerationInfo::
should_rehash_for_bug_detection_on_insert(control_, capacity_);
}
void reset_reserved_growth(size_t reservation) {
CommonFieldsGenerationInfo::reset_reserved_growth(reservation, size_);
}
Expand Down Expand Up @@ -1106,11 +1119,13 @@ struct FindInfo {
inline bool is_small(size_t capacity) { return capacity < Group::kWidth - 1; }

// Begins a probing operation on `common.control`, using `hash`.
inline probe_seq<Group::kWidth> probe(const CommonFields& common, size_t hash) {
const ctrl_t* ctrl = common.control_;
const size_t capacity = common.capacity_;
inline probe_seq<Group::kWidth> probe(const ctrl_t* ctrl, const size_t capacity,
size_t hash) {
return probe_seq<Group::kWidth>(H1(hash, ctrl), capacity);
}
inline probe_seq<Group::kWidth> probe(const CommonFields& common, size_t hash) {
return probe(common.control_, common.capacity_, hash);
}

// Probes an array of control bits using a probe sequence derived from `hash`,
// and returns the offset corresponding to the first deleted or empty slot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ void TestDecompose(bool construct_three) {
}

TEST(Table, Decompose) {
if (SwisstableGenerationsEnabled()) {
GTEST_SKIP() << "Generations being enabled causes extra rehashes.";
}

TestDecompose<DecomposeHash, DecomposeEq>(false);

struct TransparentHashIntOverload {
Expand Down Expand Up @@ -903,6 +907,10 @@ struct Modulo1000HashTable

// Test that rehash with no resize happen in case of many deleted slots.
TEST(Table, RehashWithNoResize) {
if (SwisstableGenerationsEnabled()) {
GTEST_SKIP() << "Generations being enabled causes extra rehashes.";
}

Modulo1000HashTable t;
// Adding the same length (and the same hash) strings
// to have at least kMinFullGroups groups
Expand Down Expand Up @@ -996,6 +1004,10 @@ TEST(Table, EnsureNonQuadraticAsInRust) {
}

TEST(Table, ClearBug) {
if (SwisstableGenerationsEnabled()) {
GTEST_SKIP() << "Generations being enabled causes extra rehashes.";
}

IntTable t;
constexpr size_t capacity = container_internal::Group::kWidth - 1;
constexpr size_t max_size = capacity / 2 + 1;
Expand Down Expand Up @@ -2318,6 +2330,25 @@ TEST(Table, ReservedGrowthUpdatesWhenTableDoesntGrow) {
EXPECT_EQ(*it, 0);
}

TEST(Table, InvalidReferenceUseCrashesWithSanitizers) {
if (!SwisstableGenerationsEnabled()) GTEST_SKIP() << "Generations disabled.";
#ifdef ABSL_HAVE_MEMORY_SANITIZER
GTEST_SKIP() << "MSan fails to detect some of these rehashes.";
#endif

IntTable t;
t.insert(0);
// Rehashing is guaranteed on every insertion while capacity is less than
// RehashProbabilityConstant().
int64_t i = 0;
while (t.capacity() <= RehashProbabilityConstant()) {
// ptr will become invalidated on rehash.
const int64_t* ptr = &*t.begin();
t.insert(++i);
EXPECT_DEATH_IF_SUPPORTED(std::cout << *ptr, "heap-use-after-free") << i;
}
}

} // namespace
} // namespace container_internal
ABSL_NAMESPACE_END
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <x86intrin.h>
#define ABSL_CRC_INTERNAL_HAVE_X86_SIMD

#elif defined(_MSC_VER) && defined(__AVX__)
#elif defined(_MSC_VER) && !defined(__clang__) && defined(__AVX__)

// MSVC AVX (/arch:AVX) implies SSE 4.2 and PCLMULQDQ.
#include <intrin.h>
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ cc_library(
":usage_internal",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:raw_logging_internal",
"//absl/strings",
"//absl/synchronization",
],
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/flags/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ absl_source_set("usage") {
":usage_internal",
"//third_party/abseil-cpp/absl/base:config",
"//third_party/abseil-cpp/absl/base:core_headers",
"//third_party/abseil-cpp/absl/base:raw_logging_internal",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/synchronization",
]
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/flags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ absl_cc_library(
absl::config
absl::core_headers
absl::flags_usage_internal
absl::raw_logging_internal
absl::strings
absl::synchronization
)
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/flags/usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/const_init.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/thread_annotations.h"
#include "absl/flags/internal/usage.h"
#include "absl/strings/string_view.h"
Expand Down
15 changes: 13 additions & 2 deletions third_party/abseil-cpp/absl/hash/hash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <deque>
#include <forward_list>
Expand Down Expand Up @@ -1241,14 +1242,24 @@ TEST(HashTest, DoesNotUseImplicitConversionsToBool) {

TEST(HashOf, MatchesHashForSingleArgument) {
std::string s = "forty two";
int i = 42;
double d = 42.0;
std::tuple<int, int> t{4, 2};
int i = 42;
int neg_i = -42;
int16_t i16 = 42;
int16_t neg_i16 = -42;
int8_t i8 = 42;
int8_t neg_i8 = -42;

EXPECT_EQ(absl::HashOf(s), absl::Hash<std::string>{}(s));
EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i));
EXPECT_EQ(absl::HashOf(d), absl::Hash<double>{}(d));
EXPECT_EQ(absl::HashOf(t), (absl::Hash<std::tuple<int, int>>{}(t)));
EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i));
EXPECT_EQ(absl::HashOf(neg_i), absl::Hash<int>{}(neg_i));
EXPECT_EQ(absl::HashOf(i16), absl::Hash<int16_t>{}(i16));
EXPECT_EQ(absl::HashOf(neg_i16), absl::Hash<int16_t>{}(neg_i16));
EXPECT_EQ(absl::HashOf(i8), absl::Hash<int8_t>{}(i8));
EXPECT_EQ(absl::HashOf(neg_i8), absl::Hash<int8_t>{}(neg_i8));
}

TEST(HashOf, MatchesHashOfTupleForMultipleArguments) {
Expand Down
3 changes: 2 additions & 1 deletion third_party/abseil-cpp/absl/hash/internal/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,8 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
// The result should be the same as running the whole algorithm, but faster.
template <typename T, absl::enable_if_t<IntegralFastPath<T>::value, int> = 0>
static size_t hash(T value) {
return static_cast<size_t>(Mix(Seed(), static_cast<uint64_t>(value)));
return static_cast<size_t>(
Mix(Seed(), static_cast<std::make_unsigned_t<T>>(value)));
}

// Overload of MixingHashState::hash()
Expand Down
5 changes: 3 additions & 2 deletions third_party/abseil-cpp/absl/status/statusor.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ class StatusOr : private internal_statusor::StatusOrData<T>,
// Reconstructs the inner value T in-place using the provided args, using the
// T(args...) constructor. Returns reference to the reconstructed `T`.
template <typename... Args>
T& emplace(Args&&... args) {
T& emplace(Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND {
if (ok()) {
this->Clear();
this->MakeValue(std::forward<Args>(args)...);
Expand All @@ -600,7 +600,8 @@ class StatusOr : private internal_statusor::StatusOrData<T>,
absl::enable_if_t<
std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value,
int> = 0>
T& emplace(std::initializer_list<U> ilist, Args&&... args) {
T& emplace(std::initializer_list<U> ilist,
Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND {
if (ok()) {
this->Clear();
this->MakeValue(ilist, std::forward<Args>(args)...);
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/strings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ cc_library(
"//absl/container:inlined_vector",
"//absl/debugging:stacktrace",
"//absl/synchronization",
"//absl/time",
"//absl/types:span",
],
)
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/strings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ absl_source_set("cordz_info") {
"//third_party/abseil-cpp/absl/container:inlined_vector",
"//third_party/abseil-cpp/absl/debugging:stacktrace",
"//third_party/abseil-cpp/absl/synchronization",
"//third_party/abseil-cpp/absl/time",
"//third_party/abseil-cpp/absl/types:span",
]
}
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/strings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ absl_cc_library(
absl::raw_logging_internal
absl::stacktrace
absl::synchronization
absl::time
)

absl_cc_test(
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/strings/internal/cordz_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "absl/strings/internal/cordz_statistics.h"
#include "absl/strings/internal/cordz_update_tracker.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/types/span.h"

namespace absl {
Expand Down

0 comments on commit 8df7862

Please sign in to comment.