Skip to content

Commit 5fe60fd

Browse files
adonovangopherbot
authored andcommitted
internal/settings: drop "annotations" setting
This obscure suboption of the already obscure Toggle GC Details feature seems unnecessary. We should just show all the details. Change-Id: I9deff8f317c7a97fe01af1547bf022a506c37f80 Reviewed-on: https://go-review.googlesource.com/c/tools/+/639835 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c61a2b0 commit 5fe60fd

File tree

6 files changed

+22
-191
lines changed

6 files changed

+22
-191
lines changed

gopls/doc/settings.md

-19
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,6 @@ These analyses are documented on
315315

316316
Default: `false`.
317317

318-
<a id='annotations'></a>
319-
### `annotations map[enum]bool`
320-
321-
**This setting is experimental and may be deleted.**
322-
323-
annotations specifies the various kinds of compiler
324-
optimization details that should be reported as diagnostics
325-
when enabled for a package by the "Toggle compiler
326-
optimization details" (`gopls.gc_details`) command.
327-
328-
Each enum must be one of:
329-
330-
* `"bounds"` controls bounds checking diagnostics.
331-
* `"escape"` controls diagnostics about escape choices.
332-
* `"inline"` controls diagnostics about inlining choices.
333-
* `"nil"` controls nil checks.
334-
335-
Default: `{"bounds":true,"escape":true,"inline":true,"nil":true}`.
336-
337318
<a id='vulncheck'></a>
338319
### `vulncheck enum`
339320

gopls/internal/doc/api.json

-34
Original file line numberDiff line numberDiff line change
@@ -635,40 +635,6 @@
635635
"Status": "experimental",
636636
"Hierarchy": "ui.diagnostic"
637637
},
638-
{
639-
"Name": "annotations",
640-
"Type": "map[enum]bool",
641-
"Doc": "annotations specifies the various kinds of compiler\noptimization details that should be reported as diagnostics\nwhen enabled for a package by the \"Toggle compiler\noptimization details\" (`gopls.gc_details`) command.\n",
642-
"EnumKeys": {
643-
"ValueType": "bool",
644-
"Keys": [
645-
{
646-
"Name": "\"bounds\"",
647-
"Doc": "`\"bounds\"` controls bounds checking diagnostics.\n",
648-
"Default": "true"
649-
},
650-
{
651-
"Name": "\"escape\"",
652-
"Doc": "`\"escape\"` controls diagnostics about escape choices.\n",
653-
"Default": "true"
654-
},
655-
{
656-
"Name": "\"inline\"",
657-
"Doc": "`\"inline\"` controls diagnostics about inlining choices.\n",
658-
"Default": "true"
659-
},
660-
{
661-
"Name": "\"nil\"",
662-
"Doc": "`\"nil\"` controls nil checks.\n",
663-
"Default": "true"
664-
}
665-
]
666-
},
667-
"EnumValues": null,
668-
"Default": "{\"bounds\":true,\"escape\":true,\"inline\":true,\"nil\":true}",
669-
"Status": "experimental",
670-
"Hierarchy": "ui.diagnostic"
671-
},
672638
{
673639
"Name": "vulncheck",
674640
"Type": "enum",

gopls/internal/golang/compileropt.go

+21-52
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"golang.org/x/tools/gopls/internal/cache"
1717
"golang.org/x/tools/gopls/internal/cache/metadata"
1818
"golang.org/x/tools/gopls/internal/protocol"
19-
"golang.org/x/tools/gopls/internal/settings"
2019
"golang.org/x/tools/internal/event"
2120
)
2221

