Skip to content

Commit 018b4db

Browse files
Abseil Teamshaindelschwartz
Abseil Team
authored andcommitted
Export of internal Abseil changes.
-- fd86c60bac6c41f1629ce1ab7dc1c8edff398a59 by Alex Strelnikov <strel@google.com>: Import PR: abseil#243 Fix Windows ARM64 intrinsic use. PiperOrigin-RevId: 228535649 -- a0ca663f606a3b31493683e405be2b1cff450894 by CJ Johnson <johnsoncj@google.com>: Fixes issue of mixed signedness comparison PiperOrigin-RevId: 228535623 -- d71aaa1705d7303b43fe02088fe07b153e647796 by Shaindel Schwartz <shaindel@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 228534365 -- c1b49d361aa880198e071f93997724bddbcd4760 by Samuel Benzaquen <sbenza@google.com>: Internal cleanup PiperOrigin-RevId: 228406627 -- 0c4b1c2bed107698e209055b3431771d7a1bdba1 by Dave Walker <dawalker@google.com>: Add comments about the purpose of container_internal::slot_type. PiperOrigin-RevId: 228264537 -- 060aa6077d2f3a0a129149e0644d19f2f521b241 by Abseil Team <absl-team@google.com>: #include <cmath> in hashtablez_sampler.cc Expected to fix the android build. PiperOrigin-RevId: 228222550 GitOrigin-RevId: fd86c60bac6c41f1629ce1ab7dc1c8edff398a59 Change-Id: I26339fd4548c1a81b037cb52c26910d1bd850ea8
1 parent 9449ae9 commit 018b4db

File tree

11 files changed

+105
-33
lines changed

11 files changed

+105
-33
lines changed

absl/container/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,22 @@ cc_library(
510510
visibility = ["//visibility:private"],
511511
)
512512

