Просмотр исходного кода

Update design to use current `impl` syntax. (#2309)

Richard Smith 3 лет назад
Родитель
Сommit
dca7214c25
2 измененных файлов с 15 добавлено и 28 удалено
  1. 4 4
      docs/design/README.md
  2. 11 24
      docs/design/expressions/if.md

+ 4 - 4
docs/design/README.md

@@ -2790,14 +2790,14 @@ values for the `ElementType` member of the interface using a `where` clause:
 
 ```carbon
 class IntStack {
-  impl as StackInterface where .ElementType == i32 {
+  impl as StackInterface where .ElementType = i32 {
     fn Push[addr me: Self*](value: i32);
     // ...
   }
 }
 
 class FruitStack {
-  impl as StackInterface where .ElementType == Fruit {
+  impl as StackInterface where .ElementType = Fruit {
     fn Push[addr me: Self*](value: Fruit);
     // ...
   }
@@ -3030,7 +3030,7 @@ to type `T` and the second argument to type `U`, add the `like` keyword to both
 types in the `impl` declaration, as in:
 
 ```carbon
-external impl like T as AddWith(like U) where .Result == V {
+external impl like T as AddWith(like U) where .Result = V {
   // `Self` is `T` here
   fn Op[me: Self](other: U) -> V { ... }
 }
@@ -3136,7 +3136,7 @@ The common type is specified by implementing the `CommonTypeWith` interface:
 
 ```carbon
 // Common type of `A` and `B` is `C`.
-impl A as CommonTypeWith(B) where .Result == C { }
+impl A as CommonTypeWith(B) where .Result = C { }
 ```
 
 The common type is required to be a type that both types have an

+ 11 - 24
docs/design/expressions/if.md

@@ -126,12 +126,10 @@ interface SymmetricCommonTypeWith(U:! Type) {
           U is ImplicitAs(.Self);
 }
 match_first {
-  impl [T:! Type, U:! CommonTypeWith(T)] T as SymmetricCommonTypeWith(U) {
-    let Result:! Type = U.Result;
-  }
-  impl [U:! Type, T:! CommonTypeWith(U)] T as SymmetricCommonTypeWith(U) {
-    let Result:! Type = T.Result;
-  }
+  impl forall [T:! Type, U:! CommonTypeWith(T)]
+      T as SymmetricCommonTypeWith(U) where .Result = U.Result {}
+  impl forall [U:! Type, T:! CommonTypeWith(U)]
+      T as SymmetricCommonTypeWith(U) where .Result = T.Result {}
 }
 ```
 
@@ -154,14 +152,10 @@ the `CommonType` constraint is not met. For example, given:
 
 ```
 // Implementation #1
-impl [T:! Type] MyX as CommonTypeWith(T) {
-  let Result:! Type = MyX;
-}
+impl forall [T:! Type] MyX as CommonTypeWith(T) where .Result = MyX {}
 
 // Implementation #2
-impl [T:! Type] MyY as CommonTypeWith(T) {
-  let Result:! Type = MyY;
-}
+impl forall [T:! Type] MyY as CommonTypeWith(T) where .Result = MyY {}
 ```
 
 `MyX as CommonTypeWith(MyY)` will select #1, and `MyY as CommonTypeWith(MyX)`
@@ -173,9 +167,7 @@ because result types differ.
 If `T` is the same type as `U`, the result is that type:
 
 ```
-final impl [T:! Type] T as CommonTypeWith(T) {
-  let Result:! Type = T;
-}
+final impl forall [T:! Type] T as CommonTypeWith(T) where .Result = T {}
 ```
 
 _Note:_ This rule is intended to be considered more specialized than the other
@@ -197,9 +189,8 @@ fn F[T:! Hashable](c: bool, x: T, y: T) -> HashCode {
 If `T` implicitly converts to `U`, the common type is `U`:
 
 ```
-impl [T:! Type, U:! ImplicitAs(T)] T as CommonTypeWith(U) {
-  let Result:! Type = T;
-}
+impl forall [T:! Type, U:! ImplicitAs(T)]
+    T as CommonTypeWith(U) where .Result = T {}
 ```
 
 _Note:_ If an implicit conversion is possible in both directions, and no more
@@ -210,12 +201,8 @@ for such a case, `CommonTypeWith` implementations in both directions must be
 provided to override the blanket `impl`s in both directions:
 
 ```
-impl MyString as CommonTypeWith(YourString) {
-  let Result:! Type = MyString;
-}
-impl YourString as CommonTypeWith(MyString) {
-  let Result:! Type = MyString;
-}
+impl MyString as CommonTypeWith(YourString) where .Result = MyString {}
+impl YourString as CommonTypeWith(MyString) where .Result = MyString {}
 var my_string: MyString;
 var your_string: YourString;
 // The type of `also_my_string` is `MyString`.