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

125 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley b8ff201971 gopls/internal/cache: refine bug reports for inconsistent dep view
The most likely cause of an inconsistent view of a dependency is a
mismatching test variant. Refine the bug report to identify this case.

For golang/go#63822

Change-Id: I1334501be1ea55a43a49557ad2cb1d03178268cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628495
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 16:03:08 +00:00
Rob Findley 60bc93d368 gopls/internal/cache: fix handling of cgo standalone files
It is not a bug for go/packages to return no packages for standalone
files, if they use cgo and cgo is disabled. There may also be other
scenarios where standalone packages are not produced. In any case,
downgrade the bug report to a normal error.

Also, fix the failing test to require cgo.

Fixes golang/go#70363
Fixes golang/go#70362

Change-Id: I2b8a8b3947e4d7ff6482279540638e13dc9de2b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628017
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 01:22:19 +00:00
Rob Findley 254baba677 gopls/internal/cache: failure to extract diagnostic fixes is an error
Although the LSP specifies that diagnostic data should be transmitted
unmodified to codeAction requests, we can't control whether clients
abide by this rule. Therefore, a failure to extract fixes should be
treated as a user-facing error, not a bug.

Fixes golang/go#68819

Change-Id: I57e629cf381ee1112d98d22e728449995679b05f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628237
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-15 16:16:26 +00:00
Rob Findley b1c39aa3b6 gopls/internal/cache: use a named bool type for allowNetwork
As suggested on CL 626715, using a named bool clarifies call sites.

Change-Id: Ie36f406dcca382c7edc277895826265ae9040ee2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628235
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-14 23:38:11 +00:00
Rob Findley c043599d4e gopls/internal/protocol: add DocumentURI.DirPath
To simplify many callsites where we called filepath.Dir on uri.Path(),
introduce the DocumentURI.DirPath helper method. This clarified many
call sites, and could make it easier to optimize URI manipulation in the
future.

Change-Id: Icc64155b6bba631f9df5da5a05e3126c7cb7954b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-14 23:37:56 +00:00
Rob Findley 29f4edbc1a gopls/internal/cache: simplify usage of snapshot.GoCommandInvocation
The Snapshot.GoCommandInvocation API is a source of confusion, because
it passes in a gocommand.Invocation, performs arbitrary mutation, and
then passes it back to the caller (which may perform mutation on top).
Aside from the readability problems of this indirectness, this API can
lead to real bugs, for example if one of the mutations is incompatible
with another.

Furthermore, the fact that the GoCommandInvocation is the golden source
of information about the Go command environment leads to awkwardness and
redundant work. For example, to get the packages.Config we called
Snapshot.GoCommandInvocation, just to read env, working dir, and build
flags (and the now irrelevant ModFile and ModFlag). But
GoCommandInvocation wrote overlays, so we'd end up writing overlays
twice: once within the gopls layer, and then again in the go/packages go
list driver.

Simplify as follows:
- Pass in dir, verb, args, and env to GoCommandInvocation, to avoid
  passing around and mutating an Invocation.
- Extract the View.Env, which is a useful concept, and apply invocation
  env on top. Surveying existing use cases that this was correct, as all
  call sites expected their env not to be overwritten.
- Move Snapshot.config to load.go, where it belongs, and simplify not to
  depend on GoCommandInvocation.

Also add an additional test case for BenchmarkReload.

Change-Id: I8ae7a13a033360e0e7b0b24ff718b5a22123e99c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626715
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-14 23:37:48 +00:00
Rob Findley 221e94d05c gopls/internal/cache: id command-line-arguments packages using GoFiles
Previously, we were using the first CompiledGoFiles to disambiguate the
ID of command-line-arguments packages, but in the presence of cgo
preprocessing there can actually be multiple CompiledGoFiles, leading
to the bug report of golang/go#64557. Fix this by using GoFiles instead.

Fixes golang/go#64557

Change-Id: I3eff976d07da32db1f26ced69228af41a388d9a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627776
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-14 19:13:17 +00:00
Rob Findley 35d7f2837a go/packages: add Dir and ForTest fields to Package
Add a new Dir field, and export ForTest, per golang/go#38445. The
needInternalForTest mode bit is promoted to NeedForTest, but no mode bit
is added for Dir as it is logically related to NeedFiles.

