From 2b1d76b61438dad25c4b14b1322392d5a6ef0bda Mon Sep 17 00:00:00 2001 From: Chressie Himpel Date: Thu, 5 May 2022 09:50:59 +0200 Subject: [PATCH 1/2] all: upgrade to latest x/tools version Upgrading to newest x/tools was performed with these steps: ``` % go get golang.org/x/tools@v0.1.11-0.20220504225841-45c8a7131235 % go get golang.org/x/tools/internal/gocommand@v0.1.11-0.20220504225841-45c8a7131235 % go mod download github.com/yuin/goldmark ``` With this update `interface{}` is now rendered with the new builtin type `any`, which interfers with the golden test data in the debug/render package. The golden files have been simply updated with the following command: ``` % sed -i 's/interface{}/any/g' internal/pkg/debug/render/testdata/* ``` The following test fails after this upgrade: ``` % go1.18.1 test github.com/google/go-flow-levee/internal/pkg/earpointer --- FAIL: TestMethodInvoke (0.00s) analysis_test.go:1212: got: {**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->g.t0], {g.x2}: --> *g.x2 want: {**T2:f.arg0}: [T1->*T1:f.arg0], {*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}: --> *g.x2 FAIL FAIL github.com/google/go-flow-levee/internal/pkg/earpointer 0.054s FAIL ``` The following test panics with go1.18.1 and with this upgrade it fails: ``` % go1.18.1 test github.com/google/go-flow-levee/internal/pkg/levee --- FAIL: TestLeveeEAR (5.97s) analysistest.go:455: levee_analysistest/example/tests/position/tests.go:36:11: diagnostic "a source has reached a sink\n source: /home/chressie/src/github.com/google/go-flow-levee/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go:35:7" does not match pattern "a source has reached a sink\n source: .*tests.go:34:2" analysistest.go:455: levee_analysistest/example/tests/position/tests.go:42:11: diagnostic "a source has reached a sink\n source: /home/chressie/src/github.com/google/go-flow-levee/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go:42:12" does not match pattern "a source has reached a sink\n source: .*tests.go:42:24" analysistest.go:519: levee_analysistest/example/tests/position/tests.go:36: no diagnostic was reported matching "a source has reached a sink\n source: .*tests.go:34:2" analysistest.go:519: levee_analysistest/example/tests/position/tests.go:42: no diagnostic was reported matching "a source has reached a sink\n source: .*tests.go:42:24" --- FAIL: TestLevee (0.54s) analysistest.go:455: levee_analysistest/example/tests/position/tests.go:36:11: diagnostic "a source has reached a sink\n source: /home/chressie/src/github.com/google/go-flow-levee/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go:35:7" does not match pattern "a source has reached a sink\n source: .*tests.go:34:2" analysistest.go:455: levee_analysistest/example/tests/position/tests.go:42:11: diagnostic "a source has reached a sink\n source: /home/chressie/src/github.com/google/go-flow-levee/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go:42:12" does not match pattern "a source has reached a sink\n source: .*tests.go:42:24" analysistest.go:519: levee_analysistest/example/tests/position/tests.go:36: no diagnostic was reported matching "a source has reached a sink\n source: .*tests.go:34:2" analysistest.go:519: levee_analysistest/example/tests/position/tests.go:42: no diagnostic was reported matching "a source has reached a sink\n source: .*tests.go:42:24" analysistest.go:519: levee_analysistest/example/tests/stdlib/interface_funcs.go:45: no diagnostic was reported matching `a source has reached a sink` FAIL FAIL github.com/google/go-flow-levee/internal/pkg/levee 6.870s FAIL ``` --- go.mod | 2 +- go.sum | 20 ++++++++++++ .../pkg/debug/render/testdata/TestClosure.ssa | 4 +-- .../render/testdata/TestDisconnected.dot | 8 ++--- .../render/testdata/TestDisconnected.ssa | 2 +- .../debug/render/testdata/TestMultiBlock.dot | 32 +++++++++---------- .../debug/render/testdata/TestMultiBlock.ssa | 10 +++--- .../pkg/debug/render/testdata/TestParams.dot | 28 ++++++++-------- .../pkg/debug/render/testdata/TestParams.ssa | 8 ++--- .../debug/render/testdata/TestSingleBlock.dot | 12 +++---- .../debug/render/testdata/TestSingleBlock.ssa | 4 +-- 11 files changed, 75 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index ae8ac5f8..41265560 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.14 require ( github.com/google/go-cmp v0.5.2 - golang.org/x/tools v0.0.0-20200416214402-fc959738d646 + golang.org/x/tools v0.1.11-0.20220504225841-45c8a7131235 sigs.k8s.io/yaml v1.2.0 ) diff --git a/go.sum b/go.sum index 269efb6a..a9523fba 100644 --- a/go.sum +++ b/go.sum @@ -3,21 +3,41 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs 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= +github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 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/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +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/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/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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/sync v0.0.0-20210220032951-036812b2e83c/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/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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/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-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 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 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...) From 51c4ee7bc9b007c5ae29967ab5b5a96c7ba9d3ce Mon Sep 17 00:00:00 2001 From: Chressie Himpel Date: Thu, 5 May 2022 08:55:55 +0200 Subject: [PATCH 2/2] skip analysis when seeing generics The analyzers (or helpers that the analyzers use) currently do not support generics. Use the `usesgenerics` analyzer from the x/tools repository to detect usage of generics and return a synthesized empty result in that case. Updates google/go-flow-levee/issues/323 --- internal/pkg/earpointer/analysis.go | 8 +++++++- internal/pkg/fieldpropagator/analyzer.go | 8 +++++++- internal/pkg/source/analyzer.go | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/internal/pkg/earpointer/analysis.go b/internal/pkg/earpointer/analysis.go index 72f99cac..3c8f6599 100644 --- a/internal/pkg/earpointer/analysis.go +++ b/internal/pkg/earpointer/analysis.go @@ -26,6 +26,7 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/buildssa" + "golang.org/x/tools/go/analysis/passes/usesgenerics" "golang.org/x/tools/go/callgraph" "golang.org/x/tools/go/callgraph/static" "golang.org/x/tools/go/ssa" @@ -49,7 +50,7 @@ var Analyzer = &analysis.Analyzer{ Flags: config.FlagSet, Run: run, ResultType: reflect.TypeOf(new(Partitions)), - Requires: []*analysis.Analyzer{buildssa.Analyzer}, + Requires: []*analysis.Analyzer{buildssa.Analyzer, usesgenerics.Analyzer}, } // visitor traverse the instructions in a function and perform unifications @@ -63,6 +64,11 @@ type visitor struct { } func run(pass *analysis.Pass) (interface{}, error) { + if r, ok := pass.ResultOf[usesgenerics.Analyzer].(*usesgenerics.Result); ok && r.Transitive != 0 { + // Generics are not supported yet (https://github.com/google/go-flow-levee/issues/323). + // TODO: Remove this check once the analyzers support generics. + return &Partitions{}, nil + } conf, err := config.ReadConfig() if err != nil { return nil, err diff --git a/internal/pkg/fieldpropagator/analyzer.go b/internal/pkg/fieldpropagator/analyzer.go index 45ebb232..7fe5dcdf 100644 --- a/internal/pkg/fieldpropagator/analyzer.go +++ b/internal/pkg/fieldpropagator/analyzer.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-flow-levee/internal/pkg/utils" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/buildssa" + "golang.org/x/tools/go/analysis/passes/usesgenerics" "golang.org/x/tools/go/ssa" ) @@ -53,12 +54,17 @@ var Analyzer = &analysis.Analyzer{ A field propagator is a function that returns a value that is tainted by a source field.`, Flags: config.FlagSet, Run: run, - Requires: []*analysis.Analyzer{buildssa.Analyzer, fieldtags.Analyzer}, + Requires: []*analysis.Analyzer{buildssa.Analyzer, fieldtags.Analyzer, usesgenerics.Analyzer}, ResultType: reflect.TypeOf(new(ResultType)).Elem(), FactTypes: []analysis.Fact{new(isFieldPropagator)}, } func run(pass *analysis.Pass) (interface{}, error) { + if r := pass.ResultOf[usesgenerics.Analyzer].(*usesgenerics.Result); r.Transitive != 0 { + // Generics are not supported yet (https://github.com/google/go-flow-levee/issues/323). + // TODO: Remove this check once the analyzers support generics. + return ResultType{}, nil + } taggedFields := pass.ResultOf[fieldtags.Analyzer].(fieldtags.ResultType) ssaInput := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) diff --git a/internal/pkg/source/analyzer.go b/internal/pkg/source/analyzer.go index b0d03628..e2916374 100644 --- a/internal/pkg/source/analyzer.go +++ b/internal/pkg/source/analyzer.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-flow-levee/internal/pkg/fieldtags" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/buildssa" + "golang.org/x/tools/go/analysis/passes/usesgenerics" "golang.org/x/tools/go/ssa" ) @@ -33,11 +34,16 @@ var Analyzer = &analysis.Analyzer{ Doc: "This analyzer identifies ssa.Values that are sources.", Flags: config.FlagSet, Run: run, - Requires: []*analysis.Analyzer{buildssa.Analyzer, fieldtags.Analyzer, fieldpropagator.Analyzer}, + Requires: []*analysis.Analyzer{buildssa.Analyzer, fieldtags.Analyzer, fieldpropagator.Analyzer, usesgenerics.Analyzer}, ResultType: reflect.TypeOf(new(ResultType)).Elem(), } func run(pass *analysis.Pass) (interface{}, error) { + if r := pass.ResultOf[usesgenerics.Analyzer].(*usesgenerics.Result); r.Transitive != 0 { + // Generics are not supported yet (https://github.com/google/go-flow-levee/issues/323). + // TODO: Remove this check once the analyzers support generics. + return map[*ssa.Function][]*Source{}, nil + } ssaInput := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) taggedFields := pass.ResultOf[fieldtags.Analyzer].(fieldtags.ResultType) fieldPropagators := pass.ResultOf[fieldpropagator.Analyzer].(fieldpropagator.ResultType)