Commit Graph
750 Commits
Author SHA1 Message Date
Jon MeowandRichard Smith 22721da92b Avoid unnecessary relexing of the last line (#999)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-25 10:20:42 -08:00
Jon Meow ad08148304 Specify gql version (#1039)
3.0.0 is incompatible, this is a quick fix
2022-01-24 14:05:35 -08:00
Jon Meow 79e85d4830 Use lit_test for driver (#1037) 2022-01-24 11:15:19 -08:00
josh11bandRichard Smith f4e9063b97 Generics details 8: interface default and final members (#990)
Allowing interfaces to define default values for its associated entities. This:

-   Helps with evolution by reducing the changes needed to add new members to an interface.
-   Reduces boilerplate when some value is more common than others.
-   Addresses the gap between the minimum necessary for a type to provide the desired functionality of an interface and the breadth of API that user's desire.

As an alternative, final values can be provided instead, which can't be overridden, but are more predictable for users and may avoid dynamic dispatch overhead in some cases.

Example:
```
// Interface parameter has a default of `Self`
interface Add(Right:! Type = Self) {
  // `AddWith` *always* equals `Right`
  final let AddWith:! Type = Right;
  // `Result` has a default of `Self`
  let Result:! Type = Self;
  fn DoAdd[me: Self](right: Right) -> Result;
}

impl String as Add() {
  // Right == AddWith == Result == Self == String
  fn DoAdd[me: Self](right: Self) -> Self;
}
```

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-21 14:10:20 -08:00
pk19604014andGeoff Romer 2017eb4da0 Initial implementation of block string literals following lexical_conventions/string_literals.md. (#1028)
* Initial implementation of block string literals following lexical_conventions/string_literals.md.

Enabled yyinput() in flex to implement parsing.
Added ParseBlockStringLiteral() helper to handler further transformations such as indenting.
Modified formar_grammar to support single-quoted strings to prevent a failure on lexer.lpp.

* Fixed _find_string_end quote parameter type int -> str.

* Update executable_semantics/syntax/BUILD

Co-authored-by: Geoff Romer <gromer@google.com>

* Addressed code review comments - split table-drived test into individual tests, renamed constants to match style guide.

* Addressed code review comments -- using EXPECT_THAT_EXPECTED() in tests, lexer comments and code cleanup.

Co-authored-by: Geoff Romer <gromer@google.com>
2022-01-21 13:11:18 -05:00
Geoff RomerandJon Meow c311c8849c Use static name resolution in Interpreter (#1022)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2022-01-21 09:48:11 -08:00
Jon Meow d28e75629e Adjust pre-commit order and autoupdate (#1035) 2022-01-21 09:44:50 -08:00
Jon Meow ffc2be92d6 Add carbon to a couple python imports for correctness (#1033) 2022-01-20 08:37:47 -08:00
Jon Meow adee1d7c94 Remove operators.md in favor of expressions/ (#1031) 2022-01-18 15:13:36 -08:00
Jon Meow 81f28687cc Remove XDG reference for now (#1030) 2022-01-18 13:56:54 -08:00
Geoff Romer b954542d06 Reorganize and document Action (#1024) 2022-01-18 13:29:44 -08:00
josh11b ad5072b7b8 Link to Swift re: origin of witness table term (#1029) 2022-01-18 11:17:09 -08:00
josh11bandRichard Smith c08cbdb0bd Clarify class declaration syntax (#1026)
Clarify class declaration syntax

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-14 14:23:43 -08:00
Jon Meow cc1f3a6432 Workaround for libtool_check_unique errors (#1016)
e.g. https://github.com/carbon-language/carbon-lang/runs/4768894988?check_suite_focus=true -- I'm seeing this too frequently and wondering if we can duck it per https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
2022-01-13 14:21:13 -08:00
Jon Meow b672e34bd9 Turn fix_cc_deps into a pre-commit (#1015) 2022-01-13 14:01:45 -08:00
Geoff Romer 461e178273 Store named constant values in the AST (#1011)
This enables us to stop using `Env` in the typechecker. As a byproduct, this commit also restructures the interpreter to handle run-time global initialization as part of ordinary execution, using the Action stack.
2022-01-13 11:07:28 -08:00
Jon Meow d88f95ad31 Add missing syntax deps (#1014) 2022-01-10 14:25:16 -08:00
df63b5e054 auto keyword for vars (#851)
Allow `var <identifier>: auto = <expression>;` syntax.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2022-01-10 10:08:14 -08:00
josh11bandRichard Smith 00a178769f Principle: One static open extension mechanism (#998)
This is a proposal to adopt interfaces as the single static open extension mechanism for things like selecting how operators are implemented for types.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-07 15:54:27 -08:00
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 cab5bb0158 Clean up SimpleDiagnostic inheritance (#1004) 2022-01-07 11:01:01 -08:00
Jon Meow b7df523dc8 Fix cross-file links in non-proposal files (#1010) 2022-01-07 11:00:21 -08:00
Jon Meow a30a2b6730 Delete empty diagnostic_emitter.cpp (#1007) 2022-01-07 10:36:42 -08:00
b333f48697 Generics details 6: remove facets (#950)
There were some concerns about facet types leaking out of generic code in return types. Some initial fixes for this were done in [PR #900](https://github.com/carbon-language/carbon-lang/pull/900), but there remain concerns, for example when associated types are involved.

In particular, given an interface method with return type using an associated type, as in:

```
interface Deref {
  let Result:! Type;
  fn DoDeref[me: Self]() -> Result;
}

class IntHandle {
  impl as Deref {
    let Result:! Type = i32;
    fn DoDeref[me: Self]() -> Result { ... }
  }
}
```

Since `Result` has type `Type`, we had the problem that `IntHandle.DoDeref` would have to return `i32 as Type`, instead of the desired `i32`.

We also think we can simplify the model by eliminating the facet type concept and syntax.

This proposal removes facet types, introduces archetypes in their place, clarifies how associated types work outside of a generic function, and specifies how a generic `let` statement in a function body works.

Co-authored-by: Wolff Dobson <wolffg@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-06 14:08:08 -08:00
josh11bandRichard Smith 1534970146 Implicit conversions for aggregates (#981)
Define initialization, assignment, comparison, and implicit conversion between data classes with different field orders and/or types.

Implements the decision made in #710 .

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-01-06 11:16:41 -08:00
Geoff Romer e533442028 Use /* instead of #if 0 for NamedEntity interface (#1006) 2022-01-06 10:00:10 -08:00
Jon Meowandjosh11b 24b763c7e8 Fix or remove invalid anchor links, adding pre-commit (#997)
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2022-01-05 15:00:02 -08:00
Jon Meow 29522e6ed8 Modify parsing to monitor stack depth and error before overflow (#987) 2022-01-05 14:38:16 -08:00
Jon Meow fd489b69ad Lexer style cleanup (#1002) 2022-01-05 10:30:19 -08:00
Jon Meow cba02e1b47 Update WORKSPACE deps (#1003) 2022-01-05 09:45:59 -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
josh11bandChandler Carruth 3f12316d6b Generics details 7: final impls (#983)
Add support for marking impls as `final` to say they can't be specialized. This allows generic functions that see that the impl applies to determine the values for its associated types. For example this allows us to say that the implementation of the `Deref` interface for pointers can't be specialized. Otherwise, `*p` could have unknown type in a generic function.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-01-04 14:17:41 -08:00
pk19604014 3ffd3e09d5 More minor cleanup: added missing gtest build dep for toolchain/lexer:test_helpers and switched to use system include for gmock header. (#993) 2021-12-16 08:47:37 -05:00
Jon Meow 9c716e9c3b Move tests into Carbon::Testing, set small size (#992)
The small size is for the 1m vs 5m time limit -- all these tests _should_ be fast so a lower limit seems consistent, and the 5m timeout was getting in my way when trying to debug *actual* timeouts.

The Carbon::Testing bit is for convenience -- test libraries are generally using it, it seems like the tests should too. Note this reduces the need for `using`.

This does push NodeMatchers into Carbon::Testing -- I don't think this was benefiting from having its own namespace; `using namespace` is discouraged [under style](https://google.github.io/styleguide/cppguide.html#Namespaces), we wouldn't support an equivalent in Carbon, and it feels like it's not helping to avoid name collisions. (also tidy was bugging about it, and while I could NOLINT that, this felt like the better approach)
2021-12-15 15:18:44 -08:00
josh11b 3cb3ee32dd Double -> f64 (#991)
Replace `Double` with `f64` for the 64-bit floating point type.
2021-12-15 13:33:47 -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
Jon Meow 90c58dae2b Limit the number of parsed digits in numeric literals (#979) 2021-12-13 11:08:00 -08:00
Geoff Romer e65e85b15d Use AST nodes as generic arg deduction keys (#982) 2021-12-10 12:19:06 -08:00
josh11bandRichard Smith dcc287cb6e Generic parameterized impls (details 5) (#920)
There are cases where an impl definition should apply to more than a single type and interface combination. The solution is to parameterize the impl definition, so it applies to a family of types, interfaces, or both. This includes:

-   Declare an impl for a parameterized type, which may be external or declared out-of-line.
    ```
    external impl [T:! Type] Vector(T) as Iterable { ... }
    external impl Vector(T:! Type) as Iterable { ... }
    ```
-   "Conditional conformance" where a parameterized type implements some interface if the parameter to the type satisfies some criteria, like implementing the same interface.
    ```
    external impl [T:! Type] Pair(T, T) as Foo(T) { ... }
    class Array(T:! Type, template N:! Int) {
      impl [P:! Printable] Array(P, N) as Printable { ... }
      impl Array(P:! Printable, N) as Printable { ... }
    }
    ```
-   "Blanket" impls where an interface is implemented for all types that implement another interface, or some other criteria beyond being a specific type.
    ```
    external impl [T:! Ordered] T as PartiallyOrdered { ... }
    ```
-   "Wildcard" impls where a family of interfaces are implemented for single type.
    ```
    class BigInt {
      external impl [T:! ImplicitAs(i32)] as AddTo(T) { ... }
      external impl as AddTo(T:! ImplicitAs(i32)) { ... }
    }
    external impl [T:! ImplicitAs(i32)] BigInt as AddTo(T) { ... }
    external impl BigInt as AddTo(T:! ImplicitAs(i32)) { ... }
    ```

In addition to a syntax for defining parameterized impls, we need rules for coherence:

-   Orphan rules that ensure that impls are imported in any code that might use it.
-   We need overlap rules that pick a specific impl when more than one impl declaration matches a specific query about whether a type implements an interface.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2021-12-09 14:29:54 -08:00
pk19604014 6808d7ac50 Small cleanup changes: added missing dependency, fixed hdrs/srcs mimatched, changed throw to FATAL(). (#978)
* Small cleanup changes: added missing dependency, fixed hdrs/srcs mismatched, changed throw to FATAL().

* Replaced FATAL() with CHECK().
2021-12-09 16:49:00 -05:00
634148c39f Coherence: terminology, rationale, alternatives considered (#624)
Add an appendix with the rationale for and alternatives to coherence, along with an entry in the terminology and updates to the coherence discussion in the goals.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2021-12-09 13:27:15 -08:00
Jon Meow 97ce1f5449 Fix handling of closing scopes in FindNextof (#977) 2021-12-09 08:10:36 -08:00
Jon MeowandChandler Carruth a562f872e7 Switch from assert to CHECK (#975)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-12-08 08:38:27 -08:00
Jon Meow e727eb8fe6 Update gtest to pull in clang-tidy workarounds (#972) 2021-12-07 16:58:42 -08:00
Geoff Romer 021e83a4f4 Ensure all NamedEntities have static types (#968) 2021-12-07 12:27:47 -08:00
Jon MeowandChandler Carruth 652cd8c636 Style updates, mostly _ naming (#970)
There are some declaration order changes, and a few test classes switched from `struct` to `class`. However, this PR is mostly adopting `_` naming of private member variables due to the shift in naming style. None of what's here should have behavior impacts, it should just be style.

Note, there are a lot of things that *look* like they could be accessor-named, but I'm not doing that in this change. Happy to do it separately if you want me to do another PR focused on it.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-12-07 09:46:44 -08:00
josh11bandRichard Smith be8d0a993b Generic impls access (details 4) (#931)
Implementations of interfaces are as public as the names used in their signature. No access control modifiers are allowed on `impl` declarations.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2021-12-07 09:28:08 -08:00