Commit Graph
264 Commits
Author SHA1 Message Date
Jon MeowandGeoff Romer 1b4c81fa69 Add script for generating missing C++ deps (#1012)
Co-authored-by: Geoff Romer <gromer@google.com>
2022-01-07 14:44:40 -08:00
Jon Meow b7df523dc8 Fix cross-file links in non-proposal files (#1010) 2022-01-07 11:00:21 -08:00
Geoff Romer e533442028 Use /* instead of #if 0 for NamedEntity interface (#1006) 2022-01-06 10:00:10 -08:00
Geoff Romer 50263483d8 Add name accessor to NamedEntityView (#994)
This required changing BindingPattern::name() to return `"_"` instead of nullopt when representing a `"_"` binding.

Semi-related drive-by fixes:
- Update BindingPlaceholderValue to expose a NamedEntity instead of a string name, and stop exposing its type.
- Drop the unused SourceLocation parameter of ValueEqual
2022-01-04 15:53:11 -08:00
Geoff Romer c89ce1d570 Handle identifier value category properly. (#986) 2021-12-15 13:27:36 -08:00
Geoff Romer daf8729a75 Use static names in typechecker. (#985) 2021-12-14 11:26:53 -08:00
Geoff Romer 8e6c209a28 Use resolved names in typechecker (#974)
As a byproduct, replace NamedEntity with a type-erasing wrapper NamedEntityView, eliminate virtual inheritance from the AST, and eliminate interfaces from gen_rtti.
2021-12-13 16:35:30 -08:00
Geoff Romer fd45b089e9 Add typechecking of type declarations (#984)
Also explicitly model the types of expressions whose values are class or choice types, and make those be the static_type of the type declaration. This ensures that the static_type of a NamedEntity consistently corresponds to the static type of an IdentifierExpression using that name.
2021-12-13 16:19:52 -08:00
Geoff Romer e65e85b15d Use AST nodes as generic arg deduction keys (#982) 2021-12-10 12:19:06 -08:00
Geoff Romer 021e83a4f4 Ensure all NamedEntities have static types (#968) 2021-12-07 12:27:47 -08:00
Jon Meow beea60d0b8 Switch prelude to a file and refactor lit testing to pass commands directly. (#966) 2021-12-03 14:23:13 -08:00
Geoff Romer f75b4d322f Handle use-before-declare in static name lookup (#967)
Also remove inheritance from NamedEntity for some classes that don't need it.
2021-12-03 13:52:31 -08:00
Jon Meow 3c76b0ab01 Test --trace directly (#933) 2021-12-02 13:54:35 -08:00
Jon Meow 92903afbd5 clang-tidy pass on executable_semantics (#963) 2021-12-02 12:21:18 -08:00
Geoff Romer 29bef42f7d Fix broken build (#961) 2021-11-30 16:04:17 -08:00
Geoff RomerandJon Meow 17e0a1afb9 Implement static name resolution (#958)
This doesn't actually use the results of name resolution, but it does verify that they are present.
Also ensures that name resolution and type checking are applied to deduced function parameters and the implicit call to `Main()`.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-11-30 13:33:54 -08:00
Geoff RomerandJon Meow dc5e62fc7a Support parsing and testing unimplemented expressions (#957)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-11-30 12:29:15 -08:00
Geoff Romer be0c1e9da6 Move value-category checking to compile time (#960) 2021-11-29 17:07:50 -08:00
Geoff Romer 3e188c8562 Express prelude using Carbon syntax (#955)
This should be clearer, more maintainable, and more scalable than building the prelude AST by hand.
2021-11-29 13:56:55 -08:00
Geoff Romer b14c97d0d7 Clean up remaining uses of old spelling main (#959) 2021-11-24 14:32:39 -08:00
Geoff Romer 3f7e1cd3fb Clarify and simplify handling of lvalues (#956)
- Rename `PointerValue` to `LValue` to reflect how it's actually used. We can introduce a `PointerValue` type when we add support for actual pointer values.
- Remove support for pattern assignment. It's unclear if Carbon will support this, and even if we do, it raises questions that should first be addressed in a language proposal, like "is the left-hand side of `(x, y) = (1, 2)` an lvalue, or a pattern, or both, or something else entirely?"
2021-11-23 14:13:08 -08:00
Geoff Romer 6ae85bd13a Initial batch of AST matchers. (#953)
Also fixes an issue where llvm casts wouldn't work on AstNode.
2021-11-23 12:34:55 -08:00
Geoff Romer ec2f8e64e2 Support parsing Carbon files from strings. (#954)
Also, pass file names as string_view for greater convenience.
2021-11-23 10:44:39 -08:00
Geoff Romer 9642d7ad05 Factor out ActionStack from Interpreter (#951) 2021-11-17 12:59:16 -08:00
Geoff Romer 7a5b8434c8 Define a base class for all AST nodes. (#947)
Also implement code-generation to manage the resulting boilerplate.
2021-11-16 11:54:47 -08:00
Geoff Romer d854fb93cb Factor out AST node for function return types. (#912)
This enables us to stop treating the return type as a Pattern (which is really isn't), treat return types more consistently with other static types in the typechecker, and drop ReturnTypeContext.

Additional changes:
- Merge TypeCheckFunDef with TypeOfFunDef.
- Handle implicit conversions in `return` statements.
- Require function type literals to have an explicit `->`.
- Move consistency check for omitted returns from TypeChecker to ResolveControlFlow.
2021-11-12 11:30:31 -08:00
Geoff RomerandJon Meow a4aff26821 Stop allocating Actions on the Arena (#934)
This enables us to manage local variables in Carbon using C++ RAII.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-11-10 16:35:06 -08:00
Geoff Romer a9bb06ca14 Make NamedEntityInterface non-movable (#946) 2021-11-10 09:33:00 -08:00
Jon Meow e8d9b7675b Merge ClassDefinition and ClassDeclaration (#940) 2021-11-09 15:24:22 -08:00
Jon Meow 73eea8e47a Merge UnwindTo and UnwindPast logic (#926)
Also shifts the DeallocateScope concept into UnwindTodoTop since that's how it's used.
2021-11-08 09:22:38 -08:00
Chandler Carruth b990bab452 Fix main names that got past CI to fix tests. (#945)
#939 switch to `Main`, but #919 predated it and didn't get updated
before merging. Its tests passed on the PR branch as a consequence, but
failed when landed.

This just updates the test cases. Trivial fix forward.
2021-11-04 22:08:23 -07:00
Chandler Carruth 65ac59eb2a Add a script to compute minimal roots for check_deps. (#932)
This avoids needing to have nearly as many rules here which should
reduce its churn.

I've tested that this reaches the exact same set of transitive
dependencies.

Note, only the last commit here is new.
2021-11-03 12:53:54 -07:00
Jon Meow 2f15a64a6b Move a little logic into TypeChecker to narrow what's exposed. (#938) 2021-11-03 10:36:12 -07:00
Jon MeowandGeoff Romer 27e084d37a Start populating named entities in relevant locations. (#919)
This starts detecting naming collisions as a consequence of being able to determine when the name is declared twice in a given scope.



Co-authored-by: Geoff Romer <gromer@google.com>
2021-11-03 08:04:13 -07:00
Chandler Carruth 5f67029479 Use upstream GoogleTest and add related test utils. (#876)
This moves over to the vanilla upstream GoogleTest pulled in the more
expected manner with Bazel. It also adds Abseil and Google Benchmark
libraries in the same fashion (there are cross dependencies here).

As part of this, also introduce a dependency check test that can enforce
basic layering of dependencies. For example, this lets us ensure that
non-test Carbon code only depends on LLVM and Clang despite having other
libraries available. There remains some cleanup to improve the way these
dependency tests work, but this at least ensures we don't regress.

I've also provided workarounds to allow both Carbon code and LLVM code
to freely be used with GoogleTest (and other `std::ostream` based
output code). This is done by extending the code in
`//common/ostream.h`. One downside is that it requires opening the
`llvm` namespace and adding an ADL_found overload there. I think on
balance this is still a win and doesn't make me too nervous.

The new version of GoogleTest requires printing more often from matchers
and so I've also added several printing routines to types that
previously didn't require them. Otherwise, most of the updates are just
using the more conventional upstream style of including the headers and
adding `ostream.h` where it is needed.

I did consider moving code over to use `std::ostream` instead of LLVM's
`raw_ostream`, but the advantages of not doing virtual dispatch still
seem significant, and it also seems good to retain access to LLVM's
formatting utilities built around `raw_ostream` given that we can't pull
arbitrary dependencies into Carbon code outside of test code.

All of this was slightly motivated by requests for newer features in
GoogleTest, but much more-so by my desire to have access to Google
Benchmark and Abseil when writing benchmarks. For example, using
Abseil's random number generator seems extremely helpful when generating
inputs for benchmarks. The growing dependencies between these packages
further motivated me to just pull them all in and ensure they worked
well.
2021-11-02 20:14:12 -07:00
Jon Meow 6d822ababb Rename main to Main for Carbon style consistency (#939)
Main() is more consistency with Carbon's naming guidelines. C# offers some precedent: https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line
2021-11-02 14:53:18 -07:00
Jon Meow 17be4adec6 Use is_constructible to correct New error lines (#936) 2021-11-02 13:26:07 -07:00
Jon Meow 904774fbb8 Collapse Sequence into Block. (#927) 2021-11-01 14:59:39 -07:00
Jon Meow eeff5dcdae Mark fnty as __Fn to reflect experimental state (#928)
The `__Fn` naming is intended to mirror things like `__Continuation`.

The reason for this path is because it's not clear this is the form we'll want, and I think experimental naming will help reflect that.
2021-11-01 10:56:04 -07:00
Jon Meow bbd4940e6d Be more explicit about AST types (#921)
This was born out of wanting FunctionDeclaration to explicitly have a Block for a body, and became a bit more of specifying types around. Note this forces exec_program to generate a Block for print()'s body, which is probably more correct as now we can expect a standard FunctionDeclaration AST structure, even for the built-ins.

There is a syntactic change here: a continuation's body is now a Block, not just a Statement. I've added an example disallowed test case. I think this is more reasonable syntax.

Other than that, note that optional_else now generates a valid Block. This has me thinking about whether we can eliminate Sequence, but that seemed well out of scope for this.
2021-10-28 13:54:45 -07:00
Geoff Romer dea277d8e1 Factor allocation interface out of Heap (#918)
This will enable `Action` to deallocate from the heap without creating a dependency cycle.
2021-10-28 10:01:24 -07:00
Geoff Romer 70a7839a31 Fix bug from #909 (#924) 2021-10-27 17:09:03 -07:00
Geoff Romer 0df9e8666c Factor AllocationId out of Address (#916)
This lets us statically distinguish between code that works with arbitrary `Address`es and code that can only work with pointers to separately-allocated storage, and so we no longer need to worry about the latter code crashing at run-time (as `Heap::Deallocate` did) or silently doing the wrong thing (as `Heap::PrintAddress` did) if it's given the wrong kind of `Address`.
2021-10-27 16:40:17 -07:00
Geoff Romer 0da907fd2a Unify StructElement and VarValues (#909) 2021-10-27 16:33:38 -07:00
Geoff RomerandJon Meow 3bec7f8dc0 Unify Action and Scope stacks, and eliminate Frame (#880)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-10-21 14:55:41 -07:00
Geoff Romer 3677b76cb8 Perform implicit conversions at run time (#903)
This resolves the "cheating" in #870.
2021-10-21 12:47:49 -07:00
Geoff Romer d79387479c Revert formatting suggestion from #906 (#910)
Clang-format insists on this, which seems like a bug to me.
2021-10-21 12:46:09 -07:00
Jon Meow 91b99b1148 Test tuple indexing (#908) 2021-10-21 10:49:28 -07:00
Jon MeowandGeoff Romer 057b9fe253 Clean up remaining executable_semantics clang-tidy warnings (#906)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-10-20 10:25:22 -07:00
Geoff RomerandJon Meow 79e3d284b4 Move pattern interpretation to compile time (#904)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-10-20 10:05:17 -07:00