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>
diff --git a/src/cmd/compile/internal/types2/unify.go b/src/cmd/compile/internal/types2/unify.go
index 5043125..abf159d 100644
--- a/src/cmd/compile/internal/types2/unify.go
+++ b/src/cmd/compile/internal/types2/unify.go
@@ -240,12 +240,16 @@
 		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 36023f1..886e841 100644
--- a/src/go/types/unify.go
+++ b/src/go/types/unify.go
@@ -242,12 +242,16 @@
 		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.