Bumping k8s version to 1.13.0-beta.1

This commit is contained in:
Cheng Xing
2018-11-19 14:10:50 -08:00
parent 01bd7f356e
commit e2f1bdc372
633 changed files with 11189 additions and 126194 deletions

View File

@@ -18,7 +18,7 @@ string. It uses heuristics that do not guarantee all reports are
genuine problems, but it can find errors not caught by the compilers.
`
// Help implements the help subcommand for a multichecker or vet-lite
// Help implements the help subcommand for a multichecker or unitchecker
// style command. The optional args specify the analyzers to describe.
// Help calls log.Fatal if no such analyzer exists.
func Help(progname string, analyzers []*analysis.Analyzer, args []string) {

View File

@@ -16,7 +16,7 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const Doc = `checked for unkeyed composite literals
const Doc = `check for unkeyed composite literals
This analyzer reports a diagnostic for composite literals of struct
types imported from another package that do not use the field-keyed

View File

@@ -93,32 +93,32 @@ func runFunc(pass *analysis.Pass, node ast.Node) {
// ctx, cancel = context.WithCancel(...)
// var ctx, cancel = context.WithCancel(...)
//
if isContextWithCancel(pass.TypesInfo, n) && isCall(stack[len(stack)-2]) {
var id *ast.Ident // id of cancel var
stmt := stack[len(stack)-3]
switch stmt := stmt.(type) {
case *ast.ValueSpec:
if len(stmt.Names) > 1 {
id = stmt.Names[1]
}
case *ast.AssignStmt:
if len(stmt.Lhs) > 1 {
id, _ = stmt.Lhs[1].(*ast.Ident)
}
if !isContextWithCancel(pass.TypesInfo, n) || !isCall(stack[len(stack)-2]) {
return true
}
var id *ast.Ident // id of cancel var
stmt := stack[len(stack)-3]
switch stmt := stmt.(type) {
case *ast.ValueSpec:
if len(stmt.Names) > 1 {
id = stmt.Names[1]
}
if id != nil {
if id.Name == "_" {
pass.Reportf(id.Pos(),
"the cancel function returned by context.%s should be called, not discarded, to avoid a context leak",
n.(*ast.SelectorExpr).Sel.Name)
} else if v, ok := pass.TypesInfo.Uses[id].(*types.Var); ok {
cancelvars[v] = stmt
} else if v, ok := pass.TypesInfo.Defs[id].(*types.Var); ok {
cancelvars[v] = stmt
}
case *ast.AssignStmt:
if len(stmt.Lhs) > 1 {
id, _ = stmt.Lhs[1].(*ast.Ident)
}
}
if id != nil {
if id.Name == "_" {
pass.Reportf(id.Pos(),
"the cancel function returned by context.%s should be called, not discarded, to avoid a context leak",
n.(*ast.SelectorExpr).Sel.Name)
} else if v, ok := pass.TypesInfo.Uses[id].(*types.Var); ok {
cancelvars[v] = stmt
} else if v, ok := pass.TypesInfo.Defs[id].(*types.Var); ok {
cancelvars[v] = stmt
}
}
return true
})
@@ -179,18 +179,22 @@ func hasImport(pkg *types.Package, path string) bool {
// isContextWithCancel reports whether n is one of the qualified identifiers
// context.With{Cancel,Timeout,Deadline}.
func isContextWithCancel(info *types.Info, n ast.Node) bool {
if sel, ok := n.(*ast.SelectorExpr); ok {
switch sel.Sel.Name {
case "WithCancel", "WithTimeout", "WithDeadline":
if x, ok := sel.X.(*ast.Ident); ok {
if pkgname, ok := info.Uses[x].(*types.PkgName); ok {
return pkgname.Imported().Path() == contextPackage
}
// Import failed, so we can't check package path.
// Just check the local package name (heuristic).
return x.Name == "context"
}
sel, ok := n.(*ast.SelectorExpr)
if !ok {
return false
}
switch sel.Sel.Name {
case "WithCancel", "WithTimeout", "WithDeadline":
default:
return false
}
if x, ok := sel.X.(*ast.Ident); ok {
if pkgname, ok := info.Uses[x].(*types.PkgName); ok {
return pkgname.Imported().Path() == contextPackage
}
// Import failed, so we can't check package path.
// Just check the local package name (heuristic).
return x.Name == "context"
}
return false
}
@@ -270,29 +274,30 @@ outer:
var search func(blocks []*cfg.Block) *ast.ReturnStmt
search = func(blocks []*cfg.Block) *ast.ReturnStmt {
for _, b := range blocks {
if !seen[b] {
seen[b] = true
if seen[b] {
continue
}
seen[b] = true
// Prune the search if the block uses v.
if blockUses(pass, v, b) {
continue
}
// Prune the search if the block uses v.
if blockUses(pass, v, b) {
continue
}
// Found path to return statement?
if ret := b.Return(); ret != nil {
if debug {
fmt.Printf("found path to return in block %s\n", b)
}
return ret // found
// Found path to return statement?
if ret := b.Return(); ret != nil {
if debug {
fmt.Printf("found path to return in block %s\n", b)
}
return ret // found
}
// Recur
if ret := search(b.Succs); ret != nil {
if debug {
fmt.Printf(" from block %s\n", b)
}
return ret
// Recur
if ret := search(b.Succs); ret != nil {
if debug {
fmt.Printf(" from block %s\n", b)
}
return ret
}
}
return nil

View File

@@ -131,7 +131,7 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
expectFmt += " (" + argjoin(expect.results) + ")"
}
actual := types.TypeString(sign, (*types.Package).Name)
actual := typeString(sign)
actual = strings.TrimPrefix(actual, "func")
actual = id.Name + actual
@@ -139,6 +139,10 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
}
}
func typeString(typ types.Type) string {
return types.TypeString(typ, (*types.Package).Name)
}
func argjoin(x []string) string {
y := make([]string, len(x))
for i, s := range x {
@@ -178,5 +182,5 @@ func matchParamType(fset *token.FileSet, pkg *types.Package, expect string, actu
}
// Overkill but easy.
return actual.String() == expect
return typeString(actual) == expect
}

View File

@@ -24,6 +24,10 @@ func (U) GobDecode() {} // want `should have signature GobDecode\(\[\]byte\) err
// Test rendering of type names such as xml.Encoder in diagnostic.
func (U) MarshalXML(*xml.Encoder) {} // want `method MarshalXML\(\*xml.Encoder\) should...`
func (U) UnmarshalXML(*xml.Decoder, xml.StartElement) error { // no error: signature matches xml.Unmarshaler
return nil
}
type I interface {
ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)`
}

View File

@@ -62,28 +62,28 @@ func isSafeUintptr(info *types.Info, x ast.Expr) bool {
return isSafeUintptr(info, x.X)
case *ast.SelectorExpr:
switch x.Sel.Name {
case "Data":
// reflect.SliceHeader and reflect.StringHeader are okay,
// but only if they are pointing at a real slice or string.
// It's not okay to do:
// var x SliceHeader
// x.Data = uintptr(unsafe.Pointer(...))
// ... use x ...
// p := unsafe.Pointer(x.Data)
// because in the middle the garbage collector doesn't
// see x.Data as a pointer and so x.Data may be dangling
// by the time we get to the conversion at the end.
// For now approximate by saying that *Header is okay
// but Header is not.
pt, ok := info.Types[x.X].Type.(*types.Pointer)
if ok {
t, ok := pt.Elem().(*types.Named)
if ok && t.Obj().Pkg().Path() == "reflect" {
switch t.Obj().Name() {
case "StringHeader", "SliceHeader":
return true
}
if x.Sel.Name != "Data" {
break
}
// reflect.SliceHeader and reflect.StringHeader are okay,
// but only if they are pointing at a real slice or string.
// It's not okay to do:
// var x SliceHeader
// x.Data = uintptr(unsafe.Pointer(...))
// ... use x ...
// p := unsafe.Pointer(x.Data)
// because in the middle the garbage collector doesn't
// see x.Data as a pointer and so x.Data may be dangling
// by the time we get to the conversion at the end.
// For now approximate by saying that *Header is okay
// but Header is not.
pt, ok := info.Types[x.X].Type.(*types.Pointer)
if ok {
t, ok := pt.Elem().(*types.Named)
if ok && t.Obj().Pkg().Path() == "reflect" {
switch t.Obj().Name() {
case "StringHeader", "SliceHeader":
return true
}
}
}

View File

@@ -1,7 +1,12 @@
// The vet-lite command is a driver for static checkers conforming to
// the golang.org/x/tools/go/analysis API. It must be run by go vet:
// +build ignore
// This file provides an example command for static checkers
// conforming to the golang.org/x/tools/go/analysis API.
// It serves as a model for the behavior of the cmd/vet tool in $GOROOT.
// Being based on the unitchecker driver, it must be run by go vet:
//
// $ go vet -vettool=$(which vet-lite)
// $ go build -o unitchecker main.go
// $ go vet -vettool=unitchecker my/project/...
//
// For a checker also capable of running standalone, use multichecker.
package main
@@ -32,21 +37,6 @@ import (
"golang.org/x/tools/go/analysis/passes/unusedresult"
)
// Legacy vet had the concept of "experimental" checkers. There
// was exactly one, shadow, and it had to be explicitly enabled
// by the -shadow flag, which would of course disable all the
// other tristate flags, requiring the -all flag to reenable them.
// (By itself, -all did not enable all checkers.)
// The -all flag is no longer needed, so it is a no-op.
//
// The shadow analyzer has been removed from the suite,
// but can be run using these additional commands:
// $ go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
// $ go vet -vettool=$(which shadow)
// Alternatively, one could build a multichecker containing all
// the desired checks (vet's suite + shadow) and run it in a
// single "go vet" command.
func main() {
unitchecker.Main(
asmdecl.Analyzer,

View File

@@ -95,7 +95,7 @@ func Main(analyzers ...*analysis.Analyzer) {
Usage of %[1]s:
%.16[1]s unit.cfg # execute analysis specified by config file
%.16[1]s help # general help
%.16[1]s help # general help
%.16[1]s help name # help on specific analyzer and its flags
`, progname)
os.Exit(1)

