Skip to content

Commit c695489

Browse files
Abseil Teamderekmauro
authored andcommitted
Export of internal Abseil changes
-- 66a0a46462692378f77518f9db766a218bfac40b by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 300565981 -- 2a1ad67662b2e22beec7d3be019e6bba23c41c7f by Derek Mauro <[email protected]>: Fix CompressedTuple move constructor on MSVC Imports GitHub #637 PiperOrigin-RevId: 300545840 -- a3ee3ad036bbb6b0031121fd58299e5c59a243e1 by Derek Mauro <[email protected]>: Disable LLVM's XRay instrumentation on Android Fixes #626 PiperOrigin-RevId: 300540906 -- 87999244b1f825e585ec12a431086cb60daeb24f by Gennadiy Rozental <[email protected]>: Increase max cord depth by 2. After reviewing of the paper we can prove that the algorithm in fact can lead to slightly larger max depth. PiperOrigin-RevId: 300422376 -- 98de175ee8ad33290ef883c167c2de4414a11007 by Abseil Team <[email protected]>: Use *opt/opt-> instead of opt.value() in an example, after checking the optional has a value. PiperOrigin-RevId: 300253502 -- 1107aa0acf0fe743ef50173e02e48f0d4eb572ef by Derek Mauro <[email protected]>: Stop overriding the default system C++ dialect in CMake CMake on MacOS has some very strange defaults, like Wno-c++11-extensions, and doesn't seem to respect CMAKE_CXX_STANDARD, so use CMAKE_CXX_FLAGS instead. PiperOrigin-RevId: 300180753 GitOrigin-RevId: 66a0a46462692378f77518f9db766a218bfac40b Change-Id: Icd7b84c49306441b012cb87f244cc92a11697db8
1 parent b92f35f commit c695489

File tree

7 files changed

+33
-53
lines changed

7 files changed

+33
-53
lines changed

absl/base/attributes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,10 @@
507507
// packages/targets, as this may lead to conflicting definitions of functions at
508508
// link-time.
509509
//
510+
// XRay isn't currently supported on Android:
511+
// https://github.com/android/ndk/issues/368
510512
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_always_instrument) && \
511-
!defined(ABSL_NO_XRAY_ATTRIBUTES)
513+
!defined(ABSL_NO_XRAY_ATTRIBUTES) && !defined(__ANDROID__)
512514
#define ABSL_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]]
513515
#define ABSL_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]]
514516
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_log_args)

