Skip to content

Commit 188b785

Browse files
committed
all: merge master (9c97539) into gopls-release-branch.0.12
Also put back the x/tools replace directive in gopls/go.mod. For golang/go#59818 Merge List: + 2023-05-24 9c97539 gopls/internal/lsp/cache: remove nested module warning + 2023-05-24 d44a094 gopls/internal/lsp/cmd: add a stats -anon flag to show anonymous data + 2023-05-24 e106694 gopls/internal/lsp: bundle certain quick-fixes with their diagnostic + 2023-05-24 5dc3f74 gopls/internal/lsp/filecache: reenable memory cache layer + 2023-05-24 7e146a6 gopls/internal/lsp/cmd: simplify connection type + 2023-05-24 1e60668 gopls/internal/regtest/workspace: unskip duplicate modules test + 2023-05-23 5ce721d gopls/doc: Fix broken links + 2023-05-23 7a03feb gopls/internal/lsp/cmd: remove vestiges of debugging golang/go#59475 + 2023-05-22 a70f2bc gopls/internal/regtest/misc: update and unskip TestHoverIntLiteral + 2023-05-22 6997d19 gopls/internal/regtest/misc: unskip TestMajorOptionsChange + 2023-05-22 ec543c5 gopls/internal/lsp/cache: fix crash in Session.updateViewLocked + 2023-05-22 a12ee94 gopls/internal/regtest/misc: update some unilaterally skipped tests + 2023-05-22 5ff5cbb gopls: deprecate support for Go 1.16 and 1.17, update warnings + 2023-05-22 e6fd7f4 gopls/internal/lsp/cache: limit module scan to 100K files + 2023-05-22 9ca66ba gopls/internal/lsp/regtest: delete TestWatchReplaceTargets + 2023-05-22 edbfdbe gopls/internal/lsp/source/completion: (unimported) add placeholders + 2023-05-22 3a5dbf3 gopls: add a new "subdirWatchPatterns" setting + 2023-05-22 3c02551 internal/typesinternal: remove NewObjectpathFunc + 2023-05-20 0729362 present: reformat doc comment for lack of inline code + 2023-05-20 d4e66bd go/ssa: TestStdlib: disable check that function names are distinct + 2023-05-20 738ea2b go/ssa: use core type for field accesses + 2023-05-19 2ec4299 gopls/internal/lsp: split file-watching glob patterns + 2023-05-19 43b02ea gopls/internal/lsp/cache: only delete the most relevant mod tidy handle + 2023-05-19 5919673 internal/lsp/filecache: eliminate 'kind' directories + 2023-05-19 a5ef6c3 gopls/internal/lsp: keep track of overlays on the files map + 2023-05-19 d7f4359 gopls/internal/lsp/mod: optimizations for mod tidy diagnostics + 2023-05-19 2eb726b gopls/internal/lsp/filecache: touch only files older than 1h + 2023-05-19 b742cb9 gopls/internal/regtest/bench: add a benchmark for diagnosing saves + 2023-05-19 4d66324 gopls/internal/lsp/cache: tweak error message + 2023-05-19 e46df40 gopls/internal/lsp/filecache: delayed tweaks from code review + 2023-05-19 3df69b8 gopls/internal/lsp/debug: remove memory monitoring + 2023-05-19 a069704 gopls/internal/lsp/filecache: avoid flock + 2023-05-18 3d53c2d gopls/internal/lsp/cache: fix race in adhoc reloading + 2023-05-17 8b4b27b go/analysis/passes/slog: fix Group kv offset + 2023-05-17 242e5ed cover: eliminate an unnecessary fsync in TestParseProfiles + 2023-05-17 651d951 go/ssa: fix typo in package docs Change-Id: Ie57d55ba8f3ae9bcf868db08088f68955b5e4856
2 parents 12762ec + 9c97539 commit 188b785

Some content is hidden

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

80 files changed

+1336
-2360
lines changed

cover/profile_test.go

+5-19
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package cover
66

77
import (
88
"fmt"
9-
"io/ioutil"
109
"os"
10+
"path/filepath"
1111
"reflect"
1212
"testing"
1313
)
@@ -208,26 +208,12 @@ some/fancy/path:42.69,44.16 2 -1`,
208208

209209
for _, tc := range tests {
210210
t.Run(tc.name, func(t *testing.T) {
211-
f, err := ioutil.TempFile("", "")
212-
if err != nil {
213-
t.Fatalf("Failed to create a temp file: %v.", err)
214-
}
215-
defer func() {
216-
f.Close()
217-
os.Remove(f.Name())
218-
}()
219-
n, err := f.WriteString(tc.input)
220-
if err != nil {
221-
t.Fatalf("Failed to write to temp file: %v", err)
222-
}
223-
if n < len(tc.input) {
224-
t.Fatalf("Didn't write enough bytes to temp file (wrote %d, expected %d).", n, len(tc.input))
225-
}
226-
if err := f.Sync(); err != nil {
227-
t.Fatalf("Failed to sync temp file: %v", err)
211+
fname := filepath.Join(t.TempDir(), "test.cov")
212+
if err := os.WriteFile(fname, []byte(tc.input), 0644); err != nil {
213+
t.Fatal(err)
228214
}
229215

230-
result, err := ParseProfiles(f.Name())
216+
result, err := ParseProfiles(fname)
231217
if err != nil {
232218
if !tc.expectErr {
233219
t.Errorf("Unexpected error: %v", err)

go/analysis/passes/slog/slog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ var kvFuncs = map[string]map[string]int{
204204
"WarnCtx": 2,
205205
"ErrorCtx": 2,
206206
"Log": 3,
207-
"Group": 0,
207+
"Group": 1,
208208
},
209209
"Logger": map[string]int{
210210
"Debug": 1,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ func All() {
143143

144144
r.Add(1, 2) // want `slog.Record.Add arg "1" should be a string or a slog.Attr`
145145

146-
_ = slog.Group("a", 1, 2, 3) // want `slog.Group arg "2" should be a string or a slog.Attr`
146+
_ = slog.Group("key", "a", 1, "b", 2)
147+
_ = slog.Group("key", "a", 1, 2, 3) // want `slog.Group arg "2" should be a string or a slog.Attr`
147148

148149
}
149150

go/ssa/builder_generic_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func TestInstructionString(t *testing.T) {
685685
//@ instrs("f12", "*ssa.MakeMap", "make map[P]bool 1:int")
686686
func f12[T any, P *struct{f T}](x T) map[P]bool { return map[P]bool{{}: true} }
687687
688-
//@ instrs("f13", "&v[0:int]")
688+
//@ instrs("f13", "*ssa.IndexAddr", "&v[0:int]")
689689
//@ instrs("f13", "*ssa.Store", "*t0 = 7:int", "*v = *new(A):A")
690690
func f13[A [3]int, PA *A](v PA) {
691691
*v = A{7}

go/ssa/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
// *FieldAddr ✔ ✔
6767
// *FreeVar ✔
6868
// *Function ✔ ✔ (func)
69-
// *GenericConvert ✔ ✔
7069
// *Global ✔ ✔ (var)
7170
// *Go ✔
7271
// *If ✔
@@ -80,6 +79,7 @@
8079
// *MakeMap ✔ ✔
8180
// *MakeSlice ✔ ✔
8281
// *MapUpdate ✔
82+
// *MultiConvert ✔ ✔
8383
// *NamedConst ✔ (const)
8484
// *Next ✔ ✔
8585
// *Panic ✔

go/ssa/emit.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func emitTailCall(f *Function, call *Call) {
476476
// value of a field.
477477
func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos) Value {
478478
for _, index := range indices {
479-
if st, vptr := deptr(v.Type()); vptr {
479+
if st, vptr := deref(v.Type()); vptr {
480480
fld := fieldOf(st, index)
481481
instr := &FieldAddr{
482482
X: v,
@@ -486,7 +486,7 @@ func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos)
486486
instr.setType(types.NewPointer(fld.Type()))
487487
v = f.emit(instr)
488488
// Load the field's value iff indirectly embedded.
489-
if _, fldptr := deptr(fld.Type()); fldptr {
489+
if _, fldptr := deref(fld.Type()); fldptr {
490490
v = emitLoad(f, v)
491491
}
492492
} else {
@@ -510,7 +510,7 @@ func emitImplicitSelections(f *Function, v Value, indices []int, pos token.Pos)
510510
// field's value.
511511
// Ident id is used for position and debug info.
512512
func emitFieldSelection(f *Function, v Value, index int, wantAddr bool, id *ast.Ident) Value {
513-
if st, vptr := deptr(v.Type()); vptr {
513+
if st, vptr := deref(v.Type()); vptr {
514514
fld := fieldOf(st, index)
515515
instr := &FieldAddr{
516516
X: v,

go/ssa/ssa.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ type Slice struct {
865865
type FieldAddr struct {
866866
register
867867
X Value // *struct
868-
Field int // field is typeparams.CoreType(X.Type().Underlying().(*types.Pointer).Elem()).(*types.Struct).Field(Field)
868+
Field int // index into CoreType(CoreType(X.Type()).(*types.Pointer).Elem()).(*types.Struct).Fields
869869
}
870870

871871
// The Field instruction yields the Field of struct X.
@@ -884,7 +884,7 @@ type FieldAddr struct {
884884
type Field struct {
885885
register
886886
X Value // struct
887-
Field int // index into typeparams.CoreType(X.Type()).(*types.Struct).Fields
887+
Field int // index into CoreType(X.Type()).(*types.Struct).Fields
888888
}
889889

890890
// The IndexAddr instruction yields the address of the element at

go/ssa/stdlib_test.go

+28-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func bytesAllocated() uint64 {
3636

3737
func TestStdlib(t *testing.T) {
3838
if testing.Short() {
39-
t.Skip("skipping in short mode; too slow (https://golang.org/issue/14113)")
39+
t.Skip("skipping in short mode; too slow (https://golang.org/issue/14113)") // ~5s
4040
}
4141
testenv.NeedsTool(t, "go")
4242

@@ -81,20 +81,33 @@ func TestStdlib(t *testing.T) {
8181

8282
allFuncs := ssautil.AllFunctions(prog)
8383

84-
// Check that all non-synthetic functions have distinct names.
85-
// Synthetic wrappers for exported methods should be distinct too,
86-
// except for unexported ones (explained at (*Function).RelString).
87-
byName := make(map[string]*ssa.Function)
88-
for fn := range allFuncs {
89-
if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
90-
str := fn.String()
91-
prev := byName[str]
92-
byName[str] = fn
93-
if prev != nil {
94-
t.Errorf("%s: duplicate function named %s",
95-
prog.Fset.Position(fn.Pos()), str)
96-
t.Errorf("%s: (previously defined here)",
97-
prog.Fset.Position(prev.Pos()))
84+
// The assertion below is not valid if the program contains
85+
// variants of the same package, such as the test variants
86+
// (e.g. package p as compiled for test executable x) obtained
87+
// when cfg.Tests=true. Profile-guided optimization may
88+
// lead to similar variation for non-test executables.
89+
//
90+
// Ideally, the test would assert that all functions within
91+
// each executable (more generally: within any singly rooted
92+
// transitively closed subgraph of the import graph) have
93+
// distinct names, but that isn't so easy to compute efficiently.
94+
// Disabling for now.
95+
if false {
96+
// Check that all non-synthetic functions have distinct names.
97+
// Synthetic wrappers for exported methods should be distinct too,
98+
// except for unexported ones (explained at (*Function).RelString).
99+
byName := make(map[string]*ssa.Function)
100+
for fn := range allFuncs {
101+
if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
102+
str := fn.String()
103+
prev := byName[str]
104+
byName[str] = fn
105+
if prev != nil {
106+
t.Errorf("%s: duplicate function named %s",
107+
prog.Fset.Position(fn.Pos()), str)
108+
t.Errorf("%s: (previously defined here)",
109+
prog.Fset.Position(prev.Pos()))
110+
}
98111
}
99112
}
100113
}

gopls/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ version of gopls.
9393
| ----------- | --------------------------------------------------- |
9494
| Go 1.12 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.7.5) |
9595
| Go 1.15 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.9.5) |
96+
| Go 1.17 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.11.0) |
9697

9798
Our extended support is enforced via [continuous integration with older Go
9899
versions](doc/contributing.md#ci). This legacy Go CI may not block releases:

gopls/doc/commands.md

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ Args:
267267
"URI": string,
268268
// The module path to remove.
269269
"ModulePath": string,
270+
// If the module is tidied apart from the one unused diagnostic, we can
271+
// run `go get module@none`, and then run `go mod tidy`. Otherwise, we
272+
// must make textual edits.
270273
"OnlyDiagnostic": bool,
271274
}
272275
```

