Export of internal Abseil changes

--
4409b08e103d6e7041d18a4d431290cafe3650cf by Derek Mauro <dmauro@google.com>:

Workaround NVCC compile error in StringConstant

Based on a patch in TensorFlow:
da83132aba/third_party/absl/com_google_absl_fix_mac_and_nvcc_build.patch (L262-L282)

Fixes #1105

PiperOrigin-RevId: 426156316

--
25db16567ffc5400dfaa30b567398ede84729687 by Abseil Team <absl-team@google.com>:

Only look for Elf64_Auxinfo on 64-bit FreeBSD.

PiperOrigin-RevId: 426132251

--
2e73c3d9df59b2b769d2b8dca97f0ca5c512c72a by Abseil Team <absl-team@google.com>:

Add a problem hint to the error message when dereferencing the end() iterator.

PiperOrigin-RevId: 426120394

--
6befbf89c47963656b9e8151166ab4c8446d4785 by Martijn Vels <mvels@google.com>:

Make Cord Btree the default and remove opt out machinery

This change makes btree the default Cord format and removes the machinery to opt out. Subsequent changes will remove the 'true' constant evaluation and effectively cleanup all old code and references to CONCAT.

PiperOrigin-RevId: 426119728

--
f6a0a664029d61811d90bd484f4eefa0400b5dd4 by Abseil Team <absl-team@google.com>:

Mark Notification::HasBeenNotified as ABSL_MUST_USE_RESULT

PiperOrigin-RevId: 425927033
GitOrigin-RevId: 4409b08e103d6e7041d18a4d431290cafe3650cf
Change-Id: I86f1052c63c13c6486baf4108de2554f162f9c40
pull/1110/head
Abseil Team 3 years ago committed by Derek Mauro
parent 5202173ca7
commit 36db0e4b69
  1. 16
      absl/container/internal/raw_hash_set.h
  2. 2
      absl/debugging/internal/vdso_support.cc
  3. 5
      absl/strings/cord.cc
  4. 73
      absl/strings/cord_test.cc
  5. 1
      absl/strings/internal/cord_internal.cc
  6. 6
      absl/strings/internal/cord_internal.h
  7. 8
      absl/strings/internal/string_constant.h
  8. 3
      absl/synchronization/notification.h

