diff options
| author | Robert Griesemer <gri@golang.org> | 2023-02-01 20:30:35 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-02 14:52:39 +0000 |
| commit | d871f63bcfa4d32ec442afa0f2a190543f94073f (patch) | |
| tree | 58a554bab992e8eb63b4b11921e4b677ca1f9e92 | |
| parent | 756a8ac91a7d26becb8f3c5c8e8fbdbae0eb77e2 (diff) | |
| download | go-d871f63bcfa4d32ec442afa0f2a190543f94073f.tar.xz | |
go/types, types2: avoid recursive invocation when unifying underlying types
There's no need to invoke unifier.nify recursively when we decide to
unify underlying types. Just update the respective type variable and
continue.
Change-Id: I3abe335464786dc509d18651dff14b20022c7d63
Reviewed-on: https://go-review.googlesource.com/c/go/+/464347
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
| -rw-r--r-- | src/cmd/compile/internal/types2/unify.go | 8 | ||||
| -rw-r--r-- | src/go/types/unify.go | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/types2/unify.go b/src/cmd/compile/internal/types2/unify.go index 5043125a91..abf159d5a2 100644 --- a/src/cmd/compile/internal/types2/unify.go +++ b/src/cmd/compile/internal/types2/unify.go @@ -240,12 +240,16 @@ func (u *unifier) nify(x, y Type, p *ifacePair) (result bool) { if traceInference { u.tracef("under %s ≡ %s", nx, y) } - return u.nify(nx.under(), y, p) + x = nx.under() + // Per the spec, a defined type cannot have an underlying type + // that is a type parameter. + assert(!isTypeParam(x)) } else if ny, _ := y.(*Named); ny != nil && !hasName(x) { if traceInference { u.tracef("%s ≡ under %s", x, ny) } - return u.nify(x, ny.under(), p) + y = ny.under() + assert(!isTypeParam(y)) } // Cases where at least one of x or y is a type parameter recorded with u. diff --git a/src/go/types/unify.go b/src/go/types/unify.go index 36023f1179..886e84183c 100644 --- a/src/go/types/unify.go +++ b/src/go/types/unify.go @@ -242,12 +242,16 @@ func (u *unifier) nify(x, y Type, p *ifacePair) (result bool) { if traceInference { u.tracef("under %s ≡ %s", nx, y) } - return u.nify(nx.under(), y, p) + x = nx.under() + // Per the spec, a defined type cannot have an underlying type + // that is a type parameter. + assert(!isTypeParam(x)) } else if ny, _ := y.(*Named); ny != nil && !hasName(x) { if traceInference { u.tracef("%s ≡ under %s", x, ny) } - return u.nify(x, ny.under(), p) + y = ny.under() + assert(!isTypeParam(y)) } // Cases where at least one of x or y is a type parameter recorded with u. |
