Skip to content

Commit

Permalink
gopls/internal/cache: refine a bug report related to package metadata
Browse files Browse the repository at this point in the history
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 <[email protected]>
Auto-Submit: Robert Findley <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Oct 22, 2024
1 parent 6381f0b commit 6618569
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ type typeCheckBatch struct {
handleMu sync.Mutex
_handles map[PackageID]*packageHandle

parseCache *parseCache
fset *token.FileSet // describes all parsed or imported files
cpulimit chan unit // concurrency limiter for CPU-bound operations
syntaxPackages *futureCache[PackageID, *Package] // transient cache of in-progress syntax futures
importPackages *futureCache[PackageID, *types.Package] // persistent cache of imports
parseCache *parseCache
fset *token.FileSet // describes all parsed or imported files
cpulimit chan unit // concurrency limiter for CPU-bound operations
syntaxPackages *futureCache[PackageID, *Package] // transient cache of in-progress syntax futures
importPackages *futureCache[PackageID, *types.Package] // persistent cache of imports
gopackagesdriver bool // for bug reporting: were packages loaded with a driver?
}

// addHandles is called by each goroutine joining the type check batch, to
Expand Down Expand Up @@ -237,7 +238,7 @@ func (s *Snapshot) acquireTypeChecking() (*typeCheckBatch, func()) {

if s.batch == nil {
assert(s.batchRef == 0, "miscounted type checking")
s.batch = newTypeCheckBatch(s.view.parseCache)
s.batch = newTypeCheckBatch(s.view.parseCache, s.view.typ == GoPackagesDriverView)
}
s.batchRef++

Expand All @@ -256,14 +257,15 @@ func (s *Snapshot) acquireTypeChecking() (*typeCheckBatch, func()) {
// shared parseCache.
//
// If a non-nil importGraph is provided, imports in this graph will be reused.
func newTypeCheckBatch(parseCache *parseCache) *typeCheckBatch {
func newTypeCheckBatch(parseCache *parseCache, gopackagesdriver bool) *typeCheckBatch {
return &typeCheckBatch{
_handles: make(map[PackageID]*packageHandle),
parseCache: parseCache,
fset: fileSetWithBase(reservedForParsing),
cpulimit: make(chan unit, runtime.GOMAXPROCS(0)),
syntaxPackages: newFutureCache[PackageID, *Package](false), // don't persist syntax packages
importPackages: newFutureCache[PackageID, *types.Package](true), // ...but DO persist imports
_handles: make(map[PackageID]*packageHandle),
parseCache: parseCache,
fset: fileSetWithBase(reservedForParsing),
cpulimit: make(chan unit, runtime.GOMAXPROCS(0)),
syntaxPackages: newFutureCache[PackageID, *Package](false), // don't persist syntax packages
importPackages: newFutureCache[PackageID, *types.Package](true), // ...but DO persist imports
gopackagesdriver: gopackagesdriver,
}
}

Expand Down Expand Up @@ -479,8 +481,14 @@ func (b *typeCheckBatch) importPackage(ctx context.Context, mp *metadata.Package
// manifest in the export data of mp.PkgPath is
// inconsistent with mp.Name. Or perhaps there
// are duplicate PkgPath items in the manifest?
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
pkg.Name(), item.Name, id, item.Path)
if b.gopackagesdriver {
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904) (using GOPACKAGESDRIVER)",
pkg.Name(), item.Name, id, item.Path)
} else {
return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
pkg.Name(), item.Name, id, item.Path)

}
}
} else {
id = importLookup(PackagePath(item.Path))
Expand Down

0 comments on commit 6618569

Please sign in to comment.