513+
cc_library(
514+
name = "common",
515+
hdrs = ["internal/common.h"],
516+
copts = ABSL_DEFAULT_COPTS,
517+
deps = [
518+
"//absl/meta:type_traits",
519+
],
520+
)
521+
513522
cc_library(
514523
name = "raw_hash_set",
515524
srcs = ["internal/raw_hash_set.cc"],
516525
hdrs = ["internal/raw_hash_set.h"],
517526
copts = ABSL_DEFAULT_COPTS,
518527
deps = [
528+
":common",
519529
":compressed_tuple",
520530
":container_memory",
521531
":hash_policy_traits",

absl/container/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,17 @@ absl_cc_library(
527527
PUBLIC
528528
)
529529

530+
absl_cc_library(
531+
NAME
532+
container_common
533+
HDRS
534+
"internal/commom.h"
535+
COPTS
536+
${ABSL_DEFAULT_COPTS}
537+
DEPS
538+
absl::type_traits
539+
)
540+
530541
absl_cc_library(
531542
NAME
532543
raw_hash_set
@@ -540,6 +551,7 @@ absl_cc_library(
540551
absl::bits
541552
absl::compressed_tuple
542553
absl::config
554+
absl::container_common
543555
absl::container_memory
544556
absl::core_headers
545557
absl::endian

absl/container/internal/common.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2018 The Abseil Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef ABSL_CONTAINER_INTERNAL_CONTAINER_H_
16+
#define ABSL_CONTAINER_INTERNAL_CONTAINER_H_
17+
18+
#include <type_traits>
19+
20+
#include "absl/meta/type_traits.h"
21+
22+
namespace absl {
23+
namespace container_internal {
24+
25+
template <class, class = void>
26+
struct IsTransparent : std::false_type {};
27+
template <class T>
28+
struct IsTransparent<T, absl::void_t<typename T::is_transparent>>
29+
: std::true_type {};
30+
31+
template <bool is_transparent>
32+
struct KeyArg {
33+
// Transparent. Forward `K`.
34+
template <typename K, typename key_type>
35+
using type = K;
36+
};
37+
38+
template <>
39+
struct KeyArg<false> {
40+
// Not transparent. Always use `key_type`.
41+
template <typename K, typename key_type>
42+
using type = key_type;
43+
};
44+
45+
} // namespace container_internal
46+
} // namespace absl
47+
48+
#endif // ABSL_CONTAINER_INTERNAL_CONTAINER_H_

absl/container/internal/container_memory.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,30 @@ struct IsLayoutCompatible {
286286

287287
} // namespace memory_internal
288288

289-
// If kMutableKeys is false, only the value member is accessed.
289+
// The internal storage type for key-value containers like flat_hash_map.
290290
//
291-
// If kMutableKeys is true, key is accessed through all slots while value and
292-
// mutable_value are accessed only via INITIALIZED slots. Slots are created and
293-
// destroyed via mutable_value so that the key can be moved later.
291+
// It is convenient for the value_type of a flat_hash_map<K, V> to be
292+
// pair<const K, V>; the "const K" prevents accidental modification of the key
293+
// when dealing with the reference returned from find() and similar methods.
294+
// However, this creates other problems; we want to be able to emplace(K, V)
295+
// efficiently with move operations, and similarly be able to move a
296+
// pair<K, V> in insert().
297+
//
298+
// The solution is this union, which aliases the const and non-const versions
299+
// of the pair. This also allows flat_hash_map<const K, V> to work, even though
300+
// that has the same efficiency issues with move in emplace() and insert() -
301+
// but people do it anyway.
302+
//
303+
// If kMutableKeys is false, only the value member can be accessed.
304+
//
305+
// If kMutableKeys is true, key can be accessed through all slots while value
306+
// and mutable_value must be accessed only via INITIALIZED slots. Slots are
307+
// created and destroyed via mutable_value so that the key can be moved later.
308+
//
309+
// Accessing one of the union fields while the other is active is safe as
310+
// long as they are layout-compatible, which is guaranteed by the definition of
311+
// kMutableKeys. For C++11, the relevant section of the standard is
312+
// https://timsong-cpp.github.io/cppwp/n3337/class.mem#19 (9.2.19)
294313
template <class K, class V>
295314
union slot_type {
296315
private:

absl/container/internal/hashtablez_sampler.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <atomic>
1818
#include <cassert>
19+
#include <cmath>
1920
#include <functional>
2021
#include <limits>
2122

absl/container/internal/raw_hash_map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class raw_hash_map : public raw_hash_set<Policy, Hash, Eq, Alloc> {
3939
using MappedConstReference = decltype(P::value(
4040
std::addressof(std::declval<typename raw_hash_map::const_reference>())));
4141

42-
using KeyArgImpl = container_internal::KeyArg<IsTransparent<Eq>::value &&
43-
IsTransparent<Hash>::value>;
42+
using KeyArgImpl =
43+
KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;
4444

4545
public:
4646
using key_type = typename Policy::key_type;

absl/container/internal/raw_hash_set.h

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#include "absl/base/internal/bits.h"
106106
#include "absl/base/internal/endian.h"
107107
#include "absl/base/port.h"
108+
#include "absl/container/internal/common.h"
108109
#include "absl/container/internal/compressed_tuple.h"
109110
#include "absl/container/internal/container_memory.h"
110111
#include "absl/container/internal/hash_policy_traits.h"
@@ -165,12 +166,6 @@ struct IsDecomposable<
165166
std::declval<Ts>()...))>,
166167
Policy, Hash, Eq, Ts...> : std::true_type {};
167168

168-
template <class, class = void>
169-
struct IsTransparent : std::false_type {};
170-
template <class T>
171-
struct IsTransparent<T, absl::void_t<typename T::is_transparent>>
172-
: std::true_type {};
173-
174169
// TODO(alkis): Switch to std::is_nothrow_swappable when gcc/clang supports it.
175170
template <class T>
176171
constexpr bool IsNoThrowSwappable() {
@@ -605,24 +600,6 @@ struct insert_return_type {
605600
NodeType node;
606601
};
607602

608-
// Helper trait to allow or disallow arbitrary keys when the hash and
609-
// eq functions are transparent.
610-
// It is very important that the inner template is an alias and that the type it
611-
// produces is not a dependent type. Otherwise, type deduction would fail.
612-
template <bool is_transparent>
613-
struct KeyArg {
614-
// Transparent. Forward `K`.
615-
template <typename K, typename key_type>
616-
using type = K;
617-
};
618-
619-
template <>
620-
struct KeyArg<false> {
621-
// Not transparent. Always use `key_type`.
622-
template <typename K, typename key_type>
623-
using type = key_type;
624-
};
625-
626603
// Policy: a policy defines how to perform different operations on
627604
// the slots of the hashtable (see hash_policy_traits.h for the full interface
628605
// of policy).
@@ -643,8 +620,8 @@ struct KeyArg<false> {
643620
template <class Policy, class Hash, class Eq, class Alloc>
644621
class raw_hash_set {
645622
using PolicyTraits = hash_policy_traits<Policy>;
646-
using KeyArgImpl = container_internal::KeyArg<IsTransparent<Eq>::value &&
647-
IsTransparent<Hash>::value>;
623+
using KeyArgImpl =
624+
KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;
648625

649626
public:
650627
using init_type = typename PolicyTraits::init_type;

absl/synchronization/internal/thread_pool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define ABSL_SYNCHRONIZATION_INTERNAL_THREAD_POOL_H_
1717

1818
#include <cassert>
19+
#include <cstddef>
1920
#include <functional>
2021
#include <queue>
2122
#include <thread> // NOLINT(build/c++11)
@@ -42,7 +43,7 @@ class ThreadPool {
4243
~ThreadPool() {
4344
{
4445
absl::MutexLock l(&mu_);
45-
for (int i = 0; i < threads_.size(); ++i) {
46+
for (size_t i = 0; i < threads_.size(); i++) {
4647
queue_.push(nullptr); // Shutdown signal.
4748
}
4849
}

absl/time/internal/cctz/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ cc_test(
8787
"no_test_android_arm",
8888
"no_test_android_arm64",
8989
"no_test_android_x86",
90+
"no_test_wasm",
9091
],
9192
deps = [
9293
":civil_time",
@@ -105,6 +106,7 @@ cc_test(
105106
"no_test_android_arm",
106107
"no_test_android_arm64",
107108
"no_test_android_x86",
109+
"no_test_wasm",
108110
],
109111
deps = [
110112
":civil_time",

absl/time/internal/cctz/src/cctz_benchmark.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ const char* const kTimeZoneNames[] = {
357357
"Asia/Pontianak",
358358
"Asia/Pyongyang",
359359
"Asia/Qatar",
360+
"Asia/Qostanay",
360361
"Asia/Qyzylorda",
361362
"Asia/Rangoon",
362363
"Asia/Riyadh",

absl/time/internal/cctz/src/time_zone_lookup_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ const char* const kTimeZoneNames[] = {
337337
"Asia/Pontianak",
338338
"Asia/Pyongyang",
339339
"Asia/Qatar",
340+
"Asia/Qostanay",
340341
"Asia/Qyzylorda",
341342
"Asia/Rangoon",
342343
"Asia/Riyadh",

0 commit comments

Comments
 (0)