Skip to content

Commit 1a58307

Browse files
alexandeargopherbot
authored andcommitted
all: modernize interface{} -> any
Produced with the command: $ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -any -test -fix ./... Change-Id: I09993badc57974a708d348a492ba3ea39f27052e Reviewed-on: https://go-review.googlesource.com/c/sync/+/744340 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com>
1 parent 3172ca5 commit 1a58307

File tree

5 files changed

+63
-63
lines changed

5 files changed

+63
-63
lines changed

singleflight/singleflight.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var errGoexit = errors.New("runtime.Goexit was called")
2222
// A panicError is an arbitrary value recovered from a panic
2323
// with the stack trace during the execution of given function.
2424
type panicError struct {
25-
value interface{}
25+
value any
2626
stack []byte
2727
}
2828

@@ -40,7 +40,7 @@ func (p *panicError) Unwrap() error {
4040
return err
4141
}
4242

43-
func newPanicError(v interface{}) error {
43+
func newPanicError(v any) error {
4444
stack := debug.Stack()
4545

4646
// The first line of the stack trace is of the form "goroutine N [status]:"
@@ -58,7 +58,7 @@ type call struct {
5858

5959
// These fields are written once before the WaitGroup is done
6060
// and are only read after the WaitGroup is done.
61-
val interface{}
61+
val any
6262
err error
6363

6464
// These fields are read and written with the singleflight
@@ -78,7 +78,7 @@ type Group struct {
7878
// Result holds the results of Do, so they can be passed
7979
// on a channel.
8080
type Result struct {
81-
Val interface{}
81+
Val any
8282
Err error
8383
Shared bool
8484
}
@@ -88,7 +88,7 @@ type Result struct {
8888
// time. If a duplicate comes in, the duplicate caller waits for the
8989
// original to complete and receives the same results.
9090
// The return value shared indicates whether v was given to multiple callers.
91-
func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool) {
91+
func (g *Group) Do(key string, fn func() (any, error)) (v any, err error, shared bool) {
9292
g.mu.Lock()
9393
if g.m == nil {
9494
g.m = make(map[string]*call)
@@ -118,7 +118,7 @@ func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, e
118118
// results when they are ready.
119119
//
120120
// The returned channel will not be closed.
121-
func (g *Group) DoChan(key string, fn func() (interface{}, error)) <-chan Result {
121+
func (g *Group) DoChan(key string, fn func() (any, error)) <-chan Result {
122122
ch := make(chan Result, 1)
123123
g.mu.Lock()
124124
if g.m == nil {
@@ -141,7 +141,7 @@ func (g *Group) DoChan(key string, fn func() (interface{}, error)) <-chan Result
141141
}
142142

143143
// doCall handles the single call for a key.
144-
func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
144+
func (g *Group) doCall(c *call, key string, fn func() (any, error)) {
145145
normalReturn := false
146146
recovered := false
147147

singleflight/singleflight_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestPanicErrorUnwrap(t *testing.T) {
3030

3131
testCases := []struct {
3232
name string
33-
panicValue interface{}
33+
panicValue any
3434
wrappedErrorType bool
3535
}{
3636
{
@@ -51,7 +51,7 @@ func TestPanicErrorUnwrap(t *testing.T) {
5151
t.Run(tc.name, func(t *testing.T) {
5252
t.Parallel()
5353

54-
var recovered interface{}
54+
var recovered any
5555

5656
group := &Group{}
5757

@@ -61,7 +61,7 @@ func TestPanicErrorUnwrap(t *testing.T) {
6161
t.Logf("after panic(%#v) in group.Do, recovered %#v", tc.panicValue, recovered)
6262
}()
6363

64-
_, _, _ = group.Do(tc.name, func() (interface{}, error) {
64+
_, _, _ = group.Do(tc.name, func() (any, error) {
6565
panic(tc.panicValue)
6666
})
6767
}()
@@ -84,7 +84,7 @@ func TestPanicErrorUnwrap(t *testing.T) {
8484

8585
func TestDo(t *testing.T) {
8686
var g Group
87-
v, err, _ := g.Do("key", func() (interface{}, error) {
87+
v, err, _ := g.Do("key", func() (any, error) {
8888
return "bar", nil
8989
})
9090
if got, want := fmt.Sprintf("%v (%T)", v, v), "bar (string)"; got != want {
@@ -98,7 +98,7 @@ func TestDo(t *testing.T) {
9898
func TestDoErr(t *testing.T) {
9999
var g Group
100100
someErr := errors.New("Some error")
101-
v, err, _ := g.Do("key", func() (interface{}, error) {
101+
v, err, _ := g.Do("key", func() (any, error) {
102102
return nil, someErr
103103
})
104104
if err != someErr {
@@ -114,7 +114,7 @@ func TestDoDupSuppress(t *testing.T) {
114114
var wg1, wg2 sync.WaitGroup
115115
c := make(chan string, 1)
116116
var calls int32
117-
fn := func() (interface{}, error) {
117+
fn := func() (any, error) {
118118
if atomic.AddInt32(&calls, 1) == 1 {
119119
// First invocation.
120120
wg1.Done()
@@ -167,7 +167,7 @@ func TestForget(t *testing.T) {
167167
)
168168

169169
go func() {
170-
g.Do("key", func() (i interface{}, e error) {
170+
g.Do("key", func() (i any, e error) {
171171
close(firstStarted)
172172
<-unblockFirst
173173
close(firstFinished)
@@ -178,15 +178,15 @@ func TestForget(t *testing.T) {
178178
g.Forget("key")
179179

180180
unblockSecond := make(chan struct{})
181-
secondResult := g.DoChan("key", func() (i interface{}, e error) {
181+
secondResult := g.DoChan("key", func() (i any, e error) {
182182
<-unblockSecond
183183
return 2, nil
184184
})
185185

186186
close(unblockFirst)
187187
<-firstFinished
188188

189-
thirdResult := g.DoChan("key", func() (i interface{}, e error) {
189+
thirdResult := g.DoChan("key", func() (i any, e error) {
190190
return 3, nil
191191
})
192192

@@ -200,7 +200,7 @@ func TestForget(t *testing.T) {
200200

201201
func TestDoChan(t *testing.T) {
202202
var g Group
203-
ch := g.DoChan("key", func() (interface{}, error) {
203+
ch := g.DoChan("key", func() (any, error) {
204204
return "bar", nil
205205
})
206206

@@ -219,7 +219,7 @@ func TestDoChan(t *testing.T) {
219219
// See https://github.com/golang/go/issues/41133
220220
func TestPanicDo(t *testing.T) {
221221
var g Group
222-
fn := func() (interface{}, error) {
222+
fn := func() (any, error) {
223223
panic("invalid memory address or nil pointer dereference")
224224
}
225225

@@ -256,7 +256,7 @@ func TestPanicDo(t *testing.T) {
256256

257257
func TestGoexitDo(t *testing.T) {
258258
var g Group
259-
fn := func() (interface{}, error) {
259+
fn := func() (any, error) {
260260
runtime.Goexit()
261261
return nil, nil
262262
}
@@ -310,7 +310,7 @@ func TestPanicDoChan(t *testing.T) {
310310
}()
311311

312312
g := new(Group)
313-
ch := g.DoChan("", func() (interface{}, error) {
313+
ch := g.DoChan("", func() (any, error) {
314314
panic("Panicking in DoChan")
315315
})
316316
<-ch
@@ -351,15 +351,15 @@ func TestPanicDoSharedByDoChan(t *testing.T) {
351351
defer func() {
352352
recover()
353353
}()
354-
g.Do("", func() (interface{}, error) {
354+
g.Do("", func() (any, error) {
355355
close(blocked)
356356
<-unblock
357357
panic("Panicking in Do")
358358
})
359359
}()
360360

361361
<-blocked
362-
ch := g.DoChan("", func() (interface{}, error) {
362+
ch := g.DoChan("", func() (any, error) {
363363
panic("DoChan unexpectedly executed callback")
364364
})
365365
close(unblock)
@@ -395,11 +395,11 @@ func ExampleGroup() {
395395
g := new(Group)
396396

397397
block := make(chan struct{})
398-
res1c := g.DoChan("key", func() (interface{}, error) {
398+
res1c := g.DoChan("key", func() (any, error) {
399399
<-block
400400
return "func 1", nil
401401
})
402-
res2c := g.DoChan("key", func() (interface{}, error) {
402+
res2c := g.DoChan("key", func() (any, error) {
403403
<-block
404404
return "func 2", nil
405405
})

syncmap/map_bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func BenchmarkRange(b *testing.B) {
157157

158158
perG: func(b *testing.B, pb *testing.PB, i int, m mapInterface) {
159159
for ; pb.Next(); i++ {
160-
m.Range(func(_, _ interface{}) bool { return true })
160+
m.Range(func(_, _ any) bool { return true })
161161
}
162162
},
163163
})
@@ -204,7 +204,7 @@ func BenchmarkAdversarialDelete(b *testing.B) {
204204
m.Load(i)
205205

206206
if i%mapSize == 0 {
207-
m.Range(func(k, _ interface{}) bool {
207+
m.Range(func(k, _ any) bool {
208208
m.Delete(k)
209209
return false
210210
})

syncmap/map_reference_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,58 @@ import (
1313

1414
// mapInterface is the interface Map implements.
1515
type mapInterface interface {
16-
Load(interface{}) (interface{}, bool)
17-
Store(key, value interface{})
18-
LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
19-
Delete(interface{})
20-
Range(func(key, value interface{}) (shouldContinue bool))
16+
Load(any) (any, bool)
17+
Store(key, value any)
18+
LoadOrStore(key, value any) (actual any, loaded bool)
19+
Delete(any)
20+
Range(func(key, value any) (shouldContinue bool))
2121
}
2222

2323
// RWMutexMap is an implementation of mapInterface using a sync.RWMutex.
2424
type RWMutexMap struct {
2525
mu sync.RWMutex
26-
dirty map[interface{}]interface{}
26+
dirty map[any]any
2727
}
2828

29-
func (m *RWMutexMap) Load(key interface{}) (value interface{}, ok bool) {
29+
func (m *RWMutexMap) Load(key any) (value any, ok bool) {
3030
m.mu.RLock()
3131
value, ok = m.dirty[key]
3232
m.mu.RUnlock()
3333
return
3434
}
3535

36-
func (m *RWMutexMap) Store(key, value interface{}) {
36+
func (m *RWMutexMap) Store(key, value any) {
3737
m.mu.Lock()
3838
if m.dirty == nil {
39-
m.dirty = make(map[interface{}]interface{})
39+
m.dirty = make(map[any]any)
4040
}
4141
m.dirty[key] = value
4242
m.mu.Unlock()
4343
}
4444

45-
func (m *RWMutexMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
45+
func (m *RWMutexMap) LoadOrStore(key, value any) (actual any, loaded bool) {
4646
m.mu.Lock()
4747
actual, loaded = m.dirty[key]
4848
if !loaded {
4949
actual = value
5050
if m.dirty == nil {
51-
m.dirty = make(map[interface{}]interface{})
51+
m.dirty = make(map[any]any)
5252
}
5353
m.dirty[key] = value
5454
}
5555
m.mu.Unlock()
5656
return actual, loaded
5757
}
5858

59-
func (m *RWMutexMap) Delete(key interface{}) {
59+
func (m *RWMutexMap) Delete(key any) {
6060
m.mu.Lock()
6161
delete(m.dirty, key)
6262
m.mu.Unlock()
6363
}
6464

65-
func (m *RWMutexMap) Range(f func(key, value interface{}) (shouldContinue bool)) {
65+
func (m *RWMutexMap) Range(f func(key, value any) (shouldContinue bool)) {
6666
m.mu.RLock()
67-
keys := make([]interface{}, 0, len(m.dirty))
67+
keys := make([]any, 0, len(m.dirty))
6868
for k := range m.dirty {
6969
keys = append(keys, k)
7070
}
@@ -89,30 +89,30 @@ type DeepCopyMap struct {
8989
clean atomic.Value
9090
}
9191

92-
func (m *DeepCopyMap) Load(key interface{}) (value interface{}, ok bool) {
93-
clean, _ := m.clean.Load().(map[interface{}]interface{})
92+
func (m *DeepCopyMap) Load(key any) (value any, ok bool) {
93+
clean, _ := m.clean.Load().(map[any]any)
9494
value, ok = clean[key]
9595
return value, ok
9696
}
9797

98-
func (m *DeepCopyMap) Store(key, value interface{}) {
98+
func (m *DeepCopyMap) Store(key, value any) {
9999
m.mu.Lock()
100100
dirty := m.dirty()
101101
dirty[key] = value
102102
m.clean.Store(dirty)
103103
m.mu.Unlock()
104104
}
105105

106-
func (m *DeepCopyMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
107-
clean, _ := m.clean.Load().(map[interface{}]interface{})
106+
func (m *DeepCopyMap) LoadOrStore(key, value any) (actual any, loaded bool) {
107+
clean, _ := m.clean.Load().(map[any]any)
108108
actual, loaded = clean[key]
109109
if loaded {
110110
return actual, loaded
111111
}
112112

113113
m.mu.Lock()
114114
// Reload clean in case it changed while we were waiting on m.mu.
115-
clean, _ = m.clean.Load().(map[interface{}]interface{})
115+
clean, _ = m.clean.Load().(map[any]any)
116116
actual, loaded = clean[key]
117117
if !loaded {
118118
dirty := m.dirty()
@@ -124,26 +124,26 @@ func (m *DeepCopyMap) LoadOrStore(key, value interface{}) (actual interface{}, l
124124
return actual, loaded
125125
}
126126

127-
func (m *DeepCopyMap) Delete(key interface{}) {
127+
func (m *DeepCopyMap) Delete(key any) {
128128
m.mu.Lock()
129129
dirty := m.dirty()
130130
delete(dirty, key)
131131
m.clean.Store(dirty)
132132
m.mu.Unlock()
133133
}
134134

135-
func (m *DeepCopyMap) Range(f func(key, value interface{}) (shouldContinue bool)) {
136-
clean, _ := m.clean.Load().(map[interface{}]interface{})
135+
func (m *DeepCopyMap) Range(f func(key, value any) (shouldContinue bool)) {
136+
clean, _ := m.clean.Load().(map[any]any)
137137
for k, v := range clean {
138138
if !f(k, v) {
139139
break
140140
}
141141
}
142142
}
143143

144-
func (m *DeepCopyMap) dirty() map[interface{}]interface{} {
145-
clean, _ := m.clean.Load().(map[interface{}]interface{})
146-
dirty := make(map[interface{}]interface{}, len(clean)+1)
144+
func (m *DeepCopyMap) dirty() map[any]any {
145+
clean, _ := m.clean.Load().(map[any]any)
146+
dirty := make(map[any]any, len(clean)+1)
147147
for k, v := range clean {
148148
dirty[k] = v
149149
}

0 commit comments

Comments
 (0)