gopls/doc/design/implementation.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Package | Description
3737

3838
[gopls]: https://github.com/golang/tools/tree/master/gopls
3939
[internal/jsonrpc2]: https://github.com/golang/tools/tree/master/internal/jsonrpc2
40-
[internal/lsp]: https://github.com/golang/tools/tree/master/internal/lsp
41-
[internal/lsp/cache]: https://github.com/golang/tools/tree/master/internal/lsp/cache
42-
[internal/lsp/cmd]: https://github.com/golang/tools/tree/master/internal/lsp/cmd
43-
[internal/lsp/debug]: https://github.com/golang/tools/tree/master/internal/lsp/debug
44-
[internal/lsp/protocol]: https://github.com/golang/tools/tree/master/internal/lsp/protocol
45-
[internal/lsp/source]: https://github.com/golang/tools/tree/master/internal/lsp/source
40+
[internal/lsp]: https://github.com/golang/tools/tree/master/gopls/internal/lsp
41+
[internal/lsp/cache]: https://github.com/golang/tools/tree/master/gopls/internal/lsp/cache
42+
[internal/lsp/cmd]: https://github.com/golang/tools/tree/master/gopls/internal/lsp/cmd
43+
[internal/lsp/debug]: https://github.com/golang/tools/tree/master/gopls/internal/lsp/debug
44+
[internal/lsp/protocol]: https://github.com/golang/tools/tree/master/gopls/internal/lsp/protocol
45+
[internal/lsp/source]: https://github.com/golang/tools/tree/master/gopls/internal/lsp/source
4646
[internal/memoize]: https://github.com/golang/tools/tree/master/internal/memoize
47-
[internal/span]: https://github.com/golang/tools/tree/master/internal/span
47+
[internal/span]: https://github.com/golang/tools/tree/master/gopls/internal/span
4848
[x/tools]: https://github.com/golang/tools

