StaticCallee reports the destination of a CallExpr, if it is a static
call to a Go function or method.
StaticCallee is not a complicated function, but I wrote it four times
during the course of prototyping the analysis API in
go-review.googlesource.com/c/tools/+/134935.
Change-Id: Icd26fc1e5f6ed9edebd4d0a00fdf18aa0acb074c
Reviewed-on: https://go-review.googlesource.com/135676
Reviewed-by: Robert Griesemer <gri@golang.org>
For some reason, the type of the last Param in a wrapper function
for a variadic method (T) f(...U) had type [][]U instead of []U.
(Possibly a workaround for a long-since fixed bug in go/types?)
Added a sanity check to ensure that the common suffix of
fn.Params and fn.Signature.Params match in type.
Fixesgolang/go#27453
Change-Id: I9506f4f67a7ff3a283e9ec0142f638aad00287a9
Reviewed-on: https://go-review.googlesource.com/134515
Reviewed-by: Robert Griesemer <gri@golang.org>
Go 1.11 has been released; it's time to update zstdlib so
imports knows about API additions that went into Go 1.11.
Unfortunately, this does not include the syscall/js package
that was added in Go 1.11 for WebAssembly. This is because
it's not included in the GOROOT/api/go1.11.txt file. Getting
it into imports can/will be done in a future CL (after some
discussion of the best way to do it).
Previously:
- https://golang.org/cl/93195 (Go 1.10)
- https://golang.org/cl/49150 (Go 1.9)
Updates golang/go#27590.
Change-Id: I229d7c0a658b0d8090b58cfe844c95b4cb0b2212
Reviewed-on: https://go-review.googlesource.com/134176
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This reformats the table using the new gofmt rules in Go 1.11. No
changes apart from the whitespace change.
Change-Id: I74a1d9c14ec7a4f691e78cc7ffa443da68fb8681
Reviewed-on: https://go-review.googlesource.com/132395
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Errors relating to a particular package (as opposed to the Load
operation as a whole) are now only recorded in the Errors
field of the corresponding Package.
Clients are responsible for printing or otherwise handling errors.
This is a breaking API change.
The PrintErrors function prints all accumulated errors,
dependencies first, and is provided for convenience.
PrintErrors is based on Visit, another helper function, which
visits each Package in an import graph.
Also:
- add an Example documenting typical use.
- update clients to handle errors explicitly.
Depends on https://go-review.googlesource.com/c/tools/+/130576
Change-Id: I39407ab7f46dae2f0dd0fdde21080e172e1258aa
Reviewed-on: https://go-review.googlesource.com/131015
Reviewed-by: Michael Matloob <matloob@golang.org>
This change fixes a bug that occured in the golist fallback logic when
an x_test package imported its own package under test. For a package
"a", if "a_test" imported "a", we'd populate "a_test"'s import map
with an entry "a [a.test]" pointing to the test variant of the package
with id "a [a.test]". This change fixes the key to be "a", the correct
import path of the package, not "a [a.test], which is the ID".
Change-Id: If798f2675b01aa537c6ccc129dc35d042d967337
Reviewed-on: https://go-review.googlesource.com/133356
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Rather than document the range of possible error types, requiring
clumsy client code to extract position information, we now expose a
single concrete type for all errors. Position information (in
standardized string form) is technically optional, but we should
strive for 100%, fixing gaps as they arise.
This change enables us to unify the Package and JSON structs in a
follow-up.
Question: should we eliminate the Config.Error hook and be silent by default?
Pro:
+ most clients suppress it.
Con:
- clients that want to print errors (e.g. vet-like tools) would have
to traverse the entire import graph to find them.
- silence is not the most fail-safe behavior.
Change-Id: Ie92b9fb7641ceda429f00928474b650d1dfadedd
Reviewed-on: https://go-review.googlesource.com/130576
Reviewed-by: Michael Matloob <matloob@golang.org>
See comment in the patch for an explanation, Firefox (specifically
with the Menlo font) does not like tabs beginning in column 9, so we
start it in column 10.
Updates webcompat/web-bugs#17530Fixesgolang/go#26316Fixesgolang/go#23500
Change-Id: I4c96118b8c3b13ee1fd21ce85bd7c681e99a4b4f
Reviewed-on: https://go-review.googlesource.com/131716
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
1.8 is no longer supported. Remove code that placates it.
Also removes a superfluous newline in appinit.go.
Change-Id: I9c89b5bddf4c001d0854404114fb354209ad6024
Reviewed-on: https://go-review.googlesource.com/131715
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
GOROOT is not a function, so use "is" instead of "returns".
This was originally raised during review of golang.org/cl/131315.
Also add a missing period.
Change-Id: Ie28d38529889702ae5035d0f48d8122b6bee6819
Reviewed-on: https://go-review.googlesource.com/131316
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This is a fixup for golang.org/cl/130796.
Change-Id: If151325738b59ab61a7b456a140d3bc8dff57b9c
Reviewed-on: https://go-review.googlesource.com/131315
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This makes Load use the value of GOPACKAGESDRIVER in the current
process's environment if the loader's environment wasn't explicitly
set.
Note that if GOPACKAGESDRIVER is not set, we'll still search PATH in
the current process, regardless of whether PATH is set in the loader's
environment. This has not changed.
Change-Id: I3081a6cb0876a21ccd4d87b4b8d082aa47911b75
Reviewed-on: https://go-review.googlesource.com/131016
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
The interpreter has no intrinsic for reflect.Value.MapRange,
so it no longer supports fmt.Sprint on a map, which uses it.
Suppressing part of complit.go test for now.
Change-Id: Id6ade19bdbb92593d6da57c82e75f311fb65b4fe
Reviewed-on: https://go-review.googlesource.com/131075
Reviewed-by: Robert Griesemer <gri@golang.org>
The logic to determine whether a filesystem root was in GOROOT or GOPATH
still relied on runtime.GOROOT(), whereas cmd/godoc was updated to copy
the goroot finding logic from standard library.
Hence, godoc is unable to determine if a filesystem is in GOROOT or not
when the binary is outside runtime.GOROOT(). So we expose a new variable
and set that from cmd/godoc to avoid copying the logic again for the 3rd time.
Fixesgolang/go#27162
Change-Id: I160dcdbdd262e671f09f7bf01c329be5eac280ad
Reviewed-on: https://go-review.googlesource.com/130796
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Visit packages in deterministic order for predictable JSON.
(I don't know why the test only appears to fail on darwin;
I would expect it to randomly fail in linux 50% of the time.)
Change-Id: I5270804077fc9ca8f529a1f4657e1c35f0586579
Reviewed-on: https://go-review.googlesource.com/130755
Reviewed-by: Michael Matloob <matloob@golang.org>
This change adds the -buildflag argument to go/packages/gopackages,
which may be passed repeatedly to set config.BuildFlags. I felt -flag
was too vague.
config.Flags is renamed to config.BuildFlags for consistency, and
packages.findExternalDriver now passes -buildflag instead of -flag to
drivers. This will break existing drivers.
Change-Id: Iaed58026373a46e137a236ee9a652eb3a9433ee3
Reviewed-on: https://go-review.googlesource.com/130136
Reviewed-by: Alan Donovan <adonovan@google.com>
The legacy implementation currently always loads from source code, so
packages are more complete than expected.
Change-Id: Ib8c9f7ac590038108dba05c1f47d22e70734945c
Reviewed-on: https://go-review.googlesource.com/130095
Reviewed-by: Michael Matloob <matloob@golang.org>
Also switch usage printing to using stderr always, as is common for Go
tools.
Change-Id: I240da4344fe6b51a418c0d4b0b7d7e7d5614c1d7
Reviewed-on: https://go-review.googlesource.com/129776
Reviewed-by: Alan Donovan <adonovan@google.com>
In ModeTypes, we only need the roots, in ModeSyntax we need the direct
dependancies.
We now do exactly what we need rather than the entire set of transitive
dependancies.
Without this change tools operating on source of a deep dependancy tree are far
to slow.
Change-Id: I3ddbe660709184758ad33ab7cdea860244433ce6
Reviewed-on: https://go-review.googlesource.com/129355
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This saves 35% of wall time in a command such as
$ gopackages -mode=syntax golang.org/x/tools/go/packages/gopackages fmt
that would otherwise typecheck every function in each package that
depends on fmt. It also applies in -mode=types when source was loaded
as a fall back for missing export data due to an error in a lower package.
Also, remove Config.TypeChecker field now that not a single of its
subfields is passed through go/packages to the type checker.
(The Sizes function is logically a result, not an input, of loading,
though we have yet to implement it properly.)
Change-Id: I472d21b34fc5e2832f7353e82992a67a06e4e4cc
Reviewed-on: https://go-review.googlesource.com/129497
Reviewed-by: Ian Cottrell <iancottrell@google.com>
The default timeout for urlfetch requests on App Engine Classic is
5 seconds. Sometimes the requests can take longer, so increase it to
the maximum value of 60 seconds. The playground has its own timeout for
running code so there's no need to impose a second level of protection.
Also cleans up the code to remove old appenginevm code and use the
correct imports.
Change-Id: I15da96e5ba70fb008bf821f4609f431847662223
Reviewed-on: https://go-review.googlesource.com/129395
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
We were calling types.Type.Underlying() too early, which caused CanPoint
to see an ordinary struct, not reflect.Value.
Change-Id: I23ba3b9451bc1abc1ad8a45c790d2e22c1481f26
Reviewed-on: https://go-review.googlesource.com/129196
Run-TryBot: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
go1.10 and earlier versions of go list do not report test main packages.
Furthermore, go/packages has errors in its Imports under go1.10.
The long-term fix is for go/packages to synthesize test main packages
when working with older versions of the go command, but in the
meantime we will disable the tests.
Updates golang/go#11811
Change-Id: Ifd5e37d5b68a01134e911fda90e30a39fc25b88d
Reviewed-on: https://go-review.googlesource.com/129175
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Go 1.11 changed the behavior of line directives, so reflect that in the
golden files for tests.
Change-Id: I7df282dfbeb3bfc5d75481c345acf724bb0b25bf
Reviewed-on: https://go-review.googlesource.com/128999
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Unlike go/loader's FromArgs, go/packages doesn't return the
non-package arguments, so we add a new repeated flag -arg=x -arg=y to
specify them.
Because we cannot add packages to a packages.Load query, we emit an
error if -run is specified and "runtime" is not among the
dependencies.
There is no easy way to distinguish synthetic test main packages
from regular main packages, so we no longer try.
This makes -test and -run orthogonal.
Change-Id: Ibd69b993c05de62df01dde52218a9e266cd63a71
Reviewed-on: https://go-review.googlesource.com/128837
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TestFixImports did not have to explicitly add "strings" to the
simplePkgs map - this only happened because sibling files were searched
and the strings import was found through them. If we stub out the
dirPackageInfo function, we have to explicitly add the strings import.
Change-Id: I149e522fad37039fc790e6a855834d86ff050674
Reviewed-on: https://go-review.googlesource.com/129036
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This is fixes for review comments made on cl/128120
Change-Id: Ie6382d6ec91db2bbdece564a83ae028be4e2e269
Reviewed-on: https://go-review.googlesource.com/129000
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
For any identity imports to be added to the import map of a package,
make sure these are not already in there. If the package imports "C",
be sure not to overwrite the import map entries for "runtime/cgo", "unsafe",
and "syscall".
Test the import map when test variants are loaded. This tests the fix
in 'go list' made by https://golang.org/cl/128836Fixesgolang/go#26847
Change-Id: I05dff4d3a75fab03f333f6d88128de6a6bf169e6
Reviewed-on: https://go-review.googlesource.com/128876
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Copy imports.VendorlessPath into go/packages to avoid an unnecessary
dependency on imports.
Change-Id: Ie77c2fb87f2199f139ece9f3d1b707f065fc1a79
Reviewed-on: https://go-review.googlesource.com/128996
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This deletes the raw and golist packatges, instead using the main
Package structure as the serialzied form between the build tool and the
loader.
This requires a few new fields on Package for information that we used
to hide, and some extra json tags on Package.
It also required Package to have custom JSON marshalling methods.
Change-Id: Ib72171bc93e2b494b97f4b0266504acaa9b3f647
Reviewed-on: https://go-review.googlesource.com/128120
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
If GOROOT is unset (as is common now),
then the output of "go env GOROOT" may
differ from the GOROOT inferred by alternate
compilers being executed and also from the
value of runtime.GOROOT() inside compilebench,
used by go/build. Harmonize all of these by
setting GOROOT explicitly (will fix subcommands)
and by invoking the go command to learn about
packages instead of assuming go/build has any
idea what it's doing.
Change-Id: If97aa76cc2afec11a8404975f39329db7eb452e0
Reviewed-on: https://go-review.googlesource.com/109516
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This change addresses some style issues pointed out by rsc in
golang.org/cl/126177. It doesn't fix the comment on listfunc
or the comment on the processing of the containing directories.
Those will be handled in a separate cl.
Change-Id: I2094ad1e5e2ee181a646466675f4d993bd69ff9b
Reviewed-on: https://go-review.googlesource.com/128897
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This change addresses adonovan's comments in golang.org/cl/125939.
Make sure to include CXXFiles, MFiles, HFiles, FFiles, SwigFiles,
SwigCXXFiles, and SysoFiles from the go list output into the Package
struct's OtherFiles field.
When computing packages from the output of fallback golist,
make sure to create the test variant of a package whenever creating
an x_test for a package because the x_test always depends on
the test variant even when there are no non-x_test files.
Sort dependency packages from the fallback golist to ensure
output is deterministic.
Change-Id: I3a942898c7edbe0ad62dbdf3d521775ffd9b9594
Reviewed-on: https://go-review.googlesource.com/128838
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Also:
- make a nil *Config equivalent to new(Config).
- add a test for nil *Config.
- document that Load may return an empty list of packages.
Change-Id: I642133abe18553ca8c7f46b7bd2709a03eda0b28
Reviewed-on: https://go-review.googlesource.com/128875
Reviewed-by: Michael Matloob <matloob@golang.org>
Use export data in LoadTypes mode, when it is available to get the type information.
The lock can be moved back to loadFromExportData, as each package is
loaded in topological order, and all calls to loadFromExportData for a
particular package occur when that package is being loaded.
Fixesgolang/go#26834
Change-Id: Ib6c28eb8642a473cc100d54d0aac7b90644d5d22
Reviewed-on: https://go-review.googlesource.com/128365
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Because go/packages presents each synthesized test main package
as a first-class package, the tests now analyze all of the dependencies
of "testing", which they previously avoided. This makes the tests
slower and the resulting call graph much larger,
so they now look for a subset match, not an exact match,
on the set of graph edges.
Change-Id: I9d7acf420e41cbffc03ca8423f5afb3ef671d775
Reviewed-on: https://go-review.googlesource.com/128695
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Gerrit's rendering is cleaner and Gerrit is the source of truth anyway.
Fixesgolang/go#26871.
Change-Id: I0bf69d174662c7acc083b03b009bac92f781a17c
Reviewed-on: https://go-review.googlesource.com/128596
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Adds ssautil.Packages function, which creates ssa.Packages
from packages.Packages.
Deprecates testmain synthesis logic now that go/packages
reports the test packages synthesized by the build system
as first-class packages.
Updates docs, examples, and tests.
Flags potential confusion around legacy concept of "importable" packages.
Change-Id: I6d9cd7c6436c715d1ef39e3e280f4af4d48ccc5a
Reviewed-on: https://go-review.googlesource.com/128675
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Also collect errors so we can set them on the Package (once
golang.org/cl/128120 is in).
Change-Id: I2950405404f060312813e4aa27393496078a3b7e
Reviewed-on: https://go-review.googlesource.com/128357
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>