]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: avoid recursive invocation when unifying underlying types
authorRobert Griesemer <gri@golang.org>
Thu, 2 Feb 2023 04:30:35 +0000 (20:30 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 2 Feb 2023 14:52:39 +0000 (14:52 +0000)
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>

src/cmd/compile/internal/types2/unify.go
src/go/types/unify.go

index 5043125a91f9dd392c323fa75f94af6da02d7ee5..abf159d5a26f7e0eae527ebe3253ac8a4135fd57 100644 (file)
@@ -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.
index 36023f1179fef1b821a3cb56dc188a830063f3f3..886e84183ca5d27d7e9fc234c60402872058d352 100644 (file)
@@ -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.