Commit Graph
298 Commits
Author SHA1 Message Date
Jon Ross-Perkins b9bd7e1eff Turn addr self in destructors into an error. (#2803)
Previously crashed. See #2802
2023-05-01 11:30:19 -07:00
Jon Ross-Perkins ad52f1e547 Fix lit_autoupdate for explorer (#2801)
#2793 added a README.md, #2796 added the non-auto-updated test.
2023-04-26 13:52:16 -07:00
Jon Ross-Perkins 8715cded29 Prevent generic bindings in binding types (#2789)
Adds TODO #2788 for the bigger refactoring.

Fixes #2783
2023-04-24 14:06:35 -07:00
Manmeet Singh 90577f18a0 fix alias resolved_declaration error (#2796)
Closes #2794
2023-04-24 10:02:04 -07:00
Lucile Rose Nihlen c180e6367b [explorer] fix assert when aliasing interface as member (#2792)
Note that this code still results in a compilation error pending the merge of #2628, this just prevents the assertion from happening.

Closes #2583.
2023-04-24 08:05:31 -07:00
Jon Ross-Perkins b828093c87 Start checking for a few possible resource exhaustion scenarios for explorer (#2793)
I couldn't figure out a way to actually hit a reasonable out-of-memory case once I add the maximum interpreter step count. However, the step count limit seems more important.

I've moved the todo stack limit out of function calls because there are plenty of ways to build up the todo stack without any function calls.

Fixes #2791
2023-04-21 15:14:14 -07:00
Manmeet Singh f310316ef4 fix printing for single element tuple values (#2786)
adds trailing comma to single element tuple

example:
```carbon
package ExplorerTest api;

fn Main() -> i32
{
  var a: (i32,) = (1, 2);
  return 0;
}

```

change in error message:
```diff
-type error in initializer of variable: '(i32, i32)' is not implicitly convertible to '(i32)'
+type error in initializer of variable: '(i32, i32)' is not implicitly convertible to '(i32,)'
```
2023-04-21 09:34:22 -07:00
Manmeet Singh 7eabd0a64a fix incorrect condition in InSameMatchFirst (#2773)
fixes a typo
2023-04-21 09:28:37 -07:00
Jon Ross-Perkins d12583fc08 Do cleanup on explorer fuzzing infrastructure. (#2790)
I'm partly doing this because the current setup would be difficult to share with the toolchain. e.g., ProtoToCarbon isn't explorer-specific, but the only way to run it via CLI is the explorer's fuzzverter. I want a separate tool.

This change:

- Adds a //common/fuzzing:proto_to_carbon tool.
  - The rest of fuzzverter is now just //explorer/fuzzing:ast_to_proto.
  - The change simplifies overall handling and removes a LLVM CLI dependency.
- Stops allowing unknown fields in the proto.
  - This has mostly led to forgetting to remove fuzzer inputs that were for removed features.
- Moves more non-explorer-specific bits to //common/fuzzing.
- Cleans up remaining pieces in //explorer/fuzzing
  - Merges the //explorer/fuzzing proto tests, which deduplicates AstToString copies.
    - These tests also had duplicate dependencies, etc -- and all complete in ~6s.
  - Updates and fixes regen_corpus which was previously broken by other changes.
  - Updates the README to reflect changes.
- Removes obsolete proto-fuzzer build configuration (AFAICT this is no longer needed).
2023-04-21 08:23:58 -07:00
Jon Ross-Perkins c9f0ef9e2c Require names where we expect binding patterns (#2782)
This also clusters the various `var` tests. This tests similar patterns for a few syntaxes, but `fn f(x: i32, i32) {}` and local variables `var (x: i32, i32);` and `var i32;` were the crashers I found.

In `fn`, the `x: i32,` is helpful to convince the parser that this is valid syntax.

Fixes #2778
2023-04-20 10:58:03 -07:00
masbuz ac10b36595 Fix BindingPattern type check handling (#2777) (#2787)
Recursive call of TypeCheckPattern ignored 'expected' parameter.

Closes #2777
2023-04-20 09:48:36 -07:00
Jon Ross-Perkins 62ee4a5c7a Suppress Print intrinsic output in the fuzzer. (#2784)
Related to #2780, but mostly an issue when running over the committed corpus since we use Print a lot.
2023-04-19 16:56:02 -07:00
Jon Ross-Perkins 39155d34ae Remove experimental continuation support (#2776)
Removes `__continuation`, `__await`, and `__run`.

In part here, the discussion was that while the feature had been useful for validating the early explorer design, it's no longer needed for that role as the explorer is now quite robust. Continuations have been experimental and, at this point, don't have an owner pushing to a proposal.

The triggering factor is that, as we push to address fuzzer issues, I ran into a crash bug in this code; basically, `fn Main() -> i32 { __await; return 0; }`. When I mentioned this, the reaction seemed to trend towards removal of the feature.
2023-04-19 14:22:43 -07:00
Jon Ross-Perkins 60059ff726 Type check the mix argument before interpreting it (#2781)
This is a crash bug.

Fixes #2779
2023-04-19 11:56:39 -07:00
Jon Ross-Perkins b07f9295d7 Stop printing per-input results in fuzzer (#2780)
Right now, running the fuzzer in fuzzing mode is pretty noisy due to this output; it makes it hard to see the fuzzer's own progress output. It's also not really needed: users can run explorer on inputs more directly, without using this tool (albeit with fuzzverter), if they want to see detailed results.
2023-04-19 11:55:47 -07:00
Manmeet Singh 68e15c37a3 feat: implement namespace alias (#2720)
Fixes 

https://github.com/carbon-language/carbon-lang/blob/46503c0a9d20d8e38dde1ff4266f4e2b98699669/explorer/interpreter/resolve_names.cpp#L281

This was super fun to implement as first contribution. Learnt a lot about how the interpreter works while digging through the code and trying different ways to fix it.
2023-04-17 15:56:31 -07:00
Jon Ross-Perkins 710eb0480c Add validation of Print format strings (#2765)
Also adds some validation of various direct print intrinsic calls.

Fixes #2734
2023-04-17 11:45:21 -07:00
Manmeet Singh 951cac9607 clang-tidy cleanup (#2774)
running clang-tidy locally got a bunch of warning. 

I have ignored `bugprone-unchecked-optional-access` for now, because there are large number of occurrences.
2023-04-17 10:15:11 -07:00
Jon Ross-Perkins 1f49c3e36d Add some validation of as intrinsics. (#2767) 2023-04-13 12:53:49 -07:00
Jon Ross-Perkins d7978deb3a Start doing more validation of intrinsics: assert, new, delete, rand (#2766)
This is adding more validation of intrinsics. It addresses a bug in rand where CHECK-fails would occur for bad range inputs, instead of a runtime error. I'm also addressing what I think was an int32 range issue in the handling by running the generator with int64.
2023-04-13 12:53:34 -07:00
Jon Ross-Perkinsandmingodad d52836e854 Switch bison variables to $[...] (#2756)
This is using the idea from #2264, but written from scratch.

Co-authored-by: mingodad
2023-04-13 12:48:27 -07:00
Amr Hesham 0fd0855da0 Detect duplicate struct member names (#2764)
Detect struct literal or struct type literal member duplicate name

Closes #2762
2023-04-12 16:24:29 -07:00
Jon Ross-Perkins 694dd7bf55 Fix poor dyn_cast usage (#2763)
Note the dest_class case didn't actually check dyn_cast success until after using the pointer. That's the case I noticed first, but also cleaning up a couple other small related things.
2023-04-12 15:56:27 -07:00
Jon Ross-Perkins 9245e17d4c Validate that the argument to __mix is a mixin. (#2757) 2023-04-12 09:25:43 -07:00
Jon Ross-Perkins 819c1745c7 Fix handling of struct conversions in deduction (#2758)
This case previously crashed. Trying to handle allow_implicit_conversion better per discussion; I've split out the for loop for each path because I think it's now clearer this way.
2023-04-11 15:50:03 -07:00
Manmeet Singh 7979c886e0 fix: incorrect loop in builtins_indexes (#2751)
Replaces the incorrect `<=` with `<`. Earlier this also included `Builtin::Invalid` which is meant to be used as count of Builtins.

Closes #2729
2023-04-10 13:37:57 -07:00
Manmeet Singh d9e37da4fb fix: set StaticScope::NameStatus correctly for Associated Constants (#2752)
The StaticScope::NameStatus pattern is not being correctly follow for associated constant deceleration.

Closes #2728
Closes #2730
2023-04-10 13:21:32 -07:00
Manmeet Singh 72d8f86e79 fix: incorrect index in TypeEqual for ConstraintType (#2754)
Just a typo.

Closes #2727
2023-04-10 13:17:33 -07:00
Amr Hesham 08f8c9bb27 Explorer: Move Concrete type check for Variable Definition to the type checker (#2750)
Move concrete type check for Variable Definition (Local variable) from interpreter to type checker using the `ExpectConcreteType` function created in #2748
2023-04-10 12:15:49 -07:00
Amr Hesham 0dc80bac01 Explorer: Report compiletime error when global variable type is abstract (#2748)
Add concrete type check for Variable Declaration to report a compile time error when the variable type is abstract

Closes #2747
2023-04-07 17:37:08 -07:00
Poorna Gunathilaka 0177764a03 Explorer: Fuzzer issue around integer overflow (#2737)
Closes #2732
2023-04-06 16:54:58 -07:00
Amr Hesham 87df7f7c43 Explorer: Fuzzer issue around infinite recursion (#2741)
I limited the stack size to 1K we can change it or make it dynamic from CLI later

Closes #2733
2023-04-06 16:50:02 -07:00
Adrien Leravat 8cb3f00f1b Explorer: fix assignment error typo (#2746)
Fix typo in error message from expression categories renaming
2023-04-06 16:48:51 -07:00
Adrien Leravat d0645c6a85 Explorer: rename value categories to expression categories (#2744)
Rename value categories to expression categories based on [Discord discussion](https://discord.com/channels/655572317891461132/753021843459538996/1092924035517665332) regarding naming and behavior.

>* let expression -> value expression
>* var expression -> reference expression
>* located expression -> initializing expression
>So:
>- "value expressions" produce values (with no associated location). "reference expressions" produce a location of an existing value. "initializing expressions" take a location and initialize it.
>- A let binding is initialized by a value expression, because lets represent values (with category conversions performed as needed, but if a conversion is performed from a different category of expression, the value of the object is pinned for the lifetime of the let).
>- A var binding is initialized by an initializing expression, without performing a copy (with category conversions performed as needed, calling a copy constructor if the initializer is a different expression category).
>- The & operator requires a reference expression, and it's an error to give it other kinds.
>- The left-hand side of . requires a value expression when calling a function with a non-addr receiver, and requires a reference expression when calling a function with an addr receiver (it's an error to give it a value expression, and for an initializing expression, a temporary is materialized).

Changes
* Rename "value category" to "expression category"
* Rename Var and Let value categories to Value, Reference, and Initializing expression
* Rename `lvalue` to `location` (most of the time)
2023-04-05 16:16:10 -07:00
Prabhat Sachdeva 3f1515af55 Change InstantiateType to be an Action (#2660)
Added an alternative way of Instantiating types (it was previously done using `InstantiateType` method).
Created an `Action` called `TypeInstantiationAction` and changed most of the code that directly invokes `InstantiateType` to instead spawn a new `TypeInstantiationAction`.

Relates to [#2594 ](https://github.com/carbon-language/carbon-lang/issues/2594)
2023-04-03 17:15:24 -07:00
Amr Hesham 29cdeb0d6b Explorer: Fuzzer issue around divide-by-zero (#2735)
fail with a runtime error, preventing the divide-by-zero from actually running.

Issue #2731
2023-03-31 20:53:26 -07:00
Richard SmithandChandler Carruth 807ef98758 Replace RTTI generation script with macros. (#2703)
This keeps all of our C++ code written in C++ source files, and avoids the increasing size of the RTTI generation script we'd started to see in #2699.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-03-30 14:16:44 -07:00
Jon Ross-Perkins dbde1f7b8f Restore clone_test, accidentally removed by #2700 (#2723) 2023-03-29 17:44:25 -07:00
josh11bandGeoff Romer 46503c0a9d Explorer and toolchain changes to implement #2483 (#2707)
This PR is making two main changes to the Explorer and Toolchain:
- Replace the `is` keyword in `where SomeType is SomeInterface` with `impls`, so it is `where SomeType impls SomeInterface`
- Rewrite uses of the "impls" to something else to avoid, frequently "`impl` declarations" or "implementations", to avoid confusion with the `impls` keyword.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2023-03-28 12:28:52 -07:00
Jon Ross-Perkins 4fa11af13f Update clang-format to 16.0.0 (#2712) 2023-03-24 16:34:05 -07:00
Richard Smith e0c90767be Support for templated impl declarations (#2700)
The strategy that we use for now to support template instantiation is to check the impl declaration as if it were a generic, but to defer all checking of the impl definition until we see a use in which all template parameters have arguments. At that point, we clone the impl definition and type-check the whole thing, with constant values set on the template parameters corresponding to the given arguments.

No caching of template instantiations is performed yet; each time we form a reference to a template instantiation, we instantiate it afresh. We also don't implement the name lookup rule from #949 yet; lookups during template instantiation look only in the actual type and not in the constraint.

Depends on #2699
2023-03-22 14:19:02 -07:00
Adrien Leravat df289efac4 Explorer: Add virtual destructor support (#2695)
### Features

* Add virtual `destructor`s support (Closes #2521)
* Check virtual override for virtual destructors
* Error if attempting to `Delete` a class that does not have virtual destructors from a base class pointer 

### Implementation

* Update parser to support virtual override introducers for destructors
* Check virtual override for class destructor and add to class vtable if necessary
* Add corresponding tests

### Notes

Contrary to initial implementation, this implementation leverages the `Address` structure and implements a new `Address::DowncastedAddress()` method to get address from child most class from a base class address. This avoids the need to use `GetAllocationId` and its issues when it comes to having multiple values for an `AllocationId`.

### Next work

Following this PR, we need to:

* Check when using `Delete` that the class was allocated with `New` (WIP)
* Drop the old `GetAllocationId(Value*)` in favor of a better system (WIP)
2023-03-22 09:58:30 -07:00
Richard Smith 782bd87316 AST cloning mechanism (#2699)
This is intended to be used for template instantiation, but for now takes no stance as to what it's cloning.

This is tested by parsing and cloning all of our test files, and checking that the result of converting each AST to proto is the same as the result of cloning and then converting each AST to proto.
2023-03-21 12:36:05 -07:00
Richard Smith f50ca72797 Propagate errors out of Substitute. (#2694)
This is in preparation for template instantiation being triggered during substitution, and being able to fail.

Fix rule-of-three violation (missing assignment operator) in `Error` that got in the way of using it to hold an error temporarily in a failed transformation.
2023-03-20 13:15:11 -07:00
Richard SmithandJon Ross-Perkins 28946d4b87 Order impl matching by type structure (#2691)
As described in [the generics design](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#type-structure-of-an-impl-declaration), `impl` declarations are prioritized by type structure. Given two `impl` declarations that match a `type as interface` query, the one that describes the longest prefix of the query without using placeholders is preferred.

We implement this by putting all impls in a total order, first by type structure equivalence classes and then by lexical order. When matching an impl, we walk this total order, and stop once we find a match and reach the end of its equivalence class.

Equivalence classes are determined by finding the locations of the "holes" (the positions where deduced parameters appear) within the type structure, viewed as a tree. Two impls are in the same equivalence class if their holes are in the same place, and equivalence classes are ordered based on a reverse lexicographical ordering of their holes.

Explorer doesn't keep the `Bindings` list for a parameterized type in any particular order, but the type structure rule requires that we consider them in lexical order. In order to support this, we now track an index on the declared parameters of each generic. This is a simple numbering of enclosing generic parameters, both on that generic and on all lexically enclosing generics.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-03-17 16:50:06 -07:00
Jon Ross-Perkins 9e1a5cfaee Reuse EnumBase for interpreter's Builtin enum (#2688)
This was bugging me after I saw all the strings; it feels like this is why we have EnumBase on the toolchain side.

I've included the move of EnumBase to //common because I figured it's reasonable to evaluate together; if we don't want EnumBase in this case, it doesn't make sense to move.
2023-03-17 08:40:43 -07:00
Richard Smith e25d8b0875 Remove support for an ImplScope to have multiple parents. (#2689)
This simplifies the code a little, and we neither have nor anticipate
any use for this facility.
2023-03-16 16:44:27 -07:00
Richard SmithandJon Ross-Perkins 5b6873d147 Fix handling of choice types with a mixture of alternatives with parameters and alternatives without parameters in pattern analysis. (#2626)
This case previously caused a crash.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-03-07 17:09:40 -08:00
Richard Smith bfe5c36bfc Move Value, Address, and ElementPath to ast/. (#2659)
These are used by the AST in lots of ways, and this resolves various layering issues.

This means that `AllocationId` also lives in ast/, but is managed by interpreter/. A better layering here would be desirable, but this seems good enough for the time being.
2023-03-06 16:28:03 -08:00
Richard Smith 2717dc1097 Decouple Value from interpreter-specific representation of continuations. (#2658)
`ContinuationValue` is the only dependency that `Value`s have on implementation details of the interpreter, and removing this allows `Value` to be moved from interpreter/ to ast/, as [discussed on #explorer](https://discord.com/channels/655572317891461132/763516049710120960/1081326038858092624).
2023-03-06 15:25:53 -08:00