Skip to content

Commit 3c8e5b1

Browse files
aclementsgopherbot
authored andcommitted
cmd/go/internal/cacheprog: drop redundant Prog prefixes
Now that these types are in their own package, drop the unnecessary Prog prefixes from everything. Updates #71032 Updates #59719 Change-Id: Id54edf0473754e3b21a71beb72803fb5481206c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/638996 Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Austin Clements <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 20da34c commit 3c8e5b1

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

src/cmd/go/internal/cache/prog.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ProgCache struct {
3939

4040
// can are the commands that the child process declared that it supports.
4141
// This is effectively the versioning mechanism.
42-
can map[cacheprog.ProgCmd]bool
42+
can map[cacheprog.Cmd]bool
4343

4444
// fuzzDirCache is another Cache implementation to use for the FuzzDir
4545
// method. In practice this is the default GOCACHE disk-based
@@ -56,7 +56,7 @@ type ProgCache struct {
5656

5757
mu sync.Mutex // guards following fields
5858
nextID int64
59-
inFlight map[int64]chan<- *cacheprog.ProgResponse
59+
inFlight map[int64]chan<- *cacheprog.Response
6060
outputFile map[OutputID]string // object => abs path on disk
6161

6262
// writeMu serializes writing to the child process.
@@ -111,14 +111,14 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
111111
stdout: out,
112112
stdin: in,
113113
bw: bufio.NewWriter(in),
114-
inFlight: make(map[int64]chan<- *cacheprog.ProgResponse),
114+
inFlight: make(map[int64]chan<- *cacheprog.Response),
115115
outputFile: make(map[OutputID]string),
116116
readLoopDone: make(chan struct{}),
117117
}
118118

119119
// Register our interest in the initial protocol message from the child to
120120
// us, saying what it can do.
121-
capResc := make(chan *cacheprog.ProgResponse, 1)
121+
capResc := make(chan *cacheprog.Response, 1)
122122
pc.inFlight[0] = capResc
123123

124124
pc.jenc = json.NewEncoder(pc.bw)
@@ -133,7 +133,7 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
133133
case <-timer.C:
134134
log.Printf("# still waiting for GOCACHEPROG %v ...", prog)
135135
case capRes := <-capResc:
136-
can := map[cacheprog.ProgCmd]bool{}
136+
can := map[cacheprog.Cmd]bool{}
137137
for _, cmd := range capRes.KnownCommands {
138138
can[cmd] = true
139139
}
@@ -150,7 +150,7 @@ func (c *ProgCache) readLoop(readLoopDone chan<- struct{}) {
150150
defer close(readLoopDone)
151151
jd := json.NewDecoder(c.stdout)
152152
for {
153-
res := new(cacheprog.ProgResponse)
153+
res := new(cacheprog.Response)
154154
if err := jd.Decode(res); err != nil {
155155
if c.closing.Load() {
156156
return // quietly
@@ -175,8 +175,8 @@ func (c *ProgCache) readLoop(readLoopDone chan<- struct{}) {
175175
}
176176
}
177177

178-
func (c *ProgCache) send(ctx context.Context, req *cacheprog.ProgRequest) (*cacheprog.ProgResponse, error) {
179-
resc := make(chan *cacheprog.ProgResponse, 1)
178+
func (c *ProgCache) send(ctx context.Context, req *cacheprog.Request) (*cacheprog.Response, error) {
179+
resc := make(chan *cacheprog.Response, 1)
180180
if err := c.writeToChild(req, resc); err != nil {
181181
return nil, err
182182
}
@@ -191,7 +191,7 @@ func (c *ProgCache) send(ctx context.Context, req *cacheprog.ProgRequest) (*cach
191191
}
192192
}
193193

194-
func (c *ProgCache) writeToChild(req *cacheprog.ProgRequest, resc chan<- *cacheprog.ProgResponse) (err error) {
194+
func (c *ProgCache) writeToChild(req *cacheprog.Request, resc chan<- *cacheprog.Response) (err error) {
195195
c.mu.Lock()
196196
c.nextID++
197197
req.ID = c.nextID
@@ -252,7 +252,7 @@ func (c *ProgCache) Get(a ActionID) (Entry, error) {
252252
// error types on the Cache interface.
253253
return Entry{}, &entryNotFoundError{}
254254
}
255-
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
255+
res, err := c.send(c.ctx, &cacheprog.Request{
256256
Command: cacheprog.CmdGet,
257257
ActionID: a[:],
258258
})
@@ -321,7 +321,7 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
321321
deprecatedValue = out[:]
322322
}
323323

324-
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
324+
res, err := c.send(c.ctx, &cacheprog.Request{
325325
Command: cacheprog.CmdPut,
326326
ActionID: a[:],
327327
OutputID: out[:],
@@ -347,7 +347,7 @@ func (c *ProgCache) Close() error {
347347
// and clean up if it wants. Only after that exchange do we cancel
348348
// the context that kills the process.
349349
if c.can[cacheprog.CmdClose] {
350-
_, err = c.send(c.ctx, &cacheprog.ProgRequest{Command: cacheprog.CmdClose})
350+
_, err = c.send(c.ctx, &cacheprog.Request{Command: cacheprog.CmdClose})
351351
}
352352
// Cancel the context, which will close the helper's stdin.
353353
c.ctxCancel()

src/cmd/go/internal/cacheprog/cacheprog.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,64 @@
1313
// with it via JSON messages over stdin/stdout. The subprocess's stderr will be
1414
// connected to the go command's stderr.
1515
//
16-
// The subprocess should immediately send a [ProgResponse] with its capabilities.
17-
// After that, the go command will send a stream of [ProgRequest] messages and the
18-
// subprocess should reply to each [ProgRequest] with a [ProgResponse] message.
16+
// The subprocess should immediately send a [Response] with its capabilities.
17+
// After that, the go command will send a stream of [Request] messages and the
18+
// subprocess should reply to each [Request] with a [Response] message.
1919
package cacheprog
2020

2121
import (
2222
"io"
2323
"time"
2424
)
2525

26-
// ProgCmd is a command that can be issued to a child process.
26+
// Cmd is a command that can be issued to a child process.
2727
//
2828
// If the interface needs to grow, the go command can add new commands or new
29-
// versioned commands like "get2" in the future. The initial [ProgResponse] from
29+
// versioned commands like "get2" in the future. The initial [Response] from
3030
// the child process indicates which commands it supports.
31-
type ProgCmd string
31+
type Cmd string
3232

3333
const (
3434
// CmdPut tells the cache program to store an object in the cache.
3535
//
36-
// [ProgRequest.ActionID] is the cache key of this object. The cache should
37-
// store [ProgRequest.OutputID] and [ProgRequest.Body] under this key for a
36+
// [Request.ActionID] is the cache key of this object. The cache should
37+
// store [Request.OutputID] and [Request.Body] under this key for a
3838
// later "get" request. It must also store the Body in a file in the local
39-
// file system and return the path to that file in [ProgResponse.DiskPath],
39+
// file system and return the path to that file in [Response.DiskPath],
4040
// which must exist at least until a "close" request.
41-
CmdPut = ProgCmd("put")
41+
CmdPut = Cmd("put")
4242

4343
// CmdGet tells the cache program to retrieve an object from the cache.
4444
//
45-
// [ProgRequest.ActionID] specifies the key of the object to get. If the
46-
// cache does not contain this object, it should set [ProgResponse.Miss] to
47-
// true. Otherwise, it should populate the fields of [ProgResponse],
48-
// including setting [ProgResponse.OutputID] to the OutputID of the original
49-
// "put" request and [ProgResponse.DiskPath] to the path of a local file
45+
// [Request.ActionID] specifies the key of the object to get. If the
46+
// cache does not contain this object, it should set [Response.Miss] to
47+
// true. Otherwise, it should populate the fields of [Response],
48+
// including setting [Response.OutputID] to the OutputID of the original
49+
// "put" request and [Response.DiskPath] to the path of a local file
5050
// containing the Body of the original "put" request. That file must
5151
// continue to exist at least until a "close" request.
52-
CmdGet = ProgCmd("get")
52+
CmdGet = Cmd("get")
5353

5454
// CmdClose requests that the cache program exit gracefully.
5555
//
5656
// The cache program should reply to this request and then exit
5757
// (thus closing its stdout).
58-
CmdClose = ProgCmd("close")
58+
CmdClose = Cmd("close")
5959
)
6060

61-
// ProgRequest is the JSON-encoded message that's sent from the go command to
61+
// Request is the JSON-encoded message that's sent from the go command to
6262
// the GOCACHEPROG child process over stdin. Each JSON object is on its own
6363
// line. A ProgRequest of Type "put" with BodySize > 0 will be followed by a
6464
// line containing a base64-encoded JSON string literal of the body.
65-
type ProgRequest struct {
65+
type Request struct {
6666
// ID is a unique number per process across all requests.
67-
// It must be echoed in the ProgResponse from the child.
67+
// It must be echoed in the Response from the child.
6868
ID int64
6969

7070
// Command is the type of request.
7171
// The go command will only send commands that were declared
7272
// as supported by the child.
73-
Command ProgCmd
73+
Command Cmd
7474

7575
// ActionID is the cache key for "put" and "get" requests.
7676
ActionID []byte `json:",omitempty"` // or nil if not used
@@ -85,7 +85,7 @@ type ProgRequest struct {
8585
// as a base64-encoded JSON string when BodySize is non-zero.
8686
// It's sent as a separate JSON value instead of being a struct field
8787
// send in this JSON object so large values can be streamed in both directions.
88-
// The base64 string body of a ProgRequest will always be written
88+
// The base64 string body of a Request will always be written
8989
// immediately after the JSON object and a newline.
9090
Body io.Reader `json:"-"`
9191

@@ -101,26 +101,26 @@ type ProgRequest struct {
101101
ObjectID []byte `json:",omitempty"`
102102
}
103103

104-
// ProgResponse is the JSON response from the child process to the go command.
104+
// Response is the JSON response from the child process to the go command.
105105
//
106106
// With the exception of the first protocol message that the child writes to its
107107
// stdout with ID==0 and KnownCommands populated, these are only sent in
108-
// response to a ProgRequest from the go command.
108+
// response to a Request from the go command.
109109
//
110-
// ProgResponses can be sent in any order. The ID must match the request they're
110+
// Responses can be sent in any order. The ID must match the request they're
111111
// replying to.
112-
type ProgResponse struct {
113-
ID int64 // that corresponds to ProgRequest; they can be answered out of order
112+
type Response struct {
113+
ID int64 // that corresponds to Request; they can be answered out of order
114114
Err string `json:",omitempty"` // if non-empty, the error
115115

116116
// KnownCommands is included in the first message that cache helper program
117117
// writes to stdout on startup (with ID==0). It includes the
118-
// ProgRequest.Command types that are supported by the program.
118+
// Request.Command types that are supported by the program.
119119
//
120120
// This lets the go command extend the protocol gracefully over time (adding
121121
// "get2", etc), or fail gracefully when needed. It also lets the go command
122122
// verify the program wants to be a cache helper.
123-
KnownCommands []ProgCmd `json:",omitempty"`
123+
KnownCommands []Cmd `json:",omitempty"`
124124

125125
// For "get" requests.
126126

0 commit comments

Comments
 (0)