Commit Graph
3011 Commits
Author SHA1 Message Date
Richard Smith a02dfe0226 Superficial support for Core.BigInt type (#4414)
Add a `Core.BigInt` type and a corresponding builtin type in the
toolchain. See [corresponding section of the
design](https://docs.carbon-lang.dev/docs/design/expressions/literals.html#defined-types).

So far this type is not used for anything, and there is no way to create
an instance of it.
v0.0.0-0.nightly.2024.10.17
2024-10-16 23:27:01 +00:00
Jon Ross-Perkins 96964ee534 Implement basic bool and int formatting for diagnostics (#4411)
Note, this supports plurals, but doesn't apply it anywhere. I'm mainly
doing that to demonstrate the approach regarding syntax. See
format_providers.h for details.
2024-10-16 22:46:15 +00:00
Jon Ross-Perkins a5ba0eed6a Drop macos-12 runners due to shutdown (#4412)
macos-12 is being shut down; it will have outages in November, and will
be fully removed in December:
https://github.com/actions/runner-images/issues/10721
2024-10-16 21:52:28 +00:00
David BlaikieandRichard Smith dfed743de2 Add vtable pointers to class layout (#4407)
A small step to virtual functions - adding vtable pointers to the
layout, but not initializing or otherwise using them at this stage.

A few open design questions I'd love feedback on:

* Is this the right/good enough SemIR representation for now? This patch
adds a `is_dynamic` attribute to `SemIR::Class` and populates/flags it
based on the flag of the base class, or if any virtual function is
declared in the class (or, at least that's my intent). Some other
options include:
* Each `Class` could store a `ClassId` (or `TypeId`?) of the (possibly
indirect, possibly self) base class that is the first one that is
dynamic/has a vtable pointer
* Could make the property narrower, like `has vtable pointer` and have
it `true` only on the type that introduces the vtable - then derived
classes would have to walk their base classes to check if they're the
one that needs to define the vtable pointer or not
* Should the vtable be the first element in the type? If there's a
non-dynamic base type, we could have a layout that's `{<non-dynamic base
type>, vtable ptr, <derived members>}`? Derived types would still be
able to uniquely identify where their vtable pointer is just fine... -
and the vtable pointer is, in a sense, a member of that intermediate
type, so it does seem a bit strange to force it to the front - but I
guess it's probably more efficient in some ways?

Open to any other suggestions/advice/thoughts on the direction, etc.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-10-16 21:26:17 +00:00
Jon Ross-Perkins 3c58fb7ec5 Adjust libpfm4 dep to use git instead of the tar. (#4413)
The .tar.gz link is currently broken (I think wget used to work, now it
doesn't); not sure if that's deliberate since it's a download page. I'm
hoping the new location remains more reliable.

Note I tried using SourceForge's git directly. That works locally, but
on the action runners it seems to be blocked:

```
fatal: unable to access 'https://git.code.sf.net/p/perfmon2/libpfm4/': Failed to connect to git.code.sf.net port 443 after 5 ms: Connection refused
```
2024-10-16 20:07:33 +00:00
Geoff RomerandJon Ross-Perkins 9d942f4633 Generate parameter pattern-match IR from pattern IR (#4388)
Also propagate the pattern IR along with the pattern-match IR, and use
it where appropriate.

Strictly speaking, some parts of the pattern-match IR are allocated
eagerly, while traversing the pattern's parse tree, but they still
aren't actually emitted until we traverse the associated pattern insts.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2024-10-16 19:15:29 +00:00
Jon Ross-Perkins 4a73b36688 Switch back to the system llvm-symbolizer. (#4410)
Undoes most of #4347, because of [performance
complaints](https://discord.com/channels/655572317891461132/707150492370862090/1295527235133898772).
With a 30-ish frame stack trace and `-c dbg`, my installed
`llvm-symbolizer` still seems slow (~6s), but the hermetic
`llvm-symbolizer` adds ~4s (i.e., ~10s total). I don't think we can
easily force the hermetic version to build in opt configuration, so I'm
backing it out.
2024-10-16 18:32:11 +00:00
Jon Ross-Perkins 77facdd775 Remove unused benchmark_main.h (#4409)
This was refactored to Testing::GetExePath, but apparently the header
was missed.
v0.0.0-0.nightly.2024.10.16
2024-10-15 20:43:26 +00:00
Jon Ross-Perkins e2256516e8 Fix InitLLVM argv (#4405)
`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The
order needs to be switched.
v0.0.0-0.nightly.2024.10.15 v0.0.0-0.nightly.2024.10.14
2024-10-13 17:47:57 +00:00
David BlaikieandRichard Smith d491387a98 Disallow creating instances of abstract classes (#4381)
A good first-pass, at least. (abstract adapters are rejected with this
change, though pending further language design discussion)

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
v0.0.0-0.nightly.2024.10.13
2024-10-12 15:17:42 +00:00
Jon Ross-Perkins bafddd8711 Use @bazel_tools//tools/cpp:malloc instead of defining a library (#4404)
@bazel_tools//tools/cpp:malloc is equivalent and comes from
https://bazel.build/reference/be/c-cpp#cc_binary.malloc. This also
avoids some confusion in the documentation, since while system_malloc
_can_ be used with `malloc`, it has no effect when it's used with
`--custom_malloc`. But, rather than trying to adjust that, maybe we can
just use @bazel_tools//tools/cpp:malloc
v0.0.0-0.nightly.2024.10.12
2024-10-11 21:11:11 +00:00
josh11bandJosh L 8ecf844ba5 Fix missing ` (#4403)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-11 20:43:51 +00:00
josh11bandJosh L 4994e13068 Document that extend base must appear early in a class definition (#4401)
Note: some of this is from the principle of information accumulation,
and some is from [proposal
#2760](https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p2760.md#class-inheritance).

Also: change terminology from "virtual override keywords" to "virtual
modifier keywords", to be consistent with our other modifier keywords.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-11 19:51:15 +00:00
josh11bandJosh L b0cde707f8 Rename "partial facet" and to "partial class type" (#4402)
See [2024-10-01 discussion on #typesystem in
Discord](https://discord.com/channels/655572317891461132/708431657849585705/1290774105498325122).

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-11 18:25:18 +00:00
Richard Smith 851ef2c517 Initial, very rough lowering for calls to specific functions and specific function declarations. (#4399)
Generate declarations of specific functions on demand. Definitions are
not emitted yet, and I'm using a temporary, known-broken scheme for name
mangling.
v0.0.0-0.nightly.2024.10.11
2024-10-10 23:37:16 +00:00
Jon Ross-Perkins df55b89e08 Implement some token-based formatting structure. (#4386)
Here I'm trying to add some simple formatting based on the token kind,
aiming mainly to keep the implementation short for now.

This approach won't generalize to arbitrary structures (e.g., it doesn't
discern between braces for a function body and a struct literal). I
think we'll probably want to build a parse tree and associate parse
kinds with tokens in order to format, additionally doing something less
linear. But my essential goal at present is to just get a
proof-of-concept that the basics can yield something that looks okay.
2024-10-10 23:18:38 +00:00
josh11bandJosh L c721a020a7 Store pointer not reference in ConstantStore (#4398)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-10 22:30:10 +00:00
Jon Ross-PerkinsandChandler Carruth 0db96ebc52 Stitch together adjacent comments using the indent. (#4397)
This is improving the comment production to produce fewer distinct
comments.

At present, comment processing uses strict prefix matching. It either
expects `// ` (with a space) for valid comments, or just `//` (without a
space) for invalid comments that lacked the space.

As a consequence, the following would be three comments:

```
// Comment 1
//
//
// Comment 4
```

This is because a 3-character prefix is used for valid comments. The
prefix switches between lines 1 and 2, and again between lines 3 and 4,
each resulting in a separate comment.

For contrast, this is one comment because only a 2-character prefix is
used:

```
//Comment 1
//
//
//Comment 4
```

That's because all lines lack a suffix space.

Additionally, with SIMD 16-byte boundaries, further splits can occur if
processing needs to transition to non-SIMD.

Here, I'm trying to just address all of this by:

1. Stitching together adjacent comments. Since a lexed comment starts at
the `//` excluding the indent, the delta from the prior comment must be
precisely the indent.
2. Adding support for switching from SIMD to non-SIMD on file
boundaries.

I considered trying to have a separate `//\n` prefix for SIMD processing
of `// `, but I wasn't sure about the tradeoff of doing both at the same
time (in particular, it'd require constructing a string for the
different prefix), thus this stitch approach. This does mean multiple
passes will be required for a typical long comment structure using blank
comment lines to separate paragraphs (for performance reasons, I will
recommend engineers not write comm... nevermind).

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-10-10 22:25:41 +00:00
9e5e33082c Update instructions for adding a SemIR instruction. (#4348)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2024-10-10 21:57:29 +00:00
Richard Smith 1a1bfd2eb2 Track and resolve the specific callee in a call to a generic function (#4395)
Add a new `specific_function` instruction that represents a generic
function plus its deduced argument list as a callee in a function call.
The new instruction can only appear as the immediate operand of a call
instruction, so we give it a builtin placeholder type.

At the end of each file, require definitions for all specific functions
used in that file. Resolve the generic with the argument list to produce
those specific function definitions as needed, and diagnose if the
generic doesn't have a definition available.

A few tests are updated in cases where they declared and used generic
functions but didn't previously provide a function definition.
2024-10-10 20:52:46 +00:00
Céline Dedaj bb874f21f7 Update conduct team member list (#4394)
deleted @flysand7 from the conduct team member list after they left the
team
2024-10-10 20:02:05 +00:00
Jon Ross-Perkins 0f350255ce Refactor compile-related tests to share construction. (#4396)
Note in particular that this fixes an issue where SharedValueStore had
been shared across files, when they should be per-file. This is only
visible when doing multiple compilations in a single test, which was
rare before.

This also moves these tests into the Testing namespace. My memory of the
various namespacing changes is that we'd generally agreed to have tests
in Testing so that we'd see SemIR:: and similar, same as we would in a
lot of the implementation.
2024-10-10 19:43:31 +00:00
David Blaikie b1014bf9f5 Disallow abstract or base on class declarations (that are not definitions) (#4378)
Per:
[p3762](https://docs.carbon-lang.dev/proposals/p3762.html#modifier-keywords:~:text=Other%20class%2C%20impl%2C%20and%20interface%20modifiers%20%28abstract%2C%20base%2C%20final%29%20exist%20only%20on%20the%20definition%2C%20not%20on%20the%20forward%20declaration):
"Other class, impl, and interface modifiers (`abstract`, `base`,
`final`) exist only on the definition, not on the forward declaration."
2024-10-10 17:41:38 +00:00
Jon Ross-Perkins 1338f9e0ad Add tracking of lexed comments, with skeletal formatting. (#4385)
In order to format comments, it's helpful if they're tracked. This
tracks them separately from tokens in order to avoid interfering with
parse; it'd be inconvenient if comment tokens could show up in arbitrary
locations, albeit possible to support.

This additionally extracts out the TokenIterator support into a template
in order to generally have it available for IndexBase types. I'm only
adding it for CommentInfo, not sure if we'll want it elsewhere, but this
structure still felt like a good fit.
v0.0.0-0.nightly.2024.10.10
2024-10-09 21:05:53 +00:00
Richard Smith efb5d6d25a Assign locations to instructions in a generic eval block. (#4393)
The locations point to the first instruction in the generic that needed
the relevant constant value or type.

For now, this must makes the formatted SemIR a bit more useful, but in
the future it will also provide locations for diagnostics caused by
monomorphization failure.
2024-10-09 19:03:15 +00:00
Céline Dedaj b1366f3e4e Update CoC team members (#4392)
deleted @flysand7 from the conduct team member list, as requested by
@flysand7
2024-10-09 18:48:53 +00:00
Jon Ross-Perkins e9a6b9dfcc Add AUTOUPDATE-SPLIT to help with format tests. (#4384)
Since formatting covers comments, and the CHECK lines are in comments,
it can create recursive behaviors. This introduces AUTOUPDATE-SPLIT as a
way of formally designating a split to exclusively be used for
autoupdate output.
2024-10-09 18:47:03 +00:00
Jon Ross-Perkins 434173b016 Add skeletal format subcommand. (#4383)
This extracts out the SourceBuffer handling of `-` in order to trivially
share it.

Note this still has a number of TODOs, it's just setting up the
essential subcommand infrastructure, with some tests demonstrating that
it at least does something.
2024-10-09 17:33:29 +00:00
Chandler Carruth 33954d1f20 Improve -c dbg, enabling Split DWARF and other enhancements (#4382)
This should substantially reduce the total build size of `-c dbg`
builds, and especially improve cache hits during incremental
development. I'm seeing over 50% reduction total on Linux in just the
raw size of a complete debug build. Even on macOS where we can't use
split DWARF there are substantial reductions.

Note that LLDB and GDB want slightly different flags to have the best
experience with split debug information, and so the build and
documentation have been updated to enable LLDB's flags by default but
provide clear instructions for switching to GDB's flags, and they are
structured so that this can be done persistently for an individual
developer.
2024-10-09 03:58:47 +00:00
Richard Smith 8650f1c173 Remove out-of-date TODO (#4390) v0.0.0-0.nightly.2024.10.09 2024-10-09 01:41:14 +00:00
Richard SmithandJon Ross-Perkins 6410d6e140 Add support for deduction of most kinds of type constant. (#4389)
This adds deduction in all the cases where we can match the instruction
fields of the parameter against the corresponding instruction fields of
the argument. This handles all current type constants except for struct
types, for which we would want to match by field name.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2024-10-09 00:42:53 +00:00
Richard Smith 9fadfb5e82 Basic support for argument deduction in generic impls. (#4380)
Refactor the current function call deduction logic to make it reusable.
Call into it from `impl` deduction. Also build a generic region for the
definition portion of a generic `impl` and substitute into it before
accessing the witness in a specific `impl`.

This is enough to get simple uses of generic `impl`s to work. The main
blocker for more complex cases is that we have very little support for
non-trivial deduction, so while we can deduce `forall [T:! type] T as
I`, we can't deduce `forall [T:! type] C as I(T)` yet.
2024-10-08 22:17:37 +00:00
Richard Smithandjosh11b b274622228 Improve infrastructure for formatting types in diagnostics. (#4374)
Instead of stringifying types in the caller in some cases, add new types
to represent:

- `InstIdAsType`: an `InstId` diagnostic argument that represents a type
expression that should be included in the diagnostic
- `InstIdAsTypeOfExpr`: an `InstId` diagnostic argument that represents
an expression whose type should be included in the diagnostic

For these cases, we can produce more user-friendly descriptions of a
type than we can with a canonicalized `TypeId`. Add comments to
discourage using `TypeId` diagnostic arguments when one of the above can
be used, and move over existing uses where it's straightforward to do
so.

Move type stringification code to its own files and out of `SemIR::File`
to make `File` smaller and to further discourage the direct use of the
stringification logic.

Also update type printing to include the `` ` `` delimiters surrounding
the type. The intent is that we will eventually want to include other
information when formatting a type, like Clang does when printing a
typedef (`'string' (aka 'std::basic_string<char>')`), and such
formatting requires that the diagnostic machinery produces the `` ` ``s
itself.

There are a couple of cases where we really want to format valid Carbon
type syntax directly into a diagnostic, rather than an `aka` or similar,
because the diagnostic text includes part of the type itself, for
example: ``"consider using `partial {0}`"``. For such cases, a `Raw`
form of the diagnostic argument types is added: `TypeIdAsRawType` and
`InstIdAsRawType`. In principle we could instead use ``"consider using
`partial {0:raw}`"``, but our diagnostic machinery isn't set up for
that.

---------

Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
v0.0.0-0.nightly.2024.10.08
2024-10-07 22:55:26 +00:00
Geoff Romer 6439f9065d Handle block scopes in compile-time binding check (#4379)
This fixes a fuzzer-found crash when a compile-time binding occurs
inside a block (which is represented by an invalid inst ID).
2024-10-07 22:53:22 +00:00
Chandler Carruth 284b14981d Fix our default fastbuild Bazel config (#4363)
Causes the default development (`fastbuild`) Bazel build and test to
both use ASan, minimal optimizations, and produce good backtraces with
source locations.

This also fixes all of the non-host configs that were deeply broken for
the latest releases of Bazel going back quite some time.

The intent of our our Bazel toolchain config was for a minimally
optimized, minimal debug info, and ASan + UBSan configuration to be the
`fastbuild`, or the default development build of the project. This
matches its inclusion of asserts, etc.

At some point quite some time ago, all of this stopped working. Bazel no
longer has a `nonhost` feature. This was disabled a long time ago,
briefly argued to be re-enabled, but has persistently been removed.
However, since then the host and non-host features have been separated
including the compilation mode, and so none of that is needed now.
Instead, we can use a much simpler and more principled approach to all
of the feature configuration now which this PR implements.

However, we added TCMalloc _after_ all of the ASan stuff became broken,
and so we never saw that it is fundamentally incompatible with ASan. So
this PR also reworks how TCMalloc is used to only apply to `-c opt`
builds on Linux, and it also explicitly disables it when using
`--config=asan`. I've not found a convenient way to tie the malloc
library choice to a toolchain feature in Bazel, so this relies on the
config being used rather than the feature in isolation.

Last but not least, with this change `fastbuild` creates substantially
larger output and so this change also passes several new flags to reduce
the size costs. One is a general improvement from outlining ASan
instrumentation. The others are in a special feature as they reduce the
error message quality for two of the more expensive UBSan checks in
favor of small generated code size. Keeping these last two separate
allows disabling this locally if needed to debug a failure.
2024-10-07 18:19:49 +00:00
Chandler Carruth 55d8edcdc7 Some trivial check-phase inlining. (#4362)
When profiling, these jumped out as good inline candidates that happened
to be out-of-line, this just moves them inline so that they're
available. I think as much as 10% improvement in check-phase from this,
but I haven't run detailed before/after measurements as these changes
seemed minimally disruptive.

Also switched from `CHECK` to `DCHECK` in one place that seems
especially hot and where the check itself seems reasonable to only do in
debug builds. Left a comment since we rarely need to remove these any
more.
2024-10-07 17:31:22 +00:00
josh11bandJosh L c1b871f361 Add link to video for C++Now variadics talk (#4377)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-07 17:30:32 +00:00
David Blaikie 0b5d1101f9 Remove redundant optional wrapping llvm::function_ref (#4367)
llvm::function_ref (like std::unique_ptr, for instance) already has a
null/empty state, so use that to avoid confusion/duplication of empty
states between optional and the nested function_refs.
2024-10-07 17:25:35 +00:00
Chandler Carruth e38ad83bfd Disable the Bazel disk cache on CI. (#4375)
This should free up quite a bit of space and even make our builds faster
by avoiding duplicating every output. The syntax for this flag is
counter intuitive, so I've left a comment explaining it.
v0.0.0-0.nightly.2024.10.07
2024-10-06 18:02:30 +00:00
josh11bandJosh L 6dbeda612a where check stage, step 3: some type checking (#4364)
With this, we now check:

* The left argument to `where` is a facet type
* The right argument of a rewrite (`=`) requirement converts to the type
of the left argument.
* The left argument of an `impls` requirement is a type and the right
argument is a facet type.

No checking is done for `==` constraints yet.

In addition, make the "is facet type" query into its own function and
fix some comments noticed as part of this change.

This change reveals that accessing the members of a facet, like `.Self`,
isn't doing the right thing, and will have to be fixed in a follow-on
PR. Some tests have been adjusted or disabled as a result.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
v0.0.0-0.nightly.2024.10.06 v0.0.0-0.nightly.2024.10.05
2024-10-05 01:03:43 +00:00
Richard Smith 17411c5e78 Assign a name to interface_type instructions. (#4369)
This matches what we do for `class_type` and `function_type`.
2024-10-04 23:06:24 +00:00
82937e1a3c Change how to get info for a parameter (#4366)
Updates `SemIR::Function::GetParamFromParamRefId` to return more
information in the form of a new `ParamInfo` struct. This struct has a
method for getting the `NameId` from the name binding instruction. The
callers previously got it from the `Param` instruction, but the plan is
for that instruction to no longer be associated with a name.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2024-10-04 16:30:00 +00:00
Richard Smith 568ad197d1 Track the instruction used to name the type and constraint in an impl. (#4368)
This is necessary in order to have access to the specific versions of
their constant values in a generic impl.

Stub out impl deduction.
v0.0.0-0.nightly.2024.10.04
2024-10-04 00:06:55 +00:00
David Blaikie eab5dd6112 Reject abstract function definitions (#4350)
Not sure about error recovery options - can/should we drop the
definition as a means of recovery when building the SemIR? I guess
probably not, so I guess this change is about right.

Phrasing of the error message I'm certainly open to.
2024-10-03 22:50:46 +00:00
josh11bandJosh L 8f547365f5 Increase test timeout to unblock submit (#4365)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-03 21:19:53 +00:00
josh11bandJosh L d6d70bf80d Handle runtime implicit parameters, and self outside of methods (#4361)
Closes #4356, #4359

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-03 20:24:28 +00:00
Geoff Romer e617d64939 Remove parameter-constant arrays from import_ref (#4360)
This makes the code more resilient to changes in the structure of
parameter insts, and could help avoid bugs by making the
ImportRefResolver's data structures the single source of truth.
2024-10-03 19:39:12 +00:00
David Blaikie afbea6a9ec Disallow base virtual in adapter (#4343)
According to
https://docs.carbon-lang.dev/docs/design/generics/details.html#adapting-types:
> You can add any declaration that you could add to a class except for
declarations that would change the representation of the type. This
means you can add methods, functions, interface implementations, and
aliases, but not fields, base classes, or virtual functions. The
specific implementations of virtual functions are part of the type
representation, and so no virtual functions may be overridden in an
adapter either.
So, let's check/reject that.

Checking at the end of the class ensures that no matter the order of
methods and adapt statements, the issue will still be correctly
diagnosed.
v0.0.0-0.nightly.2024.10.03
2024-10-02 18:38:00 +00:00
josh11bandJosh L 49e0c186fc Add comma between the arguments to the bind_symbolic_name instruction (#4358)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
v0.0.0-0.nightly.2024.10.02
2024-10-01 23:58:30 +00:00
josh11bandJosh L 958279c869 Update instructions for running tests (#4357)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
2024-10-01 21:29:40 +00:00