Commit Graph
1027 Commits
Author SHA1 Message Date
Matt Godbolt dab4f56e4e Use the same shell as invoked with for installation. (#1403)
Fixes #1402
2022-07-17 10:16:47 -07:00
Jon Ross-Perkins 142a48e204 rm CODEOWNERS (#1399)
Versus #1367 which approved this in principle, this is the actual removal (I've updated write permissions in GH now).
2022-07-15 18:40:57 -07:00
Jon Ross-Perkins 7d253dc08d Fix assign action in use (#1400)
I accidentally put in one I'd considered, instead of the one I'd decided was probably the best fit, and the names are so similar I didn't notice.

NOTE: This still isn't totally working, but I think it will when we go public.
2022-07-15 17:20:46 -07:00
8dd878b314 Remove CODEOWNERS (#1367)
Remove CODEOWNERS and rely on repository commit access

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Geoff Romer <gromer@google.com>
2022-07-15 15:31:56 -07:00
Jon Ross-Perkins 6c291ba00d Update README/CONTRIBUTING for go-public access rules (#1390) 2022-07-15 15:06:06 -07:00
53053e5959 Design overview update part 7: values (#1378)
This follows #1274 , #1325 , #1328 , #1336 , #1347 , and #1368 . This fills in details about how values work, value categories, parameter passing, unformed state, and so on.

Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-07-15 14:42:39 -07:00
josh11b 9863cb98bb Make C++ import syntax match what we've been using in examples (#1397) 2022-07-15 13:47:37 -07:00
pk19604014 9f90fa3633 Added a patch with a fuzzer Bazel BUILD file and updated fuzz_test rule to use the new @llvm-project//compiler-rt:FuzzerMain
Fixes #1208 (_LIBCPP_DEBUG crash)

Fully bazel-ifying compiler-rt is more complex than I originally thought, due to dependencies on other llvm projects like libcxx which currently also don't have bazel build support -- https://github.com/carbon-language/carbon-lang/issues/1208#issuecomment-1171555971
2022-07-15 09:14:30 -04:00
Richard SmithandJon Ross-Perkins 663ed32b1b Initial support for associated constants (#1376)
Basic support for declaring, specifying the values of, and using associated constants.

This is incomplete in various ways. For example, when checking whether a type satisfies a constraint, there is no check that its associated constants match those in the constraint, and name lookup into a value whose type is an associated constant is not supported yet.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-07-14 18:18:27 -07:00
Geoff Romer 4c90b4928e Update discussion of trace flag in README (#1386) 2022-07-14 16:43:18 -07:00
Céline Dedajandjonmeow 2cdad27d94 Deleted "uncomfortable", left "threatened" (#1389)
Some discomfort is required for us to grow as people as well as a community. Requesting to not make people feel "discomfort" may be weaponized against people seeking help from the CoC team.
So, I deleted "uncomfortable and" from "uncomfortable and threatened". Not making people "threatened" suffices.
Please see this document for more background information: [CLP CoC review July 2022](https://docs.google.com/document/d/1XzHMymzn3hxdlnaI44iukT24fy1MdwTXdebhzT45bCI/edit?usp=sharing)

Co-authored-by: jonmeow <jperkins@google.com>
2022-07-14 14:04:23 -07:00
josh11b eed666f0d4 Fix interface extends syntax (#1383) 2022-07-12 10:14:32 -07:00
josh11b 16f9d82541 Fix binding syntax to be id: Type (#1381) 2022-07-12 10:14:11 -07:00
Hana DusíkováandChandler Carruth e96dbcb7b4 fix: highlight.js didn't properly show comments inside classes (#1380)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-07-12 01:22:35 -07:00
Chandler Carruth b4d4f5423d [highlightjs] Add virtual method keywords. (#1377)
This also tidies up the keyword detection for classes a bit so we won't
highlight bizarre things like `allyourbase class`, or `base classy` etc.
2022-07-10 00:05:51 -07:00
Chandler Carruth 0ed6600615 [highlightjs] Add struct literal support. (#1370)
This is especially tricky, as there doesn't seem to be support for
indirect recursion, only direct recursion. As a consequence, its
important to have a single recursive pattern that handles all the
balanced delimiters in an expression context.

I've tried to add some comments to help explain this.

I also tried to add something to check that the balanced delimiters
*matched* and re-synchronize if they don't, but that didn't end up
working. I also tried various things to force re-synchronizing more
rapidly in the face of unbalanced delimiters but they all produced
strictly worse highlighting than what I have here. I will try again in
a follow-up commit, but for now this will work well enough for slides.
2022-07-09 20:05:38 -07:00
Chandler Carruthandjosh11b e2c5a7ef68 [highlightjs] Add support for var and let. (#1366)
This required reworking how `=` and `;` were handled as well as more
general surgery on patterns.

This looks for initializers at the top level of parameters and at the
end of `var` or `let` declarations. It supports fancy nested `var`
patterns within `let` declarations, etc.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2022-07-09 19:40:09 -07:00
Céline Dedajandjonmeow 22743976a8 Replaced "good intent" with our "learning journey" (#1375)
Asking people to “assume good intent” may be weaponized against people seeking help from the CoC team.
So, I replaced instances in which we mentioned we'd expect "positivity" with the more accurate and less risky "constructivity".
Please see this document for more background information: CLP CoC review July 2022

Co-authored-by: jonmeow <jperkins@google.com>
2022-07-08 15:04:08 -07:00
Céline Dedajandjonmeow c5bca42e73 Replaced "positive" with "constructive" (#1374)
Asking people to be “positive” is preventing us from creating psychological safety in our community. It may be weaponized against people seeking help from the CoC team.
So, I replaced instances in which we mentioned we'd expect "positivity" with the more accurate and less risky "constructivity".
Please see this document for more background information: https://docs.google.com/document/d/1XzHMymzn3hxdlnaI44iukT24fy1MdwTXdebhzT45bCI/edit?usp=sharing

Co-authored-by: jonmeow <jperkins@google.com>
2022-07-08 14:57:01 -07:00
Céline Dedajandjonmeow f0ee96d6f5 Replaced "respectful" with "kind" (#1373)
Asking people to be “respectful” can be considered “tone policing” and may be weaponized against people seeking help from the CoC team.
So, I replaced instances in which we stated that we'd expect "respect" with the more encompassing and less risky "kindness".
Please see this document for more background information: https://docs.google.com/document/d/1XzHMymzn3hxdlnaI44iukT24fy1MdwTXdebhzT45bCI/edit?usp=sharing

Co-authored-by: jonmeow <jperkins@google.com>
2022-07-08 14:56:28 -07:00
Céline Dedaj 5fbbc2ad97 Corrected definition of "doxing" (#1372)
Replaced "Posting, or threatening to post, other people’s personally identifying information ("doxing") without their explicit permission." 
by "Posting, or threatening to post, other people’s personally identifying information without their explicit permission ("doxing")."
2022-07-08 09:20:18 -07:00
Chandler Carruthandjosh11b 1f075a1348 Add a language definition for highlight.js. (#1365)
There are still quite a few parts of the language that need support
here, but I've tried to piece together a decent foundation and address
some of the particular challenges with building a good framework that
handles some of the complex parts of the grammar such as successfully
identifying the declared names in even reasonably complex patterns.

I've included a pretty ad-hoc test file I've been using to make sure it
works. If folks want a particular testing strategy for this, happy to
explore building one although I don't really know what it should look
like.

Also happy to have suggestions about where this should live in the
repository. No strong opinions there. Hoping to eventually add
a `tmLanguage` file and any other syntax highlighting systems that are
useful.

I'll next be finishing off other parts of the language, and then I plan
to use this as a component of our presentation material, which is why
I'm focused on Highlight.js -- that's the system used most widely in
HTML-based presentation infrastructure like Reveal.js.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2022-07-07 23:20:29 -07:00
josh11bandJon Ross-Perkins 77df7c56d9 Design overview update part 6 (#1368)
This follows #1274 , #1325 , #1328 , #1336 , and #1347 . This has miscellaneous changes to the design overview without a particular focus.

Also adds some missing keywords to our list of keywords.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-07-07 22:05:41 -07:00
5535f5ee30 Design overview update part 5: Names (#1347)
This follows #1274 , #1325 , #1328 , and #1336 . It fills in the "Names" section.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-07-06 16:57:25 -07:00
Richard SmithandJon Ross-Perkins 3603db0a08 Give a different diagnostic if a name is used before it's declared. (#1364)
Instead of complaining that the name is not completely declared, say it's not
declared at all yet.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-07-06 14:54:14 -07:00
SlaterLatiao 9106e9239e Initial implementation of returned var. (#1348)
This PR implements the `returned var` for the explorer.
- Enabled `returned var` and `return var` syntax in lexer and parser.
- Split `Return` statement into `ReturnVar` and `ReturnExpression` to distinguish the two types of returns.
- Added logic in name resolution, type checking and interpretation to process `returned var` definition and `ReturnVar` statement.
2022-07-06 13:35:41 -07:00
Jon Ross-Perkins a23f15e901 Refactoring Semantics towards a more instruction-like model (#1349)
This is how I'm interpreting discussion:

- Basic elements are getting set to an ID.
- SetName exists to assign a name (which can then be referred to later with an identifier expression) to an ID.
- Expressions are broken down into a series of operations which operate on IDs.

So with something like the last test:

```
fn Main() { return 12 + 34; }
```

This becomes:

```
Function(%0,
  {IntegerLiteral(%3, 12),
   IntegerLiteral(%2, 34),
   BinaryOperator(%1, +, %3, %2),
   Return(%1),
  })
SetName(`Main`, %0)
```

Note I'm treating blocks as fairly equal to the top of a file now, and basically eliminating boundaries between things. That's because we have discussed also supporting code like:

```
fn Foo() {
  fn Bar() {}
  Bar();
}
```

Here a declaration of a function is occurring inside a code block, so it felt like eliminating the difference was the best choice.

I know you'd commented on the separation of nodes to individual files before; I still think we're going to have a lot of different types of nodes, and so separating them out into individual files makes them easier to browse.
2022-07-06 11:08:47 -07:00
4aa462c2ac Make the Carbon experiment public. (#1363)
This is a proposal to make the Carbon experiment public.

We have not yet hit many of the originally suggested criteria for going
public. However, this proposal suggests that increasingly there is more
value to moving public sooner rather than waiting to hit these criteria.
We are increasingly unable to substantially learn more about the broader
interest in Carbon without it being public and we increasingly see value
in working with the industry to build and shape the language.

Given this, the proposal removes the old plan-of-record and suggests
a concrete set of steps to make the experiment public in the immediate
future.

This is not a change that we can make lightly to the project, and so we
worked to check with as many folks as we could first and all three
leads were unanimous to move forward here.

Note that this proposal was originally discussed in PR #1315.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-07-01 18:11:40 -07:00
Richard Smith 75d10e326f Make the names of declarations unusable before the point where their type is known. (#1352)
Following #875, diagnose any use of a name prior to the point where it is introduced and its type is known.

This works by performing name resolution on a top-level class, interface, or impl twice: the first pass performs name-resolution for everything other than nested function bodies, and the second pass performs name resolution on function bodies. At the moment, the second pass does a superset of the work done by the first pass, and as a consequence, some identifier expressions now have their target set twice to the same thing.
2022-07-01 16:49:51 -07:00
pk19604014 98f4bb3110 Changed fuzzer_util_test to not process the full fuzzer corpus, but instead just run on a single file, to minimize friction when making fuzzer proto changes (#1354)
At least one successful parse is still required for the test to pass.
2022-06-30 14:45:36 -04:00
Chandler Carruth b8ebea81ef Update LLVM. (#1353)
This gets us into 2022-06-29 commits.

Originally @JonMeow was doing this, and we paired to resolve a bug in
our Bazel configs that landed in #1350 so now we can pull it.

Sending this out now so that CI can do the slow run and start caching
build artifacts.
2022-06-30 08:58:42 -07:00
Jon Ross-Perkins 8adcf8b5dd rm update_llvm.sh (it's legacy) (#1351) 2022-06-29 16:47:40 -07:00
Chandler Carruth d7a79ca7fd Fix missing actions in our Bazel toolchain. (#1350)
There were compile actions that should use `clang` that we didn't
include because they aren't *technically* C compile actions. For our
toolchain though, we treat them as such, so create a list of actions
that we compile equivalently to C, and use that to set it up.

This will fix a problem with top-of-tree LLVM where we need to handle
preprocessed assembly files.
2022-06-29 16:46:11 -07:00
df345b5ec7 Remove LLVM from the repo, and clean up history. (#1344)
This proposal establishes a plan for moving away from the embedded copy
of LLVM and instead downloading it with Bazel.

The goal is that after this lands, we will do a history-rewrite to
cleanup the repository. There are instructions on how folks can move any
in-flight work over to the newly tidied repo.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2022-06-28 13:49:38 -07:00
Jon Ross-Perkins b626cb9c64 Run brew install on all platforms, and stop searching for clang-format (#1346)
This was noticed because macos stopped installing the brew llvm, and they don't have clang-format. However, our tests don't actually need clang-format (and even if they did, we should probably match the pre-commit version), so it seems superfluous to check for.

Keeping brew because there's an advantage to consistency on tool versions, just running it on all platforms instead of linux-only.
2022-06-28 13:09:24 -07:00
fbf353afe8 Design overview update part 4: C and C++ Interop (#1336)
This follows #1274 , #1325 , and #1328 . It fills in the "Bidirectional interoperability with C and C++" section.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2022-06-27 17:20:24 -07:00
Richard Smith 9ea405788e Combine most ast/ build targets into one. (#1334)
We fundamentally have cyclic references between declarations,
statements, expressions, and patterns, and there's no meaningful
layering between them. Combine them into a single build target.

Components such as paren_contents, static_scope, and library_name that
are defined without reference to specific AST nodes are kept as separate
BUILD targets.
2022-06-27 16:55:42 -07:00
Chandler Carruth 282bac207e Switch back to std::abort() in CARBON_CHECK. (#1341)
This is a variation on #1339 and also fixes #1338.

The important difference from #1339 is that this works to retain the
benefits of #1216 which seem important -- both the clarity of printing
the message last and the correctness of actually showing the correct
line number in the backtrace.

The approach in this patch is to disable LLVM's error handling just
before using `std::abort()`. This should give us roughly the best of
both worlds.

This PR also fixes an issue where we wouldn't run the file-cleanup
actions that the LLVM `std::abort()` handler does. This almost certainly
doesn't yet matter, but likely would in the future.

We should separately consider adding back information about filing bugs
that roughly corresponds to the error message that LLVM itself prints.
I've not tried to replicate that from #1339 here and just focused on
getting to `std::abort()` while preserving the desired order of messages
and stack trace locations.
2022-06-24 23:51:30 -07:00
Jon Ross-Perkins 6dd08d09ac Add workaround for StatementBlock declaration circularity (#1342)
This won't be visible everywhere, but I think something's needed -- this workaround is temporary while I work on a bigger change to semantics.
2022-06-23 15:28:50 -07:00
8d0f3364d8 Initial implementation of raw string literals (#1304)
* test cases for raw string literals

* raw string literal implementation

* match as block string if starting with triple ", and better error message for simple string

except for *#"""#*

* fix broken test case

block string  literal cannot be one line

* test cases for raw string literals

* raw string literal implementation

* match as block string if starting with triple ", and better error message for simple string

except for *#"""#*

* fix broken test case

block string  literal cannot be one line

* removed unused initial value

* rename flag to indicate multi-line string and remove comment

* use * to get value from std::optional

* clean-ups

* removed skip_scan flag and directly return in case of a single line string starting with #+\'\'\'

* Updated error message: simple string -> single-line string.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Updated test cases according to changes in error message

* Removed counting_hashtag flag.

* Implemented ScanHelper class to handle scanning

* Fixed explanation of ReadHashTags.

* Addressed PR comment.

* Clarify that scan_helper holds the source text.

* Addressed PR comments.

* Updated error messages in test cases.

* Added const keyword to return type of GetCurrentStr().

* addressed PR comments.

1. Moved ScanHelper class to lex_scan_helper.h and lex_scan_helper.cpp.
2. Moved ReadHashTags and Process* functions to lex_scan_helper.cpp. Moved YY_USER_ACTION, SIMPLE_TOKEN and ARG_TOKEN to lex_helper.h. Added a wrapper function YyinputWrapper to call static function yyinput in lexer.lpp.
3. Renamed ScanHelper with StringLexHelper.
4. Modified BUILD accordingly.
5. Renamed data members and functions.

* Addressed PR comments.

1. Adjusted order to keep ret usage close.
2. Used resize to construct the string to avoid creation of temp string.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Removed the multi_line flag and skip_read field to improve readability.

* Copied default parameter value to definition of UnescapeStringLiteral.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Copied default parameter value to definition of ParseBlockStringLiteral.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Prefix CARBON_ to SIMPLE_TOKEN and ARG_TOKEN macros.

* Rollback redefinition of arguments.

* Updated comment on the flex macro.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Updated wording.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Moved the EOF error out of the loop.

* Removed duplicated declaration.

* Changed type of `hashtag_num` and `leading_quotes` to int.

* Minor fix: string copy.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Added comment on YyinputWrapper.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Garmmar in comment.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

* Added check of eof before readling next char.

* Minor updates based on PR comments.

* Minor changes to address PR comments.

* Used a clearer way to calculate `hashtag_num` and `leading_quotes`. Switched back to indicate muti-line string with a flag.

* Directly copy StringRef for compilation error message.

* Make str_with_quote const as we don't change it.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Added TODO for unsupported cases.

* Fixed a typo.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-06-22 15:38:47 -07:00
Richard Smith a1be2a8a38 Track the arguments and witnesses on values indirectly. (#1335)
This avoids the need to make copies of potentially large maps when
the same bindings are used in multiple values, such as when forming
a bound method value.
2022-06-21 08:48:48 -07:00
Chandler Carruth 8705e29d9f Workaround LLVM compiler bug when fuzzing. (#1340)
Fixes #1173

There is a long standing crash in the LLVM code generator that we manage
to hit when fuzzing. Disable the fast instruction selector in the
fuzzing config to avoid it. I reduced a test case and filed the LLVM bug
here: https://github.com/llvm/llvm-project/issues/56133
2022-06-21 08:41:58 -07:00
Richard Smith d1c8496858 Evaluate the type prior to the . in Type.member accesses (#1337)
Per the design of member access, evaluate the first operand of `.` if it's a type in order to find which type it is, and perform the lookup there.

This allows us to handle the case where the first operand is of type `Type` rather than a more specific type, but can still be evaluated to some specific type value while type-checking.
2022-06-17 16:04:24 -07:00
Richard Smith 17ee3ed9b7 Track a resolved Member on each member access expression. (#1333)
Type checking now stores information on a member access identifying the member that was accessed, not only its name. This parallels what we do for other similar constructs whose meaning is resolved by name lookup or type-checking, and will allow us to avoid redoing lookups in some cases during interpretation.
2022-06-16 17:22:31 -07:00
Jon Ross-Perkins 4113ec8a67 Semantics (#1213)
Working on toolchain semantics:

- SemanticsIR is set up as a container for the semantic tree.
- SemanticsIRFactory builds the tree, with separate transformations for each ParseNodeKind.
- ParseSubtreeConsumer is a helper for transforming a ParseTree::Node's children, managing size/nodes to prevent errors.
- The nodes subdirectory contains SemanticIR nodes.
- MetaNode is used to represent nodes which have "sub-classes": Statements, Declarations, and Expressions.
- MetaNodeBlock is used to represent nodes which exist together in a block with name lookup: Statements and Declarations (not Expressions).

This is traversing children first in order to address the RPO format of ParseTree. This means that when lists are formed, they're reversed to be in code-order (`FixReverseOrdering`).

This is still very much incomplete -- the main intent at present is to demonstrate structure.
2022-06-15 12:40:07 -07:00
Richard Smith 9512a9fcc1 Support implementing a non-interface constraint. (#1329)
This works by splitting the constraint up into interfaces and checking
that each of them is implemented in turn.

Also check that the parameters of the impl are deducible from each of
the resulting (type, interface) pairs.
2022-06-15 09:50:02 -07:00
Richard Smith 2fef76e58c Basic support for .Self within :! bindings and where expressions. (#1311)
`.Self` is modeled as a new kind of expression, `DotSelfExpression`. Name resolution associates each occurrence of a `DotSelfExpression` with a generic binding, much like for an `IdentifierExpression`.

Both `:!` bindings and `where` expressions bring `.Self` into scope. The tentative intent is that if there are multiple `.Self`s in scope and they refer to different bindings, the result of using a `.Self` expression is an ambiguity error, but that is not implemented in this patch. Instead, like for `IdentifierExpression`s, we find the innermost enclosing definition of `.Self`.

`.Foo` expressions are rewritten to `.Self.Foo`, but this isn't enough to make them do anything useful, because associated constants aren't supported in general yet.
2022-06-14 21:49:01 -07:00
josh11b b83f5c3fc7 Generics: impl forall (#1327)
Implement the decision in #1192 to use this syntax for parameterized impls:

> `impl forall [`_generic parameters_`]` _type_ `as` _constraint_ ...
2022-06-14 19:35:53 -07:00
josh11bandChandler Carruth d37dfd2fb8 Design overview update part 3: Safety (#1328)
This follows #1274 and #1325 and fills in the "safety" section. It only covers our approach in general terms.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-06-14 13:22:22 -07:00
Richard Smith 392182cee1 Check for a symbolic value only if normal value lookup fails. (#1326)
This causes compile-time evaluation to give the same result as runtime
evaluation wherever possible. In particular, referencing a generic
parameter at compile time will resolve to the actual value if we're
evaluating a call to the enclosing function so a value for the
parameter is available in the call frame.

Clean up recently-added support for `SymbolicWitness`es using this.
2022-06-13 14:41:19 -07:00