A test is added for the new fields using a simpler txtar-based setup,
since I did not have time to page in the quite heavyweight packagestest
framework.

For golang/go#38445

Change-Id: I92026462f7ed7e237db1f4e50a3bbf2936802fbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-08 18:44:44 +00:00
Rob Findley 61415bee33 gopls/internal/cache: guard against malformed paths in port.matches
It's possible that we may encounter the path inconsistency of
golang/go#67288 due to unclean or relative paths. Guard against this
with a new bug report.

For golang/go#67288

Change-Id: I37ac1f74334bcb9e955d75e436f74398c73f0acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626015
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-07 22:10:23 +00:00
Alan Donovan ca2b41b3fd x/tools: use internal/expect instead of go/expect
The only remaining uses of go/expect are from packagestest.

Updates golang/go#70229

Change-Id: I5a8c835b761381747fbd3f936d261ed773b536e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625919
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-06 19:53:11 +00:00
Rob Findley f1f7c26696 gopls/internal/cache: ensure GO111MODULE is unset in GOPATH tests
With GO111MODULE=on in the test environment, the GOPATH subtest of
TestZeroConfigAlgorithm was failing, since GO111MODULE=on invalidated
our detection of a GOPATH workspace. Fix the test environment.

Fixes golang/go#70196

Change-Id: Ia80a5a63d93842aef4b67ca419e1d27eb11573c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625515
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
2024-11-05 18:44:49 +00:00
Rob Findley e5417d7d9f gopls/internal/cache: log go env in TestZeroConfigAlgorithm
Add an additional log message to help diagnose the problem encountered
by a user in golang/go#70196.

For golang/go#70196

Change-Id: I8347d842d5a9327fa6797229bf64dc4407f7aa61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-05 16:00:57 +00:00
Rob Findley cceaf96b25 internal/imports: carve out a Source interface for index integration
In preparation for integrating the newly implemented shared module cache
index, carve out a minimal imports.Source interface to be used by
FixImports. For now, this interface has a single implementation,
wrapping the legacy ProcessEnv abstraction, but in the future we can
replace it with an implementation that synthesizes the module cache
index with gopls' own view of the workspace.

This CL intentionally avoids any refactoring aside from extracting the
ProcessEnv-specific logic into a ProcessEnvSource.

For golang/go#36077

Change-Id: I189a908c917aba68868b08845880b1f0aa731180
Reviewed-on: https://go-review.googlesource.com/c/tools/+/623296
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-04 18:14:50 +00:00
Alan Donovan 99e8fee2bf x/tools: fset.File(file.Pos()) -> fset.File(file.FileStart)
This CL fixes a bug (#70149) in gopls/internal/golang/pkgdoc.go
in which a call to fset.File(file.Pos()) would return nil
because when file points to an empty ast.File, Pos() returns NoPos.

Instead, we should use file.FileStart, which is (in principle)
always valid even for an empty file. However, there is a separate
bug in go1.23 (#70162) that means FileStart is invalid whenever
Pos() is. So, this fix only works with go1.24, and there's no
real workaround short of the additional logic this CL adds to
parsego.Parse, which at least covers all of gopls.

Also, we audit all of x/tools for similar faulty uses of Pos()
and replace them with FileStart. In future, we should use File.Pos
only for its specific meaning related to the package decl.

Fixes golang/go#70149
Updates golang/go#70162

Change-Id: Ic8cedfe912e44a0b4eb6e5e6874a6266d4be9076
Reviewed-on: https://go-review.googlesource.com/c/tools/+/624437
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-04 15:48:36 +00:00
Hongxiang Jiang 386503de7a gopls/internal/golang: add source code action for add test
This CL is some glue code which build the connection between the
LSP "code action request" with second call which compute the actual
DocumentChange.

AddTest source code action will create a test file if not already
exist and insert a random function at the end of the test file.

For testing, an internal boolean option "addTestSourceCodeAction"
is created and only effective if set explicitly in marker test.

For golang/vscode-go#1594

Change-Id: Ie3d9279ea2858805254181608a0d5103afd3a4c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621056
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-29 21:52:38 +00:00
Rob Findley 91421d7314 gopls/internal/cache: share type checking with analysis
Consolidate the logic of type checking and analysis, for the following
benefits:

- Simplify by eliminating redundant logic to type check and import
  packages in the analysis driver.
- Reduce work by reusing type checked packages in analysis. By the time
  we run analysis on open packages, we likely have type checked the
  packages already, so the work to type check inside the analysis driver
  is very much redundant.
- Reduce work by reusing the package key from packageHandle (which we
  have gone to great pains to optimize).
- Reduce work (and file cache space) by avoiding the need to store
  export data alongside analysis facts.
- Leverage the precision of our reachability analysis by using a bloom
  filter of reachable packages to better filter facts.
- This indirectly fixes golang/go#64227 and golang/go#64236, since the
  crashing logic is deleted.

For golang/go#53275
Fixes golang/go#64227
Fixes golang/go#64236

Change-Id: I431b8da35b2dce7c63f56ec1a3727e0747b79740
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622038
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-28 18:30:04 +00:00
Rob Findley 17213ba81a gopls/internal/cache/parsego: support lazy object resolution for Files
For the purposes of go/analysis, gopls could not skip syntactic object
resolution, as it is part of the go/analysis contract. This prevents
analysis from reusing existing type-checked packages, leading to
increased CPU and memory during diagnostics.

Fix this by making object resolution lazy, and ensuring that all
analysed files are resolved prior to analysis.

This could introduce a race if gopls were to read the fields set by
object resolution, for example if it was printing the tree using
ast.Fprint, so we include a test that these fields are only accessed
from packages or declarations that are verified to be safe.

Since the resolver is not separate from the parser, we fork the code and
use go generate to keep it in sync.

For golang/go#53275

Change-Id: I24ce94b5d8532c5e679789d2ec1f75376e9e9208
Reviewed-on: https://go-review.googlesource.com/c/tools/+/619516
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-28 16:00:44 +00:00
Rob Findley 9f3c6463b9 gopls/internal/cache: memoize cache keys
analysisNode.cacheKey shows up as very hot in benchmarks, yet analysis
should observe the same invalidation heuristics as other package data.

Memoizing the cache keys in the snapshot reduced total CPU of
BenchmarkDiagnosePackageFiles by 10-15%.

For golang/go#53275

Change-Id: I0f60c3e78c77ac6e58b14308bb0331022babae69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622037
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-24 15:50:50 +00:00
Rob Findley 1f162c6c5b gopls/internal/cache: async pull diagnostics and joined analysis
Make pull diagnostics async, to optimize handling of many simultaneous
requests for the diagnostics of open files. Accordingly, update the pull
diagnostic benchmark to request diagnostics concurrently.

Naively, these concurrent diagnostics would cause gopls to incur major
performance penalty due to duplicate analyses -- as much as 5x total CPU
in the pull diagnostic benchmark. To mitigate this cost, join ongoing
analysis operations using a shared global transient futureCache. This
reduces the benchmark back down close to its previous total CPU, with
reduced latency. Eyeballing the net delta of this CL in the benchmark,
it looks like +20% total CPU, -30% latency.

As a nice side effect, this more than eliminates the need to pre-seed
the file cache in the gopls marker tests. The shared futures provide
more consolidation of work than the pre-seeding, because of variance in
the cache keys of standard library packages, due to different gopls
options.

For golang/go#53275

Change-Id: Ie92bab4c140e3f86852531be8204b6574b254d8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622036
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-23 20:06:04 +00:00
Rob Findley c45778760f gopls/internal/cache: avoid reporting bugs when go/packages has errors
When go/packages.Load returns an error, or has packages with errors, we
should not assume that assumptions of the resulting packages still hold.
I believe this is the cause of the two telemetry bug reports below.

Fixes golang/go#66204
Fixes golang/go#69895

Change-Id: I9beab020ddb37d36a8826cb36a576990463d7bce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621859
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-22 22:05:38 +00:00
Rob Findley 401eca0e4a gopls/internal/settings: remove "allowImplicitNetworkAccess"
This setting was slated for removal in gopls@v0.16. Nobody has
complained on the linked bug. Remove it.

Fixes golang/go#66861

Change-Id: I942dbd06755114a13ef097b4a57ffe169441e76f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621877
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-22 21:03:59 +00:00
Rob Findley 6618569404 gopls/internal/cache: refine a bug report related to package metadata
Refine a bug report to isolate incoherent package metadata potentially
related to using a GOPACKAGESDRIVER.

For golang/go#64235

Change-Id: I82dc6f53b1668d15cbfc146e5cf9b3c5d2ad79c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621858
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-22 20:55:56 +00:00
Rob Findley 6381f0b832 gopls/internal/cache: refine bug reports
Refine a few bug reports related to incorrectly positioned type checker
errors, by differentiating the 'fixed file' case from the case with no
fixed files.

Since we haven't made progress on these bugs, we need more information
to guide our debugging.

If the bugs only occur in the presence of AST fixes, we can probably
downgrade them to not be a bug: if we're fixing the AST, we won't
display type checker errors anyway. Nevertheless, leave the bug reports
for now, so that we can collect data.

For golang/go#65960
For golang/go#66765
For golang/go#66766

Change-Id: I2060c897d249cdd5cc3e7bb183d3f563987bec57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621876
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-10-22 20:17:14 +00:00
Rob Findley 8128bcf18d gopls/internal/cache: add tolerance for builtin test variants
Gopls tests are failing on CL 620196, where a test file is being added
to the builtin package. The failures were caused by test workspace
picking up new std dependencies through the builtin test variants, which
were being handled like normal packages. Queries like completion or
workspace symbols were affected, as they scan transitive imports.

Ignore builtin test variants to fix the breakage.

Change-Id: Ia1a99918b0bfb470c74470fa82e03e49fa460b06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621095
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-18 23:04:33 +00:00
Alan Donovan 454be607b6 x/tools: be defensive after types.Info.Types[expr] lookups
This CL is the result of a quick audit
of x/tools for places that look in the Types map and do
not handle missing entries gracefully (unless dominated
by a check for welltypedness, such as RunDespiteErrors:false
in the analysis framework). In each case it either adds
a defensive check or documents the assumption.

See https://github.com/golang/go/issues/69092#issuecomment-2389643780

Updates golang/go#69092

Change-Id: I3573512fd47ee4dca2e0b4bce2803b92424d7037
Reviewed-on: https://go-review.googlesource.com/c/tools/+/617416
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-10-14 18:46:52 +00:00
Rob Findley bd86f8c28a gopls/internal/cache/analysis: lazily resolve the import map
In CL 613715, we made import lookup lazy to mitigate the quadratic
construction of the import map during type checking. This CL makes the
equivalent change for the analysis driver.

Since analysis does not have fine-grained invalidation, it is even more
susceptible to the performance cost of this quadratic operation:

DiagnosePackageFiles-64
│  before.txt   │              after.txt              │
│    sec/op     │    sec/op     vs base               │
  1691.6m ± ∞ ¹   693.6m ± ∞ ¹  -59.00% (p=0.008 n=5)

│   before.txt   │               after.txt               │
│ cpu_seconds/op │ cpu_seconds/op  vs base               │
     6.480 ± ∞ ¹      3.260 ± ∞ ¹  -49.69% (p=0.008 n=5)

For golang/go#53275

Change-Id: I8690bc85848fe1e36391d4622aa2e3d3f9878f57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/619095
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-09 17:58:41 +00:00
Rob Findley f21a1dce1e gopls: add initial support for pull diagnostics
Implement the scaffolding for pull diagnostics. For now, these are only
supported for Go files, only return parse/type errors for the narrowest
package in the default view, do not report related diagnostics, and do
not run analysis. All of these limitations can be fixed, but this
implementation should be sufficient for some end-to-end testing.

Since the implementation is incomplete, guard the server capability
behind a new internal "pullDiagnostics" setting.

Wire in pull diagnostics to the marker tests: if the server supports it
("pullDiagnostics": true), use pull diagnostics rather than awaiting to
collect the marker test diagnostics.

For golang/go#53275

Change-Id: If6d1c0838d69e43f187863adeca6a3bd5d9bb45d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/616835
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-07 22:08:29 +00:00
Rob Findley c19060b012 gopls/internal/cache: use packageHandles to hold an active package cache
Previously, gopls was keeping a common import graph up to date between
snapshots, to optimize re-typechecking open packages. However, this had
several downsides:
 - It required rather complicated accounting
 - Working in package A could get slower after opening package B, if
   package B was in the forward closure of A, since it reduced the
   common import graph.
 - Since imports were constructed a-priori to type checking, we imported
   *all* packages in the forward closure of open packages, even if they
   wouldn't be needed for type checking, inflating the memory footprint.

This CL changes gopls to instead keep track of the active package on the
packageHandle, and invalidate its imports independently of other active
packages. As a result, we can eliminate the complicated importGraph
logic and the associated relationships between open packages. We also
reduce memory by holding on to a minimal set of imports for open
packages.

Change-Id: I82c49bb7002ab748497f34b43844b34176bdef9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614165
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-07 21:38:32 +00:00
Tim King a30b2075ca internal/versions: remove InitFileVersions
InitFileVersions is not longer conditionally needed at x/tools
supports Go >= 1.22.

Change-Id: I5df1b46463d23acda569e1378027d542ac749f93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/617637
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Commit-Queue: Tim King <taking@google.com>
2024-10-07 18:12:27 +00:00
Rob Findley d0d0d9ebc2 gopls/internal/cache: memoize dependent hash on analysisNode
Benchmarking demonstrated a nontrivial amount of time spent hashing
dependency information in the computation of analysisNode.cacheKey.
Memoize this hash to reduce cost.

Change-Id: Ic123202fbdf00c9de7b3f697c40f593ef798cd42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/617395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-03 13:35:00 +00:00
Rob Findley a19eef6bcb gopls/internal/cache: express packageHandle as a state machine
In preparation for storing active packages on packageHandle, express the
various package handle states using a new packageState type, and hold on
to package handle data even if their local files may have changed, as
long as their metadata did not change.

Also: rename buildPackageHandle to evaluatePackageHandle, which better
matches its meaning, and move the package ID index to the View, since it
is shared across all snapshots.

Change-Id: I2c14613d320b1121f20bb3960d42370bef5ad98b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614164
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-10-03 13:22:18 +00:00
Rob Findley b577f77ea7 gopls/internal/cache: remove unnecessary active package check
Snapshot.TypeCheck implemented an eager check for active packages that
was redundant with the same check in Snapshot.forEachPackage. Remove it.

Change-Id: Ia58c85ac4e8795ddcc47c124d006c609b8ae715e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614155
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-25 18:18:42 +00:00
Rob Findley 06b986b1e8 gopls/internal/cache: add a few checks for context cancellation
Now that we start diagnosing changes immediately following an edit, we
should be a bit more proactive about checking for cancellation during
the evaluation of a Snapshot. This CL adds a few cancellation checks at
locations indicated by benchmarking.

Change-Id: Iea71be2975d8343a5ca283ab9299ed5efe994bc8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/613716
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-25 18:18:31 +00:00
Rob Findley 83326b7c9c gopls/internal/cache: join concurrent package batch operations
One of the unsolved problems of the gopls scalability redesign described
at https://go.dev/blog/gopls-scalability is that concurrent type
checking operations may perform redundant work. While we avoided
redundancy within the context of *one* operation, by encapsulating the
type checking batch, it is possible that there will be logically
distinct operations occurring concurrently, such as computing
diagnostics and autocompletion. These operations could not share type
information, as they were operating within distinct type checking
"realms" (recall that go/types relies on the canonicalization of
imports).

This CL addresses that problem by refactoring the type checking batch
such that it can join two distinct operations into a shared state. The
typeCheckBatch becomes a queryable entity, coordinating work across
ongoing package graph traversals.

This required surprisingly little change to the typeCheckBatch itself,
which already abstracted the notion of a package traversal. Rather, the
key missing component was a future cache implementation that was (1)
retryable and (2) transient, in the sense that computed values were
discarded after use. The bulk of this change is the implementation and
testing of such a cache.

Some elements of the refactoring remain awkward:

- packageHandles are collected and merged into a shared map, because
  they must still be computed in large batches for efficiency.
- the shared importGraph remains a clumsy optimization, requiring subtle
  logic to pre-build a shared import graph.

My intuition is that both of these problems have an elegant solution,
but this work is left for a subsequent CL.

In addition to reducing CPU across the board, due to less redundancy in
the existing diagnostic pass, this CL will facilitate the following
additions to gopls:

- Pull-based diagnostics (golang/go#53275): now that diagnostic
  operations are naturally joined, there is less need for gopls to
  manage the scheduling of the diagnostic pass.
- Improvements to loading behavior (golang/go#68002): being able to
  handle requests asynchronously allows completion requests to
  potentially be handled using stale metadata.

Updates golang/go#53275
Updates golang/go#68002

Change-Id: Ib228cdcce2c4b6f616d6ba5b0abeb40e87f449be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/611843
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-25 18:17:51 +00:00
Alan Donovan d911e4a884 gopls: disable ast.Object resolution wherever possible
And where not, document why.

(Locations were found by instrumenting parser.ParseFile
and running gopls' tests.)

Change-Id: Iab205b1f96b4fb4b22a5d056b40fbbb326dcd7a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/615436
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
2024-09-25 16:16:45 +00:00
Alan Donovan 752860b84e gopls/internal/protocol/command: simplify ApplyFix
- combine URI + Range into one Location field
- factor n calls addCommand(NewApplyFixCommand).

Change-Id: I01c4ff7efeaa577331253348f4816a3a82b80db0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614157
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-23 18:23:46 +00:00
Alan Donovan 1d5e334177 internal/aliases: remove Alias and Unalias
These two declarations can now safely be accessed directly
from go/types.

Also, remove all mention of internal/aliases from gopls/...
We can enable two suppressed tests now that go1.23 is assured.

Updates golang/go#46477

Change-Id: I9ae8536b0d022e3300b285547c18202bed302cf2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/614638
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Tim King <taking@google.com>
Reviewed-by: Tim King <taking@google.com>
2024-09-20 19:51:09 +00:00
Alan Donovan bea7373d8a gopls/internal/protocol/command: remove nuisance error handling
The various command.NewXXXCommand functions all used to return
an error in case argument marshalling failed. However, in 100%
of cases, the particular argument types have infallible JSON
marshalling. This change emits the error handling code only
in the fallible cases (none yet).

Also, the New functions now return a pointer to a Command,
(as they should), simplifying surrounding logic.

(This is a preparatory cleanup for CL 612495.)

Change-Id: I2dac9f84034c2fade2ca05adc62129afc78e1cfe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/613263
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-09-18 14:43:40 +00:00
Rob Findley a58d83bcd9 gopls/internal/cache: build the import map lazily during type checking
For larger repositories, a significant amount of time in the importer is
spent building the import map.

While we don't really want to persist these import maps, which can be
quite large, we can largely eliminate their cost by doing an incremental
breadth-first search of dependencies for the desired import path: most
imports are direct or found within a shallow search starting from the
original package.

As one reference point, the DiagnoseChange/kubernetes benchmark went
from 10% of CPU spent in importMap, to ~0% in importLookup.

Change-Id: I219aa6b7d41dfb11ec5d8a5e3819adc46dd37f2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/613715
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-17 17:12:07 +00:00
Alan Donovan 5aac53c5ff gopls/internal/golang: Definition: jump to assembly
This CL adds support for jumping to the definition of a function
implemented in assembly. The first Definition query jumps to the
Go declaration, as usual; this func has no body. Executing a
second Definition query jumps to the assembly implementation,
if found.

+ Test, doc, relnote

Fixes golang/go#60531

Change-Id: I943a05d4a2a5b6a398450131831f49cc7c0754e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/612537
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-16 20:58:43 +00:00
Ethan Reesor dc4c52551c gopls/internal: test discovery
Implements test discovery. Tests are discovered as part of the type
checking process, at the same time as method sets and xrefs, and cached.
Does not implement the Modules command.

Adds static detection of simple subtests. This provides a framework for
static analysis of subtests but intentionally does not support more than
the most trivial case in order to minimize the complexity of this CL.

Fixes golang/go#59445. Updates golang/go#59445, golang/vscode-go#1602,
golang/vscode-go#2445.

Change-Id: Ief497977da09a1e07831e6c5f3b7d28d6874fd9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/548675
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-10 14:00:01 +00:00
Alan Donovan c2e057bbd2 gopls: use Func.Signature everywhere
Updates golang/go#65917

Change-Id: I20bec8b0a1778f0d2d81f729d12ba966799c7805
Reviewed-on: https://go-review.googlesource.com/c/tools/+/612037
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-09 18:09:59 +00:00
Alan Donovan 9d7d14e469 x/tools/gopls: delete code obsoleted by go1.23
The util/slices package has been deleted; but util/maps
has been renamed to moremaps since it still has some
useful things.

Note: the standard maps.Clone may return nil.

Updates golang/go#65917

Change-Id: Ide8cbb9aa13d80a35cdab258912a6e18a7db97c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/611837
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-09-09 18:00:29 +00:00
Rob Findley 9f9b7e39b5 gopls/internal/settings: add missing deep cloning in Options.Clone
As noted in a TODO, it appeared that settings.Clone was failing to deep
clone several map or slice fields. A test revealed that ten (!) fields
were not deeply cloned.

Fix this by:
1. Removing pointers and interfaces from settings.Options, by making
   ClientInfo a non-pointer, and by making LinksInHover a proper enum.
2. Adding a deepclone package that implements deep cloning using
   reflection. By avoiding supporting pointers and interfaces, this
   package doesn't need to worry about recursive data structures.

Change-Id: Ic89916f7cad51d8e60ed0a8a095758acd1c09a2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/606816
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-09-06 21:56:41 +00:00
Rob Findley dc4d64cc1c gopls: fix non-constant format strings
Fix vet failures related to the new vet check for non-constant format
strings with no args (golang/go#60529).

Change-Id: If63006613ec4827b8f7d23990654f5ecc1521ec8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/610795
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-04 18:00:29 +00:00
Rob Findley 826d8d971b gopls/internal/cache: add a note about GOMEMLIMIT and ballasts
As suggested post-submit in CL 608796, add a note explaining why
GOMEMLIMIT doesn't help gopls solve its GC CPU problems, and a ballast
is still necessary.

Change-Id: Ia452129e259c6f44a0f807028543699d3dd19495
Reviewed-on: https://go-review.googlesource.com/c/tools/+/609236
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-28 17:58:38 +00:00
Rob Findley aaf49f1fb8 gopls/internal/cache: add a 100MB ballast to reduce GC CPU
As described in the doc comment, add a 100MB ballast to reduce GC CPU in
small workspaces or during gopls startup.

Change-Id: I43ff2dcd15e62bebde43fb27567d19e462b2fa22
Reviewed-on: https://go-review.googlesource.com/c/tools/+/608796
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-28 16:26:39 +00:00
Alan Donovan 136c165474 gopls/internal/cache: remove spurious assertions
The various assertions that the package "unsafe" has
Metadata ID "unsafe" all appear to be false when using
Bazel via its gopackagesdriver.

I was (rather embarassingly) unable, within a reasonable
amount of time, to successfully analyze a trivial
hello-world Bazel project using the gopackages debugging
tool and the Bazel gopackagesdriver, so unfortunately
I can't verify the bug or its fix. The documentation
https://github.com/bazelbuild/rules_go/wiki/Editor-and-tool-integration#standard-library
seems to say that all the std packages should be recognized
as command-line targets. Nonetheless, the issue is clearly
related to Bazel from the statistics, and the ID==PkgPath
assumption is clearly unwarranted.

Fixes golang/go#60890

Change-Id: I4769083bfb0cba0a8698c7ec2e8e7b2d044e3a5c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/605735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-08-15 15:01:08 +00:00
Rob Findley fcf5463260 gopls/internal/server: add counters to inform v0.17.0
Add two counters to help inform decisions for gopls@v0.17.0:

- Add a gopls/gotoolchain:{auto,local,other} counter to help us
  understand toolchain upgradability.
- Add a gopls/telemetryprompt/accepted counter to track telemetry prompt
  acceptance.

Fixes golang/go#68240

Change-Id: I8fc06b3a266761dbf7c2781267dfb1235eef1a63
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595560
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2024-06-28 20:28:24 +00:00
Rob Findley 02912f74a5 gopls/internal/cache: lift package caching to forEachPackage
For some reason this solution didn't occur to me in CL 512636. By
lifting this handling out of forEachPackageInternal, we simplify the
logic of type checking.

Change-Id: Ie8738d04aa5e1e4811f978f2ebe2d1cfc3b839b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/591918
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-06-26 14:39:32 +00:00