diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 49f6f4a1..4df5d0d2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ on: branches: [master] env: - GO_VERSION: "1.14" + GO_VERSION: "1.18" jobs: lint: @@ -29,7 +29,7 @@ jobs: - name: Check goimports if: ${{ always() }} run: | - go install golang.org/x/tools/cmd/goimports + go install golang.org/x/tools/cmd/goimports@v0.1.10 if [[ $(goimports -l cmd internal pkg) ]]; then echo 'Please run `goimports -w cmd internal pkg`.' false @@ -47,13 +47,13 @@ jobs: - name: Check for license headers if: ${{ always() }} run: | - go get -u github.com/google/addlicense + go install github.com/google/addlicense@v1.0.0 addlicense -check cmd internal pkg - name: Run staticcheck if: ${{ always() }} run: | - go install honnef.co/go/tools/cmd/staticcheck + go install honnef.co/go/tools/cmd/staticcheck@v0.3.1 staticcheck ./... - name: Check YAML diff --git a/go.mod b/go.mod index ae8ac5f8..c70e3732 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,17 @@ module github.com/google/go-flow-levee -go 1.14 +go 1.18 require ( github.com/google/go-cmp v0.5.2 - golang.org/x/tools v0.0.0-20200416214402-fc959738d646 + golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171 + golang.org/x/tools v0.1.11-0.20220504225841-45c8a7131235 sigs.k8s.io/yaml v1.2.0 ) + +require ( + golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect + gopkg.in/yaml.v2 v2.2.8 // indirect +) diff --git a/go.sum b/go.sum index 269efb6a..036b2eaa 100644 --- a/go.sum +++ b/go.sum @@ -2,24 +2,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200416214402-fc959738d646 h1:7CEkhBsBejkW845gR1AmglqMfc1yGzn42FBmtM4jxyM= -golang.org/x/tools v0.0.0-20200416214402-fc959738d646/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -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/exp/typeparams v0.0.0-20220428152302-39d4317da171 h1:DZhP7zSquENyG3Yb6ZpGqNEtgE8dfXhcLcheIF9RQHY= +golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +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/tools v0.1.11-0.20220504225841-45c8a7131235 h1:crlaTzOCJe82TDDRppEHbWCLjV9WU+uEPhpF07euMnI= +golang.org/x/tools v0.1.11-0.20220504225841-45c8a7131235/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/internal/pkg/debug/render/testdata/TestClosure.ssa b/internal/pkg/debug/render/testdata/TestClosure.ssa index f8cf5d34..0cd46984 100644 --- a/internal/pkg/debug/render/testdata/TestClosure.ssa +++ b/internal/pkg/debug/render/testdata/TestClosure.ssa @@ -4,9 +4,9 @@ func TestClosure() 1(*ssa.Return ): return func TestClosure$1(x int) 0: entry - 0(*ssa.Alloc ): t0 = new [1]interface{} (varargs) + 0(*ssa.Alloc ): t0 = new [1]any (varargs) 1(*ssa.IndexAddr ): t1 = &t0[0:int] - 2(*ssa.MakeInterface ): t2 = make interface{} <- int (x) + 2(*ssa.MakeInterface ): t2 = make any <- int (x) 3(*ssa.Store ): *t1 = t2 4(*ssa.Slice ): t3 = slice t0[:] 5(*ssa.Call ): t4 = fmt.Println(t3...) diff --git a/internal/pkg/debug/render/testdata/TestDisconnected.dot b/internal/pkg/debug/render/testdata/TestDisconnected.dot index 96fc6aef..f19aba61 100644 --- a/internal/pkg/debug/render/testdata/TestDisconnected.dot +++ b/internal/pkg/debug/render/testdata/TestDisconnected.dot @@ -15,7 +15,7 @@ digraph { color=black; label="for.done"; "t2 = \"error: \":string + \"unreachable code\":string\n(BinOp)" [shape=rectangle]; - "t3 = fmt.Printf(t2, nil:[]interface{}...)\n(Call)" [shape=rectangle]; + "t3 = fmt.Printf(t2, nil:[]any...)\n(Call)" [shape=rectangle]; "return\n(Return)" [shape=diamond]; } subgraph cluster_3 { @@ -32,9 +32,9 @@ digraph { "1:int\n(Const)" -> "t1 = t0 + 1:int\n(BinOp)" [color=orange]; "\"error: \":string\n(Const)" -> "t2 = \"error: \":string + \"unreachable code\":string\n(BinOp)" [color=orange]; "\"unreachable code\":string\n(Const)" -> "t2 = \"error: \":string + \"unreachable code\":string\n(BinOp)" [color=orange]; - "Printf\n(Function)" -> "t3 = fmt.Printf(t2, nil:[]interface{}...)\n(Call)" [color=orange]; - "t2 = \"error: \":string + \"unreachable code\":string\n(BinOp)" -> "t3 = fmt.Printf(t2, nil:[]interface{}...)\n(Call)" [color=orange]; - "nil:[]interface{}\n(Const)" -> "t3 = fmt.Printf(t2, nil:[]interface{}...)\n(Call)" [color=orange]; + "Printf\n(Function)" -> "t3 = fmt.Printf(t2, nil:[]any...)\n(Call)" [color=orange]; + "t2 = \"error: \":string + \"unreachable code\":string\n(BinOp)" -> "t3 = fmt.Printf(t2, nil:[]any...)\n(Call)" [color=orange]; + "nil:[]any\n(Const)" -> "t3 = fmt.Printf(t2, nil:[]any...)\n(Call)" [color=orange]; "0:int\n(Const)" -> "t4 = phi [0: 0:int, 1: t1] #i\n(Phi)" [color=orange]; "t1 = t0 + 1:int\n(BinOp)" -> "t4 = phi [0: 0:int, 1: t1] #i\n(Phi)" [color=orange]; "1:int\n(Const)" -> "t5 = 1:int * 2:int\n(BinOp)" [color=orange]; diff --git a/internal/pkg/debug/render/testdata/TestDisconnected.ssa b/internal/pkg/debug/render/testdata/TestDisconnected.ssa index 836c1187..491d11ac 100644 --- a/internal/pkg/debug/render/testdata/TestDisconnected.ssa +++ b/internal/pkg/debug/render/testdata/TestDisconnected.ssa @@ -12,5 +12,5 @@ func TestDisconnected() 2(*ssa.Jump ): jump 3 3: for.done 0(*ssa.BinOp ): t2 = "error: ":string + "unreachable code":string - 1(*ssa.Call ): t3 = fmt.Printf(t2, nil:[]interface{}...) + 1(*ssa.Call ): t3 = fmt.Printf(t2, nil:[]any...) 2(*ssa.Return ): return diff --git a/internal/pkg/debug/render/testdata/TestMultiBlock.dot b/internal/pkg/debug/render/testdata/TestMultiBlock.dot index 013356a3..93087bee 100644 --- a/internal/pkg/debug/render/testdata/TestMultiBlock.dot +++ b/internal/pkg/debug/render/testdata/TestMultiBlock.dot @@ -28,9 +28,9 @@ digraph { subgraph cluster_3 { color=black; label="if.else"; - "t9 = new [1]interface{} (varargs)\n(Alloc)" [shape=rectangle]; + "t9 = new [1]any (varargs)\n(Alloc)" [shape=rectangle]; "t10 = &t9[0:int]\n(IndexAddr)" [shape=rectangle]; - "t11 = make interface{} <- string (\"somewhere\":string)\n(MakeInterface)" [shape=rectangle]; + "t11 = make any <- string (\"somewhere\":string)\n(MakeInterface)" [shape=rectangle]; "*t10 = t11\n(Store)" [shape=diamond]; "t12 = slice t9[:]\n(Slice)" [shape=rectangle]; "t13 = fmt.Println(t12...)\n(Call)" [shape=rectangle]; @@ -43,12 +43,12 @@ digraph { "t15 = *t14\n(UnOp)" [shape=rectangle]; "t16 = &t0.Y [#1]\n(FieldAddr)" [shape=rectangle]; "t17 = *t16\n(UnOp)" [shape=rectangle]; - "t18 = new [2]interface{} (varargs)\n(Alloc)" [shape=rectangle]; + "t18 = new [2]any (varargs)\n(Alloc)" [shape=rectangle]; "t19 = &t18[0:int]\n(IndexAddr)" [shape=rectangle]; - "t20 = make interface{} <- int (t15)\n(MakeInterface)" [shape=rectangle]; + "t20 = make any <- int (t15)\n(MakeInterface)" [shape=rectangle]; "*t19 = t20\n(Store)" [shape=diamond]; "t21 = &t18[1:int]\n(IndexAddr)" [shape=rectangle]; - "t22 = make interface{} <- int (t17)\n(MakeInterface)" [shape=rectangle]; + "t22 = make any <- int (t17)\n(MakeInterface)" [shape=rectangle]; "*t21 = t22\n(Store)" [shape=diamond]; "t23 = slice t18[:]\n(Slice)" [shape=rectangle]; "t24 = fmt.Printf(\"in top right quad...\":string, t23...)\n(Call)" [shape=rectangle]; @@ -70,29 +70,29 @@ digraph { "t7 = *t6\n(UnOp)" -> "t8 = t7 > 0:int\n(BinOp)" [color=orange]; "0:int\n(Const)" -> "t8 = t7 > 0:int\n(BinOp)" [color=orange]; "t8 = t7 > 0:int\n(BinOp)" -> "if t8 goto 4 else 2\n(If)" [color=orange]; - "t9 = new [1]interface{} (varargs)\n(Alloc)" -> "t10 = &t9[0:int]\n(IndexAddr)" [color=orange]; + "t9 = new [1]any (varargs)\n(Alloc)" -> "t10 = &t9[0:int]\n(IndexAddr)" [color=orange]; "0:int\n(Const)" -> "t10 = &t9[0:int]\n(IndexAddr)" [color=orange]; - "\"somewhere\":string\n(Const)" -> "t11 = make interface{} <- string (\"somewhere\":string)\n(MakeInterface)" [color=orange]; + "\"somewhere\":string\n(Const)" -> "t11 = make any <- string (\"somewhere\":string)\n(MakeInterface)" [color=orange]; "t10 = &t9[0:int]\n(IndexAddr)" -> "*t10 = t11\n(Store)" [color=orange]; - "t11 = make interface{} <- string (\"somewhere\":string)\n(MakeInterface)" -> "*t10 = t11\n(Store)" [color=orange]; - "t9 = new [1]interface{} (varargs)\n(Alloc)" -> "t12 = slice t9[:]\n(Slice)" [color=orange]; + "t11 = make any <- string (\"somewhere\":string)\n(MakeInterface)" -> "*t10 = t11\n(Store)" [color=orange]; + "t9 = new [1]any (varargs)\n(Alloc)" -> "t12 = slice t9[:]\n(Slice)" [color=orange]; "Println\n(Function)" -> "t13 = fmt.Println(t12...)\n(Call)" [color=orange]; "t12 = slice t9[:]\n(Slice)" -> "t13 = fmt.Println(t12...)\n(Call)" [color=orange]; "t0 = local image.Point (p)\n(Alloc)" -> "t14 = &t0.X [#0]\n(FieldAddr)" [color=orange]; "t14 = &t0.X [#0]\n(FieldAddr)" -> "t15 = *t14\n(UnOp)" [color=orange]; "t0 = local image.Point (p)\n(Alloc)" -> "t16 = &t0.Y [#1]\n(FieldAddr)" [color=orange]; "t16 = &t0.Y [#1]\n(FieldAddr)" -> "t17 = *t16\n(UnOp)" [color=orange]; - "t18 = new [2]interface{} (varargs)\n(Alloc)" -> "t19 = &t18[0:int]\n(IndexAddr)" [color=orange]; + "t18 = new [2]any (varargs)\n(Alloc)" -> "t19 = &t18[0:int]\n(IndexAddr)" [color=orange]; "0:int\n(Const)" -> "t19 = &t18[0:int]\n(IndexAddr)" [color=orange]; - "t15 = *t14\n(UnOp)" -> "t20 = make interface{} <- int (t15)\n(MakeInterface)" [color=orange]; + "t15 = *t14\n(UnOp)" -> "t20 = make any <- int (t15)\n(MakeInterface)" [color=orange]; "t19 = &t18[0:int]\n(IndexAddr)" -> "*t19 = t20\n(Store)" [color=orange]; - "t20 = make interface{} <- int (t15)\n(MakeInterface)" -> "*t19 = t20\n(Store)" [color=orange]; - "t18 = new [2]interface{} (varargs)\n(Alloc)" -> "t21 = &t18[1:int]\n(IndexAddr)" [color=orange]; + "t20 = make any <- int (t15)\n(MakeInterface)" -> "*t19 = t20\n(Store)" [color=orange]; + "t18 = new [2]any (varargs)\n(Alloc)" -> "t21 = &t18[1:int]\n(IndexAddr)" [color=orange]; "1:int\n(Const)" -> "t21 = &t18[1:int]\n(IndexAddr)" [color=orange]; - "t17 = *t16\n(UnOp)" -> "t22 = make interface{} <- int (t17)\n(MakeInterface)" [color=orange]; + "t17 = *t16\n(UnOp)" -> "t22 = make any <- int (t17)\n(MakeInterface)" [color=orange]; "t21 = &t18[1:int]\n(IndexAddr)" -> "*t21 = t22\n(Store)" [color=orange]; - "t22 = make interface{} <- int (t17)\n(MakeInterface)" -> "*t21 = t22\n(Store)" [color=orange]; - "t18 = new [2]interface{} (varargs)\n(Alloc)" -> "t23 = slice t18[:]\n(Slice)" [color=orange]; + "t22 = make any <- int (t17)\n(MakeInterface)" -> "*t21 = t22\n(Store)" [color=orange]; + "t18 = new [2]any (varargs)\n(Alloc)" -> "t23 = slice t18[:]\n(Slice)" [color=orange]; "Printf\n(Function)" -> "t24 = fmt.Printf(\"in top right quad...\":string, t23...)\n(Call)" [color=orange]; "\"in top right quad...\":string\n(Const)" -> "t24 = fmt.Printf(\"in top right quad...\":string, t23...)\n(Call)" [color=orange]; "t23 = slice t18[:]\n(Slice)" -> "t24 = fmt.Printf(\"in top right quad...\":string, t23...)\n(Call)" [color=orange]; diff --git a/internal/pkg/debug/render/testdata/TestMultiBlock.ssa b/internal/pkg/debug/render/testdata/TestMultiBlock.ssa index 385ef0f7..2b72d4cf 100644 --- a/internal/pkg/debug/render/testdata/TestMultiBlock.ssa +++ b/internal/pkg/debug/render/testdata/TestMultiBlock.ssa @@ -19,12 +19,12 @@ func TestMultiBlock() 1(*ssa.UnOp ): t15 = *t14 2(*ssa.FieldAddr ): t16 = &t0.Y [#1] 3(*ssa.UnOp ): t17 = *t16 - 4(*ssa.Alloc ): t18 = new [2]interface{} (varargs) + 4(*ssa.Alloc ): t18 = new [2]any (varargs) 5(*ssa.IndexAddr ): t19 = &t18[0:int] - 6(*ssa.MakeInterface ): t20 = make interface{} <- int (t15) + 6(*ssa.MakeInterface ): t20 = make any <- int (t15) 7(*ssa.Store ): *t19 = t20 8(*ssa.IndexAddr ): t21 = &t18[1:int] - 9(*ssa.MakeInterface ): t22 = make interface{} <- int (t17) + 9(*ssa.MakeInterface ): t22 = make any <- int (t17) 10(*ssa.Store ): *t21 = t22 11(*ssa.Slice ): t23 = slice t18[:] 12(*ssa.Call ): t24 = fmt.Printf("in top right quad...":string, t23...) @@ -32,9 +32,9 @@ func TestMultiBlock() 3: if.done 0(*ssa.Return ): return 4: if.else - 0(*ssa.Alloc ): t9 = new [1]interface{} (varargs) + 0(*ssa.Alloc ): t9 = new [1]any (varargs) 1(*ssa.IndexAddr ): t10 = &t9[0:int] - 2(*ssa.MakeInterface ): t11 = make interface{} <- string ("somewhere":string) + 2(*ssa.MakeInterface ): t11 = make any <- string ("somewhere":string) 3(*ssa.Store ): *t10 = t11 4(*ssa.Slice ): t12 = slice t9[:] 5(*ssa.Call ): t13 = fmt.Println(t12...) diff --git a/internal/pkg/debug/render/testdata/TestParams.dot b/internal/pkg/debug/render/testdata/TestParams.dot index 046a2a41..d3186581 100644 --- a/internal/pkg/debug/render/testdata/TestParams.dot +++ b/internal/pkg/debug/render/testdata/TestParams.dot @@ -2,36 +2,36 @@ digraph { subgraph cluster_0 { color=black; label="entry"; - "t0 = new [3]interface{} (varargs)\n(Alloc)" [shape=rectangle]; + "t0 = new [3]any (varargs)\n(Alloc)" [shape=rectangle]; "t1 = &t0[0:int]\n(IndexAddr)" [shape=rectangle]; - "t2 = make interface{} <- int (a)\n(MakeInterface)" [shape=rectangle]; + "t2 = make any <- int (a)\n(MakeInterface)" [shape=rectangle]; "*t1 = t2\n(Store)" [shape=diamond]; "t3 = &t0[1:int]\n(IndexAddr)" [shape=rectangle]; - "t4 = make interface{} <- int (b)\n(MakeInterface)" [shape=rectangle]; + "t4 = make any <- int (b)\n(MakeInterface)" [shape=rectangle]; "*t3 = t4\n(Store)" [shape=diamond]; "t5 = &t0[2:int]\n(IndexAddr)" [shape=rectangle]; - "t6 = make interface{} <- string (c)\n(MakeInterface)" [shape=rectangle]; + "t6 = make any <- string (c)\n(MakeInterface)" [shape=rectangle]; "*t5 = t6\n(Store)" [shape=diamond]; "t7 = slice t0[:]\n(Slice)" [shape=rectangle]; "t8 = fmt.Println(t7...)\n(Call)" [shape=rectangle]; "return\n(Return)" [shape=diamond]; } - "t0 = new [3]interface{} (varargs)\n(Alloc)" -> "t1 = &t0[0:int]\n(IndexAddr)" [color=orange]; + "t0 = new [3]any (varargs)\n(Alloc)" -> "t1 = &t0[0:int]\n(IndexAddr)" [color=orange]; "0:int\n(Const)" -> "t1 = &t0[0:int]\n(IndexAddr)" [color=orange]; - "a\n(Parameter)" -> "t2 = make interface{} <- int (a)\n(MakeInterface)" [color=orange]; + "a\n(Parameter)" -> "t2 = make any <- int (a)\n(MakeInterface)" [color=orange]; "t1 = &t0[0:int]\n(IndexAddr)" -> "*t1 = t2\n(Store)" [color=orange]; - "t2 = make interface{} <- int (a)\n(MakeInterface)" -> "*t1 = t2\n(Store)" [color=orange]; - "t0 = new [3]interface{} (varargs)\n(Alloc)" -> "t3 = &t0[1:int]\n(IndexAddr)" [color=orange]; + "t2 = make any <- int (a)\n(MakeInterface)" -> "*t1 = t2\n(Store)" [color=orange]; + "t0 = new [3]any (varargs)\n(Alloc)" -> "t3 = &t0[1:int]\n(IndexAddr)" [color=orange]; "1:int\n(Const)" -> "t3 = &t0[1:int]\n(IndexAddr)" [color=orange]; - "b\n(Parameter)" -> "t4 = make interface{} <- int (b)\n(MakeInterface)" [color=orange]; + "b\n(Parameter)" -> "t4 = make any <- int (b)\n(MakeInterface)" [color=orange]; "t3 = &t0[1:int]\n(IndexAddr)" -> "*t3 = t4\n(Store)" [color=orange]; - "t4 = make interface{} <- int (b)\n(MakeInterface)" -> "*t3 = t4\n(Store)" [color=orange]; - "t0 = new [3]interface{} (varargs)\n(Alloc)" -> "t5 = &t0[2:int]\n(IndexAddr)" [color=orange]; + "t4 = make any <- int (b)\n(MakeInterface)" -> "*t3 = t4\n(Store)" [color=orange]; + "t0 = new [3]any (varargs)\n(Alloc)" -> "t5 = &t0[2:int]\n(IndexAddr)" [color=orange]; "2:int\n(Const)" -> "t5 = &t0[2:int]\n(IndexAddr)" [color=orange]; - "c\n(Parameter)" -> "t6 = make interface{} <- string (c)\n(MakeInterface)" [color=orange]; + "c\n(Parameter)" -> "t6 = make any <- string (c)\n(MakeInterface)" [color=orange]; "t5 = &t0[2:int]\n(IndexAddr)" -> "*t5 = t6\n(Store)" [color=orange]; - "t6 = make interface{} <- string (c)\n(MakeInterface)" -> "*t5 = t6\n(Store)" [color=orange]; - "t0 = new [3]interface{} (varargs)\n(Alloc)" -> "t7 = slice t0[:]\n(Slice)" [color=orange]; + "t6 = make any <- string (c)\n(MakeInterface)" -> "*t5 = t6\n(Store)" [color=orange]; + "t0 = new [3]any (varargs)\n(Alloc)" -> "t7 = slice t0[:]\n(Slice)" [color=orange]; "Println\n(Function)" -> "t8 = fmt.Println(t7...)\n(Call)" [color=orange]; "t7 = slice t0[:]\n(Slice)" -> "t8 = fmt.Println(t7...)\n(Call)" [color=orange]; } diff --git a/internal/pkg/debug/render/testdata/TestParams.ssa b/internal/pkg/debug/render/testdata/TestParams.ssa index 6bd6eb7f..34e311d6 100644 --- a/internal/pkg/debug/render/testdata/TestParams.ssa +++ b/internal/pkg/debug/render/testdata/TestParams.ssa @@ -1,14 +1,14 @@ func TestParams(a int, b int, c string) 0: entry - 0(*ssa.Alloc ): t0 = new [3]interface{} (varargs) + 0(*ssa.Alloc ): t0 = new [3]any (varargs) 1(*ssa.IndexAddr ): t1 = &t0[0:int] - 2(*ssa.MakeInterface ): t2 = make interface{} <- int (a) + 2(*ssa.MakeInterface ): t2 = make any <- int (a) 3(*ssa.Store ): *t1 = t2 4(*ssa.IndexAddr ): t3 = &t0[1:int] - 5(*ssa.MakeInterface ): t4 = make interface{} <- int (b) + 5(*ssa.MakeInterface ): t4 = make any <- int (b) 6(*ssa.Store ): *t3 = t4 7(*ssa.IndexAddr ): t5 = &t0[2:int] - 8(*ssa.MakeInterface ): t6 = make interface{} <- string (c) + 8(*ssa.MakeInterface ): t6 = make any <- string (c) 9(*ssa.Store ): *t5 = t6 10(*ssa.Slice ): t7 = slice t0[:] 11(*ssa.Call ): t8 = fmt.Println(t7...) diff --git a/internal/pkg/debug/render/testdata/TestSingleBlock.dot b/internal/pkg/debug/render/testdata/TestSingleBlock.dot index afaa2d80..fe8f557e 100644 --- a/internal/pkg/debug/render/testdata/TestSingleBlock.dot +++ b/internal/pkg/debug/render/testdata/TestSingleBlock.dot @@ -16,9 +16,9 @@ digraph { "t7 = &t0.Y [#1]\n(FieldAddr)" [shape=rectangle]; "t8 = *t7\n(UnOp)" [shape=rectangle]; "t9 = t6 + t8\n(BinOp)" [shape=rectangle]; - "t10 = new [1]interface{} (varargs)\n(Alloc)" [shape=rectangle]; + "t10 = new [1]any (varargs)\n(Alloc)" [shape=rectangle]; "t11 = &t10[0:int]\n(IndexAddr)" [shape=rectangle]; - "t12 = make interface{} <- int (t9)\n(MakeInterface)" [shape=rectangle]; + "t12 = make any <- int (t9)\n(MakeInterface)" [shape=rectangle]; "*t11 = t12\n(Store)" [shape=diamond]; "t13 = slice t10[:]\n(Slice)" [shape=rectangle]; "t14 = fmt.Println(t13...)\n(Call)" [shape=rectangle]; @@ -42,12 +42,12 @@ digraph { "t7 = &t0.Y [#1]\n(FieldAddr)" -> "t8 = *t7\n(UnOp)" [color=orange]; "t6 = *t5\n(UnOp)" -> "t9 = t6 + t8\n(BinOp)" [color=orange]; "t8 = *t7\n(UnOp)" -> "t9 = t6 + t8\n(BinOp)" [color=orange]; - "t10 = new [1]interface{} (varargs)\n(Alloc)" -> "t11 = &t10[0:int]\n(IndexAddr)" [color=orange]; + "t10 = new [1]any (varargs)\n(Alloc)" -> "t11 = &t10[0:int]\n(IndexAddr)" [color=orange]; "0:int\n(Const)" -> "t11 = &t10[0:int]\n(IndexAddr)" [color=orange]; - "t9 = t6 + t8\n(BinOp)" -> "t12 = make interface{} <- int (t9)\n(MakeInterface)" [color=orange]; + "t9 = t6 + t8\n(BinOp)" -> "t12 = make any <- int (t9)\n(MakeInterface)" [color=orange]; "t11 = &t10[0:int]\n(IndexAddr)" -> "*t11 = t12\n(Store)" [color=orange]; - "t12 = make interface{} <- int (t9)\n(MakeInterface)" -> "*t11 = t12\n(Store)" [color=orange]; - "t10 = new [1]interface{} (varargs)\n(Alloc)" -> "t13 = slice t10[:]\n(Slice)" [color=orange]; + "t12 = make any <- int (t9)\n(MakeInterface)" -> "*t11 = t12\n(Store)" [color=orange]; + "t10 = new [1]any (varargs)\n(Alloc)" -> "t13 = slice t10[:]\n(Slice)" [color=orange]; "Println\n(Function)" -> "t14 = fmt.Println(t13...)\n(Call)" [color=orange]; "t13 = slice t10[:]\n(Slice)" -> "t14 = fmt.Println(t13...)\n(Call)" [color=orange]; } diff --git a/internal/pkg/debug/render/testdata/TestSingleBlock.ssa b/internal/pkg/debug/render/testdata/TestSingleBlock.ssa index 906752c7..04d574a4 100644 --- a/internal/pkg/debug/render/testdata/TestSingleBlock.ssa +++ b/internal/pkg/debug/render/testdata/TestSingleBlock.ssa @@ -14,9 +14,9 @@ func TestSingleBlock() 11(*ssa.FieldAddr ): t7 = &t0.Y [#1] 12(*ssa.UnOp ): t8 = *t7 13(*ssa.BinOp ): t9 = t6 + t8 - 14(*ssa.Alloc ): t10 = new [1]interface{} (varargs) + 14(*ssa.Alloc ): t10 = new [1]any (varargs) 15(*ssa.IndexAddr ): t11 = &t10[0:int] - 16(*ssa.MakeInterface ): t12 = make interface{} <- int (t9) + 16(*ssa.MakeInterface ): t12 = make any <- int (t9) 17(*ssa.Store ): *t11 = t12 18(*ssa.Slice ): t13 = slice t10[:] 19(*ssa.Call ): t14 = fmt.Println(t13...) diff --git a/internal/pkg/earpointer/analysis_test.go b/internal/pkg/earpointer/analysis_test.go index b2e8ea93..a9897811 100644 --- a/internal/pkg/earpointer/analysis_test.go +++ b/internal/pkg/earpointer/analysis_test.go @@ -1201,11 +1201,11 @@ func TestMethodInvoke(t *testing.T) { // Note that in "**T2", the first "*" is the synthesized ValueOf operator, // and "*T2" is the receiver type. want := concat(map[string]string{ - "{**T2:f.arg0}": "[T1->*T1:f.arg0]", + "{**T2:f.arg0}": "[T1->g.t0]", "{*T1:f.arg0,*T2:f.t0,g.t0}": "[]", "{*T1:f.x,*T2:f.x,g.x}": "[]", "{*T2:f.arg0}": "--> **T2:f.arg0", - "{*g.x2}": "[T1->*T1:f.arg0]", + "{*g.x2}": "[T1->g.t0]", "{g.x2}": "--> *g.x2", }) if got := state.String(); got != want { @@ -1382,3 +1382,21 @@ func TestCallReturnContextSensitive(t *testing.T) { t.Errorf("diff (-want +got):\n%s", diff) } } + +func TestGenerics(t *testing.T) { + code := `package p + type G[T any] struct{ x T } + func f[T any](a G[T]) T { + return a.x + } + ` + state, err := runCodeK0(code) + if err != nil { + t.Fatal(err) + } + // Generics are not fully supported yet. + want := "{f.a}: []" + if diff := cmp.Diff(want, state.String()); diff != "" { + t.Errorf("diff (-want +got):\n%s", diff) + } +} diff --git a/internal/pkg/earpointer/heap.go b/internal/pkg/earpointer/heap.go index ef5a89be..d7d3fa38 100644 --- a/internal/pkg/earpointer/heap.go +++ b/internal/pkg/earpointer/heap.go @@ -205,6 +205,9 @@ func typeMayShareObject(tp types.Type) bool { } case *types.Named: return typeMayShareObject(tp.Underlying()) + case *types.TypeParam, *types.Union: + // Generics are not resolved yet + return true } return false } diff --git a/internal/pkg/earpointer/taint.go b/internal/pkg/earpointer/taint.go index 25a50495..27219a4a 100644 --- a/internal/pkg/earpointer/taint.go +++ b/internal/pkg/earpointer/taint.go @@ -104,6 +104,8 @@ func (ht *heapTraversal) srcRefs(rep Reference, tp types.Type, result ReferenceS for _, r := range heap.PartitionFieldMap(rep) { ht.srcRefs(r, tp.Elem(), result) } + case *types.TypeParam, *types.Union: + // Generics are not resolved yet case *types.Basic, *types.Tuple, *types.Interface, *types.Signature: // These types do not currently represent possible source types } diff --git a/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go b/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go index 3484e985..a8cbb15c 100644 --- a/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go +++ b/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go @@ -28,18 +28,17 @@ func TestSourcePointerExtract() { // The field is extracted on its own line so we can differentiate between the struct's position // and the field's position. // The Source in this function is created by a FieldAddr that is not represented explicitly in the code. -// Indeed, es.Data is actually es.Source.Data. -// Because of this, we expect the report to be produced at the struct's position. +// Indeed, es.Data is actually es.Source.Data, and we expect the report to be produced at its position. func TestEmbeddedSourceFieldAddr() { es := EmbedsSource{} d := es.Data - core.Sink(d) // want "a source has reached a sink\n source: .*tests.go:34:2" + core.Sink(d) // want "a source has reached a sink\n source: .*tests.go:34:7" } // In order for the SSA to contain a Field, the EmbedsSource instance's fields must not be addressable. // One way to do this is to create a literal and to access the field directly, as part of the same expression. func TestEmbeddedSourceField() { - core.Sink(EmbedsSource{}.Data) // want "a source has reached a sink\n source: .*tests.go:42:24" + core.Sink(EmbedsSource{}.Data) // want "a source has reached a sink\n source: .*tests.go:41:12" } type EmbedsSource struct { diff --git a/internal/pkg/propagation/summary/summaries.go b/internal/pkg/propagation/summary/summaries.go index 8b2597d0..5208938d 100644 --- a/internal/pkg/propagation/summary/summaries.go +++ b/internal/pkg/propagation/summary/summaries.go @@ -737,7 +737,7 @@ var InterfaceFuncSummaries = map[funcKey]Summary{ IfTainted: first, TaintedRets: []int{0}, }, - {"Value", "(interface{})(interface{})"}: { + {"Value", "(any)(any)"}: { IfTainted: first, TaintedRets: []int{0}, }, diff --git a/internal/pkg/sourceinfer/analyzer.go b/internal/pkg/sourceinfer/analyzer.go index c20df477..328c8c42 100644 --- a/internal/pkg/sourceinfer/analyzer.go +++ b/internal/pkg/sourceinfer/analyzer.go @@ -27,6 +27,7 @@ import ( "github.com/google/go-flow-levee/internal/pkg/config" "github.com/google/go-flow-levee/internal/pkg/fieldtags" "github.com/google/go-flow-levee/internal/pkg/utils" + "golang.org/x/exp/typeparams" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/inspect" "golang.org/x/tools/go/ast/inspector" @@ -163,6 +164,8 @@ func findObjects(t types.Type) map[types.Object]bool { // these do not contain relevant objects case *types.Pointer: // this should be unreachable due to the dereference above + case *typeparams.TypeParam, *typeparams.Union: + // generics are not resolved yet default: // The above should be exhaustive. Reaching this default case is an error. fmt.Printf("unexpected type received: %T %v; please report this issue\n", tt, tt) diff --git a/internal/pkg/sourceinfer/testdata/src/example.com/tests/generics/test.go b/internal/pkg/sourceinfer/testdata/src/example.com/tests/generics/test.go new file mode 100644 index 00000000..5f11ffb1 --- /dev/null +++ b/internal/pkg/sourceinfer/testdata/src/example.com/tests/generics/test.go @@ -0,0 +1,20 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package generics + +type G[T any] struct{} + +func (G[T]) M(_ T) { +} diff --git a/internal/pkg/sourcetype/sourcetype.go b/internal/pkg/sourcetype/sourcetype.go index c80a2804..567edec8 100644 --- a/internal/pkg/sourcetype/sourcetype.go +++ b/internal/pkg/sourcetype/sourcetype.go @@ -19,6 +19,8 @@ import ( "fmt" "go/types" + "golang.org/x/exp/typeparams" + "github.com/google/go-flow-levee/internal/pkg/config" "github.com/google/go-flow-levee/internal/pkg/fieldtags" "github.com/google/go-flow-levee/internal/pkg/utils" @@ -65,6 +67,9 @@ func isSourceType(c *config.Config, tf fieldtags.ResultType, t types.Type, seen case *types.Basic, *types.Tuple, *types.Interface, *types.Signature: // These types do not currently represent possible source types return false + case *typeparams.TypeParam, *typeparams.Union: + // Generics are not resolved yet + return false default: // The above should be exhaustive. Reaching this default case is an error. fmt.Printf("unexpected type received: %T %v; please report this issue\n", tt, tt) diff --git a/internal/pkg/sourcetype/testdata/test_generics.go b/internal/pkg/sourcetype/testdata/test_generics.go new file mode 100644 index 00000000..04d57a74 --- /dev/null +++ b/internal/pkg/sourcetype/testdata/test_generics.go @@ -0,0 +1,20 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package test + +type G[T any] struct{} + +func (G[T]) M(_ T) { +}