Skip to content

Commit a2a2477

Browse files
committed
gopls/internal/regtest: externalize shouldLoad tracking
The fundamental bug causing TestChangePackageName to fail has been fixed, yet unskipping it revealed a new bug: tracking whether or not a package should be loaded requires that we actually store that package in s.meta. In cases where we drop metadata, we also lose the information that a package path needs to be reloaded. Fix this by significantly reworking the tracking of pending loads, to simplify the code and separate the reloading logic from the logic of tracking metadata. As a nice side-effect, this eliminates the needless work necessary to mark/unmark packages as needing loading, since this is no longer tracked by the immutable metadata graph. Additionally, eliminate the "shouldLoad" guard inside of snapshot.load. We should never ask for loads that we do not want, and the shouldLoad guard either masks bugs or leads to bugs. For example, we would repeatedly call load from reloadOrphanedFiles for files that are part of a package that needs loading, because we skip loading the file scope. Lift the responsibility for determining if we should load to the callers of load. Along the way, make a few additional minor improvements: - simplify the code where possible - leave TODOs for likely bugs or things that should be simplified in the future - reduce the overly granular locking in getOrLoadIDsForURI, which could lead to strange races - remove a stale comment for a test that is no longer flaky. Updates golang/go#53878 Change-Id: I6d9084806f1fdebc43002c7cc75dc1b94f8514b9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/417576 Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 7b605f4 commit a2a2477

File tree

6 files changed

+129
-152
lines changed

6 files changed

+129
-152
lines changed

Diff for: gopls/internal/regtest/diagnostics/diagnostics_test.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ func main() {
703703

704704
// Test for golang/go#38207.
705705
func TestNewModule_Issue38207(t *testing.T) {
706-
testenv.NeedsGo1Point(t, 14)
706+
// Fails at Go 1.14 following CL 417576. Not investigated.
707+
testenv.NeedsGo1Point(t, 15)
707708
const emptyFile = `
708709
-- go.mod --
709710
module mod.com
@@ -874,7 +875,7 @@ func TestX(t *testing.T) {
874875
}
875876

876877
func TestChangePackageName(t *testing.T) {
877-
t.Skip("This issue hasn't been fixed yet. See golang.org/issue/41061.")
878+
testenv.NeedsGo1Point(t, 16) // needs native overlay support
878879

879880
const mod = `
880881
-- go.mod --
@@ -889,15 +890,11 @@ package foo_
889890
Run(t, mod, func(t *testing.T, env *Env) {
890891
env.OpenFile("foo/bar_test.go")
891892
env.RegexpReplace("foo/bar_test.go", "package foo_", "package foo_test")
892-
env.SaveBuffer("foo/bar_test.go")
893893
env.Await(
894894
OnceMet(
895-
env.DoneWithSave(),
896-
NoDiagnostics("foo/bar_test.go"),
897-
),
898-
OnceMet(
899-
env.DoneWithSave(),
900-
NoDiagnostics("foo/foo.go"),
895+
env.DoneWithChange(),
896+
EmptyOrNoDiagnostics("foo/bar_test.go"),
897+
EmptyOrNoDiagnostics("foo/foo.go"),
901898
),
902899
)
903900
})

Diff for: gopls/internal/regtest/misc/vendor_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ var Goodbye error
2727
func TestInconsistentVendoring(t *testing.T) {
2828
testenv.NeedsGo1Point(t, 14)
2929

30-
// TODO(golang/go#49646): delete this comment once this test is stable.
31-
//
32-
// In golang/go#49646, this test is reported as flaky on Windows. We believe
33-
// this is due to file contention from go mod vendor that should be resolved.
34-
// If this test proves to still be flaky, skip it.
35-
//
36-
// if runtime.GOOS == "windows" {
37-
// t.Skipf("skipping test due to flakiness on Windows: https://golang.org/issue/49646")
38-
// }
39-
4030
const pkgThatUsesVendoring = `
4131
-- go.mod --
4232
module mod.com

Diff for: internal/lsp/cache/load.go

-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package cache
77
import (
88
"bytes"
99
"context"
10-
"errors"
1110
"fmt"
1211
"io/ioutil"
1312
"os"
@@ -41,24 +40,10 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
4140
var query []string
4241
var containsDir bool // for logging
4342

44-
// Unless the context was canceled, set "shouldLoad" to false for all
45-
// of the metadata we attempted to load.
46-
defer func() {
47-
if errors.Is(err, context.Canceled) {
48-
return
49-
}
50-
// TODO(rfindley): merge these metadata updates with the updates below, to
51-
// avoid updating the graph twice.
52-
s.clearShouldLoad(scopes...)
53-
}()
54-
5543
// Keep track of module query -> module path so that we can later correlate query
5644
// errors with errors.
5745
moduleQueries := make(map[string]string)
5846
for _, scope := range scopes {
59-
if !s.shouldLoad(scope) {
60-
continue
61-
}
6247
switch scope := scope.(type) {
6348
case PackagePath:
6449
if source.IsCommandLineArguments(string(scope)) {

Diff for: internal/lsp/cache/metadata.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Metadata struct {
2929
Name PackageName
3030
GoFiles []span.URI
3131
CompiledGoFiles []span.URI
32-
ForTest PackagePath
32+
ForTest PackagePath // package path under test, or ""
3333
TypesSizes types.Sizes
3434
Errors []packages.Error
3535
Deps []PackageID // direct dependencies, in string order
@@ -94,12 +94,8 @@ type KnownMetadata struct {
9494

9595
// PkgFilesChanged reports whether the file set of this metadata has
9696
// potentially changed.
97-
PkgFilesChanged bool
98-
99-
// ShouldLoad is true if the given metadata should be reloaded.
10097
//
101-
// Note that ShouldLoad is different from !Valid: when we try to load a
102-
// package, we mark ShouldLoad = false regardless of whether the load
103-
// succeeded, to prevent endless loads.
104-
ShouldLoad bool
98+
// TODO(rfindley): this is used for WorkspacePackages, and looks fishy: we
99+
// should probably only consider valid packages to be workspace packages.
100+
PkgFilesChanged bool
105101
}

0 commit comments

Comments
 (0)