Граф коммитов

3118 Коммитов

Автор SHA1 Сообщение Дата
Robert Findley c35476fcce gopls: commands to start/stop profiling, and a new benchmark metric
Total CPU used by gopls is a critical metric for our users, yet was not
previously captured in any benchmark. This change uses the new pprof
parsing utilities added in CL 507885 to instrument a cpu_seconds
benchmark metric, for now just associated with the DidChange benchmark.

This is achieved via new LSP commands that start and stop a profile. The
benchmark runner uses these commands to bracket the critical section of
the benchmark, then parses the resulting profile for its total sampled
CPU.

Additionally, the benchmark runner is updated to actually check for the
existence of the custom command before instrumenting the new metric.
This allows it to be compatible with testing older versions of gopls.
The same technique is adopted for memstats metrics.

I only instrumented BenchmarkDidChange, because the profile file schema
is getting truly out of hand. I'll try to simplify it before
instrumenting all the other benchmarks, but want to do that in a
separate CL.

For golang/go#60926

Change-Id: Ia082bad49e8d30c567a7c07e050511d49b93738b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/508449
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-07-11 13:57:10 +00:00
Bryan C. Mills ec9bc53425 internal/gopathwalk: use os.ReadFile instead of ioutil.ReadFile
ioutil.ReadFile is deprecated.

Change-Id: I6854af32d05e4a3ea2ad00002fb39f4d87fc1794
Reviewed-on: https://go-review.googlesource.com/c/tools/+/508504
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-07-10 20:18:28 +00:00
Alan Donovan aac7fb67ae internal/cmd/deadcode: a command to report dead code in Go programs
This CL adds a command to report functions that are unreachable
from the main functions of applications and tests.

It uses the Rapid Type Analysis (RTA) algorithm to
compute reachability, and reports all functions referenced
by the SSA representation that were not found to be
reachable, grouped by package and sorted by position.

Also, a basic integration test.

Change-Id: Ide78b4e22d4f4066bf901e2d676e5058ca132827
Reviewed-on: https://go-review.googlesource.com/c/tools/+/507738
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-07-10 18:10:37 +00:00
cui fliter 7bb83606e3 internal: fix typo
Change-Id: I56eea523be552c05a9588bc18bdbfe4cddada8a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/504755
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: shuang cui <imcusg@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-07-10 15:00:08 +00:00
Alan Donovan 124ebfa4c4 internal/pprof: a function to compute total pprof time
Also, a test.

Change-Id: I86c777a7519ba5cf6c9980eb2e7ff3acdba4031f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/507885
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-07-06 20:34:16 +00:00
Olivier Mengué 27fd94e099 internal/fastwalk: doc formatting fixes (including godoc links)
* add godoc links
* fix minor typos

Change-Id: Iea7727913c412ccad259d62e75325903327fdb9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/506775
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
2023-06-28 16:11:18 +00:00
Alan Donovan b71392afd8 gopls/internal/lsp/cache: reduce importing in analysis
This CL is a substantial reorganization of the analysis driver to
ensure that export data is imported at most once per batch of packages
that are analyzed, instead of once per import edge. This greatly
reduces the amount of allocation and computation done during analysis.

In cache/analysis.go, Snapshot.Analyze (which now takes a set of
PackageIDs, instead of being called singly in a loop) constructs an
ephemeral DAG that mirrors the package graph, and then works in
parallel postorder over this graph doing analysis. It uses a single
FileSet for the whole batch of packages it creates. The subgraph
rooted at each node is effectively a types.Importer for that node,
as it represents the mapping from PackagePath to *types.Package.

We no longer bother with promises or invalidation. We rely on the fact
that the graph is relatively cheap to construct, cache hits are cheap
to process, and the whole process only occurs after an idle delay of
about a second.

Also:

- In internal/facts, optimize the fact decoder by using a callback.
  Previously, it was spending a lot of time traversing the API of all
  imports of a package to build a PackagePath-to-types.Package
  mapping. For many packages in terraform-provider-aws this visits
  over 1M objects (!!). But of course this is trivially computed from
  the new representation.

- In internal/gcimporter, IImportShallow now uses a single callback to
  get all the types.Package symbols from the client, potentially in
  parallel (and that's what gopls does). The previous separation of
  "create" and "populate" has gone away.

  The analysis driver additionally exploits the getPackages callback to
  efficiently read the package manifest of an export data file,
  then abort with an error before proceeding to actually decode
  the rest of the file.

With this change, we can process the internal/provider package of the
terraform-provider-aws repo in 20s cold, 4s hot. (Before, it would run
out of memory.)

$ go test -bench=InitialWorkspaceLoad/hashiform ./gopls/internal/regtest/bench
BenchmarkInitialWorkspaceLoad/hashiform-8         	       1	4014521793 ns/op	 349570384 alloc_bytes	 439230464 in_use_bytes	 668992216 total_alloc_bytes
PASS

Fixes golang/go#60621

Change-Id: Iadeb02f57eb19dcccb639857053b897a60e0a90e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/503195
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-06-20 19:04:06 +00:00
Robert Findley d1a388b0ec internal/gcimporter: avoid a crash when exporting a struct with no pkg
This is an arbitrary fix to avoid a crash while exporting an empty
struct with no ambient package. Unfortunately, the struct encoding
assumes that there is an implied package for structs, which at least in
invalid code may not be the case.

Fixes golang/go#60891

Change-Id: I8acd591ac15cdc1770d615fdca57dcb7bb9b7651
Reviewed-on: https://go-review.googlesource.com/c/tools/+/504556
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-06-20 18:36:31 +00:00
Robert Findley 7261b32692 gopls/internal/regtest: fix goimports on windows when using vendoring
Add a test for goimports when using mod vendoring on windows, along with
a very subtle one-line fix.

Fixes golang/go#56291

Change-Id: I2e45f70fc6dfa32164d4664acad886ec811474b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498695
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-06-15 14:21:39 +00:00
Rob Findley 6e1595c156 internal/gcimporter: treat unknown constant values the same as invalid
Fixes a crash resulting from trying to convert an unknown constant
value.

Fixes golang/go#60605

Change-Id: If6b831b8fe2f9690b9f89e191b329eb7660f5e14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/501209
TryBot-Bypass: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2023-06-12 20:53:04 +00:00
Alan Donovan a01290f984 internal/typeparams: work around LookupFieldOrMethod inconsistency
This change adds to x/tools a workaround for a bug in go/types
that causes LookupFieldOrMethod and NewTypeSet to be inconsistent
wrt an ill-typed method (*T).f where T itself is a pointer.

The workaround is that, if Lookup fails, we walk the MethodSet.

Updates golang/go#60634
Fixes golang/go#60628

Change-Id: I87caa2ae077e5cdfa40b65a2f52e261384c91167
Reviewed-on: https://go-review.googlesource.com/c/tools/+/501197
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-06-06 20:18:50 +00:00
Alan Donovan 0b4461babc internal/diff: fix LineEdits bug in slow path
Previously, the expandEdit operation would expand to
the end of the line unconditionally, but this caused it
to gulp an extra line if it was already line-aligned.

This change causes it to do the expansion only if
the end is not line-aligned, or the replacement text
doesn't end with a newline.

Now, removing the fast path no longer causes tests to fail.
This also allows us to remove the logic added in CL 489695
to work around issue golang/go#59232.

Fixes golang/go#60379
Fixes golang/go#59232

Change-Id: Ia40e4e3bb714d75acb95103a38e8c49a8ef456de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/499377
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2023-06-01 18:40:17 +00:00
Alan Donovan 1943c1e3e1 internal/diff: fix LineEdits bug in fast path
The fast-path "optimization" that skips the main
algorithm when the input is already line-aligned
failed to check that the replacement text consisted
of complete lines.

(Scare quotes because removing the "optimization" causes
tests to fail. See CL 499377 next in stack for why.)

Thanks to pjw for diagnosing the root cause and
providing the test case in CL 498975.

Fixes golang/go#60379

Change-Id: I2ff92de4550754691442362b8a8932ee42971461
Reviewed-on: https://go-review.googlesource.com/c/tools/+/499376
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2023-06-01 18:40:08 +00:00
Alan Donovan ed90c6d201 internal/diff: unexport various identifiers
They were exported only because of unnecessary coupling
with another package, solved by copying.

Change-Id: I5f08ad9091b8fce10c2bac6383e020a3c45426f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498257
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-25 16:41:48 +00:00
Alan Donovan 3c02551765 internal/typesinternal: remove NewObjectpathFunc
Updates golang/go#58668
Fixes golang/go#60330

Change-Id: I06bf739e9278028cbafb174b93699fbdfe98882f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/496875
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-05-22 13:02:24 +00:00
Alan Donovan a069704d01 gopls/internal/lsp/filecache: avoid flock
This CL changes the implementation of the filecache to use
a scheme similar to that used by the go command's cache.
Instead of atomic rename(2), or flock(2), it instead relies
on the atomicity in practice of writes to small files (in our
case 32 bytes, the size of a SHA256 hash).

A cache entry now consists of two files, a kind="cas" file that
holds the cache value, keyed by its SHA256 hash, and an
index file, whose name is formed from the user-provided
kind and key, and whose content is the SHA256 hash that
is a key into the CAS.

Writes to the CAS may race, so we check the integrity of
everything we read back from it using SHA256.
Writes to the index files may also race, but we assume
that small writes are in practice atomic.

The memory-based LRU cache has beeen temporarily disabled
so that we can soak test the new implementation for a while.

We expect this to be significantly more reliable, and also faster.

Change-Id: I25cf341b90c985dcab015df770be579ea786bd06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/495800
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2023-05-19 14:45:18 +00:00
Alan Donovan 12a0517ad6 internal/gcimporter: improve error handling
This change:
- updates the error message reported when the importer
  recovers from a panic.
- updates the set of test input files to include examples
  of the formats used in go1.16-go1.20.
- adds a recover handler to UImportData, for symmetry with
  IImportData. This was exposed by the new test case.
- fixes an accidental shadowing bug that suppressed the
  bundle format version check.

Fixes golang/go#59179

Change-Id: Ib6c20fc15e2051481fccba593607a7df0e01bc74
Reviewed-on: https://go-review.googlesource.com/c/tools/+/494676
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-05-15 19:46:39 +00:00
Alan Donovan ad74ff6345 go/gcexportdata: drop support for the ancient binary format
Compilers and tools haven't produced it since go1.11,
several years ago now.

Change-Id: I5056c5bba81030a2eba5e3931190b8249524aed7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/494442
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-05-12 19:05:24 +00:00
Russ Cox 9aa9d134de cmd/bisect, internal/bisect: use more precise skip suffixes, written in hex
If the target is misbehaving and some changes unlock others,
then in general bisect is going to have a hard time and can fail
to identify the problem. It will usually say "target fails inconsistently".

One robustness improvement we can make is to use more bits than
necessary for exclusions, which reduces the chances of accidentally
excluding changes that simply didn't trigger this time around but
might still be part of a bug later. To do this, we calculate the minimum
number of bits needed to distinguish all the =y and =n changes
observed, round up to a number of hex digits, and then add another
digit for good measure.

Change-Id: I02354f281370806c3eb4d85911a6ca92fcfcae05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/494276
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2023-05-11 03:57:30 +00:00
Rob Findley d799eba7d4 gopls: additional instrumentation during goimports
Add some visibility into goimports operations, by instrumenting spans in
top-level imports and gocommand operations.

This may be the first time we instrument non-gopls code in this way, but
it should be safe as other build targets (e.g. the goimports or
gopackages commands) do not set a global exporter, and therefore the
cost of event instrumentation should be minimal.

For golang/go#59216

Change-Id: Id2f8fe05d6b61e96cdd2d41cc43b3d4c3cf39e21
Reviewed-on: https://go-review.googlesource.com/c/tools/+/494095
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-05-10 16:50:45 +00:00
Rob Findley ddfa2200ae internal/fuzzy: improvements to the symbol scoring algorithm
Based on feedback in golang/go#60027, tweak the fuzzy symbol scoring
algorithm to much more strongly prefer sequential and exact matches.

Fixes golang/go#60027

Change-Id: I1c6d019065c4dff4adf2db9e94397a635e13d50f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/493623
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-05-09 14:15:48 +00:00
Peter Weinberger 3d99ebe9f3 gopls/diff/unified: remove redundant information
Sometimes the unified diff would show the same line removed and added.
That is avoided by this CL.

Fixes: golang/go#59232

Change-Id: Ie6562e3c922b8f0c4319eefdde1913b2d9bc7878
Reviewed-on: https://go-review.googlesource.com/c/tools/+/489695
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-08 16:21:27 +00:00
Rob Findley 4ac71c005e internal/imports: sort fixes for deterministic results
Fixes golang/go#59976

Change-Id: I59c309e126b1ec4cd05c50e5af8e5df8cfe49072
Reviewed-on: https://go-review.googlesource.com/c/tools/+/492738
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-05-05 13:51:58 +00:00
Russ Cox dd0938175b bisect: move to internal/bisect until API is reviewed
I wasn't thinking of this package as an exported library,
but of course it is, so it should go through proposal review.
Moving to internal until that happens.

Change-Id: Ic8abbe5f6530d5d6201114c1799e26d604f3dd64
Reviewed-on: https://go-review.googlesource.com/c/tools/+/492976
TryBot-Bypass: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-05-05 13:26:48 +00:00
Russ Cox 58fedf60c6 internal/diffp: add patience diff from main repo
This is the main repo's internal/diff, renamed because
there is a different internal/diff already in x/tools.

Change-Id: I7b6da718e46c9fa23931908b520b9f39c178206b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/491915
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Chase <drchase@google.com>
2023-05-05 00:46:00 +00:00
Bryan C. Mills 2415ce1593 gopls: skip tests that load gopls packages if x/tools replacement is missing
The gopls go.mod file often contains a replace directive, but the
target of the replacement (a parent directory) is not present when the
test is run from the module cache or in an equivalent setting.

To avoid having more configurations to test and maintain, we skip
these tests if the replacement directory does not exist or does not
contain a plausible x/tools go.mod file.

Fixes golang/go#59841.

Change-Id: Icf86af46899686c3aae410250e6d26ffd11b429a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/489216
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-02 16:53:13 +00:00
Ayman Bagabas 80dc031992 internal/diff: unified: match diff delete for empty file
GNU diff -u prints +0,0 for the special case of deleting into an empty file.
This also adds a test for this case.

What version of Go are you using (go version)? `go version go1.20.3 darwin/amd64`

What operating system and processor architecture are you using? MacOS/amd64

What did you do?
```sh
echo -n "test" >src
touch dst
diff -u src dst
```

What did you expect to see?
```
--- src	2023-04-20 18:04:23
+++ dst	2023-04-20 18:04:23
@@ -1 +0,0 @@
-test
\ No newline at end of file
```

What did you see instead?
internal/diff prints the wrong unified diff, it should be `@@ -1 +0,0 @@` instead of `@@ -1 +1 @@`.
```
--- src
+++ dst
@@ -1 +1 @@
-test
\ No newline at end of file
```

Change-Id: If23b609ada4a45249f1c382ebe8f821dde7aadc0
GitHub-Last-Rev: d08a1ba959
GitHub-Pull-Request: golang/tools#436
Reviewed-on: https://go-review.googlesource.com/c/tools/+/487175
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-04-28 16:11:30 +00:00
cui fliter 165099bd7e all: remove repeated definite articles
Change-Id: I2100bb55aeecccad5ff3462b68b7308f9e20bf12
Reviewed-on: https://go-review.googlesource.com/c/tools/+/489655
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: shuang cui <imcusg@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-04-27 22:13:51 +00:00
Bryan C. Mills ac40903eed internal/gocommand: simplify GoVersion invocation
Detecting the go version does not require build flags,
and should not depend on the value of GO111MODULE.

For golang/go#59841.

Change-Id: I74255953985e6d2ad01095eea2b6d72f7d280e3f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/489215
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-04-27 16:11:57 +00:00
Bryan C. Mills 76e1037d71 internal/testenv: assume that mobile platforms are small machines
Experiments in CL 488655 suggest that the android builders are capable
of running tests that require 'go build' but do not have enough disk
resources to run gopls regression tests. It seems reasonable to always
assume that mobile platforms are (by definition) resource-constrained.

Change-Id: If91627b681050bb2e53d03a86ce609565ae3dc6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/488815
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2023-04-25 20:18:36 +00:00
Alan Donovan 4baa3dc484 gopls/internal/bug: move bug package into gopls
A follow-up change will cause it to write to
the file system.

Change-Id: I1c3b04af1d0f7b8e223d96b4bc9d1399b610f6ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/488595
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
2023-04-25 16:18:47 +00:00
Bryan C. Mills 82c8a38232 internal/gocommand: set a WaitDelay (when available) on commands
Fixes golang/go#59541.

Change-Id: I8b88f369c5b8d41f3dc2f1c38e0e736279046c6d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/484743
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-04-21 18:35:09 +00:00
Bryan C. Mills 6deeacb5ba all: fix remaining tests on js/wasm
Several non-short tests were missing needed testenv checks.

gopls/internal/lsp/cmd in particular has a weird failure mode.
(I suspect that there is still a missing error check somewhere in that
test.)

For golang/go#58141.

Change-Id: I13d7d19545d46a681a12635eb357617a0fbbd9ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/486935
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Commit-Queue: Bryan Mills <bcmills@google.com>
2023-04-20 21:20:13 +00:00
Bryan C. Mills 780626cdd1 all: fix non-gopls short tests on js/wasm and update for wasip1/wasm
testenv.HasExec should not assume that "js" and "ios" are the only
platforms that can't exec. Instead of hard-coding a list of GOOS,
hard-code only the ones known to work and probe the remainder by
trying to re-exec the test binary.

Similarly, in testenv_notunix, negate the list of unix platforms
instead of hard-coding the non-unix ones.

Add missing calls to testenv functions were needed.

For golang/go#58141.
Updates golang/go#59718.

Change-Id: I0114e0bfb6d091e84b325d7f9bb0896da22482be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/486315
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-20 14:27:21 +00:00
Bryan C. Mills 13c52bcee9 internal/gocommand: stop copying stdout as soon as ctx is done
If ctx is done, that means (by definition) that the caller is no
longer interested in the output of the command. Since 'go list'
output can be quite long, we shouldn't waste time copying it
if we no longer care about it.

If the command doesn't shut down on its own in response to the initial
Interrupt signal, or if it triggers a bug in the kernel leading to a
deadlock, or I/O is otherwise extremely slow (perhaps due to
swapping), the savings from this earlier shutdown could be
significant. Even if not, the impact (or lack thereof) of this change
could tell us more about what's going on.

For golang/go#54461.

Change-Id: I0df067cb77496dacd29497f0995da6fc1a4a37f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/484741
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-20 02:13:37 +00:00
Alan Donovan 866a200092 internal/gocommand: more tweaks to DebugHangingGoCommands
As suggested by bcmills, this change increases the time
between SIGINT and SIGKILL to 5s (was 1s), and also
suppresses the process dump if SIGKILL returned
"already done".

Updates golang/go#57999
Updates golang/go#54461

Change-Id: Ie0e55a69d3bbfb4224e5f4ea272c7c2f3210e342
Reviewed-on: https://go-review.googlesource.com/c/tools/+/483215
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-10 15:00:41 +00:00
Nooras Saba f4e613e8db go/analysis/passes/tests: enable fuzz checks in 'tests' analysis pass for cmd/vet
This will remove the flag analysisinternal.DiagnoseFuzzTests created during golang/go#50198.Malformed fuzz target check will be enabled for cmd/vet.

For golang/go#46218

Change-Id: I5cc8d685a57060f8dd84c1957f0d296a6205ddb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/471295
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Nooras Saba‎ <saba@golang.org>
2023-03-30 21:38:09 +00:00
Robert Findley 488ba86990 gopls/internal/lsp/cache: hold on to imports used by open packages
Benchmarking demonstrated clearly that gopls must memoize active
packages, to efficiently handle repeated requests related to open files
(e.g. code lens, completion, semantic tokens).

In doing so, gopls is effectively pinning the import graph of these open
packages. However, when those packages changed, this import graph was not
being reused. Furthermore when multiple open packages shared packages in
their import graph, there was a chance that gopls may pin multiple copies
of those packages, if the open packages were type-checked in separate
batches.

This change introduces a new optimization which manages a shared import
graph to be re-used across snapshots. Before performing any
type-checking we re-evaluate this shared import graph. This is purely an
optimization, and is not necessary for correctness. As such, the
feature is guarded behind a compile-time constant, so that it may easily
be disabled for debugging. The plan is to have several such constants.

For golang/go#57987

Change-Id: Ica654ffc8f1e5f39bcab7000c0839ece22e20ab2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/479015
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-03-24 15:12:23 +00:00
Robert Findley fa556487c5 gopls/internal/lsp/cache: evaluate imports lazily in TypeCheck
Now that we do not need a static importMap for importing, and do not
need to eagerly parse or load export data, we can evaluate imported
packages lazily during type-checking, thereby avoiding importing
packages that will not be used.

This has a mild beneficial impact on benchmarks (because iimporting is
already cheap). The other direction -- avoiding invalidating packages
that are unaffected by changes -- should have a more significant impact.

For golang/go#57987

Change-Id: I894656af9ca8dea286b6be55f83c4b6bffaaf110
Reviewed-on: https://go-review.googlesource.com/c/tools/+/473166
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2023-03-17 16:53:17 +00:00
Robert Findley b6dbcf8656 internal/gcimporter: have IImportShallow accept an import func
In preparation for skipping imports that aren't reached, change the
gcimporter.IImportShallow API to accept an func rather than an explicit
map.

Update call sites to use a trivial wrapper around the new API.
Subsequent CLs will avoid building packages that aren't needed.

Updates golang/go#57987

Change-Id: Iee88e5f42fa353cde3e87447031c3e7485f04ca4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/476436
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-15 16:03:28 +00:00
Robert Findley 35ef64eeee internal/tool: add the profile.alloc flag
Alloc profiles are very useful. Add a -profile.alloc flag to the
tool.Profile helper (and therefore, to gopls).

Change-Id: I0250be5eadb1c644c6d7b6386077362ec97b06d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/473164
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-03-15 15:36:18 +00:00
Alan Donovan c881168622 internal/tokeninternal: add AddExistingFiles helper
This function breaks the encapsulation of token.FileSet
to add a set of token.Files efficiently. All of the files
in the resulting set must be nonoverlapping, though
identical elements are permitted (and deduplicated).

This is a precursor to optimizations in gopls's typechecking phase.

Change-Id: I1b731bca334b55756d7ba26562e70232965ae3fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/476437
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
2023-03-15 15:30:03 +00:00
Robert Findley 21d2256f2c gopls/internal/lsp/cache: make type-checking incremental
In this CL type-checked packages are made entirely independent of each
other, and package export data and indexes are stored in a file cache.
As a result, gopls uses significantly less memory, and (with a warm
cache) starts significantly faster. Other benchmarks have regressed
slightly due to the additional I/O and export data loading, but not
significantly so, and we have some ideas for how to further narrow or
even close the performance gap.

In the benchmarks below, based on the x/tools repository, we can see
that in-use memory was reduced by 88%, and startup time with a warm
cache by 65% (this is the best case where nothing has changed). Other
benchmarks regressed by 10-50%, much of which can be addressed by
improvements to the objectpath package (golang/go#51017), and by making
package data serialization asynchronous to type-checking.

Notably, we observe larger regressions in implementations, references,
and rename because the index implementations (by Alan Donovan) preceded
this change to type-checking, and so these benchmark statistics compare
in-memory index performance to on-disk index performance. Again, we can
optimize these if necessary by keeping certain index information in
memory, or by decoding more selectively.

name                              old in_use_bytes  new in_use_bytes  delta
InitialWorkspaceLoad/tools-12            432M ± 2%          50M ± 2%    -88.54%  (p=0.000 n=10+10)

name                              old time/op       new time/op       delta
StructCompletion/tools-12              27.2ms ± 5%       31.8ms ± 9%    +16.99%  (p=0.000 n=9+9)
ImportCompletion/tools-12              2.07ms ± 8%       2.21ms ± 6%     +6.64%  (p=0.004 n=9+9)
SliceCompletion/tools-12               29.0ms ± 5%       32.7ms ± 5%    +12.78%  (p=0.000 n=10+9)
FuncDeepCompletion/tools-12            39.6ms ± 6%       39.3ms ± 3%       ~     (p=0.853 n=10+10)
CompletionFollowingEdit/tools-12       72.7ms ± 7%      108.1ms ± 7%    +48.59%  (p=0.000 n=9+9)
Definition/tools-12                     525µs ± 6%        601µs ± 2%    +14.33%  (p=0.000 n=9+10)
DidChange/tools-12                     6.17ms ± 7%       6.77ms ± 2%     +9.64%  (p=0.000 n=10+10)
Hover/tools-12                         2.11ms ± 5%       2.61ms ± 3%    +23.87%  (p=0.000 n=10+10)
Implementations/tools-12               4.04ms ± 3%      60.19ms ± 3%  +1389.77%  (p=0.000 n=9+10)
InitialWorkspaceLoad/tools-12           3.84s ± 4%        1.33s ± 2%    -65.47%  (p=0.000 n=10+9)
References/tools-12                    9.72ms ± 6%      24.28ms ± 6%   +149.83%  (p=0.000 n=10+10)
Rename/tools-12                         121ms ± 8%        168ms ±12%    +38.92%  (p=0.000 n=10+10)
WorkspaceSymbols/tools-12              14.4ms ± 6%       15.6ms ± 3%     +8.76%  (p=0.000 n=9+10)

This CL is one step closer to the end* of a long journey to reduce
memory usage and statefulness in gopls, so that it can be more
performant and reliable.

Specifically, this CL implements a new type-checking pass that loads and
stores export data, cross references, serialized diagnostics, and method
set indexes in the file system. Concurrent type-checking passes may
share in-progress work, but after type-checking only active packages are
kept in memory. Consequently, there can be no global relationship
between type-checked packages. The work to break any dependence on
global relationships was done over a long time leading up to this CL.

In order to approach the previous type-checking performance, the
following new optimizations are made:
 - the global FileSet is completely removed: repeatedly importing from
   export data resulted in a tremendous amount of unnecessary token.File
   information, and so FileSets had to be scoped to packages
 - files are parsed as a batch and stored in the LRU cache implemented
   in the preceding CL
 - type-checking is also turned into a batch process, so that
   overlapping nodes in the package graph may be shared during large
   type-checking operations such as the initial workspace load

This new execution model enables several simplifications:
 - We no longer need to trim the AST before type-checking:
   TypeCheckMode and ParseExported are gone.
 - We no longer need to do careful bookkeeping around parsed files: all
   parsing uses the LRU parse cache.
 - It is no longer necessary to estimate cache heap usage in debug
   information.

There is still much more to do. This new model for gopls's execution
requires significant testing and experimentation. There may be new bugs
in the complicated new algorithms that enable this change, or bugs
related to the new reliance on export data (this may be the first time
export data for packages with type errors is significantly exercised).
There may be new environments where the new execution model does not
have the same beneficial effect. (On the other hand, there may be
some where it has an even more beneficial effect, such as resource
limited environments like dev containers.) There are also a lot of new
opportunities for optimization now that we are no longer tied to a rigid
structure of in-memory data.

*Furthermore, the following planned work is simply not done yet:
 - Implement precise pruning based on "deep" hash of imports.
 - Rewrite unimported completion, now that we no longer have cached
   import paths.

For golang/go#57987

Change-Id: Iedfc16656f79e314be448b892b710b9e63f72551
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466975
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-03-03 22:59:49 +00:00
Alan Donovan 096bae8f4d internal/gcimporter: document non-idempotence of export∘import
In gopls we were recently surprised to discover that the
the message obtained by exporting a types.Package, and the
message obtained by importing and reexporting that message,
differ.

(Specifically because the importer calls NewInterfaceType,
which has a shortcut for empty interfaces, and this shortcut
is not used by go/types, so the importer produces a more
compact data structure than go/types. There may be other examples.)

This change documents the longstanding invariant that the encoding
is deterministic for a given types.Package data structure, while
also explicitly disclaiming that the composition of export∘import
is idemptotent.

Change-Id: Ie07efc1046315cd2104e78714d8312ecdf10e817
Reviewed-on: https://go-review.googlesource.com/c/tools/+/472075
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2023-03-01 16:36:58 +00:00
Robert Findley 120642f1f6 gopls/internal/bug: fix a bug in the bug package
After refactoring the public API of the bug package, the skip value used
in runtime.Caller became inaccurate for some new APIs. Fix this so that
we can actually see where the bug occurred.

Change-Id: Ie301084187dd9309895b2541c5dfc3b5ec4c63ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/472135
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-28 19:36:06 +00:00
Alan Donovan f98fce20d9 go/types/objectpath: add encoder type, to amortize allocation
This change adds a new encoder type with For method, that
is functionally equivalent to the old For function but avoids
the surprising cost of repeated calls to Scope.Names and
canonicalize (now called namedMethods), both of which
allocate and sorts a slice.

The former canonicalize function was previously applied to
interface types too, but this was costly and unnecessary
as they are already sorted.

The public API change will have to wait for proposal 58668
to be accepted and thus fix issue 51017; this change uses
the linkname hack to expose the function to x/tools to fix a
pressing bug in gopls.

See golang/go#58668
Updates golang/go#51017

Change-Id: Id3e8726517d31371b9376b0e47e320f8b6c5e085
Reviewed-on: https://go-review.googlesource.com/c/tools/+/470679
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-02-25 00:08:52 +00:00
Alan Donovan e5c9e63175 gopls/internal/lsp/regtest: add @rename marker tests
This change adds rudimentary support for @rename
markers, which make an LSP 'rename' request and
assert that the expected file changes are obtained.
We also introduce a separate marker, @renameerr,
for expectations of failure.

The treatment both of changed files and of expected errors
should be used by other markers, for consistency.

Also:
- Env.Mapper returns an error.
- add diff.ApplyBytes and compare.Bytes convenience wrappers.
- simplify fake.ApplyEdits by using ApplyProtocolEdits.
- change ApplyProtocolEdits to use []byte.

Change-Id: Ib64b3d8e12c025f01dd0783b4faee94f082b4895
Reviewed-on: https://go-review.googlesource.com/c/tools/+/466144
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-16 18:08:49 +00:00
Tim King 352e41afa4 internal/gcimporter: updates how imports are handled in unified IR
The imports of the main package are now all of the packages that
were referenced during reading the unified IR. This is similar to
the non-bundled option for iimport.

Without this imports of some packages are not the transitive closure.

Fixes golang/go#58296

Change-Id: I4c58c99a5538a9f990ca7325baa1637e7141a97e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/465936
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-02-13 17:10:11 +00:00
Tim King 8111118043 go/analysis/internal/facts: fix cycle in importMap.
This change resolves two interrelated outstanding bugs in handling Named
types and type declarations in importMap().
1) Named types did not visit their Underlying() types.
2) Whether Named types were fully visited was order dependent.
   Previously a Named type was not fully visited (methods visited, etc)
   when the type declaration was visited by addObj() before the Named
   type was visited by addType().

