Commit Graph

199 Commits

Author SHA1 Message Date
Abseil Team
852fc61f31 Remove more lingering C++17 type traits polyfill usages
This will let us deprecate the declarations without triggering warnings in Abseil itself.

PiperOrigin-RevId: 906360966
Change-Id: Iee362ac0eac647909ef38003280f1179813f764d
2026-04-27 08:03:53 -07:00
Derek Mauro
0b1904f017 Fix MSVC warning C4819 by removing various unicode dash characters
Fixes #2039
Fixes #2040

PiperOrigin-RevId: 905121492
Change-Id: I26a5a0da728243f7cfe8fc7932ce0878ed3baf1d
2026-04-24 11:02:13 -07:00
Abseil Team
9cb62a03a4 Remove unnecessary usages of absl::void_t
Most usages of absl::void_t compile fine with std::void_t, so we migrate them here. A few don't compile due to overly eager template instantiations, so we leave those.

PiperOrigin-RevId: 897231619
Change-Id: Iad34101916dac2b995257ebd5d6aacb9a0acfa32
2026-04-09 12:01:41 -07:00
Abseil Team
ed2114e8ff Stop using C++17 type traits polyfills
This will let us deprecate the declarations without triggering warnings in Abseil itself.

PiperOrigin-RevId: 894202105
Change-Id: I57bb2a1647be1fedf9b724a07042fd0f564ce074
2026-04-03 12:34:35 -07:00
Laramie Leavitt
b7c61d35e6 Reduce duplication in absl/random/internal.
Consolidate the mocking requirements so that mock detection is mediated
via the MockingAccess class
* HasInvokeMock has been deduplicated; MockingAccess now owns it
* InvokeMock is done via MockingAccess::InvokeMock
* In absl::BitGenRef, if a class has a conversion operator that is used.
* `friend class MockingAccess` is now the only mocking friend, except for backwards compat.
  - friend DistributionCaller is now unnecessary.
  - friend BitGenRef is now unnecessary.
  - friend MockHelpers now unnecessary.

PiperOrigin-RevId: 889366369
Change-Id: I288cd60f6ac13b257c10ec3268d96828f1e61db6
2026-03-25 12:08:24 -07:00
Derek Mauro
972e4ab4a0 Minor reformatting
PiperOrigin-RevId: 882117140
Change-Id: Ibe88c2385114a286eaa93d4047b11e3be55a03d4
2026-03-11 11:38:12 -07:00
Mike Kruskal
45c8989b87 Add a visibility placeholder to Abseil for Gloop.
PiperOrigin-RevId: 875292936
Change-Id: I5622f33f8d6581ca3f55783579f612e3e5c4822f
2026-02-25 12:48:48 -08:00
Derek Mauro
5088cf5194 Cleanup the uses of the polyfills absl::any, absl::optional,
absl::variant, and related types

The corresponding headers are removed from cc files, but kept in
headers to prevent breakages from transitive dependencies.

PiperOrigin-RevId: 872421685
Change-Id: I867d4c3f7c9e422289c63816d44719b0530fb0a6
2026-02-19 08:53:17 -08:00
Abseil Team
f8c283dabf Remove support for Native Client
Native Client has been fully removed from Chromium.

PiperOrigin-RevId: 803093147
Change-Id: I7fea87a8a66b35b2f0cc3d815c23f90e5e4d2043
2025-09-04 10:54:42 -07:00
Abseil Team
e5266cd1cd Tag tests that currently fail on ios_sim_arm64 with "no_test_ios_sim_arm64"
This is to prepare for continuous testing on ios_sim_arm64.

PiperOrigin-RevId: 792119312
Change-Id: I44f09b969138863afa79798efa2cd18f5d718e8f
2025-08-07 05:42:35 -07:00
Chris Kennelly
0f1abc9b73 Inline internal usages of pointerful SpinLockHolder/MutexLock.
PiperOrigin-RevId: 789441157
Change-Id: I2ed5d12f4b9725edbe3fd6cf629a0563a2f2d739
2025-07-31 12:59:26 -07:00
Abseil Team
878361312d Automated Code Change
PiperOrigin-RevId: 783054860
Change-Id: I3f84881642f2f77be5d5275983243edf6305178c
2025-07-14 15:00:34 -07:00
Evan Brown
501d0a586e Reduce flakiness in MockDistributions.Examples test case.
PiperOrigin-RevId: 763928380
Change-Id: I2063b45e660a9601bb52d72963b19803863c5c36
2025-05-27 13:37:25 -07:00
co63oc
8dfced289c PR #1878: Fix typos in comments
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1878