@ -535,15 +535,19 @@ size_t SelectBucketCountForIterRange(InputIter first, InputIter last,
}
inline void AssertIsFull(ctrl_t* ctrl) {
ABSL_HARDENING_ASSERT((ctrl != nullptr && IsFull(*ctrl)) &&
"Invalid operation on iterator. The element might have "
"been erased, or the table might have rehashed.");
ABSL_HARDENING_ASSERT(
(ctrl != nullptr && IsFull(*ctrl)) &&
"Invalid operation on iterator. The element might have "
"been erased, the table might have rehashed, or this may "
"be an end() iterator.");
}
inline void AssertIsValid(ctrl_t* ctrl) {
ABSL_HARDENING_ASSERT((ctrl == nullptr || IsFull(*ctrl)) &&
"Invalid operation on iterator. The element might have "
"been erased, or the table might have rehashed.");
ABSL_HARDENING_ASSERT(
(ctrl == nullptr || IsFull(*ctrl)) &&
"Invalid operation on iterator. The element might have "
"been erased, the table might have rehashed, or this may "
"be an end() iterator.");
}
struct FindInfo {

@ -51,7 +51,9 @@
#endif
#if defined(__FreeBSD__)
#if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64
using Elf64_auxv_t = Elf64_Auxinfo;
#endif
using Elf32_auxv_t = Elf32_Auxinfo;
#endif

@ -96,10 +96,7 @@ static constexpr uint64_t min_length[] = {
static const int kMinLengthSize = ABSL_ARRAYSIZE(min_length);
static inline bool btree_enabled() {
return cord_internal::cord_btree_enabled.load(
std::memory_order_relaxed);
}
static inline constexpr bool btree_enabled() { return true; }
static inline bool IsRootBalanced(CordRep* node) {
if (!node->IsConcat()) {

@ -231,15 +231,7 @@ ABSL_NAMESPACE_END
// and with our without expected CRCs being set on the subject Cords.
class CordTest : public testing::TestWithParam<int> {
public:
CordTest() : was_btree_(absl::cord_internal::cord_btree_enabled.load()) {
absl::cord_internal::cord_btree_enabled.store(UseBtree());
}
~CordTest() override {
absl::cord_internal::cord_btree_enabled.store(was_btree_);
}
// Returns true if test is running with btree enabled.
bool UseBtree() const { return GetParam() == 1 || GetParam() == 3; }
bool UseCrc() const { return GetParam() == 2 || GetParam() == 3; }
void MaybeHarden(absl::Cord& c) {
if (UseCrc()) {
@ -255,27 +247,19 @@ class CordTest : public testing::TestWithParam<int> {
static std::string ToString(testing::TestParamInfo<int> param) {
switch (param.param) {
case 0:
return "Concat";
case 1:
return "Btree";
case 2:
return "ConcatHardened";
case 3:
case 1:
return "BtreeHardened";
default:
assert(false);
return "???";
}
}
private:
const bool was_btree_;
};
INSTANTIATE_TEST_SUITE_P(WithParam, CordTest, testing::Values(0, 1, 2, 3),
INSTANTIATE_TEST_SUITE_P(WithParam, CordTest, testing::Values(0, 1),
CordTest::ToString);
TEST(CordRepFlat, AllFlatCapacities) {
// Explicitly and redundantly assert built-in min/max limits
static_assert(absl::cord_internal::kFlatOverhead < 32, "");
@ -1561,8 +1545,6 @@ TEST(CordTest, CordMemoryUsageFlatHardenedAndShared) {
}
TEST(CordTest, CordMemoryUsageBTree) {
absl::cord_internal::enable_cord_btree(true);
absl::Cord cord1;
size_t flats1_size = 0;
absl::Cord flats1[4] = {MakeCord(1000, 'a'), MakeCord(1100, 'a'),
@ -1611,57 +1593,6 @@ TEST(CordTest, CordMemoryUsageBTree) {
rep2_size);
}
TEST(CordTest, CordMemoryUsageConcat) {
absl::cord_internal::enable_cord_btree(false);
absl::Cord cord1;
size_t flats1_size = 0;
absl::Cord flats1[4] = {MakeCord(1000, 'a'), MakeCord(1100, 'a'),
MakeCord(1200, 'a'), MakeCord(1300, 'a')};
for (absl::Cord flat : flats1) {
flats1_size += absl::CordTestPeer::Tree(flat)->flat()->AllocatedSize();
cord1.Append(std::move(flat));
}
// Make sure the created cord is a CONCAT tree. Under some builds such as
// windows DLL, we may have ODR like effects on the flag, meaning the DLL
// code will run with the picked up default.
if (!absl::CordTestPeer::Tree(cord1)->IsConcat()) {
ABSL_RAW_LOG(WARNING, "Cord library code not respecting btree flag");
return;
}
size_t rep1_size = sizeof(CordRepConcat) * 3 + flats1_size;
size_t rep1_shared_size = sizeof(CordRepConcat) * 3 + flats1_size / 2;
EXPECT_EQ(cord1.EstimatedMemoryUsage(), sizeof(absl::Cord) + rep1_size);
EXPECT_EQ(cord1.EstimatedMemoryUsage(kFairShare),
sizeof(absl::Cord) + rep1_shared_size);
absl::Cord cord2;
size_t flats2_size = 0;
absl::Cord flats2[4] = {MakeCord(600, 'a'), MakeCord(700, 'a'),
MakeCord(800, 'a'), MakeCord(900, 'a')};
for (absl::Cord& flat : flats2) {
flats2_size += absl::CordTestPeer::Tree(flat)->flat()->AllocatedSize();
cord2.Append(std::move(flat));
}
size_t rep2_size = sizeof(CordRepConcat) * 3 + flats2_size;
EXPECT_EQ(cord2.EstimatedMemoryUsage(), sizeof(absl::Cord) + rep2_size);
EXPECT_EQ(cord2.EstimatedMemoryUsage(kFairShare),
sizeof(absl::Cord) + rep2_size);
absl::Cord cord(cord1);
cord.Append(std::move(cord2));
EXPECT_EQ(cord.EstimatedMemoryUsage(),
sizeof(absl::Cord) + sizeof(CordRepConcat) + rep1_size + rep2_size);
EXPECT_EQ(cord.EstimatedMemoryUsage(kFairShare),
sizeof(absl::Cord) + sizeof(CordRepConcat) + rep1_shared_size / 2 +
rep2_size);
}
// Regtest for a change that had to be rolled back because it expanded out
// of the InlineRep too soon, which was observable through MemoryUsage().
TEST_P(CordTest, CordMemoryUsageInlineRep) {

@ -27,7 +27,6 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace cord_internal {
ABSL_CONST_INIT std::atomic<bool> cord_btree_enabled(kCordEnableBtreeDefault);
ABSL_CONST_INIT std::atomic<bool> cord_ring_buffer_enabled(
kCordEnableRingBufferDefault);
ABSL_CONST_INIT std::atomic<bool> shallow_subcords_enabled(

@ -37,12 +37,10 @@ class CordzInfo;
// Default feature enable states for cord ring buffers
enum CordFeatureDefaults {
kCordEnableBtreeDefault = true,
kCordEnableRingBufferDefault = false,
kCordShallowSubcordsDefault = false
};
extern std::atomic<bool> cord_btree_enabled;
extern std::atomic<bool> cord_ring_buffer_enabled;
extern std::atomic<bool> shallow_subcords_enabled;
@ -52,10 +50,6 @@ extern std::atomic<bool> shallow_subcords_enabled;
// O(n^2) complexity as recursive / full tree validation is O(n).
extern std::atomic<bool> cord_btree_exhaustive_validation;
inline void enable_cord_btree(bool enable) {
cord_btree_enabled.store(enable, std::memory_order_relaxed);
}
inline void enable_cord_ring_buffer(bool enable) {
cord_ring_buffer_enabled.store(enable, std::memory_order_relaxed);
}

@ -35,12 +35,18 @@ namespace strings_internal {
// below.
template <typename T>
struct StringConstant {
private:
static constexpr bool TryConstexprEval(absl::string_view view) {
return view.empty() || 2 * view[0] != 1;
}
public:
static constexpr absl::string_view value = T{}();
constexpr absl::string_view operator()() const { return value; }
// Check to be sure `view` points to constant data.
// Otherwise, it can't be constant evaluated.
static_assert(value.empty() || 2 * value[0] != 1,
static_assert(TryConstexprEval(value),
"The input string_view must point to constant data.");
};

@ -52,6 +52,7 @@
#include <atomic>
#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
@ -74,7 +75,7 @@ class Notification {
// Notification::HasBeenNotified()
//
// Returns the value of the notification's internal "notified" state.
bool HasBeenNotified() const {
ABSL_MUST_USE_RESULT bool HasBeenNotified() const {
return HasBeenNotifiedInternal(&this->notified_yet_);
}

Loading…
Cancel
Save