@@ -69,10 +68,9 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
6968
return nil, err
7069
}
7170
reports := make(map[protocol.DocumentURI][]*cache.Diagnostic)
72-
opts := snapshot.Options()
7371
var parseError error
7472
for _, fn := range files {
75-
uri, diagnostics, err := parseDetailsFile(fn, opts)
73+
uri, diagnostics, err := parseDetailsFile(fn)
7674
if err != nil {
7775
// expect errors for all the files, save 1
7876
parseError = err
@@ -93,7 +91,7 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
9391
}
9492

9593
// parseDetailsFile parses the file written by the Go compiler which contains a JSON-encoded protocol.Diagnostic.
96-
func parseDetailsFile(filename string, options *settings.Options) (protocol.DocumentURI, []*cache.Diagnostic, error) {
94+
func parseDetailsFile(filename string) (protocol.DocumentURI, []*cache.Diagnostic, error) {
9795
buf, err := os.ReadFile(filename)
9896
if err != nil {
9997
return "", nil, err
@@ -124,14 +122,30 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
124122
if err := dec.Decode(d); err != nil {
125123
return "", nil, err
126124
}
125+
if d.Source != "go compiler" {
126+
continue
127+
}
127128
d.Tags = []protocol.DiagnosticTag{} // must be an actual slice
128129
msg := d.Code.(string)
129130
if msg != "" {
131+
// Typical message prefixes gathered by grepping the source of
132+
// cmd/compile for literal arguments in calls to logopt.LogOpt.
133+
// (It is not a well defined set.)
134+
//
135+
// - canInlineFunction
136+
// - cannotInlineCall
137+
// - cannotInlineFunction
138+
// - copy
139+
// - escape
140+
// - escapes
141+
// - isInBounds
142+
// - isSliceInBounds
143+
// - iteration-variable-to-{heap,stack}
144+
// - leak
145+
// - loop-modified-{range,for}
146+
// - nilcheck
130147
msg = fmt.Sprintf("%s(%s)", msg, d.Message)
131148
}
132-
if !showDiagnostic(msg, d.Source, options) {
133-
continue
134-
}
135149

136150
// zeroIndexedRange subtracts 1 from the line and
137151
// range, because the compiler output neglects to
@@ -176,51 +190,6 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
176190
return uri, diagnostics, nil
177191
}
178192

179-
// showDiagnostic reports whether a given diagnostic should be shown to the end
180-
// user, given the current options.
181-
func showDiagnostic(msg, source string, o *settings.Options) bool {
182-
if source != "go compiler" {
183-
return false
184-
}
185-
if o.Annotations == nil {
186-
return true
187-
}
188-
189-
// The strings below were gathered by grepping the source of
190-
// cmd/compile for literal arguments in calls to logopt.LogOpt.
191-
// (It is not a well defined set.)
192-
//
193-
// - canInlineFunction
194-
// - cannotInlineCall
195-
// - cannotInlineFunction
196-
// - escape
197-
// - escapes
198-
// - isInBounds
199-
// - isSliceInBounds
200-
// - leak
201-
// - nilcheck
202-
//
203-
// Additional ones not handled by logic below:
204-
// - copy
205-
// - iteration-variable-to-{heap,stack}
206-
// - loop-modified-{range,for}
207-
208-
switch {
209-
case strings.HasPrefix(msg, "canInline") ||
210-
strings.HasPrefix(msg, "cannotInline") ||
211-
strings.HasPrefix(msg, "inlineCall"):
212-
return o.Annotations[settings.Inline]
213-
case strings.HasPrefix(msg, "escape") || msg == "leak":
214-
return o.Annotations[settings.Escape]
215-
case strings.HasPrefix(msg, "nilcheck"):
216-
return o.Annotations[settings.Nil]
217-
case strings.HasPrefix(msg, "isInBounds") ||
218-
strings.HasPrefix(msg, "isSliceInBounds"):
219-
return o.Annotations[settings.Bounds]
220-
}
221-
return false
222-
}
223-
224193
func findJSONFiles(dir string) ([]string, error) {
225194
ans := []string{}
226195
f := func(path string, fi os.FileInfo, _ error) error {

gopls/internal/settings/default.go

-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ func DefaultOptions(overrides ...func(*Options)) *Options {
8989
},
9090
UIOptions: UIOptions{
9191
DiagnosticOptions: DiagnosticOptions{
92-
Annotations: map[Annotation]bool{
93-
Bounds: true,
94-
Escape: true,
95-
Inline: true,
96-
Nil: true,
97-
},
9892
Vulncheck: ModeVulncheckOff,
9993
DiagnosticsDelay: 1 * time.Second,
10094
DiagnosticsTrigger: DiagnosticsOnEdit,

gopls/internal/settings/settings.go

+1-69
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ import (
1616
"golang.org/x/tools/gopls/internal/util/frob"
1717
)
1818

19-
// An Annotation is a category of Go compiler optimization diagnostic.
20-
//
21-
// TODO(adonovan): this seems like a large control surface. Let's
22-
// remove it, and just show all kinds when the flag is enabled.
23-
type Annotation string
24-
25-
const (
26-
// Nil controls nil checks.
27-
Nil Annotation = "nil"
28-
29-
// Escape controls diagnostics about escape choices.
30-
Escape Annotation = "escape"
31-
32-
// Inline controls diagnostics about inlining choices.
33-
Inline Annotation = "inline"
34-
35-
// Bounds controls bounds checking diagnostics.
36-
Bounds Annotation = "bounds"
37-
)
38-
3919
// Options holds various configuration that affects Gopls execution, organized
4020
// by the nature or origin of the settings.
4121
//
@@ -426,12 +406,6 @@ type DiagnosticOptions struct {
426406
// [Staticcheck's website](https://staticcheck.io/docs/checks/).
427407
Staticcheck bool `status:"experimental"`
428408

429-
// Annotations specifies the various kinds of compiler
430-
// optimization details that should be reported as diagnostics
431-
// when enabled for a package by the "Toggle compiler
432-
// optimization details" (`gopls.gc_details`) command.
433-
Annotations map[Annotation]bool `status:"experimental"`
434-
435409
// Vulncheck enables vulnerability scanning.
436410
Vulncheck VulncheckMode `status:"experimental"`
437411

@@ -1043,7 +1017,7 @@ func (o *Options) setOne(name string, value any) error {
10431017
return setBoolMap(&o.Hints, value)
10441018

10451019
case "annotations":
1046-
return setAnnotationMap(&o.Annotations, value)
1020+
return deprecatedError("the 'annotations' setting was removed in gopls/v0.18.0; all compiler optimization details are now shown")
10471021

10481022
case "vulncheck":
10491023
return setEnum(&o.Vulncheck, value,
@@ -1299,48 +1273,6 @@ func setDuration(dest *time.Duration, value any) error {
12991273
return nil
13001274
}
13011275

1302-
func setAnnotationMap(dest *map[Annotation]bool, value any) error {
1303-
all, err := asBoolMap[string](value)
1304-
if err != nil {
1305-
return err
1306-
}
1307-
if all == nil {
1308-
return nil
1309-
}
1310-
// Default to everything enabled by default.
1311-
m := make(map[Annotation]bool)
1312-
for k, enabled := range all {
1313-
var a Annotation
1314-
if err := setEnum(&a, k,
1315-
Nil,
1316-
Escape,
1317-
Inline,
1318-
Bounds); err != nil {
1319-
// In case of an error, process any legacy values.
1320-
switch k {
1321-
case "noEscape":
1322-
m[Escape] = false
1323-
return fmt.Errorf(`"noEscape" is deprecated, set "Escape: false" instead`)
1324-
case "noNilcheck":
1325-
m[Nil] = false
1326-
return fmt.Errorf(`"noNilcheck" is deprecated, set "Nil: false" instead`)
1327-
1328-
case "noInline":
1329-
m[Inline] = false
1330-
return fmt.Errorf(`"noInline" is deprecated, set "Inline: false" instead`)
1331-
case "noBounds":
1332-
m[Bounds] = false
1333-
return fmt.Errorf(`"noBounds" is deprecated, set "Bounds: false" instead`)
1334-
default:
1335-
return err
1336-
}
1337-
}
1338-
m[a] = enabled
1339-
}
1340-
*dest = m
1341-
return nil
1342-
}
1343-
13441276
func setBoolMap[K ~string](dest *map[K]bool, value any) error {
13451277
m, err := asBoolMap[K](value)
13461278
if err != nil {

gopls/internal/settings/settings_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ func TestOptions_Set(t *testing.T) {
180180
return len(o.DirectoryFilters) == 0
181181
},
182182
},
183-
{
184-
name: "annotations",
185-
value: map[string]any{
186-
"Nil": false,
187-
"noBounds": true,
188-
},
189-
wantError: true,
190-
check: func(o Options) bool {
191-
return !o.Annotations[Nil] && !o.Annotations[Bounds]
192-
},
193-
},
194183
{
195184
name: "vulncheck",
196185
value: []any{"invalid"},

0 commit comments

Comments
 (0)