Commit 4ef57406 by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
3dbb096e4662311f81df1017a8e0975e903936cf by Derek Mauro <dmauro@google.com>:

Document and workaround a known MSVC bug doing constexpr pointer arithmetic

PiperOrigin-RevId: 262604652

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

Fix typo in macos_xcode_bazel.sh

PiperOrigin-RevId: 262591285

--
89dd77ab5bb44d76b6cb6b2f288e21536e16a85a by Derek Mauro <dmauro@google.com>:

Internal change

PiperOrigin-RevId: 262582747

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

Internal change

PiperOrigin-RevId: 262569140

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

Internal change

PiperOrigin-RevId: 262563554

--
314aed043639abbd221074125c57b7c68616de7e by Derek Mauro <dmauro@google.com>:

Release absl::btree

PiperOrigin-RevId: 262553526

--
72b44056c6ce9000c4a6cd9aec58b82067c82a13 by CJ Johnson <johnsoncj@google.com>:

Internal change

PiperOrigin-RevId: 262421185

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

Update documentation to make it less likely for users to write `Hours(24)` without considering using civil dates instead.

PiperOrigin-RevId: 262420758

--
92b85b9573e800bd96b019408eefbc5ce4f68780 by Derek Mauro <dmauro@google.com>:

Add the ability to override the bazel version in the macos_xcode_bazel.sh
test script.

