Commit Graph
929 Commits
Author SHA1 Message Date
Jon Meow 20728dbd3a CARBON_ header guards (#1261)
This modifies scripts/check_header_guards.py to add the CARBON_ prefix; everything else is pre-commit.
2022-05-12 17:25:43 -07:00
Jon Meow 3825f97e43 Add automatic header guard checks/fixes (#1260)
My intent is to add CARBON_ bas a prefix, and this makes that easier by creating a tool for auto-fixing guards in general.

string_literal is a manual fix -- it had no guard and I didn't automate that (technically I think I could, especially by enforcing the file header/footer, but it didn't feel quite worth it to me).
2022-05-12 15:54:45 -07:00
Richard Smith 27c8d1fc12 Support explicit generic parameters in function parameter lists (#1259) 2022-05-12 12:39:51 -07:00
Jon MeowandChandler Carruth 451004a44e Fix buildifier file regex (#1254)
Previous form didn't include *.BUILD or *.bzl files by acceident -- this new form is simpler and more correct, with no issues detected.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-05-12 08:58:54 -07:00
Richard SmithandJon Meow c29f56e667 Initial support for generic parameters that are introduced in a function parameter list (#1247)
In order for this to work, we need to always use the argument deduction code path for function calls, instead of only using it when there is a `[...]` list, which means that argument deduction now needs to support implicit conversion.

Co-authored-by: Jon Meow <jperkins@google.com>
2022-05-12 08:48:19 -07:00
Jon Meow b27aa21a88 Update tools (#1252) 2022-05-11 17:23:01 -07:00
Jon Meow 9619533519 Automate naming of fuzzer files (#1250)
We use sha1 right now, this just automates consistency.
2022-05-11 16:32:06 -07:00
pk19604014 589930b703 Fix for a crash caused by choice alternative name being the same as choice name (#1243)
Fixes #1248

Changed resolve names logic to add choice name to name resolution after choice's alternatives are added.
2022-05-11 11:03:19 -07:00
pk19604014 aea04209ee Added a few files to explorer fuzzer corpus (top files by size after converting from explorer test_data sources) (#1236)
Generated with:

$ bazel build explorer/fuzzing:fuzzverter
$ cd explorer/testdata/

$ find . -name "*.carbon" | while read t; do mkdir -p "/tmp/fuzzer_corpus/$(dirname $t)" && ../../bazel-bin/explorer/fuzzing/fuzzverter --mode carbon_to_proto --input $t --output "/tmp/fuzzer_corpus/$(dirname $t)/$(basename $t .carbon).textproto" ; done

$ du -ah /tmp/fuzzer_corpus/ | grep -v fail_ | grep textproto | sort -rh | head -32 | cut -f 2 | while read t; do cp $t ../fuzzing/fuzzer_corpus/`shasum $t | cut -d ' ' -f1`.textproto; done

Tested:
$ bazel test -k explorer/...
2022-05-11 10:07:47 -07:00
Richard Smith dbe535b719 Improve diagnostic for call to non-function. (#1245) 2022-05-10 16:06:15 -07:00
Richard Smith 0996b203fb Make update_checks.py treat RUNTIME ERROR lines as containing a line number too. (#1246)
Move the corresponding CHECK lines adjacent to their referenced line and use `[[@LINE+n]]`.
2022-05-10 16:05:15 -07:00
Jon Meow 553ee84fdb Recommend GH MD preview for mermaid support (#1240) 2022-05-09 17:25:44 -07:00
Jon Meow 9fe7474cb9 pre-commit autoupdate --freeze (#1241)
Mainly running this now because I should've done this for the mypy rev, but letting it update in general.
2022-05-09 17:24:54 -07:00
Jon Meow 24bea76c3e Move mypy config to setup.cfg (#1239) 2022-05-09 15:53:02 -07:00
Jon Meow 7ef7d7aecc Fix pre-commit scoping of proposals/scripts, comment exclusions (#1238) 2022-05-09 13:23:33 -07:00
Jon Meow 51775e9374 Clean up gen_rtti type information. (#1237) 2022-05-09 12:17:00 -07:00
Jon Meow 107848e30f Switch mypy approach to pre-commit (#1234)
I'm treating my PR to mypy bazel integration as dead in the water. Abandoning that approach, this seems to work reasonably well as a replacement. It's actually a slightly newer version of mypy too -- the bazel integration was stuck on an old version.

Note I don't think we're losing much: we shouldn't be writing too much python.
2022-05-09 09:54:12 -07:00
Richard Smith d2b33a712f Fix missing backtick (#1235) 2022-05-06 20:56:16 -07:00
Jon Meow af694b97cb Prefix most macro names with CARBON_ (#1232)
I'm doing this to avoid macro name conflicts, following https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros: "If you do export a macro from a header, it must have a globally unique name. To achieve this, it must be named with a prefix consisting of your project's namespace name (but upper case)."

Commands run:

```
sed -i 's/\(DCHECK\|CHECK\|FATAL\|MAKE_UNIQUE_NAME\|MAKE_UNIQUE_NAME_IMPL\|RAW_EXITING_STREAM\|RETURN_IF_ERROR\|RETURN_IF_ERROR_IMPL\|ASSIGN_OR_RETURN\|ASSIGN_OR_RETURN_IMPL\|DIAGNOSTIC_KIND\|RETURN_IF_STACK_LIMITED\)(/CARBON_\1(/g' $(git ls-files *.cpp *.h *.lpp *.ypp *.def ':!third_party')
sed -i 's/#undef DIAGNOSTIC_KIND/#undef CARBON_DIAGNOSTIC_KIND/' toolchain/diagnostics/diagnostic_registry.def
```

Note this isn't *quite* everything, but it's intended to be a large pass at everything:

```
╚╡git grep '#define ' *.cpp *.h *.lpp *.ypp *.def ':!third_party' | grep -v '#define CARBON' | grep -v _H_
explorer/syntax/lexer.lpp:  #define YY_USER_ACTION                                             \
explorer/syntax/lexer.lpp:  #define SIMPLE_TOKEN(name) \
explorer/syntax/lexer.lpp:  #define ARG_TOKEN(name, arg) \
explorer/syntax/parse_and_lex_context.h:#define YY_DECL                                                         \
migrate_cpp/cpp_refactoring/var_decl.cpp:#define ABSTRACT_TYPE(Class, Base)
migrate_cpp/cpp_refactoring/var_decl.cpp:#define TYPE(Class, Base)     \
```

We may in particular want to do a pass to clean up #ifdef guards and make them be CARBON_ rooted.
2022-05-06 15:30:25 -07:00
Richard SmithandChandler Carruth c4fecf720f Bitwise operators (#1191)
Add bitwise and bit-shift operators `&`, `|`, `^`, `<<`, `>>`. Replace C++ `~` with unary prefix `^`.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-05-06 14:26:55 -07:00
josh11bandJon Meow 0a93289706 Add support for Self and impl as (#1194)
- Makes `Self` a keyword
- Inside `class Foo { `... `}`, `Self` means `Foo`
- Inside `class Foo(T:! Type, U:! Type) {` ...` }`, `Self` means `Foo(T, U)`
- `impl as Bar` means `impl Self as Bar`
- Inside `external impl Foo as Bar {`...`}`, not in a scope already defining `Self`, `Self` means `Foo`

Implemented by introducing a new kind of declaration, a `SelfDeclaration`, that is automatically added to class and impl declarations.

Co-authored-by: Jon Meow <jperkins@google.com>
2022-05-05 18:23:13 -07:00
Jon Meow 3b8d4a4910 Adjust test to work in more environments. (#1231)
The current test is really testing too closely to bazel internals.
2022-05-05 17:16:56 -07:00
josh11bandRichard Smith 125224ab08 Generic details 10: interface-implemented requirements (#1088)
This proposal:

- Adds support for interfaces requiring other types than `Self` to implement interfaces, as in:
  ```
  interface IntLike {
    impl i32 as As(Self);
    // ...
  }
  ```
- Defines requirements on how to satisfy those requirements that have a `where` clause.
- Extends `observe` declarations to include saying a type implements an interface, so code can provide a proof instead of the compiler having to perform a recursive search.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-05-05 15:30:40 -07:00
josh11b ccd5545ebf Fix "and" vs. "add" typo in fuzzing README (#1228) 2022-05-05 14:31:19 -07:00
Richard Smith a2176e1e28 Use a separate type for a parameterized entity name that is waiting for its arguments to arrive. (#1223)
Previously we modeled these as being class types or interface types, with special case checks to treat them as not actually being class or interface types.
2022-05-05 14:30:18 -07:00
pk19604014 56604322f0 Added docs for incorporating AST changes into fuzzer logic (#1221) 2022-05-05 16:42:10 -04:00
Jon MeowandGeoff Romer cc9bebb1d0 Minor carbon-explorer edit to roadmap (#1225)
A rephrasing was suggested on https://github.com/carbon-language/carbon-lang/pull/1188#discussion_r851416370 because "explorer" alone could be hard to parse; I'm suggesting just replacing with "Carbon explorer" to get precision without changing phrasing, as well as rephrasing "Executable semantic" as "Carbon explorer" (which... the former *may* have meant "executable semantics", but the difference in pluralization made it vague, so I'm not sure this is right -- but it also didn't explain _where_, so "executable semantics" seems the right reading)

Co-authored-by: Geoff Romer <gromer@google.com>
2022-05-04 16:12:26 -07:00
e18675608b Reviewer-merged PRs (#1190)
Encourage reviewers to merge when they feel okay doing so. Let reviewers make
that choice. Let authors say they'll merge themselves.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-05-04 13:12:18 -07:00
Richard Smith b87d04bf9b Remove executable_semantics files that were accidentally re-created (#1227)
Remove files accidentally duplicated in e85f45de10 between explorer/ and
executable_semantics/. Each removed file already has a corresponding file in explorer/.
2022-05-04 12:39:12 -07:00
Richard SmithandJon Meow e85f45de10 Move CHECK lines in tests next to the line that caused the output. (#1224)
Use FileCheck's `[[@LINE+n]]` mechanism to refer to the next line.

This is made awkward by a couple of things:

* We want to keep the `CHECK` lines in the original order.
* Errors are sometimes more than one line long.

The approach we use is to interleave the original lines and the check lines, putting each check line as early as possible subject to two rules:

1) Check lines never precede the 'AUTOUPDATE' line
2) Except when required by rule (1), a check line that refers to a source line by line number is never placed earlier than a source line that precedes that source line.

The actual `[[@LINE+n]]` annotations are created in a second pass after we've interleaved the lines so that we can work out the correct offsets.

Co-authored-by: Jon Meow <jperkins@google.com>
2022-05-03 15:48:56 -07:00
Richard SmithandChandler Carruth 4a8ca9cd0f Rework operator interfaces (#1178)
Add concrete design for interfaces for comparison.

Rename interfaces for arithmetic following current thinking in #1058.

Update rules for mixed-type comparisons for data classes following #710.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-05-03 15:37:45 -07:00
Jon MeowandChandler Carruth f42ca044cb Rephrase arguments around data versus emotional. (#1212)
Right now, the text is disallowing appeals to logic (which are persuasive methods, per the linked wikipedia article). Consensus seems to be that this is unintentional.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-05-02 08:25:26 -07:00
pk19604014 150057f260 Added GetRunfilesFile() to be able to reliably determine prelude location under various invocation scenarios
The logic is using bazel Runfiles API per Jon's suggestion.

One of the scenarios used by the fuzzing framework is to place the binary and its runfiles into a folder, resulting in a directory layout like this:

[temp dir]
fuzzer
fuzzer.runfiles/

Tested:
bazel test -c opt explorer/fuzzing:explorer_fuzzer
bazel build -c opt explorer/fuzzing:explorer_fuzzer + run the binary from various locations
2022-05-02 10:36:21 -04:00
Jon Meow 309ec35f95 Rename executable_semantics to explorer (#1188)
Change generated with:

```
#!/usr/bin/bash -eux

# Helper script for renaming pending work.
# Run from the repo root.

# Rename executable_semantics in code.
sed -i 's/executable_semantics/explorer/g' \
  $(git grep -l 'executable_semantics' . | grep -v proposals)
sed -i 's/executable semantics/explorer/g' \
  $(git grep -l 'executable semantics' . | grep -v proposals)
sed -i 's/Executable semantics/Explorer/g' \
  $(git grep -l 'Executable semantics' . |  grep -v proposals)
sed -i 's/Executable Semantics/Explorer/g' \
  $(git grep -l 'Executable Semantics' . |  grep -v proposals)
sed -i 's/EXECUTABLE_SEMANTICS/EXPLORER/g' \
  $(git grep -l 'EXECUTABLE_SEMANTICS' . | grep -v proposals)
sed -i 's/ExecutableSemantics/Explorer/g' \
  $(git grep -l 'ExecutableSemantics' . | grep -v proposals)
sed -i 's/executable-semantics/explorer/g' \
  $(git grep -l 'executable-semantics' . | grep -v proposals)

# This is only needed for the initial move.
mv executable_semantics explorer
mv explorer/fuzzing/executable_semantics_fuzzer.cpp explorer/fuzzing/explorer_fuzzer.cpp
```

Verified with `bazel test ...`
2022-04-29 13:20:25 -07:00
Richard Smith 3b58a1bf48 Basic support for parameterized interfaces. (#1220)
To make this work, introduce impl bindings into scope immediately when type-checking. We may rely on their existence before we finish type-checking the enclosing pattern.
2022-04-29 12:42:15 -07:00
josh11bandRichard Smith b9538129a2 Generic details 12: parameterized types (#1146)
This proposal has three main contributions:
- Types with generic parameters have an identity that consists of the types names plus the values of those parameters.
- The parameters of a type may be deduced from a function's argument.
- Types with generic parameters do not support specialization. Instead, a type can delegate to an interface to opt in to allowing specific customization points.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-04-28 16:16:00 -07:00
62c8821f20 Rewrite example for span/Slice. (#1203)
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-04-27 12:43:55 -07:00
josh11bandRichard Smith d7a90609cc Update docs/ READMEs (#1211)
With a focus on making each README a good representation for its directory, and adding links.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-04-27 12:07:53 -07:00
pk19604014 9ec2a0bb98 Added googletest deps removed in #1215 as the deps are still required in strict headers mode for the googletest.h include (#1218) 2022-04-27 13:25:57 -04:00
pk19604014 85080fe49a added missing text_format dep (#1214) 2022-04-27 12:35:45 -04:00
Jon Meow 8dee661adb Move CHECK stack traces to be before the message (#1216)
Before, if the llvm hook to print a stack trace on CHECK was bound, it would trace after the message rather than before the message. I'm thinking swapping the order will generally be easier to debug.
2022-04-27 09:17:23 -07:00
Jeremy G. Siek 0e061d1c24 add check for double instantiation of a generic class (#1217) 2022-04-27 11:23:08 -04:00
Jon MeowandChandler Carruth d3700d5cd0 Changes tests to init LLVM stack tracing (#1215)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-04-26 16:19:51 -07:00
Jon Meow 6013424b87 Iterate on the readme bumper. (#1202) 2022-04-25 13:49:06 -07:00
Jeremy G. Siek adf1a85ee9 Fix IsConcreteType for generic classes and add IsType predicate. (#1204)
* check that the return type is a type, add more implicit conversions

* update IsConcreteType for generic classes, add IsType predicate

* delete a comment

* trivial change

* move Witness wrt IsConcreteType and IsType

* added comments to tests

* update error line numbers
2022-04-25 16:25:22 -04:00
pk19604014 0230ebdf38 Removed erroneously added file. (#1210) 2022-04-25 16:00:49 -04:00
pk19604014 0b4e9b5ecb Split executable semantics fuzzer into cc_binary and cc_test
This is a workaround for #1208, allowing to remove manual tag to allow building and testing fuzzer code during precommits and in bazel test ...

Tested:
bazel test -k ...
bazel build -c opt executable_semantics/fuzzing:executable_semantics_fuzzer
bazel-bin/executable_semantics/fuzzing/executable_semantics_fuzzer
2022-04-25 15:35:12 -04:00
Jon Meow 9356a847d7 Fix nullptr -> nullopt (#1201)
Error in #1193, I should have tested more.
2022-04-22 09:29:12 -07:00
josh11b 6a9625216d Test for mismatch in generic class argument list (#1195)
Diagnostic added for this case in #1200
2022-04-22 08:17:22 -07:00
josh11b 663d67b316 More testdata formatting fixes (#1199) 2022-04-20 11:53:45 -07:00