Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/tools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.30.0
Choose a base ref
...
head repository: golang/tools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.31.0
Choose a head ref
Loading
Showing 456 changed files with 7,709 additions and 5,572 deletions.
2 changes: 1 addition & 1 deletion blog/blog.go
Original file line number Diff line number Diff line change
@@ -420,7 +420,7 @@ type rootData struct {
BasePath string
GodocURL string
AnalyticsHTML template.HTML
Data interface{}
Data any
}

// ServeHTTP serves the front, index, and article pages
12 changes: 0 additions & 12 deletions cmd/bundle/gotypesalias.go

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/callgraph/gotypesalias.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/callgraph/main_test.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
// No testdata on Android.

//go:build !android && go1.11
// +build !android,go1.11

package main

95 changes: 8 additions & 87 deletions cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
@@ -15,11 +15,13 @@ import (
"go/types"
"io"
"log"
"maps"
"os"
"path/filepath"
"regexp"
"runtime"
"runtime/pprof"
"slices"
"sort"
"strings"
"text/template"
@@ -175,7 +177,7 @@ func main() {
}
}

if isGenerated(file) {
if ast.IsGenerated(file) {
generated[p.Fset.File(file.Pos()).Name()] = true
}
}
@@ -290,9 +292,7 @@ func main() {

// Build array of jsonPackage objects.
var packages []any
pkgpaths := keys(byPkgPath)
sort.Strings(pkgpaths)
for _, pkgpath := range pkgpaths {
for _, pkgpath := range slices.Sorted(maps.Keys(byPkgPath)) {
if !filter.MatchString(pkgpath) {
continue
}
@@ -303,7 +303,7 @@ func main() {
// declaration order. This tends to keep related
// methods such as (T).Marshal and (*T).Unmarshal
// together better than sorting.
fns := keys(m)
fns := slices.Collect(maps.Keys(m))
sort.Slice(fns, func(i, j int) bool {
xposn := prog.Fset.Position(fns[i].Pos())
yposn := prog.Fset.Position(fns[j].Pos())
@@ -368,7 +368,7 @@ func prettyName(fn *ssa.Function, qualified bool) string {
// anonymous?
if fn.Parent() != nil {
format(fn.Parent())
i := index(fn.Parent().AnonFuncs, fn)
i := slices.Index(fn.Parent().AnonFuncs, fn)
fmt.Fprintf(&buf, "$%d", i+1)
return
}
@@ -414,45 +414,6 @@ func printObjects(format string, objects []any) {
}
}

// TODO(adonovan): use go1.21's ast.IsGenerated.

// isGenerated reports whether the file was generated by a program,
// not handwritten, by detecting the special comment described
// at https://go.dev/s/generatedcode.
//
// The syntax tree must have been parsed with the ParseComments flag.
// Example:
//
// f, err := parser.ParseFile(fset, filename, src, parser.ParseComments|parser.PackageClauseOnly)
// if err != nil { ... }
// gen := ast.IsGenerated(f)
func isGenerated(file *ast.File) bool {
_, ok := generator(file)
return ok
}

func generator(file *ast.File) (string, bool) {
for _, group := range file.Comments {
for _, comment := range group.List {
if comment.Pos() > file.Package {
break // after package declaration
}
// opt: check Contains first to avoid unnecessary array allocation in Split.
const prefix = "// Code generated "
if strings.Contains(comment.Text, prefix) {
for _, line := range strings.Split(comment.Text, "\n") {
if rest, ok := strings.CutPrefix(line, prefix); ok {
if gen, ok := strings.CutSuffix(rest, " DO NOT EDIT."); ok {
return gen, true
}
}
}
}
}
}
return "", false
}

// pathSearch returns the shortest path from one of the roots to one
// of the targets (along with the root itself), or zero if no path was found.
func pathSearch(roots []*ssa.Function, res *rta.Result, targets map[*ssa.Function]bool) (*callgraph.Node, []*callgraph.Edge) {
@@ -466,7 +427,7 @@ func pathSearch(roots []*ssa.Function, res *rta.Result, targets map[*ssa.Functio
// Sort roots into preferred order.
importsTesting := func(fn *ssa.Function) bool {
isTesting := func(p *types.Package) bool { return p.Path() == "testing" }
return containsFunc(fn.Pkg.Pkg.Imports(), isTesting)
return slices.ContainsFunc(fn.Pkg.Pkg.Imports(), isTesting)
}
sort.Slice(roots, func(i, j int) bool {
x, y := roots[i], roots[j]
@@ -500,7 +461,7 @@ func pathSearch(roots []*ssa.Function, res *rta.Result, targets map[*ssa.Functio
for {
edge := seen[node]
if edge == nil {
reverse(path)
slices.Reverse(path)
return path
}
path = append(path, edge)
@@ -604,43 +565,3 @@ type jsonPosition struct {
func (p jsonPosition) String() string {
return fmt.Sprintf("%s:%d:%d", p.File, p.Line, p.Col)
}

// -- from the future --

// TODO(adonovan): use go1.22's slices and maps packages.

func containsFunc[S ~[]E, E any](s S, f func(E) bool) bool {
return indexFunc(s, f) >= 0
}

func indexFunc[S ~[]E, E any](s S, f func(E) bool) int {
for i := range s {
if f(s[i]) {
return i
}
}
return -1
}

func index[S ~[]E, E comparable](s S, v E) int {
for i := range s {
if v == s[i] {
return i
}
}
return -1
}

func reverse[S ~[]E, E any](s S) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}

func keys[M ~map[K]V, K comparable, V any](m M) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}
12 changes: 0 additions & 12 deletions cmd/deadcode/gotypesalias.go

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/eg/gotypesalias.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/fiximports/main_test.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
// No testdata on Android.

//go:build !android
// +build !android

package main

12 changes: 0 additions & 12 deletions cmd/godex/gotypesalias.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/godex/isAlias18.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !go1.9
// +build !go1.9

package main

1 change: 0 additions & 1 deletion cmd/godex/isAlias19.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build go1.9
// +build go1.9

package main

12 changes: 0 additions & 12 deletions cmd/godoc/gotypesalias.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/goimports/goimports_gc.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build gc
// +build gc

package main

1 change: 0 additions & 1 deletion cmd/goimports/goimports_not_gc.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !gc
// +build !gc

package main

12 changes: 0 additions & 12 deletions cmd/goimports/gotypesalias.go

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/gomvpkg/gotypesalias.go

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/gotype/gotypesalias.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/gotype/sizesFor18.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !go1.9
// +build !go1.9

// This file contains a copy of the implementation of types.SizesFor
// since this function is not available in go/types before Go 1.9.
1 change: 0 additions & 1 deletion cmd/gotype/sizesFor19.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build go1.9
// +build go1.9

package main

Loading