Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go list has confusing/inconsistent semantics for Match and DepOnly #60794

Open
aclements opened this issue Jun 14, 2023 · 1 comment
Open
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aclements
Copy link
Member

What version of Go are you using (go version)?

$ go version
go version go1.20.5 linux/amd64

(Also reproduced at HEAD.)

Does this issue reproduce with the latest release?

Yes.

What did you do?

$ cd $GOROOT/src
$ go list -deps -test -f '{{.ImportPath}} {{.DepOnly}} {{.Match}}' ./... | grep 'context\.test'
context [context.test] false [./...]
runtime/trace [context.test] true [./...]
testing [context.test] true [./...]
os/exec [context.test] true [./...]
internal/fuzz [context.test] true [./...]
os/signal [context.test] true [./...]
runtime/pprof [context.test] true [./...]
testing/internal/testdeps [context.test] true [./...]
net [context.test] true [./...]
context_test [context.test] false []
context.test false []

What did you expect to see?

The documentation for DepOnly and Match is:

        Match          []string // command-line patterns matching this package
        DepOnly        bool     // package is only a dependency, not explicitly listed

It's not clear whether packages built on behalf of tests "match" the pattern, but the output seems clearly inconsistent in some ways:

  1. Given that context.test has DepOnly == false, that implies cmd/go does think of context.test as "explicitly listed" by ./.... It also clearly thinks of, say, net as "explicitly listed" by ./.... So it seems odd that net [context.test] (and several others) have DepOnly == true, indicating that they're not "explicitly listed".
  2. Based on the documentation, I would expect that, if DepOnly == true, then it's "not explicitly listed", so Match should be empty because it didn't match any patterns. And if DepOnly == false, then it is "explicitly listed", and Match should list at least one pattern. For example, context.test is "explicitly listed", yet cmd/go can't tell me what pattern it matched.

What did you see instead?

DepOnly is true for some of these and false for others in ways I can't rationalize.

For some packages, DepOnly == true, but a Match pattern is also listed.

For some packages, DepOnly == false, but a Match pattern is listed.

@aclements aclements added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 14, 2023
@bcmills bcmills added the GoCommand cmd/go label Jun 14, 2023
@bcmills
Copy link
Contributor

bcmills commented Jun 14, 2023

(CC @matloob)

@bcmills bcmills added this to the Backlog milestone Jun 14, 2023
aclements added a commit to rsc/rf that referenced this issue Jun 30, 2023
rf only modifies files in the current module, but it has to load
imported modules for type checking, so it records on every package
whether it's in the current module or not. However, currently, it uses
the DepOnly field from "go list" to determine this. It's true that if
.DepOnly is false, then it's in the current module, but there are
various conditions under which .DepOnly is true and the package is
still in the current module (these conditions may not always be right,
but they're complicated regardless; see golang/go#60794).

Inside of using .DepOnly, use .Module.Version, which is nil for
anything in the current workspace, and thus much more closely matches
the semantics of "can we edit this?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants