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

x/tools/go/packages/gopackages: better documentation of -mode flag #60995

Closed
ghost opened this issue Jun 25, 2023 · 4 comments
Closed

x/tools/go/packages/gopackages: better documentation of -mode flag #60995

ghost opened this issue Jun 25, 2023 · 4 comments
Assignees
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ghost
Copy link

ghost commented Jun 25, 2023

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

go version go1.20 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Steven\AppData\Local\go-build
set GOENV=C:\Users\Steven\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Steven\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Steven\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Windows\TEMP\go-build2434007380=/tmp/go-build -gno-record-gcc-switches

What did you do?

using this input:

package tls

type dsaSignature struct { }

type lruSessionCache struct {}

func NewLRUClientSessionCache() lruSessionCache {
	return lruSessionCache{}
}

What did you see instead?

I get this result:

> gopackages -mode types -private tls
Go package "tls":
        package tls
        has complete exported type info
        file D:\Desktop\etc\common.go
        func NewLRUClientSessionCache() lruSessionCache
        type lruSessionCache struct{}

one type is listed, but the other is not.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jun 25, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 25, 2023
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 26, 2023
@cagedmantis
Copy link
Contributor

/cc @golang/tools-team

@adonovan
Copy link
Member

When you specify -mode=types, you're requesting (only) complete type information for the package's exported API. This includes exported declarations such as NewLRUClientSessionCache, but it additionally includes named types referenced by them (even if unexported), such as lruSessionCache, plus all of their methods, and any types required by them, and so on. But it does not include types that are unreachable from the public API. (This information can be efficiently obtained from the cached output of the compiler.)

If you want the types for all declarations, you'll need -mode=syntax, which loads the package from syntax and type-checks the whole thing, including the internals. This is a more expensive operation. (More expensive than you need, because it type-checks function bodies, which are by far the majority of the syntax yet are irrelevant to you. There is a way to suppress that (IgnoreFuncBodies in https://pkg.go.dev/go/types#Config), but not from the command-line interface of gopackages.)

I agree this could be better documented, but I think the tool is working as intended.

@adonovan adonovan changed the title x/tools/go/packages/gopackages: some private items missing x/tools/go/packages/gopackages: better documentation of -mode flag Jun 26, 2023
@ghost
Copy link
Author

ghost commented Jun 26, 2023

ah OK yes that works, thanks - I will leave this open since it seems the documentation part is still a valid concern

@adonovan adonovan self-assigned this Jun 27, 2023
@gopherbot
Copy link

Change https://go.dev/cl/506357 mentions this issue: go/packages/gopackages: document -mode flag

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants