Commit Graph

2535 Commits

Author SHA1 Message Date
Abseil Team
74058c0f49 Add ABSL_REQUIRE_EXPLICIT_INIT to Abseil to enable enforcing explicit field initializations
Also include portable fallbacks for other compilers. They don't produce good error messages, but they do prevent silent breakages on other platforms/toolchains.

PiperOrigin-RevId: 723629074
Change-Id: I29ee8fbc679b70bb67d42577d0723b52268f7caf
2025-02-05 13:26:21 -08:00
Derek Mauro
7a03cdb4c0 Require C++17
Policy information:
https://opensource.google/documentation/policies/cplusplus-support#c_language_standard
https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md

PiperOrigin-RevId: 723589409
Change-Id: Ia8665c052ed40f2a78308f7eb0c330191b0cf981
2025-02-05 11:33:01 -08:00
Vitaly Goldshteyn
69b58f9227 Minimize number of InitializeSlots with respect to SizeOfSlot.
I am still keeping `SooSlotMemcpySize` that may be 1, 4, 8 or 16. Microbenchmarks showed that it is useful to have compile time memcpy. In the long run, when/if more types will become trivially transferable and a potential increase of the SOO maximal size, this optimization can become (even) more useful. So I would stick with it for the time being.

`SooSlotMemcpySize` is always zero for non SOO types or not memcpyable types.
So as a result we merge all sizes for non SOO or non transferable types.
For memcpyable SOO types we have 4 options.

PiperOrigin-RevId: 723233539
Change-Id: If38c69527a2f873c07ce869bf3ca609fc7371a07
2025-02-04 14:46:31 -08:00
Vitaly Goldshteyn
9ebb40865f Leave the call to SampleSlow only in type erased InitializeSlots.
Call to `SampleSlow` was happening in SOO tables on insert.
That increases binary size in the hot place.
With this change only verification of whether sample needs to be done is performed.

PiperOrigin-RevId: 723201811
Change-Id: I75eba1c4803390587edc9342a177d4ed5eaf342c
2025-02-04 13:14:04 -08:00
Evan Brown
ee2839208a Update comments for Read4To8 and Read1To3.
The implementations for these functions changed recently to no longer zero pad and instead duplicate input bytes. Also remove a TODO that has been done.

PiperOrigin-RevId: 722793915
Change-Id: Ib5c3d444530270d227ec1636935925acc4d8dc0c
2025-02-03 14:15:30 -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
Vitaly Goldshteyn
7253ff8f95 Move SOO processing inside of InitializeSlots and move it once.
That reduces binary size by moving more code to type erased InitializeSlots.

It also make SOO element to be moved once that can be useful for expensive to move types.

PiperOrigin-RevId: 721938625
Change-Id: I449753440fe91cb1bb5a1569e23d1986f5b0a642
2025-01-31 16:10:47 -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
Vitaly Goldshteyn
5f9f2cf80a Optimize InitControlBytesAfterSoo to have less writes and make them with compile time known size.
X86:
```
name                                                                           old CYCLES/op        new CYCLES/op        delta
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:1           14.8 ± 0%            14.8 ± 0%  -0.05%  (p=0.001 n=49+50)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:2           49.2 ± 0%            44.7 ± 0%  -9.19%  (p=0.000 n=54+50)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:4           59.3 ± 0%            57.2 ± 0%  -3.61%  (p=0.000 n=54+53)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:8           56.1 ± 1%            55.1 ± 1%  -1.86%  (p=0.000 n=54+54)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:16          61.8 ± 1%            61.2 ± 1%  -0.98%  (p=0.000 n=56+55)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:32          60.5 ± 1%            60.2 ± 1%  -0.41%  (p=0.000 n=42+55)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:64          57.7 ± 2%            57.5 ± 2%  -0.32%  (p=0.031 n=55+56)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:128         55.2 ± 1%            55.2 ± 1%    ~     (p=0.493 n=52+51)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:256         52.9 ± 1%            53.0 ± 1%    ~     (p=0.877 n=45+49)
```

ARM (altra,arch=aarch64)
```
name                                                                           old CYCLES/op        new CYCLES/op        delta
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:1           16.9 ± 3%            16.8 ± 3%    ~     (p=0.107 n=57+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:2           55.9 ± 1%            51.6 ±11%  -7.62%  (p=0.000 n=46+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:4           61.6 ± 0%            59.9 ± 7%  -2.77%  (p=0.000 n=33+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:8           61.9 ± 0%            61.0 ± 4%  -1.47%  (p=0.000 n=33+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:16          58.0 ± 2%            57.7 ± 3%    ~     (p=0.073 n=40+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:32          54.4 ± 3%            54.2 ± 3%    ~     (p=0.138 n=57+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:64          51.3 ± 2%            51.1 ± 2%    ~     (p=0.110 n=57+57)
BM_SWISSMAP_InsertManyToEmpty_Hot<::absl::flat_hash_set, 4>/set_size:128         48.8 ± 2%            48.7 ± 2%    ~     (p=0.163 n=57+57)
```