gopls/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ require (
2525
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
2626
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 // indirect
2727
)
28+
29+
replace golang.org/x/tools => ../

gopls/go.sum

-44
Original file line numberDiff line numberDiff line change
@@ -42,86 +42,42 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
4242
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4343
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
4444
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
45-
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
46-
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
4745
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
48-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
49-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
50-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
5146
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
5247
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
5348
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
5449
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
5550
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
5651
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
57-
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
58-
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
5952
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
6053
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
6154
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
6255
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
6356
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
6457
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
65-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
66-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
67-
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
6858
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
69-
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
70-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
71-
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
72-
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
7359
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
74-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
75-
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7660
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
77-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7861
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7962
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8063
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
8164
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
82-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
83-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
84-
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8565
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
86-
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
87-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8866
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8967
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9068
golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
91-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
92-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9369
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9470
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9571
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9672
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
9773
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9874
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
99-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
100-
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
101-
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
10275
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
103-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
10476
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
105-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
106-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
107-
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
108-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
10977
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
11078
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
111-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
112-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
113-
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
114-
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
115-
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
116-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
117-
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
118-
golang.org/x/tools v0.4.1-0.20221217013628-b4dfc36097e2/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
119-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
120-
golang.org/x/tools v0.9.2-0.20230516204147-76f78597112f h1:sbeNk1oZVYGPodwxlh++zvjWdh/C9nWD3lkPTLPkzDU=
121-
golang.org/x/tools v0.9.2-0.20230516204147-76f78597112f/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
12279
golang.org/x/vuln v0.0.0-20230110180137-6ad3e3d07815 h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
12380
golang.org/x/vuln v0.0.0-20230110180137-6ad3e3d07815/go.mod h1:XJiVExZgoZfrrxoTeVsFYrSSk1snhfpOEC95JL+A4T0=
124-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12581
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12682
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12783
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

gopls/internal/bug/bug.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"runtime/debug"
1818
"sort"
1919
"sync"
20+
"time"
2021
)
2122

2223
// PanicOnBugs controls whether to panic when bugs are reported.
@@ -32,12 +33,15 @@ var (
3233

3334
// A Bug represents an unexpected event or broken invariant. They are used for
3435
// capturing metadata that helps us understand the event.
36+
//
37+
// Bugs are JSON-serializable.
3538
type Bug struct {
36-
File string // file containing the call to bug.Report
37-
Line int // line containing the call to bug.Report
38-
Description string // description of the bug
39-
Key string // key identifying the bug (file:line if available)
40-
Stack string // call stack
39+
File string // file containing the call to bug.Report
40+
Line int // line containing the call to bug.Report
41+
Description string // description of the bug
42+
Key string // key identifying the bug (file:line if available)
43+
Stack string // call stack
44+
AtTime time.Time // time the bug was reported
4145
}
4246

4347
// Reportf reports a formatted bug message.
@@ -77,6 +81,7 @@ func report(description string) {
7781
Description: description,
7882
Key: key,
7983
Stack: string(debug.Stack()),
84+
AtTime: time.Now(),
8085
}
8186

8287
mu.Lock()

gopls/internal/bug/bug_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
package bug
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"testing"
11+
"time"
12+
13+
"github.com/google/go-cmp/cmp"
1014
)
1115

1216
func resetForTesting() {
@@ -62,3 +66,26 @@ func TestBugHandler(t *testing.T) {
6266
t.Errorf("got %q, want %q", got, want)
6367
}
6468
}
69+
70+
func TestBugJSON(t *testing.T) {
71+
b1 := Bug{
72+
File: "foo.go",
73+
Line: 1,
74+
Description: "a bug",
75+
Key: "foo.go:1",
76+
Stack: "<stack>",
77+
AtTime: time.Now(),
78+
}
79+
80+
data, err := json.Marshal(b1)
81+
if err != nil {
82+
t.Fatal(err)
83+
}
84+
var b2 Bug
85+
if err := json.Unmarshal(data, &b2); err != nil {
86+
t.Fatal(err)
87+
}
88+
if diff := cmp.Diff(b1, b2); diff != "" {
89+
t.Errorf("bugs differ after JSON Marshal/Unmarshal (-b1 +b2):\n%s", diff)
90+
}
91+
}

0 commit comments

Comments
 (0)