Commit Graph
3410 Commits
Author SHA1 Message Date
Jon Ross-PerkinsandChandler Carruth 7befe2ce9f Switch custom error stream output to diagnostic (#4846)
This switches most error printing to use diagnostics instead of direct
stream writes, even when not a specific file diagnostic. I'm allowing
empty filenames for this use-case.

This allows a little more specific testing to validate coverage of
output using the diagnostic coverage test. I'm adding a few tests to
cover things that weren't previously tested.

Separately, this also forces a little more standardization in format...
considering how changes like #4568 show effort being spent to _mirror_
diagnostic style, my thought is now to just use diagnostic code where
possible.

Note this also allows incrementally better testing of the language
server; I'm changing the crash fix from #4847 in favor of diagnostic
testing.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-01-30 01:58:07 +00:00
Jon Ross-Perkins 7d2958ad37 Broaden file_test support for LSP requests (#4854)
Adds `@LSP-NOTIFY` and `@LSP-REPLY` to capture the slightly different
formats versus a typical call. Removes special-casing for `exit`.
v0.0.0-0.nightly.2025.01.30
2025-01-29 21:31:10 +00:00
Jon Ross-Perkins 4ecf914a07 Make SemIRLoc data private to diagnostics (#4867)
I think the name of `SemIRLoc` might be leading to a few suggestions to
use it for non-diagnostic purposes that I've been responding to. At the
same time, a short name seems desirable given its frequency of use for
diagnostics. I did also clean up misuse in #4857, and eval.cpp (noted
below) might be similar. We don't typically use `friend` to emphasize
relationships, but given the diagnostic-specific intent and ways it's
been used, perhaps it's reasonable to close the API of this type using
`friend`?

eval.cpp inspects contents, but it's not clear that's needed because
changing logic doesn't affect tests, so I'm just removing it. Note that
SemIRLoc could've also been a loc_id, and it seems like the current
approach would mishandle that (i.e., print for `LocId::None` when that
seems not to be the intent). I figure we can add a `has_value` or
`AddNoteRequiringLoc` or something like that if needed.
2025-01-29 20:46:30 +00:00
Dana Jansens bb67c7dfb2 Add SemIR::MakeSymbolicConstantId(int) (#4862)
Symbolic constants are negative values (starting at -3 at the moment)
but instead of having to figure the correct integer value for
MakeConstantId, provide a function to make a symbolic constant directly.
2025-01-29 16:55:14 +00:00
Boaz Brickner 7c01bb4e5c Return the NameId for a new instruction regardless if it's unresolved because it's poisoned or not (#4861)
i.e. Support `Poisoned` in `NameContext::name_id_for_new_inst()`.
Part of #4622.
2025-01-29 14:20:05 +00:00
Jon Ross-Perkins 3bd7252f29 Clean up obsolete import handling in class/function (#4857)
Noticed because the `new_loc.inst_id` use would be invalid as-is
v0.0.0-0.nightly.2025.01.29
2025-01-28 22:49:03 +00:00
Jon Ross-Perkins ad0a47d06b Change LookupNameInCore to use a LocId (#4858)
SemIRLoc is doing extra wrapping which shouldn't be used here.
2025-01-28 22:33:07 +00:00
Boaz Brickner f4e19f4390 Change DeclNameStack::LookupOrAddName() to return SemIR::ScopeLookupResult instead of a pair (#4852)
This makes the lookup API more consistent and would make it easier to
add poisoning location.
Part of #4622.
2025-01-28 21:36:20 +00:00
Boaz Brickner 51d7e6315e When looking up a name in a scope, propagate the lookup result when it's poisoned (#4851)
Instead of creating a new poisoned result.
This would allow propagating the poisoning location when we add it.
Part of #4622.
2025-01-28 17:45:24 +00:00
5abe5a3c21 Stop allowing impl redeclarations to differ syntactically in where clause (#4850)
Based on [the lastest thinking on
#4672](https://github.com/carbon-language/carbon-lang/issues/4672#issuecomment-2606209281)
, require a full syntactic match for impl redeclaration, instead of
excluding the `where` restriction. This means no updates to the impl
witness on redeclaration, and no diagnostics that those updates are
consistent.

Not included in this PR, but will need to be done in the future:
* Support for assigning values to associated constants in the body of
the impl definition. This will require moving the checking that
non-function associated constants are set from the definition start to
definition end.
* Identify semantic redeclarations that are not syntactic matches to
give a failed redeclaration diagnostic. This should be done once we are
already identifying impl declarations with the same type structure in
order to require they be identified in an impl_priority/match_first
block.
* Merging of the functions in `check/impl.cpp` that are now always
called together.

Also add some test coverage of `where` parsing I developed in PR I've
now abandoned because of this new simplification of the impl
redeclaration semantics.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-01-28 06:00:34 +00:00
Jon Ross-Perkins 0d0e202ce8 Switch Driver back to parameters for construction (#4849)
This is for more complex construction, see #4846
v0.0.0-0.nightly.2025.01.28
2025-01-27 23:48:44 +00:00
Jon Ross-Perkins 8727445656 Add a framework for LSP testing. (#4841)
Also adds tests for exit and initialize, just basic things.
2025-01-27 16:15:04 +00:00
Richard Smith 809c53287a Fix crash when driver fuzzer finds language-server. (#4847)
The driver fuzzer, unlike the actual driver, provides a null
`input_stream`, which caused the `language-server` subcommand to crash.
2025-01-27 15:36:09 +00:00
Boaz Brickner 3d39ab67bf Wrap lookup result in a new ScopeLookupResult (#4831)
Benefits:
* Provide a proper API for accessing lookup information.
* Make assumptions on whether the result is poisoned or not and how we
can use `InstId` explicit.
* Allow safely reusing the `InstId` value for pointing to the poisoning
entity for poisoned results (in a future PR).
* Consolidate `LookupNameInExactScopeResult`, `std::pair<SemIR::InstId,
bool>` and part of `LookupResult`.
Part of #4622.
2025-01-27 10:05:23 +00:00
Richard Smith 5f888e1124 Treat associated constants as entities parameterized by Self (#4837)
Add a full entity representation for associated constants, and build a
`Generic` object for them. This `Generic` is parameterized by the
enclosing `Self` type, allowing the use of `Self` within the type of the
associated constant to be supported.

When performing impl lookup for an associated constant, produce the type
with the provided self type substituted for its `Self` along with any
generic parameters of the interface.

Split the handling of associated constant declarations into two parts,
corresponding to the code before the `=`, and the code between the `=`
and `;` (if any). The former goes into the generic declaration region;
the latter into the generic definition region. This prepares us to
handle the default value for an associated constant, but for now we're
just storing the information and not actually using it.

Remove the entity type field from `assoc_entity_type`, because it's
almost unused and is an attractive nuisance -- it must necessarily be a
type in the generic scope of the associated constant rather than in the
scope of the instruction (because there is no `Self` anywhere else),
which means that it's hard to substitute into or derive meaning from.

See `toolchain/check/testdata/impl/assoc_const_self.carbon` for tests of
the new functionality; these used to cause the toolchain to crash.
v0.0.0-0.nightly.2025.01.27 v0.0.0-0.nightly.2025.01.26
2025-01-25 02:13:52 +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
v0.0.0-0.nightly.2025.01.25
2025-01-24 21:52:02 +00:00
Jon Ross-Perkins 22c0198835 Fix flag name from #4835 (#4844) 2025-01-24 17:25:46 +00:00
Jon Ross-Perkins aec951d7c3 Fix autoupdate handling of carriage return (#4840)
Switching from RE2 to StrReplaceAll because it seems a fair fit for what
actually needs to be done here. Also pick up \t for visibility reasons.

This came up because clangd's LSP-related APIs print carriage returns.
2025-01-24 16:41:57 +00:00
Richard Smith bc952b1a4b Document numeric type literals in lexical conventions. (#4842)
Also improve the precision of some other nearby documentation.
v0.0.0-0.nightly.2025.01.24
2025-01-24 01:57:42 +00:00
Jon Ross-Perkins ad49647661 Refactor ToolchainFileTest functions out-of-line (#4839)
I'm going to be adding more, and it's large already. Also adding API
comments.
2025-01-24 00:56:13 +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
Geoff Romer 96256652c5 Use FullPatternStack instead of node stack for binding context (#4829) 2025-01-23 17:25:31 +00:00
Jon Ross-Perkins 9c0faf007e Invalid comment cleanup (#4836)
This is a followup from #4834, I searched for "invalid" uses in our
codebase. This is mostly changing comments, and a couple debug
functions, but shouldn't affect testable behavior.

Note a couple things I'll highlight as not changing (but could) are:
- `ReturnTypeInfo::is_valid`
- `"invalid"` uses in the formatter
- `AddInvalid` for `!has_value` in `inst_fingerprinter` (because the
cases it's called sound invalid-ish)
2025-01-23 02:21:48 +00:00
Jon Ross-Perkins 6b5eb1a101 Id::Invalid -> Id::None (#4834)
High level, replacing `Id::Invalid` with `Id::None` and `Id::is_valid`
with `Id::has_value` for clarity, as discussed
[here](https://discord.com/channels/655572317891461132/655578254970716160/1331664574545395794).
The `IntId` refactoring is needed together with `AnyIdBase` because it's
also used with `ValueStore`.

Note, trying to be careful not to rewrite `EnumBase::InvalidIndex`, or
`is_valid` in general (e.g., `IdKind::is_valid`).

I've tried to sequence commits here:

1. Automatic replacements:

- `((?:Id|Index)(?: |::|\(|Base(?:\(|::)))Invalid((?:Index)?\W)` ->
`$1None$2`
  - `<invalid>` -> `<none>`
  - `InvalidNodeId` -> `NoneNodeId`
  - `/\*invalid\*/` -> `/*none*/`
  - `id((?:_|\(\))(?:\.|->))is_valid` -> `id$1has_value`

2. Manual edits:

  - In `int.h` and `int_test.cpp`
    - `IntT` has `is_value`, which I'm renaming to `is_embedded_value`.
    - Manual edits to comments in this file.
  - `AnyIdBase` and `IdBase`
- Declaration of `is_valid` -> `has_value`, `InvalidIndex` ->
`NoneIndex`.
  - In `ids.h` and `ids.cpp`
    - `is_valid` -> `has_value`
- `// An explicitly invalid ID.` -> `// An ID with no value.`; similar
for index
    - Various math on `InvalidIndex` -> `NoneIndex`
    - Various mentions of "valid" in comments
  - In `value_store.h`, for `IdT::Invalid`, plus one comment
- In `impl.h` and `tokenized_buffer.h`, we had different initialization
of `::None` values (versus `ids.h` syntax) that I fixed manually.
  - Spot checks to compile
- Particularly where `is_valid` replacements didn't catch spots due to
different naming.

3. Autoupdate tests

4. verbose.carbon (NOAUTOUPDATE)

5. Comment spot checks

Note there are probably other mentions of "Invalid" that should be swept
up, but I'd like to argue for merging and separating out remaining
cleanup since this is so sweeping (and likely to hit merge conflicts
from churn). We'll probably have lingering mentions of "invalid" for a
bit regardless, just because there are uses of "invalid" in non-Id APIs.
v0.0.0-0.nightly.2025.01.23
2025-01-22 23:15:00 +00:00
David Blaikie b292943648 Sink comment into implementation (#4833)
This comment applies equally to any called passing `check_syntax=false`,
such as for virtual function impls, being tested in #4816
2025-01-22 22:26:35 +00:00
David Blaikie d620f3f2da Remove unused parameter (#4832)
Post-commit review in #4732
2025-01-22 20:27:05 +00:00
Calvin 3f4de65ad8 Improve SemIR naming of import_refs (#4824)
Changes the name of SemIR `import_ref`s to use the format
`<package>.<entity>`.

<table>
<tr><th>Before</th><th>After</th></tr>
<tr>
<td><code>%import_ref.05a: type</code></td>
<td><code>%Main.D: type</code></td>
</tr>
<tr>
<td><code>%import_ref.8f2: &lt;witness&gt;</code></td>
<td><code>%Main.import_ref.8f2: &lt;witness&gt;</code></td>
</tr>
</table>

* [Discord discussion in
#toolchain](https://discord.com/channels/655572317891461132/655578254970716160/1330253540999827577)
* Closes #4769
2025-01-22 07:22:07 +00:00
dependabot[bot] fe92e3f552 Bump undici from 6.21.0 to 6.21.1 in /utils/vscode in the npm_and_yarn group across 1 directory (#4830)
Bumps the npm_and_yarn group with 1 update in the /utils/vscode
directory: [undici](https://github.com/nodejs/undici).

Updates `undici` from 6.21.0 to 6.21.1
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/nodejs/undici/releases">undici's
releases</a>.</em></p>
<blockquote>
<h2>v6.21.1</h2>
<h1>⚠️ Security Release ⚠️</h1>
<p>Fixes CVE CVE-2025-22150 <a
href="https://github.com/nodejs/undici/security/advisories/GHSA-c76h-2ccp-4975">https://github.com/nodejs/undici/security/advisories/GHSA-c76h-2ccp-4975</a>
(embargoed until 22-01-2025).</p>
<h2>What's Changed</h2>
<ul>
<li>fix(<a
href="https://redirect.github.com/nodejs/undici/issues/3736">#3736</a>):
back-port 183f8e9 to v6.x by <a
href="https://github.com/ggoodman"><code>@​ggoodman</code></a> in <a
href="https://redirect.github.com/nodejs/undici/pull/3855">nodejs/undici#3855</a></li>
<li>fix(<a
href="https://redirect.github.com/nodejs/undici/issues/3817">#3817</a>):
send servername for SNI on TLS (<a
href="https://redirect.github.com/nodejs/undici/issues/3821">#3821</a>)
[backport] by <a
href="https://github.com/metcoder95"><code>@​metcoder95</code></a> in <a
href="https://redirect.github.com/nodejs/undici/pull/3864">nodejs/undici#3864</a></li>
<li>fix: sending formdata bodies with http2 (<a
href="https://redirect.github.com/nodejs/undici/issues/3863">#3863</a>)
[backport] by <a
href="https://github.com/metcoder95"><code>@​metcoder95</code></a> in <a
href="https://redirect.github.com/nodejs/undici/pull/3866">nodejs/undici#3866</a></li>
<li>[Backport v6.x] fix: Fixed the issue that there is no running
request when http2 goaway by <a
href="https://github.com/github-actions"><code>@​github-actions</code></a>
in <a
href="https://redirect.github.com/nodejs/undici/pull/3877">nodejs/undici#3877</a></li>
<li>types: [backport] Update return type of RetryCallback (<a
href="https://redirect.github.com/nodejs/undici/issues/3851">#3851</a>)
by <a href="https://github.com/metcoder95"><code>@​metcoder95</code></a>
in <a
href="https://redirect.github.com/nodejs/undici/pull/3876">nodejs/undici#3876</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/nodejs/undici/compare/v6.21.0...v6.21.1">https://github.com/nodejs/undici/compare/v6.21.0...v6.21.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/nodejs/undici/commit/e260e7bb173abe3399dabd61338ca4a71fcf8825"><code>e260e7b</code></a>
Bumped v6.21.1</li>
<li><a
href="https://github.com/nodejs/undici/commit/c3acc6050b781b827d80c86cbbab34f14458d385"><code>c3acc60</code></a>
Merge commit from fork</li>
<li><a
href="https://github.com/nodejs/undici/commit/2414bc9f7d651f830902af00238e1b11d9a389dc"><code>2414bc9</code></a>
Update return type of RetryCallback (<a
href="https://redirect.github.com/nodejs/undici/issues/3851">#3851</a>)
(<a
href="https://redirect.github.com/nodejs/undici/issues/3876">#3876</a>)</li>
<li><a
href="https://github.com/nodejs/undici/commit/be8cd0afa0cf8207d8849026f2ee6fdc6dc9dcec"><code>be8cd0a</code></a>
[Backport v6.x] fix: Fixed the issue that there is no running request
when ht...</li>
<li><a
href="https://github.com/nodejs/undici/commit/ee6176cd2e09853c868bf5bc1a34bf0500963e4d"><code>ee6176c</code></a>
fix: sending formdata bodies with http2 (<a
href="https://redirect.github.com/nodejs/undici/issues/3863">#3863</a>)
[backport] (<a
href="https://redirect.github.com/nodejs/undici/issues/3866">#3866</a>)</li>
<li><a
href="https://github.com/nodejs/undici/commit/a0220f14bfd2a404173eacc94aa1722829075283"><code>a0220f1</code></a>
fix(<a
href="https://redirect.github.com/nodejs/undici/issues/3817">#3817</a>):
send servername for SNI on TLS (<a
href="https://redirect.github.com/nodejs/undici/issues/3821">#3821</a>)
[backport] (<a
href="https://redirect.github.com/nodejs/undici/issues/3864">#3864</a>)</li>
<li><a
href="https://github.com/nodejs/undici/commit/353ab63188af904a17030d96018d6193247d7d18"><code>353ab63</code></a>
fix(<a
href="https://redirect.github.com/nodejs/undici/issues/3736">#3736</a>):
back-port 183f8e9 to v6.x (<a
href="https://redirect.github.com/nodejs/undici/issues/3855">#3855</a>)</li>
<li>See full diff in <a
href="https://github.com/nodejs/undici/compare/v6.21.0...v6.21.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=undici&package-manager=npm_and_yarn&previous-version=6.21.0&new-version=6.21.1)](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>
v0.0.0-0.nightly.2025.01.22
2025-01-22 01:02:24 +00:00
Jon Ross-Perkins e393c769af Add support for testing with stdin (#4819)
In order to write language-server tests, we need some way to pass stdin
input. This adds support for a split "// --- STDIN" which will be
provided as a temp file for testing.

Note this does more stdin -> input_stream style renaming, this is just
bugging me more since I know shadowing works but it can be subtle to
read, particularly since I'm now making direct use of stdin in a handful
of spots.
2025-01-21 22:04:13 +00:00
David Blaikie 667a010ae6 Readd the missing class !members list. (#4828)
Thanks to danakj for spotting this was removed accidentally in #4732
2025-01-21 20:37:07 +00:00
Geoff Romer 943acf1ec2 Separate node kind for bindings inside var (#4822)
This is a step toward making binding pattern handling more robust, by
removing its reliance on the node stack for context.
2025-01-21 20:15:19 +00:00
Jon Ross-Perkins 4f024410f7 Add stdin to driver's streams, and refactor stream passing (#4812)
The language server needs stdin, and for tests we should be passing it
around. My intent is to pass in a faux stdin to Driver for language
server tests.

As long as I'm adding a new parameter, I was looking at also changing
the way streams are passed in to Driver for style (pointers since
they're held past construction lifetime). Since these are all stored in
DriverEnv, I thought it might be a net improvement to use the struct
directly, getting more explicit parameter names and also removing the
need for `SetFuzzing`.

I'm trying here to avoid functional changes, but there are a couple
additional fixes like removing an obsolete `find_insensitive` and
refactoring how `ValidateOptions` handles errors (because it reduces the
number of spots that operate on error_stream).
2025-01-21 16:52:05 +00:00
Jon Ross-Perkins 41b6bb5688 Update TODO for semantic checking (#4821)
I believe `check_syntax` is already controlling the semantic vs
syntactic merge, added in #4149. Other parts of the TODO are clarified
per discussion. But this is tested, e.g. errors with the bool flipped:

```
 impl i32 as I {
+  // CHECK:STDERR: method.carbon:[[@LINE+6]]:14: error: redeclaration syntax di
ffers here [RedeclParamSyntaxDiffers]
+  // CHECK:STDERR:   fn F[self: i32](other: i32) -> i32 = "int.sadd";
+  // CHECK:STDERR:              ^~~
+  // CHECK:STDERR: method.carbon:[[@LINE-7]]:14: note: comparing with previous
declaration here [RedeclParamSyntaxPrevious]
+  // CHECK:STDERR:   fn F[self: Self](other: Self) -> Self;
+  // CHECK:STDERR:              ^~~~
   fn F[self: i32](other: i32) -> i32 = "int.sadd";
 }
```
2025-01-21 16:50:25 +00:00
Boaz Brickner 6636baf392 Remove comment about inst_id not being poisoned (#4827)
`InstId` cannot be poisoned since #4764.
Part of #4622.
2025-01-21 16:34:46 +00:00
Calvin a664801608 Reformat CompilationUnit function definitions out-of-line (#4825)
The `Driver::CompilationUnit` class is defined with multiple long
function definitions inline. This change moves those definitions
out-of-line.
2025-01-21 16:27:00 +00:00
Boaz Brickner c304e73857 When adding a namespace, explicitly unpoison an optimistically poisoned name (#4826)
Part of #4622
2025-01-21 16:18:49 +00:00
Boaz Brickner d30957fc65 Remove extra SemIR:: qualification in NameScope since it's already in SemIR namespace (#4823) v0.0.0-0.nightly.2025.01.21 2025-01-20 15:44:14 +00:00
Boaz Brickner 30c1530261 Support multiple import Cpp library in a single unit (#4814)
Instead of compiling the imported file, generate a C++ header that
includes all `Cpp` import files.
Part of #4666
2025-01-20 09:44:45 +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>
v0.0.0-0.nightly.2025.01.20 v0.0.0-0.nightly.2025.01.19
2025-01-18 01:11:44 +00:00
Richard SmithandCarbon Infra Bot ef6e035e7d Website: exclude files that would cause problems for prebuild or jekyll (#4810)
Exclude some files from the website and prebuild steps that aren't part
of the git repository, but may exist in a checkout, and if present will
cause the website prebuild or build to misbehave or break.

---------

Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
v0.0.0-0.nightly.2025.01.18
2025-01-17 20:47:52 +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-Perkins 6572da7314 Add dwblaikie as a toolchain reviewer (#4820) 2025-01-17 16:51:53 +00:00
David BlaikieandJon Ross-Perkins e6c1f0630a Add a newline after diagnostic output when testing (#4818)
This removes some churn when adding new diagnostic cases to test files
(where previous to this change the newly added newline would cause the
previous diagnostic CHECKs to be updated including changes to the line
number because the CHECK for the blank line meant an extra line between
CHECK and source line).

A few alternatives discussed here:
https://discord.com/channels/655572317891461132/655578254970716160/1329573358475673723

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
v0.0.0-0.nightly.2025.01.17
2025-01-16 23:23:57 +00:00
a8b46cf561 Add SemIR Vtable instruction and usage (#4732)
Add a Vtable typed inst with a type_id (of the type this vtable applies
to) and list of virtual function decls (or import refs to function
object constants).

This doesn't add lowering/emission of the vtable, or usage when
initializing objects of the type.

Some questions in case they're interesting to discuss:
* is it right/worth having the type_id in the vtable? (probably makes it
easier to emit - using the type to get the class name to figure out the
mangled name for the vtable) perhaps it should be a ClassId?
* I'm thinking the logic in CheckCompleteClassType could be the place we
handle diagnostics for mismatched keywords (virtual/abstract for a
function that's already virtual/abstract, maybe checking for non-virtual
functions with the same name in a base class, or derived class functions
without `impl`, etc) - but we could move some of that to the moment we
walk the function decl, and record our findings in the function decl
(record the base function it overrides, or the index of the vtable to
slot to use when building the vtable at the end of the class)
* the Vtable typed inst has `constant_kind = InstConstantKind::Always`
and `is_lowered = false`, I think I added that in to workaround/address
some failures in lowering. And seems correct for this intermediate step
- I'll add lowering in a follow-up patch. But the constant_kind - what
should this be? We can just say all vtables are of VtableType (in which
case the `Always` constant kind sounds right to me) or we could have
them introduce a type with each virtual function as a named member,
even?

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-01-16 20:19:22 +00:00
Jon Ross-Perkins e348119feb Update a few faq questions which are showing their age (#4813)
Struck me I hadn't looked through this recently, although it feels it's
mostly held together.
v0.0.0-0.nightly.2025.01.16
2025-01-16 01:27:42 +00:00
Richard Smith a058f30f3a Fix rendering of https://docs.carbon-lang.dev/proposals/p2188.html (#4802)
Per https://kramdown.gettalong.org/syntax.html#html-blocks, kramdown
doesn't render markdown inside HTML tags by default. Enable this
globally to get results more similar to Github-Flavored Markdown.
2025-01-15 22:38:11 +00:00
Dana Jansens 6aba386eeb Move the complete_witness_type above the !members label. (#4808)
When printing a Class, the complete_type_witness was printed last but
this gave a somewhat misleading representation as it appeared to be part
of the !members label. Move it above the label so that the label more
clearly refers to everything below it.
2025-01-15 22:13:19 +00:00
Jon Ross-Perkins f7269482fe Remove node_stack Peek templating where possible (#4801)
The "templated for consistency" variants felt a little confusing when I
was working on #4795, so suggesting to remove templating where it's not
helpful to instantiate (particularly when there were both templated and
non-templated variants). Note this leaves a `PeekIs<IdT>` because
there's indirection there, but that's more the exception than the rule.
2025-01-15 22:12:22 +00:00
Richard Smith e0f9c40f47 Switch some codeblocks to recognized languages. (#4811)
Fix syntax highlighting for these code blocks.
2025-01-15 21:49:14 +00:00