PiperOrigin-RevId: 720984174
Change-Id: I3297a89e678421e4e784af6b5f66b862fd1aae05
2025-01-29 08:18:40 -08:00
Abseil Team
da2b12d7c9 Remove stray plus operator in cleanup_internal::Storage
PiperOrigin-RevId: 720611342
Change-Id: I0c4253cb5eff9afe60cf922bd6df0300bc6a65fc
2025-01-28 09:53:57 -08:00
Abseil Team
9cf0a2f842 Include <cerrno> to fix compilation error in chromium build.
Errno is being used in the source file (see `errno`).

PiperOrigin-RevId: 720611021
Change-Id: I374f080c3997221cd320d8364e71dd7c9c51b644
2025-01-28 09:52:47 -08:00
Andy Getzendanner
0dd7d3925a Adjust internal logging namespacing for consistency s/ABSL_LOGGING_INTERNAL_/ABSL_LOG_INTERNAL_/
PiperOrigin-RevId: 720566733
Change-Id: I49d5c82f3ba88619f641617e7b8e0f742008abc5
2025-01-28 07:27:10 -08:00
Andy Getzendanner
20a1220136 Rewrite LOG_EVERY_N (et al) docs to clarify that the first instance is logged. Also, deliberately avoid giving exact numbers or examples since IRL behavior is not so exact.
PiperOrigin-RevId: 720347226
Change-Id: Ie90d4887e49bf8ec8e92bc1d87abd5c5b32b236f
2025-01-27 16:28:41 -08:00
Derek Mauro
c64f219a33 ABSL_ASSUME: Use a ternary operator instead of do-while in the
implementations that use a branch marked unreachable so that it is
usable in more contexts.

The unimplemented case now uses the same definition as ABSL_ASSERT
when NDEBUG is defined.

Fixes https://github.com/abseil/abseil-cpp/issues/1814

PiperOrigin-RevId: 720236336
Change-Id: I4f4f6e8a384dd11a07626b085a001fc2f5b7db21
2025-01-27 11:07:33 -08:00
Evan Brown
e118b39b45 Simplify the comment for raw_hash_set::erase.
raw_hash_set is an internal class, and the API comments are mostly targeted towards implementers rather than users. Note that the public API comments are in the public headers, e.g. flat_hash_set.h.

PiperOrigin-RevId: 720199830
Change-Id: I0b0a31a1b905696fb9da7706105b7fb4117a90c3
2025-01-27 09:32:23 -08:00
Abseil Team
747c9768b5 Remove preprocessors for now unsupported compilers.
PiperOrigin-RevId: 719126950
Change-Id: I0978c295896acdf069175ba99156e8bbf6e1e188
2025-01-23 20:42:10 -08:00
Dino Radakovic
d5bafc01dd absl::ScopedMockLog: Explicitly document that it captures logs emitted by all threads
This is already documented by a [test case](fd8b35b9aa/absl/log/scoped_mock_log_test.cc (L218)), but it would have been nicer to just read about it in the header file.

PiperOrigin-RevId: 719021749
Change-Id: I058eeec77d6c54b906ad449221b09222be59f898
2025-01-23 14:49:13 -08:00
Derek Mauro
5a0e2cb5e3 Fix potential integer overflow in hash container create/resize
The sized constructors, reserve(), and rehash() methods of
absl::{flat,node}_hash_{set,map} did not impose an upper bound on
their size argument. As a result, it was possible for a caller to pass
a very large size that would cause an integer overflow when computing
the size of the container's backing store. Subsequent accesses to the
container might then access out-of-bounds memory.

The fix is in two parts:

1) Update max_size() to return the maximum number of items that can be
stored in the container

2) Validate the size arguments to the constructors, reserve(), and
rehash() methods, and abort the program when the argument is invalid

We've looked at uses of these containers in Google codebases like
Chrome, and determined this vulnerability is likely to be difficult to
exploit. This is primarily because container sizes are rarely
attacker-controlled.

The bug was discovered by Dmitry Vyukov <dvyukov@google.com>.

PiperOrigin-RevId: 718841870
Change-Id: Ic09dc9de140a35dbb45ab9d90f58383cf2de8286
2025-01-23 06:34:23 -08:00
Abseil Team
5f8d605c09 Add lifetimebound to StripPrefix/StripSuffix.
PiperOrigin-RevId: 718507839
Change-Id: I86e394b1d29150c3cf1c9aaec6cd84785f4c3684
2025-01-22 13:33:30 -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
David Majnemer
df8178e26e Crc: Only test non_temporal_store_memcpy_avx on AVX targets
non_temporal_store_memcpy_avx uses gnu::target("avx") to use AVX intrinsics
inside its function body even if the compiler was not configured for AVX
support. This is OK because non_temporal_store_memcpy_avx is guarded by a cpuid
check before it is called.

