diff --git a/go.mod b/go.mod index b6b2d9549c..1180e2d6b7 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/armon/go-radix v1.0.0 github.com/ghodss/yaml v1.0.0 github.com/golang/snappy v0.0.4 - github.com/golangci/golangci-lint v1.51.0 + github.com/golangci/golangci-lint v1.51.1 github.com/google/addlicense v1.1.1 github.com/google/go-cmp v0.5.9 github.com/google/go-containerregistry v0.13.0 @@ -211,7 +211,7 @@ require ( github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.11.0 // indirect github.com/go-toolsmith/astcast v1.0.0 // indirect - github.com/go-toolsmith/astcopy v1.0.2 // indirect + github.com/go-toolsmith/astcopy v1.0.3 // indirect github.com/go-toolsmith/astequal v1.0.3 // indirect github.com/go-toolsmith/astfmt v1.0.0 // indirect github.com/go-toolsmith/astp v1.0.0 // indirect @@ -249,7 +249,7 @@ require ( github.com/google/wire v0.5.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect - github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 // indirect + github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.4.2 // indirect @@ -285,7 +285,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/julz/importas v0.1.0 // indirect - github.com/junk1tm/musttag v0.4.3 // indirect + github.com/junk1tm/musttag v0.4.4 // indirect github.com/kelseyhightower/envconfig v1.4.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kisielk/errcheck v1.6.3 // indirect @@ -324,7 +324,7 @@ require ( github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect github.com/nishanths/exhaustive v0.9.5 // indirect github.com/nishanths/predeclared v0.2.2 // indirect - github.com/nunnatsa/ginkgolinter v0.7.1 // indirect + github.com/nunnatsa/ginkgolinter v0.8.1 // indirect github.com/oklog/run v1.1.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect @@ -349,9 +349,9 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryancurrah/gomodguard v1.3.0 // indirect - github.com/ryanrolds/sqlclosecheck v0.3.0 // indirect + github.com/ryanrolds/sqlclosecheck v0.4.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect - github.com/sanposhiho/wastedassign/v2 v2.0.6 // indirect + github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect github.com/sashamelentyev/interfacebloat v1.1.0 // indirect github.com/sashamelentyev/usestdlibvars v1.21.1 // indirect github.com/sassoftware/relic v0.0.0-20210427151427-dfb082b79b74 // indirect @@ -368,7 +368,7 @@ require ( github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/soheilhy/cmux v0.1.5 // indirect github.com/sonatard/noctx v0.0.1 // indirect - github.com/sourcegraph/go-diff v0.6.2-0.20221031073116-7ef5f68ebea1 // indirect + github.com/sourcegraph/go-diff v0.7.0 // indirect github.com/spf13/afero v1.9.2 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cobra v1.6.1 // indirect @@ -391,7 +391,7 @@ require ( github.com/timonwong/loggercheck v0.9.3 // indirect github.com/tjfoc/gmsm v1.3.2 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect - github.com/tomarrell/wrapcheck/v2 v2.7.0 // indirect + github.com/tomarrell/wrapcheck/v2 v2.8.0 // indirect github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/transparency-dev/merkle v0.0.1 // indirect github.com/ultraware/funlen v0.0.3 // indirect @@ -458,7 +458,7 @@ require ( gopkg.in/src-d/go-git.v4 v4.13.1 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720 // indirect + honnef.co/go/tools v0.4.0 // indirect k8s.io/apiextensions-apiserver v0.25.2 // indirect k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7 // indirect k8s.io/klog/v2 v2.80.1 // indirect diff --git a/go.sum b/go.sum index 4779cce78f..2fbd7f5cc8 100644 --- a/go.sum +++ b/go.sum @@ -1291,16 +1291,17 @@ github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48/go.mod h1:dZGr github.com/go-rod/rod v0.112.3 h1:xbSaA9trZ8v/+eJRGOM6exK1RCsLPwwnzA78vpES0gk= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g= github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4= -github.com/go-toolsmith/astcopy v1.0.2 h1:YnWf5Rnh1hUudj11kei53kI57quN/VH6Hp1n+erozn0= github.com/go-toolsmith/astcopy v1.0.2/go.mod h1:4TcEdbElGc9twQEYpVo/aieIXfHhiuLh4aLAck6dO7Y= +github.com/go-toolsmith/astcopy v1.0.3 h1:r0bgSRlMOAgO+BdQnVAcpMSMkrQCnV6ZJmIkrJgcJj0= +github.com/go-toolsmith/astcopy v1.0.3/go.mod h1:4TcEdbElGc9twQEYpVo/aieIXfHhiuLh4aLAck6dO7Y= github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= github.com/go-toolsmith/astequal v1.0.2/go.mod h1:9Ai4UglvtR+4up+bAD4+hCj7iTo4m/OXVTSLnCyTAx4= github.com/go-toolsmith/astequal v1.0.3 h1:+LVdyRatFS+XO78SGV4I3TCEA0AC7fKEGma+fH+674o= @@ -1432,8 +1433,8 @@ github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe h1:6RGUuS7EGotKx6 github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe/go.mod h1:gjqyPShc/m8pEMpk0a3SeagVb0kaqvhscv+i9jI5ZhQ= github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2 h1:amWTbTGqOZ71ruzrdA+Nx5WA3tV1N0goTspwmKCQvBY= github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2/go.mod h1:9wOXstvyDRshQ9LggQuzBCGysxs3b6Uo/1MvYCR2NMs= -github.com/golangci/golangci-lint v1.51.0 h1:M1bpDymgdaPKNzPwQdebCGki/nzvVkr2f/eUfk9C9oU= -github.com/golangci/golangci-lint v1.51.0/go.mod h1:7taIMcmZ5ksCuRruCV/mm8Ir3sE+bIuOHVCvt1B4hi4= +github.com/golangci/golangci-lint v1.51.1 h1:N5HD/x0ZrhJYsgKWyz7yJxxQ8JKR0Acc+FOP7QtGSAA= +github.com/golangci/golangci-lint v1.51.1/go.mod h1:hnyNNO3fJ2Rjwo6HM+VXvcmLkKDOuBAnR9gVlS1mW1E= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= @@ -1579,8 +1580,8 @@ github.com/gophercloud/gophercloud v1.0.0/go.mod h1:Q8fZtyi5zZxPS/j9aj3sSxtvj41A github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU= -github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 h1:PVRE9d4AQKmbelZ7emNig1+NT27DUmKZn5qXxfio54U= -github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= +github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28 h1:9alfqbrhuD+9fLZ4iaAVwhlp5PEhmnBt7yvK2Oy5C1U= +github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= github.com/goreleaser/goreleaser v0.134.0/go.mod h1:ZT6Y2rSYa6NxQzIsdfWWNWAlYGXGbreo66NmE+3X3WQ= github.com/goreleaser/nfpm v1.2.1/go.mod h1:TtWrABZozuLOttX2uDlYyECfQX7x5XYkVxhjYcR6G9w= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= @@ -1847,7 +1848,6 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmhodges/clock v0.0.0-20160418191101-880ee4c33548 h1:dYTbLf4m0a5u0KLmPfB6mgxbcV7588bOCx79hxa5Sr4= -github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= @@ -1874,8 +1874,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/julz/importas v0.1.0 h1:F78HnrsjY3cR7j0etXy5+TU1Zuy7Xt08X/1aJnH5xXY= github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= -github.com/junk1tm/musttag v0.4.3 h1:I8UHQkDj2u/MClcGU8PbMoYwhykiSQFEbXKKMjixPyk= -github.com/junk1tm/musttag v0.4.3/go.mod h1:XkcL/9O6RmD88JBXb+I15nYRl9W4ExhgQeCBEhfMC8U= +github.com/junk1tm/musttag v0.4.4 h1:VK4L7v7lvWAhKDDx0cUJgbb0UBNipYinv8pPeHJzH9Q= +github.com/junk1tm/musttag v0.4.4/go.mod h1:XkcL/9O6RmD88JBXb+I15nYRl9W4ExhgQeCBEhfMC8U= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= @@ -2014,7 +2014,6 @@ github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vq github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/mattn/go-shellwords v1.0.10/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= -github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -2123,8 +2122,8 @@ github.com/nishanths/exhaustive v0.9.5/go.mod h1:IbwrGdVMizvDcIxPYGVdQn5BqWJaOwp github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= -github.com/nunnatsa/ginkgolinter v0.7.1 h1:j4mzqx1hkE75mXHs3AUlWghZBi59c3GDWXp6zzcI+kE= -github.com/nunnatsa/ginkgolinter v0.7.1/go.mod h1:jTgd60EAdXDmmIPZi+xoMDqAYo/4AakhWNmnPisd7Rc= +github.com/nunnatsa/ginkgolinter v0.8.1 h1:/y4o/0hV+ruUHj4xXh89xlFjoaitnI4LnkpuYs02q1c= +github.com/nunnatsa/ginkgolinter v0.8.1/go.mod h1:FYYLtszIdmzCH8XMaMPyxPVXZ7VCaIm55bA+gugx+14= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -2386,8 +2385,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryancurrah/gomodguard v1.3.0 h1:q15RT/pd6UggBXVBuLps8BXRvl5GPBcwVA7BJHMLuTw= github.com/ryancurrah/gomodguard v1.3.0/go.mod h1:ggBxb3luypPEzqVtq33ee7YSN35V28XeGnid8dnni50= -github.com/ryanrolds/sqlclosecheck v0.3.0 h1:AZx+Bixh8zdUBxUA1NxbxVAS78vTPq4rCb8OUZI9xFw= -github.com/ryanrolds/sqlclosecheck v0.3.0/go.mod h1:1gREqxyTGR3lVtpngyFo3hZAgk0KCtEdgEkHwDbigdA= +github.com/ryanrolds/sqlclosecheck v0.4.0 h1:i8SX60Rppc1wRuyQjMciLqIzV3xnoHB7/tXbr6RGYNI= +github.com/ryanrolds/sqlclosecheck v0.4.0/go.mod h1:TBRRjzL31JONc9i4XMinicuo+s+E8yKZ5FN8X3G6CKQ= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= @@ -2395,8 +2394,8 @@ github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIH github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sanposhiho/wastedassign/v2 v2.0.6 h1:+6/hQIHKNJAUixEj6EmOngGIisyeI+T3335lYTyxRoA= -github.com/sanposhiho/wastedassign/v2 v2.0.6/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= +github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc= +github.com/sanposhiho/wastedassign/v2 v2.0.7/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tMEOsumirXcOJqAw= github.com/sashamelentyev/interfacebloat v1.1.0/go.mod h1:+Y9yU5YdTkrNvoX0xHc84dxiN1iBi9+G8zZIhPVoNjQ= github.com/sashamelentyev/usestdlibvars v1.21.1 h1:GQGlReyL9Ek8DdJmwtwhHbhwHnuPfsKaprpjnrPcjxc= @@ -2478,8 +2477,8 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE github.com/sonatard/noctx v0.0.1 h1:VC1Qhl6Oxx9vvWo3UDgrGXYCeKCe3Wbw7qAWL6FrmTY= github.com/sonatard/noctx v0.0.1/go.mod h1:9D2D/EoULe8Yy2joDHJj7bv3sZoq9AaSb8B4lqBjiZI= github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= -github.com/sourcegraph/go-diff v0.6.2-0.20221031073116-7ef5f68ebea1 h1:FEIBISvqa2IsyC4KQQBQ1Ef2QvweGUgEIjCdE3gz+zs= -github.com/sourcegraph/go-diff v0.6.2-0.20221031073116-7ef5f68ebea1/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs= +github.com/sourcegraph/go-diff v0.7.0 h1:9uLlrd5T46OXs5qpp8L/MTltk0zikUGi0sNNyCpA8G0= +github.com/sourcegraph/go-diff v0.7.0/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= @@ -2600,8 +2599,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tomarrell/wrapcheck/v2 v2.7.0 h1:J/F8DbSKJC83bAvC6FoZaRjZiZ/iKoueSdrEkmGeacA= -github.com/tomarrell/wrapcheck/v2 v2.7.0/go.mod h1:ao7l5p0aOlUNJKI0qVwB4Yjlqutd0IvAB9Rdwyilxvg= +github.com/tomarrell/wrapcheck/v2 v2.8.0 h1:qDzbir0xmoE+aNxGCPrn+rUSxAX+nG6vREgbbXAR81I= +github.com/tomarrell/wrapcheck/v2 v2.8.0/go.mod h1:ao7l5p0aOlUNJKI0qVwB4Yjlqutd0IvAB9Rdwyilxvg= github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4= github.com/tommy-muehle/go-mnd/v2 v2.5.1 h1:NowYhSdyE/1zwK9QCLeRb6USWdoif80Ie+v+yU8u1Zw= github.com/tommy-muehle/go-mnd/v2 v2.5.1/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw= @@ -3410,7 +3409,6 @@ golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200625211823-6506e20df31f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= @@ -3829,8 +3827,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720 h1:L3lQbXWMmkBfyGXTvipQVmLXSM5SsT/39qcf+0RBIlQ= -honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720/go.mod h1:lbrxuU0wR28B7d2OiCxa+DVcNWwTjaY3RfXQNu3r10U= +honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8= +honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA= k8s.io/api v0.20.1/go.mod h1:KqwcCVogGxQY3nBlRpwt+wpAMF/KjaCc7RpywacvqUo= k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ= k8s.io/api v0.20.6/go.mod h1:X9e8Qag6JV/bL5G6bU8sdVRltWKmdHsFUGS3eVndqE8= diff --git a/vendor/github.com/go-toolsmith/astcopy/astcopy.go b/vendor/github.com/go-toolsmith/astcopy/astcopy.go index 91e1f31096..72bc58ce6d 100644 --- a/vendor/github.com/go-toolsmith/astcopy/astcopy.go +++ b/vendor/github.com/go-toolsmith/astcopy/astcopy.go @@ -346,21 +346,6 @@ func FieldList(x *ast.FieldList) *ast.FieldList { return &cp } -// FuncType returns x deep copy. -// Copy of nil argument is nil. -func FuncType(x *ast.FuncType) *ast.FuncType { - if x == nil { - return nil - } - cp := *x - cp.Params = FieldList(x.Params) - cp.Results = FieldList(x.Results) - if typeParams := typeparams.ForFuncType(x); typeParams != nil { - *typeparams.ForFuncType(&cp) = *FieldList(typeParams) - } - return &cp -} - // InterfaceType returns x deep copy. // Copy of nil argument is nil. func InterfaceType(x *ast.InterfaceType) *ast.InterfaceType { @@ -435,23 +420,6 @@ func ValueSpec(x *ast.ValueSpec) *ast.ValueSpec { return &cp } -// TypeSpec returns x deep copy. -// Copy of nil argument is nil. -func TypeSpec(x *ast.TypeSpec) *ast.TypeSpec { - if x == nil { - return nil - } - cp := *x - cp.Name = Ident(x.Name) - cp.Type = copyExpr(x.Type) - cp.Doc = CommentGroup(x.Doc) - cp.Comment = CommentGroup(x.Comment) - if typeParams := typeparams.ForTypeSpec(x); typeParams != nil { - *typeparams.ForTypeSpec(&cp) = *FieldList(typeParams) - } - return &cp -} - // Spec returns x deep copy. // Copy of nil argument is nil. func Spec(x ast.Spec) ast.Spec { diff --git a/vendor/github.com/go-toolsmith/astcopy/astcopy_go117.go b/vendor/github.com/go-toolsmith/astcopy/astcopy_go117.go new file mode 100644 index 0000000000..1b748bae50 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astcopy/astcopy_go117.go @@ -0,0 +1,30 @@ +//go:build !go1.18 +// +build !go1.18 + +package astcopy + +// FuncType returns x deep copy. +// Copy of nil argument is nil. +func FuncType(x *ast.FuncType) *ast.FuncType { + if x == nil { + return nil + } + cp := *x + cp.Params = FieldList(x.Params) + cp.Results = FieldList(x.Results) + return &cp +} + +// TypeSpec returns x deep copy. +// Copy of nil argument is nil. +func TypeSpec(x *ast.TypeSpec) *ast.TypeSpec { + if x == nil { + return nil + } + cp := *x + cp.Name = Ident(x.Name) + cp.Type = copyExpr(x.Type) + cp.Doc = CommentGroup(x.Doc) + cp.Comment = CommentGroup(x.Comment) + return &cp +} diff --git a/vendor/github.com/go-toolsmith/astcopy/astcopy_go118.go b/vendor/github.com/go-toolsmith/astcopy/astcopy_go118.go new file mode 100644 index 0000000000..72f800acc1 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astcopy/astcopy_go118.go @@ -0,0 +1,36 @@ +//go:build go1.18 +// +build go1.18 + +package astcopy + +import ( + "go/ast" +) + +// FuncType returns x deep copy. +// Copy of nil argument is nil. +func FuncType(x *ast.FuncType) *ast.FuncType { + if x == nil { + return nil + } + cp := *x + cp.Params = FieldList(x.Params) + cp.Results = FieldList(x.Results) + cp.TypeParams = FieldList(x.TypeParams) + return &cp +} + +// TypeSpec returns x deep copy. +// Copy of nil argument is nil. +func TypeSpec(x *ast.TypeSpec) *ast.TypeSpec { + if x == nil { + return nil + } + cp := *x + cp.Name = Ident(x.Name) + cp.Type = copyExpr(x.Type) + cp.Doc = CommentGroup(x.Doc) + cp.Comment = CommentGroup(x.Comment) + cp.TypeParams = FieldList(x.TypeParams) + return &cp +} diff --git a/vendor/github.com/golangci/golangci-lint/pkg/golinters/unused.go b/vendor/github.com/golangci/golangci-lint/pkg/golinters/unused.go index 35b4360119..d464690549 100644 --- a/vendor/github.com/golangci/golangci-lint/pkg/golinters/unused.go +++ b/vendor/github.com/golangci/golangci-lint/pkg/golinters/unused.go @@ -63,25 +63,19 @@ func runUnused(pass *analysis.Pass) ([]goanalysis.Issue, error) { return nil, err } - sr := unused.Serialize(pass, res.(unused.Result), pass.Fset) - used := make(map[string]bool) - for _, obj := range sr.Used { + for _, obj := range res.(unused.Result).Used { used[fmt.Sprintf("%s %d %s", obj.Position.Filename, obj.Position.Line, obj.Name)] = true } var issues []goanalysis.Issue // Inspired by https://github.com/dominikh/go-tools/blob/d694aadcb1f50c2d8ac0a1dd06217ebb9f654764/lintcmd/lint.go#L177-L197 - for _, object := range sr.Unused { + for _, object := range res.(unused.Result).Unused { if object.Kind == "type param" { continue } - if object.InGenerated { - continue - } - key := fmt.Sprintf("%s %d %s", object.Position.Filename, object.Position.Line, object.Name) if used[key] { continue diff --git a/vendor/github.com/golangci/golangci-lint/pkg/lint/lintersdb/manager.go b/vendor/github.com/golangci/golangci-lint/pkg/lint/lintersdb/manager.go index 10e27f6d62..03f898cefe 100644 --- a/vendor/github.com/golangci/golangci-lint/pkg/lint/lintersdb/manager.go +++ b/vendor/github.com/golangci/golangci-lint/pkg/lint/lintersdb/manager.go @@ -745,8 +745,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithSince("v1.28.0"). WithPresets(linter.PresetBugs, linter.PresetSQL). WithLoadForGoAnalysis(). - WithURL("https://github.com/ryanrolds/sqlclosecheck"). - WithNoopFallback(m.cfg), + WithURL("https://github.com/ryanrolds/sqlclosecheck"), linter.NewConfig(golinters.NewStaticcheck(staticcheckCfg)). WithSince("v1.0.0"). diff --git a/vendor/github.com/gordonklaus/ineffassign/pkg/ineffassign/ineffassign.go b/vendor/github.com/gordonklaus/ineffassign/pkg/ineffassign/ineffassign.go index c7b4fa9784..3d7b18d77b 100644 --- a/vendor/github.com/gordonklaus/ineffassign/pkg/ineffassign/ineffassign.go +++ b/vendor/github.com/gordonklaus/ineffassign/pkg/ineffassign/ineffassign.go @@ -60,6 +60,7 @@ type builder struct { block *block vars map[*ast.Object]*variable results []*ast.FieldList + defers []bool breaks branchStack continues branchStack gotos branchStack @@ -181,6 +182,9 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { } brek.setDestination(bld.newBlock(exits...)) bld.breaks.pop() + case *ast.DeferStmt: + bld.defers[len(bld.defers)-1] = true + return bld case *ast.LabeledStmt: bld.gotos.get(n.Label).setDestination(bld.newBlock(bld.block)) bld.labelStmt = n @@ -360,6 +364,7 @@ func (bld *builder) fun(typ *ast.FuncType, body *ast.BlockStmt) { v.fundept++ } bld.results = append(bld.results, typ.Results) + bld.defers = append(bld.defers, false) b := bld.block bld.newBlock() @@ -369,6 +374,7 @@ func (bld *builder) fun(typ *ast.FuncType, body *ast.BlockStmt) { bld.block = b bld.results = bld.results[:len(bld.results)-1] + bld.defers = bld.defers[:len(bld.defers)-1] for _, v := range bld.vars { v.fundept-- } @@ -422,8 +428,11 @@ func (bld *builder) swtch(stmt ast.Stmt, cases []ast.Stmt) { bld.breaks.pop() } -// An operation that might panic marks named function results as used. +// If an operation might panic and be recovered, mark named function results as used. func (bld *builder) maybePanic() { + if len(bld.defers) == 0 || !bld.defers[len(bld.defers)-1] { + return + } if len(bld.results) == 0 { return } diff --git a/vendor/github.com/junk1tm/musttag/.goreleaser.yml b/vendor/github.com/junk1tm/musttag/.goreleaser.yml index d15c74d624..6f85d818fb 100644 --- a/vendor/github.com/junk1tm/musttag/.goreleaser.yml +++ b/vendor/github.com/junk1tm/musttag/.goreleaser.yml @@ -4,6 +4,8 @@ builds: - CGO_ENABLED=0 flags: - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} targets: - darwin_amd64 - darwin_arm64 diff --git a/vendor/github.com/junk1tm/musttag/musttag.go b/vendor/github.com/junk1tm/musttag/musttag.go index de7f0503e1..a58dc1cce4 100644 --- a/vendor/github.com/junk1tm/musttag/musttag.go +++ b/vendor/github.com/junk1tm/musttag/musttag.go @@ -206,7 +206,11 @@ func checkStruct(s *types.Struct, tag string, pos *token.Pos) (ok bool) { st := reflect.StructTag(s.Tag(i)) if _, ok := st.Lookup(tag); !ok { - return false + // it's ok for embedded types not to be tagged, + // see https://github.com/junk1tm/musttag/issues/12 + if !s.Field(i).Embedded() { + return false + } } // check if the field is a nested struct. diff --git a/vendor/github.com/nunnatsa/ginkgolinter/ginkgo_linter.go b/vendor/github.com/nunnatsa/ginkgolinter/ginkgo_linter.go index 7de8cf1178..fc089be106 100644 --- a/vendor/github.com/nunnatsa/ginkgolinter/ginkgo_linter.go +++ b/vendor/github.com/nunnatsa/ginkgolinter/ginkgo_linter.go @@ -4,12 +4,12 @@ import ( "bytes" "flag" "fmt" - "go/ast" "go/printer" "go/token" gotypes "go/types" + "github.com/go-toolsmith/astcopy" "golang.org/x/tools/go/analysis" "github.com/nunnatsa/ginkgolinter/gomegahandler" @@ -161,6 +161,7 @@ func (l *ginkgoLinter) run(pass *analysis.Pass) (interface{}, error) { } func checkExpression(pass *analysis.Pass, exprSuppress types.Suppress, actualArg ast.Expr, assertionExp *ast.CallExpr, handler gomegahandler.Handler) bool { + assertionExp = astcopy.CallExpr(assertionExp) oldExpr := goFmt(pass.Fset, assertionExp) if !bool(exprSuppress.Len) && isActualIsLenFunc(actualArg) { diff --git a/vendor/github.com/ryanrolds/sqlclosecheck/pkg/analyzer/analyzer.go b/vendor/github.com/ryanrolds/sqlclosecheck/pkg/analyzer/analyzer.go index bc42dfb3a0..c22817cafc 100644 --- a/vendor/github.com/ryanrolds/sqlclosecheck/pkg/analyzer/analyzer.go +++ b/vendor/github.com/ryanrolds/sqlclosecheck/pkg/analyzer/analyzer.go @@ -14,6 +14,19 @@ const ( closeMethod = "Close" ) +type action uint8 + +const ( + actionUnhandled action = iota + actionHandled + actionReturned + actionPassed + actionClosed + actionUnvaluedCall + actionUnvaluedDefer + actionNoOp +) + var ( sqlPackages = []string{ "database/sql", @@ -33,7 +46,10 @@ func NewAnalyzer() *analysis.Analyzer { } func run(pass *analysis.Pass) (interface{}, error) { - pssa := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) + pssa, ok := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) + if !ok { + return nil, nil + } // Build list of types we are looking for targetTypes := getTargetTypes(pssa, sqlPackages) @@ -168,16 +184,16 @@ func checkClosed(refs *[]ssa.Instruction, targetTypes []*types.Pointer) bool { action := getAction(ref, targetTypes) switch action { - case "closed": + case actionClosed: return true - case "passed": + case actionPassed: // Passed and not used after if numInstrs == idx+1 { return true } - case "returned": + case actionReturned: return true - case "handled": + case actionHandled: return true default: // log.Printf(action) @@ -187,51 +203,61 @@ func checkClosed(refs *[]ssa.Instruction, targetTypes []*types.Pointer) bool { return false } -func getAction(instr ssa.Instruction, targetTypes []*types.Pointer) string { +func getAction(instr ssa.Instruction, targetTypes []*types.Pointer) action { switch instr := instr.(type) { case *ssa.Defer: if instr.Call.Value == nil { - return "unvalued defer" + return actionUnvaluedDefer } name := instr.Call.Value.Name() if name == closeMethod { - return "closed" + return actionClosed } case *ssa.Call: if instr.Call.Value == nil { - return "unvalued call" + return actionUnvaluedCall } isTarget := false - receiver := instr.Call.StaticCallee().Signature.Recv() - if receiver != nil { - isTarget = isTargetType(receiver.Type(), targetTypes) + staticCallee := instr.Call.StaticCallee() + if staticCallee != nil { + receiver := instr.Call.StaticCallee().Signature.Recv() + if receiver != nil { + isTarget = isTargetType(receiver.Type(), targetTypes) + } } name := instr.Call.Value.Name() if isTarget && name == closeMethod { - return "closed" + return actionClosed } if !isTarget { - return "passed" + return actionPassed } case *ssa.Phi: - return "passed" + return actionPassed case *ssa.MakeInterface: - return "passed" + return actionPassed case *ssa.Store: + // A Row/Stmt is stored in a struct, which may be closed later + // by a different flow. + if _, ok := instr.Addr.(*ssa.FieldAddr); ok { + return actionReturned + } + if len(*instr.Addr.Referrers()) == 0 { - return "noop" + return actionNoOp } for _, aRef := range *instr.Addr.Referrers() { if c, ok := aRef.(*ssa.MakeClosure); ok { - f := c.Fn.(*ssa.Function) - for _, b := range f.Blocks { - if checkClosed(&b.Instrs, targetTypes) { - return "handled" + if f, ok := c.Fn.(*ssa.Function); ok { + for _, b := range f.Blocks { + if checkClosed(&b.Instrs, targetTypes) { + return actionHandled + } } } } @@ -241,21 +267,21 @@ func getAction(instr ssa.Instruction, targetTypes []*types.Pointer) string { for _, targetType := range targetTypes { if types.Identical(instrType, targetType) { if checkClosed(instr.Referrers(), targetTypes) { - return "handled" + return actionHandled } } } case *ssa.FieldAddr: if checkClosed(instr.Referrers(), targetTypes) { - return "handled" + return actionHandled } case *ssa.Return: - return "returned" + return actionReturned default: // log.Printf("%s", instr) } - return "unhandled" + return actionUnhandled } func checkDeferred(pass *analysis.Pass, instrs *[]ssa.Instruction, targetTypes []*types.Pointer, inDefer bool) { @@ -280,10 +306,10 @@ func checkDeferred(pass *analysis.Pass, instrs *[]ssa.Instruction, targetTypes [ for _, aRef := range *instr.Addr.Referrers() { if c, ok := aRef.(*ssa.MakeClosure); ok { - f := c.Fn.(*ssa.Function) - - for _, b := range f.Blocks { - checkDeferred(pass, &b.Instrs, targetTypes, true) + if f, ok := c.Fn.(*ssa.Function); ok { + for _, b := range f.Blocks { + checkDeferred(pass, &b.Instrs, targetTypes, true) + } } } } diff --git a/vendor/github.com/sanposhiho/wastedassign/v2/README.md b/vendor/github.com/sanposhiho/wastedassign/v2/README.md index cd2deedad5..6b736f7f1d 100644 --- a/vendor/github.com/sanposhiho/wastedassign/v2/README.md +++ b/vendor/github.com/sanposhiho/wastedassign/v2/README.md @@ -39,10 +39,19 @@ $ go vet -vettool=`which wastedassign` sample.go ## Installation + +### Go version < 1.16 + ``` go get -u github.com/sanposhiho/wastedassign/v2/cmd/wastedassign ``` +### Go version 1.16+ + +``` +go install github.com/sanposhiho/wastedassign/v2/cmd/wastedassign@latest +``` + ## Usage ``` diff --git a/vendor/github.com/sourcegraph/go-diff/LICENSE b/vendor/github.com/sourcegraph/go-diff/LICENSE index 0733b6e5f2..5ba1c44360 100644 --- a/vendor/github.com/sourcegraph/go-diff/LICENSE +++ b/vendor/github.com/sourcegraph/go-diff/LICENSE @@ -33,3 +33,14 @@ in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/sourcegraph/go-diff/diff/parse.go b/vendor/github.com/sourcegraph/go-diff/diff/parse.go index f45c2f2aa7..48eeb96702 100644 --- a/vendor/github.com/sourcegraph/go-diff/diff/parse.go +++ b/vendor/github.com/sourcegraph/go-diff/diff/parse.go @@ -436,8 +436,17 @@ func parseDiffGitArgs(diffArgs string) (string, string, bool) { // to handle that case here. first := diffArgs[:length/2] second := diffArgs[length/2+1:] - if len(first) >= 3 && length%2 == 1 && first[1] == '/' && first[1:] == second[1:] { - return first, second, true + + // If the two strings could be equal, based on length, proceed. + if length%2 == 1 { + // If the name minus the a/ b/ prefixes is equal, proceed. + if len(first) >= 3 && first[1] == '/' && first[1:] == second[1:] { + return first, second, true + } + // If the names don't have the a/ and b/ prefixes and they're equal, proceed. + if !(first[:2] == "a/" && second[:2] == "b/") && first == second { + return first, second, true + } } // The syntax is (unfortunately) valid, but we could not extract diff --git a/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go b/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go index ea36c3f97c..6da17bd867 100644 --- a/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go +++ b/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go @@ -16,6 +16,7 @@ var DefaultIgnoreSigs = []string{ ".Errorf(", "errors.New(", "errors.Unwrap(", + "errors.Join(", ".Wrap(", ".Wrapf(", ".WithMessage(", diff --git a/vendor/honnef.co/go/tools/analysis/facts/deprecated/deprecated.go b/vendor/honnef.co/go/tools/analysis/facts/deprecated/deprecated.go index c558fabb00..dd6d655c32 100644 --- a/vendor/honnef.co/go/tools/analysis/facts/deprecated/deprecated.go +++ b/vendor/honnef.co/go/tools/analysis/facts/deprecated/deprecated.go @@ -48,6 +48,7 @@ func deprecated(pass *analysis.Pass) (interface{}, error) { } return "" } + doDocs := func(names []*ast.Ident, docs []*ast.CommentGroup) { alt := extractDeprecatedMessage(docs) if alt == "" { @@ -86,7 +87,15 @@ func deprecated(pass *analysis.Pass) (interface{}, error) { switch node.Tok { case token.TYPE, token.CONST, token.VAR: docs = append(docs, node.Doc) - return true + for i := range node.Specs { + switch n := node.Specs[i].(type) { + case *ast.ValueSpec: + names = append(names, n.Names...) + case *ast.TypeSpec: + names = append(names, n.Name) + } + } + ret = true default: return false } diff --git a/vendor/honnef.co/go/tools/analysis/facts/purity/purity.go b/vendor/honnef.co/go/tools/analysis/facts/purity/purity.go index 4afc7a6a58..0f6895a8c3 100644 --- a/vendor/honnef.co/go/tools/analysis/facts/purity/purity.go +++ b/vendor/honnef.co/go/tools/analysis/facts/purity/purity.go @@ -1,5 +1,8 @@ package purity +// TODO(dh): we should split this into two facts, one tracking actual purity, and one tracking side-effects. A function +// that returns a heap allocation isn't pure, but it may be free of side effects. + import ( "go/types" "reflect" @@ -53,6 +56,52 @@ var pureStdlib = map[string]struct{}{ "strings.TrimSpace": {}, "strings.TrimSuffix": {}, "(*net/http.Request).WithContext": {}, + "time.Now": {}, + "time.Parse": {}, + "time.ParseInLocation": {}, + "time.Unix": {}, + "time.UnixMicro": {}, + "time.UnixMilli": {}, + "(time.Time).Add": {}, + "(time.Time).AddDate": {}, + "(time.Time).After": {}, + "(time.Time).Before": {}, + "(time.Time).Clock": {}, + "(time.Time).Compare": {}, + "(time.Time).Date": {}, + "(time.Time).Day": {}, + "(time.Time).Equal": {}, + "(time.Time).Format": {}, + "(time.Time).GoString": {}, + "(time.Time).GobEncode": {}, + "(time.Time).Hour": {}, + "(time.Time).ISOWeek": {}, + "(time.Time).In": {}, + "(time.Time).IsDST": {}, + "(time.Time).IsZero": {}, + "(time.Time).Local": {}, + "(time.Time).Location": {}, + "(time.Time).MarshalBinary": {}, + "(time.Time).MarshalJSON": {}, + "(time.Time).MarshalText": {}, + "(time.Time).Minute": {}, + "(time.Time).Month": {}, + "(time.Time).Nanosecond": {}, + "(time.Time).Round": {}, + "(time.Time).Second": {}, + "(time.Time).String": {}, + "(time.Time).Sub": {}, + "(time.Time).Truncate": {}, + "(time.Time).UTC": {}, + "(time.Time).Unix": {}, + "(time.Time).UnixMicro": {}, + "(time.Time).UnixMilli": {}, + "(time.Time).UnixNano": {}, + "(time.Time).Weekday": {}, + "(time.Time).Year": {}, + "(time.Time).YearDay": {}, + "(time.Time).Zone": {}, + "(time.Time).ZoneBounds": {}, } func purity(pass *analysis.Pass) (interface{}, error) { @@ -99,10 +148,26 @@ func purity(pass *analysis.Pass) (interface{}, error) { return false } + var isBasic func(typ types.Type) bool + isBasic = func(typ types.Type) bool { + switch u := typ.Underlying().(type) { + case *types.Basic: + return true + case *types.Struct: + for i := 0; i < u.NumFields(); i++ { + if !isBasic(u.Field(i).Type()) { + return false + } + } + return true + default: + return false + } + } + for _, param := range fn.Params { - // TODO(dh): this may not be strictly correct. pure code - // can, to an extent, operate on non-basic types. - if _, ok := param.Type().Underlying().(*types.Basic); !ok { + // TODO(dh): this may not be strictly correct. pure code can, to an extent, operate on non-basic types. + if !isBasic(param.Type()) { return false } } @@ -134,6 +199,18 @@ func purity(pass *analysis.Pass) (interface{}, error) { } return true } + + var isStackAddr func(ir.Value) bool + isStackAddr = func(v ir.Value) bool { + switch v := v.(type) { + case *ir.Alloc: + return !v.Heap + case *ir.FieldAddr: + return isStackAddr(v.X) + default: + return false + } + } for _, b := range fn.Blocks { for _, ins := range b.Instrs { switch ins := ins.(type) { @@ -154,13 +231,22 @@ func purity(pass *analysis.Pass) (interface{}, error) { case *ir.Panic: return false case *ir.Store: - return false + if !isStackAddr(ins.Addr) { + return false + } case *ir.FieldAddr: - return false + if !isStackAddr(ins.X) { + return false + } case *ir.Alloc: - return false + // TODO(dh): make use of proper escape analysis + if ins.Heap { + return false + } case *ir.Load: - return false + if !isStackAddr(ins.X) { + return false + } } } } diff --git a/vendor/honnef.co/go/tools/simple/lint.go b/vendor/honnef.co/go/tools/simple/lint.go index 67c694f9c9..084264367c 100644 --- a/vendor/honnef.co/go/tools/simple/lint.go +++ b/vendor/honnef.co/go/tools/simple/lint.go @@ -176,20 +176,20 @@ func CheckLoopCopy(pass *analysis.Pass) (interface{}, error) { report.ShortRange(), report.Fixes(edit.Fix("replace loop with assignment", edit.ReplaceWithNode(pass.Fset, node, r)))) } else { - opts := []report.Option{ - report.ShortRange(), - report.FilterGenerated(), - } tv, err := types.Eval(pass.Fset, pass.Pkg, node.Pos(), "copy") if err == nil && tv.IsBuiltin() { + to := "to" + from := "from" src := m.State["src"].(ast.Expr) if TsrcArray { + from = "from[:]" src = &ast.SliceExpr{ X: src, } } dst := m.State["dst"].(ast.Expr) if TdstArray { + to = "to[:]" dst = &ast.SliceExpr{ X: dst, } @@ -199,9 +199,13 @@ func CheckLoopCopy(pass *analysis.Pass) (interface{}, error) { Fun: &ast.Ident{Name: "copy"}, Args: []ast.Expr{dst, src}, } - opts = append(opts, report.Fixes(edit.Fix("replace loop with call to copy()", edit.ReplaceWithNode(pass.Fset, node, r)))) + opts := []report.Option{ + report.ShortRange(), + report.FilterGenerated(), + report.Fixes(edit.Fix("replace loop with call to copy()", edit.ReplaceWithNode(pass.Fset, node, r))), + } + report.Report(pass, node, fmt.Sprintf("should use copy(%s, %s) instead of a loop", to, from), opts...) } - report.Report(pass, node, "should use copy() instead of a loop", opts...) } } code.Preorder(pass, fn, (*ast.ForStmt)(nil), (*ast.RangeStmt)(nil)) diff --git a/vendor/honnef.co/go/tools/staticcheck/analysis.go b/vendor/honnef.co/go/tools/staticcheck/analysis.go index 171467a8f9..210c348c9c 100644 --- a/vendor/honnef.co/go/tools/staticcheck/analysis.go +++ b/vendor/honnef.co/go/tools/staticcheck/analysis.go @@ -174,7 +174,7 @@ var Analyzers = lint.InitializeAnalyzers(Docs, map[string]*analysis.Analyzer{ Requires: []*analysis.Analyzer{inspect.Analyzer, tokenfile.Analyzer}, }, "SA4017": { - Run: CheckPureFunctions, + Run: CheckSideEffectFreeCalls, Requires: []*analysis.Analyzer{buildir.Analyzer, purity.Analyzer}, }, "SA4018": { diff --git a/vendor/honnef.co/go/tools/staticcheck/doc.go b/vendor/honnef.co/go/tools/staticcheck/doc.go index ffb2674da9..c28fdbf04b 100644 --- a/vendor/honnef.co/go/tools/staticcheck/doc.go +++ b/vendor/honnef.co/go/tools/staticcheck/doc.go @@ -506,7 +506,7 @@ falsify results.`, }, "SA4017": { - Title: `A pure function's return value is discarded, making the call pointless`, + Title: `Discarding the return values of a function without side effects, making the call pointless`, Since: "2017.1", Severity: lint.SeverityWarning, MergeIf: lint.MergeIfAll, diff --git a/vendor/honnef.co/go/tools/staticcheck/lint.go b/vendor/honnef.co/go/tools/staticcheck/lint.go index 85bcb21aad..77e42b4232 100644 --- a/vendor/honnef.co/go/tools/staticcheck/lint.go +++ b/vendor/honnef.co/go/tools/staticcheck/lint.go @@ -3009,7 +3009,7 @@ func CheckNonOctalFileMode(pass *analysis.Pass) (interface{}, error) { return nil, nil } -func CheckPureFunctions(pass *analysis.Pass) (interface{}, error) { +func CheckSideEffectFreeCalls(pass *analysis.Pass) (interface{}, error) { pure := pass.ResultOf[purity.Analyzer].(purity.Result) fnLoop: @@ -3055,7 +3055,7 @@ fnLoop: // special case for benchmarks in the fmt package continue } - report.Report(pass, ins, fmt.Sprintf("%s is a pure function but its return value is ignored", callee.Object().Name())) + report.Report(pass, ins, fmt.Sprintf("%s doesn't have side effects and its return value is ignored", callee.Object().Name())) } } } @@ -3166,6 +3166,8 @@ func CheckDeprecated(pass *analysis.Pass) (interface{}, error) { if fn, ok := node.(*ast.FuncDecl); ok { tfn = pass.TypesInfo.ObjectOf(fn.Name) } + + // FIXME(dh): this misses dot-imported objects sel, ok := node.(*ast.SelectorExpr) if !ok { return true @@ -3178,8 +3180,26 @@ func CheckDeprecated(pass *analysis.Pass) (interface{}, error) { if obj.Pkg() == nil { return true } - if pass.Pkg == obj.Pkg() || obj.Pkg().Path()+"_test" == pass.Pkg.Path() { - // Don't flag stuff in our own package + + if obj.Pkg() == pass.Pkg { + // A package is allowed to use its own deprecated objects + return true + } + + // A package "foo" has two related packages "foo_test" and "foo.test", for external tests and the package main + // generated by 'go test' respectively. "foo_test" can import and use "foo", "foo.test" imports and uses "foo" + // and "foo_test". + + if strings.TrimSuffix(pass.Pkg.Path(), "_test") == obj.Pkg().Path() { + // foo_test (the external tests of foo) can use objects from foo. + return true + } + if strings.TrimSuffix(pass.Pkg.Path(), ".test") == obj.Pkg().Path() { + // foo.test (the main package of foo's tests) can use objects from foo. + return true + } + if strings.TrimSuffix(pass.Pkg.Path(), ".test") == strings.TrimSuffix(obj.Pkg().Path(), "_test") { + // foo.test (the main package of foo's tests) can use objects from foo's external tests. return true } @@ -3208,6 +3228,19 @@ func CheckDeprecated(pass *analysis.Pass) (interface{}, error) { } } + if strings.TrimSuffix(pass.Pkg.Path(), "_test") == path { + // foo_test can import foo + return + } + if strings.TrimSuffix(pass.Pkg.Path(), ".test") == path { + // foo.test can import foo + return + } + if strings.TrimSuffix(pass.Pkg.Path(), ".test") == strings.TrimSuffix(path, "_test") { + // foo.test can import foo_test + return + } + handleDeprecation(depr, spec.Path, path, path, nil) } } @@ -3996,12 +4029,12 @@ func CheckImpossibleTypeAssertion(pass *analysis.Pass) (interface{}, error) { ms := msc.MethodSet(left) for i := 0; i < righti.NumMethods(); i++ { - mr := righti.Method(i) + mr := righti.Method(i).Origin() sel := ms.Lookup(mr.Pkg(), mr.Name()) if sel == nil { continue } - ml := sel.Obj().(*types.Func) + ml := sel.Obj().(*types.Func).Origin() if types.AssignableTo(ml.Type(), mr.Type()) { continue } diff --git a/vendor/honnef.co/go/tools/unused/edge.go b/vendor/honnef.co/go/tools/unused/edge.go deleted file mode 100644 index 6d32946d29..0000000000 --- a/vendor/honnef.co/go/tools/unused/edge.go +++ /dev/null @@ -1,59 +0,0 @@ -package unused - -//go:generate go run golang.org/x/tools/cmd/stringer@master -type edgeKind -type edgeKind uint64 - -func (e edgeKind) is(o edgeKind) bool { - return e&o != 0 -} - -const ( - edgeAlias edgeKind = 1 << iota - edgeBlankField - edgeAnonymousStruct - edgeCgoExported - edgeConstGroup - edgeElementType - edgeEmbeddedInterface - edgeExportedConstant - edgeExportedField - edgeExportedFunction - edgeExportedMethod - edgeExportedType - edgeExportedVariable - edgeExtendsExportedFields - edgeExtendsExportedMethodSet - edgeFieldAccess - edgeFunctionArgument - edgeFunctionResult - edgeFunctionSignature - edgeImplements - edgeInstructionOperand - edgeInterfaceCall - edgeInterfaceMethod - edgeKeyType - edgeLinkname - edgeMainFunction - edgeNamedType - edgeNetRPCRegister - edgeNoCopySentinel - edgeProvidesMethod - edgeReceiver - edgeRuntimeFunction - edgeSignature - edgeStructConversion - edgeTestSink - edgeTupleElement - edgeType - edgeTypeName - edgeUnderlyingType - edgePointerType - edgeUnsafeConversion - edgeUsedConstant - edgeVarDecl - edgeIgnored - edgeSamePointer - edgeTypeParam - edgeTypeArg - edgeUnionTerm -) diff --git a/vendor/honnef.co/go/tools/unused/edgekind_string.go b/vendor/honnef.co/go/tools/unused/edgekind_string.go deleted file mode 100644 index ae27b2507d..0000000000 --- a/vendor/honnef.co/go/tools/unused/edgekind_string.go +++ /dev/null @@ -1,119 +0,0 @@ -// Code generated by "stringer -type edgeKind"; DO NOT EDIT. - -package unused - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[edgeAlias-1] - _ = x[edgeBlankField-2] - _ = x[edgeAnonymousStruct-4] - _ = x[edgeCgoExported-8] - _ = x[edgeConstGroup-16] - _ = x[edgeElementType-32] - _ = x[edgeEmbeddedInterface-64] - _ = x[edgeExportedConstant-128] - _ = x[edgeExportedField-256] - _ = x[edgeExportedFunction-512] - _ = x[edgeExportedMethod-1024] - _ = x[edgeExportedType-2048] - _ = x[edgeExportedVariable-4096] - _ = x[edgeExtendsExportedFields-8192] - _ = x[edgeExtendsExportedMethodSet-16384] - _ = x[edgeFieldAccess-32768] - _ = x[edgeFunctionArgument-65536] - _ = x[edgeFunctionResult-131072] - _ = x[edgeFunctionSignature-262144] - _ = x[edgeImplements-524288] - _ = x[edgeInstructionOperand-1048576] - _ = x[edgeInterfaceCall-2097152] - _ = x[edgeInterfaceMethod-4194304] - _ = x[edgeKeyType-8388608] - _ = x[edgeLinkname-16777216] - _ = x[edgeMainFunction-33554432] - _ = x[edgeNamedType-67108864] - _ = x[edgeNetRPCRegister-134217728] - _ = x[edgeNoCopySentinel-268435456] - _ = x[edgeProvidesMethod-536870912] - _ = x[edgeReceiver-1073741824] - _ = x[edgeRuntimeFunction-2147483648] - _ = x[edgeSignature-4294967296] - _ = x[edgeStructConversion-8589934592] - _ = x[edgeTestSink-17179869184] - _ = x[edgeTupleElement-34359738368] - _ = x[edgeType-68719476736] - _ = x[edgeTypeName-137438953472] - _ = x[edgeUnderlyingType-274877906944] - _ = x[edgePointerType-549755813888] - _ = x[edgeUnsafeConversion-1099511627776] - _ = x[edgeUsedConstant-2199023255552] - _ = x[edgeVarDecl-4398046511104] - _ = x[edgeIgnored-8796093022208] - _ = x[edgeSamePointer-17592186044416] - _ = x[edgeTypeParam-35184372088832] - _ = x[edgeTypeArg-70368744177664] - _ = x[edgeUnionTerm-140737488355328] -} - -const _edgeKind_name = "edgeAliasedgeBlankFieldedgeAnonymousStructedgeCgoExportededgeConstGroupedgeElementTypeedgeEmbeddedInterfaceedgeExportedConstantedgeExportedFieldedgeExportedFunctionedgeExportedMethodedgeExportedTypeedgeExportedVariableedgeExtendsExportedFieldsedgeExtendsExportedMethodSetedgeFieldAccessedgeFunctionArgumentedgeFunctionResultedgeFunctionSignatureedgeImplementsedgeInstructionOperandedgeInterfaceCalledgeInterfaceMethodedgeKeyTypeedgeLinknameedgeMainFunctionedgeNamedTypeedgeNetRPCRegisteredgeNoCopySentineledgeProvidesMethodedgeReceiveredgeRuntimeFunctionedgeSignatureedgeStructConversionedgeTestSinkedgeTupleElementedgeTypeedgeTypeNameedgeUnderlyingTypeedgePointerTypeedgeUnsafeConversionedgeUsedConstantedgeVarDecledgeIgnorededgeSamePointeredgeTypeParamedgeTypeArgedgeUnionTerm" - -var _edgeKind_map = map[edgeKind]string{ - 1: _edgeKind_name[0:9], - 2: _edgeKind_name[9:23], - 4: _edgeKind_name[23:42], - 8: _edgeKind_name[42:57], - 16: _edgeKind_name[57:71], - 32: _edgeKind_name[71:86], - 64: _edgeKind_name[86:107], - 128: _edgeKind_name[107:127], - 256: _edgeKind_name[127:144], - 512: _edgeKind_name[144:164], - 1024: _edgeKind_name[164:182], - 2048: _edgeKind_name[182:198], - 4096: _edgeKind_name[198:218], - 8192: _edgeKind_name[218:243], - 16384: _edgeKind_name[243:271], - 32768: _edgeKind_name[271:286], - 65536: _edgeKind_name[286:306], - 131072: _edgeKind_name[306:324], - 262144: _edgeKind_name[324:345], - 524288: _edgeKind_name[345:359], - 1048576: _edgeKind_name[359:381], - 2097152: _edgeKind_name[381:398], - 4194304: _edgeKind_name[398:417], - 8388608: _edgeKind_name[417:428], - 16777216: _edgeKind_name[428:440], - 33554432: _edgeKind_name[440:456], - 67108864: _edgeKind_name[456:469], - 134217728: _edgeKind_name[469:487], - 268435456: _edgeKind_name[487:505], - 536870912: _edgeKind_name[505:523], - 1073741824: _edgeKind_name[523:535], - 2147483648: _edgeKind_name[535:554], - 4294967296: _edgeKind_name[554:567], - 8589934592: _edgeKind_name[567:587], - 17179869184: _edgeKind_name[587:599], - 34359738368: _edgeKind_name[599:615], - 68719476736: _edgeKind_name[615:623], - 137438953472: _edgeKind_name[623:635], - 274877906944: _edgeKind_name[635:653], - 549755813888: _edgeKind_name[653:668], - 1099511627776: _edgeKind_name[668:688], - 2199023255552: _edgeKind_name[688:704], - 4398046511104: _edgeKind_name[704:715], - 8796093022208: _edgeKind_name[715:726], - 17592186044416: _edgeKind_name[726:741], - 35184372088832: _edgeKind_name[741:754], - 70368744177664: _edgeKind_name[754:765], - 140737488355328: _edgeKind_name[765:778], -} - -func (i edgeKind) String() string { - if str, ok := _edgeKind_map[i]; ok { - return str - } - return "edgeKind(" + strconv.FormatInt(int64(i), 10) + ")" -} diff --git a/vendor/honnef.co/go/tools/unused/implements.go b/vendor/honnef.co/go/tools/unused/implements.go index f62018572b..2a202c6d73 100644 --- a/vendor/honnef.co/go/tools/unused/implements.go +++ b/vendor/honnef.co/go/tools/unused/implements.go @@ -37,7 +37,7 @@ func sameId(obj types.Object, pkg *types.Package, name string) bool { return pkg.Path() == obj.Pkg().Path() } -func (g *graph) implements(V types.Type, T *types.Interface, msV *types.MethodSet) ([]*types.Selection, bool) { +func implements(V types.Type, T *types.Interface, msV *types.MethodSet) ([]*types.Selection, bool) { // fast path for common case if T.Empty() { return nil, true diff --git a/vendor/honnef.co/go/tools/unused/runtime.go b/vendor/honnef.co/go/tools/unused/runtime.go new file mode 100644 index 0000000000..11be4a34af --- /dev/null +++ b/vendor/honnef.co/go/tools/unused/runtime.go @@ -0,0 +1,331 @@ +package unused + +// Functions defined in the Go runtime that may be called through +// compiler magic or via assembly. +var runtimeFuncs = map[string]bool{ + // Copied from cmd/compile/internal/typecheck/builtin.go, var runtimeDecls + "newobject": true, + "panicindex": true, + "panicslice": true, + "panicdivide": true, + "panicmakeslicelen": true, + "throwinit": true, + "panicwrap": true, + "gopanic": true, + "gorecover": true, + "goschedguarded": true, + "printbool": true, + "printfloat": true, + "printint": true, + "printhex": true, + "printuint": true, + "printcomplex": true, + "printstring": true, + "printpointer": true, + "printiface": true, + "printeface": true, + "printslice": true, + "printnl": true, + "printsp": true, + "printlock": true, + "printunlock": true, + "concatstring2": true, + "concatstring3": true, + "concatstring4": true, + "concatstring5": true, + "concatstrings": true, + "cmpstring": true, + "intstring": true, + "slicebytetostring": true, + "slicebytetostringtmp": true, + "slicerunetostring": true, + "stringtoslicebyte": true, + "stringtoslicerune": true, + "slicecopy": true, + "slicestringcopy": true, + "decoderune": true, + "countrunes": true, + "convI2I": true, + "convT16": true, + "convT32": true, + "convT64": true, + "convTstring": true, + "convTslice": true, + "convT2E": true, + "convT2Enoptr": true, + "convT2I": true, + "convT2Inoptr": true, + "assertE2I": true, + "assertE2I2": true, + "assertI2I": true, + "assertI2I2": true, + "panicdottypeE": true, + "panicdottypeI": true, + "panicnildottype": true, + "ifaceeq": true, + "efaceeq": true, + "fastrand": true, + "makemap64": true, + "makemap": true, + "makemap_small": true, + "mapaccess1": true, + "mapaccess1_fast32": true, + "mapaccess1_fast64": true, + "mapaccess1_faststr": true, + "mapaccess1_fat": true, + "mapaccess2": true, + "mapaccess2_fast32": true, + "mapaccess2_fast64": true, + "mapaccess2_faststr": true, + "mapaccess2_fat": true, + "mapassign": true, + "mapassign_fast32": true, + "mapassign_fast32ptr": true, + "mapassign_fast64": true, + "mapassign_fast64ptr": true, + "mapassign_faststr": true, + "mapiterinit": true, + "mapdelete": true, + "mapdelete_fast32": true, + "mapdelete_fast64": true, + "mapdelete_faststr": true, + "mapiternext": true, + "mapclear": true, + "makechan64": true, + "makechan": true, + "chanrecv1": true, + "chanrecv2": true, + "chansend1": true, + "closechan": true, + "writeBarrier": true, + "typedmemmove": true, + "typedmemclr": true, + "typedslicecopy": true, + "selectnbsend": true, + "selectnbrecv": true, + "selectnbrecv2": true, + "selectsetpc": true, + "selectgo": true, + "block": true, + "makeslice": true, + "makeslice64": true, + "growslice": true, + "memmove": true, + "memclrNoHeapPointers": true, + "memclrHasPointers": true, + "memequal": true, + "memequal8": true, + "memequal16": true, + "memequal32": true, + "memequal64": true, + "memequal128": true, + "int64div": true, + "uint64div": true, + "int64mod": true, + "uint64mod": true, + "float64toint64": true, + "float64touint64": true, + "float64touint32": true, + "int64tofloat64": true, + "uint64tofloat64": true, + "uint32tofloat64": true, + "complex128div": true, + "racefuncenter": true, + "racefuncenterfp": true, + "racefuncexit": true, + "raceread": true, + "racewrite": true, + "racereadrange": true, + "racewriterange": true, + "msanread": true, + "msanwrite": true, + "x86HasPOPCNT": true, + "x86HasSSE41": true, + "arm64HasATOMICS": true, + "mallocgc": true, + "panicshift": true, + "panicmakeslicecap": true, + "goPanicIndex": true, + "goPanicIndexU": true, + "goPanicSliceAlen": true, + "goPanicSliceAlenU": true, + "goPanicSliceAcap": true, + "goPanicSliceAcapU": true, + "goPanicSliceB": true, + "goPanicSliceBU": true, + "goPanicSlice3Alen": true, + "goPanicSlice3AlenU": true, + "goPanicSlice3Acap": true, + "goPanicSlice3AcapU": true, + "goPanicSlice3B": true, + "goPanicSlice3BU": true, + "goPanicSlice3C": true, + "goPanicSlice3CU": true, + "goPanicSliceConvert": true, + "printuintptr": true, + "convT": true, + "convTnoptr": true, + "makeslicecopy": true, + "unsafeslicecheckptr": true, + "panicunsafeslicelen": true, + "panicunsafeslicenilptr": true, + "unsafestringcheckptr": true, + "panicunsafestringlen": true, + "panicunsafestringnilptr": true, + "mulUintptr": true, + "memequal0": true, + "f32equal": true, + "f64equal": true, + "c64equal": true, + "c128equal": true, + "strequal": true, + "interequal": true, + "nilinterequal": true, + "memhash": true, + "memhash0": true, + "memhash8": true, + "memhash16": true, + "memhash32": true, + "memhash64": true, + "memhash128": true, + "f32hash": true, + "f64hash": true, + "c64hash": true, + "c128hash": true, + "strhash": true, + "interhash": true, + "nilinterhash": true, + "int64tofloat32": true, + "uint64tofloat32": true, + "getcallerpc": true, + "getcallersp": true, + "msanmove": true, + "asanread": true, + "asanwrite": true, + "checkptrAlignment": true, + "checkptrArithmetic": true, + "libfuzzerTraceCmp1": true, + "libfuzzerTraceCmp2": true, + "libfuzzerTraceCmp4": true, + "libfuzzerTraceCmp8": true, + "libfuzzerTraceConstCmp1": true, + "libfuzzerTraceConstCmp2": true, + "libfuzzerTraceConstCmp4": true, + "libfuzzerTraceConstCmp8": true, + "libfuzzerHookStrCmp": true, + "libfuzzerHookEqualFold": true, + "addCovMeta": true, + "x86HasFMA": true, + "armHasVFPv4": true, + + // Extracted from assembly code in the standard library, with the exception of the runtime package itself + "abort": true, + "aeshashbody": true, + "args": true, + "asminit": true, + "badctxt": true, + "badmcall2": true, + "badmcall": true, + "badmorestackg0": true, + "badmorestackgsignal": true, + "badsignal2": true, + "callbackasm1": true, + "callCfunction": true, + "cgocallback_gofunc": true, + "cgocallbackg": true, + "checkgoarm": true, + "check": true, + "debugCallCheck": true, + "debugCallWrap": true, + "emptyfunc": true, + "entersyscall": true, + "exit": true, + "exits": true, + "exitsyscall": true, + "externalthreadhandler": true, + "findnull": true, + "goexit1": true, + "gostring": true, + "i386_set_ldt": true, + "_initcgo": true, + "init_thread_tls": true, + "ldt0setup": true, + "libpreinit": true, + "load_g": true, + "morestack": true, + "mstart": true, + "nacl_sysinfo": true, + "nanotimeQPC": true, + "nanotime": true, + "newosproc0": true, + "newproc": true, + "newstack": true, + "noted": true, + "nowQPC": true, + "osinit": true, + "printf": true, + "racecallback": true, + "reflectcallmove": true, + "reginit": true, + "rt0_go": true, + "save_g": true, + "schedinit": true, + "setldt": true, + "settls": true, + "sighandler": true, + "sigprofNonGo": true, + "sigtrampgo": true, + "_sigtramp": true, + "sigtramp": true, + "stackcheck": true, + "syscall_chdir": true, + "syscall_chroot": true, + "syscall_close": true, + "syscall_dup2": true, + "syscall_execve": true, + "syscall_exit": true, + "syscall_fcntl": true, + "syscall_forkx": true, + "syscall_gethostname": true, + "syscall_getpid": true, + "syscall_ioctl": true, + "syscall_pipe": true, + "syscall_rawsyscall6": true, + "syscall_rawSyscall6": true, + "syscall_rawsyscall": true, + "syscall_RawSyscall": true, + "syscall_rawsysvicall6": true, + "syscall_setgid": true, + "syscall_setgroups": true, + "syscall_setpgid": true, + "syscall_setsid": true, + "syscall_setuid": true, + "syscall_syscall6": true, + "syscall_syscall": true, + "syscall_Syscall": true, + "syscall_sysvicall6": true, + "syscall_wait4": true, + "syscall_write": true, + "traceback": true, + "tstart": true, + "usplitR0": true, + "wbBufFlush": true, + "write": true, + + // Other runtime functions that can get called in non-standard ways + "bgsweep": true, + "memhash_varlen": true, + "strhashFallback": true, + "asanregisterglobals": true, + "cgoUse": true, + "cgoCheckPointer": true, + "cgoCheckResult": true, + "_cgo_panic_internal": true, + "addExitHook": true, +} + +var runtimeCoverageFuncs = map[string]bool{ + "initHook": true, + "markProfileEmitted": true, + "processCoverTestDir": true, +} diff --git a/vendor/honnef.co/go/tools/unused/serialize.go b/vendor/honnef.co/go/tools/unused/serialize.go new file mode 100644 index 0000000000..126e7400aa --- /dev/null +++ b/vendor/honnef.co/go/tools/unused/serialize.go @@ -0,0 +1,99 @@ +package unused + +import ( + "fmt" + "go/token" + "os" + + "golang.org/x/tools/go/types/objectpath" +) + +type ObjectPath struct { + PkgPath string + ObjPath objectpath.Path +} + +// XXX make sure that node 0 always exists and is always the root + +type SerializedGraph struct { + nodes []Node + nodesByPath map[ObjectPath]NodeID + // XXX deduplicating on position is dubious for `switch x := foo.(type)`, where x will be declared many times for + // the different types, but all at the same position. On the other hand, merging these nodes is probably fine. + nodesByPosition map[token.Position]NodeID +} + +func trace(f string, args ...interface{}) { + fmt.Fprintf(os.Stderr, f, args...) + fmt.Fprintln(os.Stderr) +} + +func (g *SerializedGraph) Merge(nodes []Node) { + if g.nodesByPath == nil { + g.nodesByPath = map[ObjectPath]NodeID{} + } + if g.nodesByPosition == nil { + g.nodesByPosition = map[token.Position]NodeID{} + } + if len(g.nodes) == 0 { + // Seed nodes with a root node + g.nodes = append(g.nodes, Node{}) + } + // OPT(dh): reuse storage between calls to Merge + remapping := make([]NodeID, len(nodes)) + + // First pass: compute remapping of IDs of to-be-merged nodes + for _, n := range nodes { + // XXX Column is never 0. it's 1 if there is no column information in the export data. which sucks, because + // objects can also genuinely be in column 1. + if n.id != 0 && n.obj.Path == (ObjectPath{}) && n.obj.Position.Column == 0 { + // If the object has no path, then it couldn't have come from export data, which means it needs to have full + // position information including a column. + panic(fmt.Sprintf("object %q has no path but also no column information", n.obj.Name)) + } + + if orig, ok := g.nodesByPath[n.obj.Path]; ok { + // We already have a node for this object + trace("deduplicating %d -> %d based on path %s", n.id, orig, n.obj.Path) + remapping[n.id] = orig + } else if orig, ok := g.nodesByPosition[n.obj.Position]; ok && n.obj.Position.Column != 0 { + // We already have a node for this object + trace("deduplicating %d -> %d based on position %s", n.id, orig, n.obj.Position) + remapping[n.id] = orig + } else { + // This object is new to us; change ID to avoid collision + newID := NodeID(len(g.nodes)) + trace("new node, remapping %d -> %d", n.id, newID) + remapping[n.id] = newID + g.nodes = append(g.nodes, Node{ + id: newID, + obj: n.obj, + uses: make([]NodeID, 0, len(n.uses)), + owns: make([]NodeID, 0, len(n.owns)), + }) + if n.id == 0 { + // Our root uses all the roots of the subgraphs + g.nodes[0].uses = append(g.nodes[0].uses, newID) + } + if n.obj.Path != (ObjectPath{}) { + g.nodesByPath[n.obj.Path] = newID + } + if n.obj.Position.Column != 0 { + g.nodesByPosition[n.obj.Position] = newID + } + } + } + + // Second step: apply remapping + for _, n := range nodes { + n.id = remapping[n.id] + for i := range n.uses { + n.uses[i] = remapping[n.uses[i]] + } + for i := range n.owns { + n.owns[i] = remapping[n.owns[i]] + } + g.nodes[n.id].uses = append(g.nodes[n.id].uses, n.uses...) + g.nodes[n.id].owns = append(g.nodes[n.id].owns, n.owns...) + } +} diff --git a/vendor/honnef.co/go/tools/unused/unused.go b/vendor/honnef.co/go/tools/unused/unused.go index 58bdea8c63..95e743a277 100644 --- a/vendor/honnef.co/go/tools/unused/unused.go +++ b/vendor/honnef.co/go/tools/unused/unused.go @@ -1,8 +1,6 @@ // Package unused contains code for finding unused code. package unused -// TODO(dh): don't add instantiated types/methods to the graph. add the origin types/methods. - import ( "fmt" "go/ast" @@ -12,66 +10,61 @@ import ( "reflect" "strings" - "honnef.co/go/tools/analysis/code" "honnef.co/go/tools/analysis/facts/directives" "honnef.co/go/tools/analysis/facts/generated" "honnef.co/go/tools/analysis/lint" "honnef.co/go/tools/analysis/report" "honnef.co/go/tools/go/ast/astutil" - "honnef.co/go/tools/go/ir" "honnef.co/go/tools/go/types/typeutil" - "honnef.co/go/tools/internal/passes/buildir" "golang.org/x/exp/typeparams" "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/types/objectpath" ) -var Debug io.Writer +// OPT(dh): don't track local variables that can't have any interesting outgoing edges. For example, using a local +// variable of type int is meaningless; we don't care if `int` is used or not. +// +// Note that we do have to track variables with for example array types, because the array type could have involved a +// named constant. +// +// We probably have different culling needs depending on the mode of operation, too. If we analyze multiple packages in +// one graph (unused's "whole program" mode), we could remove further useless edges (e.g. into nodes that themselves +// have no outgoing edges and aren't meaningful objects on their own) after having analyzed a package, to keep the +// in-memory representation small on average. If we only analyze a single package, that step would just waste cycles, as +// we're about to throw the entire graph away, anyway. -// The graph we construct omits nodes along a path that do not -// contribute any new information to the solution. For example, the -// full graph for a function with a receiver would be Func -> -// Signature -> Var -> Type. However, since signatures cannot be -// unused, and receivers are always considered used, we can compact -// the graph down to Func -> Type. This makes the graph smaller, but -// harder to debug. +// TODO(dh): currently, types use methods that implement interfaces. However, this makes a method used even if the +// relevant interface is never used. What if instead interfaces used those methods? Right now we cannot do that, because +// methods use their receivers, so using a method uses the type. But do we need that edge? Is there a way to refer to a +// method without explicitly mentioning the type somewhere? If not, the edge from method to receiver is superfluous. -// TODO(dh): conversions between structs mark fields as used, but the -// conversion itself isn't part of that subgraph. even if the function -// containing the conversion is unused, the fields will be marked as -// used. +// XXX vet all code for proper use of core types // TODO(dh): we cannot observe function calls in assembly files. /* +This overview is true when using the default options. Different options may change individual behaviors. + - packages use: - (1.1) exported named types - - (1.2) exported functions + - (1.2) exported functions (but not methods!) - (1.3) exported variables - (1.4) exported constants - (1.5) init functions - (1.6) functions exported to cgo - (1.7) the main function iff in the main package - (1.8) symbols linked via go:linkname + - (1.9) objects in generated files - named types use: - (2.1) exported methods - (2.2) the type they're based on - - (2.3) all their aliases. we can't easily track uses of aliases - because go/types turns them into uses of the aliased types. assume - that if a type is used, so are all of its aliases. - - (2.4) the pointer type. this aids with eagerly implementing - interfaces. if a method that implements an interface is defined on - a pointer receiver, and the pointer type is never used, but the - named type is, then we still want to mark the method as used. - (2.5) all their type parameters. Unused type parameters are probably useless, but they're a brand new feature and we don't want to introduce false positives because we couldn't anticipate some novel use-case. - (2.6) all their type arguments -- variables and constants use: - - their types - - functions use: - (4.1) all their arguments, return parameters and receivers - (4.2) anonymous functions defined beneath them @@ -80,11 +73,14 @@ var Debug io.Writer that way we don't have to keep track of closures escaping functions. - (4.4) functions they return. we assume that someone else will call the returned function - (4.5) functions/interface methods they call - - types they instantiate or convert to + - (4.6) types they instantiate or convert to - (4.7) fields they access - - (4.8) types of all instructions - (4.9) package-level variables they assign to iff in tests (sinks for benchmarks) - (4.10) all their type parameters. See 2.5 for reasoning. + - (4.11) local variables + - Note that the majority of this is handled implicitly by seeing idents be used. In particular, unlike the old + IR-based implementation, the AST-based one doesn't care about closures, bound methods or anonymous functions. + They're all just additional nodes in the AST. - conversions use: - (5.1) when converting between two equivalent structs, the fields in @@ -107,7 +103,7 @@ var Debug io.Writer - (8.1) We do not technically care about interfaces that only consist of exported methods. Exported methods on concrete types are always marked as used. - - Any concrete type implements all known interfaces. Even if it isn't + - (8.2) Any concrete type implements all known interfaces. Even if it isn't assigned to any interfaces in our code, the user may receive a value of the type and expect to pass it back to us through an interface. @@ -126,20 +122,22 @@ var Debug io.Writer used by 8.3 just because it contributes A's methods to C. - Inherent uses: - - thunks and other generated wrappers call the real function - (9.2) variables use their types - (9.3) types use their underlying and element types - (9.4) conversions use the type they convert to - - (9.5) instructions use their operands - - (9.6) instructions use their operands' types - (9.7) variable _reads_ use variables, writes do not, except in tests - (9.8) runtime functions that may be called from user code via the compiler + - (9.9) objects named the blank identifier are used. They cannot be referred to and are usually used explicitly to + use something that would otherwise be unused. + - The majority of idents get marked as read by virtue of being in the AST. - const groups: - (10.1) if one constant out of a block of constants is used, mark all - of them used. a lot of the time, unused constants exist for the sake - of completeness. See also - https://github.com/dominikh/go-tools/issues/365 + - (10.1) if one constant out of a block of constants is used, mark all + of them used. a lot of the time, unused constants exist for the sake + of completeness. See also + https://github.com/dominikh/go-tools/issues/365 + + Do not, however, include constants named _ in constant groups. - (11.1) anonymous struct types use all their fields. we cannot @@ -155,364 +153,19 @@ var Debug io.Writer */ +var Debug io.Writer + func assert(b bool) { if !b { panic("failed assertion") } } -// /usr/lib/go/src/runtime/proc.go:433:6: func badmorestackg0 is unused (U1000) - -// Functions defined in the Go runtime that may be called through -// compiler magic or via assembly. -var runtimeFuncs = map[string]bool{ - // Copied from cmd/compile/internal/typecheck/builtin.go, var runtimeDecls - "newobject": true, - "panicindex": true, - "panicslice": true, - "panicdivide": true, - "panicmakeslicelen": true, - "throwinit": true, - "panicwrap": true, - "gopanic": true, - "gorecover": true, - "goschedguarded": true, - "printbool": true, - "printfloat": true, - "printint": true, - "printhex": true, - "printuint": true, - "printcomplex": true, - "printstring": true, - "printpointer": true, - "printiface": true, - "printeface": true, - "printslice": true, - "printnl": true, - "printsp": true, - "printlock": true, - "printunlock": true, - "concatstring2": true, - "concatstring3": true, - "concatstring4": true, - "concatstring5": true, - "concatstrings": true, - "cmpstring": true, - "intstring": true, - "slicebytetostring": true, - "slicebytetostringtmp": true, - "slicerunetostring": true, - "stringtoslicebyte": true, - "stringtoslicerune": true, - "slicecopy": true, - "slicestringcopy": true, - "decoderune": true, - "countrunes": true, - "convI2I": true, - "convT16": true, - "convT32": true, - "convT64": true, - "convTstring": true, - "convTslice": true, - "convT2E": true, - "convT2Enoptr": true, - "convT2I": true, - "convT2Inoptr": true, - "assertE2I": true, - "assertE2I2": true, - "assertI2I": true, - "assertI2I2": true, - "panicdottypeE": true, - "panicdottypeI": true, - "panicnildottype": true, - "ifaceeq": true, - "efaceeq": true, - "fastrand": true, - "makemap64": true, - "makemap": true, - "makemap_small": true, - "mapaccess1": true, - "mapaccess1_fast32": true, - "mapaccess1_fast64": true, - "mapaccess1_faststr": true, - "mapaccess1_fat": true, - "mapaccess2": true, - "mapaccess2_fast32": true, - "mapaccess2_fast64": true, - "mapaccess2_faststr": true, - "mapaccess2_fat": true, - "mapassign": true, - "mapassign_fast32": true, - "mapassign_fast32ptr": true, - "mapassign_fast64": true, - "mapassign_fast64ptr": true, - "mapassign_faststr": true, - "mapiterinit": true, - "mapdelete": true, - "mapdelete_fast32": true, - "mapdelete_fast64": true, - "mapdelete_faststr": true, - "mapiternext": true, - "mapclear": true, - "makechan64": true, - "makechan": true, - "chanrecv1": true, - "chanrecv2": true, - "chansend1": true, - "closechan": true, - "writeBarrier": true, - "typedmemmove": true, - "typedmemclr": true, - "typedslicecopy": true, - "selectnbsend": true, - "selectnbrecv": true, - "selectnbrecv2": true, - "selectsetpc": true, - "selectgo": true, - "block": true, - "makeslice": true, - "makeslice64": true, - "growslice": true, - "memmove": true, - "memclrNoHeapPointers": true, - "memclrHasPointers": true, - "memequal": true, - "memequal8": true, - "memequal16": true, - "memequal32": true, - "memequal64": true, - "memequal128": true, - "int64div": true, - "uint64div": true, - "int64mod": true, - "uint64mod": true, - "float64toint64": true, - "float64touint64": true, - "float64touint32": true, - "int64tofloat64": true, - "uint64tofloat64": true, - "uint32tofloat64": true, - "complex128div": true, - "racefuncenter": true, - "racefuncenterfp": true, - "racefuncexit": true, - "raceread": true, - "racewrite": true, - "racereadrange": true, - "racewriterange": true, - "msanread": true, - "msanwrite": true, - "x86HasPOPCNT": true, - "x86HasSSE41": true, - "arm64HasATOMICS": true, - "mallocgc": true, - "panicshift": true, - "panicmakeslicecap": true, - "goPanicIndex": true, - "goPanicIndexU": true, - "goPanicSliceAlen": true, - "goPanicSliceAlenU": true, - "goPanicSliceAcap": true, - "goPanicSliceAcapU": true, - "goPanicSliceB": true, - "goPanicSliceBU": true, - "goPanicSlice3Alen": true, - "goPanicSlice3AlenU": true, - "goPanicSlice3Acap": true, - "goPanicSlice3AcapU": true, - "goPanicSlice3B": true, - "goPanicSlice3BU": true, - "goPanicSlice3C": true, - "goPanicSlice3CU": true, - "goPanicSliceConvert": true, - "printuintptr": true, - "convT": true, - "convTnoptr": true, - "makeslicecopy": true, - "unsafeslicecheckptr": true, - "panicunsafeslicelen": true, - "panicunsafeslicenilptr": true, - "unsafestringcheckptr": true, - "panicunsafestringlen": true, - "panicunsafestringnilptr": true, - "mulUintptr": true, - "memequal0": true, - "f32equal": true, - "f64equal": true, - "c64equal": true, - "c128equal": true, - "strequal": true, - "interequal": true, - "nilinterequal": true, - "memhash": true, - "memhash0": true, - "memhash8": true, - "memhash16": true, - "memhash32": true, - "memhash64": true, - "memhash128": true, - "f32hash": true, - "f64hash": true, - "c64hash": true, - "c128hash": true, - "strhash": true, - "interhash": true, - "nilinterhash": true, - "int64tofloat32": true, - "uint64tofloat32": true, - "getcallerpc": true, - "getcallersp": true, - "msanmove": true, - "asanread": true, - "asanwrite": true, - "checkptrAlignment": true, - "checkptrArithmetic": true, - "libfuzzerTraceCmp1": true, - "libfuzzerTraceCmp2": true, - "libfuzzerTraceCmp4": true, - "libfuzzerTraceCmp8": true, - "libfuzzerTraceConstCmp1": true, - "libfuzzerTraceConstCmp2": true, - "libfuzzerTraceConstCmp4": true, - "libfuzzerTraceConstCmp8": true, - "libfuzzerHookStrCmp": true, - "libfuzzerHookEqualFold": true, - "addCovMeta": true, - "x86HasFMA": true, - "armHasVFPv4": true, - - // Extracted from assembly code in the standard library, with the exception of the runtime package itself - "abort": true, - "aeshashbody": true, - "args": true, - "asminit": true, - "badctxt": true, - "badmcall2": true, - "badmcall": true, - "badmorestackg0": true, - "badmorestackgsignal": true, - "badsignal2": true, - "callbackasm1": true, - "callCfunction": true, - "cgocallback_gofunc": true, - "cgocallbackg": true, - "checkgoarm": true, - "check": true, - "debugCallCheck": true, - "debugCallWrap": true, - "emptyfunc": true, - "entersyscall": true, - "exit": true, - "exits": true, - "exitsyscall": true, - "externalthreadhandler": true, - "findnull": true, - "goexit1": true, - "gostring": true, - "i386_set_ldt": true, - "_initcgo": true, - "init_thread_tls": true, - "ldt0setup": true, - "libpreinit": true, - "load_g": true, - "morestack": true, - "mstart": true, - "nacl_sysinfo": true, - "nanotimeQPC": true, - "nanotime": true, - "newosproc0": true, - "newproc": true, - "newstack": true, - "noted": true, - "nowQPC": true, - "osinit": true, - "printf": true, - "racecallback": true, - "reflectcallmove": true, - "reginit": true, - "rt0_go": true, - "save_g": true, - "schedinit": true, - "setldt": true, - "settls": true, - "sighandler": true, - "sigprofNonGo": true, - "sigtrampgo": true, - "_sigtramp": true, - "sigtramp": true, - "stackcheck": true, - "syscall_chdir": true, - "syscall_chroot": true, - "syscall_close": true, - "syscall_dup2": true, - "syscall_execve": true, - "syscall_exit": true, - "syscall_fcntl": true, - "syscall_forkx": true, - "syscall_gethostname": true, - "syscall_getpid": true, - "syscall_ioctl": true, - "syscall_pipe": true, - "syscall_rawsyscall6": true, - "syscall_rawSyscall6": true, - "syscall_rawsyscall": true, - "syscall_RawSyscall": true, - "syscall_rawsysvicall6": true, - "syscall_setgid": true, - "syscall_setgroups": true, - "syscall_setpgid": true, - "syscall_setsid": true, - "syscall_setuid": true, - "syscall_syscall6": true, - "syscall_syscall": true, - "syscall_Syscall": true, - "syscall_sysvicall6": true, - "syscall_wait4": true, - "syscall_write": true, - "traceback": true, - "tstart": true, - "usplitR0": true, - "wbBufFlush": true, - "write": true, - - // Other runtime functions that can get called in non-standard ways - "bgsweep": true, - "memhash_varlen": true, - "strhashFallback": true, - "asanregisterglobals": true, - "cgoUse": true, - "cgoCheckPointer": true, - "cgoCheckResult": true, - "_cgo_panic_internal": true, - "addExitHook": true, -} - -var runtimeCoverageFuncs = map[string]bool{ - "initHook": true, - "markProfileEmitted": true, - "processCoverTestDir": true, -} - -type pkg struct { - Fset *token.FileSet - Files []*ast.File - Pkg *types.Package - TypesInfo *types.Info - TypesSizes types.Sizes - IR *ir.Package - SrcFuncs []*ir.Function - Directives []lint.Directive -} - // TODO(dh): should we return a map instead of two slices? type Result struct { - Used []types.Object - Unused []types.Object -} - -type SerializedResult struct { - Used []SerializedObject - Unused []SerializedObject + Used []Object + Unused []Object + Quiet []Object } var Analyzer = &lint.Analyzer{ @@ -523,483 +176,321 @@ var Analyzer = &lint.Analyzer{ Name: "U1000", Doc: "Unused code", Run: run, - Requires: []*analysis.Analyzer{buildir.Analyzer, generated.Analyzer, directives.Analyzer}, + Requires: []*analysis.Analyzer{generated.Analyzer, directives.Analyzer}, ResultType: reflect.TypeOf(Result{}), }, } -type SerializedObject struct { - Name string - Position token.Position - DisplayPosition token.Position - Kind string - InGenerated bool -} - -func typString(obj types.Object) string { - switch obj := obj.(type) { - case *types.Func: - return "func" - case *types.Var: - if obj.IsField() { - return "field" - } - return "var" - case *types.Const: - return "const" - case *types.TypeName: - if _, ok := obj.Type().(*types.TypeParam); ok { - return "type param" - } else { - return "type" - } - default: - return "identifier" - } -} - -func Serialize(pass *analysis.Pass, res Result, fset *token.FileSet) SerializedResult { - // OPT(dh): there's no point in serializing Used objects that are - // always used, such as exported names, blank identifiers, or - // anonymous struct fields. Used only exists to overrule Unused of - // a different package. If something can never be unused, then its - // presence in Used is useless. - // - // I'm not sure if this should happen when serializing, or when - // returning Result. - - out := SerializedResult{ - Used: make([]SerializedObject, len(res.Used)), - Unused: make([]SerializedObject, len(res.Unused)), - } - for i, obj := range res.Used { - out.Used[i] = serializeObject(pass, fset, obj) - } - for i, obj := range res.Unused { - out.Unused[i] = serializeObject(pass, fset, obj) - } - return out -} - -func serializeObject(pass *analysis.Pass, fset *token.FileSet, obj types.Object) SerializedObject { - name := obj.Name() - if sig, ok := obj.Type().(*types.Signature); ok && sig.Recv() != nil { - switch sig.Recv().Type().(type) { - case *types.Named, *types.Pointer: - typ := types.TypeString(sig.Recv().Type(), func(*types.Package) string { return "" }) - if len(typ) > 0 && typ[0] == '*' { - name = fmt.Sprintf("(%s).%s", typ, obj.Name()) - } else if len(typ) > 0 { - name = fmt.Sprintf("%s.%s", typ, obj.Name()) - } - } - } - return SerializedObject{ - Name: name, - Position: fset.PositionFor(obj.Pos(), false), - DisplayPosition: report.DisplayPosition(fset, obj.Pos()), - Kind: typString(obj), - InGenerated: code.IsGenerated(pass, obj.Pos()), - } -} - -func debugf(f string, v ...interface{}) { - if Debug != nil { - fmt.Fprintf(Debug, f, v...) - } +func newGraph( + fset *token.FileSet, + files []*ast.File, + pkg *types.Package, + info *types.Info, + directives []lint.Directive, + generated map[string]generated.Generator, + opts Options, +) *graph { + g := graph{ + pkg: pkg, + info: info, + files: files, + directives: directives, + generated: generated, + fset: fset, + nodes: []Node{{}}, + edges: map[edge]struct{}{}, + objects: map[types.Object]NodeID{}, + opts: opts, + } + + return &g } func run(pass *analysis.Pass) (interface{}, error) { - irpkg := pass.ResultOf[buildir.Analyzer].(*buildir.IR) - dirs := pass.ResultOf[directives.Analyzer].([]lint.Directive) - pkg := &pkg{ - Fset: pass.Fset, - Files: pass.Files, - Pkg: pass.Pkg, - TypesInfo: pass.TypesInfo, - TypesSizes: pass.TypesSizes, - IR: irpkg.Pkg, - SrcFuncs: irpkg.SrcFuncs, - Directives: dirs, - } + g := newGraph( + pass.Fset, + pass.Files, + pass.Pkg, + pass.TypesInfo, + pass.ResultOf[directives.Analyzer].([]lint.Directive), + pass.ResultOf[generated.Analyzer].(map[string]generated.Generator), + DefaultOptions, + ) + g.entry() - g := newGraph() - g.entry(pkg) - used, unused := results(g) + sg := &SerializedGraph{ + nodes: g.nodes, + } if Debug != nil { - debugNode := func(n *node) { - if n.obj == nil { - debugf("n%d [label=\"Root\"];\n", n.id) - } else { - color := "red" - if n.seen { - color = "green" - } - debugf("n%d [label=%q, color=%q];\n", n.id, fmt.Sprintf("(%T) %s", n.obj, n.obj), color) - } - for _, e := range n.used { - for i := edgeKind(1); i < 64; i++ { - if e.kind.is(1 << i) { - debugf("n%d -> n%d [label=%q];\n", n.id, e.node.id, edgeKind(1< 0 && typ[0] == '*' { + name = fmt.Sprintf("(%s).%s", typ, obj.Name()) + } else if len(typ) > 0 { + name = fmt.Sprintf("%s.%s", typ, obj.Name()) + } + } + } + return Object{ + Name: name, + ShortName: obj.Name(), + Kind: typString(obj), + Path: path, + Position: g.fset.PositionFor(obj.Pos(), false), + DisplayPosition: report.DisplayPosition(g.fset, obj.Pos()), } - return nil, false } -func (g *graph) node(obj interface{}) (n *node, new bool) { +func typString(obj types.Object) string { switch obj := obj.(type) { - case types.Type: - if v := g.TypeNodes[obj]; v != nil { - return v, false + case *types.Func: + return "func" + case *types.Var: + if obj.IsField() { + return "field" } - n = g.newNode(obj) - g.TypeNodes[obj] = n - return n, true - case types.Object: - // OPT(dh): the types.Object and default cases are identical - if node, ok := g.Nodes[obj]; ok { - return node, false + return "var" + case *types.Const: + return "const" + case *types.TypeName: + if _, ok := obj.Type().(*types.TypeParam); ok { + return "type param" + } else { + return "type" } - - n = g.newNode(obj) - g.Nodes[obj] = n - return n, true default: - if node, ok := g.Nodes[obj]; ok { - return node, false - } - - n = g.newNode(obj) - g.Nodes[obj] = n - return n, true + return "identifier" } } -func (g *graph) newNode(obj interface{}) *node { - g.nodeCounter++ - return &node{ - obj: obj, - id: g.nodeCounter, +func (g *graph) newNode(obj types.Object) NodeID { + id := NodeID(len(g.nodes)) + n := Node{ + id: id, + obj: g.objectToObject(obj), } + g.nodes = append(g.nodes, n) + if _, ok := g.objects[obj]; ok { + panic(fmt.Sprintf("already had a node for %s", obj)) + } + g.objects[obj] = id + return id } -func (n *node) use(n2 *node, kind edgeKind) { - assert(n2 != nil) - n.used = append(n.used, edge{node: n2, kind: kind}) -} - -// isIrrelevant reports whether an object's presence in the graph is -// of any relevance. A lot of objects will never have outgoing edges, -// nor meaningful incoming ones. Examples are basic types and empty -// signatures, among many others. -// -// Dropping these objects should have no effect on correctness, but -// may improve performance. It also helps with debugging, as it -// greatly reduces the size of the graph. -func isIrrelevant(obj interface{}) bool { - if obj, ok := obj.(types.Object); ok { - switch obj := obj.(type) { - case *types.Var: - if obj.IsField() { - // We need to track package fields - return false - } - if obj.Pkg() != nil && obj.Parent() == obj.Pkg().Scope() { - // We need to track package-level variables - return false - } - return isIrrelevant(obj.Type()) - default: - return false - } +func (g *graph) node(obj types.Object) NodeID { + if obj == nil { + return 0 } - if T, ok := obj.(types.Type); ok { - switch T := T.(type) { - case *types.Array: - return isIrrelevant(T.Elem()) - case *types.Slice: - return isIrrelevant(T.Elem()) - case *types.Basic: - return true - case *types.Tuple: - for i := 0; i < T.Len(); i++ { - if !isIrrelevant(T.At(i).Type()) { - return false - } - } - return true - case *types.Signature: - if T.Recv() != nil { - return false - } - for i := 0; i < T.Params().Len(); i++ { - if !isIrrelevant(T.Params().At(i)) { - return false - } - } - for i := 0; i < T.Results().Len(); i++ { - if !isIrrelevant(T.Results().At(i)) { - return false - } - } - return true - case *types.Interface: - return T.NumMethods() == 0 && T.NumEmbeddeds() == 0 - case *types.Pointer: - return isIrrelevant(T.Elem()) - case *types.Map: - return isIrrelevant(T.Key()) && isIrrelevant(T.Elem()) - case *types.Struct: - return T.NumFields() == 0 - case *types.Chan: - return isIrrelevant(T.Elem()) - default: - return false - } + obj = origin(obj) + if n, ok := g.objects[obj]; ok { + return n } - return false + n := g.newNode(obj) + return n } -func (g *graph) see(obj interface{}) *node { - if isIrrelevant(obj) { - return nil +func origin(obj types.Object) types.Object { + switch obj := obj.(type) { + case *types.Var: + return obj.Origin() + case *types.Func: + return obj.Origin() + default: + return obj } +} - assert(obj != nil) - - if fn, ok := obj.(*types.Func); ok { - obj = typeparams.OriginMethod(fn) - } - if t, ok := obj.(*types.Named); ok { - obj = t.Origin() +func (g *graph) addEdge(e edge) bool { + if _, ok := g.edges[e]; ok { + return false } + g.edges[e] = struct{}{} + return true +} - // add new node to graph - node, _ := g.node(obj) - - if p, ok := obj.(*types.Pointer); ok { - if pt, ok := g.pointers[p.Elem()]; ok { - // We've used graph.newPointer before we saw this pointer; add an edge that marks the two pointers as being - // identical - if p != pt { - g.use(p, pt, edgeSamePointer) - g.use(pt, p, edgeSamePointer) - } - } else { - g.pointers[p.Elem()] = p - } +func (g *graph) addOwned(owner, owned NodeID) { + e := edge{owner, owned, edgeKindOwn} + if !g.addEdge(e) { + return } - - return node + n := &g.nodes[owner] + n.owns = append(n.owns, owned) } -func (g *graph) use(used, by interface{}, kind edgeKind) { - if isIrrelevant(used) { +func (g *graph) addUse(by, used NodeID) { + e := edge{by, used, edgeKindUse} + if !g.addEdge(e) { return } + nBy := &g.nodes[by] + nBy.uses = append(nBy.uses, used) +} - assert(used != nil) - if obj, ok := by.(types.Object); ok && obj.Pkg() != nil { - if obj.Pkg() != g.pkg.Pkg { - return - } +func (g *graph) see(obj, owner types.Object) { + if obj == nil { + panic("saw nil object") } - if fn, ok := used.(*types.Func); ok { - used = typeparams.OriginMethod(fn) - } - if fn, ok := by.(*types.Func); ok { - by = typeparams.OriginMethod(fn) + if g.opts.ExportedIsUsed && obj.Pkg() != g.pkg || obj.Pkg() == nil { + return } - if t, ok := used.(*types.Named); ok { - used = t.Origin() - } - if t, ok := by.(*types.Named); ok { - by = t.Origin() + nObj := g.node(obj) + if owner != nil { + nOwner := g.node(owner) + g.addOwned(nOwner, nObj) } +} - usedNode, new := g.node(used) - assert(!new) - if by == nil { - g.Root.use(usedNode, kind) - } else { - byNode, new := g.node(by) - assert(!new) - byNode.use(usedNode, kind) +func isIrrelevant(obj types.Object) bool { + switch obj.(type) { + case *types.PkgName: + return true + default: + return false } } -func (g *graph) seeAndUse(used, by interface{}, kind edgeKind) *node { - n := g.see(used) - g.use(used, by, kind) - return n -} +func (g *graph) use(used, by types.Object) { + if g.opts.ExportedIsUsed && used.Pkg() != g.pkg || used.Pkg() == nil { + return + } -func (g *graph) entry(pkg *pkg) { - g.pkg = pkg - scopes := map[*types.Scope]*ir.Function{} - for _, fn := range pkg.SrcFuncs { - if fn.Object() != nil { - scope := fn.Object().(*types.Func).Scope() - scopes[scope] = fn - } + if isIrrelevant(used) { + return } - for _, f := range pkg.Files { + nUsed := g.node(used) + nBy := g.node(by) + g.addUse(nBy, nUsed) +} + +func (g *graph) entry() { + for _, f := range g.files { for _, cg := range f.Comments { for _, c := range cg.List { if strings.HasPrefix(c.Text, "//go:linkname ") { @@ -1011,303 +502,69 @@ func (g *graph) entry(pkg *pkg) { // (1.8) packages use symbols linked via go:linkname fields := strings.Fields(c.Text) if len(fields) == 3 { - if m, ok := pkg.IR.Members[fields[1]]; ok { - var obj types.Object - switch m := m.(type) { - case *ir.Global: - obj = m.Object() - case *ir.Function: - obj = m.Object() - default: - panic(fmt.Sprintf("unhandled type: %T", m)) - } - assert(obj != nil) - g.seeAndUse(obj, nil, edgeLinkname) + obj := g.pkg.Scope().Lookup(fields[1]) + if obj == nil { + continue } + g.use(obj, nil) } } } } } - surroundingFunc := func(obj types.Object) *ir.Function { - scope := obj.Parent() - for scope != nil { - if fn := scopes[scope]; fn != nil { - return fn - } - scope = scope.Parent() + for _, f := range g.files { + for _, decl := range f.Decls { + g.decl(decl, nil) } - return nil } - // IR form won't tell us about locally scoped types that aren't - // being used. Walk the list of Defs to get all named types. - // - // IR form also won't tell us about constants; use Defs and Uses - // to determine which constants exist and which are being used. - for _, obj := range pkg.TypesInfo.Defs { - switch obj := obj.(type) { - case *types.TypeName: - // types are being handled by walking the AST - case *types.Const: - g.see(obj) - fn := surroundingFunc(obj) - if fn == nil && obj.Exported() { - // (1.4) packages use exported constants - g.use(obj, nil, edgeExportedConstant) + if g.opts.GeneratedIsUsed { + // OPT(dh): depending on the options used, we do not need to track all objects. For example, if local variables + // are always used, then it is enough to use their surrounding function. + for obj := range g.objects { + path := g.fset.PositionFor(obj.Pos(), false).Filename + if _, ok := g.generated[path]; ok { + g.use(obj, nil) } - g.typ(obj.Type(), nil) - g.seeAndUse(obj.Type(), obj, edgeType) } } - // Find constants being used inside functions, find sinks in tests - for _, fn := range pkg.SrcFuncs { - if fn.Object() != nil { - g.see(fn.Object()) - } - n := fn.Source() - if n == nil { - continue - } - ast.Inspect(n, func(n ast.Node) bool { - switch n := n.(type) { - case *ast.Ident: - obj, ok := pkg.TypesInfo.Uses[n] - if !ok { - return true - } - switch obj := obj.(type) { - case *types.Const: - g.seeAndUse(obj, owningObject(fn), edgeUsedConstant) - } - case *ast.AssignStmt: - for _, expr := range n.Lhs { - ident, ok := expr.(*ast.Ident) - if !ok { - continue - } - obj := pkg.TypesInfo.ObjectOf(ident) - if obj == nil { - continue - } - path := pkg.Fset.File(obj.Pos()).Name() - if strings.HasSuffix(path, "_test.go") { - if obj.Parent() != nil && obj.Parent().Parent() != nil && obj.Parent().Parent().Parent() == nil { - // object's scope is the package, whose - // parent is the file, whose parent is nil - - // (4.9) functions use package-level variables they assign to iff in tests (sinks for benchmarks) - // (9.7) variable _reads_ use variables, writes do not, except in tests - g.seeAndUse(obj, owningObject(fn), edgeTestSink) - } - } + processMethodSet := func(named *types.TypeName, ms *types.MethodSet) { + if g.opts.ExportedIsUsed { + for i := 0; i < ms.Len(); i++ { + m := ms.At(i) + if token.IsExported(m.Obj().Name()) { + // (2.1) named types use exported methods + // (6.4) structs use embedded fields that have exported methods + // + // By reading the selection, we read all embedded fields that are part of the path + g.readSelection(m, named) } } - - return true - }) - } - // Find constants being used in non-function contexts - for _, obj := range pkg.TypesInfo.Uses { - _, ok := obj.(*types.Const) - if !ok { - continue } - g.seeAndUse(obj, nil, edgeUsedConstant) - } - var fns []*types.Func - var fn *types.Func - var stack []ast.Node - for _, f := range pkg.Files { - ast.Inspect(f, func(n ast.Node) bool { - if n == nil { - pop := stack[len(stack)-1] - stack = stack[:len(stack)-1] - if _, ok := pop.(*ast.FuncDecl); ok { - fns = fns[:len(fns)-1] - if len(fns) == 0 { - fn = nil - } else { - fn = fns[len(fns)-1] - } - } - return true - } - stack = append(stack, n) - switch n := n.(type) { - case *ast.FuncDecl: - fn = pkg.TypesInfo.ObjectOf(n.Name).(*types.Func) - fns = append(fns, fn) - g.see(fn) - case *ast.GenDecl: - switch n.Tok { - case token.CONST: - groups := astutil.GroupSpecs(pkg.Fset, n.Specs) - for _, specs := range groups { - if len(specs) > 1 { - cg := &constGroup{} - g.see(cg) - for _, spec := range specs { - for _, name := range spec.(*ast.ValueSpec).Names { - obj := pkg.TypesInfo.ObjectOf(name) - // (10.1) const groups - g.seeAndUse(obj, cg, edgeConstGroup) - g.use(cg, obj, edgeConstGroup) - } - } - } - } - case token.VAR: - for _, spec := range n.Specs { - v := spec.(*ast.ValueSpec) - for _, name := range v.Names { - T := pkg.TypesInfo.TypeOf(name) - if fn != nil { - g.seeAndUse(T, fn, edgeVarDecl) - } else { - // TODO(dh): we likely want to make - // the type used by the variable, not - // the package containing the - // variable. But then we have to take - // special care of blank identifiers. - g.seeAndUse(T, nil, edgeVarDecl) - } - g.typ(T, nil) - } - } - case token.TYPE: - for _, spec := range n.Specs { - // go/types doesn't provide a way to go from a - // types.Named to the named type it was based on - // (the t1 in type t2 t1). Therefore we walk the - // AST and process GenDecls. - // - // (2.2) named types use the type they're based on - v := spec.(*ast.TypeSpec) - T := pkg.TypesInfo.TypeOf(v.Type) - obj := pkg.TypesInfo.ObjectOf(v.Name) - g.see(obj) - g.see(T) - g.use(T, obj, edgeType) - g.typ(obj.Type(), nil) - g.typ(T, nil) - - if v.Assign != 0 { - aliasFor := obj.(*types.TypeName).Type() - // (2.3) named types use all their aliases. we can't easily track uses of aliases - if isIrrelevant(aliasFor) { - // We do not track the type this is an - // alias for (for example builtins), so - // just mark the alias used. - // - // FIXME(dh): what about aliases declared inside functions? - g.use(obj, nil, edgeAlias) - } else { - g.see(aliasFor) - g.seeAndUse(obj, aliasFor, edgeAlias) - } - } + if _, ok := named.Type().Underlying().(*types.Interface); !ok { + // (8.0) handle interfaces + // + // We don't care about interfaces implementing interfaces; all their methods are already used, anyway + for _, iface := range g.interfaceTypes { + if sels, ok := implements(named.Type(), iface, ms); ok { + for _, sel := range sels { + // (8.2) any concrete type implements all known interfaces + // (6.3) structs use embedded fields that help implement interfaces + g.readSelection(sel, named) } } } - return true - }) + } } - for _, m := range pkg.IR.Members { - switch m := m.(type) { - case *ir.NamedConst: - // nothing to do, we collect all constants from Defs - case *ir.Global: - if m.Object() != nil { - g.see(m.Object()) - if m.Object().Exported() { - // (1.3) packages use exported variables - g.use(m.Object(), nil, edgeExportedVariable) - } - } - case *ir.Function: - mObj := owningObject(m) - if mObj != nil { - g.see(mObj) - } - //lint:ignore SA9003 handled implicitly - if m.Name() == "init" { - // (1.5) packages use init functions - // - // This is handled implicitly. The generated init - // function has no object, thus everything in it will - // be owned by the package. - } - // This branch catches top-level functions, not methods. - if m.Object() != nil && m.Object().Exported() { - // (1.2) packages use exported functions - g.use(mObj, nil, edgeExportedFunction) - } - if m.Name() == "main" && pkg.Pkg.Name() == "main" { - // (1.7) packages use the main function iff in the main package - g.use(mObj, nil, edgeMainFunction) - } - if pkg.Pkg.Path() == "runtime" && runtimeFuncs[m.Name()] { - // (9.8) runtime functions that may be called from user code via the compiler - g.use(mObj, nil, edgeRuntimeFunction) - } else if pkg.Pkg.Path() == "runtime/coverage" && runtimeCoverageFuncs[m.Name()] { - // (9.8) runtime functions that may be called from user code via the compiler - g.use(mObj, nil, edgeRuntimeFunction) - } - if m.Source() != nil { - doc := m.Source().(*ast.FuncDecl).Doc - if doc != nil { - for _, cmt := range doc.List { - if strings.HasPrefix(cmt.Text, "//go:cgo_export_") { - // (1.6) packages use functions exported to cgo - g.use(mObj, nil, edgeCgoExported) - } - } - } - } - g.function(m) - case *ir.Type: - g.see(m.Object()) - if m.Object().Exported() { - // (1.1) packages use exported named types - g.use(m.Object(), nil, edgeExportedType) - } - g.typ(m.Type(), nil) - default: - panic(fmt.Sprintf("unreachable: %T", m)) - } - } - - // OPT(dh): can we find meaningful initial capacities for these slices? - var ifaces []*types.Interface - var notIfaces []types.Type + for _, named := range g.namedTypes { + // OPT(dh): do we already have the method set available? + processMethodSet(named, types.NewMethodSet(named.Type())) + processMethodSet(named, types.NewMethodSet(types.NewPointer(named.Type()))) - for t := range g.seenTypes { - switch t := t.(type) { - case *types.Interface: - // OPT(dh): (8.1) we only need interfaces that have unexported methods - ifaces = append(ifaces, t) - default: - if _, ok := t.Underlying().(*types.Interface); !ok { - notIfaces = append(notIfaces, t) - } - } - } - - // (8.0) handle interfaces - for _, t := range notIfaces { - ms := pkg.IR.Prog.MethodSets.MethodSet(t) - for _, iface := range ifaces { - if sels, ok := g.implements(t, iface, ms); ok { - for _, sel := range sels { - g.useMethod(t, sel, t, edgeImplements) - } - } - } } type ignoredKey struct { @@ -1315,7 +572,7 @@ func (g *graph) entry(pkg *pkg) { line int } ignores := map[ignoredKey]struct{}{} - for _, dir := range pkg.Directives { + for _, dir := range g.directives { if dir.Command != "ignore" && dir.Command != "file-ignore" { continue } @@ -1324,7 +581,7 @@ func (g *graph) entry(pkg *pkg) { } for _, check := range strings.Split(dir.Arguments[0], ",") { if check == "U1000" { - pos := pkg.Fset.PositionFor(dir.Node.Pos(), false) + pos := g.fset.PositionFor(dir.Node.Pos(), false) var key ignoredKey switch dir.Command { case "ignore": @@ -1347,46 +604,43 @@ func (g *graph) entry(pkg *pkg) { if len(ignores) > 0 { // all objects annotated with a //lint:ignore U1000 are considered used - for obj := range g.Nodes { - if obj, ok := obj.(types.Object); ok { - pos := pkg.Fset.PositionFor(obj.Pos(), false) - key1 := ignoredKey{ - pos.Filename, - pos.Line, - } - key2 := ignoredKey{ - pos.Filename, - -1, - } - _, ok := ignores[key1] - if !ok { - _, ok = ignores[key2] - } - if ok { - g.use(obj, nil, edgeIgnored) - - // use methods and fields of ignored types - if obj, ok := obj.(*types.TypeName); ok { - if obj.IsAlias() { - if typ, ok := obj.Type().(*types.Named); ok && typ.Obj().Pkg() != obj.Pkg() { - // This is an alias of a named type in another package. - // Don't walk its fields or methods; we don't have to, - // and it breaks an assertion in graph.use because we're using an object that we haven't seen before. - // - // For aliases to types in the same package, we do want to ignore the fields and methods, - // because ignoring the alias should ignore the aliased type. - continue - } + for obj := range g.objects { + pos := g.fset.PositionFor(obj.Pos(), false) + key1 := ignoredKey{ + pos.Filename, + pos.Line, + } + key2 := ignoredKey{ + pos.Filename, + -1, + } + _, ok := ignores[key1] + if !ok { + _, ok = ignores[key2] + } + if ok { + g.use(obj, nil) + + // use methods and fields of ignored types + if obj, ok := obj.(*types.TypeName); ok { + if obj.IsAlias() { + if typ, ok := obj.Type().(*types.Named); ok && (g.opts.ExportedIsUsed && typ.Obj().Pkg() != obj.Pkg() || typ.Obj().Pkg() == nil) { + // This is an alias of a named type in another package. + // Don't walk its fields or methods; we don't have to. + // + // For aliases to types in the same package, we do want to ignore the fields and methods, + // because ignoring the alias should ignore the aliased type. + continue } - if typ, ok := obj.Type().(*types.Named); ok { - for i := 0; i < typ.NumMethods(); i++ { - g.use(typ.Method(i), nil, edgeIgnored) - } + } + if typ, ok := obj.Type().(*types.Named); ok { + for i := 0; i < typ.NumMethods(); i++ { + g.use(typ.Method(i), nil) } - if typ, ok := obj.Type().Underlying().(*types.Struct); ok { - for i := 0; i < typ.NumFields(); i++ { - g.use(typ.Field(i), nil, edgeIgnored) - } + } + if typ, ok := obj.Type().Underlying().(*types.Struct); ok { + for i := 0; i < typ.NumFields(); i++ { + g.use(typ.Field(i), nil) } } } @@ -1395,507 +649,783 @@ func (g *graph) entry(pkg *pkg) { } } -func (g *graph) useMethod(t types.Type, sel *types.Selection, by interface{}, kind edgeKind) { - obj := sel.Obj().(*types.Func) - path := sel.Index() - assert(obj != nil) - if len(path) > 1 { - base := typeutil.Dereference(t).Underlying().(*types.Struct) - for _, idx := range path[:len(path)-1] { - next := base.Field(idx) - // (6.3) structs use embedded fields that help implement interfaces - g.see(base) - g.seeAndUse(next, base, edgeProvidesMethod) - base, _ = typeutil.Dereference(next.Type()).Underlying().(*types.Struct) - } - } - g.seeAndUse(obj, by, kind) +func isOfType[T any](x any) bool { + _, ok := x.(T) + return ok } -func owningObject(fn *ir.Function) types.Object { - if fn.Object() != nil { - return fn.Object() - } - if fn.Parent() != nil { - return owningObject(fn.Parent()) - } - return nil -} - -func (g *graph) function(fn *ir.Function) { - assert(fn != nil) - if fn.Package() != nil && fn.Package() != g.pkg.IR { +func (g *graph) read(node ast.Node, by types.Object) { + if node == nil { return } - if _, ok := g.seenFns[fn]; ok { - return - } - g.seenFns[fn] = struct{}{} + switch node := node.(type) { + case *ast.Ident: + // Among many other things, this handles + // (7.1) field accesses use fields - // (4.1) functions use all their arguments, return parameters and receivers - g.signature(fn.Signature, owningObject(fn)) - g.instructions(fn) - for _, anon := range fn.AnonFuncs { - // (4.2) functions use anonymous functions defined beneath them - // - // This fact is expressed implicitly. Anonymous functions have - // no types.Object, so their owner is the surrounding - // function. - g.function(anon) - } -} + obj := g.info.ObjectOf(node) + g.use(obj, by) -func (g *graph) typ(t types.Type, parent types.Type) { - if _, ok := g.seenTypes[t]; ok { - return - } + case *ast.BasicLit: + // Nothing to do - if t, ok := t.(*types.Named); ok && t.Obj().Pkg() != nil { - if t.Obj().Pkg() != g.pkg.Pkg { - return + case *ast.SliceExpr: + g.read(node.X, by) + g.read(node.Low, by) + g.read(node.High, by) + g.read(node.Max, by) + + case *ast.UnaryExpr: + g.read(node.X, by) + + case *ast.ParenExpr: + g.read(node.X, by) + + case *ast.ArrayType: + g.read(node.Len, by) + g.read(node.Elt, by) + + case *ast.SelectorExpr: + g.readSelectorExpr(node, by) + + case *ast.IndexExpr: + // Among many other things, this handles + // (2.6) named types use all their type arguments + g.read(node.X, by) + g.read(node.Index, by) + + case *ast.IndexListExpr: + // Among many other things, this handles + // (2.6) named types use all their type arguments + g.read(node.X, by) + for _, index := range node.Indices { + g.read(index, by) } - } - g.seenTypes[t] = struct{}{} - if isIrrelevant(t) { - return - } - - g.see(t) - switch t := t.(type) { - case *types.Struct: - for i := 0; i < t.NumFields(); i++ { - g.see(t.Field(i)) - if t.Field(i).Exported() { - // (6.2) structs use exported fields - g.use(t.Field(i), t, edgeExportedField) - } else if t.Field(i).Name() == "_" { - g.use(t.Field(i), t, edgeBlankField) - } else if isNoCopyType(t.Field(i).Type()) { - // (6.1) structs use fields of type NoCopy sentinel - g.use(t.Field(i), t, edgeNoCopySentinel) - } else if parent == nil { - // (11.1) anonymous struct types use all their fields. - g.use(t.Field(i), t, edgeAnonymousStruct) + case *ast.BinaryExpr: + g.read(node.X, by) + g.read(node.Y, by) + + case *ast.CompositeLit: + g.read(node.Type, by) + // We get the type of the node itself, not of node.Type, to handle nested composite literals of the kind + // T{{...}} + typ, isStruct := typeutil.CoreType(g.info.TypeOf(node)).(*types.Struct) + + if isStruct { + unkeyed := len(node.Elts) != 0 && !isOfType[*ast.KeyValueExpr](node.Elts[0]) + if g.opts.FieldWritesAreUses && unkeyed { + // Untagged struct literal that specifies all fields. We have to manually use the fields in the type, + // because the unkeyd literal doesn't contain any nodes referring to the fields. + for i := 0; i < typ.NumFields(); i++ { + g.use(typ.Field(i), by) + } } - if t.Field(i).Anonymous() { - // does the embedded field contribute exported methods to the method set? - T := t.Field(i).Type() - if _, ok := T.Underlying().(*types.Pointer); !ok { - // An embedded field is addressable, so check - // the pointer type to get the full method set - T = g.newPointer(T) + if g.opts.FieldWritesAreUses || unkeyed { + for _, elt := range node.Elts { + g.read(elt, by) } - ms := g.pkg.IR.Prog.MethodSets.MethodSet(T) - for j := 0; j < ms.Len(); j++ { - if ms.At(j).Obj().Exported() { - // (6.4) structs use embedded fields that have exported methods (recursively) - g.use(t.Field(i), t, edgeExtendsExportedMethodSet) - break - } + } else { + for _, elt := range node.Elts { + kv := elt.(*ast.KeyValueExpr) + g.write(kv.Key, by) + g.read(kv.Value, by) } + } + } else { + for _, elt := range node.Elts { + g.read(elt, by) + } + } - seen := map[*types.Struct]struct{}{} - var hasExportedField func(t types.Type) bool - hasExportedField = func(T types.Type) bool { - t, ok := typeutil.Dereference(T).Underlying().(*types.Struct) - if !ok { - return false - } - if _, ok := seen[t]; ok { - return false - } - seen[t] = struct{}{} - for i := 0; i < t.NumFields(); i++ { - field := t.Field(i) - if field.Exported() { - return true - } - if field.Embedded() && hasExportedField(field.Type()) { - return true - } - } - return false - } - // does the embedded field contribute exported fields? - if hasExportedField(t.Field(i).Type()) { - // (6.5) structs use embedded structs that have exported fields (recursively) - g.use(t.Field(i), t, edgeExtendsExportedFields) - } + case *ast.KeyValueExpr: + g.read(node.Key, by) + g.read(node.Value, by) + + case *ast.StarExpr: + g.read(node.X, by) + + case *ast.MapType: + g.read(node.Key, by) + g.read(node.Value, by) + case *ast.FuncLit: + g.read(node.Type, by) + + // See graph.decl's handling of ast.FuncDecl for why this bit of code is necessary. + fn := g.info.TypeOf(node).(*types.Signature) + for params, i := fn.Params(), 0; i < params.Len(); i++ { + g.see(params.At(i), by) + if params.At(i).Name() == "" { + g.use(params.At(i), by) } - g.variable(t.Field(i)) } - case *types.Basic: - // Nothing to do - case *types.Named: - // (9.3) types use their underlying and element types - origin := t.Origin() - g.seeAndUse(origin.Underlying(), t, edgeUnderlyingType) - g.seeAndUse(t.Obj(), t, edgeTypeName) - g.seeAndUse(t, t.Obj(), edgeNamedType) - - // (2.4) named types use the pointer type - if _, ok := t.Underlying().(*types.Interface); !ok && t.NumMethods() > 0 { - g.seeAndUse(g.newPointer(origin), t, edgePointerType) + + g.block(node.Body, by) + + case *ast.FuncType: + m := map[*types.Var]struct{}{} + if !g.opts.ParametersAreUsed { + m = map[*types.Var]struct{}{} + // seeScope marks all local variables in the scope as used, but we don't want to unconditionally use + // parameters, as this is controlled by Options.ParametersAreUsed. Pass seeScope a list of variables it + // should skip. + for _, f := range node.Params.List { + for _, name := range f.Names { + m[g.info.ObjectOf(name).(*types.Var)] = struct{}{} + } + } } + g.seeScope(node, by, m) - // (2.5) named types use their type parameters + // (4.1) functions use all their arguments, return parameters and receivers + // (12.1) type parameters use their constraint type + g.read(node.TypeParams, by) + if g.opts.ParametersAreUsed { + g.read(node.Params, by) + } + g.read(node.Results, by) - for i := 0; i < t.TypeParams().Len(); i++ { - tparam := t.TypeParams().At(i) - g.seeAndUse(tparam, t, edgeTypeParam) - g.typ(tparam, nil) + case *ast.FieldList: + if node == nil { + return } - // (2.6) named types use their type arguments - for i := 0; i < t.TypeArgs().Len(); i++ { - targ := t.TypeArgs().At(i) - g.seeAndUse(targ, t, edgeTypeArg) - g.typ(t, nil) + // This branch is only hit for field lists enclosed by parentheses or square brackets, i.e. parameters. Fields + // (for structs) and method lists (for interfaces) are handled elsewhere. + + for _, field := range node.List { + if len(field.Names) == 0 { + g.read(field.Type, by) + } else { + for _, name := range field.Names { + // OPT(dh): instead of by -> name -> type, we could just emit by -> type. We don't care about the + // (un)usedness of parameters of any kind. + obj := g.info.ObjectOf(name) + g.use(obj, by) + g.read(field.Type, obj) + } + } } - for i := 0; i < t.NumMethods(); i++ { - g.see(t.Method(i)) - // don't use trackExportedIdentifier here, we care about - // all exported methods, even in package main or in tests. - if t.Method(i).Exported() { - // (2.1) named types use exported methods - g.use(t.Method(i), t, edgeExportedMethod) + case *ast.ChanType: + g.read(node.Value, by) + + case *ast.StructType: + // This is only used for anonymous struct types, not named ones. + + for _, field := range node.Fields.List { + if len(field.Names) == 0 { + // embedded field + + f := g.embeddedField(field.Type, by) + g.use(f, by) + } else { + for _, name := range field.Names { + // (11.1) anonymous struct types use all their fields + // OPT(dh): instead of by -> name -> type, we could just emit by -> type. If the type is used, then the fields are used. + obj := g.info.ObjectOf(name) + g.see(obj, by) + g.use(obj, by) + g.read(field.Type, g.info.ObjectOf(name)) + } } - g.function(g.pkg.IR.Prog.FuncValue(t.Method(i))) } - g.typ(origin.Underlying(), t) - case *types.Slice: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - g.typ(t.Elem(), nil) - case *types.Map: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - // (9.3) types use their underlying and element types - g.seeAndUse(t.Key(), t, edgeKeyType) - g.typ(t.Elem(), nil) - g.typ(t.Key(), nil) - case *types.Signature: - g.signature(t, nil) - case *types.Interface: - for i := 0; i < t.NumMethods(); i++ { - m := t.Method(i) - // (8.3) All interface methods are marked as used - g.seeAndUse(m, t, edgeInterfaceMethod) - g.seeAndUse(m.Type().(*types.Signature), m, edgeSignature) - g.signature(m.Type().(*types.Signature), nil) + case *ast.TypeAssertExpr: + g.read(node.X, by) + g.read(node.Type, by) + + case *ast.InterfaceType: + if len(node.Methods.List) != 0 { + g.interfaceTypes = append(g.interfaceTypes, g.info.TypeOf(node).(*types.Interface)) } - for i := 0; i < t.NumEmbeddeds(); i++ { - tt := t.EmbeddedType(i) - // (8.4) All embedded interfaces are marked as used - g.typ(tt, nil) - g.seeAndUse(tt, t, edgeEmbeddedInterface) + for _, meth := range node.Methods.List { + switch len(meth.Names) { + case 0: + // Embedded type or type union + // (8.4) all embedded interfaces are marked as used + // (this also covers type sets) + + g.read(meth.Type, by) + case 1: + // Method + // (8.3) all interface methods are marked as used + obj := g.info.ObjectOf(meth.Names[0]) + g.see(obj, by) + g.use(obj, by) + g.read(meth.Type, obj) + default: + panic(fmt.Sprintf("unexpected number of names: %d", len(meth.Names))) + } } - case *types.Array: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - g.typ(t.Elem(), nil) - case *types.Pointer: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - g.typ(t.Elem(), nil) - case *types.Chan: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - g.typ(t.Elem(), nil) - case *types.Tuple: - for i := 0; i < t.Len(); i++ { - // (9.3) types use their underlying and element types - g.seeAndUse(t.At(i).Type(), t, edgeTupleElement|edgeType) - g.typ(t.At(i).Type(), nil) + + case *ast.Ellipsis: + g.read(node.Elt, by) + + case *ast.CallExpr: + g.read(node.Fun, by) + for _, arg := range node.Args { + g.read(arg, by) } - case *typeutil.Iterator: - // (9.3) types use their underlying and element types - g.seeAndUse(t.Elem(), t, edgeElementType) - g.typ(t.Elem(), nil) - case *types.TypeParam: - // (9.3) types use their underlying and element types - - g.seeAndUse(t.Obj(), t, edgeTypeName) - g.seeAndUse(t, t.Obj(), edgeNamedType) - g.seeAndUse(t.Constraint(), t, edgeElementType) - g.typ(t.Constraint(), t) - case *types.Union: - for i := 0; i < t.Len(); i++ { - g.seeAndUse(t.Term(i).Type(), t, edgeUnionTerm) - g.typ(t.Term(i).Type(), nil) + + // Handle conversiosn + conv := node + if len(conv.Args) != 1 || conv.Ellipsis.IsValid() { + return } + + dst := g.info.TypeOf(conv.Fun) + src := g.info.TypeOf(conv.Args[0]) + + // XXX use DereferenceR instead + // XXX guard against infinite recursion in DereferenceR + tSrc := typeutil.CoreType(typeutil.Dereference(src)) + tDst := typeutil.CoreType(typeutil.Dereference(dst)) + stSrc, okSrc := tSrc.(*types.Struct) + stDst, okDst := tDst.(*types.Struct) + if okDst && okSrc { + // Converting between two structs. The fields are + // relevant for the conversion, but only if the + // fields are also used outside of the conversion. + // Mark fields as used by each other. + + assert(stDst.NumFields() == stSrc.NumFields()) + for i := 0; i < stDst.NumFields(); i++ { + // (5.1) when converting between two equivalent structs, the fields in + // either struct use each other. the fields are relevant for the + // conversion, but only if the fields are also accessed outside the + // conversion. + g.use(stDst.Field(i), stSrc.Field(i)) + g.use(stSrc.Field(i), stDst.Field(i)) + } + } else if okSrc && tDst == types.Typ[types.UnsafePointer] { + // (5.2) when converting to or from unsafe.Pointer, mark all fields as used. + g.useAllFieldsRecursively(stSrc, by) + } else if okDst && tSrc == types.Typ[types.UnsafePointer] { + // (5.2) when converting to or from unsafe.Pointer, mark all fields as used. + g.useAllFieldsRecursively(stDst, by) + } + default: - panic(fmt.Sprintf("unreachable: %T", t)) + lint.ExhaustiveTypeSwitch(node) } } -func (g *graph) variable(v *types.Var) { - // (9.2) variables use their types - g.seeAndUse(v.Type(), v, edgeType) - g.typ(v.Type(), nil) +func (g *graph) useAllFieldsRecursively(typ types.Type, by types.Object) { + switch typ := typ.Underlying().(type) { + case *types.Struct: + for i := 0; i < typ.NumFields(); i++ { + field := typ.Field(i) + g.use(field, by) + g.useAllFieldsRecursively(field.Type(), by) + } + case *types.Array: + g.useAllFieldsRecursively(typ.Elem(), by) + default: + return + } } -func (g *graph) signature(sig *types.Signature, fn types.Object) { - var user interface{} = fn - if fn == nil { - user = sig - g.see(sig) +func (g *graph) write(node ast.Node, by types.Object) { + if node == nil { + return } - if sig.Recv() != nil { - g.seeAndUse(sig.Recv().Type(), user, edgeReceiver|edgeType) - g.typ(sig.Recv().Type(), nil) + + switch node := node.(type) { + case *ast.Ident: + obj := g.info.ObjectOf(node) + if obj == nil { + // This can happen for `switch x := v.(type)`, where that x doesn't have an object + return + } + + // (4.9) functions use package-level variables they assign to iff in tests (sinks for benchmarks) + // (9.7) variable _reads_ use variables, writes do not, except in tests + path := g.fset.File(obj.Pos()).Name() + if strings.HasSuffix(path, "_test.go") { + if isGlobal(obj) { + g.use(obj, by) + } + } + + case *ast.IndexExpr: + g.read(node.X, by) + g.read(node.Index, by) + + case *ast.SelectorExpr: + if g.opts.FieldWritesAreUses { + // Writing to a field constitutes a use. See https://staticcheck.io/issues/288 for some discussion on that. + // + // This code can also get triggered by qualified package variables, in which case it doesn't matter what we do, + // because the object is in another package. + // + // FIXME(dh): ^ isn't true if we track usedness of exported identifiers + g.readSelectorExpr(node, by) + } else { + g.read(node.X, by) + g.write(node.Sel, by) + } + + case *ast.StarExpr: + g.read(node.X, by) + + case *ast.ParenExpr: + g.write(node.X, by) + + default: + lint.ExhaustiveTypeSwitch(node) } - for i := 0; i < sig.Params().Len(); i++ { - param := sig.Params().At(i) - g.seeAndUse(param.Type(), user, edgeFunctionArgument|edgeType) - g.typ(param.Type(), nil) +} + +// readSelectorExpr reads all elements of a selector expression, including implicit fields. +func (g *graph) readSelectorExpr(sel *ast.SelectorExpr, by types.Object) { + // cover AST-based accesses + g.read(sel.X, by) + g.read(sel.Sel, by) + + tsel, ok := g.info.Selections[sel] + if !ok { + return } - for i := 0; i < sig.Results().Len(); i++ { - param := sig.Results().At(i) - g.seeAndUse(param.Type(), user, edgeFunctionResult|edgeType) - g.typ(param.Type(), nil) + g.readSelection(tsel, by) +} + +func (g *graph) readSelection(sel *types.Selection, by types.Object) { + indices := sel.Index() + base := sel.Recv() + for _, idx := range indices[:len(indices)-1] { + // XXX do we need core types here? + field := typeutil.Dereference(base.Underlying()).Underlying().(*types.Struct).Field(idx) + g.use(field, by) + base = field.Type() } - for i := 0; i < sig.RecvTypeParams().Len(); i++ { - // We track the type parameter's constraint, not the type parameter itself. - // We never want to flag an unused type parameter. - param := sig.RecvTypeParams().At(i).Constraint() - g.seeAndUse(param, user, edgeFunctionArgument|edgeType) - g.typ(param, nil) + + g.use(sel.Obj(), by) +} + +func (g *graph) block(block *ast.BlockStmt, by types.Object) { + if block == nil { + return } - for i := 0; i < sig.TypeParams().Len(); i++ { - // We track the type parameter's constraint, not the type parameter itself. - // We never want to flag an unused type parameter. - param := sig.TypeParams().At(i).Constraint() - g.seeAndUse(param, user, edgeFunctionArgument|edgeType) - g.typ(param, nil) + + g.seeScope(block, by, nil) + for _, stmt := range block.List { + g.stmt(stmt, by) } } -func (g *graph) instructions(fn *ir.Function) { - fnObj := owningObject(fn) - for _, b := range fn.Blocks { - for _, instr := range b.Instrs { - ops := instr.Operands(nil) - switch instr.(type) { - case *ir.Store: - // (9.7) variable _reads_ use variables, writes do not - ops = ops[1:] - case *ir.DebugRef: - ops = nil +func isGlobal(obj types.Object) bool { + return obj.Parent() == obj.Pkg().Scope() +} + +func (g *graph) decl(decl ast.Decl, by types.Object) { + switch decl := decl.(type) { + case *ast.GenDecl: + switch decl.Tok { + case token.IMPORT: + // Nothing to do + + case token.CONST: + for _, spec := range decl.Specs { + vspec := spec.(*ast.ValueSpec) + assert(len(vspec.Values) == 0 || len(vspec.Values) == len(vspec.Names)) + for i, name := range vspec.Names { + obj := g.info.ObjectOf(name) + g.see(obj, by) + g.read(vspec.Type, obj) + + if len(vspec.Values) != 0 { + g.read(vspec.Values[i], obj) + } + + if name.Name == "_" { + // (9.9) objects named the blank identifier are used + g.use(obj, by) + } else if token.IsExported(name.Name) && isGlobal(obj) && g.opts.ExportedIsUsed { + g.use(obj, nil) + } + } } - for _, arg := range ops { - walkPhi(*arg, func(v ir.Value) { - switch v := v.(type) { - case *ir.Function: - // (4.3) functions use closures and bound methods. - // (4.5) functions use functions they call - // (9.5) instructions use their operands - // (4.4) functions use functions they return. we assume that someone else will call the returned function - if owningObject(v) != nil { - g.seeAndUse(owningObject(v), fnObj, edgeInstructionOperand) + + groups := astutil.GroupSpecs(g.fset, decl.Specs) + for _, group := range groups { + // (10.1) if one constant out of a block of constants is used, mark all of them used + // + // We encode this as a ring. If we have a constant group 'const ( a; b; c )', then we'll produce the + // following graph: a -> b -> c -> a. + + var first, prev, last types.Object + for _, spec := range group { + for _, name := range spec.(*ast.ValueSpec).Names { + if name.Name == "_" { + // Having a blank constant in a group doesn't mark the whole group as used + continue } - g.function(v) - case *ir.Const: - // (9.6) instructions use their operands' types - g.seeAndUse(v.Type(), fnObj, edgeType) - g.typ(v.Type(), nil) - case *ir.Global: - if v.Object() != nil { - // (9.5) instructions use their operands - g.seeAndUse(v.Object(), fnObj, edgeInstructionOperand) + + obj := g.info.ObjectOf(name) + if first == nil { + first = obj + } else { + g.use(obj, prev) } + prev = obj + last = obj } - }) - } - if v, ok := instr.(ir.Value); ok { - if _, ok := v.(*ir.Range); !ok { - // See https://github.com/golang/go/issues/19670 - - // (4.8) instructions use their types - // (9.4) conversions use the type they convert to - g.seeAndUse(v.Type(), fnObj, edgeType) - g.typ(v.Type(), nil) + } + if first != nil && first != last { + g.use(first, last) } } - switch instr := instr.(type) { - case *ir.Field: - // Can't access fields via generics, for now. - - st := instr.X.Type().Underlying().(*types.Struct) - field := st.Field(instr.Field) - // (4.7) functions use fields they access - g.seeAndUse(field, fnObj, edgeFieldAccess) - case *ir.FieldAddr: - // User code can't access fields on type parameters, but composite literals are still possible, which - // compile to FieldAddr + Store. - - st := typeutil.CoreType(typeutil.Dereference(instr.X.Type())).(*types.Struct) - field := st.Field(instr.Field) - // (4.7) functions use fields they access - g.seeAndUse(field, fnObj, edgeFieldAccess) - case *ir.Store: - // nothing to do, handled generically by operands - case ir.CallInstruction: - c := instr.Common() - for _, targ := range c.TypeArgs { - g.seeAndUse(targ, fnObj, edgeTypeArg) + + case token.TYPE: + for _, spec := range decl.Specs { + tspec := spec.(*ast.TypeSpec) + obj := g.info.ObjectOf(tspec.Name).(*types.TypeName) + g.see(obj, by) + g.seeScope(tspec, obj, nil) + if !tspec.Assign.IsValid() { + g.namedTypes = append(g.namedTypes, obj) } - if !c.IsInvoke() { - // handled generically as an instruction operand - } else { - // (4.5) functions use functions/interface methods they call - g.seeAndUse(c.Method, fnObj, edgeInterfaceCall) + if token.IsExported(tspec.Name.Name) && isGlobal(obj) && g.opts.ExportedIsUsed { + // (1.1) packages use exported named types + g.use(g.info.ObjectOf(tspec.Name), nil) } - case *ir.Return: - // nothing to do, handled generically by operands - case *ir.ChangeType: - // conversion type handled generically - - s1, ok1 := typeutil.CoreType(typeutil.Dereference(instr.Type())).(*types.Struct) - s2, ok2 := typeutil.CoreType(typeutil.Dereference(instr.X.Type())).(*types.Struct) - if ok1 && ok2 { - // Converting between two structs. The fields are - // relevant for the conversion, but only if the - // fields are also used outside of the conversion. - // Mark fields as used by each other. - - assert(s1.NumFields() == s2.NumFields()) - for i := 0; i < s1.NumFields(); i++ { - g.see(s1.Field(i)) - g.see(s2.Field(i)) - // (5.1) when converting between two equivalent structs, the fields in - // either struct use each other. the fields are relevant for the - // conversion, but only if the fields are also accessed outside the - // conversion. - g.seeAndUse(s1.Field(i), s2.Field(i), edgeStructConversion) - g.seeAndUse(s2.Field(i), s1.Field(i), edgeStructConversion) - } + + // (2.5) named types use all their type parameters + g.read(tspec.TypeParams, obj) + + g.namedType(obj, tspec.Type) + + if tspec.Name.Name == "_" { + // (9.9) objects named the blank identifier are used + g.use(obj, by) } - case *ir.MakeInterface: - // nothing to do, handled generically by operands - case *ir.Slice: - // nothing to do, handled generically by operands - case *ir.RunDefers: - // nothing to do, the deferred functions are already marked use by deferring them. - case *ir.Convert: - // to unsafe.Pointer - if typ, ok := instr.Type().(*types.Basic); ok && typ.Kind() == types.UnsafePointer { - if ptr, ok := instr.X.Type().Underlying().(*types.Pointer); ok { - if st, ok := ptr.Elem().Underlying().(*types.Struct); ok { - for i := 0; i < st.NumFields(); i++ { - // (5.2) when converting to or from unsafe.Pointer, mark all fields as used. - g.seeAndUse(st.Field(i), fnObj, edgeUnsafeConversion) - } + } + + case token.VAR: + // We cannot rely on types.Initializer for package-level variables because + // - initializers are only tracked for variables that are actually initialized + // - we want to see the AST of the type, if specified, not just the rhs + + for _, spec := range decl.Specs { + vspec := spec.(*ast.ValueSpec) + for i, name := range vspec.Names { + obj := g.info.ObjectOf(name) + g.see(obj, by) + // variables and constants use their types + g.read(vspec.Type, obj) + + if len(vspec.Names) == len(vspec.Values) { + // One value per variable + g.read(vspec.Values[i], obj) + } else if len(vspec.Values) != 0 { + // Multiple variables initialized with a single rhs + // assert(len(vspec.Values) == 1) + if len(vspec.Values) != 1 { + panic(g.fset.PositionFor(vspec.Pos(), false)) } + g.read(vspec.Values[0], obj) } - } - // from unsafe.Pointer - if typ, ok := instr.X.Type().(*types.Basic); ok && typ.Kind() == types.UnsafePointer { - if ptr, ok := instr.Type().Underlying().(*types.Pointer); ok { - if st, ok := ptr.Elem().Underlying().(*types.Struct); ok { - for i := 0; i < st.NumFields(); i++ { - // (5.2) when converting to or from unsafe.Pointer, mark all fields as used. - g.seeAndUse(st.Field(i), fnObj, edgeUnsafeConversion) - } - } + + if token.IsExported(name.Name) && isGlobal(obj) && g.opts.ExportedIsUsed { + // (1.3) packages use exported variables + g.use(obj, nil) } - } - case *ir.TypeAssert: - // nothing to do, handled generically by instruction - // type (possibly a tuple, which contains the asserted - // to type). redundantly handled by the type of - // ir.Extract, too - case *ir.MakeClosure: - // nothing to do, handled generically by operands - case *ir.Alloc: - // nothing to do - case *ir.UnOp: - // nothing to do - case *ir.BinOp: - // nothing to do - case *ir.If: - // nothing to do - case *ir.Jump: - // nothing to do - case *ir.Unreachable: - // nothing to do - case *ir.IndexAddr: - // nothing to do - case *ir.Extract: - // nothing to do - case *ir.Panic: - // nothing to do - case *ir.DebugRef: - // nothing to do - case *ir.BlankStore: - // nothing to do - case *ir.Phi: - // nothing to do - case *ir.Sigma: - // nothing to do - case *ir.MakeMap: - // nothing to do - case *ir.MapUpdate: - // nothing to do - case *ir.MapLookup: - // nothing to do - case *ir.StringLookup: - // nothing to do - case *ir.MakeSlice: - // nothing to do - case *ir.Send: - // nothing to do - case *ir.MakeChan: - // nothing to do - case *ir.Range: - // nothing to do - case *ir.Next: - // nothing to do - case *ir.Index: - // nothing to do - case *ir.Select: - // nothing to do - case *ir.ChangeInterface: - // nothing to do - case *ir.Load: - // nothing to do - case *ir.Parameter: - // nothing to do - case *ir.Const: - // nothing to do - case *ir.ArrayConst: - // nothing to do - case *ir.AggregateConst: - // nothing to do - case *ir.GenericConst: - // nothing to do - case *ir.Recv: - // nothing to do - case *ir.TypeSwitch: - // nothing to do - case *ir.ConstantSwitch: - // nothing to do - case *ir.SliceToArrayPointer: - // nothing to do - case *ir.SliceToArray: - // nothing to do - case *ir.CompositeValue: - if t, ok := typeutil.CoreType(instr.Type()).(*types.Struct); ok { - for i := 0; i < len(instr.Values); i++ { - if instr.Bitmap.Bit(i) == 1 { - g.seeAndUse(t.Field(i), fnObj, edgeFieldAccess) - } + + if name.Name == "_" { + // (9.9) objects named the blank identifier are used + g.use(obj, by) } } + } + + default: + panic(fmt.Sprintf("unexpected token %s", decl.Tok)) + } + + case *ast.FuncDecl: + // XXX calling OriginMethod is unnecessary if we use types.Func.Origin + obj := typeparams.OriginMethod(g.info.ObjectOf(decl.Name).(*types.Func)) + g.see(obj, nil) + + if token.IsExported(decl.Name.Name) && g.opts.ExportedIsUsed { + if decl.Recv == nil { + // (1.2) packages use exported functions + g.use(obj, nil) + } + } else if decl.Name.Name == "init" { + // (1.5) packages use init functions + g.use(obj, nil) + } else if decl.Name.Name == "main" && g.pkg.Name() == "main" { + // (1.7) packages use the main function iff in the main package + g.use(obj, nil) + } else if g.pkg.Path() == "runtime" && runtimeFuncs[decl.Name.Name] { + // (9.8) runtime functions that may be called from user code via the compiler + g.use(obj, nil) + } else if g.pkg.Path() == "runtime/coverage" && runtimeCoverageFuncs[decl.Name.Name] { + // (9.8) runtime functions that may be called from user code via the compiler + g.use(obj, nil) + } + + // (4.1) functions use their receivers + g.read(decl.Recv, obj) + g.read(decl.Type, obj) + g.block(decl.Body, obj) + + // g.read(decl.Type) will ultimately call g.seeScopes and see parameters that way. But because it relies + // entirely on the AST, it cannot resolve unnamed parameters to types.Object. For that reason we explicitly + // handle arguments here, as well as for FuncLits elsewhere. + // + // g.seeScopes can't get to the types.Signature for this function because there is no mapping from ast.FuncType to + // types.Signature, only from ast.Ident to types.Signature. + // + // This code is only really relevant when Options.ParametersAreUsed is false. Otherwise, all parameters are + // considered used, and if we never see a parameter then no harm done (we still see its type separately). + fn := g.info.TypeOf(decl.Name).(*types.Signature) + for params, i := fn.Params(), 0; i < params.Len(); i++ { + g.see(params.At(i), obj) + if params.At(i).Name() == "" { + g.use(params.At(i), obj) + } + } + + if decl.Name.Name == "_" { + // (9.9) objects named the blank identifier are used + g.use(obj, nil) + } + + if decl.Doc != nil { + for _, cmt := range decl.Doc.List { + if strings.HasPrefix(cmt.Text, "//go:cgo_export_") { + // (1.6) packages use functions exported to cgo + g.use(obj, nil) + } + } + } + + default: + // We do not cover BadDecl, but we shouldn't ever see one of those + lint.ExhaustiveTypeSwitch(decl) + } +} + +// seeScope sees all objects in node's scope. If Options.LocalVariablesAreUsed is true, all objects that aren't fields +// are marked as used. Variables set in skipLvars will not be marked as used. +func (g *graph) seeScope(node ast.Node, by types.Object, skipLvars map[*types.Var]struct{}) { + // A note on functions and scopes: for a function declaration, the body's BlockStmt can't be found in + // types.Info.Scopes. Instead, the FuncType can, and that scope will contain receivers, parameters, return + // parameters and immediate local variables. + + scope := g.info.Scopes[node] + if scope == nil { + return + } + for _, name := range scope.Names() { + obj := scope.Lookup(name) + g.see(obj, by) + + if g.opts.LocalVariablesAreUsed { + if obj, ok := obj.(*types.Var); ok && !obj.IsField() { + if _, ok := skipLvars[obj]; !ok { + g.use(obj, by) + } + } + } + } +} + +func (g *graph) stmt(stmt ast.Stmt, by types.Object) { + if stmt == nil { + return + } + + for { + // We don't care about labels, so unwrap LabeledStmts. Note that a label can itself be labeled. + if labeled, ok := stmt.(*ast.LabeledStmt); ok { + stmt = labeled.Stmt + } else { + break + } + } + + switch stmt := stmt.(type) { + case *ast.AssignStmt: + for _, lhs := range stmt.Lhs { + g.write(lhs, by) + } + for _, rhs := range stmt.Rhs { + // Note: it would be more accurate to have the rhs used by the lhs, but it ultimately doesn't matter, + // because local variables always end up used, anyway. + // + // TODO(dh): we'll have to change that once we allow tracking the usedness of parameters + g.read(rhs, by) + } + + case *ast.BlockStmt: + g.block(stmt, by) + + case *ast.BranchStmt: + // Nothing to do + + case *ast.DeclStmt: + g.decl(stmt.Decl, by) + + case *ast.DeferStmt: + g.read(stmt.Call, by) + + case *ast.ExprStmt: + g.read(stmt.X, by) + + case *ast.ForStmt: + g.seeScope(stmt, by, nil) + g.stmt(stmt.Init, by) + g.read(stmt.Cond, by) + g.stmt(stmt.Post, by) + g.block(stmt.Body, by) + + case *ast.GoStmt: + g.read(stmt.Call, by) + + case *ast.IfStmt: + g.seeScope(stmt, by, nil) + g.stmt(stmt.Init, by) + g.read(stmt.Cond, by) + g.block(stmt.Body, by) + g.stmt(stmt.Else, by) + + case *ast.IncDecStmt: + if g.opts.PostStatementsAreReads { + g.read(stmt.X, by) + g.write(stmt.X, by) + } else { + // We treat post-increment as a write only. This ends up using fields, and sinks in tests, but not other + // variables. + g.write(stmt.X, by) + } + + case *ast.RangeStmt: + g.seeScope(stmt, by, nil) + + g.write(stmt.Key, by) + g.write(stmt.Value, by) + g.read(stmt.X, by) + g.block(stmt.Body, by) + + case *ast.ReturnStmt: + for _, ret := range stmt.Results { + g.read(ret, by) + } + + case *ast.SelectStmt: + for _, clause_ := range stmt.Body.List { + clause := clause_.(*ast.CommClause) + g.seeScope(clause, by, nil) + switch comm := clause.Comm.(type) { + case *ast.SendStmt: + g.read(comm.Chan, by) + g.read(comm.Value, by) + case *ast.ExprStmt: + g.read(comm.X.(*ast.UnaryExpr).X, by) + case *ast.AssignStmt: + for _, lhs := range comm.Lhs { + g.write(lhs, by) + } + for _, rhs := range comm.Rhs { + g.read(rhs, by) + } + case nil: default: - lint.ExhaustiveTypeSwitch(instr) + lint.ExhaustiveTypeSwitch(comm) + } + for _, body := range clause.Body { + g.stmt(body, by) + } + } + + case *ast.SendStmt: + g.read(stmt.Chan, by) + g.read(stmt.Value, by) + + case *ast.SwitchStmt: + g.seeScope(stmt, by, nil) + g.stmt(stmt.Init, by) + g.read(stmt.Tag, by) + for _, clause_ := range stmt.Body.List { + clause := clause_.(*ast.CaseClause) + g.seeScope(clause, by, nil) + for _, expr := range clause.List { + g.read(expr, by) + } + for _, body := range clause.Body { + g.stmt(body, by) } } + + case *ast.TypeSwitchStmt: + g.seeScope(stmt, by, nil) + g.stmt(stmt.Init, by) + g.stmt(stmt.Assign, by) + for _, clause_ := range stmt.Body.List { + clause := clause_.(*ast.CaseClause) + g.seeScope(clause, by, nil) + for _, expr := range clause.List { + g.read(expr, by) + } + for _, body := range clause.Body { + g.stmt(body, by) + } + } + + case *ast.EmptyStmt: + // Nothing to do + + default: + lint.ExhaustiveTypeSwitch(stmt) + } +} + +// embeddedField sees the field declared by the embedded field node, and marks the type as used by the field. +// +// Embedded fields are special in two ways: they don't have names, so we don't have immediate access to an ast.Ident to +// resolve to the field's types.Var, and we cannot use g.read on the type because eventually we do get to an ast.Ident, +// and ObjectOf resolves embedded fields to the field they declare, not the type. That's why we have code specially for +// handling embedded fields. +func (g *graph) embeddedField(node ast.Node, by types.Object) *types.Var { + // We need to traverse the tree to find the ast.Ident, but all the nodes we traverse should be used by the object we + // get once we resolve the ident. Collect the nodes and process them once we've found the ident. + nodes := make([]ast.Node, 0, 4) + for { + switch node_ := node.(type) { + case *ast.Ident: + obj := g.info.ObjectOf(node_).(*types.Var) + g.see(obj, by) + for _, n := range nodes { + g.read(n, obj) + } + switch typ := typeutil.Dereference(g.info.TypeOf(node_)).(type) { + case *types.Named: + g.use(typ.Obj(), obj) + case *types.Basic: + // Nothing to do + default: + lint.ExhaustiveTypeSwitch(typ) + } + return obj + case *ast.StarExpr: + node = node_.X + case *ast.SelectorExpr: + node = node_.Sel + nodes = append(nodes, node_.X) + case *ast.IndexExpr: + node = node_.X + nodes = append(nodes, node_.Index) + case *ast.IndexListExpr: + node = node_.X + default: + lint.ExhaustiveTypeSwitch(node_) + } } } @@ -1936,27 +1466,198 @@ func isNoCopyType(typ types.Type) bool { return true } -func walkPhi(v ir.Value, fn func(v ir.Value)) { - phi, ok := v.(*ir.Phi) - if !ok { - fn(v) +func (g *graph) namedType(typ *types.TypeName, spec ast.Expr) { + // (2.2) named types use the type they're based on + + if st, ok := spec.(*ast.StructType); ok { + // Named structs are special in that its unexported fields are only used if they're being written to. That is, + // the fields are not used by the named type itself, nor are the types of the fields. + for _, field := range st.Fields.List { + seen := map[*types.Struct]struct{}{} + // For `type x struct { *x; F int }`, don't visit the embedded x + seen[g.info.TypeOf(st).(*types.Struct)] = struct{}{} + var hasExportedField func(t types.Type) bool + hasExportedField = func(T types.Type) bool { + t, ok := typeutil.Dereference(T).Underlying().(*types.Struct) + if !ok { + return false + } + if _, ok := seen[t]; ok { + return false + } + seen[t] = struct{}{} + for i := 0; i < t.NumFields(); i++ { + field := t.Field(i) + if field.Exported() { + return true + } + if field.Embedded() && hasExportedField(field.Type()) { + return true + } + } + return false + } + + if len(field.Names) == 0 { + fieldVar := g.embeddedField(field.Type, typ) + if token.IsExported(fieldVar.Name()) && g.opts.ExportedIsUsed { + // (6.2) structs use exported fields + g.use(fieldVar, typ) + } + if g.opts.ExportedIsUsed && g.opts.ExportedFieldsAreUsed && hasExportedField(fieldVar.Type()) { + // (6.5) structs use embedded structs that have exported fields (recursively) + g.use(fieldVar, typ) + } + } else { + for _, name := range field.Names { + obj := g.info.ObjectOf(name) + g.see(obj, typ) + // (7.2) fields use their types + g.read(field.Type, obj) + if name.Name == "_" { + // (9.9) objects named the blank identifier are used + g.use(obj, typ) + } else if token.IsExported(name.Name) && g.opts.ExportedIsUsed { + // (6.2) structs use exported fields + g.use(obj, typ) + } + + if isNoCopyType(obj.Type()) { + // (6.1) structs use fields of type NoCopy sentinel + g.use(obj, typ) + } + } + } + + } + } else { + g.read(spec, typ) + } +} + +func (g *SerializedGraph) color(rootID NodeID, states []nodeState) { + root := g.nodes[rootID] + if states[rootID].seen() { return } + states[rootID] |= nodeStateSeen + for _, n := range root.uses { + g.color(n, states) + } +} - seen := map[ir.Value]struct{}{} - var impl func(v *ir.Phi) - impl = func(v *ir.Phi) { - if _, ok := seen[v]; ok { - return +type Object struct { + Name string + ShortName string + // OPT(dh): use an enum for the kind + Kind string + Path ObjectPath + Position token.Position + DisplayPosition token.Position +} + +func (g *SerializedGraph) Results() Result { + // XXX objectpath does not return paths for unexported objects, which means that if we analyze the same code twice + // (e.g. normal and test variant), then some objects will appear multiple times, but may not be used identically. we + // have to deduplicate based on the token.Position. Actually we have to do that, anyway, because we may flag types + // local to functions. Those are probably always both used or both unused, but we don't want to flag them twice, + // either. + // + // Note, however, that we still need objectpaths to deduplicate exported identifiers when analyzing independent + // packages in whole-program mode, because if package A uses an object from package B, B will have been imported + // from export data, and we will not have column information. + // + // XXX ^ document that design requirement. + + states := g.colorAndQuieten() + + var res Result + // OPT(dh): can we find meaningful initial capacities for the used and unused slices? + for _, n := range g.nodes[1:] { + state := states[n.id] + if state.seen() { + res.Used = append(res.Used, n.obj) + } else if state.quiet() { + res.Quiet = append(res.Quiet, n.obj) + } else { + res.Unused = append(res.Unused, n.obj) } - seen[v] = struct{}{} - for _, e := range v.Edges { - if ev, ok := e.(*ir.Phi); ok { - impl(ev) - } else { - fn(e) + } + + return res +} + +func (g *SerializedGraph) colorAndQuieten() []nodeState { + states := make([]nodeState, len(g.nodes)+1) + g.color(0, states) + + var quieten func(id NodeID) + quieten = func(id NodeID) { + states[id] |= nodeStateQuiet + for _, owned := range g.nodes[id].owns { + quieten(owned) + } + } + + for _, n := range g.nodes { + if states[n.id].seen() { + continue + } + for _, owned := range n.owns { + quieten(owned) + } + } + + return states +} + +// Dot formats a graph in Graphviz dot format. +func (g *SerializedGraph) Dot() string { + b := &strings.Builder{} + states := g.colorAndQuieten() + // Note: We use addresses in our node names. This only works as long as Go's garbage collector doesn't move + // memory around in the middle of our debug printing. + debugNode := func(n Node) { + if n.id == 0 { + fmt.Fprintf(b, "n%d [label=\"Root\"];\n", n.id) + } else { + color := "red" + if states[n.id].seen() { + color = "green" + } else if states[n.id].quiet() { + color = "grey" } + label := fmt.Sprintf("%s %s\n%s", n.obj.Kind, n.obj.Name, n.obj.Position) + fmt.Fprintf(b, "n%d [label=%q, color=%q];\n", n.id, label, color) } + for _, e := range n.uses { + fmt.Fprintf(b, "n%d -> n%d;\n", n.id, e) + } + + for _, owned := range n.owns { + fmt.Fprintf(b, "n%d -> n%d [style=dashed];\n", n.id, owned) + } + } + + fmt.Fprintf(b, "digraph{\n") + for _, v := range g.nodes { + debugNode(v) } - impl(phi) + + fmt.Fprintf(b, "}\n") + + return b.String() +} + +func Graph(fset *token.FileSet, + files []*ast.File, + pkg *types.Package, + info *types.Info, + directives []lint.Directive, + generated map[string]generated.Generator, + opts Options, +) []Node { + g := newGraph(fset, files, pkg, info, directives, generated, opts) + g.entry() + return g.nodes } diff --git a/vendor/modules.txt b/vendor/modules.txt index 4f5ee3e20e..8485fc5707 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -680,7 +680,7 @@ github.com/go-playground/validator/v10 # github.com/go-toolsmith/astcast v1.0.0 ## explicit github.com/go-toolsmith/astcast -# github.com/go-toolsmith/astcopy v1.0.2 +# github.com/go-toolsmith/astcopy v1.0.3 ## explicit; go 1.16 github.com/go-toolsmith/astcopy # github.com/go-toolsmith/astequal v1.0.3 @@ -774,7 +774,7 @@ github.com/golangci/gofmt/gofmt github.com/golangci/gofmt/gofmt/internal/diff github.com/golangci/gofmt/gofmt/internal/execabs github.com/golangci/gofmt/goimports -# github.com/golangci/golangci-lint v1.51.0 +# github.com/golangci/golangci-lint v1.51.1 ## explicit; go 1.19 github.com/golangci/golangci-lint/cmd/golangci-lint github.com/golangci/golangci-lint/internal/cache @@ -931,7 +931,7 @@ github.com/googleapis/gax-go/v2 github.com/googleapis/gax-go/v2/apierror github.com/googleapis/gax-go/v2/apierror/internal/proto github.com/googleapis/gax-go/v2/internal -# github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 +# github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28 ## explicit; go 1.14 github.com/gordonklaus/ineffassign/pkg/ineffassign # github.com/gorilla/websocket v1.5.0 @@ -1165,7 +1165,7 @@ github.com/json-iterator/go # github.com/julz/importas v0.1.0 ## explicit; go 1.15 github.com/julz/importas -# github.com/junk1tm/musttag v0.4.3 +# github.com/junk1tm/musttag v0.4.4 ## explicit; go 1.18 github.com/junk1tm/musttag # github.com/kelseyhightower/envconfig v1.4.0 @@ -1332,7 +1332,7 @@ github.com/nishanths/exhaustive # github.com/nishanths/predeclared v0.2.2 ## explicit; go 1.14 github.com/nishanths/predeclared/passes/predeclared -# github.com/nunnatsa/ginkgolinter v0.7.1 +# github.com/nunnatsa/ginkgolinter v0.8.1 ## explicit; go 1.19 github.com/nunnatsa/ginkgolinter github.com/nunnatsa/ginkgolinter/gomegahandler @@ -1454,13 +1454,13 @@ github.com/russross/blackfriday/v2 # github.com/ryancurrah/gomodguard v1.3.0 ## explicit; go 1.19 github.com/ryancurrah/gomodguard -# github.com/ryanrolds/sqlclosecheck v0.3.0 -## explicit; go 1.13 +# github.com/ryanrolds/sqlclosecheck v0.4.0 +## explicit; go 1.19 github.com/ryanrolds/sqlclosecheck/pkg/analyzer # github.com/ryanuber/go-glob v1.0.0 ## explicit github.com/ryanuber/go-glob -# github.com/sanposhiho/wastedassign/v2 v2.0.6 +# github.com/sanposhiho/wastedassign/v2 v2.0.7 ## explicit; go 1.14 github.com/sanposhiho/wastedassign/v2 # github.com/sashamelentyev/interfacebloat v1.1.0 @@ -1594,7 +1594,7 @@ github.com/soheilhy/cmux github.com/sonatard/noctx github.com/sonatard/noctx/ngfunc github.com/sonatard/noctx/reqwithoutctx -# github.com/sourcegraph/go-diff v0.6.2-0.20221031073116-7ef5f68ebea1 +# github.com/sourcegraph/go-diff v0.7.0 ## explicit; go 1.14 github.com/sourcegraph/go-diff/diff # github.com/spf13/afero v1.9.2 @@ -1838,7 +1838,7 @@ github.com/tjfoc/gmsm/sm3 # github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 ## explicit github.com/tmc/grpc-websocket-proxy/wsproxy -# github.com/tomarrell/wrapcheck/v2 v2.7.0 +# github.com/tomarrell/wrapcheck/v2 v2.8.0 ## explicit; go 1.18 github.com/tomarrell/wrapcheck/v2/wrapcheck # github.com/tommy-muehle/go-mnd/v2 v2.5.1 @@ -2663,8 +2663,8 @@ gopkg.in/yaml.v2 # gopkg.in/yaml.v3 v3.0.1 ## explicit gopkg.in/yaml.v3 -# honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720 -## explicit; go 1.18 +# honnef.co/go/tools v0.4.0 +## explicit; go 1.19 honnef.co/go/tools/analysis/code honnef.co/go/tools/analysis/edit honnef.co/go/tools/analysis/facts/deprecated