Skip to content

Commit

Permalink
gopls/internal/cache: add more assertions for golang/go#60890
Browse files Browse the repository at this point in the history
This is one of our most frequent and oldest open crash bugs.

Updates golang/go#60890

Change-Id: I97bdf339ec355aaf23fb81ee8fed11b142d28409
Reviewed-on: https://go-review.googlesource.com/c/tools/+/581175
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan committed Apr 23, 2024
1 parent 440f3c3 commit 1523441
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type typeCheckBatch struct {
syntaxIndex map[PackageID]int // requested ID -> index in ids
pre preTypeCheck
post postTypeCheck
handles map[PackageID]*packageHandle
handles map[PackageID]*packageHandle // (immutable)
parseCache *parseCache
fset *token.FileSet // describes all parsed or imported files
cpulimit chan unit // concurrency limiter for CPU-bound operations
Expand Down Expand Up @@ -473,6 +473,7 @@ func (b *typeCheckBatch) getImportPackage(ctx context.Context, id PackageID) (pk

// Do a second check for "unsafe" defensively, due to golang/go#60890.
if ph.mp.PkgPath == "unsafe" {
// (This assertion is reached.)
bug.Reportf("encountered \"unsafe\" as %s (golang/go#60890)", id)
return types.Unsafe, nil
}
Expand Down Expand Up @@ -957,6 +958,11 @@ func (s *Snapshot) getPackageHandles(ctx context.Context, ids []PackageID) (map[
for _, v := range b.nodes {
assert(v.ph != nil, "nil handle")
handles[v.mp.ID] = v.ph

// debugging #60890
if v.ph.mp.PkgPath == "unsafe" && v.mp.ID != "unsafe" {
bug.Reportf("PackagePath \"unsafe\" with ID %q", v.mp.ID)
}
}

return handles, nil
Expand Down
12 changes: 11 additions & 1 deletion gopls/internal/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
pkgPath := PackagePath(pkg.PkgPath)
id := PackageID(pkg.ID)

// debugging #60890
if pkg.PkgPath == "unsafe" && pkg.ID != "unsafe" {
bug.Reportf("PackagePath \"unsafe\" with ID %q", pkg.ID)
}

if metadata.IsCommandLineArguments(id) {
var f string // file to use as disambiguating suffix
if len(pkg.CompiledGoFiles) > 0 {
Expand All @@ -369,7 +374,7 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
// A file=empty.go query results in IgnoredFiles=[empty.go].
f = pkg.IgnoredFiles[0]
} else {
bug.Reportf("command-line-arguments package has neither CompiledGoFiles nor IgnoredFiles: %#v", "") //*pkg.Metadata)
bug.Reportf("command-line-arguments package has neither CompiledGoFiles nor IgnoredFiles")
return nil
}
id = PackageID(pkg.ID + f)
Expand Down Expand Up @@ -404,6 +409,11 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
Standalone: standalone,
}

// debugging #60890
if mp.PkgPath == "unsafe" && mp.ID != "unsafe" {
bug.Reportf("PackagePath \"unsafe\" with ID %q", mp.ID)
}

updates[id] = mp

for _, filename := range pkg.CompiledGoFiles {
Expand Down

0 comments on commit 1523441

Please sign in to comment.