1
0
mirror of https://github.com/golang/go synced 2024-11-24 05:00:18 -07:00

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>
This commit is contained in:
Robert Griesemer 2023-02-01 20:30:35 -08:00 committed by Gopher Robot
parent 756a8ac91a
commit d871f63bcf
2 changed files with 12 additions and 4 deletions

View 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.

View 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.