Commit fbf0fdab by Abseil Team Committed by Gennadiy Rozental

Export of internal Abseil changes

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

Remove the Bazel mirror URL that we use in our WORKSPACE file

This doesn't appear to be supported. We use --distdir caching in our tests.

PiperOrigin-RevId: 327634738

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

Removing comments following license() rules as they are rarely useful, redundant with LICENSE files, and tend to fall out of date.

PiperOrigin-RevId: 327504063

--
b59c076638a57a74a3f8475f1dee8b536e32a15f by Gennadiy Rozental <rogeeff@google.com>:

Change GetAllFlags API to return a collection of mutable flag handles.

This will make this interface on par with FindCommandLineFlag and allow to call
CommandLineFlag::ParseFrom on the handle returned by GetAllFlags.
PiperOrigin-RevId: 327499084

--
bbf56b3c4a1d908d95e5a52aba38b1984151efff by Gennadiy Rozental <rogeeff@google.com>:

Make raw_hash_set compile when AllocTraits::propagate_on_container_swap is false.

PiperOrigin-RevId: 327371107

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

On macOS, `mem_alloc` is defined like this:

rpc/types.h:86:#define mem_alloc(bsize)	calloc(1, bsize)

So if that file is included before container_memory.h, the variable mem_alloc
may never get defined. This is fixed by using a different name.

PiperOrigin-RevId: 327360224

--
aa8f5528382c0d01239ce75b645723aaf7e1ef46 by Gennadiy Rozental <rogeeff@google.com>:

Release of absl::GetAllFlags API.

PiperOrigin-RevId: 327275943
GitOrigin-RevId: 9f746b79e16d36dba908ed9e2a586d890fe54acc
Change-Id: I99c5c87dd1712bf8df9a52397b0c1e400a3c3447
parent dc969f34
...@@ -39,7 +39,6 @@ http_archive( ...@@ -39,7 +39,6 @@ http_archive(
sha256 = "9a446e9dd9c1bb180c86977a8dc1e9e659550ae732ae58bd2e8fd51e15b2c91d", sha256 = "9a446e9dd9c1bb180c86977a8dc1e9e659550ae732ae58bd2e8fd51e15b2c91d",
strip_prefix = "rules_cc-262ebec3c2296296526740db4aefce68c80de7fa", strip_prefix = "rules_cc-262ebec3c2296296526740db4aefce68c80de7fa",
urls = [ urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip",
"https://github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip", "https://github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip",
], ],
) )
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "algorithm", name = "algorithm",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "atomic_hook", name = "atomic_hook",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "compressed_tuple", name = "compressed_tuple",
......
...@@ -57,8 +57,11 @@ void* Allocate(Alloc* alloc, size_t n) { ...@@ -57,8 +57,11 @@ void* Allocate(Alloc* alloc, size_t n) {
using M = AlignedType<Alignment>; using M = AlignedType<Alignment>;
using A = typename absl::allocator_traits<Alloc>::template rebind_alloc<M>; using A = typename absl::allocator_traits<Alloc>::template rebind_alloc<M>;
using AT = typename absl::allocator_traits<Alloc>::template rebind_traits<M>; using AT = typename absl::allocator_traits<Alloc>::template rebind_traits<M>;
A mem_alloc(*alloc); // On macOS, "mem_alloc" is a #define with one argument defined in
void* p = AT::allocate(mem_alloc, (n + sizeof(M) - 1) / sizeof(M)); // rpc/types.h, so we can't name the variable "mem_alloc" and initialize it
// with the "foo(bar)" syntax.
A my_mem_alloc(*alloc);
void* p = AT::allocate(my_mem_alloc, (n + sizeof(M) - 1) / sizeof(M));
assert(reinterpret_cast<uintptr_t>(p) % Alignment == 0 && assert(reinterpret_cast<uintptr_t>(p) % Alignment == 0 &&
"allocator does not respect alignment"); "allocator does not respect alignment");
return p; return p;
...@@ -73,8 +76,11 @@ void Deallocate(Alloc* alloc, void* p, size_t n) { ...@@ -73,8 +76,11 @@ void Deallocate(Alloc* alloc, void* p, size_t n) {
using M = AlignedType<Alignment>; using M = AlignedType<Alignment>;
using A = typename absl::allocator_traits<Alloc>::template rebind_alloc<M>; using A = typename absl::allocator_traits<Alloc>::template rebind_alloc<M>;
using AT = typename absl::allocator_traits<Alloc>::template rebind_traits<M>; using AT = typename absl::allocator_traits<Alloc>::template rebind_traits<M>;
A mem_alloc(*alloc); // On macOS, "mem_alloc" is a #define with one argument defined in
AT::deallocate(mem_alloc, static_cast<M*>(p), // rpc/types.h, so we can't name the variable "mem_alloc" and initialize it
// with the "foo(bar)" syntax.
A my_mem_alloc(*alloc);
AT::deallocate(my_mem_alloc, static_cast<M*>(p),
(n + sizeof(M) - 1) / sizeof(M)); (n + sizeof(M) - 1) / sizeof(M));
} }
......
...@@ -122,6 +122,16 @@ namespace absl { ...@@ -122,6 +122,16 @@ namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace container_internal { namespace container_internal {
template <typename AllocType>
void SwapAlloc(AllocType& lhs, AllocType& rhs,
std::true_type /* propagate_on_container_swap */) {
using std::swap;
swap(lhs, rhs);
}
template <typename AllocType>
void SwapAlloc(AllocType& /*lhs*/, AllocType& /*rhs*/,
std::false_type /* propagate_on_container_swap */) {}
template <size_t Width> template <size_t Width>
class probe_seq { class probe_seq {
public: public:
...@@ -169,10 +179,14 @@ struct IsDecomposable< ...@@ -169,10 +179,14 @@ struct IsDecomposable<
// TODO(alkis): Switch to std::is_nothrow_swappable when gcc/clang supports it. // TODO(alkis): Switch to std::is_nothrow_swappable when gcc/clang supports it.
template <class T> template <class T>
constexpr bool IsNoThrowSwappable() { constexpr bool IsNoThrowSwappable(std::true_type = {} /* is_swappable */) {
using std::swap; using std::swap;
return noexcept(swap(std::declval<T&>(), std::declval<T&>())); return noexcept(swap(std::declval<T&>(), std::declval<T&>()));
} }
template <class T>
constexpr bool IsNoThrowSwappable(std::false_type /* is_swappable */) {
return false;
}
template <typename T> template <typename T>
int TrailingZeros(T x) { int TrailingZeros(T x) {
...@@ -1231,8 +1245,8 @@ class raw_hash_set { ...@@ -1231,8 +1245,8 @@ class raw_hash_set {
void swap(raw_hash_set& that) noexcept( void swap(raw_hash_set& that) noexcept(
IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() && IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() &&
(!AllocTraits::propagate_on_container_swap::value || IsNoThrowSwappable<allocator_type>(
IsNoThrowSwappable<allocator_type>())) { typename AllocTraits::propagate_on_container_swap{})) {
using std::swap; using std::swap;
swap(ctrl_, that.ctrl_); swap(ctrl_, that.ctrl_);
swap(slots_, that.slots_); swap(slots_, that.slots_);
...@@ -1242,12 +1256,8 @@ class raw_hash_set { ...@@ -1242,12 +1256,8 @@ class raw_hash_set {
swap(hash_ref(), that.hash_ref()); swap(hash_ref(), that.hash_ref());
swap(eq_ref(), that.eq_ref()); swap(eq_ref(), that.eq_ref());
swap(infoz_, that.infoz_); swap(infoz_, that.infoz_);
if (AllocTraits::propagate_on_container_swap::value) { SwapAlloc(alloc_ref(), that.alloc_ref(),
swap(alloc_ref(), that.alloc_ref()); typename AllocTraits::propagate_on_container_swap{});
} else {
// If the allocators do not compare equal it is officially undefined
// behavior. We choose to do nothing.
}
} }
void rehash(size_t n) { void rehash(size_t n) {
......
...@@ -424,6 +424,77 @@ TEST_F(PropagateOnAll, Swap) { ...@@ -424,6 +424,77 @@ TEST_F(PropagateOnAll, Swap) {
EXPECT_EQ(0, it->num_copies()); EXPECT_EQ(0, it->num_copies());
} }
// This allocator is similar to std::pmr::polymorphic_allocator.
// Note the disabled assignment.
template <class T>
class PAlloc {
template <class>
friend class PAlloc;
public:
// types
using value_type = T;
// traits
using propagate_on_container_swap = std::false_type;
PAlloc() noexcept = default;
explicit PAlloc(size_t id) noexcept : id_(id) {}
PAlloc(const PAlloc&) noexcept = default;
PAlloc& operator=(const PAlloc&) noexcept = delete;
template <class U>
PAlloc(const PAlloc<U>& that) noexcept : id_(that.id_) {} // NOLINT
template <class U>
struct rebind {
using other = PAlloc<U>;
};
constexpr PAlloc select_on_container_copy_construction() const { return {}; }
// public member functions
T* allocate(size_t) { return new T; }
void deallocate(T* p, size_t) { delete p; }
friend bool operator==(const PAlloc& a, const PAlloc& b) {
return a.id_ == b.id_;
}
friend bool operator!=(const PAlloc& a, const PAlloc& b) { return !(a == b); }
private:
size_t id_ = std::numeric_limits<size_t>::max();
};
TEST(NoPropagateOn, Swap) {
using PA = PAlloc<char>;
using Table = raw_hash_set<Policy, Identity, std::equal_to<int32_t>, PA>;
Table t1(PA{1}), t2(PA{2});
swap(t1, t2);
EXPECT_EQ(t1.get_allocator(), PA(1));
EXPECT_EQ(t2.get_allocator(), PA(2));
}
TEST(NoPropagateOn, CopyConstruct) {
using PA = PAlloc<char>;
using Table = raw_hash_set<Policy, Identity, std::equal_to<int32_t>, PA>;
Table t1(PA{1}), t2(t1);
EXPECT_EQ(t1.get_allocator(), PA(1));
EXPECT_EQ(t2.get_allocator(), PA());
}
TEST(NoPropagateOn, Assignment) {
using PA = PAlloc<char>;
using Table = raw_hash_set<Policy, Identity, std::equal_to<int32_t>, PA>;
Table t1(PA{1}), t2(PA{2});
t1 = t2;
EXPECT_EQ(t1.get_allocator(), PA(1));
EXPECT_EQ(t2.get_allocator(), PA(2));
}
} // namespace } // namespace
} // namespace container_internal } // namespace container_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
......
...@@ -26,7 +26,7 @@ package( ...@@ -26,7 +26,7 @@ package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
) )
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "stacktrace", name = "stacktrace",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "path_util", name = "path_util",
...@@ -179,6 +179,7 @@ cc_library( ...@@ -179,6 +179,7 @@ cc_library(
":private_handle_accessor", ":private_handle_accessor",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/container:flat_hash_map",
"//absl/strings", "//absl/strings",
"//absl/synchronization", "//absl/synchronization",
], ],
...@@ -464,6 +465,7 @@ cc_test( ...@@ -464,6 +465,7 @@ cc_test(
":flag", ":flag",
":marshalling", ":marshalling",
":reflection", ":reflection",
":usage_internal",
"//absl/memory", "//absl/memory",
"//absl/strings", "//absl/strings",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
......
...@@ -165,6 +165,7 @@ absl_cc_library( ...@@ -165,6 +165,7 @@ absl_cc_library(
absl::flags_config absl::flags_config
absl::strings absl::strings
absl::synchronization absl::synchronization
absl::flat_hash_map
) )
# Internal-only target, do not depend on directly. # Internal-only target, do not depend on directly.
...@@ -407,9 +408,10 @@ absl_cc_test( ...@@ -407,9 +408,10 @@ absl_cc_test(
absl::flags_commandlineflag_internal absl::flags_commandlineflag_internal
absl::flags absl::flags
absl::flags_reflection absl::flags_reflection
absl::flags_usage
absl::memory absl::memory
absl::strings absl::strings
gtest_main gmock_main
) )
absl_cc_test( absl_cc_test(
......
...@@ -303,5 +303,15 @@ CommandLineFlag* FindCommandLineFlag(absl::string_view name) { ...@@ -303,5 +303,15 @@ CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
return registry.FindFlagLocked(name); return registry.FindFlagLocked(name);
} }
// --------------------------------------------------------------------
absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags() {
absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> res;
flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
res.insert({flag.Name(), &flag});
});
return res;
}
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <string> #include <string>
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/container/flat_hash_map.h"
#include "absl/flags/commandlineflag.h" #include "absl/flags/commandlineflag.h"
#include "absl/flags/internal/commandlineflag.h" #include "absl/flags/internal/commandlineflag.h"
...@@ -40,7 +41,11 @@ class FlagSaverImpl; ...@@ -40,7 +41,11 @@ class FlagSaverImpl;
// Returns the reflection handle of an Abseil flag of the specified name, or // Returns the reflection handle of an Abseil flag of the specified name, or
// `nullptr` if not found. This function will emit a warning if the name of a // `nullptr` if not found. This function will emit a warning if the name of a
// 'retired' flag is specified. // 'retired' flag is specified.
CommandLineFlag* FindCommandLineFlag(absl::string_view name); absl::CommandLineFlag* FindCommandLineFlag(absl::string_view name);
// Returns current state of the Flags registry in a form of mapping from flag
// name to a flag reflection handle.
absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// FlagSaver // FlagSaver
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/flags/declare.h"
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/flags/internal/commandlineflag.h" #include "absl/flags/internal/commandlineflag.h"
#include "absl/flags/marshalling.h" #include "absl/flags/marshalling.h"
...@@ -30,6 +32,8 @@ ABSL_FLAG(int, int_flag, 1, "int_flag help"); ...@@ -30,6 +32,8 @@ ABSL_FLAG(int, int_flag, 1, "int_flag help");
ABSL_FLAG(std::string, string_flag, "dflt", "string_flag help"); ABSL_FLAG(std::string, string_flag, "dflt", "string_flag help");
ABSL_RETIRED_FLAG(bool, bool_retired_flag, false, "bool_retired_flag help"); ABSL_RETIRED_FLAG(bool, bool_retired_flag, false, "bool_retired_flag help");
ABSL_DECLARE_FLAG(bool, help);
namespace { namespace {
namespace flags = absl::flags_internal; namespace flags = absl::flags_internal;
...@@ -61,6 +65,33 @@ TEST_F(ReflectionTest, TestFindCommandLineFlag) { ...@@ -61,6 +65,33 @@ TEST_F(ReflectionTest, TestFindCommandLineFlag) {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
TEST_F(ReflectionTest, TestGetAllFlags) {
(void)absl::GetFlag(FLAGS_help); // Force linking of usage flags.
auto all_flags = absl::GetAllFlags();
EXPECT_NE(all_flags.find("int_flag"), all_flags.end());
EXPECT_NE(all_flags.find("bool_retired_flag"), all_flags.end());
EXPECT_NE(all_flags.find("help"), all_flags.end());
EXPECT_EQ(all_flags.find("some_undefined_flag"), all_flags.end());
std::vector<absl::string_view> flag_names_first_attempt;
auto all_flags_1 = absl::GetAllFlags();
for (auto f : all_flags_1) {
flag_names_first_attempt.push_back(f.first);
}
std::vector<absl::string_view> flag_names_second_attempt;
auto all_flags_2 = absl::GetAllFlags();
for (auto f : all_flags_2) {
flag_names_second_attempt.push_back(f.first);
}
EXPECT_THAT(flag_names_first_attempt,
::testing::UnorderedElementsAreArray(flag_names_second_attempt));
}
// --------------------------------------------------------------------
struct CustomUDT { struct CustomUDT {
CustomUDT() : a(1), b(1) {} CustomUDT() : a(1), b(1) {}
CustomUDT(int a_, int b_) : a(a_), b(b_) {} CustomUDT(int a_, int b_) : a(a_), b(b_) {}
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "bind_front", name = "bind_front",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "hash", name = "hash",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "memory", name = "memory",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "type_traits", name = "type_traits",
......
...@@ -22,7 +22,7 @@ load( ...@@ -22,7 +22,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "int128", name = "int128",
......
...@@ -30,7 +30,7 @@ package(default_visibility = [ ...@@ -30,7 +30,7 @@ package(default_visibility = [
"//absl/random:__pkg__", "//absl/random:__pkg__",
]) ])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "traits", name = "traits",
......
...@@ -26,7 +26,7 @@ load( ...@@ -26,7 +26,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "status", name = "status",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
# Internal data structure for efficiently detecting mutex dependency cycles # Internal data structure for efficiently detecting mutex dependency cycles
cc_library( cc_library(
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "time", name = "time",
......
...@@ -23,7 +23,7 @@ load( ...@@ -23,7 +23,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "any", name = "any",
......
...@@ -24,7 +24,7 @@ load( ...@@ -24,7 +24,7 @@ load(
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0 licenses(["notice"])
cc_library( cc_library(
name = "utility", name = "utility",
......
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