I got tired of spurious 'git' diffs while a 'go test' was running, so
I fixed the test that produced the diffs. (We need to do that anyway
in order to run them in the module cache, plus it's just good hygiene
not to have tests interfering with each other's sources.)
Tested using:
$ chmod -R ugo-w . && go test ./...; chmod -R u+w .
Updates golang/go#28387
Change-Id: Ie17e31aecf0e3cb022df5503d7c443000366a5c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192577
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Some tests were split off for Go 1.9, when we still supported Go 1.8.
This change recombines them and removes the special handling for 1.9.
Fixesgolang/go#24421
Change-Id: Ic871f4c3af4bb90b00cdd6d7b8f3253783554535
Reviewed-on: https://go-review.googlesource.com/c/161000
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Since *ast.CommClause implements ast.Stmt, type switch for
it would never execute in the original code, it will always
execute ast.Stmt branch.
Moving concrete types before interfaces help in this case.
Change-Id: Id84f2f7f3fac859029155d8e6debf4a8ef170b26
Reviewed-on: https://go-review.googlesource.com/c/153397
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Add typepos field to json output of describe command. This field shows where
type of current (under cursor) identifier is defined. This will help code editors
implement command 'Go to type definition'.
Implements [#27308](https://github.com/golang/go/issues/27308)
Change-Id: I4e02ddbdc03fecec98135b8996f9562a88a9cfb8
GitHub-Last-Rev: be47e397a293a96d3d39776d6090d861e7904a24
GitHub-Pull-Request: golang/tools#50
Reviewed-on: https://go-review.googlesource.com/c/140379
Reviewed-by: Alan Donovan <adonovan@google.com>
The several functions not exported, Use "The xxx function ..." rule.
Change-Id: Iaba2490b4a9675213f70d055bd9ded9e5a245aa5
Reviewed-on: https://go-review.googlesource.com/c/47872
Reviewed-by: Alan Donovan <adonovan@google.com>
Some users may set GO111MODULE=on, and we will eventually want to be able to
build x/tools itself in module mode.
Updates golang/go#27858
Updates golang/go#27852
Change-Id: Iaf488b2a89e6526471530245cb580f1f0391a770
Reviewed-on: https://go-review.googlesource.com/137815
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@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>
The gccgo compiler does not provide a gc-style GOROOT with standard
library sources. The effect is that guru may not fully work when using
gccgo. However, it can fully work if the GOROOT environment variable
points to valid gc-style GOROOT. In that case, make it work by telling
the go/build package to use gc mode.
Change-Id: Iadff8be61be8cc9a7ff2ca0a067b116b62895451
Reviewed-on: https://go-review.googlesource.com/117997
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
I felt guilty about leaving 2% on the table in CL 108878,
so I thought I'd get it a different way.
Teach readFile to accept a re-usable bytes.Buffer to read into,
to reduce the amount of garbage created.
To limit the possible memory impact of giant files,
only re-use the buffer for the duration of a single package.
Even that is enough to help.
name old time/op new time/op delta
Referrers 4.67s ± 3% 4.58s ± 2% -1.96% (p=0.029 n=10+10)
name old user-time/op new user-time/op delta
Referrers 16.5s ± 3% 15.8s ± 1% -4.39% (p=0.000 n=10+8)
name old sys-time/op new sys-time/op delta
Referrers 16.1s ± 3% 15.9s ± 3% ~ (p=0.218 n=10+10)
This work supported by Sourcegraph.
Change-Id: I594ef25c0fd5ccb766ff5b98dbbd1a75a7a4f957
Reviewed-on: https://go-review.googlesource.com/108935
Reviewed-by: Alan Donovan <adonovan@google.com>
This simplifies and unifies the code.
It also improves the output:
Now the initial result is referred to from the perspective of
the query site, rather than from the perspective of the package
containing the query object, which seems more natural.
This work supported by Sourcegraph.
Change-Id: Ie7a77d39dd6568334e72d894dc66d35494ed4ac4
Reviewed-on: https://go-review.googlesource.com/108936
Reviewed-by: Alan Donovan <adonovan@google.com>
This change parallelizes the outer loop in globalReferrersPkgLevel,
which loops over packages to inspect.
There is also an easily parallelizable inner loop.
However, parallelizing it adds complication
(deffiles needs a mutex, inQueryPackage requires a wait group)
and offers only a 2% speed-up.
Benchmarks for this change, looking for encoding/json.MarshalIndent:
name old time/op new time/op delta
Referrers 5.31s ± 2% 4.67s ± 3% -11.95% (p=0.000 n=10+10)
name old user-time/op new user-time/op delta
Referrers 15.9s ± 2% 16.5s ± 3% +3.71% (p=0.000 n=10+10)
name old sys-time/op new sys-time/op delta
Referrers 15.7s ± 3% 16.1s ± 3% +2.73% (p=0.011 n=10+10)
Fixesgolang/go#24272
Updates golang/go#25017
This work supported by Sourcegraph.
Change-Id: I5dcda9017103cdff59d0ffdf5e87d2c2c955a33a
Reviewed-on: https://go-review.googlesource.com/108878
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Global, package-level queries can be done without typechecking.
This makes it significantly cheaper.
Instead of typechecking, consider all packages that directly
import the query package. In each of those packages, filter out:
* files that don't contain the query name
* files that don't import the query package
Fully parse the remaining files and look for selector expressions
matching the query package and name.
There are a few twists (dot imports, the query package, xtests).
They are described, along with how they are handled,
in the large comment at the beginning of globalReferrersPkgLevel.
On my machine and GOPATH, this reduces typical time
needed to find referrers to encoding/json.MarshalIndent
from (roughly)
real 0m39.946s
user 2m27.844s
sys 0m54.774s
to (roughly)
real 0m5.687s
user 0m15.793s
sys 0m16.001s
The processing of packages could be parallelized;
that is left for a future change, to ease reviewing.
Benefits from that will be limited;
building the reverse import graph accounts for 73%
of the runtime, and that is dominated by syscalls.
Optimization idea from Alan Donovan.
This work supported by Sourcegraph.
Change-Id: Ib19e25fcdcb27673fb03d7300dba2a53198901ad
Reviewed-on: https://go-review.googlesource.com/97800
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
If test files are not included here,
then results in those files will be missing
for queries within a single package.
This work supported by Sourcegraph.
Change-Id: I8136ea250ba980179228d9b408d9e7409c49a873
Reviewed-on: https://go-review.googlesource.com/97799
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This make it possible to easily run individual guru tests.
It also slightly speeds up the overall test run,
from 23s to 18s on my machine;
the TestGuru/calls is now the limiting factor,
by a significant margin.
This work supported by Sourcegraph.
Change-Id: If61ebf1cc60441a65274f3fddd31f69c7ca23b48
Reviewed-on: https://go-review.googlesource.com/108876
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This regression is due to https://go-review.googlesource.com/c/go/+/100235
which made the go/scanner behavior match the compiler's scanner by
not modifying filenames in line directives in any form. Specifically,
relative filenames now remain relative. This makes it easier to reason
about the behavior of the scanner but may require clients to adjust
those filenames.
If removing the longer path in the .golden file is not satisfactory,
the (scanner) client may have to massage positions returned via line
directives; or better, the line directives are created with extended
path information.
R=adonovan
Change-Id: I836571a6dafef5e6d81e4c7add203c994e107055
Reviewed-on: https://go-review.googlesource.com/101015
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
And avoid assumptions about the contents of the standard hash/fnv
package.
Change-Id: I10cc95ac6e3b482da5b027d68ff218d08f425e89
Reviewed-on: https://go-review.googlesource.com/40870
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Change-Id: Ia12ff7a0f6898f8d140565d255793904ce8585c4
Reviewed-on: https://go-review.googlesource.com/38754
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The go1.9 type checker now returns fake packages in addition to an
error if the package was not found at all. This changes the behavior
of guru in a release-specific way, requiring the test to be split into
a common part and a go1.9-specific part.
In hindsight, perhaps it would have been better to place the
expectation in a comment alongside the query so that they can be
easily enabled or disabled together. (The downside of that design is
that you can't batch-update all the expectations to match the actual
behavior.)
Change-Id: I58054adec428fbab7fe3c57097aefc827f89a46e
Reviewed-on: https://go-review.googlesource.com/37865
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
CL golang.org/cl/37349 broke the tests, because the
golden files were not updated appropriately.
Change-Id: I9a2a56d1ca74b8bc77935aff26ed6297fbacf232
Reviewed-on: https://go-review.googlesource.com/37770
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
A 'what' query reports which other query modes are applicable to the
selected syntax. A 'whicherrs' query is similar to a 'pointsto'
query, so we enable it using the same criteria.
Fixes issue golang/go#18938
Change-Id: Iae062e0c933c7764bc335488adabf816d63ac837
Reviewed-on: https://go-review.googlesource.com/37349
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Found with honnef.co/go/tools/cmd/unused.
Change-Id: Ied3a906269ca7782071428eeb1764b3b863576a2
Reviewed-on: https://go-review.googlesource.com/37600
Reviewed-by: Alan Donovan <adonovan@google.com>
Resolve symlinks in source directories (GOPATH, GOROOT, etc.) and source
files in order to find correct package. All I/O performed through
build.Context. Also add minor fix to guru unit tests in order to pass on
Windows.
Change-Id: Ie6134b9cd74eb7386e1d93603eb37c8e44b083b8
Reviewed-on: https://go-review.googlesource.com/33924
Reviewed-by: Alan Donovan <adonovan@google.com>
Add condition to prevent unit tests from checking cases with symlinks on
Windows and Plan 9.
Change-Id: Idc41db94a04a0daab556a26390db3f75ded7be73
Reviewed-on: https://go-review.googlesource.com/33923
Reviewed-by: Alan Donovan <adonovan@google.com>
Reason: ContainingPackage must do all I/O through build.Context.
This reverts commit c945ee3be4.
Change-Id: I625410bc754ea2d150be097bf424de2be42acde4
Reviewed-on: https://go-review.googlesource.com/33921
Reviewed-by: Alan Donovan <adonovan@google.com>
Restructure tests to account for possibility of being run on Windows
(which doesn't handle symlinks).
Change-Id: I428db26c9a1aad337d8972baa2b71468be3a2e58
Reviewed-on: https://go-review.googlesource.com/33920
Reviewed-by: Alan Donovan <adonovan@google.com>
Resolve symlinks in GOPATH or source file path in order to find correct package.
Fixesgolang/go#17515
Change-Id: Iaf7e85578fce040b329427ce6f51948a69e57a39
Reviewed-on: https://go-review.googlesource.com/33858
Reviewed-by: Alan Donovan <adonovan@google.com>
Add identical workaround from gorename to guru. Only affects queries
that typecheck the code first.
Fixesgolang/go#16530
Change-Id: I718cfceb8d26868eea9128c8873b164333c50f53
Reviewed-on: https://go-review.googlesource.com/33359
Reviewed-by: Alan Donovan <adonovan@google.com>
Also:
- always display the value of a constant expr, whether query expr is a
definition, a reference, or an alias.
- eliminate some go1.5 portability code.
- remove go1.8 fork of referrers; no changes are necessary
since I decided not to treat aliases specially.
- add tests.
Tested with Go 1.6, Go 1.7, and tip (Go 1.8).
Change-Id: I94624cff82f4d8c0dcbf12d11c8ce16e8168a7fe
Reviewed-on: https://go-review.googlesource.com/32730
Reviewed-by: Robert Griesemer <gri@golang.org>
This CL only copies files and updates build tags.
Substantive changes will come in follow-ups.
This is a workaround for git's lack of rename/copy tracking.
Tested with go1.6, go1.7, and tip (go1.8).
Change-Id: Id88a05273fb963586b228d5e5dfacab32133a960
Reviewed-on: https://go-review.googlesource.com/32630
Reviewed-by: Robert Griesemer <gri@golang.org>
Most objects are declared by an identifier, so the end position is
start+len(name). However, this heuristic doesn't work for PkgName
objects because a (non-renaming) import creates an object without an
identifier.
Fixes issue github.com/Microsoft/vscode-go#562
Change-Id: I0eb44ca33a643c910d97abbf700ea4c3cd23bb41
Reviewed-on: https://go-review.googlesource.com/32440
Reviewed-by: Robert Griesemer <gri@golang.org>
Supporting user-defined TestMain functions requires that we generate a
"testmain" package for each testable package, rather than a single one
for the entire program. This entails these API changes:
1. (*ssa.Program).{CreateTestMainPackage,FindTests} both now
accept only a single package. Existing clients that pass them
multiple packages must call them from a loop.
2. (*ssa.Program).FindTests returns an additional result, the the
optional TestMain *ssa.Function. Existing clients may discard it.
Also:
- Test the new logic using the SSA interpreter
- add ssautil.MainPackages helper
- callgraph: allow multiple main packages, and analyze them all
- ssadump -run: allow multiple main/test packages, and run each in a new interpreter
- minor simplifications to some callers (e.g. guru)
Fixesgolang/go#9553
Change-Id: Ia7de9bd27448fb08b8d172ba5cdbcf37a762b7a0
Reviewed-on: https://go-review.googlesource.com/25102
Reviewed-by: Robert Griesemer <gri@golang.org>
This package requires cl-lib.el in package header but it is not loaded
and cl.el functions are used instead of cl-lib functions. Using cl.el
functions causes byte-compile warnings.
Change-Id: I6d9400f9ced6a5cc0592d83da2ab1c1cf34e20b8
Reviewed-on: https://go-review.googlesource.com/27031
Reviewed-by: Alan Donovan <adonovan@google.com>
This allows type-based guru queries to work on arbitrary files at the
root or even outside of a GOPATH workspace (as "go run foo.go" does).
Fixesgolang/go#15797
Change-Id: I2be28f7259448e6398aae84d6ae7e71d8649967a
Reviewed-on: https://go-review.googlesource.com/30451
Reviewed-by: Robert Griesemer <gri@golang.org>
The test expectation includes the text of a UNIX ENOENT message.
Also, make the same change for (deprecated) oracle tool.
Fixesgolang/go#16397
Change-Id: I8c3c6a300ff2366bfeb97cf41d34097c41aab680
Reviewed-on: https://go-review.googlesource.com/24968
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>