golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.01k stars 17.54k forks source link

x/tools/cmd/guru: limit 'referrers' query to scope? #14747

Closed dominikh closed 1 week ago

dominikh commented 8 years ago

Currently, the 'referrers' query checks all packages in GOROOT and GOPATH. Should it optionally be possible to limit it with the -scope flag?

/cc @alandonovan

alandonovan commented 8 years ago

I thought about this and ultimately decided no. The problem is that there are conceptually two different scopes that users care about; call them the "type checking scope" and the "pointer analysis scope".

Most users want the type checking scope, as used by "referrers" and "implements" queries, to be global, since it is relatively quick to find the set of packages that might need to be type checked, and both type checking and result reporting can occur in streaming fashion (although they don't yet). But no user wants the pointer analysis scope to be global because it would make callers/callees/peers queries intolerably slow.

Some users, those with very large workspaces, might want the type checking scope to be less than global, perhaps the same as the pointer analysis scope, or perhaps some independent larger set of packages, but the idea of having not one but two scope parameters in the user interface seemed terribly confusing to me. (One is already too many.) I hope that we can make the referrers and implements queries both fast and streaming, so even users with large workspaces will find them acceptable---even if they sometimes interrupt the tool before it has finishing printing all references to, say, fmt.Println.

dominikh commented 8 years ago

The primary reason I filed this issue wasn't because of performance reasons, but noise. I was interested in referrers, but only in a subset of my workspace. Instead, I got a very long list of uses I wasn't interested in. I'm not sure if this is an issue that should be addressed in guru, or the editor. Doing path-based filtering in the editor might be a close enough approximation to what I want.

adonovan commented 8 years ago

I agree that whatever we do for implements we should also do for referrers.

dominikh commented 8 years ago

Another data point: I have a Go corpus of about 250,000 packages that makes up a single GOPATH. I use that corpus for various analyses. Using referrers anywhere in there, however, is pointless right now. Even with streaming output, I'd want to restrict it to specific packages, and I feel that a -scope flag would be a much more straightforward solution than having to construct a temporary GOPATH with symlinks.

keegancsmith commented 8 years ago

-scope packages comma-separated list of packages the analysis should be limited to

I was surprised that -scope doesn't limit the inspected packages in general. The way I interpret the usage string quoted above is it won't read any other files outside of those packages.

Edit: I see in https://github.com/golang/go/issues/14748 you have pretty heavily debated this aspect already. Just take my comment as another data point I suppose.

athom commented 7 years ago

+1, guru referrers is really too slow, making this feature almost useless. and the -scope make me confusing, seems it can not limit the search scope when guru referrers.
As an end user, I would like to use the_silver_searcher or ack rather than guru referrers, although ag or ack is not accurate enough, at least the speed is acceptable.

dc0d commented 6 years ago

Same issue here; guru referrers would be a nice tool for developing other tools. When working in the scope of a certain package, we really are not interested in the whole giant tree under $GOPATH/src (and the one under $GOROOT). This default behavior could be customized using a flag (or the explained one could be activated by a new flag or even by making -scope work as one would expect).

burke commented 6 years ago

Just another data point here: my GOPATH is about 50GB of source (the vast majority of which is not Go) and referrers takes about 30 seconds.

adonovan commented 1 week ago

guru was deleted in https://github.com/golang/go/issues/65880; closing as obsolete. Incidentally, gopls uses the workspace as its scope.