Commit ba23fa48 authored by Russ Cox's avatar Russ Cox

cmd/vendor: go get -u golang.org/x/tools && go mod vendor

Picks up vet fix from CL 176357.

Change-Id: Ia77cd4a582c4edfbe59bbc311e6ce14046df0e83
Reviewed-on: https://go-review.googlesource.com/c/go/+/177137
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8116599f
...@@ -8,5 +8,5 @@ require ( ...@@ -8,5 +8,5 @@ require (
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect
golang.org/x/tools v0.0.0-20190510144052-35884eef200b golang.org/x/tools v0.0.0-20190514135123-4789ca9922f0
) )
...@@ -17,3 +17,7 @@ golang.org/x/tools v0.0.0-20190509153222-73554e0f7805 h1:1ufBXAsTpUhSmmPXEEs5PrG ...@@ -17,3 +17,7 @@ golang.org/x/tools v0.0.0-20190509153222-73554e0f7805 h1:1ufBXAsTpUhSmmPXEEs5PrG
golang.org/x/tools v0.0.0-20190509153222-73554e0f7805/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190509153222-73554e0f7805/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190510144052-35884eef200b h1:4muk7BhMes67ZgDeK3n4Jvi+FvNDRZzh6ZRqIXZNYwQ= golang.org/x/tools v0.0.0-20190510144052-35884eef200b h1:4muk7BhMes67ZgDeK3n4Jvi+FvNDRZzh6ZRqIXZNYwQ=
golang.org/x/tools v0.0.0-20190510144052-35884eef200b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190510144052-35884eef200b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190513233021-7d589f28aaf4 h1:sIGsLZaMtLBc5sLK7s2xtr7VaKk8h31mrJyHwEZq2WQ=
golang.org/x/tools v0.0.0-20190513233021-7d589f28aaf4/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190514135123-4789ca9922f0 h1:0Bz67IMuNMofIoO/F+rX8oPltlfrAC5HU68DEyynMQg=
golang.org/x/tools v0.0.0-20190514135123-4789ca9922f0/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
...@@ -8,6 +8,7 @@ package analysisflags ...@@ -8,6 +8,7 @@ package analysisflags
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/gob"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
...@@ -32,6 +33,14 @@ var ( ...@@ -32,6 +33,14 @@ var (
// including (in multi mode) a flag named after the analyzer, // including (in multi mode) a flag named after the analyzer,
// parses the flags, then filters and returns the list of // parses the flags, then filters and returns the list of
// analyzers enabled by flags. // analyzers enabled by flags.
//
// The result is intended to be passed to unitchecker.Run or checker.Run.
// Use in unitchecker.Run will gob.Register all fact types for the returned
// graph of analyzers but of course not the ones only reachable from
// dropped analyzers. To avoid inconsistency about which gob types are
// registered from run to run, Parse itself gob.Registers all the facts
// only reachable from dropped analyzers.
// This is not a particularly elegant API, but this is an internal package.
func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer { func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer {
// Connect each analysis flag to the command line as -analysis.flag. // Connect each analysis flag to the command line as -analysis.flag.
enabled := make(map[*analysis.Analyzer]*triState) enabled := make(map[*analysis.Analyzer]*triState)
...@@ -88,6 +97,8 @@ func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer { ...@@ -88,6 +97,8 @@ func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer {
os.Exit(0) os.Exit(0)
} }
everything := expand(analyzers)
// If any -NAME flag is true, run only those analyzers. Otherwise, // If any -NAME flag is true, run only those analyzers. Otherwise,
// if any -NAME flag is false, run all but those analyzers. // if any -NAME flag is false, run all but those analyzers.
if multi { if multi {
...@@ -119,9 +130,35 @@ func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer { ...@@ -119,9 +130,35 @@ func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer {
} }
} }
// Register fact types of skipped analyzers
// in case we encounter them in imported files.
kept := expand(analyzers)
for a := range everything {
if !kept[a] {
for _, f := range a.FactTypes {
gob.Register(f)
}
}
}
return analyzers return analyzers
} }
func expand(analyzers []*analysis.Analyzer) map[*analysis.Analyzer]bool {
seen := make(map[*analysis.Analyzer]bool)
var visitAll func([]*analysis.Analyzer)
visitAll = func(analyzers []*analysis.Analyzer) {
for _, a := range analyzers {
if !seen[a] {
seen[a] = true
visitAll(a.Requires)
}
}
}
visitAll(analyzers)
return seen
}
func printFlags() { func printFlags() {
type jsonFlag struct { type jsonFlag struct {
Name string Name string
......
...@@ -30,8 +30,13 @@ func run(pass *analysis.Pass) (interface{}, error) { ...@@ -30,8 +30,13 @@ func run(pass *analysis.Pass) (interface{}, error) {
nodeFilter := []ast.Node{ nodeFilter := []ast.Node{
(*ast.BinaryExpr)(nil), (*ast.BinaryExpr)(nil),
} }
seen := make(map[*ast.BinaryExpr]bool)
inspect.Preorder(nodeFilter, func(n ast.Node) { inspect.Preorder(nodeFilter, func(n ast.Node) {
e := n.(*ast.BinaryExpr) e := n.(*ast.BinaryExpr)
if seen[e] {
// Already processed as a subexpression of an earlier node.
return
}
var op boolOp var op boolOp
switch e.Op { switch e.Op {
...@@ -43,10 +48,7 @@ func run(pass *analysis.Pass) (interface{}, error) { ...@@ -43,10 +48,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
return return
} }
// TODO(adonovan): this reports n(n-1)/2 errors for an comm := op.commutativeSets(pass.TypesInfo, e, seen)
// expression e||...||e of depth n. Fix.
// See https://golang.org/issue/28086.
comm := op.commutativeSets(pass.TypesInfo, e)
for _, exprs := range comm { for _, exprs := range comm {
op.checkRedundant(pass, exprs) op.checkRedundant(pass, exprs)
op.checkSuspect(pass, exprs) op.checkSuspect(pass, exprs)
...@@ -70,8 +72,9 @@ var ( ...@@ -70,8 +72,9 @@ var (
// expressions in e that are connected by op. // expressions in e that are connected by op.
// For example, given 'a || b || f() || c || d' with the or op, // For example, given 'a || b || f() || c || d' with the or op,
// commutativeSets returns {{b, a}, {d, c}}. // commutativeSets returns {{b, a}, {d, c}}.
func (op boolOp) commutativeSets(info *types.Info, e *ast.BinaryExpr) [][]ast.Expr { // commutativeSets adds any expanded BinaryExprs to seen.
exprs := op.split(e) func (op boolOp) commutativeSets(info *types.Info, e *ast.BinaryExpr, seen map[*ast.BinaryExpr]bool) [][]ast.Expr {
exprs := op.split(e, seen)
// Partition the slice of expressions into commutative sets. // Partition the slice of expressions into commutative sets.
i := 0 i := 0
...@@ -188,11 +191,13 @@ func hasSideEffects(info *types.Info, e ast.Expr) bool { ...@@ -188,11 +191,13 @@ func hasSideEffects(info *types.Info, e ast.Expr) bool {
// split returns a slice of all subexpressions in e that are connected by op. // split returns a slice of all subexpressions in e that are connected by op.
// For example, given 'a || (b || c) || d' with the or op, // For example, given 'a || (b || c) || d' with the or op,
// split returns []{d, c, b, a}. // split returns []{d, c, b, a}.
func (op boolOp) split(e ast.Expr) (exprs []ast.Expr) { // seen[e] is already true; any newly processed exprs are added to seen.
func (op boolOp) split(e ast.Expr, seen map[*ast.BinaryExpr]bool) (exprs []ast.Expr) {
for { for {
e = unparen(e) e = unparen(e)
if b, ok := e.(*ast.BinaryExpr); ok && b.Op == op.tok { if b, ok := e.(*ast.BinaryExpr); ok && b.Op == op.tok {
exprs = append(exprs, op.split(b.Y)...) seen[b] = true
exprs = append(exprs, op.split(b.Y, seen)...)
e = b.X e = b.X
} else { } else {
exprs = append(exprs, e) exprs = append(exprs, e)
......
...@@ -26,7 +26,7 @@ golang.org/x/crypto/ssh/terminal ...@@ -26,7 +26,7 @@ golang.org/x/crypto/ssh/terminal
# golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 # golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82
golang.org/x/sys/unix golang.org/x/sys/unix
golang.org/x/sys/windows golang.org/x/sys/windows
# golang.org/x/tools v0.0.0-20190510144052-35884eef200b # golang.org/x/tools v0.0.0-20190514135123-4789ca9922f0
golang.org/x/tools/go/analysis golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/internal/analysisflags golang.org/x/tools/go/analysis/internal/analysisflags
golang.org/x/tools/go/analysis/internal/facts golang.org/x/tools/go/analysis/internal/facts
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment