Commit Graph
5 Commits
Author SHA1 Message Date
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
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
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
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