Skip to content

Commit

Permalink
tools: rename interface{} to any in codegen
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed Mar 17, 2022
1 parent 0cf77eb commit 25d0ffa
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 35 deletions.
3 changes: 1 addition & 2 deletions doc/V3HighLevelDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

12 changes: 6 additions & 6 deletions examples/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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(),
}
Expand All @@ -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)
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion go/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions go/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/sqltypes/bind_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go/sqltypes/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go/test/utils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Top declaration:
//
// var mustMatch = testutils.MustMatchFn(
// []interface{}{ // types with unexported fields
// []any{ // types with unexported fields
// type1{},
// type2{},
// ...
Expand Down
2 changes: 1 addition & 1 deletion go/tools/asthelpergen/clone_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions go/tools/asthelpergen/equals_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/goyacc/goyacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/ci_workflow_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/rowlog/rowlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 25d0ffa

Please sign in to comment.