Commit Graph
6043 Commits
Author SHA1 Message Date
Nicholas Bishop 30516f07b5 Fix export of generic functions with generic class params (#8168)
For example, when exporting `fn F[T: type](c: C(T))`, where `C` is a
generic class, the exported type of the `c` param should be a
`clang::TemplateSpecializationType`.

Prior to this commit it was instead exported as the tag type for a
`clang::ClassTemplateSpecializationDecl`. This wasn't rejected by clang,
but it prevented type substitution from working, causing a failure to
infer the template argument.
2026-11-23 17:41:33 +00:00
Chandler Carruth 0072b28129 Start every diagnostic with a single message attached to the code (#8102)
This is the final step in landing the _structural_ updates to diagnostic
rendering.

The key idea here is that we want the primary diagnostic to have a
message clearly explaining the problem and attached to the code that has
that problem. This should be the starting point for readers working to
address the issue, but is rendered attached to the code snippet in
question so errors are always "in context" of the code with the error.
Everything else in a diagnostic is an additional label attached to code
to explain or help the reader understand the problem in the primary
message.

Previously, `ContextScope` resulted in some confusion here, as
diagnostic consumers turned messages into labels and made the message in
the context scope the message. In essence, this isn't a scope with
context _for_ a diagnostic (with two exceptions that should probably
have been an `AnnotationScope`), but a context within `check` where we
have a preferred message for a diagnostic emitted by general purpose
code we call into. For example, "class was forward declared here" starts
as an error, and then consumers render it as a label to make the message
from the context scope the error. We also grew an `AnnotationScope` to
handle the contextual information we want to show for a diagnostic (what
I would have assumed `ContextScope` actually did).

Now we have a `Diagnoser`: code in `check` that can better explain the
problem than shared logic it is calling into passes a callback that
builds a caller-specific diagnostic. The callee then can attach relevant
labels and emit it. Diagnostics no longer store `contexts` and consumers
no longer need the logic to restructure things. We move all (but two) of
the old contexts to be normal messages emitted in this way, and we move
some diagnostics to become labels. Each of the new normal messages
corresponds to a new diagnostic kind as usual. Common code following
this pattern now _requires_ the `Diagnoser` to be passed (or emit
nothing), and this uncovered three places where an empty context was
used that made the rendered form miss key information. All three are
fixed with new diagnostics, one already covered by tests, and two with
TODOs to add test coverage.

We also completely remove the old `ContextScope` and
`CARBON_DIAGNOSTIC_CONTEXT` and rename `AnnotationScope` to
`ContextScope`. It is only used to attach information about when/where a
diagnostic occurred.

Labels also no longer have categories. What were `Primary` are now
`ExtraRange`s on the diagnostic rather than labels. Labels are now
always informational.

`DeclaredName` now narrows the range of a label when the range is a
declaration of a named entity to only be the range of that name. For
entities that don't have a declared name, the entire declaration remains
the range. The code building and emitting these diagnostics can skip
them if the declared location isn't distinct from the diagnostic
location.

Wording is largely unchanged here so we can just review the _structural_
change. #7991 iterates using this to improve locations and adds missing
labels. A subsequent PR will iterate on the wording to increasingly fit
within this structural model.

This is separated out as a way to review incrementally, and so that
subsequently we don't have to review wording improvements that only make
sense in a new structure that you cannot see yet. It seems easier to
look at the structure here even with awkward wording.

Assisted-by: Claude Code
2026-11-22 05:19:35 +00:00
Chandler Carruth 4729b4473b Provide optimized string equality for hashtable keys (#8143)
We shouldn't need to do this, and we should be able to rely on LLVM's
`StringRef::operator==` and similar routines to be efficient. But in
practice and after measuring, this seems to not be the case. =/

Both glibc and LLVM-libc have `bcmp` implementations significantly
slower than what we introduce here, and reaching into libc requires PLT
overhead and other challenges. I plan to send a PR to LLVM-libc of this
implementation to replace its `bcmp`. Until that lands and we can
reliably use it, having this makes a _dramatic_ impact on hashtable
performance for string keys, which happens to be the case we care very
much about in the compiler.

This implementation is somewhat based on the premise that hashtable keys
and other kinds of string comparisons are close enough in their expected
behavior and distribution of data sizes that we don't need to overly
specialize. We have data suggesting that _all_ string comparisons are
heavily biased towards short strings and latency-sensitive code paths,
much as hashtable keys are. This implementation specifically optimizes
for those two priorities: latency and short strings.

The overarching design of this string comparison has a few key ideas
that enable it to be efficient:

- Must be an efficient out-of-line function to allow callers to remain
good inline candidates. Also uses `preserve_most` to minimize register
pressure in the caller, and `pure` to avoid re-loading values from
memory.
- Avoid trying to pass `bool`, a defined `0` vs `1` value, or condition
flags across this out-of-line ABI boundary as they are not efficiently
represented and converting to these representations within the
implementation adds overhead. We want the caller to be able to have the
conditional branch that converts to a boolean state where it can be
fused and efficient. The out-of-line function needs to return an
efficient input to a caller's conditional branch. This motivates a
`uint64_t` result type which has the most flexibility for the
implementation.
- Overread for sizes up to 8 bytes when within the page -- we read 8
bytes and then mask off the bits that we were not allowed to read. This
has to be disabled when using sanitizers and we only support
little-endian masking, but is a _significant_ performance improvement
when available.
- Overlapping reads at the start and end: much like in hashing,
_duplicate_ reads are fine, and we can leverage this to handle a range
of sizes with common code, for example reading the first and last 8
bytes handles sizes 9 through 16 with identical code.
- Balance between branch-predictable returns of constants and returning
a computed non-zero value (via xor or other operation) for the caller to
branch on. Sometimes, it is useful to allow branch prediction to
early-exit the comparisons, other times it ends up better to compute the
data and let the caller's branch be predicted or not.
- Use relevant architecture and microarchitecture details when needed.
For example, we carefully select between vector operations and GPR
operations to minimize vector <-> GPR movement overhead.

The PR provides unit tests for the relevant size classes and various
boundary conditions.

We also provide benchmarks, both ones that measure _latency_ of the
comparison by causing each iteration to have a data dependency on the
prior iteration, and ones that measure _throughput_ by allowing each
iteration to run in parallel. Even though we optimize for latency first,
we want to have the best throughput we can.

Cycles per comparison (lower is better) vs. Linux glibc ("System") and
out-of-line LLVM-libc `inline_bcmp` ("LLVM"). "C++ ids" uses the C++
identifier length distribution. `System` and `LLVM` are relative to this
implementation: positive `%` and `>1x` mean this implementation is
faster; negative `%` and `<1x` mean it is slower; `~` is no significant
difference (p < 0.05).

AArch64 (armv8.2-a) on an Apple M1 P-core, cycles per comparison:

| Sizes    | Latency | System |   LLVM | Throughput | System |   LLVM |
| :------- | ------: | -----: | -----: | ---------: | -----: | -----: |
| C++ ids  |    21.3 |   +41% |   +40% |       12.5 |   +93% |  +100% |
| 1-3      |    14.4 |   +48% |   +64% |        5.0 |  3.99x |  3.83x |
| 4-8      |    14.5 |   +55% |   +46% |        5.0 |  2.30x |  3.02x |
| 9-16     |    14.6 |   +47% |   +29% |        4.0 |  2.22x |   +95% |
| 17-32    |    17.6 |   +20% |   +50% |        5.2 |   +38% |   -21% |
| 33-64    |    20.1 |   +40% |   +47% |        7.2 |  2.68x |   -16% |
| 65-256   |    36.9 |   +49% |   +17% |       30.0 |   +57% |    -3% |
| 257-1024 |   103.8 |   +38% |    +7% |       85.1 |   +58% |  +0.2% |

x86-64-v3 on an AMD Ryzen 9 9950X (Zen 5), cycles per comparison:

| Sizes    | Latency | System |   LLVM | Throughput | System |   LLVM |
| :------- | ------: | -----: | -----: | ---------: | -----: | -----: |
| C++ ids  |    24.0 |    +1% |   +75% |       18.1 |  0.39x |  2.36x |
| 1-3      |    14.4 |   +57% |  2.34x |        4.7 |    +7% |  7.24x |
| 4-8      |    14.4 |   +57% |  2.62x |        4.7 |    +7% |  8.36x |
| 9-16     |    15.0 |   +53% |    +5% |        5.9 |   -15% |      ~ |
| 17-32    |    22.8 |  +0.4% |   +10% |        7.0 |   -29% |   -21% |
| 33-64    |    25.8 |    -6% |    +6% |        7.1 |   -16% |    -5% |
| 65-256   |    45.1 |    +4% |   +25% |       28.3 |    -7% |   +50% |
| 257-1024 |    64.0 |   +17% |   +35% |       64.7 |   +10% |   +16% |

x86-64-v3 on an AMD EPYC 7B13 (Zen 3), cycles per comparison:

| Sizes    | Latency | System |   LLVM | Throughput | System |   LLVM |
| :------- | ------: | -----: | -----: | ---------: | -----: | -----: |
| C++ ids  |    24.1 |    N/A |   +54% |       16.9 |    +8% |  2.15x |
| 1-3      |    15.6 |    N/A |   +94% |        5.7 |  4.29x |  5.04x |
| 4-8      |    15.6 |    N/A |  2.12x |        5.7 |  2.56x |  5.87x |
| 9-16     |    15.8 |    N/A |   +11% |        7.1 |  2.03x |      ~ |
| 17-32    |    24.6 |    N/A |  +0.4% |        8.1 |   +74% |   -12% |
| 33-64    |    30.5 |    -6% |    -1% |       10.1 |    +9% |   -10% |
| 65-256   |    46.3 |   +12% |   +32% |       33.2 |    -8% |   +39% |
| 257-1024 |    78.8 |   +12% |   +26% |       82.3 |    -3% |      ~ |

x86-64-v2 on an AMD Ryzen 9 9950X (Zen 5), cycles per comparison:

| Sizes    | Latency | System |   LLVM | Throughput | System |   LLVM |
| :------- | ------: | -----: | -----: | ---------: | -----: | -----: |
| C++ ids  |    23.9 |    +2% |   +78% |       17.7 |  0.40x |  2.45x |
| 1-3      |    14.8 |   +53% |  2.28x |        5.0 |      ~ |  6.68x |
| 4-8      |    14.9 |   +55% |  2.54x |        5.0 |      ~ |  7.82x |
| 9-16     |    14.9 |   +53% |    +5% |        6.0 |   -17% |   -17% |
| 17-32    |    22.7 |  +0.4% |   +10% |        6.0 |   -17% |      ~ |
| 33-64    |    26.9 |   -10% |   +37% |        7.5 |   -20% |  3.35x |
| 65-256   |    47.7 |    -1% |   +20% |       38.2 |   -31% |   +30% |
| 257-1024 |    91.5 |   -18% |   +24% |       91.4 |   -22% |   +18% |

x86-64-v2 on an AMD EPYC 7B13 (Zen 3), cycles per comparison:

| Sizes    | Latency | System |   LLVM | Throughput | System |   LLVM |
| :------- | ------: | -----: | -----: | ---------: | -----: | -----: |
| C++ ids  |    24.1 |    N/A |   +55% |       16.5 |   +10% |  2.24x |
| 1-3      |    15.8 |    N/A |   +92% |        6.3 |  3.88x |  4.60x |
| 4-8      |    15.8 |    N/A |  2.10x |        6.3 |  2.32x |  5.34x |
| 9-16     |    15.8 |    N/A |   +11% |        7.1 |  2.03x |      ~ |
| 17-32    |    24.4 |    N/A |    +4% |        8.1 |   +74% |      ~ |
| 33-64    |    30.7 |    -7% |   +26% |       10.0 |   +11% |  2.70x |
| 65-256   |    48.5 |    +7% |   +31% |       45.8 |   -33% |   +19% |
| 257-1024 |   108.1 |   -21% |   +11% |      110.9 |   -29% |      ~ |

Note: Zen 3 `System` latency is `N/A` for `C++ ids` and 1-32 bytes
because glibc's AVX2 `memcmp` returns a constant `0` behind a predicted
branch for equal 2-31 byte strings, so the latency benchmark's select
doesn't wait on the comparison.

Assisted-by: Antigravity with Gemini, Fable, and other models
2026-11-21 22:35:59 +00:00
Chandler Carruth 26fe610621 Allow replaying benchmark results so we can backfill a bit of data (#8162)
We may want to replay or re-analyze historical benchmark data, so this
keeps around the raw JSON results. The continuous benchmarks are GitHub
action artifacts that are available for 90 days. The nightly benchmarks
have their JSON attached to the release itself so that we have a
permanent archive for nightlies going forward.

This both supports historical analysis and replay/backfill.

Details of making this work, plus several other improvements spotted
while making the changes:

- Use `actions/upload-artifact` to upload the JSON file in the relevant
  part of the workflow. This requires a new end-point to be available in
  our hardened runner, and saving the target SHA for re-use.
- Passes `--backdate` with the timestamp of the commit to record a more
  accurate time. Especially important for nightly releases.
- Increases `timeout-minutes` as the `nightly` runs can get too close to
  the prior timeout (44 minutes currently).
- Adds an isolated `attach-nightly-release` job (`workflow_run` only,
  and gets separate permissions). This job has the write permissions,
  downloads all the relevant JSON files, compresses them, and attaches
  the archive to the most recent release.

Assisted-by: Antigravity with Gemini
2026-11-20 23:59:51 +00:00
Chandler Carruth 34cf614a26 Improve register allocation across HashSizedBytesLarge calls (#8119)
Because this function was a non-static member function, calls passed
`this` across the call boundary, and the caller assumed it might clobber
the memory of `Hasher`.

This PR changes it to a `[[gnu::pure]]` and `static` function which
takes and returns a `uint64_t` by value like other static helpers.
Between knowing this does not write to memory and the state being passed
in and out in registers, this allows `Hasher` to stay in a single
register across all size classes, reducing stack memory accesses and
code size.

On an AMD Ryzen 9 9950X (Zen 5), hashtable and lexer benchmarks vs
`trunk` (10 runs; negative means faster):

| Hashtable benchmark     |         x86-64-v3 |         x86-64-v2 |
| :---------------------- | ----------------: | ----------------: |
| BM_SetContainsHitPtr    |  -2.1% (-4..+1%)  |  -1.1% (-3..+5%)  |
| BM_SetLookupHitPtr      |  -2.8% (-4..-1%)  |  -2.7% (-7..-2%)  |
| BM_SetEraseInsertHitPtr |  +1.0% (-1..+6%)  |  +1.8% (-0..+5%)  |
| BM_SetInsertSeq         |  -2.7% (-3..-2%)  |  -2.6% (-3..-2%)  |
| BM_MapContainsHit       |  -2.7% (-4..-0%)  |  -3.7% (-8..-1%)  |
| BM_MapUpdateHit         |  -6.2% (-9..-2%)  | -5.6% (-10..+2%)  |
| BM_MapLookupHit         |  -2.4% (-9..-1%)  |  -1.1% (-3..+2%)  |
| BM_MapInsertSeq         |  -2.4% (-4..-1%)  |  -0.5% (-3..+1%)  |
| 4-Hit-Family Mean       |            -3.47% |            -3.28% |

| Lexer benchmark                  |       x86-64-v3 |       x86-64-v2 |
| :------------------------------- | --------------: | --------------: |
| BM_ValidIdentifiers              | +0.1% (-1..+1%) | -0.8% (-3..+1%) |
| BM_ValidKeywords                 |           -1.3% |           +0.9% |
| BM_ValidKeywordsAsRawIdentifiers |           +0.0% |           +1.8% |
| BM_RawIdentifierFocus            |           +0.7% |           -0.3% |
| BM_RandomSource                  |           +0.8% |           -0.0% |

Zen 5 x86-64-v3 per-lookup hardware counters (`BM_SetContainsHitPtr`):

| Size/Keys | Variant |       Cycles |       Instrs |          Ops |
| :-------- | :------ | -----------: | -----------: | -----------: |
| 4096/256  | trunk   |        18.20 |        98.54 |        89.27 |
| 4096/256  | after   | 17.51 (-0.7) | 95.92 (-2.6) | 87.63 (-1.6) |
| 4096/2048 | trunk   |        19.63 |        98.39 |        89.11 |
| 4096/2048 | after   | 18.99 (-0.6) | 95.90 (-2.5) | 87.62 (-1.5) |

Assisted-by: Antigravity with various models
2026-11-20 21:57:55 +00:00
Chandler Carruth af53554f1e Keep the changes link on dependent PR comments until rebase/merge (#8163)
Previously, the dependent PR workflow updated the comment as soon as all
dependency PRs were merged in a way that removed the changes link that
helps with identifying the start of review. If the PR hadn't yet been
rebased or merged trunk, this made it hard to review again. =/

This PR fixes it by detecting when we haven't rebased or merged far
enough to just review the PR as a whole, and preserves the review link.
And once `trunk` _has_ been merged far enough (or PR has been rebased),
updates the comment again to reflect that.

This requires persisting the `review_base` in the hidden JSON of the
comment, and somewhat more interesting API queries to manage this.

Docs are also updated.

Assisted-by: Antigravity with Gemini
2026-11-20 17:47:40 +00:00
Faris Basha TM 1359231ddc Fix the pointer operator link in the expressions diagram (#8154)
The `*x` / `&x` node of the expression precedence diagram in
`docs/design/expressions/README.md` links to
`docs/design/expressions/pointer.md`, which does not exist (404). The
pointer operators are documented in
`docs/design/expressions/pointer_operators.md`, so the `click pointer`
target now points there. All other `click` targets in the diagram exist.

An AI assistant found the broken link with a dead-link scan of the docs
and prepared the one-line change; the new target was checked against
`docs/design/expressions/`.

Assisted-by: Claude Opus 5.5
2026-11-20 05:18:02 +00:00
Chandler Carruth 534197a3cd Add actionlint to our prek checks and fix issues (#8157)
This adds GitHub `actionlint` to validate our actions much more
thoroughly ahead of time. This would have caught the recent issue of
benchmarking workflow.

To make this work, the PR adds a `run_actionlint.py` and extends our
script utilities to support a release in an archive where we extract the
binary.

The `prek` check combines `actionlint` with `shellcheck-py` to also
check the shell within the actions. It runs on all the workflows and
action files.

And we fix various existing issues:
- Adds missing `description` metadata and missing `id: pages`.
- Quotes shell variables across several files.
- Document the intentional word-splitting in `clangd_tidy.yaml`.

Assisted-by: Antigravity with Gemini
2026-11-19 22:44:44 +00:00
Dana Jansens cc7e707321 Add test that verifies compound lookup into an interface uses the self specific (#8160)
This test fails with a poisoning error if the interface's facet type is
mistakenly used as the Self when forming the specific to access the
interface's associated constant, as was mistakenly done in #8153.
2026-11-19 21:52:20 +00:00
Lucile Rose Nihlen f81d327067 Roll LLVM to c03c4571b1b (#8152)
Adds a patch to adjust for libc build changes.
Removes patch 13 which landed upstream.
Modifies patch 12 to apply successfully.
Removes an unused variable in testing caught during testing.
2026-11-19 20:01:27 +00:00
Geoff RomerandDana Jansens 5c46874719 Introduce ImportIRId::Local to represent the local file (#8151)
This is more self-documenting than using `None`, and avoids the need to
special-case `None` when mapping an `ImportIRId` to a `SemIR::File`.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-18 19:34:22 +00:00
Chandler Carruth f789ad4bdd Fix benchmarks.yaml workflow failure due to syntax errors (#8156)
We were setting up `BMF_FILE` environment variable in the job rather
than the step, and we don't have a `runner` variable available at that
point. Sink it into the step where it can resolve successfully.

Assisted-by: Antigravity with Gemini
2026-11-18 17:07:56 +00:00
Dana Jansens 6c9a6a4ed5 Dump expression category for an InstId (#8150) 2026-11-18 14:08:36 +00:00
Dana Jansens 6814311c72 Move impl requirement checking to the end of the impl definition (#8138)
Previously the design required the impl declaration to meet its
requirements, but in proposal #5168 that was changed. The rules are
provided in a [table here] and from the [changes here].

Now associated constants can be set inside the body of the impl
definition, which means requirements set in the impl declaration (like
`.A impls Y` or `.B == C`) can't be checked until the end of the
definition where we know all associated constants have been set.

Likewise, the check that all associated constants have been set needs to
be done at the end of the impl definition instead of at the start. And
requirements from require decls in the interface being impl'd must also
be met at the end of the definition now.

[table here]:
https://github.com/carbon-language/carbon-lang/blob/b7ea32c3a49620fae12f0b2298c81d429a20eab3/proposals/p005168-forward-impl-declaration-of-an-incomplete-interface.md#proposed-rules
[changes here]:
https://github.com/carbon-language/carbon-lang/blob/b7ea32c3a49620fae12f0b2298c81d429a20eab3/proposals/p005168-forward-impl-declaration-of-an-incomplete-interface.md#associated-constants-may-be-assigned-in-the-body-of-an-impl-definition
2026-11-18 14:07:47 +00:00
dependabot[bot] c75778d80d Bump the github-actions group across 1 directory with 2 updates (#8158)
- `ruby/setup-ruby` 1.336.0 -> 1.338.0
- `step-security/harden-runner` 2.22.3 -> 2.22.4

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-18 11:38:52 +00:00
josh11bandJosh L 21c87c69bf Fix member access typos (#8155)
Assisted-by: Gemini

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-11-18 04:33:14 +00:00
Chandler Carruth 173351f69f Add workflow to run benchmarks continuously and nightly (#8111)
This is adding our benchmark running workflows. One runs a light weight
teir of benchmarks on every push to `trunk`. This should give us
continuous light weight performance signals. Once we're happy with the
results, we can also enable this workflow on PRs.

The second fixes our nightly release to ensure it is pinned to the exact
SHA, and then trigger a more comprehensive tier of benchmarks on that
exact SHA. This gives us nightly signal, and lines it up with our
nightly releases.

We also add some documentation about these workflows.

Assisted-by: Antigravity with Gemini
2026-11-17 08:56:34 +00:00
Chandler Carruth 55ff3be05d Use the lexer dispatch table to handle special identifier prefixes (#8095)
There are a few syntaxes we lex in Carbon that overlap with the start of
an identifier: raw identifiers, sized type literals, and dollar-literals
(`$0`). Instead of handling these with branches and code in the hot
identifier and keyword lexing path, provide dedicated dispatch entries
for them that directly check for the two syntaxes. This relies on the
exact overlap space, so a compile-time check is added to catch any
changes to syntax that would require us to change this dispatch-based
approach.

This changes the identifier IDs because previously we unnecessarily
added `r` as an identifier when lexing raw identifiers.

Assisted-by: Antigravity with Gemini and Opus
2026-11-17 08:54:15 +00:00
Chandler CarruthandDana Jansens 4e830a085e Add fast paths for lexing simple decimal integer literals (#8115)
Previously, small-enough integer literals went through a code path that
still built an `APInt`, even though we don't store that in the
`IntStore` and instead embed the integer into its ID. The APInt
construction as well as the API design ended up costing _significant_
performance in lexing for common cases of decimal integer literals.

This PR makes three fundamental changes:

1. It redesigns the API to minimize how many object addresses are
escaped to memory across out-of-line boundaries, and to allow bypassing
any `APInt` construction by switching from computing and returning the
value from the literal lexer to having the literal lexer add the value
to the relevant value store if needed and return the ID instead. This
allows the fast path of an integer embedded into the ID to actually be
fast. It also allows easily making that fast path itself be inlinable
while the complex general cases are kept out-of-line to manage register
pressure and make inlining profitable across the board.

2. It adds an inlinable _very_ fast path for single-digit integer
literals that helps handle particularly common cases. We can do this
without creating problematic register pressure for the rest of the lexer
which is why it is left inlinable.

3. It adds an out-of-line fast path for simple decimal integer literals.
We actually had a fast path of parsing these already, but we still built
`APInt`s around them. This makes parallel fast paths to both identify
simple integer literals as well as turning them directly into an
integer-embedded ID when they fit.

Beyond these changes, the PR makes a number of minor changes to help
cause them to all play together effectively: refactorings to support all
of the above larger changes, and force inlining to remove calls from hot
paths.

Lex-phase benchmark time, cycles, and instructions per file, by number
of lines, comparing this change against trunk:

| Benchmark | Metric | 4K | 16K | 64K | 256K |
| ---------------------- | ------------ | -----: | -----: | -----: |
-----: |
| ApiFileDenseDecls | CPU time | -2.1% | -3.1% | -3.3% | ~ |
| | Cycles | -2.8% | -3.5% | -3.6% | ~ |
| | Instructions | -2.9% | -3.9% | -4.3% | -4.4% |
| ImplFile | CPU time | -9.8% | -14.7% | -16.7% | -15.9% |
| | Cycles | -11.6% | -15.5% | -16.9% | -15.8% |
| | Instructions | -15.8% | -19.1% | -20.3% | -20.4% |
| ApiFileRealisticHeader | CPU time | -4.6% | -7.6% | -8.7% | -5.9% |
| | Cycles | -5.8% | -7.9% | -9.0% | -6.0% |
| | Instructions | -7.8% | -10.0% | -10.7% | -10.9% |

Assisted-by: Antigravity with various models

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-17 08:41:53 +00:00
Geoff RomerandDana Jansens 645e784aa0 Move/rename InstNamer::Namespace to TextualNamespace (#8131)
This class is now reusable independently of `InstNamer`, so it shouldn't
be nested under it (but we have to choose a new name because
`SemIR::Namespace` is already taken).

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-16 18:49:41 +00:00
Dana Jansens 873f7a3f73 Handle where assignment in an invalid scope without a decl (#8145) 2026-11-16 18:48:05 +00:00
Dana Jansens d10a566aba Flatten the where assignment decl parse subtree (#8144)
Make the `WhereAssignmentOp` node a sibling of its LHS and RHS nodes, so
that we have an opportunity in check/ to perform actions between the LHS
and RHS. Previously it was a parent of the LHS and RHS, so the two sides
would be checked one immediately after the other without any
where-assignment-specific checking in between.
2026-11-16 17:29:04 +00:00
dependabot[bot] 7a3608bab2 Bump addressable from 2.9.0 to 2.9.1 in /website in the bundler group across 1 directory (#8132)
- `addressable` 2.9.0 -> 2.9.1

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-14 07:06:28 +00:00
Dana Jansens c0b2cc5921 Parse where assignment declarations in impl definitions (#8136)
These were introduced in proposal #5168.

Details:
https://github.com/carbon-language/carbon-lang/blob/b7ea32c3a49620fae12f0b2298c81d429a20eab3/proposals/p005168-forward-impl-declaration-of-an-incomplete-interface.md#associated-constants-may-be-assigned-in-the-body-of-an-impl-definition
2026-11-13 22:45:00 +00:00
josh11bandJosh L 71a125a4c1 Fix decrement typo (#8134)
Assisted-by: Gemini

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-11-13 20:57:44 +00:00
Nicholas Bishop 72abc7a466 Add missing return type to BuildCppFunctionDecl (#8135) 2026-11-13 19:36:54 +00:00
Chandler Carruth 0b9d0c7042 Begin adding support for Bencher's BMF format and benchmark running (#8109)
This extends `scripts/bench_runner.py` with `--output=bmf` and other
flags, as well as fixing severaly other flags, all to allow it to
successfully output the schema consumed by Bencher.

Also adds the `bencher_suites.py` and `run_bencher.py` that prepare and
produce uploadable benchmark results. It addresses benchmark naming and
extra metrics collected for each run of the benchmark.

A major chunk of logic is selecting the suites and metrics for
benchmarks that we want to track long term. We define two tiers here,
one to track continuously that we can run reasonbly quickly, and a more
comprehensive set that we track only nightly on each nightly release. We
also make sure each metric from the benchmark is correctly recorded for
tracking, including its units.

Assisted-by: Antigravity with Gemini
2026-11-13 18:33:10 +00:00
Lucile Rose Nihlen dbf02ad100 Adds an AddrOfAction for deferred checking of dependent types (#8122)
For `template` generics specifically, when trying check the address of
`&` a dependent expression would always fail with `AddrOfNonRef`
diagnostic. Adds a test both of successful deferred checking and a fail
test for an invalid dependent type.
2026-11-13 16:48:52 +00:00
Chandler Carruth b7ea32c3a4 Support re-checking, overriding, and requiring the PR dependency check (#8120)
There are a world of reasons why the dependent state check can be wrong
or get stuck. We need ways to manually override inaccurate findings or
trigger a re-check when things change.

Overriding: removing the `dependent` label causes the job to run and
immediately report success to unblock merging. The `workflow_dispatch`
can also run with an `override` mode. This requires adding more tracked
state in the form of _ignored_ PRs that would otherwise be considered
dependencies.

Re-checking: the job now makes the status have a `Details` link that can
be used to re-run it, and editing the PR description also re-runs it.
However, adding the `dependent` label or doing an explicit
`workflow_dispatch` with mode `recheck` goes further: it drops any
overrides and recomputes the open dependencies from the current commits,
keeping the record of merged dependencies.

Hiding the comment still clears _all_ of the tracked state for the PR,
so the next check starts completely from scratch.

Lastly, this extends the workflow to support being marked as required by
letting it run in the merge queue and report success.

Works to keep the changes to `_process_pr` organized so that we first
collect and analyze the state, and only at the end mutate the PR's state
to the new configuration. Adds relevant unit tests for the new features.
Also added some basic documentation of this so that folks have a
reference when it has issues.

I considered the alternative of parsing mentions out of comments
(dependabot-style), but it ended up significantly more complicated and
brittle, so instead went with basing each change on an operation on the
PR that is already mechanically available.

Assisted-by: Antigravity with Opus
2026-11-13 05:19:44 +00:00
Geoff Romer 92534a0e07 Cache and reuse InstNamers (#8105)
This is intended to enable a future change, where a file's SemIR will be
able to directly refer to insts from another file. In order to format
such references, we will need to access the `InstNamer` for the foreign
IR while formatting the local IR, so that we can keep the inst name
consistent across files.
2026-11-13 01:17:20 +00:00
Geoff RomerandDana Jansens e67b6db910 Give files shorthand names in textual SemIR (#8104)
Shorthand names are intended to be used in the textual format of
references to instructions in another IR (which can't happen now, but
will be possible in a forthcoming PR). The shorthand name uses the file
name (minus the `.carbon` suffix) as a base, and if that base name is
ambiguous within the compilation, it is given a numerical suffix `.N`,
just like other textual IR names. Shorthand names are prefixed with `$`
in the textual format, to distinguish them from inst and scope names.

For example, a file `foo/bar.carbon` has the shorthand name `$bar`, and
an instruction `@baz.%qux` in that file can be referenced from another
file as `$bar.@baz.%qux`.

This PR adds `toolchain/check/testdata/basics/file_name.carbon` to test
this behavior. All other test changes are just applying this change to
the existing textual SemIR dumps.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-12 23:34:32 +00:00
Nicholas BishopandGeoff Romer 54728e47fe Handle ParameterizedClassType in ExportNameScopeToCpp (#8123)
This is a step towards being able to export methods of parameterized
classes. When exporting such a method, the decl context should be a
`ClassTemplateSpecializationDecl`. Thread the scope's specific ID down
from `MapInstIdToClangDeclOrType` and call `ExportClassSpecificToCpp` to
create this context.

Also add a `context.TODO` to prevent too much code from being exercised
with methods of parameterized classes after getting the parent scope, as
that would lead to various test crashes.

The user-visible effect of this change is that the somewhat mysterious
"TODO: non-class non-namespace name scope" error is replaced with "TODO:
support exporting member functions of parameterized classes".

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2026-11-12 23:12:38 +00:00
Dana Jansens f0e3d04d00 Add a bunch of tests for .Self converting to a FacetValue in specifics inside impl as (#8130)
When `.Self` converts to a FacetValue, we include witnesses for the
interfaces required by the conversion. In the facet type declaration of
an `impl as`, a witness will evaluate to ImplSelfWitness if it's for the
impl'd interface, and to IdentifiedWitness otherwise. Inside a named
constraint, it will evaluates to IdentifiedWitness always. These tests
show that we're failing to resolve these witnesses in the same ways.

For instance, in the
`fail_todo_period_self_converted_in_specific_in_named_constraint.carbon`
test split, we get a failure of inequality:
```
found `C(D as Z & Y)` and `C(D as Z & Y)`
```
These read as the same type and they should be the same constant id, but
they contain different witnesses.

In the named constraint `C(PeriodSelf)` produces this semir when
`PeriodSelf` is replaced by `D` in a specific:
```
%facet_value.4b7: %facet_type = facet_value %D, (%Z.impl_witness, %Y.lookup_impl_witness.7e5) [concrete]
%C.bb4: type = class_type @C, @C(%facet_value.4b7) [concrete]
```
Which is dumped as this in the debugger:
```
  - inst78000182: {kind: ImplWitness, arg0: inst78000180, arg1: specific<none>, type: type(inst(WitnessType))}
  - inst78000186: {kind: LookupImplWitness, arg0: inst78000131, arg1: specific_interface78000000, type: type(inst(WitnessType))}
```

Whereas the facet value constructed directly in the `impl as` facet type
has these witnesses:
```
  - inst78000182: {kind: ImplWitness, arg0: inst78000180, arg1: specific<none>, type: type(inst(WitnessType))}
  - inst78000191: {kind: ImplWitness, arg0: inst78000037, arg1: specific78000027, type: type(inst(WitnessType))}
```

Where the second witness was an IdentifiedWitness(`D as Y`) and it
resolved to the particular impl, as the query is concrete. But in the
first case, it never did because the relationship between `D` and `Z`
was lost (the interface we are impl'ing) so the impl was not found once
the witness became concrete.

We also canonicalize the self from the impl when comparing against
witnesses, which enables one of the new tests to pass
(`period_self_converted_in_specific_in_named_constraint_from_generic_impl.carbon`),
as seen between the first and second commit. But also allows the
`period_self_conversion_in_generic_impl.carbon` test to not crash. This
was the most minimal change toward making all of these tests pass.
2026-11-12 19:14:18 +00:00
Geoff Romer 4286832b4d Generalize OperandDependence to take a SemIR::File (#8106)
This enables us to query the dependence of operations in imported files.
2026-11-12 17:35:08 +00:00
Dana Jansens 30318f87f7 Introduce StableStack to avoid UAF into Context stacks (#8055)
Stacks in Context can grow when eval is run, and if they are implemented
as SmallVector, the growing can cause a reallocation. Meanwhile for
stacks that hold larger structs/classes, we hold onto the pointer into
the stack instead of copying out. This can cause a UAF when reallocation
happens.

StableStack never reallocates when growing, as it is represented by a
vector of pointers to arrays, where each array is a factor larger than
the previous one. This prevents UAF from occurring when we run eval
while holding a pointer into a stack.

This solves a similar problem that our ValuesStores previously solved in
#5576. In that case, we also represent them as a vector of pointers to
arrays. The difference being our ValueStores are meant to grow but not
shrink, and they are built around the ID concept where IDs happen to be
an index into the store.
2026-11-12 16:48:09 +00:00
Chandler CarruthandDana Jansens 4a46ea888f Add Arm SIMD line scanning and extend it to build an id-end bitmask (#8093)
It turns out `memchr` alone left a bunch of performance on the table for
Arm, similar to what we fixed for x86 with a dedicated AVX2 path. This
PR lifts the SIMD line scanning into a `SourceBlock` helper class with
scalar, x86, and Arm implementations. It uses the same technique as our
hash tables to cross-check the scalar and SIMD implementations in debug
builds. A key to making the Arm NEON implementation actually fast is
avoiding a GPR-to-NEON round trip to do popcount.

Beyond that, instead of scanning for the end of each identifier as it is
lexed, `SourceBlock` also classifies every byte of the source while
loading each 64-byte block to find newlines. This builds a
one-bit-per-byte bitmap where each bit is set when the corresponding
byte can't continue an identifier or keyword. This lets us compute the
length of an identifier or keyword by loading an unaligned 8-bytes of
the bitmap and counting the zero bits. If necessary, we loop, with a
single 8-byte load for each additional 64-bytes of source scanned. We
ensure the bitmap has sentinel bits past the end so that this can
proceed throughout the source buffer. The result is essentially a
64-byte SWAR (SIMD Within A Register) computation of the identifier and
keyword extent. We can also efficiently build this even with a scalar
implementation, and so we always use the `SourceBlock` technique.

This approach was originally described as an idea in a comment on the
Arm path of `ScanForIdentifierPrefix`, along with the main challenge:
the high latency of moving data from vector registers to general purpose
registers. The SWAR approach, which only uses GPRs during lexing, neatly
avoids that problem.

This replaces both the byte-at-a-time loop and the SIMD identifier scan
used on x86 -- we repurpose that code, and its nibble lookup tables to
classify both newlines and the identifier ends.

A test is added to ensure we continue to gracefully degrade on non-ASCII
characters. The TODO to address these fully remains unchanged with this
PR.

My agent's benchmarks of the lex phase show the change in CPU time of
each `BM_Compile*<Lang::Carbon, Phase::Lex>` benchmark by number of
lines. For Arm, this uses an Apple M1 running Linux. For x86, this uses
an AMD server, both with `-march=x86-64-v3` (v3) and with our default of
`-march=x86-64-v2` (v2):

| Benchmark              | Target |     4K |    16K |    64K |   256K |
| ---------------------- | ------ | -----: | -----: | -----: | -----: |
| ApiFileDenseDecls      | M1     | -15.4% | -18.4% | -18.5% | -17.0% |
|                        | x86 v3 |  -0.8% |      ~ |      ~ |  -7.6% |
|                        | x86 v2 |  -8.7% |  -7.1% | -11.1% |      ~ |
| ImplFile               | M1     | -13.4% | -15.2% | -15.3% | -14.7% |
|                        | x86 v3 |  -5.8% |  -4.1% | -11.0% |  -5.9% |
|                        | x86 v2 |  -4.6% |  -8.5% |  -7.7% |  -6.6% |
| ApiFileRealisticHeader | M1     | -14.2% | -18.3% | -18.4% | -16.2% |
|                        | x86 v3 |      ~ |  -2.2% |      ~ |  -3.2% |
|                        | x86 v2 |  -5.9% |  -9.2% |  -9.1% |      ~ |

`~` marks changes that weren't statistically significant (p >= 0.05),
although their medians still improved by 3-9%.

Assisted-by: Antigravity with Gemini and Opus

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-12 04:47:10 +00:00
David Blaikie e2603996e5 Allow autoupdate_testdata.py to update C++ file tests (#8124)
Some driver file tests are C++ files, such as
toolchain/driver/testdata/fail_clang_no_args.cpp, but
autoupdate_testdata.py ignored any file argument that wasn't a .carbon
file.

I tested this manually (since there's no automated test coverage for the
script)
by making a modification to that .cpp file's CHECK before and after this
PR's
change:

Before:
```
[hi on] blaikie@blaikie-cloudtop2:~/dev/carbon$ ./toolchain/autoupdate_testdata.py toolchain/driver/testdata/fail_clang_no_args.cpp
Args do not seem to be test files; for example, toolchain/driver/testdata/fail_clang_no_args.cpp
```
After:
```
[hi on] blaikie@blaikie-cloudtop2:~/dev/carbon$ ./toolchain/autoupdate_testdata.py toolchain/driver/testdata/fail_clang_no_args.cpp
...
TEST: toolchain/driver/testdata/fail_clang_no_args.cpp !
Ran 1 tests in 25 ms wall time, 1 ms across threads
```

This improves the situation for those two .cpp files, and paves the way
for more
top-level C++ test coverage for reverse interop functionality.
2026-11-11 22:57:11 +00:00
dependabot[bot] 86e6f42822 Bump ruby/setup-ruby from 1.335.0 to 1.336.0 in the github-actions group across 1 directory (#8121)
- `ruby/setup-ruby` 1.335.0 -> 1.336.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-11 17:43:05 +00:00
josh11bandJosh L bd116f5e83 Remove bound (#8110)
Remove the `bound` parameter modifier introduced in [proposal
#5434](https://github.com/carbon-language/carbon-lang/pull/5434), as it
is superseded by the upcoming memory safety design.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2026-11-11 00:03:45 +00:00
Nicholas Bishop 11b5c29244 Add missing ID check to scopes lookup in FindExternalVisibleDeclsByName (#8112)
Also update the `AppendLookupScopesForConstant` doc comment to make it
clearer that callers should have this check.
2026-11-10 23:44:41 +00:00
Geoff Romer f44cfa5784 Prepare to support cross-file evaluation of rewrite constraints (#8107)
An upcoming PR will update expression evaluation to support evaluating
insts in the ID space of an imported file. This PR makes two independent
changes to prepare for that, grouped together to minimize merge
conflicts:
- Resolve rewrite constraints after constant-evaluating them, so that
resolution only has to deal with insts in the ID space of the local
file.
- Generalize `GetImplWitnessAccessWithoutSubstitution` to take a
`SemIR::File` instead of a `Check::Context`, so that it can be used with
instructions in the imported file's ID space.
2026-11-10 19:42:22 +00:00
Dana Jansens a83e1d8374 Handle errors in the witness table when checking impl as requirements (#8113)
If there's an error in the table, don't generate further errors on the
same `impl as` declaration. But also if there was a requirement that
can't be verified because of an error, then the `impl as` declaration as
a whole becomes invalid and any use of it should find an ErrorInst for
the witness.
2026-11-10 13:45:58 +00:00
Richard Smith 19f1bf94db If multiple files lower the same variable, use the same GlobalVariable. (#8101)
We can lower the same variable from multiple `SemIR::File`s if we reach
it through a specific for a generic in a different file. When this
happens, reuse the same global variable in lowering. This matches how we
handle the same problem for functions.

Assisted-by: Claude via Antigravity
2026-11-10 00:25:46 +00:00
Nicholas Bishop ca1898506b Fix C++ access to Carbon friend members from an unrelated class (#8097)
See access_private_parent_member_in_unrelated_class_with_friend.carbon
for an example of this fix.

The problem with that example, prior to this fix, is that when
`Derived::F` is accessed, clang tries to find `F` via
`CarbonExternalASTSource::FindExternalVisibleDeclsByName`, but
`LookupQualifiedName` doesn't find anything because it (correctly) sees
that `F` is a private member of `Base`, so it's not accessible. What it
doesn't know is that it will be accessed from the context of `A`, which
is a friend of `Base`, and so privacy doesn't matter.

`FindExternalVisibleDeclsByName` is really supposed to report visible
items, regardless of whether they can be accessed. But changing it to
simply ignore access (e.g. by modifying `LookupQualifiedName` to
optionally ignore access) doesn't quite work here. This can make a
private member of a base class appear within the `DeclContext` of a
derived class with access set to private, when it should be set to none.
This causes an assert in clang (this case is tested in
fail_access_private_parent_member_in_unrelated_fn.carbon).

Instead, change `FindExternalVisibleDeclsByName` to call
`LookupNameInExactScope` instead of `LookupQualifiedName`. This prevents
extended scopes from being searched, so members of a base class are not
found when filling in the `DeclContext` of a derived class. Clang will
call `FindExternalVisibleDeclsByName` in the context of the base class,
and the base class members are added at that time.
2026-11-06 20:09:14 +00:00
dependabot[bot] 4e4b35e6e7 Bump the github-actions-major group across 5 directories with 9 updates (#8098)
- `actions/cache` 5.0.3 -> 6.1.0 (major)
- `actions/checkout` 6.0.2 -> 7.0.1 (major)
- `actions/configure-pages` 5.0.0 -> 6.0.0 (major)
- `actions/deploy-pages` 4.0.5 -> 5.0.1 (major)
- `actions/stale` 9.0.0 -> 11.0.0 (major)
- `actions/upload-pages-artifact` 4.0.0 -> 5.0.0 (major)
- `astral-sh/setup-uv` 8.1.0 -> 10.3.3 (major)
- `dorny/paths-filter` 3.0.2 -> 4.0.3 (major)
- `jlumbroso/free-disk-space` 1.3.1 -> 2.0.0 (major)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-06 03:12:37 +00:00
Richard Smith d50576ca16 Handle references to global lets and enclosing locals. (#8061)
When building an expression referencing the result of name lookup, if
the lookup result is non-constant then check we can access it from the
current scope.

* If it is a global, then use a new `GlobalRef` instruction to get the
value of that global. In lowering, create global variables to hold the
values of global `let` bindings so that `GlobalRef` can access those
values.
* If it is a local, walk the lexical scopes between it and the point of
use and ensure it is usable through from all of them. Error if there's
an intervening declarative scope such as a class, add a TODO to handle
captures for intervening functions, and allow `typeof(...)` to name
things it can't read the value of since it's unevaluated.

Global `let`s (which includes `let`s at class scope) now also have their
initializers collected into the global inits block. If the initializer
is non-constant, the wrapper binding also lives in the global inits
block; otherwise it continues to live in the file block and the variable
emitted for it is a global constant.

Assisted-by: Gemini and Claude via Antigravity
2026-11-06 02:53:03 +00:00
Nicholas BishopandDavid Blaikie bb6486b553 Add various access tests related to inheritance (#8100)
These tests were originally generated by David with Claude as part of
reviewing #8075; see
https://github.com/carbon-language/carbon-lang/pull/8075#issuecomment-6616160559
for more background. I've gone through the tests and made some changes
and cleanups. There are a lot of tests, and sometimes the logic of what
should be accessible can be a little subtle, so putting this up for
review separately before trying to fix any of the tests.

Co-authored-by: David Blaikie <dblaikie@gmail.com>
2026-11-06 00:01:56 +00:00
dependabot[bot]andCarbonInfraBot 5b1a9311ad Bump the bazel group across 1 directory with 13 updates (#8082)
- `abseil-cpp` 20260107.1 -> 20260817.0 (major)
- `bazel_skylib` 1.9.0 -> 1.9.2
- `google_benchmark` 1.9.5 -> 1.10.0
- `googletest` 1.17.0.bcr.2 -> 1.18.0.bcr.1
- `libxml2` 2.15.2 -> 2.15.3
- `platforms` 1.0.0 -> 1.1.0
- `protobuf` 34.0.bcr.1 -> 36.2 (major)
- `rules_cc` 0.2.25 -> 0.2.27
- `rules_pkg` 1.2.0 -> 1.3.0
- `rules_python` 1.9.0 -> 2.4.5 (major)
- `tcmalloc` 0.0.0-20250927-12f2552 -> 0.0.0-20260818-15db23d
- `zlib-ng` 2.3.3 -> 2.3.3.bcr.2
- `zstd` 1.5.7.bcr.1 -> 1.5.7.bcr.3

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: CarbonInfraBot <64870956+CarbonInfraBot@users.noreply.github.com>
2026-11-05 23:46:42 +00:00
Lucile Rose Nihlen a567040d77 Update LLVM to c744694c6ae1 (#8096)
Moves Carbon code away from deprecated `llvm::IRBuilder`
and `llvm::PassBuilder` constructors  

Removes llvm patch 0002 as it landed upstream in
[#234482](https://github.com/llvm/llvm-project/pull/234482)

Removes llvm patch 0004 as it landed upstream in
[#234485](https://github.com/llvm/llvm-project/pull/234485)

Removes llvm patch 0005 as it landed upstream in
[#234489](https://github.com/llvm/llvm-project/pull/234489)

Removes llvm patch 0006 as it landed upstream in
[#234486](https://github.com/llvm/llvm-project/pull/234486)

Adds llvm patch 0013, also uploaded as an upstream
PR in [#239321](https://github.com/llvm/llvm-project/pull/239321)

Updates tests in lower and driver to suit changes to LLVM.
2026-11-05 20:33:12 +00:00
Chandler Carruth 3741e72c8a Clean up environment variables after deleting Android SDK (#8099)
Without this, new versions of Bazel tools break on our runners.

Assisted-by: Antigravity with Opus
2026-11-05 20:09:08 +00:00