Skip to content

Commit 895b4ed

Browse files
committed
all: merge master (9b63f3d) into gopls-release-branch.0.14
Also reinstate the x/tools replace directive. For golang/go#63220 Conflicts: - gopls/go.sum Merge List: + 2023-10-11 9b63f3d gopls: upgrade x/telemetry dependency + 2023-10-11 f38ff07 internal/refactor/inline: T{} is duplicable for struct/array + 2023-10-11 ecbfa88 go/analysis/passes/timeformat: simplify isTimeDotFormat + 2023-10-11 187911b internal/refactor/inline: more precise SelectorExpr effects + 2023-10-10 dbf6f42 go/analysis/passes/httpmux: add command + 2023-10-10 7e7568c go/analysis/passes/httpmux: check for enhanced ServeMux patterns + 2023-10-10 b268156 gopls: allow all drive letters in cache/filemap_test.go + 2023-10-10 be4e4d6 go/analysis/passes/internal/analysisutil: account for nil Func.Pkg + 2023-10-10 0e4fc90 internal/refactor/inline: add missing spread context (return) + 2023-10-10 8954aa7 go/types/internal/play: fix slice OOB when *ast.File is selected + 2023-10-10 fda3fe3 gopls/internal/lsp: use the correct options for semantic tokens legend + 2023-10-10 f6d8589 cmd/compilebench: pass linker flags to prebuild + 2023-10-09 5874869 go/analysis/passes/internal/analysisutil: add IsFunctionNamed + 2023-10-09 0b06fd8 cmd/gonew: skip Test if exec is unsupported + 2023-10-09 f5fd4c9 go/analysis/passes/bools: use astutil.Unparen + 2023-10-09 59ac17f go/analysis/passes/internal/analysisutil: remove Unparen + 2023-10-08 a3b5082 go/analysis/passes/appends: improve check for append builtin + 2023-10-08 395d393 go/analysis/passes/internal/analysisutil: add IsNamedType + 2023-10-08 22abcd6 oogo/analysis/passes/bools: remove duplicate functions + 2023-10-06 3f4194e go.mod: update golang.org/x dependencies + 2023-10-05 1e4ce7c internal/refactor/inline: yet more tweaks to everything test Change-Id: Iaf86891ab5af9ee05ada507c75234e750633e0ef
2 parents 00c58c2 + 9b63f3d commit 895b4ed

File tree

48 files changed

+750
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+750
-377
lines changed

cmd/compilebench/main.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (c compile) run(name string, count int) error {
350350
return err
351351
}
352352

353-
importcfg, err := genImportcfgFile(c.dir, false)
353+
importcfg, err := genImportcfgFile(c.dir, "", false) // TODO: pass compiler flags?
354354
if err != nil {
355355
return err
356356
}
@@ -418,12 +418,19 @@ func (r link) run(name string, count int) error {
418418
}
419419

420420
// Build dependencies.
421-
out, err := exec.Command(*flagGoCmd, "build", "-o", "/dev/null", r.dir).CombinedOutput()
421+
ldflags := *flagLinkerFlags
422+
if r.flags != "" {
423+
if ldflags != "" {
424+
ldflags += " "
425+
}
426+
ldflags += r.flags
427+
}
428+
out, err := exec.Command(*flagGoCmd, "build", "-o", "/dev/null", "-ldflags="+ldflags, r.dir).CombinedOutput()
422429
if err != nil {
423430
return fmt.Errorf("go build -a %s: %v\n%s", r.dir, err, out)
424431
}
425432

426-
importcfg, err := genImportcfgFile(r.dir, true)
433+
importcfg, err := genImportcfgFile(r.dir, "-ldflags="+ldflags, true)
427434
if err != nil {
428435
return err
429436
}
@@ -643,15 +650,19 @@ func genSymAbisFile(pkg *Pkg, symAbisFile, incdir string) error {
643650
// genImportcfgFile generates an importcfg file for building package
644651
// dir. Returns the generated importcfg file path (or empty string
645652
// if the package has no dependency).
646-
func genImportcfgFile(dir string, full bool) (string, error) {
653+
func genImportcfgFile(dir string, flags string, full bool) (string, error) {
647654
need := "{{.Imports}}"
648655
if full {
649656
// for linking, we need transitive dependencies
650657
need = "{{.Deps}}"
651658
}
652659

660+
if flags == "" {
661+
flags = "--" // passing "" to go list, it will match to the current directory
662+
}
663+
653664
// find imported/dependent packages
654-
cmd := exec.Command(*flagGoCmd, "list", "-f", need, dir)
665+
cmd := exec.Command(*flagGoCmd, "list", "-f", need, flags, dir)
655666
cmd.Stderr = os.Stderr
656667
out, err := cmd.Output()
657668
if err != nil {
@@ -667,7 +678,7 @@ func genImportcfgFile(dir string, full bool) (string, error) {
667678
}
668679

669680
// build importcfg for imported packages
670-
cmd = exec.Command(*flagGoCmd, "list", "-export", "-f", "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}")
681+
cmd = exec.Command(*flagGoCmd, "list", "-export", "-f", "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}", flags)
671682
cmd.Args = append(cmd.Args, strings.Fields(string(out))...)
672683
cmd.Stderr = os.Stderr
673684
out, err = cmd.Output()

cmd/godoc/godoc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var exe struct {
4747

4848
func godocPath(t *testing.T) string {
4949
if !testenv.HasExec() {
50-
t.Skipf("skipping test that requires exec")
50+
t.Skipf("skipping test: exec not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
5151
}
5252

5353
exe.once.Do(func() {

cmd/gonew/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"testing"
1818

1919
"golang.org/x/tools/internal/diffp"
20+
"golang.org/x/tools/internal/testenv"
2021
"golang.org/x/tools/txtar"
2122
)
2223

@@ -28,6 +29,9 @@ func init() {
2829
}
2930

3031
func Test(t *testing.T) {
32+
if !testenv.HasExec() {
33+
t.Skipf("skipping test: exec not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
34+
}
3135
exe, err := os.Executable()
3236
if err != nil {
3337
t.Fatal(err)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.18
44

55
require (
66
github.com/yuin/goldmark v1.4.13
7-
golang.org/x/mod v0.12.0
8-
golang.org/x/net v0.15.0
9-
golang.org/x/sys v0.12.0
7+
golang.org/x/mod v0.13.0
8+
golang.org/x/net v0.16.0
9+
golang.org/x/sys v0.13.0
1010
)
1111

12-
require golang.org/x/sync v0.3.0
12+
require golang.org/x/sync v0.4.0

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
22
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
3-
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
4-
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5-
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
6-
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
7-
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
8-
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
9-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
10-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3+
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
4+
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
5+
golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos=
6+
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
7+
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
8+
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
9+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
10+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

go/analysis/passes/appends/appends.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"golang.org/x/tools/go/analysis/passes/inspect"
1616
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1717
"golang.org/x/tools/go/ast/inspector"
18+
"golang.org/x/tools/go/types/typeutil"
1819
)
1920

2021
//go:embed doc.go
@@ -36,12 +37,9 @@ func run(pass *analysis.Pass) (interface{}, error) {
3637
}
3738
inspect.Preorder(nodeFilter, func(n ast.Node) {
3839
call := n.(*ast.CallExpr)
39-
if ident, ok := call.Fun.(*ast.Ident); ok && ident.Name == "append" {
40-
if _, ok := pass.TypesInfo.Uses[ident].(*types.Builtin); ok {
41-
if len(call.Args) == 1 {
42-
pass.ReportRangef(call, "append with no values")
43-
}
44-
}
40+
b, ok := typeutil.Callee(pass.TypesInfo, call).(*types.Builtin)
41+
if ok && b.Name() == "append" && len(call.Args) == 1 {
42+
pass.ReportRangef(call, "append with no values")
4543
}
4644
})
4745

go/analysis/passes/appends/testdata/src/b/b.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ func userdefine() {
1616
sli = append(sli, 4, 5, 6)
1717
sli = append(sli)
1818
}
19+
20+
func localvar() {
21+
append := func(int) int { return 0 }
22+
a := append(1)
23+
_ = a
24+
}

go/analysis/passes/assign/assign.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"golang.org/x/tools/go/analysis"
1919
"golang.org/x/tools/go/analysis/passes/inspect"
2020
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
21+
"golang.org/x/tools/go/ast/astutil"
2122
"golang.org/x/tools/go/ast/inspector"
2223
)
2324

@@ -77,7 +78,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
7778

7879
// isMapIndex returns true if e is a map index expression.
7980
func isMapIndex(info *types.Info, e ast.Expr) bool {
80-
if idx, ok := analysisutil.Unparen(e).(*ast.IndexExpr); ok {
81+
if idx, ok := astutil.Unparen(e).(*ast.IndexExpr); ok {
8182
if typ := info.Types[idx.X].Type; typ != nil {
8283
_, ok := typ.Underlying().(*types.Map)
8384
return ok

go/analysis/passes/atomic/atomic.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
_ "embed"
99
"go/ast"
1010
"go/token"
11-
"go/types"
1211

1312
"golang.org/x/tools/go/analysis"
1413
"golang.org/x/tools/go/analysis/passes/inspect"
1514
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1615
"golang.org/x/tools/go/ast/inspector"
16+
"golang.org/x/tools/go/types/typeutil"
1717
)
1818

1919
//go:embed doc.go
@@ -52,18 +52,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
5252
if !ok {
5353
continue
5454
}
55-
sel, ok := call.Fun.(*ast.SelectorExpr)
56-
if !ok {
57-
continue
58-
}
59-
pkgIdent, _ := sel.X.(*ast.Ident)
60-
pkgName, ok := pass.TypesInfo.Uses[pkgIdent].(*types.PkgName)
61-
if !ok || pkgName.Imported().Path() != "sync/atomic" {
62-
continue
63-
}
64-
65-
switch sel.Sel.Name {
66-
case "AddInt32", "AddInt64", "AddUint32", "AddUint64", "AddUintptr":
55+
fn := typeutil.StaticCallee(pass.TypesInfo, call)
56+
if analysisutil.IsFunctionNamed(fn, "sync/atomic", "AddInt32", "AddInt64", "AddUint32", "AddUint64", "AddUintptr") {
6757
checkAtomicAddAssignment(pass, n.Lhs[i], call)
6858
}
6959
}

go/analysis/passes/atomic/testdata/src/a/a.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ type Counter uint64
1414

1515
func AtomicTests() {
1616
x := uint64(1)
17-
x = atomic.AddUint64(&x, 1) // want "direct assignment to atomic value"
18-
_, x = 10, atomic.AddUint64(&x, 1) // want "direct assignment to atomic value"
19-
x, _ = atomic.AddUint64(&x, 1), 10 // want "direct assignment to atomic value"
17+
x = atomic.AddUint64(&x, 1) // want "direct assignment to atomic value"
18+
_, x = 10, atomic.AddUint64(&x, 1) // want "direct assignment to atomic value"
19+
x, _ = atomic.AddUint64(&x, 1), 10 // want "direct assignment to atomic value"
20+
x, _ = (atomic.AddUint64)(&x, 1), 10 // want "direct assignment to atomic value"
2021

2122
y := &x
2223
*y = atomic.AddUint64(y, 1) // want "direct assignment to atomic value"

0 commit comments

Comments
 (0)