Commit Graph
1846 Commits
Author SHA1 Message Date
josh11b 916bb4022a Update generics goals doc (#3060)
This reflects changes from #2138 , plus a number of other updates,
including reflecting that we have decided to include templates in
Carbon.
2023-08-05 05:39:34 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique ce459d4da7 Semantics & Lowering for simple assignment. (#3058)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-08-04 20:23:46 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique 3a093980a6 Lowering for tuple indexing. (#3059)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-08-03 21:54:58 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique 64051910c8 Toolchain: Semantics for indexing (#3044)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-08-03 21:09:59 +00:00
c93a0e5e42 Implement canonicalization of Value and Element (#3024)
See arena.h for discussion of what canonicalization means in this
context. This is primarily intended to support implementing a memo table
of template instantiations to resolve #2951, but could be useful for
other purposes as well.

Additional changes:
- Pass `VTable` constructor parameters by pointer, to avoid the need to
define `operator==` and `hash_value` for it.
- Clean up the recurring pattern of allocating identical `NamedElement`s
on the stack and heap. Instead we always allocate it on the heap and
pass it by pointer.
- Add `Print()` and `Dump()` to `Bindings` as a debugging convenience.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-08-03 16:05:59 +00:00
Prabhat Sachdeva 2c4fff25a8 Explorer: add more information to stack trace (#3040)
Adds **action kind** and **source location** for stack trace.
Example:
```
(+) stack-push: <action> (<source location>)
(+) stack-pop:  <action> (<source location>)
```
This PR also updates the `Action::Print(...)` method, following is the
generalized view of `Action::Print(...)`.
```
ActionKind pos: <pos_count> `<related_code>` results: [<collected_results>]  scope: [<scope>]
```
2023-08-03 16:05:37 +00:00
587ab64d1b Update Generics terminology document (#3048)
This reflects changes from a number of approved proposals:
- #920 : concrete statements about orphan and overlap in Carbon
- #2138 : "generic" -> "checked generic", "template" -> "template
generic"
- #2188 : binding patterns are forbidden in type position
- #2360 : "type", "facet type", "facet". Note: I am not using the term
"generic type" from #2360 since that meaning conflicts with the
generally accepted meaning of "generic type" of a type with a
compile-time parameter.
- #2760 / #2770 : internal/external impl -> extending impl
- #2964 : "symbolic constant" and "template constant"

---------

Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-08-02 23:22:15 +00:00
Richard Smith c8b42379a4 Basic semantic checking for pointer types and const-qualified types. (#3038)
Semantic handling for use of `T*` and `const T` as types.

There's no way to form values of these types yet, and no conversions for
them are supported.

Factor out the common code to canonicalize types using a folding set,
and switch to using the same folding set for all kinds of type by adding
the kind as part of the folding set key.

Improve type printing to not include the `as type` portion when the type
is printed in a context within another type where a conversion to `type`
is implied, as in `{}*` and pre-existing cases like `({}, {}) as type`
(which we used to print as `({} as type, {} as type}) as type`.
2023-08-02 23:19:52 +00:00
Samiur KhanandJon Ross-Perkins e448ea5a7c Adds LLVM hardening flag for cc_toolchain libc++ for LLVM >= 17 (#3052)
LLVM 17 replaces ENABLE_ASSERTIONS with ENABLE_HARDEDNING. LLVM 18 is
temporarily warning that ENABLE_ASSERTIONS is deprecated. Since we treat
warnings as errors, this causes build failures for LLVM 18.

This commit can probably be safely removed/undone once LLVM hardening
removes the check
[here](https://github.com/llvm/llvmproject/blob/667602793bef72e64367ac46cbaf96e3afaea22e/libcxx/include/__config#L211).

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-08-02 22:39:28 +00:00
Samiur KhanandJon Ross-Perkins 45ca5bb2c4 Update contribution tools with bazel versioning details (#3053)
You need bazel version 6.0.0 (with --host_per_file_copt) to build
carbon. This adds versioning info and adds that Linux, Mac and Windows
can use bazelisk.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-08-02 22:14:23 +00:00
Jon Ross-Perkins 96517a1ee3 Migrate explorer tests to file_test and remove lit support. (#3050)
This migrates explorer tests to file_test, using the new --autoupdate
functionality. Per discussion, the trace tests that were using "not"
output are mostly migrated to checking full output. The main exception
is tests that were including trace output from the prelude: the prelude
output is pretty long (multiple MB already) and I think it wasn't the
intent to include, only trace output from the small program.

This is the remaining use of lit support, so the supporting libraries
are also removed here.
2023-08-02 21:44:16 +00:00
Jon Ross-Perkins b5167b2d69 Implement autoupdate for file_test. (#3043)
I've migrated the toolchain autoupdate scripts here, I just need a
little more time to do the explorer side (which I need to check
performance, that may require multithreading as we do in the current
script). However, this felt substantial enough to share and it means I
can handle autoupdate in more of the toolchain, including preparatory
work for autoupdate on multi-file tests.

Once explorer is done I'll remove the old script.
2023-08-02 21:32:21 +00:00
Richard Smith 90d2d7ef65 Fix some minor errors in diagnostic text. (#3047) 2023-08-02 18:17:16 +00:00
Richard SmithandJon Ross-Perkins 0c33dead70 Remove the type field from semantics nodes that don't produce values of that type. (#3049)
For `Assign` and `ReturnExpression`, this field wasn't used for
anything. For `StructTypeField`, we stored the type of the field here,
and now store it as an argument of the node instead.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-08-02 17:30:27 +00:00
Richard Smith ab709b4117 Fix crash type-checking member access into an invalid expression. (#3046)
Found by fuzzer.
2023-08-01 21:47:13 +00:00
Geoff Romer f4d45c8d88 Fix newline formatting in stale-issue message (#3045)
YAML string literals don't seem to support escape sequences like `\n`,
so `\n\n\n` was showing up literally in the issue messages.
2023-08-01 19:33:00 +00:00
Jon Ross-Perkins 1dd5caf847 Update re2, absl, and googletest (#3042)
re2 has migrated from StringPiece to absl::string_view since we last
updated. There are also some changes to how string_view is packaged by
absl. As I do test work, I'm noticing these gaps and think an update
would help.
2023-08-01 16:16:49 +00:00
Jon Ross-PerkinsandChandler Carruth eb05f618ce Refactor FileTest construction so that the test class is directly available. (#3035)
This is a simplification of the construction, although somewhat limiting
(it means that the caller can't register the same file multiple times,
though I stopped doing that anyways since it was causing confusion).
What this more importantly _allows_ is logic on the FileTestBase child
itself that's not test-specific -- in particular, autoupdate
functionality which wouldn't use RUN_ALL_TESTS.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-08-01 16:00:29 +00:00
Jon Ross-Perkins ce56226b73 Update pre-commit (#3037)
```
pre-commit autoupdate --freeze && pre-commit run -a
```

Also a manual update of clang-format versions. No format side-effects
changes apparently.
2023-08-01 00:51:16 +00:00
mx42 fe49b1b2a6 treesitter: add more highlight rules (#3036)
follow up to #2902
2023-07-28 19:15:53 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique 6cca85534f Parser for index expression such as a[0] (#3033)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-07-28 18:31:12 +00:00
Jon Ross-Perkins 9e03d5efe2 Change explorer's file_test to support argument passing to main. (#3032)
This shifts explorer's file_test to use ExplorerMain in order to be able
to pass arguments similar to how the command line would. It also means
that various output wrapping done by the command line is shared, no
longer copied by file_test.

In order to help make this work, I plugged vfs::FileSystem into
explorer, similar to how we're doing this on the toolchain side (might
try to share more code later). I was having trouble getting an overlay
working, I think due to how paths are specified -- but due to the issues
in fixing this, I'm just loading the prelude into the InMemoryFilesystem
for now.

Under this approach, I'm unifying more of the file versus string
handling. I think we should shift towards an approach where, like
toolchain code, anyone trying to use Explorer should use a vfs
implementation to supply code. This should reduce the number of distinct
code paths which we're maintaining/testing.

Short-term, this allows the trace testdata to be merged into file_test
with less special casing, using ARGS:. Long-term, it means that the
file_test knows the ARGS to pass to generate checks to match against,
which is the direction I'm planning for autoupdate.
2023-07-28 15:29:51 +00:00
Jon Ross-Perkins 3f24aa28b7 Introduce flag handling into file_test. (#3030)
I'm integrating absl flag support with a few thoughts here...

1. It simplifies the handling of files in file_test.
    - Removes the need for a separate subset target.
3. Looking forward, I'm planning to add a flag to allow for autoupdate
of golden files.
4. In explorer, there's been confusion about having file_test run tests
"twice" so hopefully it's clearer when it's a separate target with a
different flag on the target.
2023-07-27 23:36:21 +00:00
db5e269097 Removed builtin empty tuple type (#3021)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-27 21:17:29 +00:00
josh11b 1006956ed5 Fix class_value_ptr invariant bug found by fuzzer (#3025)
Invariant is `*class_value_ptr == this` when the static type matches the
dynamic type.
2023-07-27 20:39:54 +00:00
mx42 56a011f356 treesitter: implement strings completely (#3007)
follow up to #2902
2023-07-27 20:34:17 +00:00
Jon Ross-Perkins bbf896e165 Convert returned associated constants. (#3029)
Associated constants were getting returned directly, crashing because
the value InterpProgram received was an AssociatedConstant instead of an
IntValue. We have a similar Convert call in ReturnVar, so I _think_ this
is the right approach.
2023-07-26 21:30:28 +00:00
Richard Smith c4b880c6ef Parsing for pointer types and pointer operators. (#3026)
This provides parsing support for the functionality added in #2006.
2023-07-26 21:24:54 +00:00
Prabhat Sachdeva b783197ec6 Explorer: add trace for unformed variable resolution (#3015)
Adds trace information for unformed variables resolution.
2023-07-26 19:03:20 +00:00
Prabhat Sachdeva 459cfc3587 Explorer: add trace for control flow resolution (#3014)
Adds trace for control flow resolution.
2023-07-26 19:02:22 +00:00
Jon Ross-Perkins f088a71cec Add file_test support for specifying arguments and only checking a subset of output. (#3018)
This is sufficient to convert remaining toolchain tests to file_test. %s
and %t are currently used. While #2978 might use %T with lit, I think
that's resolving a lit-specific issue that's not necessary when
TEST_TMPDIR is readily available for any necessary operations (i.e.,
setting the working directory). With ARGS, I think it's feasible to
switch to file_test without %T.

Also adds documentation to file_test_base.h, which was starting to feel
like a significant gap.

This is not yet handled by autoupdate, but I'm eyeing that next.
2023-07-25 22:47:56 +00:00
Richard SmithandJon Ross-Perkins 95b53d33d6 Use precise line numbers in trace test. (#3023)
Don't replace line numbers with offsets from the CHECK line, because
that's both hard to read and unstable when the trace output changes.
Instead, include the actual line numbers. Move all the CHECKs to the end
of the file so that they don't reference lines that appear after them.

This is intended to reduce the number of merge conflicts in
full_trace.carbon and make the test CHECKs more readable.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-25 21:50:37 +00:00
Richard Smith 35ccac5125 Semantics and lowering for type keyword and type values. (#3022)
Also switch from modeling type values as `i1` to modeling them as an
empty struct. We don't need any runtime representation for types, as
there are no runtime operations on them, so an empty struct seems like a
good representation.
2023-07-25 21:49:45 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique 545688e9d4 Lowering for tuple (#3016)
Lowering for tuple with a workaround for typetype. I don't think this
will generate tuple objects with correct values for the typetype issue.

---------

Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-07-25 16:00:17 +00:00
Jon Ross-Perkins 60c9b202f6 Relocate fuzzer files and the explorer_fuzzer rule. (#3017)
Putting fuzzer files under //testing to emphasize the testonly aspect
(consolidates bazel and common subdirectories). The attributes on
explorer_fuzzer are also a little skewed from what's desirable; it's
been working okay, but this should still be a refinement.
2023-07-25 13:27:56 +00:00
Jon Ross-Perkins 1113bda09e Move explorer timing matching out of the shared script. (#3020)
This goes back to my comment at the end of #2934. Rather than
implementing support in the shared script, this only affects one
explorer test so would be better to have in the respective invocation.
It's coming up now because #3018 has me thinking about autoupdate
behaviors again.
2023-07-24 23:59:31 +00:00
Jon Ross-Perkins a7c2885728 Clean up handling of incomplete line locations. (#3011)
Building on #3010, the handling of incomplete lines seems like it can be
straightened out. Doing this separately because it seemed better to
demonstrate tests aren't affected by the change.
2023-07-24 23:17:58 +00:00
Jon Ross-Perkins a3d52b089d Fix missing assignment to me_value found by msan. (#3019)
Looks like a small oversight in #2946. Probably missed because type
access shouldn't really access the me_value.
2023-07-24 22:31:39 +00:00
josh11bandGeoff Romer cf2ddc6072 Temporary restriction that extend base is first in a class to avoid #2994 (#2995)
Closes #2994

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2023-07-24 18:11:40 +00:00
Adrien LeravatandJon Ross-Perkins 9edfa9cad3 Explorer: Avoid unecessary copies when a value binding is created from a value expression (#3000)
#### Functional changes

* Avoid unnecessary copies when a value binding is created from a value
expression in call parameters
* Ensure the result of the value expression bound is destroyed
* Provide storage to initializing expressions used in call parameters

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-24 14:39:13 +00:00
Jon Ross-Perkins 907fa82fc6 Fuzz semantics when it passes parsing without errors. (#3003)
Right now we expect crashes on invalid parses, we just don't try to
handle it in general even though the long-term intent is we should
handle semantics for bad parses. However, in theory, we should be
correctly handling code that parses as valid and that's probably more
interesting to fix bugs for. So this starts trying to fuzz that space of
valid parses.

Fuzzer corpus is based on explorer tests, with one merge run.
2023-07-22 00:03:40 +00:00
Jon Ross-Perkins 65a4e006a2 Add line output to diagnostics to help identify error locations. (#3010)
This also makes the filename a reference to the buffer since the line
seems better to have as a reference (versus copying a string per error).
Most tests now have different line deltas due to the extra output, but
the actual errors should overall stay the same.

Some of the error locations look like they could be improved, but this
change is only making it clear where they were before.
2023-07-21 23:53:36 +00:00
Jon Ross-Perkins 9c4188ab9f Free disk space because we seem to be encroaching on limits. (#3009)
At present, it looks like tools consume 3GB and fastbuild consumes 20GB
versus 23GB available. We've apparently been on the edge of this, and
are just now getting pushed over.


https://github.com/carbon-language/carbon-lang/actions/runs/5625169220/job/15243450729
shows what this looks like (review actions are run from trunk versions,
not this branch).
2023-07-21 23:17:07 +00:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique 6a81a3396e Updated tests for tool chain to incorporate type blocks (#3008)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-07-21 17:36:24 +00:00
Jon Ross-Perkins 0acc62fec0 Clean up unnecessary Carbon:: uses in the node stack. (#3004)
Not sure how I let these creep in.
2023-07-21 15:41:16 +00:00
Prabhat Sachdeva 126d45a1f1 Trace stack and memory only when there is change in state (#2982)
Add state (stack and heap information) to the trace stream only when
there is a change in state, this would prevent consecutive repetition of
state information in the trace output.

Checks it based on change in size of the stack and heap, added
`std::pair<int, int> stack_heap_sizes` in `Interpreter` to store size of
stack and heap for comparison.
2023-07-21 05:02:00 +00:00
Prabhat Sachdeva 418bad939a Add name resolution information to trace stream (#2986)
Adds the following information about name resolution to the trace
output:
* Name resolution process
```
** resolving stmt | decl `<stmt | decl>` (<source_location>)
   ...
** finished resolving stmt | decl `<stmt | decl>` (<source_location>)
```
* When a name is added to the static scope
```
--- declared `<name>` as `<entity>` in `<scope>` (<source_location>)
```
* When a name is resolved
```
--- resolved `<name>` as `<result>` in `<scope>` (<source_location>)
```
* Marking a name declared/usable
```
--- marked `<name>` <usable | declared but not usable> in `<scope>`
```
2023-07-21 01:18:18 +00:00
Jon Ross-Perkins 880b67b012 Clean up uncommented SmallVector size parameters. (#3006)
The lack of comments makes it difficult to be sure, but if any of these
are necessary, I'd like to make sure there are comments to explain why a
specific value was shown (which I do add for diagnostics_ in this
change).
2023-07-21 01:16:46 +00:00
Jon Ross-Perkins c8e02c14ce Consolidate ParseTree onto PrettyStackTraceFunction (#3002)
The function is already in use by semantics, it's intended to be cleaner
than having to write a dedicated printer class.
2023-07-21 01:09:41 +00:00
Jon Ross-Perkins e51f971bce Reduce special-casing of parameters in ParamOrArgSave. (#3001)
I think this is a simpler and more efficient way of achieving the same
end result.
2023-07-21 01:08:33 +00:00