]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: review of unify.go
authorRobert Griesemer <gri@golang.org>
Tue, 15 Dec 2020 20:17:01 +0000 (12:17 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 16 Dec 2020 17:03:29 +0000 (17:03 +0000)
Make unify.go match the corresponding and reviewed go/types version.
The remaining differences are due to other differences in the packages.
Also, this version of unify opted to preserve the longer comment around
case tj > 0.

$ diff $GOROOT/src/cmd/compile/internal/types2/unify.go $GOROOT/src/go/types/unify.go
7c7
< package types2
---
> package types
9c9,12
< import "sort"
---
> import (
>  "go/token"
>  "sort"
> )
120,123d122
<  // This case is handled like the default case.
<  // case tj > 0:
<  //  // Only the type parameter for y has an inferred type. Use y slot for x.
<  //  u.x.setIndex(i, tj)
125,126c124,125
<  // Neither type parameter has an inferred type. Use y slot for x
<  // (or x slot for y, it doesn't matter).
---
>  // Either the type parameter for y has an inferred type, or neither type
>  // parameter has an inferred type. In either case, use y slot for x.
216c215
<  // basic types and type parameters. We use Named() because we only
---
>  // basic types and type parameters. We use asNamed() because we only
219,222c218,221
<  case !isNamed(x) && y != nil && y.Named() != nil:
<  return u.nify(x, y.Under(), p)
<  case x != nil && x.Named() != nil && !isNamed(y):
<  return u.nify(x.Under(), y, p)
---
>  case !isNamed(x) && y != nil && asNamed(y) != nil:
>  return u.nify(x, under(y), p)
>  case x != nil && asNamed(x) != nil && !isNamed(y):
>  return u.nify(under(x), y, p)
353,354c352,353
<  u.check.completeInterface(nopos, x)
<  u.check.completeInterface(nopos, y)
---
>  u.check.completeInterface(token.NoPos, x)
>  u.check.completeInterface(token.NoPos, y)

Change-Id: Icb246d4befedfa82cc3dcfdb7dd162cd4127fbe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/278572
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/unify.go

index 7c639366ef0a88a3d4d1465f24c58eed376b0ed7..60ccf625b909fd897a2d7ff4ebb8586b2d0c8490 100644 (file)
@@ -1,4 +1,3 @@
-// UNREVIEWED
 // Copyright 2020 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
@@ -17,7 +16,7 @@ import "sort"
 // (even if that also contains possibly the same type parameters). This
 // is crucial to infer the type parameters of self-recursive calls:
 //
-//     func f[type P](a P) { f(a) }
+//     func f[P any](a P) { f(a) }
 //
 // For the call f(a) we want to infer that the type argument for P is P.
 // During unification, the parameter type P must be resolved to the type
@@ -63,9 +62,9 @@ type tparamsList struct {
        unifier *unifier
        tparams []*TypeName
        // For each tparams element, there is a corresponding type slot index in indices.
-       // index  < 0: unifier.types[-index] == nil
+       // index  < 0: unifier.types[-index-1] == nil
        // index == 0: no type slot allocated yet
-       // index  > 0: unifier.types[index] == typ
+       // index  > 0: unifier.types[index-1] == typ
        // Joined tparams elements share the same type slot and thus have the same index.
        // By using a negative index for nil types we don't need to check unifier.types
        // to see if we have a type or not.