go/types/typeutil: replace interface{} with any (cleanup)
Change-Id: If5b8faffbf4a60338bab4eb3c5fbcc6a3c3c3952
Reviewed-on: https://go-review.googlesource.com/c/tools/+/581116
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
diff --git a/go/types/typeutil/example_test.go b/go/types/typeutil/example_test.go
index 86c4d44..0e09503 100644
--- a/go/types/typeutil/example_test.go
+++ b/go/types/typeutil/example_test.go
@@ -52,7 +52,7 @@
// Format, sort, and print the map entries.
var lines []string
- namesByType.Iterate(func(T types.Type, names interface{}) {
+ namesByType.Iterate(func(T types.Type, names any) {
lines = append(lines, fmt.Sprintf("%s %s", names, T))
})
sort.Strings(lines)
diff --git a/go/types/typeutil/map.go b/go/types/typeutil/map.go
index 95e363f..a92f80d 100644
--- a/go/types/typeutil/map.go
+++ b/go/types/typeutil/map.go
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// Package typeutil defines various utilities for types, such as Map,
-// a mapping from types.Type to interface{} values.
+// a mapping from types.Type to any values.
package typeutil // import "golang.org/x/tools/go/types/typeutil"
import (
@@ -17,7 +17,7 @@
)
// Map is a hash-table-based mapping from types (types.Type) to
-// arbitrary interface{} values. The concrete types that implement
+// arbitrary any values. The concrete types that implement
// the Type interface are pointers. Since they are not canonicalized,
// == cannot be used to check for equivalence, and thus we cannot
// simply use a Go map.
@@ -34,7 +34,7 @@
// entry is an entry (key/value association) in a hash bucket.
type entry struct {
key types.Type
- value interface{}
+ value any
}
// SetHasher sets the hasher used by Map.
@@ -82,7 +82,7 @@
// At returns the map entry for the given key.
// The result is nil if the entry is not present.
-func (m *Map) At(key types.Type) interface{} {
+func (m *Map) At(key types.Type) any {
if m != nil && m.table != nil {
for _, e := range m.table[m.hasher.Hash(key)] {
if e.key != nil && types.Identical(key, e.key) {
@@ -95,7 +95,7 @@
// Set sets the map entry for key to val,
// and returns the previous entry, if any.
-func (m *Map) Set(key types.Type, value interface{}) (prev interface{}) {
+func (m *Map) Set(key types.Type, value any) (prev any) {
if m.table != nil {
hash := m.hasher.Hash(key)
bucket := m.table[hash]
@@ -142,7 +142,7 @@
// f will not be invoked for it, but if f inserts a map entry that
// Iterate has not yet reached, whether or not f will be invoked for
// it is unspecified.
-func (m *Map) Iterate(f func(key types.Type, value interface{})) {
+func (m *Map) Iterate(f func(key types.Type, value any)) {
if m != nil {
for _, bucket := range m.table {
for _, e := range bucket {
@@ -158,7 +158,7 @@
// The order is unspecified.
func (m *Map) Keys() []types.Type {
keys := make([]types.Type, 0, m.Len())
- m.Iterate(func(key types.Type, _ interface{}) {
+ m.Iterate(func(key types.Type, _ any) {
keys = append(keys, key)
})
return keys
@@ -171,7 +171,7 @@
var buf bytes.Buffer
fmt.Fprint(&buf, "{")
sep := ""
- m.Iterate(func(key types.Type, value interface{}) {
+ m.Iterate(func(key types.Type, value any) {
fmt.Fprint(&buf, sep)
sep = ", "
fmt.Fprint(&buf, key)
@@ -209,7 +209,7 @@
memo map[types.Type]uint32
// ptrMap records pointer identity.
- ptrMap map[interface{}]uint32
+ ptrMap map[any]uint32
// sigTParams holds type parameters from the signature being hashed.
// Signatures are considered identical modulo renaming of type parameters, so
@@ -227,7 +227,7 @@
func MakeHasher() Hasher {
return Hasher{
memo: make(map[types.Type]uint32),
- ptrMap: make(map[interface{}]uint32),
+ ptrMap: make(map[any]uint32),
sigTParams: nil,
}
}
@@ -432,7 +432,7 @@
// hashPtr hashes the pointer identity of ptr. It uses h.ptrMap to ensure that
// pointers values are not dependent on the GC.
-func (h Hasher) hashPtr(ptr interface{}) uint32 {
+func (h Hasher) hashPtr(ptr any) uint32 {
if hash, ok := h.ptrMap[ptr]; ok {
return hash
}
diff --git a/go/types/typeutil/map_test.go b/go/types/typeutil/map_test.go
index 1874de5..22630cd 100644
--- a/go/types/typeutil/map_test.go
+++ b/go/types/typeutil/map_test.go
@@ -86,7 +86,7 @@
t.Errorf("At(): got %q, want \"*string\"", v)
}
// Iteration over sole entry.
- tmap.Iterate(func(key types.Type, value interface{}) {
+ tmap.Iterate(func(key types.Type, value any) {
if key != tPStr1 {
t.Errorf("Iterate: key: got %s, want %s", key, tPStr1)
}
@@ -136,7 +136,7 @@
t.Errorf("At(): got %q, want \"*string again\"", v)
}
hamming := 1
- tmap.Iterate(func(key types.Type, value interface{}) {
+ tmap.Iterate(func(key types.Type, value any) {
switch {
case I(key, tChanInt1):
hamming *= 2 // ok
@@ -230,7 +230,7 @@
var ME1Type func(G1[int], G1[int], G2[int])
// Examples from issue #51314
-type Constraint[T any] interface{}
+type Constraint[T any] any
func Foo[T Constraint[T]]() {}
func Fn[T1 ~*T2, T2 ~*T1](t1 T1, t2 T2) {}