Commit Graph
1785 Commits
Author SHA1 Message Date
mx42andjosh11b 1cab6920f2 Treesitter parser (#2902)
A push towards better editor support.
See utils/treesitter/README.md

---------

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2023-07-13 18:28:28 +00:00
Jon Ross-Perkins 9751b4701d Start node stack push/pop setting IdT based on ParseNodeKind. (#2985)
I think there's more we can do here, but this seemed like a good
checkpoint to make sure the path I'm going down is roughly what you
expected. There's one actual edit in if expression structure to match
the increased enforcement.
2023-07-12 23:26:53 +00:00
Prabhat SachdevaandRichard Smith c0d18a62eb Trace output filtering based on file context (#2916)
To filter based on file contexts, you can use `-trace_file_context=...`
flag along with `--trace_file=...` flag. These are the following options
you can pass to the `-trace_file_context=...` flag (you can also pass
them as list by separating them with comma).
1. `main`: Include trace output for file containing the main function.
2. `prelude`: Include trace output for prelude.
3. `import`: Include trace output for imports.
4. `include`: Include trace output for all.

If the flag isn't used or non of the options are passed, by default only
main file context is traced.

File contexts are distinguished based upon the source location by
passing the source location to `TraceStream::is_enabled(..)` as
arguments. If no arguments are passed, file context is
`FileContext::Unknown` and for now it will add the trace from unknown
file context.

Note: `import` option currently doesn't work as imports aren't supported
yet.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-07-07 22:17:34 +00:00
037196f69f Creates object file from the module. (#2955)
This pr creates the object file for the carbon code that returns either
0 or 1. The command to convert the object code to binary is `clang
<object_file_name> -o <binary_name>`

---------

Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-07-07 22:16:41 +00:00
Richard Smith 123662f5b1 Basic support for non-defining declarations of functions. (#2977)
This doesn't support redeclaration, so there's no way to provide a
definition in Carbon for a forward-declared function yet.
2023-07-07 01:08:02 +00:00
Jon Ross-Perkins 239cdcc457 Finish splitting out semantics_handle.cpp (#2976)
I was running into some difficult merges in #2940, so I'm wanting to
finish splitting this last file to minimize the chance of future issues.
2023-07-06 22:56:36 +00:00
Jon Ross-Perkins bc84f109fe Rename semantics InvalidType to Error (#2975)
Following up on zygoloid's request [on
#2940](https://github.com/carbon-language/carbon-lang/pull/2940#discussion_r1253522564)
2023-07-06 22:30:56 +00:00
ea982ad2c8 Simplified package declaration for the Main package (#2550)
Make the preamble of simple programs more ergonomic, by removing the
`package Main` from the main package and removing the `package`
declaration
entirely from the main source file. Imports within a single package no
longer
need to, and are not permitted to, specify the package name.

Partially covers #2001 / #1136.
Covers #1869.
Supersedes #2265.
Addresses design idea #2323.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2023-07-06 21:55:54 +00:00
josh11bandjonmeow e0e684067a Expression phase terminology (#2964)
Update terminology around expression properties:

-   "value phase" -> "expression phase"
-   "symbolic value" -> "symbolic constant"
-   "constant" -> "template constant"
-   "constant or symbolic value" -> "constant"

Implements the decision in #1391 .

---------

Co-authored-by: jonmeow <jperkins@google.com>
2023-07-06 21:45:09 +00:00
Jon Ross-Perkins 918c089e03 Add namespace support. (#2940)
This handles namespacing of functions. Parsing and semantics are changed
significantly, while lowering works without changes. Variables can't be
namespaced yet because they're dealing with patterns, and I didn't dig
through that code.

Most of the logic is done through the new name declaration stack, which
is necessary because semantics isn't quite sure where the declaration
name ends. It'd be complex for parsing to send a signal about this,
probably involving node variants and rewrites of the tree, and this
solution seems to work well. Unfortunately this means a new stack, but
that may be inevitable due to the extra information needing to be
tracked.

Note this doesn't deal with scoped lookups of non-namespace things,
which we'll need for generics. That'll probably involve pushing resolved
scopes onto a stack (or maybe just setting a singleton value?) to affect
contextual name lookup. But, I think the basics are there to make it
work when we can test the behavior.

This renames "designator expression" to "qualified expression" and adds
"qualified declaration" in order to use terminology more consistent with
C++.

Namespaces will probably need to be considered for name mangling down
the line, but this still uses the basic name.
2023-07-06 20:43:40 +00:00
Jon Ross-Perkins 7d817c857a Remove obsolete TAG arg for devcontainer (#2974)
This shouldn't be used anymore, as of #2186
2023-07-06 18:45:53 +00:00
Adrien Leravatandjonmeow a914932b1c doc: update PR workflow for GH merge queues (#2965)
Co-authored-by: jonmeow <jperkins@google.com>
2023-07-06 18:33:58 +00:00
T.J. Givenandjonmeow c974a77314 Added newline example and clarifications for string_literals.md (#2966)
Updated string_literals.md to mitigate confusion around newline behavior
in the context of block string literals.

Addresses #2887

---------

Co-authored-by: jonmeow <jperkins@google.com>
2023-07-06 18:33:49 +00:00
Lucile Rose Nihlenandjonmeow 11d6de3863 add VSCode user debug settings to git ignore list (#2967)
VSCode uses a `.vscode/launch.json` file for configuring the debugger.
This PR adds a line to the `.gitignore` file to also ignore it along
with the already-ignored `.vscode/settings.json` file.

---------

Co-authored-by: jonmeow <jperkins@google.com>
2023-07-06 18:33:32 +00:00
Jon Ross-Perkins 9c74c5dba4 Narrow example addr pattern to self. (#2970)
Although discussed for other situations, `self` is the only concrete
use-case of `addr`.
2023-07-06 18:30:30 +00:00
Jon Ross-Perkins f4fd12def9 Use paths-filter to fix the test action. (#2972)
Trying to fix merge queue support for PRs that don't need tests, #2971
didn't work because it lacks the matrix configuration. This takes a
different approach from that, instead filtering each step based on
affected paths. This way we're also less likely to see skew in behavior.
2023-07-06 18:08:45 +00:00
Chandler Carruth c75b41bb01 Add a fallback test workflow. (#2971)
To make this cleaner, this switches the main `test` workflow to use
exclusion path patterns as that was the clearly documented intent
anyways.

This works around a problem with required GitHub status checks:
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore

Without something like this, we won't be able to use the merge queue (or
require passing tests).
2023-07-06 15:43:42 +00:00
Richard Smith f992d4d960 Don't return SemanticsFunction by value. (#2968)
It contains a vector, so it's not cheap to copy. Return by const
reference instead.

Thanks to @fasiddique for spotting this!
2023-07-05 22:09:50 +00:00
Prabhat Sachdeva 3c7bca4115 Comma seperated selection of allowed phases for trace (#2963)
For `-trace_phase` flag, makes the selection of multiple phases possible
by separating them by comma.

**Example Usage:**
```
bazel run //explorer -- <program_location> --trace_file=... -trace_phase=source_program,execution
```
2023-06-30 22:06:50 +00:00
Prabhat Sachdeva 45c185ebf7 Add -trace_phase option that takes list of allowed phases (#2962)
## Description
For filtering the trace output, we currently pass flags like
`-trace_type_checking`, `-trace_execution` etc individually and these
can be passed in a combination.
This PR introduces `-trace_phase` flag that takes a list of the
following options:
- `name_resolution`: Include trace output for the name resolution phase.
-   `control_flow_resolution`: Include trace output for the control flow
    resolution phase.
-   `type_checking`: Include trace output for the type checking phase.
- `unformed_variables_resolution`: Include trace output for the unformed
    variables resolution phase.
-   `declarations`: Include trace output for printing declarations.
-   `execution`: Include trace output for program execution.
- `timing`: Include timing logs indicating the time taken by each phase.
-   `all`: Include trace output for all phases. 

### Example usage:
```
bazel run //explorer -- <program_location> --trace_file=... -trace_phase=type_checking,execution,declarations
```
2023-06-29 20:30:45 +00:00
Richard Smith cb16a1ffca Update toolchain keyword list to match design. (#2961)
- `xor` keyword is removed, with `^` used in its place.
- For consistency, also replaced unary `~` with unary `^`, as those
changes come from the same proposal.
- `type` keyword is added.
- To keep existing tests working, parsing support for `type` literal is
added too.
- `is` keyword is removed; we'd already added the `impls` keyword to the
list.
- Several other missing keywords added.
2023-06-29 04:11:00 +00:00
Adrien LeravatandChandler Carruth cb14ce56a8 GitHub merge queue test commit (#2959)
Test change for the merge queue.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-06-29 00:38:59 +00:00
josh11b 798233fe23 Error evaluating symbolic tuple (#2957)
Reports an error (`value of generic binding T is not known`) instead of
performing an invalid cast when attempting to index into a tuple. Can
occur when trying to cast a generic constant in the interface position
of an implementation to `type`.

Closes #2938
2023-06-29 00:37:13 +00:00
Adrien Leravat f091a45c19 Infra: run pre-commit on merge groups (#2960) 2023-06-28 17:21:54 -07:00
Jon Ross-Perkins 7bcfe7df59 LLVM should be included using quotes. (#2952)
This also results in correct dependency discovery (the missing LLVM dep on expression_category).
2023-06-28 15:50:08 -07:00
Manmeet Singh 1646ba1182 update keywords in textmate syntax (#2953)
keywords were taken from docs/design/lexical_conventions/words.md
2023-06-28 15:24:04 -07:00
Richard Smith a5c8cbdbf8 Require a complete type when enumerating the fields of a class. (#2956)
Fixes a crash on invalid found by fuzzing.
2023-06-28 14:56:27 -07:00
Prabhat Sachdeva 2e45dd58f9 Check explorer's full trace output (#2934)
Created `explorer/trace_testdata/full_trace.carbon` to test the whole trace and some changes in `explorer/file_test.cpp` to treat `/trace_testdata/` tests differently.
2023-06-28 10:32:27 -07:00
josh11bandRichard Smith 318eb793eb Explorer: Include self pattern in method type (#2935)
This fixes a bug where Explorer would not detect when:

- an implementation used a method to implement a class function in an interface
- an implementation used a class function to implement a method in an interface
- an implementation method used `addr self` when the interface method did not
- an interface method used `addr self` when the implementation method did not

at type checking time. This would then cause a crash at runtime.

Closes #2857

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-06-28 09:07:01 -07:00
Jon Ross-Perkins 594ebff23b Copy-paste paths since the action isn't running. (#2954) 2023-06-27 15:48:50 -07:00
e8f0866b2f Introduce a new Conduct team (#2922)
The Carbon Project relied on the three leads to handle conduct concerns initially as it bootstrapped its community team and expertise. We now have an active and effective community lead and team of moderators. Our community lead has worked to train and ramp up a new and independent conduct team.

This proposal both provides an overview of the process and hands off conduct handling to the new team! Going forward, we expect routine updates to the conduct team to happen without full proposals as they allow trained folks to rotate in and out of this difficult but essential role on the project.

Last but not least, making these changes uncovered a restriction in the Code of
Conduct itself that we expect to be problematic to adhere to going forward.
While well intentioned, it has a bunch of unanticipated effects that made both
current and new conduct teams want to remove it. A related section has had its
wording strengthened to try and address the underlying motivation at least
partially.

Most of this content comes from @CelineausBerlin with some additions and edits from myself and the other leads as we worked toward building the new CoC team.

Co-authored-by: Céline Dedaj <CelineausBerlin@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Kate Gregory <kate@Gregcons.com>
2023-06-27 15:35:35 -07:00
josh11b 22dd6d1949 Add instructions for viewing speaker notes in conference slides (#2950) 2023-06-27 10:57:00 -07:00
Richard Smith 288ad9f8e5 Split statement-specific parts of semantics_handle.cpp into separate files. (#2949)
`semantics_handle.cpp` is a little on the large side, and is going to grow as we add new nodes. Some of the statement-specific parts have already been split into their own files. Split out the remaining such parts.
2023-06-27 09:26:59 -07:00
Geoff Romer adcb5fb0b5 Set class static type before base class lookup (#2931)
This avoids a crash when a class inherits from itself.

Closes #2929
2023-06-26 17:02:31 -07:00
Jon Ross-Perkins b2084ea15d Shift Parser from 'Identifier' to 'Name' naming (#2947)
This PR renames parse nodes on a Name/NameExpression taxonomy. NameExpressions occur in a name context. The difference is that in non-expression contexts it's useful to return the identifier / string ID for adding to name lookup, whereas in expression contexts it's useful to return the resolved node ID for consistency with other expressions.

In the code, I do note SelfValueName is returned in the expression context: I'd expect this to change, as `self` in `[self: Self]` versus `self.Foo()` will probably be best handled similarly to the above. That means that, in the proposed taxonomy, both `SelfValueName` and `SelfValueNameExpression` will exist in order to assist semantics.

To contrast choices:

Original | Current | [zygoloid suggestion](https://discord.com/channels/655572317891461132/655578254970716160/1121581663399464970) | [This PR](https://discord.com/channels/655572317891461132/655578254970716160/1121814551789318215)
--- | --- | --- | ---
DeclaredName/DesignatedName | Identifier | NameComponent | Name
NameReference | NameReference | NameReference | NameExpression
SelfValueIdentifier | SelfValueIdentifier | SelfValueReference | SelfValueName
SelfTypeIdentifier | SelfTypeIdentiifer | SelfTypeReference | SelfTypeNameExpression
2023-06-26 15:49:57 -07:00
Richard Smith 3a9bc01ec4 Flatten two terminator kind macros into one. (#2948)
As requested in #2942.
2023-06-26 15:44:46 -07:00
Richard Smith 4b69264cb1 Add implied return; at end of non-value-returning functions. (#2942)
Add validation that every code block in a function is terminated by a sequence of terminating instructions, and that terminators don't appear anywhere else in code blocks.

This required tracking whether we're in a reachable code block. That's done on the fly when we create a new code block; the new `SemanticsNodeBlockId::Unreachable` is used to represent the case where we're not actually creating a code block because we're in unreachable code.
2023-06-26 15:17:47 -07:00
Adrien Leravat 92d73985df CI: tentative enabling of tests workflow for merge group (#2933) 2023-06-24 12:08:50 -07:00
Adrien Leravat 19c74ead49 Explorer: Add initial initializing expression support for variable declaration (#2907)
Add partial support for initializing expressions for variable declaration. This is based on https://github.com/carbon-language/carbon-lang/pull/2006, which introduces expression categories, and how it is possible to convert to/from those different categories.

## Functional changes

* Initializing expressions initialize directly the provided storage when used to initialize a variable.
   * Allows initializing expressions to avoid a copy when using `[var|let] name: type = call_expression(...)` by initializing `name` in-place.
   * Support `returned var: ...` and `return <expr>`
   * Support nested initializing expressions

## Main implementation changes

* Updated PatternMatch logic to handle expression categories
* Updated `VariableDefinition` interpreter statement to allocate and pass a location to initializing expressions
    * Update statement actions to allow passing an allocation, used by return expr or returned var
* Modified the RuntimeScope API to be one step closer to the memory model we want to have
    * Remove `GetAllocationId` and older `Bind` which don't apply
* New set of tests to highlight those different situations
    * Added a new intrinsic to print the allocation stack (and make sure we behave correctly, beyond visible side effects)

## Next work

* Dedicated `Action` to retrieve expression category information in the interpreter (https://github.com/carbon-language/carbon-lang/pull/2927)
* Avoid copies when initializing value expression from reference expression and prevent mutations for the duration of the "pinning" (https://github.com/carbon-language/carbon-lang/pull/2927)
* Avoid unnecessary copies from value expression to value expression, after ensuring that even value expression temporaries are registered for destruction.
* Avoid unnecessary copies when binding function arguments
2023-06-23 21:42:00 -07:00
Farzana Ahmed SiddiqueandFarzana Ahmed Siddique aad4ed2083 Codegen: Given a carbon file prints the assembly to the stdout (#2944)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
2023-06-23 15:23:39 -07:00
Richard Smith b908c6e274 Track the list of blocks that form the body of a function. (#2941)
Use that list for lowering in lexical order, instead of rediscovering
the list based on which blocks are referenced as branch targets.
2023-06-23 08:36:13 -07:00
Jon Ross-Perkins 5a90f660b9 Unify DeclaredName and DesignatedName as just Identifier (#2939)
This is just a simplification: I think these different forms are getting in the way more than they're helping, particularly as I was looking into namespace functionality. The handling in semantics can be identical, providing a more uniform behavior.
2023-06-22 16:20:06 -07:00
Jon Ross-Perkins 2e7ce09c34 Explicit 'one or more' for digits in non-decimal integers. (#2936) 2023-06-22 15:55:10 -07:00
0b49ae32de Switched from raw_ostream to pwrite_stream in the driver.cpp (#2937)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-06-22 13:55:46 -07:00
Chandler Carruth abecb25185 Fix a fuzzer-found crash. (#2930)
The crash occurred because of an alias target of a mixin. While
eventually, we should probably have some ability to alias mixins, this
isn't yet setup in the explorer and doesn't seem like a current
priority.

We got here because the mixin type checking made it far enough to not
reject this within the type checker, but the next step wasn't prepared
for this to come out of the type checker. The simplest fix seems to be
to reflect that it *can* escape the type checker, but still isn't (yet)
a valid alias target.

Test case added.
2023-06-20 12:32:58 -07:00
Adrien Leravat 1b50bd156c README.md: Add links to C++Now 2023 talks slides (#2925) 2023-06-20 10:33:51 -07:00
josh11b 78444fa7b1 Remove and rename keywords from toolchain to reflect #2760 (#2921)
- Renames `extends` -> `extend`
- Removes `external`
- Adds `require`

None of these seem to be in use by the parser yet, so no other changes are needed.
2023-06-19 08:37:03 -07:00
Richard Smith 1ea123cd94 Semantics IR building for if statements. (#2920)
This follows the same structure as `if` expressions, except that no
result value is needed.

Semantics IR building for code blocks is also added. Rather than popping
all the node stack entries we push for statements within a code block,
change statements and declarations to not push themselves onto the
stack. We're not notionally performing work recursively within prior
statements, and we don't need their value for anything, so it seems
cleaner to not push them. This also allows statements and declarations
to determine what syntactic context they're in by peeking at the top of
the stack, though that's not used in this patch.
2023-06-16 20:10:33 -07:00
josh11b 2ae8117d62 Update design docs with syntax changes from #2760 (#2866)
This includes:

- Syntax changes from this chart:

| Before                          | After                                   |
| ------------------------------- | --------------------------------------- |
| `class D extends B { ... }`     | `class D { extend base: B; ... }`       |
| `external impl C as Sub;`       | `impl C as Sub;`                        |
| `class C { impl as Sortable; }` | `class C { extend impl as Sortable; }`  |
| `adapter A for C { ... }`       | `class A { adapt C; ... }`              |
| `adapter A extends C { ... }`   | `class A { extend adapt C; ... }`       |
| `interface I { impl as J; }`    | `interface I { require Self impls J; }` |
| `interface I { extends J; }`    | `interface I { extend J; }`             |

- Dropping the syntax for conditionally implemented internal interfaces.

This does not include:

- terminology changes from #2760 ("internal" and "external")
- changes to code, such as explorer, toolchain, language grammars, or other tooling
2023-06-16 14:22:29 -07:00
Jon Ross-Perkins e2b1511a0d Clean up lit tests and config to reflect current uses. (#2913)
Overall, cleaning up remaining lit uses.

#2851 had removed FileCheck invocations from some of the explorer tests; this starts as just restoring that. But, now that we have far fewer `lit` tests, it seems best to refine `lit.cfg.py` to focus on providing fewer commands (not all were even used).

Also, adding testing of an error to explorer (which I noticed due to a change that would've broken that) made me notice that autoupdate_lit_test's for_lit logic didn't actually work, so I'm just cutting it and going to manual updates. Really, we might want to just remove lit autoupdate support altogether since it's only a couple tests using it, but I'm not ready to make that change right now.

Fixes #2912
2023-06-16 11:52:11 -07:00