PiperOrigin-RevId: 262412063
GitOrigin-RevId: 3dbb096e4662311f81df1017a8e0975e903936cf
Change-Id: I423b2b829dc0c5f814e37bec4d68c7470f43f041
parent 9ee91d3e
...@@ -825,3 +825,72 @@ cc_test( ...@@ -825,3 +825,72 @@ cc_test(
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )
cc_library(
name = "btree",
srcs = [
"internal/btree.h",
"internal/btree_container.h",
],
hdrs = [
"btree_map.h",
"btree_set.h",
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:public"],
deps = [
":common",
":compressed_tuple",
":container_memory",
":layout",
"//absl/base:core_headers",
"//absl/base:throw_delegate",
"//absl/memory",
"//absl/meta:type_traits",
"//absl/strings",
"//absl/types:compare",
"//absl/utility",
],
)
cc_library(
name = "btree_test_common",
testonly = 1,
hdrs = ["btree_test.h"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [
":btree",
":flat_hash_set",
"//absl/strings",
"//absl/time",
],
)
cc_test(
name = "btree_test",
size = "large",
srcs = [
"btree_test.cc",
],
copts = ABSL_TEST_COPTS + ["-fexceptions"],
linkopts = ABSL_DEFAULT_LINKOPTS,
shard_count = 10,
visibility = ["//visibility:private"],
deps = [
":btree",
":btree_test_common",
":counting_allocator",
":test_instance_tracker",
"//absl/base",
"//absl/flags:flag",
"//absl/hash:hash_testing",
"//absl/memory",
"//absl/meta:type_traits",
"//absl/strings",
"//absl/types:compare",
"@com_google_googletest//:gtest_main",
],
)
...@@ -25,6 +25,68 @@ absl_cc_library( ...@@ -25,6 +25,68 @@ absl_cc_library(
absl_cc_library( absl_cc_library(
NAME NAME
btree
HDRS
"btree_map.h"
"btree_set.h"
"internal/btree.h"
"internal/btree_container.h"
COPTS
${ABSL_DEFAULT_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::container_common
absl::compare
absl::compressed_tuple
absl::container_memory
absl::core_headers
absl::layout
absl::memory
absl::strings
absl::throw_delegate
absl::type_traits
absl::utility
)
absl_cc_library(
NAME
btree_test_common
hdrs
"btree_test.h"
COPTS
${ABSL_TEST_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::btree
absl::flat_hash_set
absl::strings
absl::time
TESTONLY
)
absl_cc_test(
NAME
btree_test
SRCS
"btree_test.cc"
DEPS
absl::base
absl::btree
absl::btree_test_common
absl::compare
absl::counting_allocator
absl::flags
absl::hash_testing
absl::strings
absl::test_instance_tracker
absl::type_traits
gmock_main
)
absl_cc_library(
NAME
compressed_tuple compressed_tuple
HDRS HDRS
"internal/compressed_tuple.h" "internal/compressed_tuple.h"
......
// Copyright 2018 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ABSL_CONTAINER_BTREE_TEST_H_
#define ABSL_CONTAINER_BTREE_TEST_H_
#include <algorithm>
#include <cassert>
#include <random>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/btree_map.h"
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/time.h"
namespace absl {
namespace container_internal {
// Like remove_const but propagates the removal through std::pair.
template <typename T>
struct remove_pair_const {
using type = typename std::remove_const<T>::type;
};
template <typename T, typename U>
struct remove_pair_const<std::pair<T, U> > {
using type = std::pair<typename remove_pair_const<T>::type,
typename remove_pair_const<U>::type>;
};
// Utility class to provide an accessor for a key given a value. The default
// behavior is to treat the value as a pair and return the first element.
template <typename K, typename V>
struct KeyOfValue {
struct type {
const K& operator()(const V& p) const { return p.first; }
};
};
// Partial specialization of KeyOfValue class for when the key and value are
// the same type such as in set<> and btree_set<>.
template <typename K>
struct KeyOfValue<K, K> {
struct type {
const K& operator()(const K& k) const { return k; }
};
};
inline char* GenerateDigits(char buf[16], unsigned val, unsigned maxval) {
assert(val <= maxval);
constexpr unsigned kBase = 64; // avoid integer division.
unsigned p = 15;
buf[p--] = 0;
while (maxval > 0) {
buf[p--] = ' ' + (val % kBase);
val /= kBase;
maxval /= kBase;
}
return buf + p + 1;
}
template <typename K>
struct Generator {
int maxval;
explicit Generator(int m) : maxval(m) {}
K operator()(int i) const {
assert(i <= maxval);
return K(i);
}
};
template <>
struct Generator<absl::Time> {
int maxval;
explicit Generator(int m) : maxval(m) {}
absl::Time operator()(int i) const { return absl::FromUnixMillis(i); }
};
template <>
struct Generator<std::string> {
int maxval;
explicit Generator(int m) : maxval(m) {}
std::string operator()(int i) const {
char buf[16];
return GenerateDigits(buf, i, maxval);
}
};
template <typename T, typename U>
struct Generator<std::pair<T, U> > {
Generator<typename remove_pair_const<T>::type> tgen;
Generator<typename remove_pair_const<U>::type> ugen;
explicit Generator(int m) : tgen(m), ugen(m) {}
std::pair<T, U> operator()(int i) const {
return std::make_pair(tgen(i), ugen(i));
}
};
// Generate n values for our tests and benchmarks. Value range is [0, maxval].
inline std::vector<int> GenerateNumbersWithSeed(int n, int maxval, int seed) {
// NOTE: Some tests rely on generated numbers not changing between test runs.
// We use std::minstd_rand0 because it is well-defined, but don't use
// std::uniform_int_distribution because platforms use different algorithms.
std::minstd_rand0 rng(seed);
std::vector<int> values;
absl::flat_hash_set<int> unique_values;
if (values.size() < n) {
for (int i = values.size(); i < n; i++) {
int value;
do {
value = static_cast<int>(rng()) % (maxval + 1);
} while (!unique_values.insert(value).second);
values.push_back(value);
}
}
return values;
}
// Generates n values in the range [0, maxval].
template <typename V>
std::vector<V> GenerateValuesWithSeed(int n, int maxval, int seed) {
const std::vector<int> nums = GenerateNumbersWithSeed(n, maxval, seed);
Generator<V> gen(maxval);
std::vector<V> vec;
vec.reserve(n);
for (int i = 0; i < n; i++) {
vec.push_back(gen(nums[i]));
}
return vec;
}
} // namespace container_internal
} // namespace absl
#endif // ABSL_CONTAINER_BTREE_TEST_H_
...@@ -979,8 +979,16 @@ TEST(StringViewTest, ConstexprCompiles) { ...@@ -979,8 +979,16 @@ TEST(StringViewTest, ConstexprCompiles) {
constexpr absl::string_view::iterator const_end = cstr_len.end(); constexpr absl::string_view::iterator const_end = cstr_len.end();
constexpr absl::string_view::size_type const_size = cstr_len.size(); constexpr absl::string_view::size_type const_size = cstr_len.size();
constexpr absl::string_view::size_type const_length = cstr_len.length(); constexpr absl::string_view::size_type const_length = cstr_len.length();
static_assert(const_begin + const_size == const_end,
"pointer arithmetic check");
static_assert(const_begin + const_length == const_end,
"pointer arithmetic check");
#ifndef _MSC_VER
// MSVC has bugs doing constexpr pointer arithmetic.
// https://developercommunity.visualstudio.com/content/problem/482192/bad-pointer-arithmetic-in-constepxr-2019-rc1-svc1.html
EXPECT_EQ(const_begin + const_size, const_end); EXPECT_EQ(const_begin + const_size, const_end);
EXPECT_EQ(const_begin + const_length, const_end); EXPECT_EQ(const_begin + const_length, const_end);
#endif
constexpr bool isempty = sp.empty(); constexpr bool isempty = sp.empty();
EXPECT_TRUE(isempty); EXPECT_TRUE(isempty);
......
...@@ -380,11 +380,11 @@ constexpr Duration InfiniteDuration(); ...@@ -380,11 +380,11 @@ constexpr Duration InfiniteDuration();
// of the unit indicated by the factory function's name. The number must be // of the unit indicated by the factory function's name. The number must be
// representable as int64_t. // representable as int64_t.
// //
// Note: no "Days()" factory function exists because "a day" is ambiguous. // NOTE: no "Days()" factory function exists because "a day" is ambiguous.
// Civil days are not always 24 hours long, and a 24-hour duration often does // Civil days are not always 24 hours long, and a 24-hour duration often does
// not correspond with a civil day. If a 24-hour duration is needed, use // not correspond with a civil day. If a 24-hour duration is needed, use
// `absl::Hours(24)`. (If you actually want a civil day, use absl::CivilDay // `absl::Hours(24)`. If you actually want a civil day, use absl::CivilDay
// from civil_time.h.) // from civil_time.h.
// //
// Example: // Example:
// //
......
...@@ -23,16 +23,25 @@ if [ -z ${ABSEIL_ROOT:-} ]; then ...@@ -23,16 +23,25 @@ if [ -z ${ABSEIL_ROOT:-} ]; then
ABSEIL_ROOT="$(realpath $(dirname ${0})/..)" ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
fi fi
# Print the default compiler and Bazel versions. # If we are running on Kokoro, check for a versioned Bazel binary.
KOKORO_GFILE_BAZEL_BIN="bazel-0.28.1-darwin-x86_64"
if [ ${KOKORO_GFILE_DIR:-} ] && [ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]; then
BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}"
chmod +x ${BAZEL_BIN}
else
BAZEL_BIN="bazel"
fi
# Print the compiler and Bazel versions.
echo "---------------" echo "---------------"
gcc -v gcc -v
echo "---------------" echo "---------------"
bazel version ${BAZEL_BIN} version
echo "---------------" echo "---------------"
cd ${ABSEIL_ROOT} cd ${ABSEIL_ROOT}
bazel test ... \ ${BAZEL_BIN} test ... \
--copt=-Werror \ --copt=-Werror \
--keep_going \ --keep_going \
--show_timestamps \ --show_timestamps \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment