about summary refs log tree commit diff
path: root/absl/flags/internal
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-05-19T00·53-0700
committerMark Barolak <mbar@google.com>2020-05-19T14·59-0400
commit768eb2ca2857342673fcd462792ce04b8bac3fa3 (patch)
tree7c7951bde3dd27933b1d85621d7abf01179c0377 /absl/flags/internal
parent3f347c46272886a099852a4cd303ecf37a054de8 (diff)
Export of internal Abseil changes
--
f012012ef78234a6a4585321b67d7b7c92ebc266 by Laramie Leavitt <lar@google.com>:

Slight restructuring of absl/random/internal randen implementation.

Convert round-keys.inc into randen_round_keys.cc file.

Consistently use a 128-bit pointer type for internal method parameters. This allows simpler pointer arithmetic in C++ & permits removal of some constants and casts.

Remove some redundancy in comments & constexpr variables. Specifically, all references to Randen algorithm parameters use RandenTraits; duplication in RandenSlow removed.

PiperOrigin-RevId: 312190313

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

Internal change.

PiperOrigin-RevId: 312167304

--
f13d248fafaf206492c1362c3574031aea3abaf7 by Matthew Brown <matthewbr@google.com>:

Cleanup StrFormat extensions a little.

PiperOrigin-RevId: 312166336

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

Internal change

PiperOrigin-RevId: 312105213

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

Complete IGNORE_TYPE macro renaming.

PiperOrigin-RevId: 311999699

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

Switch to fixed bytes specific default value.

This fixes the Abseil Flags for big endian platforms.

PiperOrigin-RevId: 311844448

--
bdbe6b5b29791dbc3816ada1828458b3010ff1e9 by Laramie Leavitt <lar@google.com>:

Change many distribution tests to use pcg_engine as a deterministic source of entropy.

It's reasonable to test that the BitGen itself has good entropy, however when testing the cross product of all random distributions x all the architecture variations x all submitted changes results in a large number of tests. In order to account for these failures while still using good entropy requires that our allowed sigma need to account for all of these independent tests.

Our current sigma values are too restrictive, and we see a lot of failures, so we have to either relax the sigma values or convert some of the statistical tests to use deterministic values.

This changelist does the latter.

PiperOrigin-RevId: 311840096
GitOrigin-RevId: f012012ef78234a6a4585321b67d7b7c92ebc266
Change-Id: Ic84886f38ff30d7d72c126e9b63c9a61eb729a1a
Diffstat (limited to 'absl/flags/internal')
-rw-r--r--absl/flags/internal/commandlineflag.h17
-rw-r--r--absl/flags/internal/flag.cc36
-rw-r--r--absl/flags/internal/flag.h37
3 files changed, 18 insertions, 72 deletions
diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h
index 0a7197b7bd96..fa050209b0d7 100644
--- a/absl/flags/internal/commandlineflag.h
+++ b/absl/flags/internal/commandlineflag.h
@@ -178,23 +178,6 @@ class CommandLineFlag {
   virtual void CheckDefaultValueParsingRoundtrip() const = 0;
 };
 
-// This macro is the "source of truth" for the list of supported flag built-in
-// types.
-#define ABSL_FLAGS_INTERNAL_BUILTIN_TYPES(A) \
-  A(bool)                                    \
-  A(short)                                   \
-  A(unsigned short)                          \
-  A(int)                                     \
-  A(unsigned int)                            \
-  A(long)                                    \
-  A(unsigned long)                           \
-  A(long long)                               \
-  A(unsigned long long)                      \
-  A(double)                                  \
-  A(float)                                   \
-  A(std::string)                             \
-  A(std::vector<std::string>)
-
 }  // namespace flags_internal
 ABSL_NAMESPACE_END
 }  // namespace absl
diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc
index 8f0777fa1dc1..96c026dcb5d2 100644
--- a/absl/flags/internal/flag.cc
+++ b/absl/flags/internal/flag.cc
@@ -49,9 +49,9 @@ namespace {
 
 // Currently we only validate flag values for user-defined flag types.
 bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) {
-#define DONT_VALIDATE(T) \
+#define DONT_VALIDATE(T, _) \
   if (flag_type_id == base_internal::FastTypeId<T>()) return false;
-  ABSL_FLAGS_INTERNAL_BUILTIN_TYPES(DONT_VALIDATE)
+  ABSL_FLAGS_INTERNAL_SUPPORTED_TYPES(DONT_VALIDATE)
 #undef DONT_VALIDATE
 
   return true;
@@ -150,23 +150,11 @@ void FlagImpl::Init() {
       break;
     case FlagValueStorageKind::kOneWordAtomic: {
       alignas(int64_t) std::array<char, sizeof(int64_t)> buf{};
-      switch (def_kind) {
-        case FlagDefaultKind::kOneWord:
-          std::memcpy(buf.data(), &default_value_.one_word,
-                      sizeof(default_value_.one_word));
-          break;
-        case FlagDefaultKind::kFloat:
-          std::memcpy(buf.data(), &default_value_.float_value,
-                      sizeof(default_value_.float_value));
-          break;
-        case FlagDefaultKind::kDouble:
-          std::memcpy(buf.data(), &default_value_.double_value,
-                      sizeof(default_value_.double_value));
-          break;
-        default:
-          assert(def_kind == FlagDefaultKind::kGenFunc);
-          (*default_value_.gen_func)(buf.data());
-          break;
+      if (def_kind == FlagDefaultKind::kGenFunc) {
+        (*default_value_.gen_func)(buf.data());
+      } else {
+        assert(def_kind != FlagDefaultKind::kDynamicValue);
+        std::memcpy(buf.data(), &default_value_, Sizeof(op_));
       }
       OneWordValue().store(absl::bit_cast<int64_t>(buf),
                            std::memory_order_release);
@@ -228,14 +216,8 @@ std::unique_ptr<void, DynValueDeleter> FlagImpl::MakeInitValue() const {
       res = flags_internal::Alloc(op_);
       (*default_value_.gen_func)(res);
       break;
-    case FlagDefaultKind::kOneWord:
-      res = flags_internal::Clone(op_, &default_value_.one_word);
-      break;
-    case FlagDefaultKind::kFloat:
-      res = flags_internal::Clone(op_, &default_value_.float_value);
-      break;
-    case FlagDefaultKind::kDouble:
-      res = flags_internal::Clone(op_, &default_value_.double_value);
+    default:
+      res = flags_internal::Clone(op_, &default_value_);
       break;
   }
   return {res, DynValueDeleter{op_}};
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index 146c3efc2af3..e374ecde3d95 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -231,25 +231,21 @@ using FlagDfltGenFunc = void (*)(void*);
 union FlagDefaultSrc {
   constexpr explicit FlagDefaultSrc(FlagDfltGenFunc gen_func_arg)
       : gen_func(gen_func_arg) {}
-  template <typename T>
-  constexpr explicit FlagDefaultSrc(T one_word_value)
-      : one_word(static_cast<int64_t>(one_word_value)) {}
-  constexpr explicit FlagDefaultSrc(float f) : float_value(f) {}
-  constexpr explicit FlagDefaultSrc(double d) : double_value(d) {}
+
+#define ABSL_FLAGS_INTERNAL_DFLT_FOR_TYPE(T, name) \
+  T name##_value;                                  \
+  constexpr explicit FlagDefaultSrc(T value) : name##_value(value) {}  // NOLINT
+  ABSL_FLAGS_INTERNAL_BUILTIN_TYPES(ABSL_FLAGS_INTERNAL_DFLT_FOR_TYPE)
+#undef ABSL_FLAGS_INTERNAL_DFLT_FOR_TYPE
 
   void* dynamic_value;
   FlagDfltGenFunc gen_func;
-  int64_t one_word;
-  float float_value;
-  double double_value;
 };
 
 enum class FlagDefaultKind : uint8_t {
   kDynamicValue = 0,
   kGenFunc = 1,
-  kOneWord = 2,
-  kFloat = 3,
-  kDouble = 4
+  kOneWord = 2  // for default values UP to one word in size
 };
 
 struct FlagDefaultArg {
@@ -279,20 +275,6 @@ constexpr FlagDefaultArg DefaultArg(int) {
   return {FlagDefaultSrc(GenT{}.value), FlagDefaultKind::kOneWord};
 }
 
-template <typename ValueT, typename GenT,
-          typename std::enable_if<std::is_same<ValueT, float>::value,
-                                  int>::type = (GenT{}, 0)>
-constexpr FlagDefaultArg DefaultArg(int) {
-  return {FlagDefaultSrc(GenT{}.value), FlagDefaultKind::kFloat};
-}
-
-template <typename ValueT, typename GenT,
-          typename std::enable_if<std::is_same<ValueT, double>::value,
-                                  int>::type = (GenT{}, 0)>
-constexpr FlagDefaultArg DefaultArg(int) {
-  return {FlagDefaultSrc(GenT{}.value), FlagDefaultKind::kDouble};
-}
-
 template <typename ValueT, typename GenT>
 constexpr FlagDefaultArg DefaultArg(char) {
   return {FlagDefaultSrc(&GenT::Gen), FlagDefaultKind::kGenFunc};
@@ -576,9 +558,8 @@ class FlagImpl final : public flags_internal::CommandLineFlag {
   // Mutable flag's state (guarded by `data_guard_`).
 
   // def_kind_ is not guard by DataGuard() since it is accessed in Init without
-  // locks. If necessary we can decrease number of bits used to 2 by folding
-  // one_word storage cases.
-  uint8_t def_kind_ : 3;
+  // locks.
+  uint8_t def_kind_ : 2;
   // Has this flag's value been modified?
   bool modified_ : 1 ABSL_GUARDED_BY(*DataGuard());
   // Has this flag been specified on command line.