However, non_temporal_memcpy_test.cc performs no such cpuid guard. In practice,
nobody will really notice this bug as CPUs have had AVX for a long time by now.

That said, this does come up if one has compiled absl for x86_64 and runs the
binary on a arm64 Mac. This is because the Rosetta 2 emulation environment does
not support AVX or newer instructions.

PiperOrigin-RevId: 717991751
Change-Id: Id41bd186ebfd1cf7124ab5211fbfb74a01d5b56c
2025-01-21 11:06:47 -08:00
Dmitry Vyukov
1cdbba70ea Provide information about types of all flags.
PiperOrigin-RevId: 717986118
Change-Id: Ib962482b66e1eac09165767d4a36a91ad49e8fc8
2025-01-21 10:54:20 -08:00
Evan Brown
45dab59f1d Deprecate the precomputed hash find() API in swisstable.
PiperOrigin-RevId: 717979366
Change-Id: I5b7a14ccbd2de263b9cc65dd7390765b04ee50db
2025-01-21 10:38:24 -08:00
Abseil Team
3babd55103 Import of CCTZ from GitHub.
PiperOrigin-RevId: 717945362
Change-Id: I3e1513793b0a1eaa1d55d52a35dbc380fd36557c
2025-01-21 09:12:50 -08:00
Chris Kennelly
64d6a3a2ba Adjust whitespace
PiperOrigin-RevId: 717931888
Change-Id: Ib0c3dd32cb738c50e7bd4ea7a808b54fea096db6
2025-01-21 08:35:29 -08:00
Abseil Team
a28c4b5827 Expand documentation for absl::raw_hash_set::erase to include idiom example of iterator post-increment.
PiperOrigin-RevId: 717628872
Change-Id: I0f2b585c03a61d96a6709c26e9a7290e0d9abbe5
2025-01-20 14:27:11 -08:00
Abseil Team
513583421a Performance improvement for absl::AsciiStrToUpper() and absl::AsciiStrToLower()
PiperOrigin-RevId: 717267393
Change-Id: Ie71c605a44a3105832074c3b025b90833a7028e2
2025-01-19 10:20:39 -08:00
David Majnemer
3735766b3b Crc: Remove the __builtin_cpu_supports path for SupportsArmCRC32PMULL
It seems that this feature is not fully baked on all build configurations, let's remove it for now.

PiperOrigin-RevId: 716825311
Change-Id: I2ea9d941f8f3f177f9eb2afbd737935d58923780
2025-01-17 15:56:53 -08:00
Derek Mauro
655707fb20 Use absl::NoDestructor for some absl::Mutex instances in the flags
library to prevent some exit-time destructor warnings

This is the convention in the rest of Abseil.

PiperOrigin-RevId: 716767392
Change-Id: Ie7e1df54e79eba9057fbaeea000f63b6ec9929bc
2025-01-17 12:49:38 -08:00
Derek Mauro
40244841f1 Update the WORKSPACE dependency of rules_cc to 0.1.0
PiperOrigin-RevId: 716754010
Change-Id: Id57ff6f81667fb19fc8782f63e990d66e429d4c4
2025-01-17 12:12:06 -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
Derek Mauro
b87a7955b8 Downgrade to rules_cc 0.0.17 because 0.1.0 was yanked
Note that the error message says downgrade to 0.0.15, but I'm not sure
why. 0.0.17 is the latest.

```
ERROR: Error computing the main repository mapping: Yanked version detected in your resolved dependency graph: rules_cc@0.1.0, for the reason: rules_cc 0.1.0 is yanked due to incompatible change (prematurely removing cc_proto_library from defs.bzl), please downgrade to 0.0.15.
```
PiperOrigin-RevId: 716675841
Change-Id: I459c35186161cc3d10b8c38973041d9a592c7cec
2025-01-17 08:16:16 -08:00
Chris Kennelly
a4e7719121 Use unused set in testing.
PiperOrigin-RevId: 716373611
Change-Id: I4bfb4d51cd45be628f68917d310a44a44412a4a5
2025-01-16 14:12:15 -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
David Majnemer
3ded0b656e crc: Use absl::nullopt when returning absl::optional
Otherwise we can observe a build failure when absl::optional != std::optional.

PiperOrigin-RevId: 716275922
Change-Id: I4918a8901530f0daafeec07e319fd79123358bc1
2025-01-16 10:01:05 -08:00
Chris Kennelly
b4e899a955 Annotate absl::FixedArray to warn when unused.
PiperOrigin-RevId: 715803554
Change-Id: Ic0b733641174922b89f4d8c3ae2cb2762db76d5c
2025-01-15 08:09:29 -08:00
simonla
41984a2258 PR #1806: Fix undefined symbol: __android_log_write
This adds -llog under CMake. The Bazel build already has this.

Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1806