Fixes golang/go#49469

Change-Id: Ibf9c6d9afd4958d474149edf2749d994199f14b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/362414
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2023-02-02 23:42:27 +00:00
Robert Findley 66f8f71991 gopls/internal/lsp/source: use syntax alone in FormatVarType
FormatVarType re-formats a variable type using syntax, in order to get
accurate presentation of aliases and ellipses. However, as a result it
required typed syntax trees for the type declaration, which may exist in
a distinct package from the current package.

In the near future we may not have typed syntax trees for these
packages. We could type-check on demand, but (1) that could be costly
and (2) it may break qualification using the go/types qualifier.

Instead, perform this operation using a qualifier based on syntax
and metadata, so that we only need a fully parsed file rather than a
fully type-checked package. The resulting expressions may be inaccurate
due to built-ins, "." imported packages, or missing metadata, but that
seems acceptable for the current use-cases of this function, which are
in completion and signature help.

While doing this, add a FormatNodeWithFile helper that allows formatting
a node from a *token.File, rather than *token.FileSet. This can help us
avoid relying on a global fileset. To facilitate this, move the GetLines
helper from internal/gcimporter into a shared tokeninternal package.

For golang/go#57987

Change-Id: I3b8a5256bc2261be8b5175ee360b9336228928ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/464301
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2023-02-02 19:21:44 +00:00