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/loader: TypeCheckFuncBodies doesn't work with packages specified as files #18288
Comments
Another way to pharse this - I only want to typecheck the packages specified by |
Maybe I meant @adonovan? |
You can't accurately type-check a package without type information for each package that it imports. The gc and gccgo compilers save type information from one package and use it when compiling the next one; this information about package P can be found in a section of the archive library $GOPATH/pkg/$GOOS_GOARCH/${P}.a. This works well for a compiler because the build tool (go build) ensures that dependencies are built in order. However, the loader is not part of a build tool and so cannot assume that the .a files in $GOPATH/pkg are up to date, or exist at all. So, it loads source code for all the packages transitively imported by the initial packages. This is somewhat wasteful, but simple to understand and implement and fast enough in practice for most users, though Go workspaces are getting larger and it may be time to consider making the loader stash type information too. You're right that the TypeCheckFuncBodies hook doesn't work with packages specified as files. That's something to think about as we reconsider the API. |
Thanks for the update. Should this issue remain open about |
Yes, it's a valid bug report, so let's keep it open. |
|
go/loader.Config
has the following:I wrote a linter that needs to typecheck func bodies for the packages/files it is linting. But outside of those packages, doing that work is wasting time. For example, typechecking all of the std dependencies can bump the run time from ~0.3s to ~1.2s when running the linter on a small package.
I've tried getting around it with something like the following:
To clarify, gotool is a clone of Go's unexported code that handles package arguments. This runs fine if using the linter with arguments like
.
,./...
,mypackage
orbytes
.But it breaks if using filenames like
foo.go
, becausepaths
will be[]string{"foo.go"}
. Thepackage
node hasn't been read yet. I assume the call that ultimately reads it isconfig.Load()
- but by then, it's too late to setTypeCheckFuncBodies
.Is there a way to do this? If not, I would suggest the API should allow it somehow.
CC @alandonovan
The text was updated successfully, but these errors were encountered: