convert uses of interface{} to any

Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
This commit is contained in:
Kevin Krakauer
2022-11-08 13:14:06 -08:00
committed by gVisor bot
parent c82b70015d
commit d8aa09e04c
220 changed files with 509 additions and 509 deletions
+4 -4
View File
@@ -16,20 +16,20 @@ package tests
// +stateify savable
type arrayContainer struct {
v [1]interface{}
v [1]any
}
// +stateify savable
type arrayPtrContainer struct {
v *[1]interface{}
v *[1]any
}
// +stateify savable
type sliceContainer struct {
v []interface{}
v []any
}
// +stateify savable
type slicePtrContainer struct {
v *[]interface{}
v *[]any
}
+11 -11
View File
@@ -19,7 +19,7 @@ import (
"testing"
)
var allArrayPrimitives = []interface{}{
var allArrayPrimitives = []any{
[1]bool{},
[1]bool{true},
[2]bool{false, true},
@@ -71,12 +71,12 @@ func TestArrayPrimitives(t *testing.T) {
func TestSlices(t *testing.T) {
var allSlices = flatten(
filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) {
filter(allArrayPrimitives, func(o any) (any, bool) {
v := reflect.New(reflect.TypeOf(o)).Elem()
v.Set(reflect.ValueOf(o))
return v.Slice(0, v.Len()).Interface(), true
}),
filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) {
filter(allArrayPrimitives, func(o any) (any, bool) {
v := reflect.New(reflect.TypeOf(o)).Elem()
v.Set(reflect.ValueOf(o))
if v.Len() == 0 {
@@ -85,7 +85,7 @@ func TestSlices(t *testing.T) {
}
return v.Slice(1, v.Len()).Interface(), true
}),
filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) {
filter(allArrayPrimitives, func(o any) (any, bool) {
v := reflect.New(reflect.TypeOf(o)).Elem()
v.Set(reflect.ValueOf(o))
if v.Len() == 0 {
@@ -103,11 +103,11 @@ func TestSlices(t *testing.T) {
func TestArrayContainers(t *testing.T) {
var (
emptyArray [1]interface{}
fullArray [1]interface{}
emptyArray [1]any
fullArray [1]any
)
fullArray[0] = &emptyArray
runTestCases(t, false, "", []interface{}{
runTestCases(t, false, "", []any{
arrayContainer{v: emptyArray},
arrayContainer{v: fullArray},
arrayPtrContainer{v: nil},
@@ -118,11 +118,11 @@ func TestArrayContainers(t *testing.T) {
func TestSliceContainers(t *testing.T) {
var (
nilSlice []interface{}
emptySlice = make([]interface{}, 0)
fullSlice = []interface{}{nil}
nilSlice []any
emptySlice = make([]any, 0)
fullSlice = []any{nil}
)
runTestCases(t, false, "", []interface{}{
runTestCases(t, false, "", []any{
sliceContainer{v: nilSlice},
sliceContainer{v: emptySlice},
sliceContainer{v: fullSlice},
+9 -9
View File
@@ -26,7 +26,7 @@ import (
)
// buildPtrObject builds a benchmark object.
func buildPtrObject(n int) interface{} {
func buildPtrObject(n int) any {
b := new(benchStruct)
for i := 0; i < n; i++ {
b = &benchStruct{B: b}
@@ -35,7 +35,7 @@ func buildPtrObject(n int) interface{} {
}
// buildMapObject builds a benchmark object.
func buildMapObject(n int) interface{} {
func buildMapObject(n int) any {
b := new(benchStruct)
m := make(map[int]*benchStruct)
for i := 0; i < n; i++ {
@@ -45,7 +45,7 @@ func buildMapObject(n int) interface{} {
}
// buildSliceObject builds a benchmark object.
func buildSliceObject(n int) interface{} {
func buildSliceObject(n int) any {
b := new(benchStruct)
s := make([]*benchStruct, 0, n)
for i := 0; i < n; i++ {
@@ -55,7 +55,7 @@ func buildSliceObject(n int) interface{} {
}
var allObjects = map[string]struct {
New func(int) interface{}
New func(int) any
}{
"ptr": {
New: buildPtrObject,
@@ -68,7 +68,7 @@ var allObjects = map[string]struct {
},
}
func buildObjects(n int, fn func(int) interface{}) (iters int, v interface{}) {
func buildObjects(n int, fn func(int) any) (iters int, v any) {
// maxSize is the maximum size of an individual object below. For an N
// larger than this, we start to return multiple objects.
const maxSize = 1024
@@ -80,22 +80,22 @@ func buildObjects(n int, fn func(int) interface{}) (iters int, v interface{}) {
}
// gobSave is a version of save using gob (no stats available).
func gobSave(_ context.Context, w wire.Writer, v interface{}) (_ state.Stats, err error) {
func gobSave(_ context.Context, w wire.Writer, v any) (_ state.Stats, err error) {
enc := gob.NewEncoder(w)
err = enc.Encode(v)
return
}
// gobLoad is a version of load using gob (no stats available).
func gobLoad(_ context.Context, r wire.Reader, v interface{}) (_ state.Stats, err error) {
func gobLoad(_ context.Context, r wire.Reader, v any) (_ state.Stats, err error) {
dec := gob.NewDecoder(r)
err = dec.Decode(v)
return
}
var allAlgos = map[string]struct {
Save func(context.Context, wire.Writer, interface{}) (state.Stats, error)
Load func(context.Context, wire.Reader, interface{}) (state.Stats, error)
Save func(context.Context, wire.Writer, any) (state.Stats, error)
Load func(context.Context, wire.Reader, any) (state.Stats, error)
MaxPtr int
}{
"state": {
+8 -8
View File
@@ -62,27 +62,27 @@ func TestFloat(t *testing.T) {
const onlyDouble float64 = 1.0000000000000002
func TestFloatTruncation(t *testing.T) {
runTestCases(t, true, "pass", []interface{}{
runTestCases(t, true, "pass", []any{
truncatingFloat32{save: onlyDouble},
})
runTestCases(t, false, "fail", []interface{}{
runTestCases(t, false, "fail", []any{
truncatingFloat32{save: 1.0},
})
}
var safeComplex64s = combine(safeFloat32s, safeFloat32s, func(i, j interface{}) interface{} {
var safeComplex64s = combine(safeFloat32s, safeFloat32s, func(i, j any) any {
return complex(i.(float32), j.(float32))
})
var allComplex64s = combine(allFloat32s, allFloat32s, func(i, j interface{}) interface{} {
var allComplex64s = combine(allFloat32s, allFloat32s, func(i, j any) any {
return complex(i.(float32), j.(float32))
})
var safeComplex128s = combine(safeFloat64s, safeFloat64s, func(i, j interface{}) interface{} {
var safeComplex128s = combine(safeFloat64s, safeFloat64s, func(i, j any) any {
return complex(i.(float64), j.(float64))
})
var allComplex128s = combine(allFloat64s, allFloat64s, func(i, j interface{}) interface{} {
var allComplex128s = combine(allFloat64s, allFloat64s, func(i, j any) any {
return complex(i.(float64), j.(float64))
})
@@ -107,12 +107,12 @@ func TestComplex(t *testing.T) {
}
func TestComplexTruncation(t *testing.T) {
runTestCases(t, true, "pass", []interface{}{
runTestCases(t, true, "pass", []any{
truncatingComplex64{save: complex(onlyDouble, onlyDouble)},
truncatingComplex64{save: complex(1.0, onlyDouble)},
truncatingComplex64{save: complex(onlyDouble, 1.0)},
})
runTestCases(t, false, "fail", []interface{}{
runTestCases(t, false, "fail", []any{
truncatingComplex64{save: complex(1.0, 1.0)},
})
}
+4 -4
View File
@@ -58,7 +58,7 @@ func TestInt(t *testing.T) {
}
func TestIntTruncation(t *testing.T) {
runTestCases(t, true, "pass", []interface{}{
runTestCases(t, true, "pass", []any{
truncatingInt8{save: math.MinInt8 - 1},
truncatingInt16{save: math.MinInt16 - 1},
truncatingInt32{save: math.MinInt32 - 1},
@@ -66,7 +66,7 @@ func TestIntTruncation(t *testing.T) {
truncatingInt16{save: math.MaxInt16 + 1},
truncatingInt32{save: math.MaxInt32 + 1},
})
runTestCases(t, false, "fail", []interface{}{
runTestCases(t, false, "fail", []any{
truncatingInt8{save: 1},
truncatingInt16{save: 1},
truncatingInt32{save: 1},
@@ -81,12 +81,12 @@ func TestUint(t *testing.T) {
}
func TestUintTruncation(t *testing.T) {
runTestCases(t, true, "pass", []interface{}{
runTestCases(t, true, "pass", []any{
truncatingUint8{save: math.MaxUint8 + 1},
truncatingUint16{save: math.MaxUint16 + 1},
truncatingUint32{save: math.MaxUint32 + 1},
})
runTestCases(t, false, "fail", []interface{}{
runTestCases(t, false, "fail", []any{
truncatingUint8{save: 1},
truncatingUint16{save: 1},
truncatingUint32{save: 1},
+1 -1
View File
@@ -16,7 +16,7 @@ package tests
// +stateify savable
type genericContainer struct {
v interface{}
v any
}
// +stateify savable
+10 -10
View File
@@ -19,23 +19,23 @@ import (
)
func TestLoadHooks(t *testing.T) {
runTestCases(t, false, "load-hooks", []interface{}{
runTestCases(t, false, "load-hooks", []any{
// Root object being a struct.
afterLoadStruct{v: 1},
valueLoadStruct{v: 1},
genericContainer{v: &afterLoadStruct{v: 1}},
genericContainer{v: &valueLoadStruct{v: 1}},
sliceContainer{v: []interface{}{&afterLoadStruct{v: 1}}},
sliceContainer{v: []interface{}{&valueLoadStruct{v: 1}}},
sliceContainer{v: []any{&afterLoadStruct{v: 1}}},
sliceContainer{v: []any{&valueLoadStruct{v: 1}}},
// Root object being a pointer.
&afterLoadStruct{v: 1},
&valueLoadStruct{v: 1},
&genericContainer{v: &afterLoadStruct{v: 1}},
&genericContainer{v: &valueLoadStruct{v: 1}},
&sliceContainer{v: []interface{}{&afterLoadStruct{v: 1}}},
&sliceContainer{v: []interface{}{&valueLoadStruct{v: 1}}},
&mapContainer{v: map[int]interface{}{0: &afterLoadStruct{v: 1}}},
&mapContainer{v: map[int]interface{}{0: &valueLoadStruct{v: 1}}},
&sliceContainer{v: []any{&afterLoadStruct{v: 1}}},
&sliceContainer{v: []any{&valueLoadStruct{v: 1}}},
&mapContainer{v: map[int]any{0: &afterLoadStruct{v: 1}}},
&mapContainer{v: map[int]any{0: &valueLoadStruct{v: 1}}},
})
}
@@ -50,7 +50,7 @@ func TestCycles(t *testing.T) {
cs1.c = &cs2
cs2.c = &cs1
runTestCases(t, false, "cycles", []interface{}{
runTestCases(t, false, "cycles", []any{
cs,
cs1,
})
@@ -62,7 +62,7 @@ func TestDeadlock(t *testing.T) {
bs := badCycleStruct{nil}
bs.b = &bs
runTestCases(t, false, "self", []interface{}{
runTestCases(t, false, "self", []any{
&bs,
})
@@ -72,7 +72,7 @@ func TestDeadlock(t *testing.T) {
bs1.b = &bs2
bs2.b = &bs1
runTestCases(t, true, "deadlock", []interface{}{
runTestCases(t, true, "deadlock", []any{
&bs1,
})
}
+2 -2
View File
@@ -16,12 +16,12 @@ package tests
// +stateify savable
type mapContainer struct {
v map[int]interface{}
v map[int]any
}
// +stateify savable
type mapPtrContainer struct {
v *map[int]interface{}
v *map[int]any
}
// +stateify savable
+8 -8
View File
@@ -19,7 +19,7 @@ import (
"testing"
)
var allMapPrimitives = []interface{}{
var allMapPrimitives = []any{
bool(true),
int(1),
int8(1),
@@ -40,12 +40,12 @@ var allMapKeys = flatten(allMapPrimitives, pointersTo(allMapPrimitives))
var allMapValues = flatten(allMapPrimitives, pointersTo(allMapPrimitives), interfacesTo(allMapPrimitives))
var emptyMaps = combine(allMapKeys, allMapValues, func(v1, v2 interface{}) interface{} {
var emptyMaps = combine(allMapKeys, allMapValues, func(v1, v2 any) any {
m := reflect.MakeMap(reflect.MapOf(reflect.TypeOf(v1), reflect.TypeOf(v2)))
return m.Interface()
})
var fullMaps = combine(allMapKeys, allMapValues, func(v1, v2 interface{}) interface{} {
var fullMaps = combine(allMapKeys, allMapValues, func(v1, v2 any) any {
m := reflect.MakeMap(reflect.MapOf(reflect.TypeOf(v1), reflect.TypeOf(v2)))
m.SetMapIndex(reflect.Zero(reflect.TypeOf(v1)), reflect.Zero(reflect.TypeOf(v2)))
return m.Interface()
@@ -55,7 +55,7 @@ func TestMapAliasing(t *testing.T) {
v := make(map[int]int)
ptrToV := &v
aliases := []map[int]int{v, v}
runTestCases(t, false, "", []interface{}{ptrToV, aliases})
runTestCases(t, false, "", []any{ptrToV, aliases})
}
func TestMapsEmpty(t *testing.T) {
@@ -74,11 +74,11 @@ func TestMapsFull(t *testing.T) {
func TestMapContainers(t *testing.T) {
var (
nilMap map[int]interface{}
emptyMap = make(map[int]interface{})
fullMap = map[int]interface{}{0: nil}
nilMap map[int]any
emptyMap = make(map[int]any)
fullMap = map[int]any{0: nil}
)
runTestCases(t, false, "", []interface{}{
runTestCases(t, false, "", []any{
mapContainer{v: nilMap},
mapContainer{v: emptyMap},
mapContainer{v: fullMap},
+5 -5
View File
@@ -88,13 +88,13 @@ func (ifv *innerFieldValue) loadV(sfv *savedFieldValue) {
// +stateify savable
type system struct {
v1 interface{}
v2 interface{}
v1 any
v2 any
}
// +stateify savable
type system3 struct {
v1 interface{}
v2 interface{}
v3 interface{}
v1 any
v2 any
v3 any
}
+8 -8
View File
@@ -20,36 +20,36 @@ import (
)
func TestEmptyStruct(t *testing.T) {
runTestCases(t, false, "plain", []interface{}{
runTestCases(t, false, "plain", []any{
unregisteredEmptyStruct{},
typeOnlyEmptyStruct{},
savableEmptyStruct{},
})
runTestCases(t, false, "pointers", pointersTo([]interface{}{
runTestCases(t, false, "pointers", pointersTo([]any{
unregisteredEmptyStruct{},
typeOnlyEmptyStruct{},
savableEmptyStruct{},
}))
runTestCases(t, false, "interfaces-pass", interfacesTo([]interface{}{
runTestCases(t, false, "interfaces-pass", interfacesTo([]any{
// Only registered types can be dispatched via interfaces. All
// other types should fail, even if it is the empty struct.
savableEmptyStruct{},
}))
runTestCases(t, true, "interfaces-fail", interfacesTo([]interface{}{
runTestCases(t, true, "interfaces-fail", interfacesTo([]any{
unregisteredEmptyStruct{},
typeOnlyEmptyStruct{},
}))
runTestCases(t, false, "interfacesToPointers-pass", interfacesTo(pointersTo([]interface{}{
runTestCases(t, false, "interfacesToPointers-pass", interfacesTo(pointersTo([]any{
savableEmptyStruct{},
})))
runTestCases(t, true, "interfacesToPointers-fail", interfacesTo(pointersTo([]interface{}{
runTestCases(t, true, "interfacesToPointers-fail", interfacesTo(pointersTo([]any{
unregisteredEmptyStruct{},
typeOnlyEmptyStruct{},
})))
// Ensuring empty struct aliasing works.
es := emptyStructPointer{new(struct{})}
runTestCases(t, false, "empty-struct-pointers", []interface{}{
runTestCases(t, false, "empty-struct-pointers", []any{
emptyStructPointer{},
es,
[]emptyStructPointer{es, es}, // Same pointer.
@@ -75,7 +75,7 @@ func TestEmbeddedPointers(t *testing.T) {
osl := outerSlice{oa.inner[:]}
ofv := outerFieldValue{innerFieldValue{magic()}}
runTestCases(t, false, "embedded-pointers", []interface{}{
runTestCases(t, false, "embedded-pointers", []any{
system{&ofs, &ofs.inner},
system{&ofs.inner, &ofs},
system{&of1, &of1.inner},
+12 -12
View File
@@ -40,7 +40,7 @@ func (discard) WriteByte(byte) error { return nil }
//
// N.B. This only handles one level of dereferences for NaN. Otherwise we
// would need to fork the entire implementation of reflect.DeepEqual.
func checkEqual(root, loadedValue interface{}) bool {
func checkEqual(root, loadedValue any) bool {
if reflect.DeepEqual(root, loadedValue) {
return true
}
@@ -74,7 +74,7 @@ func checkEqual(root, loadedValue interface{}) bool {
}
// runTestCases runs a test for each object in objects.
func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []interface{}) {
func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []any) {
t.Helper()
for i, root := range objects {
t.Run(fmt.Sprintf("%s%d", prefix, i), func(t *testing.T) {
@@ -154,8 +154,8 @@ func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []interf
}
}
// convert converts the slice to an []interface{}.
func convert(v interface{}) (r []interface{}) {
// convert converts the slice to an []any.
func convert(v any) (r []any) {
s := reflect.ValueOf(v) // Must be slice.
for i := 0; i < s.Len(); i++ {
r = append(r, s.Index(i).Interface())
@@ -164,7 +164,7 @@ func convert(v interface{}) (r []interface{}) {
}
// flatten flattens multiple slices.
func flatten(vs ...interface{}) (r []interface{}) {
func flatten(vs ...any) (r []any) {
for _, v := range vs {
r = append(r, convert(v)...)
}
@@ -172,7 +172,7 @@ func flatten(vs ...interface{}) (r []interface{}) {
}
// filter maps from one slice to another.
func filter(vs interface{}, fn func(interface{}) (interface{}, bool)) (r []interface{}) {
func filter(vs any, fn func(any) (any, bool)) (r []any) {
s := reflect.ValueOf(vs)
for i := 0; i < s.Len(); i++ {
v, ok := fn(s.Index(i).Interface())
@@ -184,7 +184,7 @@ func filter(vs interface{}, fn func(interface{}) (interface{}, bool)) (r []inter
}
// combine combines objects in two slices as specified.
func combine(v1, v2 interface{}, fn func(_, _ interface{}) interface{}) (r []interface{}) {
func combine(v1, v2 any, fn func(_, _ any) any) (r []any) {
s1 := reflect.ValueOf(v1)
s2 := reflect.ValueOf(v2)
for i := 0; i < s1.Len(); i++ {
@@ -197,8 +197,8 @@ func combine(v1, v2 interface{}, fn func(_, _ interface{}) interface{}) (r []int
}
// pointersTo is a filter function that returns pointers.
func pointersTo(vs interface{}) []interface{} {
return filter(vs, func(o interface{}) (interface{}, bool) {
func pointersTo(vs any) []any {
return filter(vs, func(o any) (any, bool) {
v := reflect.New(reflect.TypeOf(o))
v.Elem().Set(reflect.ValueOf(o))
return v.Interface(), true
@@ -206,9 +206,9 @@ func pointersTo(vs interface{}) []interface{} {
}
// interfacesTo is a filter function that returns interface objects.
func interfacesTo(vs interface{}) []interface{} {
return filter(vs, func(o interface{}) (interface{}, bool) {
var v [1]interface{}
func interfacesTo(vs any) []any {
return filter(vs, func(o any) (any, bool) {
var v [1]any
v[0] = o
return v, true
})