Skip to content

Commit 1523441

Browse files
committed
gopls/internal/cache: add more assertions for golang/go#60890
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 440f3c3 commit 1523441

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

gopls/internal/cache/check.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type typeCheckBatch struct {
6262
syntaxIndex map[PackageID]int // requested ID -> index in ids
6363
pre preTypeCheck
6464
post postTypeCheck
65-
handles map[PackageID]*packageHandle
65+
handles map[PackageID]*packageHandle // (immutable)
6666
parseCache *parseCache
6767
fset *token.FileSet // describes all parsed or imported files
6868
cpulimit chan unit // concurrency limiter for CPU-bound operations
@@ -473,6 +473,7 @@ func (b *typeCheckBatch) getImportPackage(ctx context.Context, id PackageID) (pk
473473

474474
// Do a second check for "unsafe" defensively, due to golang/go#60890.
475475
if ph.mp.PkgPath == "unsafe" {
476+
// (This assertion is reached.)
476477
bug.Reportf("encountered \"unsafe\" as %s (golang/go#60890)", id)
477478
return types.Unsafe, nil
478479
}
@@ -957,6 +958,11 @@ func (s *Snapshot) getPackageHandles(ctx context.Context, ids []PackageID) (map[
957958
for _, v := range b.nodes {
958959
assert(v.ph != nil, "nil handle")
959960
handles[v.mp.ID] = v.ph
961+
962+
// debugging #60890
963+
if v.ph.mp.PkgPath == "unsafe" && v.mp.ID != "unsafe" {
964+
bug.Reportf("PackagePath \"unsafe\" with ID %q", v.mp.ID)
965+
}
960966
}
961967

962968
return handles, nil

gopls/internal/cache/load.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
353353
pkgPath := PackagePath(pkg.PkgPath)
354354
id := PackageID(pkg.ID)
355355

356+
// debugging #60890
357+
if pkg.PkgPath == "unsafe" && pkg.ID != "unsafe" {
358+
bug.Reportf("PackagePath \"unsafe\" with ID %q", pkg.ID)
359+
}
360+
356361
if metadata.IsCommandLineArguments(id) {
357362
var f string // file to use as disambiguating suffix
358363
if len(pkg.CompiledGoFiles) > 0 {
@@ -369,7 +374,7 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
369374
// A file=empty.go query results in IgnoredFiles=[empty.go].
370375
f = pkg.IgnoredFiles[0]
371376
} else {
372-
bug.Reportf("command-line-arguments package has neither CompiledGoFiles nor IgnoredFiles: %#v", "") //*pkg.Metadata)
377+
bug.Reportf("command-line-arguments package has neither CompiledGoFiles nor IgnoredFiles")
373378
return nil
374379
}
375380
id = PackageID(pkg.ID + f)
@@ -404,6 +409,11 @@ func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Packag
404409
Standalone: standalone,
405410
}
406411

412+
// debugging #60890
413+
if mp.PkgPath == "unsafe" && mp.ID != "unsafe" {
414+
bug.Reportf("PackagePath \"unsafe\" with ID %q", mp.ID)
415+
}
416+
407417
updates[id] = mp
408418

409419
for _, filename := range pkg.CompiledGoFiles {

0 commit comments

Comments
 (0)