From 25d0ffa2a55b095d4c99feafa2a39d499a337794 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 17 Mar 2022 11:08:14 +0100 Subject: [PATCH] tools: rename interface{} to any in codegen Signed-off-by: Vicent Marti --- doc/V3HighLevelDesign.md | 3 +-- examples/demo/demo.go | 12 ++++++------ go.mod | 8 ++++---- go.sum | 15 ++++++++------- go/event/event.go | 2 +- go/event/event_test.go | 4 ++-- go/sqltypes/bind_variables.go | 2 +- go/sqltypes/testing.go | 4 ++-- go/test/utils/diff.go | 2 +- go/tools/asthelpergen/clone_gen.go | 2 +- go/tools/asthelpergen/equals_gen.go | 4 ++-- go/vt/sqlparser/goyacc/goyacc.go | 4 ++-- go/vt/vtgate/executor_select_test.go | 2 +- test.go | 2 +- test/ci_workflow_gen.go | 2 +- tools/rowlog/rowlog.go | 2 +- 16 files changed, 35 insertions(+), 35 deletions(-) diff --git a/doc/V3HighLevelDesign.md b/doc/V3HighLevelDesign.md index 4ed0959df06..6adef378a65 100644 --- a/doc/V3HighLevelDesign.md +++ b/doc/V3HighLevelDesign.md @@ -1678,7 +1678,7 @@ Currently, the AST contains only information parsed from the query. When we anal Since we need them again for resolving dependencies, we have to store them somewhere. We also have to retrieve the right one for each subquery. This gives rise to a dependency issue: Subqueries can be anywhere in the parse tree. So, it’s unnatural to have an outside data structure that points to various parts of the AST. -So, we make a compromise: we extend the Select structure and add a Symbols (interface{}) member to it. Every time we finish analyzing a subquery, we set the Symbols member to point to the symbol table. With this compromise, the rest of the code base will flow naturally while resolving dependencies. +So, we make a compromise: we extend the Select structure and add a Symbols (any) member to it. Every time we finish analyzing a subquery, we set the Symbols member to point to the symbol table. With this compromise, the rest of the code base will flow naturally while resolving dependencies. ## Plan generation @@ -1735,4 +1735,3 @@ Filter: ## Other expensive primitives The rest of the primitives have potentially unbounded memory consequences. For these, we’ll have to explore map-reduce based approaches. - diff --git a/examples/demo/demo.go b/examples/demo/demo.go index cf81aa4d834..54d7e8732ca 100644 --- a/examples/demo/demo.go +++ b/examples/demo/demo.go @@ -117,7 +117,7 @@ func exec(w http.ResponseWriter, req *http.Request) { } defer conn.Close() query := req.FormValue("query") - response := make(map[string]interface{}) + response := make(map[string]any) var queries []string // Clear existing log. @@ -157,14 +157,14 @@ func exec(w http.ResponseWriter, req *http.Request) { enc.Encode(response) } -func execQuery(conn *mysql.Conn, key, query, keyspace, shard string, response map[string]interface{}) { +func execQuery(conn *mysql.Conn, key, query, keyspace, shard string, response map[string]any) { if query == "" || query == "undefined" { return } if keyspace != "" { _, err := conn.ExecuteFetch(fmt.Sprintf("use `%v:%v`", keyspace, shard), 10000, true) if err != nil { - response[key] = map[string]interface{}{ + response[key] = map[string]any{ "title": key, "error": err.Error(), } @@ -183,7 +183,7 @@ func execQuery(conn *mysql.Conn, key, query, keyspace, shard string, response ma if strings.Contains(err.Error(), "doesn't exist") { return } - response[key] = map[string]interface{}{ + response[key] = map[string]any{ "title": title, "error": err.Error(), } @@ -193,7 +193,7 @@ func execQuery(conn *mysql.Conn, key, query, keyspace, shard string, response ma response[key] = resultToMap(title, qr) } -func resultToMap(title string, qr *sqltypes.Result) map[string]interface{} { +func resultToMap(title string, qr *sqltypes.Result) map[string]any { fields := make([]string, 0, len(qr.Fields)) for _, field := range qr.Fields { fields = append(fields, field.Name) @@ -215,7 +215,7 @@ func resultToMap(title string, qr *sqltypes.Result) map[string]interface{} { } rows = append(rows, srow) } - return map[string]interface{}{ + return map[string]any{ "title": title, "fields": fields, "rows": rows, diff --git a/go.mod b/go.mod index 18acc011456..f4944533831 100644 --- a/go.mod +++ b/go.mod @@ -91,15 +91,15 @@ require ( go.etcd.io/etcd/client/pkg/v3 v3.5.0 go.etcd.io/etcd/client/v3 v3.5.0 golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 - golang.org/x/mod v0.4.2 // indirect - golang.org/x/net v0.0.0-20210825183410-e898025ed96a + golang.org/x/mod v0.5.1 // indirect + golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b golang.org/x/text v0.3.7 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac - golang.org/x/tools v0.1.5 + golang.org/x/tools v0.1.9 google.golang.org/api v0.45.0 google.golang.org/genproto v0.0.0-20210701191553-46259e63a0a9 // indirect google.golang.org/grpc v1.39.0 diff --git a/go.sum b/go.sum index 3e55ebf5f83..1cd89ba40e8 100644 --- a/go.sum +++ b/go.sum @@ -850,8 +850,9 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -902,8 +903,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw= -golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1002,8 +1003,8 @@ golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1084,8 +1085,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= +golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/go/event/event.go b/go/event/event.go index b7258e076be..e568c4a7af3 100644 --- a/go/event/event.go +++ b/go/event/event.go @@ -70,7 +70,7 @@ be called when a value of type MyEvent is dispatched: In addition, listener functions that accept an interface type will be called for any dispatched value that implements the specified interface. A listener -that accepts interface{} will be called for every event type. Listeners can also +that accepts `any` will be called for every event type. Listeners can also accept pointer types, but they will only be called if the dispatch site calls Dispatch() on a pointer. */ diff --git a/go/event/event_test.go b/go/event/event_test.go index 082efd56369..36d4d56bf5d 100644 --- a/go/event/event_test.go +++ b/go/event/event_test.go @@ -93,10 +93,10 @@ func TestEmptyInterfaceListener(t *testing.T) { triggered := false AddListener(func(any) { triggered = true }) - Dispatch("this should match interface{}") + Dispatch("this should match any") if !triggered { - t.Errorf("interface{} listener failed to trigger") + t.Errorf("any listener failed to trigger") } } diff --git a/go/sqltypes/bind_variables.go b/go/sqltypes/bind_variables.go index 8119ff4288e..ee3407c504a 100644 --- a/go/sqltypes/bind_variables.go +++ b/go/sqltypes/bind_variables.go @@ -50,7 +50,7 @@ func ProtoToValue(v *querypb.Value) Value { return MakeTrusted(v.Type, v.Value) } -// BuildBindVariables builds a map[string]*querypb.BindVariable from a map[string]interface{}. +// BuildBindVariables builds a map[string]*querypb.BindVariable from a map[string]any func BuildBindVariables(in map[string]any) (map[string]*querypb.BindVariable, error) { if len(in) == 0 { return nil, nil diff --git a/go/sqltypes/testing.go b/go/sqltypes/testing.go index cc15df11d06..83c991ba073 100644 --- a/go/sqltypes/testing.go +++ b/go/sqltypes/testing.go @@ -110,8 +110,8 @@ func MakeTestStreamingResults(fields []*querypb.Field, rows ...string) []*Result return results } -// TestBindVariable makes a *querypb.BindVariable from -// an interface{}.It panics on invalid input. +// TestBindVariable makes a *querypb.BindVariable from any. +// It panics on invalid input. // This function should only be used for testing. func TestBindVariable(v any) *querypb.BindVariable { if v == nil { diff --git a/go/test/utils/diff.go b/go/test/utils/diff.go index bfe22243cf5..1f988dcbbb9 100644 --- a/go/test/utils/diff.go +++ b/go/test/utils/diff.go @@ -33,7 +33,7 @@ import ( // Top declaration: // // var mustMatch = testutils.MustMatchFn( -// []interface{}{ // types with unexported fields +// []any{ // types with unexported fields // type1{}, // type2{}, // ... diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 0b8a43d7eeb..381a698405a 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -62,7 +62,7 @@ func (c *cloneGen) readValueOfType(t types.Type, expr jen.Code, spi generatorSPI case *types.Basic: return expr case *types.Interface: - if types.TypeString(t, noQualifier) == "interface{}" { + if types.TypeString(t, noQualifier) == "any" { // these fields have to be taken care of manually return expr } diff --git a/go/tools/asthelpergen/equals_gen.go b/go/tools/asthelpergen/equals_gen.go index 93125ebcd37..68bb9272346 100644 --- a/go/tools/asthelpergen/equals_gen.go +++ b/go/tools/asthelpergen/equals_gen.go @@ -147,8 +147,8 @@ func compareAllStructFields(strct *types.Struct, spi generatorSPI) jen.Code { var others []*jen.Statement for i := 0; i < strct.NumFields(); i++ { field := strct.Field(i) - if field.Type().Underlying().String() == "interface{}" || field.Name() == "_" { - // we can safely ignore this, we do not want ast to contain interface{} types. + if field.Type().Underlying().String() == "any" || field.Name() == "_" { + // we can safely ignore this, we do not want ast to contain `any` types. continue } fieldA := jen.Id("a").Dot(field.Name()) diff --git a/go/vt/sqlparser/goyacc/goyacc.go b/go/vt/sqlparser/goyacc/goyacc.go index 60a9fcdb89e..16837149d9d 100644 --- a/go/vt/sqlparser/goyacc/goyacc.go +++ b/go/vt/sqlparser/goyacc/goyacc.go @@ -1087,7 +1087,7 @@ func typeinfo() { fmt.Fprintf(ftable, "type %sSymType struct {", prefix) for _, tt := range gotypes { if tt.union { - fmt.Fprintf(ftable, "\n\tunion interface{}") + fmt.Fprintf(ftable, "\n\tunion any") break } } @@ -3425,7 +3425,7 @@ var yaccpar string // will be processed version of yaccpartext: s/$$/prefix/g var yaccpartext = ` /* parser for yacc output */ -func $$Iaddr(v interface{}) __yyunsafe__.Pointer { +func $$Iaddr(v any) __yyunsafe__.Pointer { type h struct { t __yyunsafe__.Pointer p __yyunsafe__.Pointer diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index a07d64b8f60..a6807c7b755 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -1285,7 +1285,7 @@ func TestSelectIN(t *testing.T) { utils.MustMatch(t, wantQueries, sbc2.Queries) // In is a bind variable list, that will end up on two shards. - // This is using an []interface{} for the bind variable list. + // This is using []any for the bind variable list. sbc1.Queries = nil sbc2.Queries = nil _, err = executorExec(executor, "select id from user where id in ::vals", map[string]*querypb.BindVariable{ diff --git a/test.go b/test.go index 43e427dfbc9..698ba85afba 100755 --- a/test.go +++ b/test.go @@ -243,7 +243,7 @@ func (t *Test) run(dir, dataDir string) ([]byte, error) { return buf.Bytes(), runErr } -func (t *Test) logf(format string, v ...interface{}) { +func (t *Test) logf(format string, v ...any) { if *runCount > 1 { log.Printf("%v.%v[%v/%v]: %v", t.flavor, t.name, t.runIndex+1, *runCount, fmt.Sprintf(format, v...)) } else { diff --git a/test/ci_workflow_gen.go b/test/ci_workflow_gen.go index a6c1ff10d01..5492c27c477 100644 --- a/test/ci_workflow_gen.go +++ b/test/ci_workflow_gen.go @@ -356,7 +356,7 @@ func setupTestDockerFile(test *selfHostedTest) error { return nil } -func writeFileFromTemplate(templateFile, path string, test interface{}) error { +func writeFileFromTemplate(templateFile, path string, test any) error { tpl, err := template.ParseFiles(templateFile) if err != nil { return fmt.Errorf("Error: %s\n", err) diff --git a/tools/rowlog/rowlog.go b/tools/rowlog/rowlog.go index c2c6680f33b..61ae6f500a5 100644 --- a/tools/rowlog/rowlog.go +++ b/tools/rowlog/rowlog.go @@ -424,7 +424,7 @@ func processPositionResult(gtidset string) (string, string) { // hack, should read json in a structured manner func parseExecOutput(result string) string { - resultMap := make(map[string]interface{}) + resultMap := make(map[string]any) err := json.Unmarshal([]byte(result), &resultMap) if err != nil { fmt.Errorf("error parsing result json %s", result)