go/types, types2: add missing Unalias calls in type unifier

The unification code has "early exits" when the compared
types are pointer-identical.

Because of Alias nodes, we cannot simply compare x == y but we
must compare Unalias(x) == Unalias(y). Still, in the common case
there are no aliases, so as a minor optimization we write:

        x == y || Unalias(x) == Unalias(y)

to test whether x and y are (pointer-) identical.
Add the missing Unalias calls in the place where we forgot them.

Fixes #67872.

Change-Id: Ia26ffe7205b0417fc698287a4aeb1c900d30cc0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/591975
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2024-06-11 08:57:37 -07:00 committed by Gopher Robot
parent beaf7f3282
commit 0d478d8e07
3 changed files with 16 additions and 2 deletions

View file

@ -344,7 +344,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
// that is a type parameter.
assert(!isTypeParam(y))
// x and y may be identical now
if x == y {
if x == y || Unalias(x) == Unalias(y) {
return true
}
}

View file

@ -347,7 +347,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
// that is a type parameter.
assert(!isTypeParam(y))
// x and y may be identical now
if x == y {
if x == y || Unalias(x) == Unalias(y) {
return true
}
}

View file

@ -0,0 +1,14 @@
// Copyright 2024 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.
package p
type A = uint8
type E uint8
func f[P ~A](P) {}
func g(e E) {
f(e)
}