close #1805
Merge 76dd9e3378 into a1de53ddde

Merging this change closes #1806

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1806 from simonla:fix_compile_android_shared_lib 76dd9e3378
PiperOrigin-RevId: 715779297
Change-Id: I19ea9433fda94a60c1d2c1b3a0b40e80bdd3c078
2025-01-15 06:47:52 -08:00
Abseil Team
a1de53ddde Move ABSL_HAVE_PTHREAD_CPU_NUMBER_NP to the file where it is needed
This macro was not intended to be a public API.

PiperOrigin-RevId: 715469634
Change-Id: I76f28ccd2fb9efb5fc4b48b26e4a567325bb7992
2025-01-14 11:58:11 -08:00
Evan Brown
be33b0aaae Use rbit instruction on ARM rather than rev.
This is a followup to the change to use ARM hashing techniques in absl. I didn't realize the distinction between rev/rbit originally, but we expect that rbit will result in better hash quality at the same latency.

LLVM-MCA rev: https://godbolt.org/z/94Mo71TKd
LLVM-MCA rbit: https://godbolt.org/z/nK8bMfeKf

PiperOrigin-RevId: 715443087
Change-Id: Ic05608851529d1447ed11557e7f430a088a4efcd
2025-01-14 10:49:37 -08:00
David Majnemer
3fba335b02 Debugging: Report the CPU we are running on under Darwin
This can be helpful to understand complex post-mortem failures.

PiperOrigin-RevId: 715435340
Change-Id: I7e5f6abcbba043055c1b33fbc09701fa8a56984c
2025-01-14 10:32:41 -08:00
Samuel Benzaquen
1b0f25267f Add a microbenchmark for very long int/string tuples.
PiperOrigin-RevId: 715398493
Change-Id: I5231ed6499e5eb7eff9436e309295d493b91365f
2025-01-14 08:47:13 -08:00
David Majnemer
6effb000ca Crc: Detect support for pmull and crc instructions on Apple AArch64
With a newer clang, we can use __builtin_cpu_supports which caches all
the feature bits.

If we are using an older clang, we fall back to querying sysctlbyname
for the relevant processor features.

PiperOrigin-RevId: 715153229
Change-Id: I570fa349f96829d5da3b32c928480ddf67176cad
2025-01-13 16:45:10 -08:00
Evan Brown
d498bf66ef Add special handling for hashing integral types so that we can optimize Read1To3 and Read4To8 for the strings case.
We introduce combine_raw as an implementation detail of HashState that allows for keeping the same IntegralFastPath implementation but to have separately optimized Read*To* functions for the string hashing use case.

PiperOrigin-RevId: 715122407
Change-Id: Iabe35d2d3ecbca5d134a782378b7ecb2e3b9aac6
2025-01-13 15:10:06 -08:00
Chris Kennelly
67d3d20683 Use unused FixedArray instances.
PiperOrigin-RevId: 715082478
Change-Id: Iaed780e2768da4a7b6173b156b3025484e36f5bf
2025-01-13 13:13:45 -08:00
Evan Brown
34875a5685 Minor reformatting
PiperOrigin-RevId: 715033647
Change-Id: I0baa842a419b1fb9e024dc081fbd7b358636bf46
2025-01-13 10:57:16 -08:00
Evan Brown
c8977ff7b5 Avoid flaky expectation in WaitDurationWoken test case in MSVC.
PiperOrigin-RevId: 715017153
Change-Id: Icbbf70f3694e3a098b2c150eb927bfb0d2504d52
2025-01-13 10:14:56 -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
Evan Brown
3f770c4d96 Mix pointers twice in absl::Hash.
PiperOrigin-RevId: 714244777
Change-Id: I832f29fe195d13154469be8292d091291a8f928b
2025-01-10 15:16:41 -08:00
Abseil Team
69b5bd124e New internal-use-only classes AsStructuredLiteralImpl and AsStructuredValueImpl
PiperOrigin-RevId: 714130164
Change-Id: Ib76de9efeecf5344ed67ca27680937971d9a84e3
2025-01-10 12:04:50 -08:00
Abseil Team
81d48b3e43 Annotate some Abseil container methods with [[clang::lifetime_capture_by(...)]]
This will allow catching some lifetime issues such as the following:
```
absl::flat_hash_set<absl::string_view> s;
s.add(std::string(...));  // dangling
```
PiperOrigin-RevId: 714123078
Change-Id: I67f382e97fa8d5e2dc2b58a1ccb8cc013819e4b3
2025-01-10 11:43:32 -08:00