Commit Graph
4165 Commits
Author SHA1 Message Date
Jon Ross-Perkins d64ec883d5 Move BlockValueStore from sem_ir to base (#5779)
The other generic `ValueStore` types are in base; this is for
consistency, to make it easier to find. I think it's only in sem_ir for
historical reasons, since it was probably the first bespoke ValueStore
variant added.
2025-07-09 16:25:23 +00:00
Richard SmithandChandler Carruth 3776e464e0 Properly set up C++ include paths and similar environment settings when parsing imported C++. (#5767)
Stop using the clang tooling library to build an ASTUnit; that library
is set up to process clang frontend arguments, assuming that something
has already built frontend arguments from the compiler arguments. It is
also too encapsulated and doesn't let us inspect and modify the compiler
invocation before it's executed.

Instead, build the AST unit directly in two phases:

* FIrst, take a list of clang driver arguments and convert them into a
list of compiler arguments, using `clang::createInvocation`. Internally,
this uses the clang driver to build a frontend invocation, including
building system-specific include paths as needed.
* Then, directly build an ASTUnit from this compiler invocation.

I've factored this so that we can split out the `createInvocation` step,
with the intention that we may want to move it out of check and into the
carbon driver with the rest of the driver-level argument handling, and
we may want to customize some of the clang options before we invoke the
clang frontend with that set of options.

In order to make the invocation reusable, it no longer depends on the
name of the carbon file importing the C++ code. In place of synthesizing
a header file name as `<foo.carbon>.generated.cpp_imports.h`, we now
insert line marker directives into the generated header so that errors
in that header cause Clang to point a diagnostic back at the Carbon
source file itself. This results in a minor improvement in the
diagnostic output: we no longer refer to a nonexistent generated file.
But the snippet still contains text that doesn't match the source code,
so it remains imperfect.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-07-09 03:09:43 +00:00
Jon Ross-Perkins da99b940f5 Fix clangd-tidy to avoid blocking merges while testing (#5782)
What I'm trying to fix is visible at:

- PR: https://github.com/carbon-language/carbon-lang/pull/5779
- clangd-tidy run on merge:
https://github.com/carbon-language/carbon-lang/actions/runs/16155546033/job/45597095935
- Merge attempt:
https://github.com/carbon-language/carbon-lang/pull/5779#event-18534768919

That PR deletes block_value_store, so excluding deleted files here
(`added|modified`). But also, I think this is blocking merge just
because it's set for merge_group. Or it may be because of the clang-tidy
job name overlap -- I'm just going to address both.

Also trying to remove the base commit; I think dorny/paths-filter should
actually be calculating this reasonably well, and it was holdover from
where we set the commit explicitly elsewhere. There's a warning about it
being ignored in pull_request, visible
[here](https://github.com/carbon-language/carbon-lang/actions/runs/16155814211/job/45597903684).
v0.0.0-0.nightly.2025.07.09
2025-07-09 01:11:28 +00:00
Richard Smith f987504614 Track the location of the Cpp import for use in Clang diagnostics. (#5783)
When diagnosing a problem with C++ code imported from Carbon, include
the location of the specific `import Cpp` statement that imported the
C++ code as part of the backtrace, rather than providing a location in a
generated file that doesn't exist on disk.

Also fix handling in autoupdate of check lines that contain multiple
file name and line number pairs to use the matched file name for
remapping of locations rather than the first file name in the line.
2025-07-09 00:47:21 +00:00
Jon Ross-Perkins 6db13532ca Try using clangd-tidy (#5763)
Run clangd-tidy in parallel with clang-tidy, to experimentally see
whether it works reasonably well. These may produce slightly different
results, and it's not clear that clangd-tidy will be better, so being
cautious about switching.

A real possibility here is this is slower in some cases (building
compile commands takes ~6m below), but faster in the extremely slow
cases (when clang-tidy takes >10m).

For contrast:

- clang-tidy:
https://github.com/carbon-language/carbon-lang/actions/runs/16038096026/job/45254162180?pr=5763
- clangd-tidy:
https://github.com/carbon-language/carbon-lang/actions/runs/16038096427/job/45254164217?pr=5763
2025-07-08 14:00:15 +00:00
Boaz Brickner 9d0aaa740b When adding an imported C++ name, make sure that its clang::Decl is mapped if import failed (#5769)
When mapping parameter types, we assume that if the `clang::Decl` isn't
mapped, the name wasn't added, so this fixes a bug that triggers a crash
otherwise.

Part of #5533.
2025-07-08 13:12:32 +00:00
Dana Jansens cd14dca749 Document and test that structs with different field orders are different types for impl lookup (#5778)
This encodes the decision of #5413 in our tests.
v0.0.0-0.nightly.2025.07.08
2025-07-07 20:59:11 +00:00
Boaz Brickner ff9154b978 Push a decl name scope before calling CalleePatternMatch() (#5771)
Otherwise the return values of different functions collide.

Part of #5063.
2025-07-07 15:02:47 +00:00
Boaz Brickner 3f5b04f777 Use Core.Print instead of Carbon.Print in documentation (#5770) v0.0.0-0.nightly.2025.07.07 v0.0.0-0.nightly.2025.07.06 v0.0.0-0.nightly.2025.07.05 2025-07-04 08:05:11 +00:00
Jon Ross-Perkins b3866250db Remove prebuilt_binary from file_test rules (#5765)
Since explorer was removed, this is no longer in use.
v0.0.0-0.nightly.2025.07.04
2025-07-03 15:29:39 +00:00
Boaz Brickner 12d66be1cd Delete files that were moved in #5716 but got undeleted in #5678 (#5768) 2025-07-03 10:33:25 +00:00
Richard Smith c7886f4336 Ask Clang to mangle names, don't try to do it ourselves. (#5764)
Fixes mangling for `extern "C"` functions, as well as some other
uncommon cases like multi-version functions.
v0.0.0-0.nightly.2025.07.03
2025-07-02 23:25:52 +00:00
Jon Ross-Perkins 5b0ae6e784 Remove IdT from ValueStoreTypes (#5761)
`IdT` is no longer needed because `ValueT` is always supplied.
2025-07-02 22:09:09 +00:00
Jon Ross-PerkinsandRichard Smith b4b4d33789 Change CanonicalValueStore to take ValueT and KeyT as parameters (#5759)
`SpecificInterface` seems oddly placed. It appears to be in ids.h just
because it's used by typed_insts.h, but maybe that should be factored
differently? We typically aren't having typed_insts.h depend on non-ID
types. To that end, I'm splitting it out to its own file so that at
least I'm not adding a `ValueStore` dep inside ids.h

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-07-02 20:58:02 +00:00
David Blaikie 967a98f845 Import vtable_ptr lazily (#5762)
Ensure `vtable_ptr`s(and the vtables they refer to) aren't
imported if the type is imported but the vtable isn't
needed (no initialization of a value of that type is required).
2025-07-02 19:45:02 +00:00
Dana Jansens 6c6552ce57 Consistently return runtime phase if the operands contain a runtime (#5729)
Currently if the first operand contains an error, we will return error,
even though the second operands contains a runtime, and it has a
stronger priority (the phase always goes up if possible).

Import is only allowed on instructions with compile-time values, so we
crash if we ever try to import a runtime value. Importable instructions
must diagnose unexpected runtime values and produce errors in the semir
from which they would be imported so that runtime values are never
imported by another semir.

If we had an instruction where you had an error value from the first
operand, and runtime from the second, and we imported it:
- Before https://github.com/carbon-language/carbon-lang/pull/5728 we
would crash in import, but only because we treated errors as runtime
- After https://github.com/carbon-language/carbon-lang/pull/5728 we
would import ErrorInst because we propagate errors. This is desirable
for cases with compile-time values and errors present only.
- After this PR, we would crash again, cuz you're importing a runtime
thing.

This change means that instructions containing an
`InstConstantKind::Never` instruction like`ValueParam` will consistently
evaluate to a runtime value, even if there are errors present. This is
visible in the `BindName` instructions changing in the semir, where they
became constant `ErrorInst` values previously but no longer do.
2025-07-02 19:21:41 +00:00
Jon Ross-Perkins 002756b4cc Change BlockValueStore to take ElementT as a parameter (#5758)
Also modify CopyOnWriteBlock to just pull block type information from
the return type of the function it receives, rather than taking some as
a parameter.

I chose the `RefType`/`ConstRefType` names based on other similar
`ValueStore` uses which I think are equivalent.
2025-07-02 19:21:01 +00:00
Jon Ross-Perkins a65f4b89e2 Make ValueStore require a ValueT parameter (#5757)
This is reducing ValueStore inference of types from `using`, and removes
`using ValueType = ...` from affected id types.

I'm adding a number of `using FooStore = ValueStore<FooId, Foo>` because
I think it's a little repetitive otherwise; often 4 cases where I'm
doing this: getter, const getter, member, and getter on `Context`. Note
we also have a number of `-> decltype(auto)` that were added I think
mainly to avoid repeating the type, but I'm not sure whether there'll be
agreement on replacing those and so am not changing them here.

I'm placing these aliases with the value type in general, because I
think it's probably easier to view that way. An alternative would be to
put all the types on `File`, but:

- That would be inconsistent with things like `InstStore`, which are
very `ValueStore`-adjacent and put with their value type.
- `File` would have a _lot_ of using's, and the accessors are already
noisy -- I think it would just make the file harder to skim.

Note this is the heart of what I'd brought up [on
Discord](https://discord.com/channels/655572317891461132/655578254970716160/1388199282250613019).
This PR still leaves CanonicalValueStore and BlockValueStore as things
to also add parameters to, but I thought it best to try breaking the set
of changes apart by type. Both of those rely on ValueStore, so
ValueStore needs to change first.
2025-07-02 18:07:55 +00:00
Jon Ross-Perkins 839a7b7c96 Refactor ValueStoreChunk and ValueStoreRange into ValueStore (#5756)
ValueStoreChunk and ValueStoreRange are implemented in a way that's
closely tied to ValueStore, and the separation makes for a lot of
additional template parameter passing, which seems easy to make mistakes
on. Combine types in order to make the close association more implicit.

I also considered passing `ValueT` everywhere, as an additional template
parameter. Note I believe the simplification is important. I'll
highlight four notes that I think favor this approach:

- `ValueStore`, with the chunk type in the same file, now has more of
the closely related implementation features in the same file. I think we
probably will want any chunking to continue to be done by `ValueStore`
itself, with related types using the implementation on `ValueStore` and
never creating their own.
- Making `ValueT` a template parameter on `ValueStore` -- my next step
-- will only change a couple lines of code on this type, instead of
sweeping changes. That should make it easier to be confident of the
correctness of those changes.
- Simpler to verify correctness. For example, `ValueStoreChunk` takes a
`ValueType` parameter that it doesn't forward; other functions assume
they can use `IdT::ValueType`. With the changes, this also no longer
benefits from separating out `IdHasValueType`, which was inconsistently
applied to related types (e.g., `ValueStoreRange` didn't use it).
- Template parameters often lead to `sizeof`, where we can't rely on
type checking to catch mistakes.
- The reduction of code is significant, with 8 `template<...>` removed
(including 1 forward declaration for `ValueStoreRange`), and also the
related `requires`. Correspondingly, places specifying template
parameters also decreased.
2025-07-02 16:19:32 +00:00
Jon Ross-Perkins 864e9cb4a2 Add a ValueT to RelationalValueStore (#5755)
RelationalValueStore is only used in one spot, so starting there.
v0.0.0-0.nightly.2025.07.02
2025-07-01 20:09:00 +00:00
Ivana Ivanovska 44b2f60c90 Carbon/C++ Interop: Primitive Types proposal (#5448)
A proposal for Primitive Types mapping between Carbon and C++.

Part of #5263
2025-07-01 18:17:02 +00:00
Jon Ross-Perkins b97646a890 Split value store related types to separate files (#5754)
As I'm looking at splitting value type setting out, this is to make it a
bit easier to see what's part of each type. Note, I expect
`ValueStoreTypes` to remain because of the `StringRef` logic it does --
I'm giving that its own file.
2025-07-01 17:38:56 +00:00
Jon Ross-Perkins 57ef976802 Move dumping into the phase factory functions (#5747)
By moving dumping, we can have dumping occur before verification that
might CHECK-fail (e.g. parse tree and llvm IR verification).

I'm dropping vlogging of raw semir. It was only done when dumping, so
`-v` would print zero copies and `-v --dump-raw-sem-ir` would print two
copies. The lack of complaints about this suggests it's not needed.

I'm making a small change to drop newlines between textual and raw
semir. This is an edge case so I don't expect people to really notice in
general, but it seemed unusually aware of what's on a stream, and it
made it harder to do the dump_stream/raw_dump_stream approach, which I
felt would be decent in general, since check is the only phase that can
emit two different things (which I could also just drop -- we don't
really use raw semir anymore, it doesn't seem like a big need to be able
to print it with textual semir, but I'm assuming to just maintain
existing behavior).

In parse, we were previously dumping the tree on verification errors.
I'm removing that because now `--dump-parse-tree` should work fine,
where previously it wouldn't.
2025-07-01 15:51:41 +00:00
Richard Smith 11d5ee5f3e Add partial to the precedence diagram. (#5749)
Following the decision in #5010.
v0.0.0-0.nightly.2025.07.01
2025-06-30 22:44:54 +00:00
Jon Ross-Perkins 6966b1879d A few more mermaid newline fixes (#5752)
Akin to #5751, found in two other files.
2025-06-30 22:43:03 +00:00
David Blaikie 0b53217372 Diagnose partial applied to final types. (#5744)
Is it worth having a distinct diagnostic or phrasing for non-class types
(like tuples, structs, pointers, etc), also for declared-but-not-defined
class types (where we can't tell if they're final or not)? Happy to add
it, but not sure how much detail to put in here at this stage at least.

I chose "non-final type" as somewhat vague wording so it sort of applies
even to pointers/tuples/structs.
2025-06-30 20:35:19 +00:00
Jon Ross-Perkins 72c3f8a6b5 Fix repeated newlines in expression mermaid (#5751)
A newline adds a br. The br tag is redundant, unless you really want two
newlines. Might stem from a mistake in #1089

We have a couple spots using br to keep text on a single line; changing
those for consistency.

Before:

![Screenshot 2025-06-30 at 1 01
51 PM](https://github.com/user-attachments/assets/29c16b0f-1180-4e91-a2f8-3889db4dd311)

After:

![Screenshot 2025-06-30 at 1 01
18 PM](https://github.com/user-attachments/assets/1b69356e-92b7-4db5-8e0d-9e838035a9f5)
2025-06-30 20:10:16 +00:00
Geoff Romer 12fbf9c9c2 Progressive disclosure principle (#5661)
This proposal codifies our preference for designs that support
"progressive
disclosure", meaning that programmers can ignore a given language
concept (or
even be unaware of it) until it is directly relevant to the task they're
doing.
2025-06-30 19:02:01 +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>
v0.0.0-0.nightly.2025.06.30 v0.0.0-0.nightly.2025.06.29 v0.0.0-0.nightly.2025.06.28
2025-06-28 00:52:58 +00:00
Jon Ross-Perkins 4aa62bf5cd Switch Destroy to addr self (#5748)
Pointed out by zygoloid on #toolchain, just taking care of this now.
2025-06-28 00:50:47 +00:00
dependabot[bot] 21762f4003 Bump webrick from 1.8.1 to 1.8.2 in /website in the bundler group across 1 directory (#5745)
Bumps the bundler group with 1 update in the /website directory:
[webrick](https://github.com/ruby/webrick).

Updates `webrick` from 1.8.1 to 1.8.2
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/ruby/webrick/releases">webrick's
releases</a>.</em></p>
<blockquote>
<h2>v1.8.2</h2>
<h2>What's Changed</h2>
<ul>
<li>Drop commented-out line by <a
href="https://github.com/olleolleolle"><code>@​olleolleolle</code></a>
in <a
href="https://redirect.github.com/ruby/webrick/pull/108">ruby/webrick#108</a></li>
<li>Add Ruby 3.1 &amp; 3.2 to CI matrix by <a
href="https://github.com/tricknotes"><code>@​tricknotes</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/109">ruby/webrick#109</a></li>
<li>Fix/redos by <a
href="https://github.com/ooooooo-q"><code>@​ooooooo-q</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/114">ruby/webrick#114</a></li>
<li>Raise HTTPStatus::BadRequest for requests with invalid/duplicate
content-length headers by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/120">ruby/webrick#120</a></li>
<li>Bump actions/checkout from 3 to 4 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/121">ruby/webrick#121</a></li>
<li>Improve CI by <a
href="https://github.com/hsbt"><code>@​hsbt</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/123">ruby/webrick#123</a></li>
<li>Fix WEBrick::TestFileHandler#test_short_filename test not working on
mswin by <a
href="https://github.com/KJTsanaktsidis"><code>@​KJTsanaktsidis</code></a>
in <a
href="https://redirect.github.com/ruby/webrick/pull/128">ruby/webrick#128</a></li>
<li>Fix bug chunk extension detection by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/125">ruby/webrick#125</a></li>
<li>Fix CI. by <a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/131">ruby/webrick#131</a></li>
<li>Merge multiple cookie headers, preserving semantic correctness. by
<a href="https://github.com/ioquatix"><code>@​ioquatix</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/130">ruby/webrick#130</a></li>
<li>Test on macos-latest by <a
href="https://github.com/byroot"><code>@​byroot</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/132">ruby/webrick#132</a></li>
<li>Require CRLF line endings in request line and headers by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/138">ruby/webrick#138</a></li>
<li>Prefer squigly heredocs. by <a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a> in <a
href="https://redirect.github.com/ruby/webrick/pull/143">ruby/webrick#143</a></li>
<li>Only strip space and horizontal tab in headers by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/141">ruby/webrick#141</a></li>
<li>Treat missing CRLF separator after headers as an EOFError by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/142">ruby/webrick#142</a></li>
<li>Return 400 response for chunked requests with unexpected data after
chunk by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/136">ruby/webrick#136</a></li>
<li>Fix reference to URI::REGEXP::PATTERN::HOST by <a
href="https://github.com/casperisfine"><code>@​casperisfine</code></a>
in <a
href="https://redirect.github.com/ruby/webrick/pull/144">ruby/webrick#144</a></li>
<li>Prevent request smuggling by <a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a> in
<a
href="https://redirect.github.com/ruby/webrick/pull/146">ruby/webrick#146</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/tricknotes"><code>@​tricknotes</code></a> made
their first contribution in <a
href="https://redirect.github.com/ruby/webrick/pull/109">ruby/webrick#109</a></li>
<li><a href="https://github.com/ooooooo-q"><code>@​ooooooo-q</code></a>
made their first contribution in <a
href="https://redirect.github.com/ruby/webrick/pull/114">ruby/webrick#114</a></li>
<li><a
href="https://github.com/KJTsanaktsidis"><code>@​KJTsanaktsidis</code></a>
made their first contribution in <a
href="https://redirect.github.com/ruby/webrick/pull/128">ruby/webrick#128</a></li>
<li><a href="https://github.com/byroot"><code>@​byroot</code></a> made
their first contribution in <a
href="https://redirect.github.com/ruby/webrick/pull/132">ruby/webrick#132</a></li>
<li><a
href="https://github.com/casperisfine"><code>@​casperisfine</code></a>
made their first contribution in <a
href="https://redirect.github.com/ruby/webrick/pull/144">ruby/webrick#144</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/ruby/webrick/compare/v1.8.1...v1.8.2">https://github.com/ruby/webrick/compare/v1.8.1...v1.8.2</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/ruby/webrick/commit/0fb9de6788a3ba5fe903e63d778a0fb8c1dce786"><code>0fb9de6</code></a>
Bump up v1.8.2</li>
<li><a
href="https://github.com/ruby/webrick/commit/b9a4c81ea94dec02a750c6b34092c55234519bf1"><code>b9a4c81</code></a>
Removed trailing spaces</li>
<li><a
href="https://github.com/ruby/webrick/commit/f5faca9222541591e1a7c3c97552ebb0c92733c7"><code>f5faca9</code></a>
Prevent request smuggling</li>
<li><a
href="https://github.com/ruby/webrick/commit/0c600e169bd4ae267cb5eeb6197277c848323bbe"><code>0c600e1</code></a>
Fix reference to URI::REGEXP::PATTERN::HOST</li>
<li><a
href="https://github.com/ruby/webrick/commit/15a93914782789520837c334e0c302702aec34e2"><code>15a9391</code></a>
Return 400 response for chunked requests with unexpected data after
chunk</li>
<li><a
href="https://github.com/ruby/webrick/commit/2b38d5614e876d313fe981e87c4e35b91556d226"><code>2b38d56</code></a>
Treat missing CRLF separator after headers as an EOFError</li>
<li><a
href="https://github.com/ruby/webrick/commit/e4efb4a2300540f14f93c09c06bf0357ac1597dc"><code>e4efb4a</code></a>
Remove unnecessary gsub calls in test_httprequest.rb</li>
<li><a
href="https://github.com/ruby/webrick/commit/426e214532bb0be5e4ab8b3c9cef328432012d0d"><code>426e214</code></a>
Only strip space and horizontal tab in headers</li>
<li><a
href="https://github.com/ruby/webrick/commit/e72cb697836e2ff201a4a74c108fdca9d3d2d0ed"><code>e72cb69</code></a>
Prefer squigly heredocs. (<a
href="https://redirect.github.com/ruby/webrick/issues/143">#143</a>)</li>
<li><a
href="https://github.com/ruby/webrick/commit/ee60354bcb84ec33b9245e1d1aa6e1f7e8132101"><code>ee60354</code></a>
Require CRLF line endings in request line and headers</li>
<li>Additional commits viewable in <a
href="https://github.com/ruby/webrick/compare/v1.8.1...v1.8.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=webrick&package-manager=bundler&previous-version=1.8.1&new-version=1.8.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/carbon-language/carbon-lang/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-27 23:19:41 +00:00
Richard Smith 3a7a09dfab Use Core.Range from for lowering tests. (#5746)
Avoids duplicated test helper `EmptyRange`.
2025-06-27 23:19:20 +00:00
Jon Ross-Perkins 2de746e83c Switch compile functions to use options structs (#5742)
I've been mulling this mainly for the parameter complexity of
check/lower, but doing lex/parse for symmetry.

I'm motivated by the plan to move dumping for all of them into the
respective functions, because of discussion about llvm-verifier. That
basically would add another bool parameter (or more) to each of these.
My instinct is we're going to probably accrue a little more over time,
so I'm suggesting this as maybe adding the boundary a little simpler
and/or easier to read.

Note it may make sense to refactor a little further, e.g. maybe
Lower::Context could receive the full set of options and pick out what
it wants, but I figured creating the struct itself would be a decent
start.

I'm trying to put things into options when we can produce a reasonable
default if the user doesn't assign a value. I'm using an explicit
constructor so that values can be added without affecting every caller.

A different factoring would be to pass in everything through the param
struct, but that just felt weird when I was trying it out.

Removing `inst_namer` and `module_name` from `LowerToLLVM` params --
both of these can be inferred from `sem_ir`, and I'm not seeing a
particular reason to maintain them at the call site.
2025-06-27 22:08:47 +00:00
Jon Ross-Perkins 0722dab0ef Reimplement destroy as an interface (#5678)
This changes `Destroy` to use an interface for its implementation.

Note that this change includes a lot of test updates. Even when
`Destroy` is a no-op, it still causes code generation as part of
determining that.

Originally I was trying to use ranges to cut down the scope of this, and
to a degree I think they have. But a flipside here is that cases where
no destructors should be generated -- particularly globals -- would be
needed to completely remove destructor calls. Even for ranges, the range
can often include the destructor placement. So I've shifted
frame-of-thought a little: accept a bunch of destructor churn, because
destructors are needed and will be prevalent. The verbosity is a feature
of the design to make desugaring apparent in IR, not a bug.
2025-06-27 21:57:14 +00:00
Chandler CarruthandGeoff Romer bba037738d Key-type customization in CanonicalValueStore and ClangDecl cleanups (#5743)
The `ClangDecl` struct caused some confusion here -- it is embedding
extra data into a `CanonicalValueStore` that isn't used for lookups or
canonicalization, but is useful to store along side. This changes the
`CanonicalValueStore` to support customized key type for `Lookup` so
that we can provide the more direct API that only takes the relevant
key.

This in turn takes advantage of the support for heterogenous keys in the
underlying `Set` as long as hashing and equality are consistent. We do
need to add support for heterogenous equality comparison with
`clang::Decl*`, but that is fairly easily done now that the
argument-reversed form isn't needed as well.

Lastly, this cleans up the `ClangDecl` customization points to be more
idiomatic by using `operator==` and `CarbonHashValue`. While there, I've
added comments to make it unambiguous why we can use the pointer value
for the underlying `clang::Decl` due to the Clang AST's
address-as-identity model.

Resolves the immediate TODOs around this type.

Future work might involve changing from the current `Add` API to one
more like `Map` and `Set`'s API where a callback is used to create the
object, but that level of API complexity isn't necessarily motivated yet
and can easily be a follow-on if and when its worth doing. The `Add`
code paths *are* working with the `inst_id` in order to create an
instruction if we are importing the Clang declaration. It is the
`Lookup` code paths that never needed to know about the `inst_id` and
became more confusing for having to stub it out in the API.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2025-06-27 20:30:05 +00:00
124313269a Represent vtables as a top level SemIR construct (#5472)
The goal was/is to reduce the overhead for vtables in generics - the
previous representation/prior to this patch caused a new vtable to be
created in every specific which isn't generally what we want for Carbon
generics (the whole specific/generic thing is meant to avoid creating
specific versions for things that can be a generic form parameterized by
a specific instead of manifest as a unique entity per specific)

So this moves vtables to a top level object (like functions, classes,
etc). Each dynamic class will have a vtable in this list.

Classes have a `vtable_ptr` instruction in them that points to the
vtable.

The actual generic support hasn't been implemented in this patch, as
I've been struggling with just getting this part of the migration going
& wanted to get it flushed out before adding the additional
complications.

It's possible more laziness when doing cross-file importing would be
suitable - for instance if we only need to reference the vtable from
another file, but don't need to know its individual contents, it may be
beneficial for the functions in the vtable to be import_refs (or to add
another layer of indirection - so it can be a single import_ref
all-or-nothing for the functions in the vtable).

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2025-06-27 18:45:26 +00:00
David BlaikieandChandler Carruth b39a0f0c8c Basic SemIR partial support (#5736)
This adds something similar to the level of `const` support - that it's
a type, but not the conversions and limitations on usage that are
needed.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
v0.0.0-0.nightly.2025.06.27
2025-06-26 23:55:48 +00:00
Jon Ross-Perkins 49212feac6 Allow repeated includes, particularly for min_prelude (#5741)
Make min_prelude parts include what they use, and remove the inclusions
which were for indirect uses from the main min_prelude files.
2025-06-26 21:59:55 +00:00
Jon Ross-PerkinsandDana Jansens c3b0c2e425 Use LLVM verifier in lowering (#5733)
Suggested by zygoloid while looking at #5678 

```
CHECK failure at toolchain/lower/context.cpp:62: !llvm::verifyModule(*llvm_module_, &errs): Verifier errors: Instruction does not dominate all uses!
  %.loc17_46.1.temp = alloca { i1, i32, i32 }, align 8, !dbg !13
  %tuple.elem0.loc17_46.2.tuple.elem = getelementptr inbounds nuw { i1, i32, i32 }, ptr %.loc17_46.1.temp, i32 0, i32 0, !dbg !13
Instruction does not dominate all uses!
  %.loc17_46.1.temp = alloca { i1, i32, i32 }, align 8, !dbg !13
  %tuple.elem1.loc17_46.2.tuple.elem = getelementptr inbounds nuw { i1, i32, i32 }, ptr %.loc17_46.1.temp, i32 0, i32 1, !dbg !13
Instruction does not dominate all uses!
  %.loc17_46.1.temp = alloca { i1, i32, i32 }, align 8, !dbg !13
  %tuple.elem2.loc17_46.2.tuple.elem = getelementptr inbounds nuw { i1, i32, i32 }, ptr %.loc17_46.1.temp, i32 0, i32 2, !dbg !13
```

Adds a `--llvm-verifier` flag to be able to turn this off easily,
particularly for debugging the LLVM IR.

The call workaround is due to a verifier requirement `inlinable function
call in a function with debug info must have a !dbg location`. It
specifically comes up for the `++x` case, with `%1 = call i32
@"_CConvert.8b3d5d6a6c17be04:ImplicitAs.Core.b88d1103f417c6d4"(i32
%other)`. I think #5397 is in the direction of a fix for that, but #5397
was set aside because it puts the debug info in too many places.
Instead, address this by adding a stub location for calls that don't
have a good location. I'm deliberately putting this next to the TODO so
that it's easier to understand the association.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2025-06-26 21:34:09 +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
Richard Smith c34d0c7adf Add Core.Range(N) facility to construct an integer range. (#5699)
Use it in examples where appropriate.

Depends on #5698.
2025-06-26 20:13:07 +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
Boaz Brickner b90d3b7751 Use Decl::getAsFunction() to cast clang_decl to FunctionDecl (#5737)
This seems like a better practice though has no effect since we don't
support templates yet.

Part of #5436.
2025-06-26 17:14:02 +00:00
Dana Jansens 67b67af7a6 Add a test where impls requires things of another generic type (#5713)
From open discussion on 2025-06-23:
https://docs.google.com/document/d/1Yt-i5AmF76LSvD4TrWRIAE_92kii6j5yFiW-S7ahzlg/edit?tab=t.0#heading=h.5mygrwse32v5

The test does not pass yet, as we have not completed implementation of
`impls` constraints.
2025-06-26 15:45:46 +00:00
Geoff Romer 1893afe479 Tolerate incomplete interface when stringifying ImplWitnessAccess (#5730)
Closes #5727
2025-06-26 14:37:16 +00:00
Alina Sbirlea 78ef1678aa Adding additional test for specific coalescing. (#5732)
Adding additional test for specific coalescing.
2025-06-26 14:32:24 +00:00
Richard SmithandJon Ross-Perkins 866794b82a Check and lowering support for for loops. (#5698)
Add check support for `for` loops following #1885. This also adds a
basic `Optional` type to the prelude, as that's necessary to support the
new `Iterate` interface.

Depends on #5688, #5697. Those PRs aren't stacked here, but this change
will crash until they land.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
v0.0.0-0.nightly.2025.06.26
2025-06-25 23:45:14 +00:00
Richard Smith a556cf41fc Use static allocas for temporaries. (#5734)
Previously we created allocas for temporaries at whatever point in the
output LLVM function we'd reached. This would result in these being
dynamic allocas (performing a dynamic stack allocation), which is
inefficent and can lead to a stack overflow if it happens in a loop.

Switch to putting the allocas in the entry block instead, and instead
generate a lifetime start marker when we reach the point where the
temporary is introduced. We already did this for local variables; this
is just factoring out and reusing that code.
2025-06-25 21:53:39 +00:00
Dana Jansens 3585b31813 Handle insts that resolve to type on the RHS of impls (#5712)
In a facet type constraint, you can write `where .Self impls T` for any
facet type `T`, or the constant `type`. It is possible to write `type`
in different ways though, with a `NameRef` instruction appearing on the
RHS instead of `TypeType`. In this case, the canonical constant value's
instruction will still be `TypeType`, so make eval look at the canonical
instruction to see this.

Add a test with an `alias Type = type` which hits this case.

After this change, we only will accept and find one of the following on
the RHS of `impls`:
- `TypeType`
- A facet type
- An error, if the source code had something else there, which will
already be diagnosed. Tested by `fail_right_of_impls_non_type.carbon`
and `fail_right_of_impls_non_facet_type.carbon`.

So we handle these three cases, and drop the implicit handling of other
things which will never appear there.
2025-06-25 21:45:23 +00:00
Alina Sbirlea dd0905ccbb Refactor coalescing logic out of the file context. (#5723)
Move coalescing logic outside of the file context.
This is intended to be pure refactoring / NFC.
2025-06-25 21:22:58 +00:00