View File

@@ -164,6 +164,7 @@ var (
posType = reflect.TypeOf(token.Pos(0))
positionType = reflect.TypeOf(token.Position{})
rangeType = reflect.TypeOf(Range{})
fsetType = reflect.TypeOf((*token.FileSet)(nil))
)
// converter converts from a marker's argument parsed from the comment to
@@ -190,6 +191,10 @@ func (e *Exported) buildConverter(pt reflect.Type) (converter, error) {
return func(n *expect.Note, args []interface{}) (reflect.Value, []interface{}, error) {
return reflect.ValueOf(n), args, nil
}, nil
case pt == fsetType:
return func(n *expect.Note, args []interface{}) (reflect.Value, []interface{}, error) {
return reflect.ValueOf(e.fset), args, nil
}, nil
case pt == posType:
return func(n *expect.Note, args []interface{}) (reflect.Value, []interface{}, error) {
r, remains, err := e.rangeConverter(n, args)

View File

@@ -103,7 +103,7 @@ func TestAll(t *testing.T, f func(*testing.T, Exporter)) {
// The file deletion in the cleanup can be skipped by setting the skip-cleanup
// flag when invoking the test, allowing the temporary directory to be left for
// debugging tests.
func Export(t *testing.T, exporter Exporter, modules []Module) *Exported {
func Export(t testing.TB, exporter Exporter, modules []Module) *Exported {
t.Helper()
dirname := strings.Replace(t.Name(), "/", "_", -1)
dirname = strings.Replace(dirname, "#", "_", -1) // duplicate subtests get a #NNN suffix.

View File

@@ -20,6 +20,7 @@ import (
"testing"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/expect"
"golang.org/x/tools/go/loader"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
@@ -232,37 +233,41 @@ func testValueForExpr(t *testing.T, testfile string) {
}
}
// Find the actual AST node for each canonical position.
parenExprByPos := make(map[token.Pos]*ast.ParenExpr)
var parenExprs []*ast.ParenExpr
ast.Inspect(f, func(n ast.Node) bool {
if n != nil {
if e, ok := n.(*ast.ParenExpr); ok {
parenExprByPos[e.Pos()] = e
parenExprs = append(parenExprs, e)
}
}
return true
})
// Find all annotations of form /*@kind*/.
for _, c := range f.Comments {
text := strings.TrimSpace(c.Text())
if text == "" || text[0] != '@' {
continue
notes, err := expect.Extract(prog.Fset, f)
if err != nil {
t.Fatal(err)
}
for _, n := range notes {
want := n.Name
if want == "nil" {
want = "<nil>"
}
text = text[1:]
pos := c.End() + 1
position := prog.Fset.Position(pos)
position := prog.Fset.Position(n.Pos)
var e ast.Expr
if target := parenExprByPos[pos]; target == nil {
t.Errorf("%s: annotation doesn't precede ParenExpr: %q", position, text)
for _, paren := range parenExprs {
if paren.Pos() > n.Pos {
e = paren.X
break
}
}
if e == nil {
t.Errorf("%s: note doesn't precede ParenExpr: %q", position, want)
continue
} else {
e = target.X
}
path, _ := astutil.PathEnclosingInterval(f, pos, pos)
path, _ := astutil.PathEnclosingInterval(f, n.Pos, n.Pos)
if path == nil {
t.Errorf("%s: can't find AST path from root to comment: %s", position, text)
t.Errorf("%s: can't find AST path from root to comment: %s", position, want)
continue
}
@@ -274,7 +279,7 @@ func testValueForExpr(t *testing.T, testfile string) {
v, gotAddr := fn.ValueForExpr(e) // (may be nil)
got := strings.TrimPrefix(fmt.Sprintf("%T", v), "*ssa.")
if want := text; got != want {
if got != want {
t.Errorf("%s: got value %q, want %q", position, got, want)
}
if v != nil {

View File

@@ -10,12 +10,13 @@ package main
func f(spilled, unspilled int) {
_ = /*@UnOp*/ (spilled)
_ = /*@Parameter*/ (unspilled)
_ = /*@<nil>*/ (1 + 2) // (constant)
_ = /*@nil*/ (1 + 2) // (constant)
i := 0
f := func() (int, int) { return 0, 0 }
/*@Call*/ (print( /*@BinOp*/ (i + 1)))
/*@Call*/
(print( /*@BinOp*/ (i + 1)))
_, _ = /*@Call*/ (f())
ch := /*@MakeChan*/ (make(chan int))
/*@UnOp*/ (<-ch)
@@ -43,7 +44,7 @@ func f(spilled, unspilled int) {
sl := []int{}
_ = /*@Slice*/ (sl[:0])
_ = /*@<nil>*/ (new(int)) // optimized away
_ = /*@nil*/ (new(int)) // optimized away
tmp := /*@Alloc*/ (new(int))
_ = tmp
var iface interface{}
@@ -88,7 +89,7 @@ func complit() {
_, _, _ = sl1, sl2, sl3
_ = /*@Slice*/ ([]int{})
_ = /*@<nil>*/ (& /*@Slice*/ ([]int{})) // & optimized away
_ = /*@nil*/ (& /*@Slice*/ ([]int{})) // & optimized away
_ = & /*@Slice*/ ([]int{})
// 2. Arrays
@@ -117,7 +118,7 @@ func complit() {
_, _, _ = m1, m2, m3
_ = /*@MakeMap*/ (M{})
_ = /*@<nil>*/ (& /*@MakeMap*/ (M{})) // & optimized away
_ = /*@nil*/ (& /*@MakeMap*/ (M{})) // & optimized away
_ = & /*@MakeMap*/ (M{})
// 4. Structs