Fix typos in comments found by codespell command.
Merge 28452566b3 into 7bf6d7918f

Merging this change closes #1878

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1878 from co63oc:fix1 28452566b3
PiperOrigin-RevId: 750227488
Change-Id: I7dd87ccb83525692df9f4b504bcd747814497ac8
2025-04-22 09:46:44 -07:00
Derek Mauro
01228903e9 Use alignas instead of the manual alignment
for the Randen entropy pool.

https://github.com/abseil/abseil-cpp/pull/1872 reports that since
we leak the pointer but no variable holds its address, Valgrind
reports a leak. The PR contains a proposed fix, but I believe this
is simpler.

PiperOrigin-RevId: 749868815
Change-Id: I222fc3202b7a38b8ff960c2398dbf2636e60e490
2025-04-21 11:52:02 -07:00
Derek Mauro
7c5528251a Add absl::FastTypeId<T>()
absl::FastTypeId<Type>() evaluates at compile-time to a unique id for the
passed-in type. These are meant to be good match for keys into maps or
straight up comparisons.

Previously this was an internal implemention detail used by a few libraries.
This is now a supported utility function.

PiperOrigin-RevId: 743194478
Change-Id: Ie01ed8a2850696ee661acb91726252adb4c20538
2025-04-02 10:37:37 -07:00
Laramie Leavitt
48f9175aa6 Minor consistency cleanups to absl::BitGen mocking.
PiperOrigin-RevId: 735546502
Change-Id: I7daacb4018cf3f2719db7043b868b4df34ddaf05
2025-03-10 16:14:42 -07:00
Laramie Leavitt
4a2ba8cade Add thread GetEntropyFromRandenPool test
PiperOrigin-RevId: 734342904
Change-Id: I7a207bbfd0a6ccadf650fee079c9991826c5f08a
2025-03-06 17:09:19 -08:00
Laramie Leavitt
80b6a00e5a Simplify some random/internal types; expose one function to acquire entropy.
PiperOrigin-RevId: 734243580
Change-Id: Ibc8f3642329b1e7a5a6ed54e505b2ced8dec2f4c
2025-03-06 12:25:18 -08:00
Laramie Leavitt
735c86164a absl/random: Convert absl::BitGen / absl::InsecureBitGen to classes from aliases.
PiperOrigin-RevId: 733063284
Change-Id: If0af60b24bcc59b6fe3a6882aebd427b8b10f3a0
2025-03-03 14:32:52 -08:00
Derek Mauro
1af129f1c3 Use C++17 [[nodiscard]] instead of the deprecated ABSL_MUST_USE_RESULT
In this change, //absl/status is intentionally excluded because of
complication with SWIG compatibility. This may be handled separately.

PiperOrigin-RevId: 731387819
Change-Id: I71bf2e02f3a477d65575d467f5e5ab163846d31e
2025-02-26 11:16:38 -08:00
Laramie Leavitt
91d68f379d Minor code cleanups
PiperOrigin-RevId: 729592629
Change-Id: I3c82c6d04fd92e04494792e122ae9d115fce4cfa
2025-02-21 11:14:26 -08:00
Derek Mauro
e78a8ce497 Delete absl/base/internal/inline_variable.h
PiperOrigin-RevId: 728684812
Change-Id: If4e2d0fed045c1cb312a48f250d5ebb1aaa1b41f
2025-02-19 08:32:03 -08:00
Abseil Team
33d9ce727c Revert: Random: Use target attribute instead of -march
If the user overrides -march e.g. via BAZEL_CXXOPTS it may conflict with
the -march override for Randen. So instead use a target attribute which
works on clang and gcc.

PiperOrigin-RevId: 728408888
Change-Id: Ie870600a80fb25f95b53f5e87bb9cc7ade53d69d
2025-02-18 16:36:54 -08:00
Peter Collingbourne
2d2093eae3 Random: Use target attribute instead of -march
If the user overrides -march e.g. via BAZEL_CXXOPTS it may conflict with
the -march override for Randen. So instead use a target attribute which
works on clang and gcc.

PiperOrigin-RevId: 728313249
Change-Id: Ifdbf5430fbec9febdab844b8c325f9d1c7518c82
2025-02-18 12:25:26 -08:00
Peter Collingbourne
23b7b19cce Make Randen benchmark program use runtime CPU detection.
ABSL_HAVE_ACCELERATED_AES is unrelated to whether AES is supported at
runtime, so replace the ABSL_HAVE_ACCELERATED_AES check with a call to
CPUSupportsRandenHwAes() to do runtime detection.

Moreover, nothing else refers to ABSL_INTERNAL_DISABLE_AES besides this
benchmark program, so stop checking for it.

PiperOrigin-RevId: 725351190
Change-Id: Ieddb0724095db060cc5defc7c09e030b3bbafd6f
2025-02-10 14:37:46 -08:00
Clément Péron
30a964d2fc PR #1819: fix compilation with AppleClang
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1819

Fix the following error:

absl/random/internal/randen_detect.cc:123:12: error: no member named 'nullopt' in namespace 'std'; did you mean 'absl::nullopt'?
  123 |     return std::nullopt;
      |            ^~~~~~~~~~~~
      |            absl::nullopt
absl/types/optional.h:86:43: note: 'absl::nullopt' declared here
   86 | ABSL_INTERNAL_INLINE_CONSTEXPR(nullopt_t, nullopt,
      |                                           ^
Merge b9a2d3920a into 7253ff8f95

Merging this change closes #1819

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1819 from clementperon:master b9a2d3920a
PiperOrigin-RevId: 722599523
Change-Id: Ie66cbf9daf3b115668194da8b74acd6a43e12a03
2025-02-03 04:11:59 -08:00
Dan Horák
0f102ad442 PR #1816: Random: use getauxval() via <sys/auxv.h>
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1816

Make the use of  `getauxval()` consistent with other parts of abseil and use it via the `<sys/auxv.h>` header instead of a local declaration.

The current situation is causing some weird symbol visibility issues at least in Firefox, see https://bugzilla.mozilla.org/show_bug.cgi?id=1942917 for details.
Merge 61a56f3a58 into 20a1220136

Merging this change closes #1816

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1816 from sharkcz:random 61a56f3a58
PiperOrigin-RevId: 721365575
Change-Id: I99d0fc6fd9abd3b8ba175af88f4a1b7f6862e589
2025-01-30 06:23:03 -08:00
David Majnemer
fd8b35b9aa Random: Rollforward support runtime dispatch on AArch64 macOS
The __builtin_cpu_supports path seems to cause problems on certain builds, let's remove it.

PiperOrigin-RevId: 717993600
Change-Id: I69568c17dc768a5edd097709884ba07f2c78db91
2025-01-21 11:11:50 -08:00
Abseil Team
95049aadbe Rollback support runtime dispatch on AArch64 macOS
for breaking some builds

PiperOrigin-RevId: 716676691
Change-Id: Icef8b00950262b6fb0385311b9b52dcac65a0a6a
2025-01-17 08:18:22 -08:00
David Majnemer
b7af5e1e41 Random: Support runtime dispatch on AArch64 macOS
This lets us dynamically determine if we should attempt to use HW
instructions for AES.

PiperOrigin-RevId: 716350656
Change-Id: I1ead17b7b44373850b3591307b7f6d3f9147d5f9
2025-01-16 13:10:47 -08:00
Derek Mauro
f4af6c0072 Use Bazel rules_cc for many compiler-specific rules
instead of our custom ones from before the Bazel rules existed.

Also add the missing rules_cc to WORKSPACE, since we already had
it in MODULE.bazel

PiperOrigin-RevId: 715006932
Change-Id: Ibb38a78c115a7dc2983426455bb271162795846f
2025-01-13 09:53:07 -08:00
Laramie Leavitt
65b7da13bf Minor include cleanup in absl/random/internal
PiperOrigin-RevId: 713065097
Change-Id: Ic89ca57a0f2882c61151c23281843041fdc99fb3
2025-01-07 15:42:49 -08:00
Derek Mauro
4e09561096 Use Bazel Platforms to support AES-NI compile options for Randen
Bazel has deprecated selecting directly on the --cpu. This change
uses platforms to select the appropriate compile options.

Fixes https://github.com/abseil/abseil-cpp/issues/1573
Fixes https://github.com/abseil/abseil-cpp/pull/1797

PiperOrigin-RevId: 712638567
Change-Id: Id16e478fe4ff1d27992b263d51c822cce0f7a98c
2025-01-06 13:23:46 -08:00
Jeremy Nimmer
3ee08f3298 PR #1801: Remove unncessary <iostream> includes
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1801

Including `<iostream>` means introducing the static (global) constructors and destructors for `std::cin`, `std::cerr`, and `std::cout`. That extra `init` and `fini` code is [undesirable](https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables) when those streams are not actually used.
Merge 4207b23cd4 into f339ea31b8

Merging this change closes #1801

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1801 from jwnimmer-tri:iostream 4207b23cd4
PiperOrigin-RevId: 712548264
Change-Id: Ia04b581753622d357d3e989d0b1ae6d938fd7335
2025-01-06 09:06:33 -08:00
Derek Mauro
90a7ba66e8 Updates to CI to support newer versions of tools
Linux "latest" containers updated to
GCC 14.2
CMake 3.31.2
Bazel 8.0.0

Included are various fixes to get these versions to work.

Bazel now references repositories by their canonical names from the
Bazel Central Registry. For example, Abseil is now @abseil-cpp instead
of @com_google_absl, and GoogleTest is now @googletest instead of
@com_google_googletest. Users still using the old WORKSPACE system may
need to use `repo_mapping` on repositories using the old names. See
`WORKSPACE.bazel` in this commit for an example.

PiperOrigin-RevId: 709102146
Change-Id: I02327ed4f8fb947766480bdeef2b1930a7f831eb
2024-12-23 10:58:05 -08:00
Laramie Leavitt
917bfee465 IWYU: Update includes and fix minor spelling mistakes.
PiperOrigin-RevId: 697000534
Change-Id: Ia885033535c5e2f57884a922bdcff9db7b565f49
2024-11-15 14:24:26 -08:00
Aaron Jacobs
feb6aab8db distributions: support a zero max value in Zipf.
There is no documentation that says zero isn't okay, and the closed interval
[0, k] described by the documentation is perfectly well-defined even when k is
zero. As far as I can tell, there is no reason *not* to support zero: a random
variable that always returns the same value is still a random variable.
absl::Uniform will happily generate on the interval [0, 1) for the same
reason.
PiperOrigin-RevId: 694649518
Change-Id: Ib940406f762a30e27c19c846c45bd908ae8411c3
2024-11-08 14:51:28 -08:00
Aaron Jacobs
6312b70b9d absl/random: run clang-format.
In order to avoid unrelated diffs in future changes that touch this code.

PiperOrigin-RevId: 694625990
Change-Id: I51ac54438a977f38c54c7638701d9ff3a259a58b
2024-11-08 13:46:02 -08:00
Justin Bassett
a3027054ab Delete UnvalidatedMockingBitGen
See some relevant context on this project in 254b3a5326. This type existed to support the incremental migration of added validation to MockingBitGen, validating that the returned value from absl::Uniform() is in bounds. All known cases where an out-of-bounds value was returned have been fixed and migrated to use MockingBitGen.

PiperOrigin-RevId: 693836317
Change-Id: I04f54b7b4856f4280580b294194ce2c25a18e9b1
2024-11-06 13:10:03 -08:00
Michael Brase
8cdf482136 Increase test timeouts to support running on Fuchsia emulators
PiperOrigin-RevId: 656439732
Change-Id: I7f405d8075c57e634d51c11a37fbe3e317abf103
2024-07-26 10:04:20 -07:00
Mike Kruskal
cd7f66cab5 Remove cyclic cmake dependency that breaks in cmake 3.30.0
PiperOrigin-RevId: 651258120
Change-Id: I1c343bc11407d33dc2d0bb1686be4bdbe6a600df
2024-07-10 21:26:20 -07:00
Anthony Lai
74f8c1eae9 Fix comment typo
PiperOrigin-RevId: 646105357
Change-Id: Ia76c1ce33faf811e988d36747f187c112ccb967e
2024-06-24 08:36:19 -07:00
Justin Bassett
33dca3ef75 Turn on validation for out of bounds MockUniform in MockingBitGen
This makes MockUniform fail if the action is specified to return an out of bounds value.

Examples that will fail:

  absl::Uniform(gen, 1, 4) -> 42
  absl::Uniform(gen, 1, 4) -> 4: [1, 4)
  absl::Uniform(absl::IntervalOpenClosed, gen, 1, 4) -> 1: (1, 4]

Examples that will pass:

  absl::Uniform(gen, 1, 4) -> 3
  absl::Uniform(gen, 1, 4) -> 1: [1, 4)
  absl::Uniform(absl::IntervalClosed, gen, 1, 4) -> 4: [1, 4]

Special case: the empty range always returns its boundary, so this case passes:

  absl::Uniform(absl::IntervalOpen, 1, 1) -> 1: (1, 1)

If this breaks your test, your test has a bug: it's relying on an absl::Uniform() call that returns an impossible value. The UnvalidatedMockingBitGen type temporarily exists to allow for disabling the validation to give a bit of time to fix the test, but this type will go away soon.

PiperOrigin-RevId: 643090275
Change-Id: I23470fa9e1efbcb42fa3866237038414545c7be2
2024-06-13 12:44:29 -07:00
Abseil Team
cb319b3e67 Fix implicit conversion of temporary bitgen to BitGenRef
There is no reason a temporary *shouldn't* be usable with BitGenRef (indeed, ABSL_ATTRIBUTE_LIFETIME_BOUND should catch errors) and it is useful when passing a temporary bitgen as an input argument.

PiperOrigin-RevId: 642021132
Change-Id: I03e46f5f437e40a0c6225ea1f0361475a3501513
2024-06-10 14:21:13 -07:00
Derek Mauro
52bc669d0e Workaround bogus GCC14 -Wmaybe-uninitialized warning
PiperOrigin-RevId: 636992927
Change-Id: I4da3be41a5961d0828eec7ac5c67b299a2e0f237
2024-05-24 12:03:23 -07:00
Justin Bassett
4a7c2ec65a Forbid absl::Uniform<absl::int128>(gen)
std::is_signed can't be specialized, so this actually lets through non-unsigned types where the types are not language primitives (i.e. it lets absl::int128 through). However, std::numeric_limits can be specialized, and is indeed specialized, so we can use that instead.
PiperOrigin-RevId: 636983590
Change-Id: Ic993518e9cac7c453b08deaf3784b6fba49f15d0
2024-05-24 11:33:58 -07:00
Justin Bassett
e7f1a950e9 Support int128/uint128 in validated MockingBitGen
`absl::int128` and `absl::uint128` are not `std::is_integral`. There is an internal `IsIntegral` type trait we could use, but it actually makes more sense to remove the `static_assert` altogether. Any compile-time validation should be done in `absl::Uniform` itself, and duplicating that logic here just increases the chance of divergence.

PiperOrigin-RevId: 635971431
Change-Id: I9177ae64c86ee1abe6571e0b29aba1844553c972
2024-05-21 16:57:23 -07:00
Justin Bassett
254b3a5326 Add (unused) validation to absl::MockingBitGen
`absl::Uniform(tag, rng, a, b)` has some restrictions on the values it can produce in that it will always be in the range specified by `a` and `b`, but these restrictions can be violated by `absl::MockingBitGen`. This makes it easier than necessary to introduce a bug in tests using a mock RNG.

We can fix this by making `MockingBitGen` emit a runtime error if the value produced is out of bounds.

Immediately fixing all the internal buggy uses of `MockingBitGen` is currently infeasible, so the plan is this:

 1. Add turned-off validation to `MockingBitGen` to avoid the costs of maintaining unsubmitted code.
 2. Temporarily migrate the internal buggy use cases to keep the current behavior, to be fixed later.
 3. Turn on validation for `MockingBitGen`.
 4. Fix the internal buggy use cases over time.

---

A few of the different categories of errors I found:

 - `Call(tag, rng, a, b) -> a or b`, for open/half-open intervals (i.e. incorrect boundary condition). This case happens quite a lot, e.g. by specifying `absl::Uniform<double>(rng, 0, 1)` to return `1.0`.
 - `Call(tag, rng, 0, 1) -> 42` (i.e. return an arbitrary value). These may be straightforward to fix by just returning an in-range value, or sometimes they are difficult to fix because other data structures depend on those values.

PiperOrigin-RevId: 635503223
Change-Id: I9293ab78e79450e2b7b682dcb05149f238ecc550
2024-05-20 10:45:19 -07:00
Abseil Team
d94c7aefe7 [random] LogUniform: Document as a discrete distribution
PiperOrigin-RevId: 630047753
Change-Id: I6ad73216bbe4e279553b9a57bd2727310091c754
2024-05-02 06:45:59 -07:00