Commit Graph
4002 Commits
Author SHA1 Message Date
Jon Ross-Perkins 0fd129ec95 Update tuple tests, and merge in expr-category (#5549)
In the vein of https://github.com/carbon-language/carbon-lang/pull/5455.

This merges the one expr_category test into tuple testing because it
seemed closely associated (particularly with
in_place_tuple_init.carbon), and it didn't seem worth keeping a
directory for a single test.

Note the entire "access" directory is combined into
element_access.carbon.
2025-06-02 16:36:22 +00:00
Jon Ross-Perkins 39a701084c Update eval tests (#5547)
In the vein of https://github.com/carbon-language/carbon-lang/pull/5455.
This also uses the 'int' min_prelude being added by #5546.
2025-06-02 16:21:11 +00:00
Jon Ross-Perkins 8615b6b411 Add an int min_prelude (#5578)
The general intent here is to support basic use of `i32` and similar
integer types in min_prelude tests, without all the various arithmetic
support.

This is in support of #5547 and #5549. However, I was originally asking
for this to be reviewed as part of #5546 rather than either of those
PRs, and I've retracted #5546 due to [the discussion on Discord about
test change
complexity](https://discord.com/channels/655572317891461132/655578254970716160/1377406366200758293).
So, to try to still get this in (and then merge the already-approved
#5547 and #5549), splitting out this file.

Note this is actually the form of the prelude in #5549, which was adding
negate -- it felt better to me to add that together as long as I'm
splitting it out.
2025-06-02 15:18:41 +00:00
Boaz Brickner 464ee76b9b Fix stack-use-after-scope issue by making LangOptions parameter non temporary (#5586)
The parameter is kept by reference.
Added a test that accesses `LangOptions` and crashes without this fix.

Part of #5176.
2025-06-02 14:28:36 +00:00
Jon Ross-Perkins e3738eb196 Try out a different IdKind table approach (#5528)
I was thinking about these after #5526, was wondering how others will
feel about this kind of approach:

- Adding a helper to `TypeEnum` to get the table construction.
- In what were previously `Make` functions, return the element instead
of returning the table.
- By returning the element, no more need to pass in a nullptr (now have
a concrete instance).

I think this is a mild simplification, but maybe worth it.

Note, would appreciate it if there are thoughts on how to provide a
boilerplate `Invalid` implementation (maybe it'd be fine to just return
`nullptr` and cause a crash that way, but I was hesitant to do that).
v0.0.0-0.nightly.2025.06.02 v0.0.0-0.nightly.2025.06.01
2025-05-31 02:15:45 +00:00
Jon Ross-Perkins c70f23408d Add range flag settings to where_expr files (#5582)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
v0.0.0-0.nightly.2025.05.31
2025-05-31 01:42:10 +00:00
Jon Ross-Perkins 3c49283b3b Add range flag settings to deduce files (#5579)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-31 01:41:39 +00:00
David Blaikie d614ed0fc9 Assert that non-None NameScopes import as non-None (#5584)
This would've identified c6f25e9018
earlier/more clearly.

I looked for similar assertions for things like
`GetLocalConstantValueOrPush` but it has the right property by
construction (if it's going to return `None`, it pushes work) so an
assertion didn't seem suitable there.

Perhaps there are other such mapping functions that could get this
treatment? Open to pointers.
2025-05-31 01:11:58 +00:00
Boaz Brickner ae454bb48c Test C++ structs as parameters and return types as declarations and definitions (#5537)
Move all function tests to a dedicated directory and all `struct`
function tests to a dedicated file in this directory.

Part of #5533.
2025-05-30 21:52:26 +00:00
Jon Ross-Perkins 7f52cc7c0e Add ranges flags in a smattering of files missed in other PRs (#5581)
Now that I'm getting to a relatively low number of remaining files for
this cleanup, this is my second look for things that I missed before in
directories that were generally already swept up (mostly by the TODOs).
2025-05-30 18:26:33 +00:00
Jon Ross-Perkins 3e2fb5e6ec Add range flag settings to patterns files (#5570)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-30 18:20:49 +00:00
Jon Ross-Perkins 5c59ee6f6f Update global tests (#5552)
Updates in the vein of #5455.

Note this seems a little like it could be merged into `var`, which
already has global tests. But the merge felt a little more complex than
just doing this update.
2025-05-30 17:17:14 +00:00
Dana Jansens 11e82e9872 Revert "Add FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to fuzzer mode and enable DCHECKs under fuzzing (#5489)" (#5580)
This reverts commit 1889ee3904.

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

We need to apply fuzzer globally when building fuzz targets somehow, or
not set different defines in fuzzer.
2025-05-30 16:20:43 +00:00
Jon Ross-Perkins 0b530de9ed Add range flag settings to operators files (#5567)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-30 15:03:42 +00:00
Jon Ross-Perkins a01648cd44 Use concat in formatter (#5577)
Because this is coming up on #5576
2025-05-30 14:36:19 +00:00
Alina Sbirlea 77afd0678b Prototype for coalescing equivalent specifics of the same generic. (#5314)
This is a working version for coalescing equivalent specifics of the
same generic, with *many* things to add and improve.
v0.0.0-0.nightly.2025.05.30
2025-05-29 22:24:13 +00:00
Jon Ross-Perkins 370027599c Add range flag settings to var files (#5574)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:57:36 +00:00
Jon Ross-Perkins 5c6e94f0ae Add range flag settings to struct files (#5573)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:57:04 +00:00
Jon Ross-Perkins f91d23b110 Add range flag settings to return files (#5572)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:54:49 +00:00
Jon Ross-Perkins ffc014bbe2 Add range flag settings to packages files (#5569)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:26:13 +00:00
Jon Ross-Perkins 59cb7183b2 Add range flag settings to pointer files (#5571)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:25:46 +00:00
Jon Ross-Perkins 34b892b774 Fix formatting of forward declared generics (#5530)
Noticed this while working on class tests (crash bug). Forward declared
generics have a decl_id of the forward declaration, not the definition.
I'm giving up trying to have the caller know if it's a start node, and
instead just choosing based on the node kind.
2025-05-29 20:20:06 +00:00
Richard Smith 42c783defa Use linkonce_odr linkage for specific functions. (#5575)
The same specific function will (eventually) be emitted as part of
lowering multiple different source files, so don't give them unique
external linkage.
2025-05-29 20:16:37 +00:00
Jon Ross-Perkins aadd29b36c Update if tests (#5551)
In the vein of #5455. This reuses the bool min_prelude in #5550.
2025-05-29 20:07:40 +00:00
Jon Ross-Perkins e135ea35b6 Add range flag settings to package-expr files (#5568)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 20:02:12 +00:00
a23631f360 Support for lowering references to imported vars. (#5513)
Previously we walked the global variables defined by the current file
and emitted an LLVM global variable definition for each of them. Now
instead, when emitting a constant reference to a global variable, we
emit an LLVM global variable declaration, and we then subsequently walk
the global variables defined by the current file and convert each of
them from a declaration to a definition.

In order to make import of names of global variables work, add support
for import of `var`, as well as support for importing `tuple_access` and
`tuple_pattern` in the case where the `var` has a tuple pattern in its
declaration. Also treat `bind_name`s that are reference bindings to
`var`s as having the same constant reference value as their `var` so
that we can properly import and lower them.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
2025-05-29 19:48:16 +00:00
David BlaikieandRichard Smith c6f25e9018 Ensure an imported Class's NameScope is allocated in phase 2 (#5548)
Entities, such as `Function`s may be created during phase 2 and need to
read the `Class`'s `scope_id` at that point, so it must be made
available earlier (in phase 2, rather than 3) when importing.

(thanks @zygoloid for explaining this all to me)

I'll look into other instances of this 3 phase lookup to see if they
have
similar bugs/if I can create test cases to tickle them as follow-ups.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2025-05-29 19:21:22 +00:00
Jon Ross-Perkins 4cd0b85600 Update while tests, adding a bool min_prelude (#5550)
In the vein of #5455.

The bool min_prelude will probably also get used for other constructs,
like `if`.
2025-05-29 19:20:28 +00:00
Jon Ross-Perkins 560b5734a4 Add range flag settings to interop files (#5564)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.
2025-05-29 18:46:37 +00:00
Jon Ross-Perkins f8019d8b58 Add range flag settings to index files (#5561)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:45:46 +00:00
Jon Ross-Perkins 27aa0898e0 Add range flag settings to if_expr files (#5562)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:44:49 +00:00
Jon Ross-Perkins 825773dcb3 Add range flag settings to impl files (#5560)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:44:09 +00:00
Jon Ross-Perkins 4193c306a4 Add range flag settings to function files (#5558)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:43:14 +00:00
Jon Ross-Perkins 2e3fb4dc1c Add range flag settings to namespace files (#5566)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:42:44 +00:00
Jon Ross-Perkins 8fb5bcedd5 Add range flag settings to interface files (#5563)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:41:55 +00:00
Jon Ross-Perkins 0b8fa690cd Add range flag settings to let files (#5565)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:35:15 +00:00
Jon Ross-Perkins cef617ac02 Add range flag settings to facet files (#5557)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:33:37 +00:00
Jon Ross-Perkins 3fb4d9a468 Add range flag settings to class files (#5556)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:32:57 +00:00
Jon Ross-Perkins 6318987343 Add range flag settings to generic files (#5559)
Where `--no-dump-sem-ir` is used, change to `--dump-sem-ir-ranges=only`.
Otherwise, add `--dump-sem-ir-ranges=if-present` with a TODO to change
to `only`.

Note, SemIR is affected just because the extra comments change line
numbers in files where splits aren't in use.
2025-05-29 18:19:58 +00:00
Thomas Köppe f18fc40a32 Add missing standard library header inclusions (#5486)
Discovered by clang-tidy.

See also #5316.
v0.0.0-0.nightly.2025.05.29
2025-05-28 22:48:20 +00:00
Jon Ross-Perkins 270174cd82 Move the ir test (#5510)
This test has its own directory, since #3056. We haven't added any more,
so fold it into basics. Also simplify it a little using `else`, and
`no_prelude`.

Note, I'm not even sure how much we need this test given the
`%.loc<line>_<col>`, but I feel slightly worse deleting it.
v0.0.0-0.nightly.2025.05.28
2025-05-27 23:31:22 +00:00
Dana Jansens 69ab97d716 Don't wrap an ErrorInst as a subpattern of another pattern (#5542)
When a pattern is an error, avoid wrapping it as a subpattern in a
RefParamPattern or VarPattern. This allows further error handling to
observe the error occurred without having to unwrap it.

This avoids a crash when an invalid associated constant is written which
has a VarPattern in it. The associated constant machinery expects an
AssociatedConstantDecl but was getting a VarPattern with an ErrorInst
inside. Now it receives an ErrorInst directly, which it is already
looking for.

This choice means that `var` statements in an `interface` will always be
diagnosed as being non-constant, or as being a constant with a `var`, so
we don't need an extra diagnostic saying that `var` is not allowed in an
interface, as this just leads to two diagnostics on the same thing.

This crash was found by a fuzzer.
2025-05-27 18:13:12 +00:00
Jon Ross-Perkins 3946cac281 Update const tests for splits, preludes, and ranges (#5532) 2025-05-27 17:05:33 +00:00
Boaz Brickner 5095af991f Make MatchContext::WorkItem, CalleeFunction, InitRepr, ReturnTypeInfo Printable (#5535)
Found these to be useful for debugging.
2025-05-27 16:50:13 +00:00
Boaz Brickner 0a5dc9a9cc Use C++ trailing return type in toolchain/check/testdata/interop/cpp/no_prelude/function.carbon (#5541) 2025-05-27 16:20:00 +00:00
Jon Ross-Perkins 90649d60f0 Fix crash on 'destroy' with return type and no params (#5527)
Fuzzer-found crash
v0.0.0-0.nightly.2025.05.27 v0.0.0-0.nightly.2025.05.26 v0.0.0-0.nightly.2025.05.25 v0.0.0-0.nightly.2025.05.24
2025-05-23 19:33:06 +00:00
Jon Ross-Perkins 95ce06a7a4 Adjust KindHasGetConstantValueOverload approach (#5526)
Tinkering with #5517, splitting out this suggestion to try to avoid
delaying merge. I figured out what I was missing on the variadiac
expansion. :)

(and also realized the struct could probably be a function)
2025-05-23 17:58:08 +00:00
Jon Ross-Perkins cea9954e28 Update basics tests for ranges, splits, and min_prelude (#5509)
Updating tests in the style of
https://github.com/carbon-language/carbon-lang/pull/5455.

- Moving `Run`-specific tests into their own directory, with a README to
explain why it's unusual.
  - Note, I suspect we'll also get more over time (e.g., with arguments)
- This makes a little more use of `if-present` just because there are
more tests that want to print their full output.
- I'm combining the two empty-ish tests, thought I do still want the
*really* empty one to be fully empty (i.e., no tokens provided by the
file).
- Dropping multifile.carbon because it doesn't seem like an interesting
test to keep.
2025-05-23 17:50:02 +00:00
Dana JansensandJon Ross-Perkins 5aea18f949 Avoid resolving the decl block for specifics in imported instructions (#5517)
Move the operation of resolving the specific decl block from
`GetConstantValue()` to `TryEvalTypedInst()`, with is now happening
after replacing the fields of the instruction with new constant values,
but before running the evaluation of the instruction. Since imported
instructions are not evaluated, this avoids resolving the specific decl
block from imported instructions, resolving a TODO in
`AddImportedConstant()`. Now `AddImportedConstant()` can replace
constant values in its fields without having to worry about that
operation resolving any specific decl blocks.

We get to add a new TODO however, to explain why we still need a special
case in resolving specific decl blocks for handling `Impl` construction.
The witness table contains instructions with specifics referring to the
generic self of the impl declaration. But the table must be constructed
before the impl's generic is finished, in order to make the instructions
dependent for the generic. But then resolving the specific decl block
can't be done when the instructions are created and evaluated, as that
requires a finished generic.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2025-05-23 16:58:46 +00:00
Jon Ross-Perkins 2c013ada42 Update choice tests for ranges (#5525)
Note the amount of IR excluded is pretty small, but non-zero (mainly
prelude-related, due to the way a choice depends on `UInt`)

Renaming fail_todo_params.carbon to just params.carbon, and folding in
fail_invalid.carbon.
v0.0.0-0.nightly.2025.05.23
2025-05-22 22:34:12 +00:00