absl/copts/AbseilConfigureCopts.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,3 @@ else()
6363
set(ABSL_DEFAULT_COPTS "")
6464
set(ABSL_TEST_COPTS "")
6565
endif()
66-
67-
if("${CMAKE_CXX_STANDARD}" EQUAL 98)
68-
message(FATAL_ERROR "Abseil requires at least C++11")
69-
elseif(NOT "${CMAKE_CXX_STANDARD}")
70-
message(STATUS "No CMAKE_CXX_STANDARD set, assuming 11")
71-
set(ABSL_CXX_STANDARD 11)
72-
else()
73-
set(ABSL_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
74-
endif()

absl/strings/cord.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,20 @@ static constexpr size_t TagToLength(uint8_t tag) {
187187
// Enforce that kMaxFlatSize maps to a well-known exact tag value.
188188
static_assert(TagToAllocatedSize(224) == kMaxFlatSize, "Bad tag logic");
189189

190-
constexpr uint64_t Fibonacci(uint8_t n, uint64_t a = 0, uint64_t b = 1) {
191-
return n == 0 ? a : n == 1 ? b : Fibonacci(n - 1, b, a + b);
190+
constexpr size_t Fibonacci(uint8_t n, const size_t a = 0, const size_t b = 1) {
191+
return n == 0
192+
? a
193+
: n == 1 ? b
194+
: Fibonacci(n - 1, b,
195+
(a > (size_t(-1) - b)) ? size_t(-1) : a + b);
192196
}
193197

194-
static_assert(Fibonacci(63) == 6557470319842,
195-
"Fibonacci values computed incorrectly");
196-
197198
// Minimum length required for a given depth tree -- a tree is considered
198199
// balanced if
199200
// length(t) >= kMinLength[depth(t)]
200201
// The node depth is allowed to become larger to reduce rebalancing
201202
// for larger strings (see ShouldRebalance).
202-
constexpr uint64_t kMinLength[] = {
203+
constexpr size_t kMinLength[] = {
203204
Fibonacci(2), Fibonacci(3), Fibonacci(4), Fibonacci(5), Fibonacci(6),
204205
Fibonacci(7), Fibonacci(8), Fibonacci(9), Fibonacci(10), Fibonacci(11),
205206
Fibonacci(12), Fibonacci(13), Fibonacci(14), Fibonacci(15), Fibonacci(16),
@@ -218,9 +219,9 @@ constexpr uint64_t kMinLength[] = {
218219
Fibonacci(77), Fibonacci(78), Fibonacci(79), Fibonacci(80), Fibonacci(81),
219220
Fibonacci(82), Fibonacci(83), Fibonacci(84), Fibonacci(85), Fibonacci(86),
220221
Fibonacci(87), Fibonacci(88), Fibonacci(89), Fibonacci(90), Fibonacci(91),
221-
Fibonacci(92), Fibonacci(93)};
222+
Fibonacci(92), Fibonacci(93), Fibonacci(94), Fibonacci(95)};
222223

223-
static_assert(sizeof(kMinLength) / sizeof(uint64_t) ==
224+
static_assert(sizeof(kMinLength) / sizeof(size_t) >=
224225
(cord_internal::MaxCordDepth() + 1),
225226
"Not enough elements in kMinLength array to cover all the "
226227
"supported Cord depth(s)");
@@ -1169,9 +1170,9 @@ class CordForest {
11691170
void AddNode(CordRep* node) {
11701171
CordRep* sum = nullptr;
11711172

1172-
// Collect together everything with which we will merge node
1173+
// Collect together everything with which we will merge with node
11731174
int i = 0;
1174-
for (; node->length > kMinLength[i + 1]; ++i) {
1175+
for (; node->length >= kMinLength[i + 1]; ++i) {
11751176
auto& tree_at_i = trees_[i];
11761177

11771178
if (tree_at_i == nullptr) continue;

absl/strings/cord.h

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,21 @@ namespace cord_internal {
7272
// It's expensive to keep a tree perfectly balanced, so instead we keep trees
7373
// approximately balanced. A tree node N of depth D(N) that contains a string
7474
// of L(N) characters is considered balanced if L >= Fibonacci(D + 2).
75-
// The "+ 2" is used to ensure that every leaf node contains at least one
76-
// character. Here we presume that
75+
// The "+ 2" is used to ensure that every balanced leaf node contains at least
76+
// one character. Here we presume that
7777
// Fibonacci(0) = 0
7878
// Fibonacci(1) = 1
7979
// Fibonacci(2) = 1
8080
// Fibonacci(3) = 2
8181
// ...
82-
//
83-
// Fibonacci numbers are convenient because it means when two balanced trees of
84-
// the same depth are made the children of a new node, the resulting tree is
85-
// guaranteed to also be balanced:
86-
//
87-
//
88-
// L(left) >= Fibonacci(D(left) + 2)
89-
// L(right) >= Fibonacci(D(right) + 2)
90-
//
91-
// L(left) + L(right) >= Fibonacci(D(left) + 2) + Fibonacci(D(right) + 2)
92-
// L(left) + L(right) == L(new_tree)
93-
//
94-
// L(new_tree) >= 2 * Fibonacci(D(child) + 2)
95-
// D(child) == D(new_tree) - 1
96-
//
97-
// L(new_tree) >= 2 * Fibonacci(D(new_tree) + 1)
98-
// 2 * Fibonacci(N) >= Fibonacci(N + 1)
99-
//
100-
// L(new_tree) >= Fibonacci(D(new_tree) + 2)
101-
//
102-
//
103-
// The 93rd Fibonacci number is the largest Fibonacci number that can be
104-
// represented in 64 bits, so the size of a balanced Cord of depth 92 is too big
105-
// for an unsigned 64 bit integer to hold. Therefore we can safely assume that
106-
// the maximum depth of a Cord is 91.
107-
constexpr size_t MaxCordDepth() { return 91; }
82+
// The algorithm is based on paper by Hans Boehm et al:
83+
// https://www.cs.rit.edu/usr/local/pub/jeh/courses/QUARTERS/FP/Labs/CedarRope/rope-paper.pdf
84+
// In this paper authors shows that rebalancing based on cord forest of already
85+
// balanced subtrees can be proven to never produce tree of depth larger than
86+
// largest Fibonacci number representable in the same integral type as cord size
87+
// For 64 bit integers this is the 93rd Fibonacci number. For 32 bit integrals
88+
// this is 47th Fibonacci number.
89+
constexpr size_t MaxCordDepth() { return sizeof(size_t) == 8 ? 93 : 47; }
10890

10991
// This class models fixed max size stack of CordRep pointers.
11092
// The elements are being pushed back and popped from the back.

absl/strings/cord_test.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,12 +1403,16 @@ TEST(CordChunkIterator, Operations) {
14031403
}
14041404

14051405
TEST(CordChunkIterator, MaxLengthFullTree) {
1406+
// Start with a 1-byte cord, and then double its length in a loop. We should
1407+
// be able to do this until the point where we would overflow size_t.
1408+
14061409
absl::Cord cord;
14071410
size_t size = 1;
14081411
AddExternalMemory("x", &cord);
14091412
EXPECT_EQ(cord.size(), size);
14101413

1411-
for (int i = 0; i < 63; ++i) {
1414+
const int kCordLengthDoublingLimit = std::numeric_limits<size_t>::digits - 1;
1415+
for (int i = 0; i < kCordLengthDoublingLimit; ++i) {
14121416
cord.Prepend(absl::Cord(cord));
14131417
size <<= 1;
14141418

@@ -1431,7 +1435,7 @@ TEST(CordChunkIterator, MaxDepth) {
14311435
AddExternalMemory("x", &left_child);
14321436
absl::Cord root = left_child;
14331437

1434-
for (int i = 0; i < 91; ++i) {
1438+
for (int i = 0; i < absl::cord_internal::MaxCordDepth() - 2; ++i) {
14351439
size_t new_size = left_child.size() + root.size();
14361440
root.Prepend(left_child);
14371441
EXPECT_EQ(root.size(), new_size);
@@ -1442,7 +1446,7 @@ TEST(CordChunkIterator, MaxDepth) {
14421446
std::swap(left_child, root);
14431447
}
14441448

1445-
EXPECT_DEATH_IF_SUPPORTED(root.Prepend(left_child), "Cord depth exceeds max");
1449+
EXPECT_DEATH_IF_SUPPORTED(root.Prepend(left_child), "Cord is too long");
14461450
}
14471451

14481452
TEST(CordCharIterator, Traits) {

absl/types/optional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class optional : private optional_internal::optional_data<T>,
444444
// Returns false if and only if the `optional` is empty.
445445
//
446446
// if (opt) {
447-
// // do something with opt.value();
447+
// // do something with *opt or opt->;
448448
// } else {
449449
// // opt is empty.
450450
// }

ci/macos_xcode_cmake.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
3636
time cmake ${ABSEIL_ROOT} \
3737
-GXcode \
3838
-DCMAKE_BUILD_TYPE=${compilation_mode} \
39-
-DCMAKE_CXX_STANDARD=11 \
39+
-DCMAKE_CXX_FLAGS=-std=c++14 \
4040
-DABSL_USE_GOOGLETEST_HEAD=ON \
4141
-DABSL_RUN_TESTS=ON
4242
time cmake --build .

0 commit comments

Comments
 (0)