Commit Graph
258 Commits
Author SHA1 Message Date
Chandler CarruthandJon Ross-Perkins e99448eecf Add support for a custom error type in ErrorOr (#5834)
This doesn't split apart the current error type into one that tracks
location and one that doesn't, although that might be easier to do once
we have this.

Instead, this is primarily intended to support custom error types that
lazily materialize the error message in case that can be avoided by
completely handling the error. For example, many file system operations
are *expected* to produce errors even in the hot path and we don't want
to render `ENOENT` (for example) to a pretty string and instead will
directly query the error to understand and handle it in code.

The type parameter ordering isn't the most obvious, but helpfully allows
us to default the error type in a useful way.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-07-23 23:15:41 +00:00
Chandler CarruthandJon Ross-Perkins b39c7c93aa Add hashtable benchmark coverage for integers with low zero bits (#5735)
These have unique challenges for our hashing scheme, and so its useful
to make sure the hash functions we use can handle them.

Some other work on Abseil's hash tables uncovered that this might be
risky and may have surfaced some improvements to reduce the impact here,
but the first step seems to try and start covering this path in the
benchmarks.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-06-28 00:52:58 +00:00
Jon Ross-Perkins fcf445b517 Print captured stdout/stderr on test crashes (#5740)
Related to #5733, but as a general fix, this will hopefully make it a
little easier to debug test/autoupdate crashes.
2025-06-26 20:28:21 +00:00
Jon Ross-Perkins 9855818bb8 Move PrettyStackTraceFunction to common (#5739)
I'm looking at using this as part of file_test to dump streaming,
related to #5733
2025-06-26 18:39:54 +00:00
Jon Ross-Perkins 3070e5cfc6 Try using getMainExecutable to address argv[0] limitations (#5643)
When finding an executable, this validates that the returned binary is a
symlink back to the same thing as /proc/self/exe, also using that as a
fallback for different things.

Looking back at #3912, we started using `findProgramByName` in order to
avoid path canonicalization done by `GetMainExecutable`. That created
issues as in #5096, wherein an `argv[0]` that's not explicit enough
(`llvm-symbolizer` instead of the full path, done in [LLVM's
Signals.cpp](https://github.com/llvm/llvm-project/blob/4f60f45130c6bd96c79e468fe9927a29af760f56/llvm/lib/Support/Signals.cpp#L198))
leads to incorrect results (finding an `llvm-symbolizer` in `$PATH`).

One option to fix this would be to patch LLVM to provide an absolute
path for `llvm-symbolizer`. However, I'll suggest that passing a
filename in `argv[0]` is not terribly uncommon, and could be a migration
limitation if we force it. The failure mode is also opaque; for example:

```
$ /bin/sh -c "exec -a llvm-symbolizer ./bazel-bin/toolchain/carbon"
error: expected carbon-busybox symlink at `/usr/lib/llvm-19/bin/llvm-symbolizer`
```

Combined with the `setenv` of `LLVM_SYMBOLIZER_PATH` in
`busybox_main.cpp`, this is intended to fix #5096.
2025-06-12 16:05:11 +00:00
Richard SmithandJon Ross-Perkins dc7839e893 Add a new facility GrowingRange for a range that might grow during iteration. (#5641)
Use it to replace most existing modernize-loop-convert lints with
range-based for loops. As requested in review of #5475.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-06-10 23:21:17 +00:00
Richard SmithandDana Jansens 6753a715f6 Avoid moving around large suspended function states in the deferred definition worklist. (#5608)
We already go to some effort to avoid moving these, but we end up still
moving them twice: once when adding to the worklist and again when
reversing a chunk of the worklist.

* To avoid a move when constructing the worklist, add an `EmplaceResult`
utility that allows the result of a function call to be emplaced into a
container.
* To avoid moves when reversing the list, stop reversing it. Instead of
reversing the list and popping tasks as we run them, we accumulate a
sequence of tasks for a deferred definition region, run them in the
order they were enqueued, then pop them all at the end. This will in
some cases increase the high-water-mark of the size of the worklist, but
not asymptotically. The same high-water-mark could be reached with the
old approach by reordering the declarations in the source file.

In passing, we no longer create `LeaveDeferredDefinitionRegion` tasks
for non-nested regions. We don't need them, because we can detect that
condition by our reaching the end of the worklist. This means that the
enter / leave region actions are now always in correspondence -- we only
create them for *nested* regions. The tasks have been renamed to convey
this.

We still move the suspended function states around if the worklist grows
to over 64 entries and gets reallocated. We could potentially address
that issue too by switching to a chunked allocation strategy as is used
by `ValueStore` and then make the tasks noncopyable, but I'm not
attempting that in this PR.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-06-10 13:37:16 +00:00
Dana Jansens 11e82e9872 Revert "Add FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to fuzzer mode and enable DCHECKs under fuzzing (#5489)" (#5580)
This reverts commit 1889ee3904.

We have identified that this is causing ODR violations, because the
`fuzzer` feature is being added `cc_fuzz_test` targets, and thus any
includes they make, but not to the rest of the build. Any include that
is seen from both places has ODR violations if it branches on
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION.

We need to apply fuzzer globally when building fuzz targets somehow, or
not set different defines in fuzzer.
2025-05-30 16:20:43 +00:00
Thomas Köppe f18fc40a32 Add missing standard library header inclusions (#5486)
Discovered by clang-tidy.

See also #5316.
2025-05-28 22:48:20 +00:00
Jon Ross-Perkins 14f19b5a86 Use TypeEnum for ScopeId to refactor call structure (#5491)
I'm trying to make the offsetting a little easier to understand, and
also get a better `requires` structure on calls. The second is for an
attempt to refactor the `Formatter` API, but also changing the `InstId`
`derived_from` requires seems helpful for clarity on what's really
happening.
2025-05-20 22:16:28 +00:00
Jon Ross-Perkins dbf12eb3fc Add a SameAsOneOf helper (#5490)
Trying to make repeated `std::same_as` easier to write. Calling it
"concepts.h" because I figure we'll maybe have a couple more things like
this.

Was looking at this because I may add a couple more similar constructs.
2025-05-16 01:39:19 +00:00
Dana Jansens 1889ee3904 Add FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to fuzzer mode and enable DCHECKs under fuzzing (#5489)
The `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` flag is a standard flag
proposed by LibFuzzer that is meant to inform compiled code that it is
being built for fuzzing, as described here:
https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode

We add the flag to our `fuzzing` feature/config, and enable DCHECKs when
under fuzzing so that we can catch bugs that currently are caught on the
other side of DCHECK, even if they don't cause ASAN to trap a read/write
beyond the capacity of a value store.
2025-05-15 19:53:06 +00:00
Jon Ross-Perkins 2f81858a36 Switch BuildData to char arrays (#5464)
string_view was suggested at
https://github.com/carbon-language/carbon-lang/pull/5451#discussion_r2080640267,
but it turns out it's helpful to be even more hermetic for build
configuration.
2025-05-12 23:46:02 +00:00
Jon Ross-PerkinsandChandler Carruth b1004012c3 Add linkstamp support to get the target name (#5451)
This removes hardcoding of the test target name from file_test.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-05-12 19:01:01 +00:00
Dana Jansens 517c4d3c20 Remove VariantMatch; use CARBON_KIND_SWITCH for std::variants (#5437)
Teach CARBON_KIND_SWITCH to handle mutable lvalues and rvalues, and
CARBON_KIND to forward along rvalues so that it's possible to write
`case CARBON_KIND(const T& t)`, `case CARBON_KIND(T& t)`, and `case
CARBON_KIND(T&& t)`, depending on the type that was passed to
CARBON_KIND_SWITCH.

Replace all uses of VariantMatch with their equivalent of a switch using
CARBON_KIND_SWITCH, and remove the VariantMatch helper from the
codebase.
2025-05-12 18:56:52 +00:00
Dana JansensandJon Ross-Perkins f5e69734d9 Bump clang version to 19 (#5440)
The version of clangd/clang-tidy on developer machines has slowly
diverged from the one on the CI builders, which is causing a slowly
increasing amount of pain as clang-tidy CI runs fail (incorrectly) over
things that a newer clangd/clang-tidy was perfectly fine with locally.
This bumps the Clang version used in the ubuntu builders to 19, which is
the most recent in Debian stable.

We use https://apt.llvm.org instead of LLVM's GitHub releases
(https://github.com/llvm/llvm-project/releases) as the former more
reliably has packages for newer Clang/LLVM versions on x64. The
community-build releases binaries on LLVM's GitHub have stopped
including Ubuntu packages that match the GitHub x64 Ubuntu workers for
some time (for at least the 18 and 19 releases).

By moving to apt.llvm.org packages we only download and install the
headers and libraries needed for development, rather than every output
of building llvm, which is much faster and saves lots of disk space. We
also remove the system installations of other versions of clang/llvm so
we should end up using negative disk space. We can no longer easily
cache the installation but apt.llvm.org is a reliable end point.

We bump the ubuntu image version for the github workers to 24.04, as
apt.llvm.org has stopped building images for 22.10 in 2022 at its end of
life.

The `pre_commit` workflow disabled sudo unlike the other workflows that
install Clang/LLVM, including the `clang-tidy` workflow (which is also
run on `pull_request`). We bring it into alignment with the other
workflows so that we can install the llvm packages. And we lock its
ubuntu image to 24.04 so that it can be moved in lockstep with the other
workflows that depend on Clang/LLVM.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-05-12 15:12:53 +00:00
Jon Ross-Perkins 74c0ed413c Update tool versions beyond just bazel (#5446)
#5445 updates to bazel 8.2.1, this does more updates (including to
buildifier, which does autofixes like the `sh_test` loads in the other
PR).

Note I'm using the latest available clang-format wheel. That's not
really something I expect people to have installed, but should mostly be
consistent. I'm specifically skipping clang-format 18 because it had
some broad regressions, and 19 got really confused by a `requires` on a
trailing return. Using the latest seemed probably okay since most people
won't see the difference. Do note that trailing returns in macros,
https://github.com/llvm/llvm-project/issues/47664, seems to be cropping
up again as an issue.
2025-05-08 16:24:28 +00:00
Jon Ross-Perkins 1bb5fe73f0 Update to bazel 8.2.1 (#5445)
- Updates incompatible flags.
- `rules_flex` is no longer used, so enable its flag.
- Fixes `sh_test` deps for
`--incompatible_disable_autoloads_in_main_repo`
- Broadens the exception for `rules_cc` and `bazel_tools` due to changes
to runfiles deps; trying to avoid minutiae that shouldn't affect the
decision.
2025-05-08 00:10:14 +00:00
Richard SmithandJon Ross-Perkins e060342411 Defer building thunks until the end of the enclosing definition. (#5403)
Instead of building the definition of a thunk immediately when we
generate the thunk declaration, wait until we reach the `}` of the
outermost class, interface, etc. -- at the same time when we would parse
the definition of the thunk if it were defined inline.

This fixes issues where we fail to define the thunk because it requires
an enclosing class to be complete, or its definition depends on
something declared later in the enclosing class.

Make the representation of a suspended function scope, and its
constituent suspended components, be move-only, and switch to passing it
around by rvalue reference instead of by value because it's expensive
both to move and especially to copy.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-05-07 22:20:39 +00:00
Dana Jansens 9a6c74f0cd Introduce FindIfOrNull() FindIfOrNone() and Contains() (#5322)
`FindIfOrNull` returns a pointer to the element in the range if it's
found, and nullptr otherwise. `FindIfOrNone` returns a copy of the
element in the range if it's found, and `T::None` (for a range of
elements of type `T`) otherwise. `Contains` returns a bool indicating
whether the element in the range is found.

These functions replace `llvm::find()` and `llvm::find_if()` when you
want a single answer back instead of an iterator. This avoids the need
to check against `end()`, allowing the return condition to be tested as
a standard bool.

We replace uses of `find()` and `find_if()` that did not require an
iterator with these new helpers.

Note that the return type of `FindIfOrNull` is a pointer since we can
not write `optional<T&>`, which must be tested for null. If the null
check is omitted, UB occurs and the resulting code may end up with an
incorrect pointer (https://crbug.com/40153300) into the range (or
elsewhere), rather than a null dereference. And this would be very
confusing to debug. Hopefully debug builds and sanitizers keep this from
being an issue we sink a bunch of time into debugging.
2025-04-18 14:17:48 +00:00
Thomas Köppe bf32da8dad Add missing standard library header inclusions (#5316)
Discovered by clang-tidy.
2025-04-17 15:37:57 +00:00
Jon Ross-Perkins 72cfaad1c7 Remove the indirect_value library (#5312)
This was used by explorer, and no longer has uses.
2025-04-15 20:16:58 +00:00
Jon Ross-Perkins 8c3fa80691 Add cc rule wrappers for cc_env (#5277)
Rules executed by bazel don't necessarily have the right environment to
find the symbolizer, which was the intent of `cc_env` setting
`LLVM_SYMBOLIZER_PATH`. So far, this has kind of been a case-by-case
fix, but every so often I'm trying to debug a crash in a test that
doesn't provide it. Rather continuing down this route, instead add
drop-in wrappers for cc rules so that it's hard to forget.

Note `bazel/cc_rules` is intended to mirror `bazel/carbon_rules` and
`bazel/cc_toolchains`, rather than `@rules_cc`.

AFAICT there isn't a great way to add this as a default for the `bazel
run` environment. It's not typically going to be set on its own,
forwarding `$PATH` would be too broad, and the [action
`env_sets`](https://bazel.build/docs/cc-toolchain-config-reference#using-action-config)
I think are not quite what we need (I think those don't include output
execution, only compilation).
2025-04-11 19:58:54 +00:00
Jon Ross-PerkinsandDana Jansens 3ae62f8130 Rewrite Dump calls to use std::string returns (#5195)
Thought this might be interesting for you to allow more continuous
stream use. Also eliminates the need for `DumpNoNewline`.

```
expr Dump(context, complete_type_id)
(std::string) $0 = "type(inst1553): <builtin i32>; {kind: IntType, arg0: signed, arg1: inst1508, type: type(TypeType)}"
complete_type_id.Dump()
(std::string) $1 = "type(inst1553)"
expr Dump(context, specific_id)
(std::string) $2 = "specific166: {generic: generic0, args: inst_block772}"
expr Dump(context, query_self_const_id)
(std::string) $3 = "concrete_constant(inst1510): {kind: ClassType, arg0: class0, arg1: specific166, type: type(TypeType)}"
expr Dump(context, MakeFacetTypeId(arg))
(std::string) $4 = "facet_type22: {impls interface: interface10}
  - interface10: {name: name26, parent_scope: name_scope0} `BitAnd`
complete: complete_facet_type22
  - interface10: {name: name26, parent_scope: name_scope0} `BitAnd` (to impl)"
```

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-03-27 21:17:54 +00:00
Jon Ross-Perkins 0d3d829478 Cleanup pass over llvm::seq uses (#5185)
I was thinking about this after `seq` changes in #5182, and looked for
other uses that might be replaceable. Here's the resulting cleanup
around `seq`:

- Switch to `enumerate` or `zip` when possible.
- `int _` -> `auto _` (it's typically a `size_t`, but there's no reason
to cast when unused)
- Fix a case of cast style `(size_t)...` -> `static_cast<size_t>(...)`
- Switch `(void)close_children_count` to `[[maybe_unused]]`
2025-03-26 19:25:03 +00:00
Alexander Kornienko b3c7a7e988 Fix a compilation error with a recent Clang (#5170)
This fixes a `copy constructor must pass its first argument by
reference` compilation error when compiled with a recent enough Clang
(after
https://github.com/llvm/llvm-project/commit/fe0d3e3764961b62f43f1b129f30aaec5f30bc16,
targeted for LLVM 21 release).

```
carbon/lang/common/set.h:81:59: error: copy constructor must pass its first argument by reference
   81 |   SetView(SetView<std::remove_const_t<KeyT>, KeyContextT> other_view)
      |                                                           ^
```
2025-03-24 15:45:45 +00:00
Dana Jansens 489d5298f2 Add a newline to the end of Printable::Dump() (#5155)
This makes it friendlier in interactive debuggers. If you want to print
a value without a newline from code, you will have to be calling Print()
anyway since Dump() is private, and Print() does not add a newline.
2025-03-20 16:03:43 +00:00
Boaz Brickner caaeabce09 Update comment following a rename (#5139)
Rename:
https://github.com/carbon-language/carbon-lang/pull/4100/commits/6da9a9ee19eec002878a0d59a1af00d24f515d9a
2025-03-18 15:19:22 +00:00
Dana Jansens 3d5d62e1c7 Allow making sets and maps with move-only keys and/or values (#4982)
When the key or value is move-only, then the set or map will be as well.
2025-03-03 21:23:18 +00:00
Jon Ross-PerkinsandDana Jansens 467e510d40 Document abbreviation style things (#4996)
We had a long discussion of this, so trying to document what seems to be
the conclusion... and also clean up the exceptions that I could find.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-02-27 02:13:17 +00:00
Jon Ross-Perkins 21252b5e94 Add missing trailing return types (#5006)
Noted CopyNameFromImportIR while glancing around (this one's interesting
because it's NameId, not void nor auto), did a scan just for a few other
cases. Not an exhaustive fix, and TBH assuming we'd prefer `auto ... ->
auto` since equivalent Carbon syntax would probably be `fn ... -> auto`
2025-02-24 22:41:59 +00:00
Jon Ross-Perkins 2ea2166cf8 Update pre-commit (#4995)
`pre-commit autoupdate --freeze && pre-commit run -a`
2025-02-21 00:27:15 +00:00
Jon Ross-Perkins 44a5e371b2 Reduce clangd-displayed errors for def files (#4957)
When I open a .def file, there are often 4 errors:

- The #error
- The #define is not defined
- Missing `;`
- Identifier naming

This PR is meant to disable all of these, since they can be distracting
from fixable diagnostics.
2025-02-14 17:54:39 +00:00
Jon Ross-Perkins 2fef1cb713 Switch to trailing returns in toolchain and related code. (#4919)
Also makes the style guide explicitly comment on void, but this was the
intent IIRC because it matches Carbon's `-> ()` (and "always" versus
"except for void", which we definitely went back and forth on).

Includes adjusting function pointers, which I definitely forget this
syntax works sometimes.

Excludes utils/tree_sitter/src/scanner.c because it claims to be C, but
really we should probably fix that to be cpp.
2025-02-11 18:11:14 +00:00
Calvin dcfccd3187 Support references in ErrorOr (#4889)
### Context & Motivation

The error handling utilities in `//base/error.h` are very useful for
writing code with strong safety guarantees. While hardening the `Dump`
debug utilities (from review in #4866), I encountered a rough edge with
references and pointers. After a [brief Discord discussion in
#contributing-help](https://discord.com/channels/655572317891461132/1052653651895779359/1334675462877610038),
it was suggested that adding support for references to `ErrorOr` would
be a good candidate to move forward.

Using a reference type with the `ErrorOr` class (e.g. `ErrorOr<Node&>`)
produces two errors:

<ol>
<li><strong><code>variant can not have a reference type as an
alternative</code></strong>
<ul><li>From private field: <code>std::variant&lt;Error, T&gt;
val_;</code></li></ul>
</li>
<li><strong><code>'operator-&gt;' declared as a pointer to a
reference</code></strong>
<ul><li>From member function: <code>auto operator-&gt;() -&gt;
T*</code></li></ul>
</li>
</ol>

### Changes

To support reference types, both errors are resolved:

1. `std::reference_wrapper` is conditionally used for storage when `T`
is a reference type
2. type trait aliases like `using ValueT = std::remove_reference_t<T>`
are used to produce compatible types for methods like `auto operator->()
-> ValueT*`
2025-02-04 21:08:43 +00:00
Jon Ross-Perkins b06fcc97f6 Clean up a few details of lex yaml printing (#4845)
- Escape dumped token strings (what got me here)
- Change the quoting from backticks to quotes
- Also add a `FormatEscaped` helper function for this, updating other
`.write_escaped` uses
2025-01-24 21:52:02 +00:00
Richard SmithandJon Ross-Perkins 58fba078ee Add a flag to make CHECK failures non-fatal for debugging. (#4835)
`toolchain/autoupdate_testdata.py --allow-check-fail` can now be used to
perform an autoupdate even if some `CARBON_CHECK`s are failing. What
this does will depend on how the toolchain behaves after the `CHECK`
failure, and of course there's no guarantees there, but this can be
useful if it's easier to debug the `CHECK` failure by looking at the
produced SemIR.

Internally, this uses `bazel build --config=non-fatal-checks`, which in
turn specifies a `--per_file_copt` for `check_internal.cpp`. The intent
here is that the rebuild required to enable or disable this mode is as
small as reasonably possible.

This mode is not compatible with `-c opt`, as it's important that check
failure calls are `[[noreturn]]` in `-c opt` mode.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-01-23 20:47:51 +00:00
Jon Ross-Perkins 1670baf180 Make binary operators non-member (#4838)
Came up on #4831, style:

"For a type T whose values can be compared for equality, define a
non-member operator== and document when two values of type T are
considered equal."
https://google.github.io/styleguide/cppguide.html#Operator_Overloading

Note while we could put some of these out-of-line, it's helpful to keep
them inside the braces:
- For private member access
- For templated cases so that we aren't duplicating templates
- Very mild preference for keeping class's API documented within the
braces
2025-01-23 20:25:06 +00:00
Jon Ross-PerkinsandGeoff Romer 4c4c4a4d2c Add RawStringOstream for slightly simpler streaming to strings (#4817)
This adds a RawStringOstream. Versus TestRawOstream, which is
consolidated over to RawStringOstream, it uses a string for storage
instead of a vector, mainly to support move-to-string semantics. Versus
llvm::raw_string_ostream, it owns the string and supports pwrite (which
is needed for driver and its fd_ostream compatibility requirement).

This converts most uses of llvm::raw_string_ostream, leaving behind a
few in InstNamer that explicitly cannot own the string, such as:

```
     llvm::raw_string_ostream(name)
          << "_" << tree.tokens().GetColumnNumber(token);
```

I have this as its own library so that it can use CHECK.

Yes this doesn't save much code, but it's code we repeatedly write.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2025-01-18 01:11:44 +00:00
Geoff RomerandRichard Smith 13434f0e8a Model var as a pattern operator (#4720)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-01-17 17:51:34 +00:00
Jon Ross-PerkinsandRichard Smith a3e66d6116 Fix short option error (#4796)
"unsigned char" prints as an integer, not a char

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-01-14 00:44:41 +00:00
Jon Ross-Perkins 82a346730a Fix clang-tidy issues (#4786)
Both of these I noticed from testing #4785, but they occur at head.

```
(elided)/execroot/_main/common/raw_hashtable.h:532:40: error: do not use nested 'std::max' calls, use an initializer list instead [modernize-min-max-use-initializer-list,-warnings-as-errors]
  532 |   static constexpr ssize_t Alignment = std::max<ssize_t>(
      |                                        ^
  533 |       {alignof(MetadataGroup), alignof(StorageEntry<KeyT, ValueT>)});
      |        ~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |        static_cast<long>(alignof(MetadataGroup)) static_cast<long>(alignof(StorageEntry<KeyT, ValueT>))

(elided)/execroot/_main/toolchain/install/busybox_info_test.cpp:259:8: error: unused local variable 'usr_prefix' of type 'std::filesystem::path' [bugprone-unused-local-non-trivial-variable,-warnings-as-errors]
  259 |   auto usr_prefix = MakeInstallTree(dir_ / "usr");
      |        ^
(elided)/execroot/_main/toolchain/install/busybox_info_test.cpp:260:8: error: unused local variable 'usr_local_prefix' of type 'std::filesystem::path' [bugprone-unused-local-non-trivial-variable,-warnings-as-errors]
  260 |   auto usr_local_prefix = MakeInstallTree(dir_ / "usr/local");
      |        ^
```

The std::max diagnostic seems a little confused, but the initializer
list seems like it can be dropped without any loss. The unused locals
diagnostic is correct.

Neither of these seem like they should be newer than my last clang-tidy
pass, maybe I just missed them in other sweeps.
2025-01-10 00:22:04 +00:00
624950c62c Store hash in the probed_indices array in common/raw_hashtable.h to avoid its recomputation. (#4726)
Store hash in probed_indices array to avoid its recomputation.

Benchmarks on ARM (altra, aarch64).
```
name                                                  old CYCLES/op        new CYCLES/op        delta
BM_MapInsertSeq<Map<int, int>>/1                         119 ± 2%             119 ± 1%     ~     (p=0.961 n=55+54)
BM_MapInsertSeq<Map<int, int>>/2                         133 ± 1%             134 ± 1%     ~     (p=0.342 n=56+57)
BM_MapInsertSeq<Map<int, int>>/3                         150 ± 1%             150 ± 1%     ~     (p=0.856 n=56+57)
BM_MapInsertSeq<Map<int, int>>/4                         167 ± 2%             167 ± 2%     ~     (p=0.430 n=56+57)
BM_MapInsertSeq<Map<int, int>>/8                         234 ± 5%             234 ± 3%     ~     (p=0.957 n=57+57)
BM_MapInsertSeq<Map<int, int>>/16                        368 ± 4%             368 ± 4%     ~     (p=0.762 n=57+57)
BM_MapInsertSeq<Map<int, int>>/32                        650 ± 4%             650 ± 4%     ~     (p=0.955 n=57+57)
BM_MapInsertSeq<Map<int, int>>/64                      1.93k ± 4%           1.98k ± 4%   +2.35%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/256                     9.68k ± 5%           9.85k ± 3%   +1.74%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/4096                     177k ± 3%            163k ± 2%   -8.17%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/65536                   3.99M ± 3%           3.87M ± 4%   -3.12%  (p=0.000 n=56+56)
BM_MapInsertSeq<Map<int, int>>/1048576                 90.5M ± 5%           91.3M ± 6%   +0.87%  (p=0.025 n=55+55)
BM_MapInsertSeq<Map<int, int>>/16777216                2.77G ± 8%           2.74G ± 9%     ~     (p=0.076 n=57+57)
BM_MapInsertSeq<Map<int, int>>/56                      1.05k ± 5%           1.05k ± 5%     ~     (p=0.727 n=57+57)
BM_MapInsertSeq<Map<int, int>>/224                     6.29k ± 5%           6.37k ± 4%   +1.32%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/3584                     124k ± 4%            109k ± 3%  -12.46%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/57344                   2.67M ± 4%           2.50M ± 4%   -6.40%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/917504                  65.3M ± 6%           65.8M ± 6%   +0.89%  (p=0.050 n=55+56)
BM_MapInsertSeq<Map<int, int>>/14680064                2.17G ±10%           2.14G ± 9%   -1.55%  (p=0.032 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/1                       122 ± 1%             122 ± 1%     ~     (p=0.415 n=56+56)
BM_MapInsertSeq<Map<int*, int*>>/2                       136 ± 1%             136 ± 1%     ~     (p=0.861 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/3                       153 ± 1%             153 ± 1%     ~     (p=0.607 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/4                       170 ± 2%             174 ± 3%   +2.34%  (p=0.001 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/8                       238 ± 4%             242 ± 3%   +1.59%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/16                      382 ± 4%             383 ± 4%     ~     (p=0.977 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/32                      701 ± 7%             682 ± 5%   -2.69%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/64                    2.13k ± 6%           2.09k ± 3%   -1.89%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/256                   10.3k ± 3%           10.2k ± 3%   -0.94%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/4096                   184k ± 2%            179k ± 2%   -2.62%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/65536                 3.63M ± 2%           3.68M ± 3%   +1.22%  (p=0.000 n=54+57)
BM_MapInsertSeq<Map<int*, int*>>/1048576                129M ±10%            129M ±10%     ~     (p=0.874 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/16777216              3.27G ±11%           3.24G ±10%     ~     (p=0.451 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/56                    1.18k ± 9%           1.10k ± 5%   -6.52%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/224                   6.76k ± 5%           6.59k ± 4%   -2.55%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/3584                   117k ± 2%            115k ± 3%   -1.93%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/57344                 2.22M ± 3%           2.24M ± 2%   +0.87%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/917504                95.0M ± 8%           94.8M ± 9%     ~     (p=0.894 n=55+57)
BM_MapInsertSeq<Map<int*, int*>>/14680064              2.42G ±14%           2.40G ±13%     ~     (p=0.852 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/1             124 ± 1%             124 ± 1%     ~     (p=0.604 n=56+55)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/2             140 ± 1%             140 ± 1%     ~     (p=0.181 n=56+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/3             158 ± 1%             158 ± 3%     ~     (p=1.000 n=56+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/4             176 ± 2%             176 ± 3%     ~     (p=0.125 n=56+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/8             247 ± 4%             247 ± 2%     ~     (p=0.614 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/16            391 ± 3%             391 ± 2%     ~     (p=0.993 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/32            690 ± 3%             691 ± 3%     ~     (p=0.224 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/64          2.17k ± 3%           2.22k ± 3%   +1.94%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/256         11.1k ± 3%           11.3k ± 3%   +1.58%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/4096         204k ± 2%            193k ± 2%   -5.65%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/65536       5.19M ± 3%           5.09M ± 3%   -2.05%  (p=0.000 n=56+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/1048576      124M ±10%            123M ± 6%     ~     (p=0.626 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/16777216    3.30G ± 9%           3.25G ± 8%   -1.39%  (p=0.019 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/56          1.12k ± 3%           1.12k ± 3%     ~     (p=0.482 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/224         7.04k ± 4%           7.14k ± 3%   +1.36%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/3584         138k ± 2%            126k ± 2%   -8.89%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/57344       3.48M ± 4%           3.34M ± 4%   -3.93%  (p=0.000 n=56+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/917504      84.4M ± 7%           84.9M ± 6%     ~     (p=0.159 n=56+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/14680064    2.42G ± 9%           2.40G ±10%     ~     (p=0.300 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1             168 ± 0%             168 ± 0%     ~     (p=0.555 n=56+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/2             208 ± 0%             208 ± 0%     ~     (p=0.722 n=52+53)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3             248 ± 0%             248 ± 0%     ~     (p=0.248 n=53+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4             288 ± 0%             288 ± 0%     ~     (p=0.185 n=54+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/8             457 ± 0%             457 ± 0%     ~     (p=0.665 n=53+53)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/16            867 ± 1%             867 ± 1%     ~     (p=0.174 n=47+52)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/32          1.61k ± 3%           1.62k ± 4%     ~     (p=0.402 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/64          4.96k ± 9%           4.89k ± 5%   -1.37%  (p=0.046 n=57+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/256         26.9k ± 8%           26.5k ± 8%   -1.51%  (p=0.004 n=56+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4096         600k ± 3%            588k ± 2%   -2.07%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/65536       13.9M ± 3%           13.5M ± 2%   -2.99%  (p=0.000 n=55+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1048576      407M ± 7%            393M ± 5%   -3.27%  (p=0.000 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/16777216    10.2G ± 8%            9.9G ± 5%   -3.50%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/56          2.81k ± 5%           2.81k ± 4%     ~     (p=0.809 n=56+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/224         17.9k ± 6%           17.6k ± 5%   -1.20%  (p=0.035 n=57+52)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3584         374k ± 3%            367k ± 3%   -1.80%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/57344       8.64M ± 3%           8.53M ± 2%   -1.29%  (p=0.000 n=55+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/917504       247M ± 6%            244M ± 5%   -1.19%  (p=0.021 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/14680064    6.81G ± 8%           6.64G ± 6%   -2.46%  (p=0.000 n=57+57)
```

Benchmarks on x86
```
name                                                  old cpu/op   new cpu/op   delta
BM_MapInsertSeq<Map<int, int>>/1                      32.9ns ± 3%  32.6ns ± 3%   -0.84%  (p=0.027 n=54+51)
BM_MapInsertSeq<Map<int, int>>/2                      35.9ns ± 3%  35.7ns ± 4%     ~     (p=0.123 n=54+54)
BM_MapInsertSeq<Map<int, int>>/3                      39.7ns ± 3%  47.4ns ± 4%  +19.40%  (p=0.000 n=55+56)
BM_MapInsertSeq<Map<int, int>>/4                      52.7ns ± 3%  52.1ns ± 4%   -1.22%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/8                      78.1ns ± 3%  78.3ns ± 3%     ~     (p=0.141 n=50+57)
BM_MapInsertSeq<Map<int, int>>/16                      135ns ± 3%   135ns ± 4%     ~     (p=0.936 n=53+57)
BM_MapInsertSeq<Map<int, int>>/32                      249ns ± 3%   241ns ± 3%   -3.28%  (p=0.000 n=55+57)
BM_MapInsertSeq<Map<int, int>>/64                      631ns ± 3%   618ns ± 3%   -2.21%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/256                    2.62µs ± 3%  2.36µs ± 4%  -10.02%  (p=0.000 n=52+53)
BM_MapInsertSeq<Map<int, int>>/4096                   39.2µs ± 3%  37.9µs ± 4%   -3.40%  (p=0.000 n=57+56)
BM_MapInsertSeq<Map<int, int>>/65536                   972µs ± 3%   955µs ± 3%   -1.76%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/1048576                16.2ms ± 4%  16.3ms ± 5%     ~     (p=0.231 n=52+54)
BM_MapInsertSeq<Map<int, int>>/16777216                651ms ± 3%   648ms ± 2%   -0.42%  (p=0.048 n=57+56)
BM_MapInsertSeq<Map<int, int>>/56                      418ns ± 3%   401ns ± 3%   -4.10%  (p=0.000 n=54+57)
BM_MapInsertSeq<Map<int, int>>/224                    1.79µs ± 3%  1.61µs ± 3%  -10.20%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, int>>/3584                   26.0µs ± 3%  24.9µs ± 4%   -4.13%  (p=0.000 n=57+56)
BM_MapInsertSeq<Map<int, int>>/57344                   560µs ± 3%   549µs ± 3%   -2.11%  (p=0.000 n=56+57)
BM_MapInsertSeq<Map<int, int>>/917504                 10.4ms ± 3%  10.4ms ± 3%     ~     (p=0.805 n=56+56)
BM_MapInsertSeq<Map<int, int>>/14680064                422ms ± 2%   421ms ± 3%     ~     (p=0.269 n=57+56)
BM_MapInsertSeq<Map<int*, int*>>/1                    33.7ns ± 3%  33.7ns ± 3%     ~     (p=0.620 n=55+55)
BM_MapInsertSeq<Map<int*, int*>>/2                    36.7ns ± 3%  36.5ns ± 3%     ~     (p=0.160 n=55+56)
BM_MapInsertSeq<Map<int*, int*>>/3                    41.1ns ± 2%  41.0ns ± 4%     ~     (p=0.284 n=54+56)
BM_MapInsertSeq<Map<int*, int*>>/4                    45.0ns ± 3%  53.9ns ± 4%  +19.70%  (p=0.000 n=57+56)
BM_MapInsertSeq<Map<int*, int*>>/8                    77.1ns ± 3%  80.9ns ± 4%   +4.98%  (p=0.000 n=55+57)
BM_MapInsertSeq<Map<int*, int*>>/16                    130ns ± 3%   136ns ± 4%   +4.42%  (p=0.000 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/32                    244ns ± 3%   246ns ± 4%   +0.95%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/64                    620ns ± 3%   674ns ± 3%   +8.83%  (p=0.000 n=55+57)
BM_MapInsertSeq<Map<int*, int*>>/256                  2.93µs ± 3%  2.88µs ± 3%   -1.73%  (p=0.000 n=56+56)
BM_MapInsertSeq<Map<int*, int*>>/4096                 54.0µs ± 3%  50.8µs ± 4%   -6.01%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/65536                1.18ms ± 2%  1.17ms ± 4%     ~     (p=0.083 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/1048576              28.9ms ± 4%  29.1ms ± 5%   +0.91%  (p=0.007 n=55+56)
BM_MapInsertSeq<Map<int*, int*>>/16777216              914ms ± 2%   919ms ± 3%   +0.56%  (p=0.015 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/56                    404ns ± 3%   427ns ± 4%   +5.60%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/224                  1.88µs ± 3%  1.87µs ± 4%   -0.68%  (p=0.013 n=55+53)
BM_MapInsertSeq<Map<int*, int*>>/3584                 34.2µs ± 3%  32.9µs ± 4%   -4.02%  (p=0.000 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/57344                 768µs ± 3%   756µs ± 3%   -1.53%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int*, int*>>/917504               16.4ms ± 5%  16.5ms ± 7%     ~     (p=0.303 n=56+57)
BM_MapInsertSeq<Map<int*, int*>>/14680064              607ms ± 2%   613ms ± 3%   +0.92%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/1          34.1ns ± 3%  34.2ns ± 4%     ~     (p=0.288 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/2          37.4ns ± 3%  37.5ns ± 3%     ~     (p=0.316 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/3          41.8ns ± 4%  49.1ns ± 3%  +17.45%  (p=0.000 n=57+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/4          54.6ns ± 3%  53.9ns ± 5%   -1.35%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/8          81.4ns ± 3%  81.4ns ± 4%     ~     (p=0.956 n=56+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/16          139ns ± 3%   139ns ± 3%     ~     (p=0.754 n=57+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/32          256ns ± 3%   250ns ± 4%   -2.32%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/64          705ns ± 4%   687ns ± 3%   -2.56%  (p=0.000 n=53+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/256        2.95µs ± 5%  3.05µs ± 3%   +3.42%  (p=0.000 n=52+55)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/4096       49.6µs ± 3%  50.8µs ± 4%   +2.44%  (p=0.000 n=55+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/65536      1.39ms ± 3%  1.40ms ± 3%   +0.65%  (p=0.004 n=57+56)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/1048576    37.7ms ± 4%  38.1ms ± 4%   +1.07%  (p=0.001 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/16777216    1.20s ± 3%   1.20s ± 3%   +0.50%  (p=0.040 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/56          432ns ± 3%   414ns ± 3%   -3.99%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/224        1.92µs ± 4%  1.89µs ± 4%   -1.48%  (p=0.000 n=52+55)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/3584       31.5µs ± 4%  32.1µs ± 4%   +1.89%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/57344       757µs ± 3%   748µs ± 3%   -1.28%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/917504     21.9ms ± 4%  22.1ms ± 5%     ~     (p=0.096 n=57+57)
BM_MapInsertSeq<Map<int, llvm::StringRef>>/14680064    735ms ± 3%   737ms ± 3%     ~     (p=0.208 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1          41.5ns ± 3%  41.4ns ± 4%     ~     (p=0.790 n=54+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/2          50.6ns ± 4%  50.6ns ± 5%     ~     (p=0.684 n=53+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3          59.7ns ± 4%  59.4ns ± 4%     ~     (p=0.277 n=55+53)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4          68.5ns ± 5%  68.2ns ± 5%     ~     (p=0.623 n=54+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/8           107ns ± 5%   107ns ± 9%     ~     (p=0.359 n=54+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/16          200ns ± 6%   200ns ± 6%     ~     (p=0.772 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/32          373ns ± 8%   371ns ± 7%     ~     (p=0.541 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/64         1.11µs ± 9%  1.09µs ± 8%   -2.09%  (p=0.003 n=56+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/256        5.61µs ± 5%  5.48µs ± 7%   -2.42%  (p=0.000 n=54+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4096        153µs ± 4%   147µs ± 6%   -3.80%  (p=0.000 n=54+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/65536      3.24ms ± 3%  3.10ms ± 3%   -4.19%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1048576     100ms ± 2%    98ms ± 3%   -1.97%  (p=0.000 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/16777216    2.45s ± 2%   2.40s ± 3%   -2.09%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/56          637ns ± 8%   630ns ± 8%     ~     (p=0.101 n=56+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/224        3.77µs ± 6%  3.68µs ± 6%   -2.42%  (p=0.000 n=56+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3584       92.1µs ± 7%  88.4µs ± 6%   -4.04%  (p=0.000 n=57+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/57344      1.99ms ± 4%  1.92ms ± 3%   -3.47%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/917504     62.1ms ± 4%  60.9ms ± 3%   -1.93%  (p=0.000 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/14680064    1.53s ± 3%   1.50s ± 3%   -1.85%  (p=0.000 n=57+57)
```

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2024-12-31 05:44:37 +00:00
Vitaly Goldshteyn 384e1cbb92 Update Read*To* to improve operation dependency graph. (#4746)
Benchmarks for StringRef key seem slightly positive.

```
name                                                               old CYCLES/op        new CYCLES/op        delta
BM_MapContainsHit<Map<llvm::StringRef, int>>/1/256                   24.2 ± 0%            23.9 ± 0%  -1.14%        (p=0.000 n=54+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/2/256                   24.2 ± 0%            23.9 ± 0%  -1.15%        (p=0.000 n=53+54)
BM_MapContainsHit<Map<llvm::StringRef, int>>/3/256                   24.2 ± 0%            23.9 ± 0%  -1.15%        (p=0.000 n=53+54)
BM_MapContainsHit<Map<llvm::StringRef, int>>/4/256                   24.2 ± 0%            23.9 ± 0%  -1.14%        (p=0.000 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/8/256                   25.4 ± 3%            26.3 ± 4%  +3.61%        (p=0.000 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/16/256                  29.1 ± 2%            29.0 ± 2%  -0.28%        (p=0.030 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/32/256                  29.2 ± 2%            29.0 ± 1%  -0.59%        (p=0.000 n=57+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/64/256                  30.1 ± 2%            30.0 ± 2%  -0.43%        (p=0.045 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/256/256                 30.5 ± 1%            30.3 ± 1%  -0.56%        (p=0.000 n=56+56)
BM_MapContainsHit<Map<llvm::StringRef, int>>/256/64                  29.2 ± 1%            29.2 ± 2%    ~           (p=0.513 n=55+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/256/128                 29.6 ± 1%            29.5 ± 1%  -0.34%        (p=0.002 n=55+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/4096/256                32.0 ± 2%            31.9 ± 2%    ~           (p=0.082 n=55+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/4096/1024               37.8 ± 2%            37.8 ± 1%    ~           (p=0.751 n=57+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/4096/2048               45.3 ± 2%            45.5 ± 2%  +0.46%        (p=0.001 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/65536/256               34.3 ± 2%            34.2 ± 2%  -0.46%        (p=0.000 n=57+56)
BM_MapContainsHit<Map<llvm::StringRef, int>>/65536/16384             72.4 ± 3%            72.3 ± 2%    ~           (p=0.458 n=54+50)
BM_MapContainsHit<Map<llvm::StringRef, int>>/65536/32768             77.7 ± 3%            77.6 ± 3%    ~           (p=0.774 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/1048576/256             34.9 ± 1%            34.8 ± 2%    ~           (p=0.051 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/1048576/262144           115 ± 5%             115 ± 5%    ~           (p=0.660 n=57+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/1048576/524288           145 ± 4%             145 ± 5%    ~           (p=0.917 n=57+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/16777216/256            36.5 ± 2%            36.5 ± 2%    ~           (p=0.250 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/16777216/4194304         288 ± 3%             287 ± 4%    ~           (p=0.058 n=56+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/16777216/8388608         303 ± 2%             302 ± 3%  -0.47%        (p=0.044 n=53+54)
BM_MapContainsHit<Map<llvm::StringRef, int>>/56/256                  29.1 ± 3%            29.0 ± 3%    ~           (p=0.147 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/224/256                 30.7 ± 2%            30.6 ± 2%    ~           (p=0.140 n=56+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/3584/256                31.4 ± 1%            31.3 ± 1%  -0.42%        (p=0.003 n=53+54)
BM_MapContainsHit<Map<llvm::StringRef, int>>/3584/896                35.8 ± 2%            36.0 ± 2%  +0.58%        (p=0.000 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/3584/1792               43.5 ± 1%            43.6 ± 2%  +0.21%        (p=0.032 n=51+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/57344/256               34.3 ± 2%            34.1 ± 1%  -0.43%        (p=0.003 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/57344/14336             67.1 ± 2%            66.8 ± 2%    ~           (p=0.057 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/57344/28672             72.8 ± 3%            72.5 ± 3%  -0.45%        (p=0.032 n=57+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/917504/256              34.7 ± 2%            34.6 ± 2%    ~           (p=0.065 n=56+57)
BM_MapContainsHit<Map<llvm::StringRef, int>>/917504/229376            104 ± 4%             104 ± 5%    ~           (p=0.853 n=55+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/917504/458752            114 ± 6%             114 ± 5%    ~           (p=0.643 n=56+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/14680064/256            36.4 ± 2%            36.2 ± 2%  -0.58%        (p=0.001 n=56+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/14680064/3670016         271 ± 2%             271 ± 4%    ~           (p=0.632 n=55+55)
BM_MapContainsHit<Map<llvm::StringRef, int>>/14680064/7340032         285 ± 3%             285 ± 3%    ~           (p=0.658 n=57+55)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/1                      19.3 ± 1%            19.3 ± 2%    ~           (p=0.201 n=55+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/2                      19.4 ± 1%            19.3 ± 1%    ~           (p=0.191 n=56+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/3                      19.4 ± 1%            19.4 ± 2%    ~           (p=0.422 n=55+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/4                      19.4 ± 1%            19.4 ± 1%    ~           (p=0.179 n=56+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/8                      19.5 ± 2%            19.5 ± 1%    ~           (p=0.148 n=54+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/16                     19.7 ± 2%            19.6 ± 2%    ~           (p=0.204 n=54+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/32                     20.0 ± 3%            20.0 ± 3%    ~           (p=0.917 n=56+54)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/64                     19.8 ± 3%            19.8 ± 3%    ~           (p=0.245 n=57+54)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/256                    20.1 ± 3%            20.1 ± 3%    ~           (p=0.307 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/4096                   20.1 ± 3%            20.2 ± 2%    ~           (p=0.070 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/65536                  20.5 ± 3%            20.5 ± 3%    ~           (p=0.174 n=56+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/1048576                20.9 ± 2%            20.8 ± 3%    ~           (p=0.476 n=53+55)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/16777216               22.2 ± 4%            22.2 ± 3%    ~           (p=0.807 n=57+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/56                     24.9 ±28%            23.9 ±16%    ~           (p=0.058 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/224                    27.1 ±19%            26.6 ±19%    ~           (p=0.122 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/3584                   28.9 ±10%            28.7 ±10%    ~           (p=0.405 n=56+57)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/57344                  30.5 ± 7%            31.2 ± 7%  +2.32%        (p=0.000 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/917504                 31.8 ± 7%            31.7 ± 7%    ~           (p=0.713 n=57+56)
BM_MapContainsMiss<Map<llvm::StringRef, int>>/14680064               33.4 ± 9%            33.5 ± 7%    ~           (p=0.921 n=56+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/1/256                     49.3 ± 0%            48.2 ± 0%  -2.17%        (p=0.000 n=55+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/2/256                     49.3 ± 0%            48.2 ± 0%  -2.17%        (p=0.000 n=56+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/3/256                     49.3 ± 0%            48.2 ± 0%  -2.17%        (p=0.000 n=54+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/4/256                     49.3 ± 0%            48.2 ± 0%  -2.17%        (p=0.000 n=54+53)
BM_MapLookupHit<Map<llvm::StringRef, int>>/8/256                     49.0 ± 0%            48.0 ± 0%  -2.02%        (p=0.000 n=51+51)
BM_MapLookupHit<Map<llvm::StringRef, int>>/16/256                    51.8 ± 1%            51.3 ± 1%  -0.89%        (p=0.000 n=50+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/32/256                    51.8 ± 1%            51.3 ± 1%  -1.07%        (p=0.000 n=56+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/64/256                    52.4 ± 1%            51.8 ± 1%  -1.12%        (p=0.000 n=57+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/256/256                   54.6 ± 1%            54.1 ± 1%  -0.94%        (p=0.000 n=53+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/256/64                    51.9 ± 1%            51.4 ± 1%  -0.95%        (p=0.000 n=55+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/256/128                   52.5 ± 1%            52.0 ± 1%  -1.07%        (p=0.000 n=57+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/4096/256                  62.0 ± 3%            61.6 ± 3%  -0.62%        (p=0.002 n=55+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/4096/1024                 74.6 ± 1%            73.5 ± 1%  -1.38%        (p=0.000 n=56+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/4096/2048                 80.9 ± 1%            79.8 ± 1%  -1.34%        (p=0.000 n=57+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/65536/256                 72.0 ± 2%            71.4 ± 2%  -0.77%        (p=0.000 n=56+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/65536/16384                145 ± 4%             145 ± 3%    ~           (p=0.662 n=57+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/65536/32768                155 ± 4%             156 ± 4%    ~           (p=0.541 n=57+54)
BM_MapLookupHit<Map<llvm::StringRef, int>>/1048576/256               73.1 ± 2%            72.5 ± 2%  -0.73%        (p=0.000 n=56+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/1048576/262144             281 ± 7%             283 ± 5%    ~           (p=0.284 n=57+49)
BM_MapLookupHit<Map<llvm::StringRef, int>>/1048576/524288             342 ± 5%             342 ± 5%    ~           (p=0.684 n=57+53)
BM_MapLookupHit<Map<llvm::StringRef, int>>/16777216/256              77.5 ± 2%            76.9 ± 2%  -0.74%        (p=0.000 n=55+54)
BM_MapLookupHit<Map<llvm::StringRef, int>>/16777216/4194304           750 ± 3%             749 ± 3%    ~           (p=0.458 n=57+53)
BM_MapLookupHit<Map<llvm::StringRef, int>>/16777216/8388608           802 ± 2%             801 ± 3%    ~           (p=0.518 n=57+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/56/256                    51.9 ± 1%            51.3 ± 1%  -1.10%        (p=0.000 n=57+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/224/256                   54.0 ± 1%            53.5 ± 1%  -1.01%        (p=0.000 n=56+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/3584/256                  58.8 ± 2%            58.1 ± 2%  -1.28%        (p=0.000 n=56+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/3584/896                  69.7 ± 2%            68.7 ± 1%  -1.35%        (p=0.000 n=57+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/3584/1792                 77.1 ± 1%            76.0 ± 1%  -1.45%        (p=0.000 n=55+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/57344/256                 71.3 ± 2%            70.7 ± 3%  -0.85%        (p=0.000 n=55+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/57344/14336                128 ± 3%             128 ± 3%    ~           (p=0.556 n=57+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/57344/28672                140 ± 4%             140 ± 3%    ~           (p=0.735 n=57+51)
BM_MapLookupHit<Map<llvm::StringRef, int>>/917504/256                72.8 ± 2%            72.3 ± 2%  -0.76%        (p=0.000 n=57+57)
BM_MapLookupHit<Map<llvm::StringRef, int>>/917504/229376              242 ± 7%             243 ± 6%    ~           (p=0.303 n=57+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/917504/458752              264 ± 7%             264 ± 6%    ~           (p=0.823 n=57+55)
BM_MapLookupHit<Map<llvm::StringRef, int>>/14680064/256              76.4 ± 2%            75.8 ± 3%  -0.78%        (p=0.000 n=57+56)
BM_MapLookupHit<Map<llvm::StringRef, int>>/14680064/3670016           696 ± 3%             698 ± 3%    ~           (p=0.189 n=56+53)
BM_MapLookupHit<Map<llvm::StringRef, int>>/14680064/7340032           749 ± 3%             750 ± 3%    ~           (p=0.266 n=55+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/1/256                     34.9 ± 0%            35.0 ± 0%  +0.36%        (p=0.000 n=56+50)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/2/256                     34.9 ± 0%            35.0 ± 0%  +0.35%        (p=0.000 n=55+53)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/3/256                     34.9 ± 0%            35.0 ± 0%  +0.35%        (p=0.000 n=55+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/4/256                     34.9 ± 0%            35.0 ± 0%  +0.36%        (p=0.000 n=56+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/8/256                     37.5 ± 3%            37.6 ± 2%    ~           (p=0.081 n=57+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/16/256                    39.4 ± 1%            39.5 ± 2%    ~           (p=0.054 n=55+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/32/256                    40.0 ± 3%            39.9 ± 4%    ~           (p=0.449 n=56+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/64/256                    40.0 ± 1%            40.1 ± 2%    ~           (p=0.796 n=54+54)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/256/256                   41.1 ± 2%            41.2 ± 2%    ~           (p=0.061 n=53+50)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/256/64                    39.6 ± 2%            39.6 ± 2%    ~           (p=0.695 n=55+52)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/256/128                   40.2 ± 2%            40.1 ± 2%    ~           (p=0.507 n=53+49)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/4096/256                  43.4 ± 2%            43.5 ± 2%    ~           (p=0.300 n=53+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/4096/1024                 50.9 ± 2%            51.8 ± 2%  +1.79%        (p=0.000 n=56+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/4096/2048                 58.2 ± 1%            58.3 ± 1%    ~           (p=0.072 n=57+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/65536/256                 46.1 ± 1%            46.1 ± 2%    ~           (p=0.197 n=54+53)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/65536/16384               88.1 ± 5%            88.9 ± 4%  +0.90%        (p=0.011 n=57+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/65536/32768               92.4 ± 3%            93.6 ± 3%  +1.35%        (p=0.000 n=57+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/1048576/256               46.6 ± 2%            46.7 ± 2%    ~           (p=0.687 n=51+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/1048576/262144             144 ± 7%             145 ± 6%    ~           (p=0.130 n=57+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/1048576/524288             181 ± 4%             182 ± 4%    ~           (p=0.057 n=56+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/16777216/256              48.9 ± 2%            48.7 ± 2%  -0.30%        (p=0.042 n=56+53)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/16777216/4194304           351 ± 2%             350 ± 3%    ~           (p=0.287 n=57+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/16777216/8388608           368 ± 3%             367 ± 3%    ~           (p=0.710 n=57+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/56/256                    39.7 ± 3%            39.6 ± 3%    ~           (p=0.572 n=57+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/224/256                   41.7 ± 2%            41.6 ± 3%    ~           (p=0.233 n=55+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/3584/256                  42.6 ± 2%            42.5 ± 2%    ~           (p=0.309 n=54+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/3584/896                  49.1 ± 1%            49.8 ± 1%  +1.51%        (p=0.000 n=57+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/3584/1792                 57.0 ± 1%            57.1 ± 2%  +0.30%        (p=0.022 n=56+57)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/57344/256                 46.1 ± 2%            46.0 ± 1%  -0.28%        (p=0.013 n=55+53)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/57344/14336               82.0 ± 2%            82.6 ± 2%  +0.71%        (p=0.000 n=57+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/57344/28672               88.7 ± 2%            89.8 ± 2%  +1.22%        (p=0.000 n=57+53)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/917504/256                46.5 ± 1%            46.5 ± 2%    ~           (p=0.961 n=53+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/917504/229376              126 ± 5%             128 ± 5%  +1.64%        (p=0.000 n=57+54)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/917504/458752              140 ± 5%             141 ± 6%    ~           (p=0.162 n=57+55)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/14680064/256              48.5 ± 2%            48.3 ± 2%    ~           (p=0.094 n=55+54)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/14680064/3670016           328 ± 4%             328 ± 3%    ~           (p=0.925 n=57+56)
BM_MapUpdateHit<Map<llvm::StringRef, int>>/14680064/7340032           345 ± 3%             345 ± 3%    ~           (p=0.489 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/1/256                76.0 ± 0%            75.9 ± 0%  -0.03%        (p=0.006 n=54+47)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/2/256                71.3 ± 1%            72.1 ± 5%    ~           (p=0.750 n=52+54)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/3/256                70.9 ± 2%            70.7 ± 2%    ~           (p=0.095 n=54+52)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/4/256                70.4 ± 2%            70.6 ± 3%    ~           (p=0.458 n=47+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/8/256                75.0 ± 1%            74.2 ± 1%  -1.16%        (p=0.000 n=52+54)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/16/256               80.5 ± 3%            79.0 ± 3%  -1.88%        (p=0.000 n=51+53)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/32/256               83.2 ± 4%            82.3 ± 5%  -1.01%        (p=0.009 n=56+57)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/64/256               80.6 ± 3%            79.4 ± 4%  -1.48%        (p=0.000 n=52+54)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/256/256              83.6 ± 3%            82.6 ± 5%  -1.23%        (p=0.000 n=54+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/256/64               79.1 ± 6%            78.8 ± 8%    ~           (p=0.359 n=55+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/256/128              81.1 ± 6%            80.3 ± 9%  -1.04%        (p=0.010 n=55+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/4096/256             85.5 ± 5%            84.1 ± 4%  -1.61%        (p=0.000 n=54+57)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/4096/1024            95.7 ± 3%            95.2 ± 2%  -0.47%        (p=0.033 n=56+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/4096/2048             101 ± 2%             101 ± 1%  -0.68%        (p=0.000 n=56+54)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/65536/256            90.5 ± 4%            88.1 ± 4%  -2.57%        (p=0.000 n=56+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/65536/16384           134 ± 3%             133 ± 2%  -0.71%        (p=0.002 n=57+57)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/65536/32768           142 ± 3%             141 ± 2%  -0.90%        (p=0.000 n=57+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/1048576/256          91.2 ± 3%            89.3 ± 4%  -2.08%        (p=0.000 n=56+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/1048576/262144        209 ± 5%             208 ± 5%    ~           (p=0.170 n=57+54)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/1048576/524288        243 ± 5%             240 ± 5%  -1.05%        (p=0.020 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/16777216/256         94.3 ± 3%            92.5 ± 5%  -1.91%        (p=0.000 n=55+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/16777216/4194304      542 ± 3%             537 ± 4%  -1.02%        (p=0.000 n=57+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/16777216/8388608      566 ± 3%             561 ± 4%  -1.01%        (p=0.000 n=57+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/56/256               83.7 ±10%            81.3 ± 8%  -2.84%        (p=0.000 n=55+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/224/256              88.7 ± 8%            86.6 ± 9%  -2.40%        (p=0.001 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/3584/256             94.0 ± 5%            91.3 ± 4%  -2.83%        (p=0.000 n=56+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/3584/896              118 ± 4%             118 ± 5%    ~           (p=0.930 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/3584/1792             143 ± 4%             141 ± 4%  -1.10%        (p=0.002 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/57344/256             102 ± 4%             100 ± 4%  -2.31%        (p=0.000 n=56+57)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/57344/14336           191 ± 2%             190 ± 1%  -0.32%        (p=0.024 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/57344/28672           197 ± 2%             197 ± 1%    ~           (p=0.059 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/917504/256            103 ± 4%             101 ± 4%  -1.99%        (p=0.000 n=57+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/917504/229376         280 ± 3%             279 ± 3%    ~           (p=0.145 n=57+52)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/917504/458752         298 ± 4%             296 ± 3%    ~           (p=0.116 n=57+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/14680064/256          107 ± 4%             104 ± 4%  -2.11%        (p=0.000 n=55+56)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/14680064/3670016      613 ± 3%             612 ± 2%    ~           (p=0.224 n=57+55)
BM_MapEraseUpdateHit<Map<llvm::StringRef, int>>/14680064/7340032      637 ± 2%             635 ± 1%    ~           (p=0.075 n=56+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1                          132 ± 0%             132 ± 0%  -0.26%        (p=0.000 n=47+41)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/2                          160 ± 0%             161 ± 4%  +0.57%        (p=0.001 n=45+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3                          188 ± 2%             189 ± 3%    ~           (p=0.327 n=54+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4                          217 ± 3%             218 ± 5%    ~           (p=0.240 n=54+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/8                          342 ± 5%             341 ± 4%    ~           (p=0.282 n=53+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/16                         640 ± 3%             648 ± 8%  +1.26%        (p=0.023 n=49+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/32                       1.20k ± 8%           1.20k ± 8%    ~           (p=0.423 n=53+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/64                       3.57k ± 8%           3.55k ± 6%    ~           (p=0.557 n=57+54)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/256                      18.6k ± 5%           18.6k ± 6%    ~           (p=0.799 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/4096                      492k ± 4%            491k ± 3%    ~           (p=0.378 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/65536                    10.5M ± 2%           10.4M ± 1%    ~           (p=0.143 n=57+48)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/1048576                   323M ± 2%            322M ± 3%    ~           (p=0.098 n=56+56)
BM_MapInsertSeq<Map<ll::StringRef, int>>/16777216                 7.07G ± 3%           7.05G ± 4%    ~           (p=0.195 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/56                       2.04k ± 8%           2.03k ± 7%    ~           (p=0.124 n=52+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/224                      12.0k ± 5%           12.0k ± 4%    ~           (p=0.467 n=57+55)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/3584                      294k ± 5%            292k ± 4%    ~           (p=0.188 n=56+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/57344                    6.40M ± 2%           6.39M ± 1%    ~           (p=0.381 n=57+56)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/917504                    199M ± 3%            199M ± 3%    ~           (p=0.977 n=57+57)
BM_MapInsertSeq<Map<llvm::StringRef, int>>/14680064                 4.56G ± 3%           4.55G ± 3%    ~           (p=0.129 n=55+56)
```
2024-12-31 04:32:52 +00:00
ezbr 9d09061301 Avoid misaligned loads from StaticRandomData in the size [4, 8] hashing case. (#4743)
Avoid misaligned loads from StaticRandomData in the size [4, 8] hashing
case. We can use aligned loads in this case for lower latency. We
introduce the SampleAlignedRandomData function for this purpose.
2024-12-31 04:32:13 +00:00
ezbr afdf846636 Align StaticRandomData to cacheline size. (#4741)
Align StaticRandomData to cacheline size to ensure the whole array is on
the same cacheline.
2024-12-31 02:34:30 +00:00
Chandler CarruthandDanila Kutenin 3ae968a74c Teach the SIMD metadata group match to defer masking (#4595)
When using a byte-encoding for matched group metadata we need to mask
down to a single bit in each matching byte to make the iteration of a
range of match indices work. In most cases, this mask can be folded into
the overall match computation, but for Arm Neon, there is avoidable
overhead from this. Instead, we can defer the mask until starting to
iterate. Doing more than one iteration is relative rare so this doesn't
accumulate much waste and makes common paths a bit faster.

For the M1 this makes the SIMD match path about 2-4% faster. This isn't
enough to catch the portable match code path on the M1 though.

For some Neoverse cores the difference here is more significant (>10%
improvement) and it makes the SIMD and scalar code paths have comparable
latency. Still not clear which is better as the latency is comparable
and beyond latency the factors are very hard to analyze -- port pressure
on different parts of the CPU, etc.

Leaving the selected code path as portable since that's so much better
on the M1, and I'm hoping to avoid different code paths for different
Arm CPUs for a while.

---------

Co-authored-by: Danila Kutenin <danilak@google.com>
2024-12-20 04:40:58 +00:00
Jon Ross-PerkinsandRichard Smith 3f9a06aee3 Look at flipping clang-tidy's misc-* to enable-by-default (#4699)
I was wondering, instead of treating `misc` differently and enabling
specific checks, maybe we can flip that since we actually seem okay with
most of the checks?

The main check I'm enabling, with significant edits here, is
`misc-no-recursion`. But maybe this is helpful to enable, even with the
necessary NOLINTs, since we want to avoid recursion in the toolchain?
This PR shows some example fixes in subst.cpp (which are more stylistic,
since the code shouldn't actually have recursed due to its structure; I
think we could remove the warning on TryResolveInst the same way). Some
also just don't seem worth fixing, like those in tests files (I didn't
see a way to exclude files in .clang-tidy, so instead I'm using
NOLINTBEGIN). But I think we might actually want to fix inst_namer, and
there's enough in convert that I didn't look closely.

Also, I made some protected -> private style fixes based on
`misc-non-private-member-variables-in-classes` (this is also how I
noticed `class Real` versus `struct Real`). With node_stack, it looks
like the `protected` wasn't even used. [Per
style](https://google.github.io/styleguide/cppguide.html#Access_Control),
data members should be private outside tests. But since we can't
trivially exclude `protected` members in tests, I'm turning it off -- I
don't view it as offering enough benefit on the whole.

migrate_cpp issues are preexisting (I believe we just aren't monitoring
it), but changes there make `bazel build --config=clang-tidy -k //...`
work cleanly.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-12-17 21:20:37 +00:00
Jon Ross-Perkins c832d523be Update files and clang-tidy config to pass with clang-tidy-20 (#4691)
Disables three new warnings because they lean more towards style
conflicts than fixes. I've brought these up on #style.

Other than that, mostly fixing basic issues, and things that
clang-tidy-20 seems to fire where clang-tiday-16 didn't. One particular
curious case is `llvm::StringLiteral::data()` uses, which are flagged as
not strictly null-terminated; I'm switching to `const char*` in those
spots which matches `llvm::formatv`'s format argument, but feels worse.

I'm removing `run_clang_tidy.py` here because I'm observing it give
fewer warnings than `bazel build --config=clang-tidy -k
//toolchain/...`. The latter matches how we enforce in GitHub actions
(and also caches results, and suppresses output for files that have no
issues), so I'm dropping the bespoke script.
2024-12-17 01:25:53 +00:00
Dana Jansens c7ae2a7b18 Avoid printing enums as characters (#4676)
Given code like the following:
```
auto kind = ConversionTarget::Kind{0};
CARBON_CHECK(!loc_id.is_valid(), "hello {0} world", kind);
```

Currently we would print 'hello <the next line>', as the check string
would be treated as terminating at the '{0}', so it does not print the
rest of the string or a newline. This is because ConversionTarget::Kind
is an enum with underlying type `int8_t` which is a char, and
llvm::formatv does not look if the type is an enum and treat is
specially. So it prints it as a char rather than a number, which in this
case is a nul terminator.

With this change, the '{0}' value will be converted to a larger integer
before being passed through to llvm::formatv so that char-sized enums
will print as a number, and the result is that we will print 'hello 0
world\n' as the developer intended.
2024-12-13 14:48:05 +00:00