Commit Graph
1548 Commits
Author SHA1 Message Date
Adrien LeravatandChandler Carruth 49726cd89e doc: add / refresh information regarding contributions (#2611)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-02-27 17:38:52 -08:00
Calvin a57c3d9801 Fix string literal parsing escaped whitespace (#2617)
The toolchain misinterprets escaped whitespace characters as unescaped when trimming trailing whitespace on a line. This PR adds a variable to track the length of the string after escaping the most recent escape, making sure we don't backup past that character, whatever it is.

I did try the approach mentioned in #2132 of not backing up `end_of_regular_text` number of characters, but this caused problems on lines like <kbd>tab</kbd> <kbd>space</kbd> <kbd>tab</kbd> (those characters literally, not escaped) where it would leave the first tab since that is processed in a different iteration of that loop.

I added a test case for this bug. I kept getting mixed up in the test output which one was the expected value, so I also changed a variable name there for clarity.

Fixes #2132.
2023-02-27 16:05:34 -08:00
Jon Ross-Perkins c7aff0a2a9 Fix quotes in multi-line string syntax (#2638)
This was pointed out by i-khadra on #2132
2023-02-27 14:17:04 -08:00
Adrien Leravat 09891d4141 Explorer: drop outdated TODO comment. (#2639)
Drop TODO as discussed in https://discord.com/channels/655572317891461132/763516049710120960/1079844131737714718
2023-02-27 13:30:04 -08:00
Jon Ross-Perkins e4487505dd Update clang-tidy details for the toolchain (#2623)
Adjusts handling of class constants (`static const`) to use CamelCase. This probably better reflects how we use it in C++ code, treating as appropriate for CamelCase instead of under_score.

Fixes adding_children to be preorder in caller (not sure why this wasn't automated).

No automated changes.
2023-02-27 08:23:11 -08:00
Jon Ross-Perkins 5fa6f04d83 Update the LLVM library version in use. (#2633)
This also fixes a couple issues with the newer version; makeArrayRef is deprecated, and ErrorHandling is now needed for llvm_unreachable.
2023-02-24 13:24:31 -08:00
Avi Aaron 0a70614235 replace me with self 2nd try (#2631)
this is a second try after PR 2629,
I restarted from scratch since most changes were undone.
2023-02-23 21:54:45 -08:00
Jon Ross-Perkins 10647b70a4 IWYU pass on toolchain (#2624)
Just opening files in vscode and seeing what clangd flags.

Some edits to ostream.h to stop it from getting flagged (the usage pattern means it's not always obviously used).
2023-02-23 10:39:18 -08:00
josh11b 4866f0f90b Announce Carbon's participation in GSoC 2023 (#2625) 2023-02-22 16:32:15 -08:00
Richard Smith 752692e08d Factor out a common base class from function and bound method values. (#2622)
This allows simplification of the interpreter in places where these two
kinds of value can be handled with common code.
2023-02-22 15:04:00 -08:00
Richard Smith 7fe06a5d2f Unify handling of calls to functions and to methods. (#2620)
This fixes some bugs in each, where the fixes had only been made on one
side of the switch or the other. Also don't forget to instantiate
deduced generic arguments in a call when we read them out of the AST.
2023-02-22 13:51:25 -08:00
Jon Ross-PerkinsandRichard Smith 9df70fb115 Disable most tracing in the prelude. (#2616)
This is intended to address currently flaky timeouts that are likely caused by the size of the prelude. I'm addressing a performance bottleneck in AnalyzeProgram with trace output. Trying to omit prelude traces reduces most trace output significantly,  and I think it'll scale better as the prelude size increases.

The basic mechanics here are:

- In order to consistently track whether tracing is on, I've added a TraceStream class, explorer/interpreter/trace_stream.h.
- The AST now has a num_prelude_declarations field, so that it's provided where the boundary is.
- In order to mark where we try to skip prelude output, I've added calls to set_in_prelude in type_checker.
- In exec_program, I just use num_prelude_declarations directly to skip over.
- Everywhere checks TraceStream::is_enabled before printing, similar to the std::optional check that was previously used.

This does add some timing output in order to better diagnose where slowness is coming from, when tracing. It also adds "verbose" targets to make it easier to get the trace output.

So for example, here's a timing for zero.carbon:

```
Timings:
- Parse: 13ms
- AddPrelude: 25ms
- AnalyzeProgram: 116ms
- ExecProgram: 12ms
```

If I make a small change to just not set skipping_prelude (essentially getting back to current output):

```
- Parse: 13ms
- AddPrelude: 25ms
- AnalyzeProgram: 2359ms
- ExecProgram: 57ms
```

Thus in this trivial example, I'm eliminating about 95% of the execution time.

Note this approach could still be refined in a few ways:

- We could add a flag to allow overriding in_prelude. It should be a small amount of work after this change. But it's a little consistent with how parser_debug works, that it won't print prelude output by default (unless there's an error).
- Execution could skip messages involving initialization of globals declared in the prelude. This is a little noisy right now, but I don't think it's significant for performance because ExecProgram is tiny.
- Once files are more separated, we should be able to change the num_prelude_declarations/set_in_prelude approach.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-02-22 13:41:12 -08:00
Jon Ross-Perkins 86aecb532f Rename lower to lowering (#2618)
Also Lower::Make to LowerToLLVM, removing the class for now.

This is per request from chandlerc and zygoloid.
2023-02-22 12:19:35 -08:00
Jon Ross-Perkins 2adaeee2ba Add handling for return types. (#2596)
This starts handling return types on functions, and comparing types with `return` statements.

Note, errors remain poor because the type literal is currently associated with a builtin, losing the parse_node that specified it. This means we don't have the original source location to associate with, even though it may be helpful to point at the type in source. We could point at the signature overall, but my leaning is that we wouldn't want that long-term, so TODOs for now and may want to change a little about how the parse node is tracked once things are a little further along.
2023-02-22 11:55:32 -08:00
Avi Aaron 5d88871682 Fix incorrect use of "overridden", should be "overriding" (#2619) 2023-02-22 11:45:51 -08:00
Richard Smith 4b2254a61f Fix some comments after #2612. (#2614) 2023-02-21 09:58:31 -08:00
Jon Ross-Perkins 530541e56c Add boilerplate framework for lowering. (#2607)
This adds boilerplate for lowering; a `dump llvm-ir` command, a `lower` directory, some files to give basic structure, and a trivial test.
2023-02-17 16:14:57 -08:00
Jon Ross-Perkins 1b662cbe73 Remove reference to None.h (#2613)
Reported by a Googler.
2023-02-17 11:45:59 -08:00
Jon Ross-PerkinsandRichard Smith 73869e9438 Modify lit_autoupdate so that it can handle errors in prelude.carbon (#2612)
The intent here is that changes to prelude.carbon shouldn't break every test that expects some error from prelude.carbon; that would be too fragile. As a consequence, this effectively ignores the line number in prelude.carbon.

This is a little complex because we don't know which line in the original source file is actually causing the error, just that there is an error. Also, the previous look-behind approach required a fixed-with prefix, whereas we want a little more than that in order to capture the filename for comparison.

This would be hard to do with extra_check_replacement because the path to bazel.runfiles is complex to calculate. As a consequence, this is basically all new code.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-02-17 09:31:48 -08:00
Richard Smith 6037f9e622 Remove AlternativeValueBase, per review comments on #2605. (#2606)
Also extend comment on `AlternativeSignature::static_type` as requested.
2023-02-16 11:15:13 -08:00
Jon Ross-Perkins a3b342d8e5 Fix reference to update_checks.py (#2610)
Scripts used to be named update_checks.py, now they're lit_autoupdate.py. This isn't dynamic due to execv; it felt odd to pass along the call.
2023-02-15 16:37:14 -08:00
Richard Smith 81532c8918 Fix mishandling of struct and tuple types in impl matching termination check. (#2609)
Both cases need a label for each level of struct and tuple type appearing in the impl query, because we can have an unbounded number of such levels with the types otherwise being the same.

Prior to this, both added testcases exhibit unbounded recursion.
2023-02-15 15:10:01 -08:00
Richard Smith 0e41c569b1 Implement the termination algorithm for impl selection described in #2458 (#2602)
Detect when evaluating an impl recursively tries to evaluate the same impl for the same or a more complex set of parameters.

In order to perform the check after we have tested that the type structure matches and before we check that constraints are recursively satisfied, argument deduction is extended to check structural matching properties earlier.

This requires us to separate match failures into two kinds: hard failures that produce errors that should never be swallowed, and soft failures such as a missing impl that lead us to merely discard an impl as a candidate. A flag has been added to `ImplScope` and `ArgumentDeduction` to specify whether soft failures should produce an error message or not.
2023-02-14 17:44:16 -08:00
Richard Smith 59ff7743c0 Expect parentheses after an alternative only if they were present in its declaration (#2605)
The design of choice types expects the declaration of an alternative to match the usage: if an alternative is declared as `None`, then it should be used as `None` not `None()`, and if it is declared as `None()` then it should be used as `None()` not `None`. Update explorer to match.

Also clean up the handling of choice types and alternative values a little in general, by moving away from identifying choice types and alternatives as strings and towards identifying them symbolically.

Closes #2422
2023-02-14 13:28:52 -08:00
Jon Ross-PerkinsandRichard Smith f7924aa93f Implement calls in the toolchain. (#2582)
This adds tracking of call information plus basic type checking. It adds a builtin for the empty tuple, mainly so that I have the basis for a default function return type.

As an aside, it also unifies printing within SemanticsIR, fixing a missing comma after callables.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-02-13 16:15:04 -08:00
Jon Ross-Perkins 22d7cd19ed Polish out support for reals and strings. (#2593)
Reals were mostly handled, but this PR adds storage of them. It also switches a little towards the FloatingPointType semantic from TokenizedBuffer.

While real literals like `1.0` were handled, the type literals were not. This just adds `f64`, similar to how I also only support `i32`.

The String type literal wasn't used, so I've added support in lexer and parser. Per discussion with @zygoloid String might be renamed based on the newer type literal plan, but it's still String in explorer and the design, so this is just consistent.

The builtin_types.carbon tests the three basic types that are there right now. The test is added to both parser and semantics so that it's clear what the state is in both stages.
2023-02-13 08:04:49 -08:00
Amr Hesham 98041d70c2 Explorer: error on bit-shift overflow (#2600)
Return Integer overflow Runtime error for bit shift if The second operand is less than zero or bigger than or equal bit width of the first operand in this case (32 bit for int)

Issue #2595
2023-02-13 08:01:24 -08:00
Jon Ross-Perkins b22e585285 Bump action versions. (#2591)
I was looking at this due to some warnings about node 12 deprecation. This resolves some of it, where updates are available. We'll probably need to keep half an eye on this for https://github.com/hkusu/review-assign-action/issues/20 and https://github.com/z0al/dependent-issues/issues/535, which haven't been addressed yet.

AFAICT no config versions are needed for these version bumps.
2023-02-11 11:00:30 -08:00
Jon Ross-Perkins b76bc875c4 Remove default constructor from IndexBase (#2598)
There were some notes about default constructors being required in parse_tree.h, but they don't seem to be. Removing the default constructor forces the explicit `::Invalid` where there's no value immediately being assigned, which works fine for existing code. I think this actually reduces the chance of accidents more than the prior default-construct-as-invalid approach.
2023-02-10 12:00:50 -08:00
Jon Ross-Perkins aa307b1144 Fix CrossReference to use NodeId instead of NodeBlockId. (#2597)
Probably a mistake from when this was referencing a node within a block instead of a node directly.
2023-02-10 11:59:19 -08:00
Jon Ross-Perkins 69117bc9c3 Exempt leads questions from inactive labeling. (#2589)
@chandlerc requested that leads questions not be marked inactive. These arise when there *isn't* a clear-cut answer, and so seem to make more sense to be effectively long-term.

The \n\n\n is trying to get a blank line between paragraphs. Right now it gets a newline, but the paragraphs sort of blend. I might need more \n's, don't know but I'll keep an eye on messages. The examples that I could find don't have multiple paragraphs.
2023-02-10 11:53:50 -08:00
Adrien Leravat 266fa401e6 Explorer: assert Optional not empty on Get() (#2587)
Prevent from unwrapping an empty Optional
2023-02-09 22:39:43 -08:00
Jon Ross-Perkins b2c60b4f53 Change the builtin enum approach to enforce addition. (#2584)
It feels like every time I add a builtin, I forget to add it to the builtin IR. This approach enforces the addition of builtin nodes, and also takes advantage of the normalized structure to set types appropriately (I think the new approach is simpler on this aspect).
2023-02-08 14:17:26 -08:00
Richard Smith 4fa71e32f5 Add support for most kinds of declarations to be declared and used as namespace members (#2575)
Support for global variables is still missing; they're a bit more tricky because they use a pattern to introduce their name.

Prior to this change, explorer heavily relied on name comparisons to determine whether two declarations declare the same entity. Some of those instances are fixed in this PR, but more remain to be fixed, and some TODOs are added for some harder-to-fix instances.
2023-02-08 13:21:15 -08:00
Adrien Leravat 245e4d1ea6 Explorer: drop unused PrintScopes method (#2588) 2023-02-08 09:31:13 -08:00
Adrien Leravat 65078ea943 Explorer: make use of != in Carbon lit (#2586)
Swap `not (a == b)` for `a != b` in test now that we have it.
2023-02-07 10:10:45 -08:00
Jon Ross-Perkins 5a0613283b Switch constexpr factory functions to constexpr values. (#2581)
Using the same const/constexpr done in EnumBase, adds Invalid and Builtin* values to replace Make functions that produced the same. This should make it clearer at call sites what the cost actually is, and reduces the syntactic overhead for MakeBuiltinReference in particular.

Really, this is that MakeBuiltinReference has been feeling pretty verbose, so I did that, and then one MakeInvalid is right next to it, and then obviously I should replace the other MakeInvalid for consistency...
2023-02-06 15:57:33 -08:00
Richard Smith 1a8a41a5a6 Improve diagnostic for unknown name in name qualifier. (#2579)
As requested in #2572.
2023-02-03 16:05:08 -08:00
Richard Smith 6d4920148b Initial support for name lookup into namespaces. (#2572)
Name lookup into namespaces needs to be resolved early, as part of name resolution, so that we can properly diagnose references to entities before they are fully declared.  Make name resolution set a target `value_node` on simple member accesses that name namespace members, and in type-checking rewrite those member accesses into `IdentifierExpression`s that directly reference the namespace member.
2023-02-03 12:58:38 -08:00
Jon Ross-Perkins 4e1b585fcf clang-tidy --fix (#2577)
Only automatic fixes.
2023-02-02 17:43:10 -08:00
Jon Ross-Perkins d5aa03d004 pre-commit autoupdate (#2576)
pre-commit autoupdate --freeze && pre-commit run -a

This update may be triggering incompatibilities with old installs. If you see an issue such as:

```
An unexpected error has occurred: CalledProcessError: command: ('python', '-mpip', 'install', '.')
```

Try updating pip packages, particularly:

```
pip3 install -U pre-commit
pip3 install -U virtualenv
```
2023-02-02 14:43:53 -08:00
Jon Ross-Perkins 7d3ef58a84 More explicit constructors in toolchain. (#2578)
Just adding `explicit`, no other changes.
2023-02-02 14:41:37 -08:00
Richard SmithandJon Ross-Perkins c172487395 Support for declaring functions within a namespace (#2569)
First step towards permitting declarations within namespaces. Supports only functions within namespaces for now, with no way to call those functions except from within other such functions. Unqualified lookups within a function in a namespace look in that namespace first.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-02-02 14:11:03 -08:00
Richard Smithandjosh11b 0b6411e6cc Associated constant assignment versus equality (#2173)
Split the `where A == B` constraint in two: `where .A = B` produces a new
constraint from an old one, where the value of `.A` in the new constraint is
known and eagerly rewritten to `B`, and `where A == B`, which does not cause
`A` and `B` to be considered as identical by language rules but does permit
implicit (no-op) conversion between them.
 
This aims to provide an efficiently-computable and human-understandable type
equality rule, with type canonicalization and therefore transitive type
equality, without sacrificing too much in the way of ergonomics and without
sacrificing determinism, while still providing the full power of a general type
constraint system in a less ergonomic form.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2023-02-01 10:03:30 -08:00
Jon Ross-Perkins 61c34c7a10 Rollback WORKSPACE sha changes (#2570)
This should undo #2566 and #2568

GitHub's trying to rollback the change:

- https://github.com/bazel-contrib/SIG-rules-authors/issues/11#issuecomment-1409438954
- https://github.blog/changelog/2023-01-30-git-archive-checksums-may-change/

At some point this PR should start working, and then we should merge it.
2023-01-30 23:03:22 -08:00
Richard Smith 60af531f5b Support parsing namespace declarations (#2563)
Initial support for parsing namespace declarations and referring to namespace names. No support for declaring members of namespaces yet.
2023-01-30 17:25:44 -08:00
Jon Ross-Perkins a7916c57fe Update a couple more WORKSPACE shas (#2568)
See #2566, I believe this is the same underlying issue. These packages weren't affected earlier.
2023-01-30 16:46:44 -08:00
Richard Smith 47a1e99b9e Factor ValueNodeView out of StaticScope. (#2562)
Also remove unused support in `StaticScope` for a scope to have multiple parents.

No functionality change intended.
2023-01-30 16:12:04 -08:00
Jon Ross-Perkinsandjosh11b e9480e7dfe Clean up a couple non-proposal docs links that had access issues. (#2565)
The toolchain link just needed a resourcekey.

The open discussion link may just not work because it was pre-go-public, so it points at a doc that we probably copied.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2023-01-30 11:33:18 -08:00
Jon Ross-Perkins bb647cc228 Update WORKSPACE checksums for everything (#2566)
I'm running a `bazel build //...` now and things look fine, so I'm guessing this is now correct. But it seems like GH changed something about their /archive/ downloads that just changed the checksums. Releases appear to be unaffected. I don't have any reference for what changed though.

https://github.com/bazelbuild/bazel/issues/15128 says to use /refs/tags, but I think we can't do that when we're trying to get a specific commit.
2023-01-30 11:23:17 -08:00