Skip to content

Commit d6bd2d7

Browse files
committed
gopls/internal/cache: add assertions for export data inconsistency
This change pushes the assertions more deeply into the type checking logic so that we might have a chance of understanding the recurring inconsistency problems reported by telemetry. Updates golang/go#63822 Change-Id: I1371f7aa7104df0c55e055a11e9e6bb15219d79a Reviewed-on: https://go-review.googlesource.com/c/tools/+/560795 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 3403ce1 commit d6bd2d7

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

gopls/internal/cache/check.go

+30-8
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"golang.org/x/mod/module"
2323
"golang.org/x/sync/errgroup"
2424
"golang.org/x/tools/go/ast/astutil"
25-
"golang.org/x/tools/gopls/internal/file"
26-
"golang.org/x/tools/gopls/internal/filecache"
2725
"golang.org/x/tools/gopls/internal/cache/metadata"
2826
"golang.org/x/tools/gopls/internal/cache/typerefs"
27+
"golang.org/x/tools/gopls/internal/file"
28+
"golang.org/x/tools/gopls/internal/filecache"
2929
"golang.org/x/tools/gopls/internal/protocol"
3030
"golang.org/x/tools/gopls/internal/util/bug"
3131
"golang.org/x/tools/gopls/internal/util/safetoken"
@@ -610,21 +610,39 @@ func (b *typeCheckBatch) importPackage(ctx context.Context, mp *metadata.Package
610610
if item.Path == string(mp.PkgPath) {
611611
id = mp.ID
612612
pkg = thisPackage
613+
614+
// debugging issues #60904, #64235
615+
if pkg.Name() != item.Name {
616+
// This would mean that mp.Name != item.Name, so the
617+
// manifest in the export data of mp.PkgPath is
618+
// inconsistent with mp.Name. Or perhaps there
619+
// are duplicate PkgPath items in the manifest?
620+
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
621+
pkg.Name(), item.Name, id, item.Path)
622+
}
613623
} else {
614624
id = impMap[item.Path]
615625
var err error
616626
pkg, err = b.getImportPackage(ctx, id)
617627
if err != nil {
618628
return err
619629
}
630+
631+
// We intentionally duplicate the bug.Errorf calls because
632+
// telemetry tells us only the program counter, not the message.
633+
634+
// debugging issues #60904, #64235
635+
if pkg.Name() != item.Name {
636+
// This means that, while reading the manifest of the
637+
// export data of mp.PkgPath, one of its indirect
638+
// dependencies had a name that differs from the
639+
// Metadata.Name
640+
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
641+
pkg.Name(), item.Name, id, item.Path)
642+
}
620643
}
621644
items[i].Pkg = pkg
622645

623-
// debugging issue #60904
624-
if pkg.Name() != item.Name {
625-
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
626-
pkg.Name(), item.Name, id, item.Path)
627-
}
628646
}
629647
return nil
630648
}
@@ -724,7 +742,11 @@ func (b *typeCheckBatch) importMap(id PackageID) map[string]PackageID {
724742
populateDeps = func(parent *metadata.Package) {
725743
for _, id := range parent.DepsByPkgPath {
726744
mp := b.handles[id].mp
727-
if _, ok := impMap[string(mp.PkgPath)]; ok {
745+
if prevID, ok := impMap[string(mp.PkgPath)]; ok {
746+
// debugging #63822
747+
if prevID != mp.ID {
748+
bug.Reportf("inconsistent view of dependencies")
749+
}
728750
continue
729751
}
730752
impMap[string(mp.PkgPath)] = mp.ID

internal/gcimporter/iimport.go

+7
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
224224

225225
// Gather the relevant packages from the manifest.
226226
items := make([]GetPackagesItem, r.uint64())
227+
uniquePkgPaths := make(map[string]bool)
227228
for i := range items {
228229
pkgPathOff := r.uint64()
229230
pkgPath := p.stringAt(pkgPathOff)
@@ -248,6 +249,12 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
248249
}
249250

250251
items[i].nameIndex = nameIndex
252+
253+
uniquePkgPaths[pkgPath] = true
254+
}
255+
// Debugging #63822; hypothesis: there are duplicate PkgPaths.
256+
if len(uniquePkgPaths) != len(items) {
257+
reportf("found duplicate PkgPaths while reading export data manifest: %v", items)
251258
}
252259

253260
// Request packages all at once from the client,

0 commit comments

Comments
 (0)