3
3
// license that can be found in the LICENSE file.
4
4
5
5
// Package typeutil defines various utilities for types, such as Map,
6
- // a mapping from types.Type to interface{} values.
6
+ // a mapping from types.Type to any values.
7
7
package typeutil // import "golang.org/x/tools/go/types/typeutil"
8
8
9
9
import (
@@ -17,7 +17,7 @@ import (
17
17
)
18
18
19
19
// Map is a hash-table-based mapping from types (types.Type) to
20
- // arbitrary interface{} values. The concrete types that implement
20
+ // arbitrary any values. The concrete types that implement
21
21
// the Type interface are pointers. Since they are not canonicalized,
22
22
// == cannot be used to check for equivalence, and thus we cannot
23
23
// simply use a Go map.
@@ -34,7 +34,7 @@ type Map struct {
34
34
// entry is an entry (key/value association) in a hash bucket.
35
35
type entry struct {
36
36
key types.Type
37
- value interface {}
37
+ value any
38
38
}
39
39
40
40
// SetHasher sets the hasher used by Map.
@@ -82,7 +82,7 @@ func (m *Map) Delete(key types.Type) bool {
82
82
83
83
// At returns the map entry for the given key.
84
84
// The result is nil if the entry is not present.
85
- func (m * Map ) At (key types.Type ) interface {} {
85
+ func (m * Map ) At (key types.Type ) any {
86
86
if m != nil && m .table != nil {
87
87
for _ , e := range m .table [m .hasher .Hash (key )] {
88
88
if e .key != nil && types .Identical (key , e .key ) {
@@ -95,7 +95,7 @@ func (m *Map) At(key types.Type) interface{} {
95
95
96
96
// Set sets the map entry for key to val,
97
97
// and returns the previous entry, if any.
98
- func (m * Map ) Set (key types.Type , value interface {} ) (prev interface {} ) {
98
+ func (m * Map ) Set (key types.Type , value any ) (prev any ) {
99
99
if m .table != nil {
100
100
hash := m .hasher .Hash (key )
101
101
bucket := m .table [hash ]
@@ -142,7 +142,7 @@ func (m *Map) Len() int {
142
142
// f will not be invoked for it, but if f inserts a map entry that
143
143
// Iterate has not yet reached, whether or not f will be invoked for
144
144
// it is unspecified.
145
- func (m * Map ) Iterate (f func (key types.Type , value interface {} )) {
145
+ func (m * Map ) Iterate (f func (key types.Type , value any )) {
146
146
if m != nil {
147
147
for _ , bucket := range m .table {
148
148
for _ , e := range bucket {
@@ -158,7 +158,7 @@ func (m *Map) Iterate(f func(key types.Type, value interface{})) {
158
158
// The order is unspecified.
159
159
func (m * Map ) Keys () []types.Type {
160
160
keys := make ([]types.Type , 0 , m .Len ())
161
- m .Iterate (func (key types.Type , _ interface {} ) {
161
+ m .Iterate (func (key types.Type , _ any ) {
162
162
keys = append (keys , key )
163
163
})
164
164
return keys
@@ -171,7 +171,7 @@ func (m *Map) toString(values bool) string {
171
171
var buf bytes.Buffer
172
172
fmt .Fprint (& buf , "{" )
173
173
sep := ""
174
- m .Iterate (func (key types.Type , value interface {} ) {
174
+ m .Iterate (func (key types.Type , value any ) {
175
175
fmt .Fprint (& buf , sep )
176
176
sep = ", "
177
177
fmt .Fprint (& buf , key )
@@ -209,7 +209,7 @@ type Hasher struct {
209
209
memo map [types.Type ]uint32
210
210
211
211
// ptrMap records pointer identity.
212
- ptrMap map [interface {} ]uint32
212
+ ptrMap map [any ]uint32
213
213
214
214
// sigTParams holds type parameters from the signature being hashed.
215
215
// Signatures are considered identical modulo renaming of type parameters, so
@@ -227,7 +227,7 @@ type Hasher struct {
227
227
func MakeHasher () Hasher {
228
228
return Hasher {
229
229
memo : make (map [types.Type ]uint32 ),
230
- ptrMap : make (map [interface {} ]uint32 ),
230
+ ptrMap : make (map [any ]uint32 ),
231
231
sigTParams : nil ,
232
232
}
233
233
}
@@ -432,7 +432,7 @@ func (h Hasher) hashTypeParam(t *types.TypeParam) uint32 {
432
432
433
433
// hashPtr hashes the pointer identity of ptr. It uses h.ptrMap to ensure that
434
434
// pointers values are not dependent on the GC.
435
- func (h Hasher ) hashPtr (ptr interface {} ) uint32 {
435
+ func (h Hasher ) hashPtr (ptr any ) uint32 {
436
436
if hash , ok := h .ptrMap [ptr ]; ok {
437
437
return hash
438
438
}
0 commit comments