golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.26k stars 17.57k forks source link

x/tools/gopls: "unexpected files in command-line-arguments package" bug (via telemetry) #64557

Open adonovan opened 10 months ago

adonovan commented 10 months ago
#!stacks
"bug.Reportf" && ("cache.buildMetadata:+19" || "cache.buildMetadata:+14")

Yay! Repro at https://github.com/golang/go/issues/64557#issuecomment-2364675959

This stacks EVz2Fg, ELG5Yw, ND0D7A were reported by telemetry:

// buildMetadata populates the updates map with metadata updates to
// apply, based on the given pkg. It recurs through pkg.Imports to ensure that
// metadata exists for all dependencies.
func buildMetadata(updates map[PackageID]*metadata.Package, pkg *packages.Package, loadDir string, standalone bool) {
    // Allow for multiple ad-hoc packages in the workspace (see #47584).
    pkgPath := PackagePath(pkg.PkgPath)
    id := PackageID(pkg.ID)

    if metadata.IsCommandLineArguments(id) {
        if len(pkg.CompiledGoFiles) != 1 {
            bug.Reportf("unexpected files in command-line-arguments package: %v", pkg.CompiledGoFiles)
            return
gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:7
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).load:173
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/lsp/source.NarrowestMetadataForFile:1
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseChangedFiles:28
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseSnapshot:25
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseSnapshots.func1:2
runtime.goexit:0
golang.org/x/tools/gopls@v0.14.2 go1.21.0 darwin/arm64 (6)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Duplicates:

This stack dDf6yw was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:7
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).load:173
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/lsp/source.selectPackageForFile:1
golang.org/x/tools/gopls/internal/lsp/source.NarrowestPackageForFile:1
golang.org/x/tools/gopls/internal/lsp/source.SignatureHelp:6
golang.org/x/tools/gopls/internal/lsp.(*Server).signatureHelp:9
golang.org/x/tools/gopls/internal/lsp.(*Server).SignatureHelp:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:490
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4:52
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1:2
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2:3
runtime.goexit:0
golang.org/x/tools/gopls@v0.14.2 go1.21.6 windows/amd64 vscode (1)

This stack Es6nFQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:7
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:143
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).load:173
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/lsp/source.NarrowestMetadataForFile:1
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseChangedFiles:28
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseSnapshot:25
golang.org/x/tools/gopls/internal/lsp.(*Server).diagnoseSnapshots.func1:2
runtime.goexit:0
golang.org/x/tools/gopls@v0.14.2 go1.21.3 darwin/arm64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

This stack OBhdqw was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:7
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:143
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).load:173
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/lsp/source.NarrowestMetadataForFile:1
golang.org/x/tools/gopls/internal/lsp.(*commandHandler).ListImports.func1:25
golang.org/x/tools/gopls/internal/lsp.(*commandHandler).run.func1:2
golang.org/x/tools/gopls/internal/lsp.(*commandHandler).run:72
golang.org/x/tools/gopls/internal/lsp.(*commandHandler).ListImports:2
golang.org/x/tools/gopls/internal/lsp/command.Dispatch:73
golang.org/x/tools/gopls/internal/lsp.(*Server).executeCommand:19
golang.org/x/tools/gopls/internal/lsp.(*Server).ExecuteCommand:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:606
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls@v0.14.2 go1.21.3 darwin/arm64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Dups: gRw1-A ibW47g Dfhd-g _p1kkQ RcEuHA fJJ7HA e0uUFg 9M1npA WNZ--Q SmQ1mg v1Eb2g DdP2cQ 5Um4Rg yWpCHQ ziMhMQ 49eF6g rAKLNA bm9HIg

adonovan commented 8 months ago

Apparently one can create a command-line-arguments package with zero CompiledGoFiles:

xtools$ echo "" > b.go
xtools$ go list -e  -compiled -json  ./b.go
{
    "Dir": "/Users/adonovan/w/xtools",
    "ImportPath": "command-line-arguments",
    "Match": [
        "./b.go"
    ],
    "Incomplete": true,
    "Stale": true,
    "StaleReason": "build ID mismatch",
    "GoFiles": [
        "b.go"
    ],
    "InvalidGoFiles": [
        "b.go"
    ],
    "Error": {
        "ImportStack": [
            "command-line-arguments"
        ],
        "Pos": "b.go:1:2",
        "Err": "expected 'package', found 'EOF'"
    }
}
gopherbot commented 8 months ago

Change https://go.dev/cl/560465 mentions this issue: gopls/internal/cache: allow command-line-package >1 CompileGoFiles

adonovan commented 7 months ago

This stack ibW47g was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:7
golang.org/x/tools/gopls/internal/lsp/cache.buildMetadata:143
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).load:173
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).resolveImportGraph:11
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).getImportGraph.func1:2
runtime.goexit:0
golang.org/x/tools/gopls@v0.14.2 devel windows/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 7 months ago

This stack gRw1-A was reported by telemetry:

buildMetadata:14 is:

bug.Reportf("unexpected files in command-line-arguments package: %v", pkg.CompiledGoFiles)
gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:35
golang.org/x/tools/gopls/internal/util/bug.Reportf:1
golang.org/x/tools/gopls/internal/cache.buildMetadata:14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:36
golang.org/x/tools/gopls/internal/cache.(*Snapshot).resolveImportGraph:11
golang.org/x/tools/gopls/internal/cache.(*Snapshot).getImportGraph.func1:2
runtime.goexit:0
golang.org/x/tools/gopls@v0.15.0-pre.2 go1.22rc1 linux/amd64 vscodium (2)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 7 months ago

Reopening due to new field reports at v0.15.

adonovan commented 6 months ago

This stack _p1kkQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.buildMetadata:+156
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/server.(*commandHandler).ListImports.func1:+25
golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3
golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+68
golang.org/x/tools/gopls/internal/server.(*commandHandler).ListImports:+2
golang.org/x/tools/gopls/internal/protocol/command.Dispatch:+79
golang.org/x/tools/gopls/internal/server.(*server).ExecuteCommand:+19
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+674
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls@v0.15.1 go1.22.0 darwin/arm64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 6 months ago

This stack RcEuHA was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.buildMetadata:+156
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.selectPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.NarrowestPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.CodeActions:+65
golang.org/x/tools/gopls/internal/server.(*server).CodeAction:+95
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+160
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.2 go1.22.1 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 6 months ago

This stack fJJ7HA was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedFiles:+33
golang.org/x/tools/gopls/internal/server.(*server).diagnoseSnapshot:+27
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedViews.func1:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.2 go1.21.8 darwin/arm64 other,vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 6 months ago

This stack e0uUFg was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/cache.(*Snapshot).orphanedFileDiagnostics:+13
golang.org/x/tools/gopls/internal/cache.(*Session).OrphanedFileDiagnostics:+50
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedViews:+54
golang.org/x/tools/gopls/internal/server.(*server).didModifyFiles.func2:+1
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.2 go1.22.1 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 6 months ago

This stack 9M1npA was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/server.goLinks:+16
golang.org/x/tools/gopls/internal/server.(*server).DocumentLink:+14
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+291
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.2 go1.22.1 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 6 months ago

This stack WNZ--Q was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.selectPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.NarrowestPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.Highlight:+6
golang.org/x/tools/gopls/internal/server.(*server).DocumentHighlight:+14
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+280
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.2 go1.22.1 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 4 months ago

This stack SmQ1mg was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/golang.Format:+47
golang.org/x/tools/gopls/internal/server.(*server).Formatting:+14
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+324
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.3 go1.22.2 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 4 months ago

27 reported crashes this week... I really need to make some progress on this one.

adonovan commented 4 months ago

The bug indicates that there are multiple .go files in a command-line-arguments package. This is perfectly valid for go list a.go b.go when multiple .go files (and only .go files) are given as argument patterns, but it should never happen in gopls. Gopls has only one call to packages.Load, in Snapshot.load, and its query arguments come from the loop over scopes, which asserts that if there is a fileLoadScope (file=foo.go), then it must be the sole one.

Crazy thought: Is it possible for strings of the form "*.go" or "file=foo.go" to arise from the other kinds of scopes? If so, it would have to be a packageLoadScope; the others all have other suffixes. These strings are created in reloadWorkspace, from the PkgPath values in the shouldLoadRange map. They all originate from Metadata.PkgPath and Metadata.ForTest. Is it possible for a PkgPath to end in .go? Yes (see below). Is this common? Very much not.

So I think the answer must lie in go list. Perhaps @matloob has some insight.

xtools$ cat h.go/h.go 
package ff
xtools$ go list -json ./h.go
{
    "Dir": "/Users/adonovan/w/xtools/h.go",
    "ImportPath": "golang.org/x/tools/h.go",
    "Name": "ff",
    "Root": "/Users/adonovan/w/xtools",
    "Module": {
        "Path": "golang.org/x/tools",
        "Main": true,
        "Dir": "/Users/adonovan/w/xtools",
        "GoMod": "/Users/adonovan/w/xtools/go.mod",
        "GoVersion": "1.19"
    },
    "Match": [
        "./h.go"
    ],
    "Stale": true,
    "StaleReason": "build ID mismatch",
    "GoFiles": [
        "h.go"
    ]
}
adonovan commented 4 months ago

This stack v1Eb2g was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.selectPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.NarrowestPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.CodeActions:+65
golang.org/x/tools/gopls/internal/server.(*server).CodeAction:+95
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+160
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.3 go1.22.0 darwin/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 3 months ago

This stack DdP2cQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+14
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+208
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.selectPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.NarrowestPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.InlayHint:+4
golang.org/x/tools/gopls/internal/server.(*server).InlayHint:+14
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+357
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.15.3 go1.22.2 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

matloob commented 3 months ago

The go command explicitly checks to see if a ".go" pattern is not a directory when making a command-line-arguments package. See https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/pkg.go;l=2791;drc=94aeedc33a4434f0d410be7c42e0bbcdaedd790f . Otherwise the pattern is treated as matching a package. The linked code also links to issue #34653, where a bug was reported (and fixed) about ".go" packages not being supported.

adonovan commented 2 months ago

This stack 5Um4Rg was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+19
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+220
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.selectPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.NarrowestPackageForFile:+1
golang.org/x/tools/gopls/internal/golang.CodeActions:+87
golang.org/x/tools/gopls/internal/server.(*server).CodeAction:+106
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+160
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.22.3 windows/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 1 month ago

This stack yWpCHQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+19
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+220
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedFiles:+33
golang.org/x/tools/gopls/internal/server.(*server).diagnoseSnapshot:+25
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedViews.func1:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.22.4 windows/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 1 month ago

This stack ziMhMQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+19
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+220
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/golang.NarrowestMetadataForFile:+1
golang.org/x/tools/gopls/internal/server.goLinks:+16
golang.org/x/tools/gopls/internal/server.(*server).DocumentLink:+14
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+291
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.22.4 windows/amd64 sublimetext (3)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 1 month ago

This stack 49eF6g was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.buildMetadata:+19
golang.org/x/tools/gopls/internal/cache.(*Snapshot).load:+220
golang.org/x/tools/gopls/internal/cache.(*Snapshot).MetadataForFile:+36
golang.org/x/tools/gopls/internal/cache.(*Snapshot).orphanedFileDiagnostics:+13
golang.org/x/tools/gopls/internal/cache.(*Session).OrphanedFileDiagnostics:+55
golang.org/x/tools/gopls/internal/server.(*server).diagnoseChangedViews:+54
golang.org/x/tools/gopls/internal/server.(*server).didModifyFiles.func2:+1
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 3 weeks ago

This stack rAKLNA was reported by telemetry:

gopls/bug

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 3 weeks ago

This stack rAKLNA was reported by telemetry:

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

adonovan commented 2 weeks ago

This stack bm9HIg was reported by telemetry:

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

siddharthab commented 1 week ago

Hi @adonovan, thank you for keeping this issue open and continuing to investigate.

I was hitting an issue with gopls and traced it down to this bug. A second compiled Go file comes from CGo in my case. Reproduction is fairly simple. Filed it as #69564.

findleyr commented 1 week ago

@siddharthab brilliant, your example reproduces this bug:

> cat main.go
//go:build ignore

package main

import (
        "C"
        "fmt"
)

func main() {
        fmt.Println("hello")
}

> gopackages -json main.go
{
        "ID": "command-line-arguments",
        "Name": "main",
        "PkgPath": "command-line-arguments",
        "GoFiles": [
                "/usr/local/google/home/rfindley/tmp/issue69564/main.go"
        ],
        "CompiledGoFiles": [
                "/usr/local/google/home/rfindley/.cache/go-build/4f/4f33c431ad5b11b8412d2953424eba9d58dbf1d77b3e1615678c780818d41a90-d",
                "/usr/local/google/home/rfindley/.cache/go-build/1f/1fd9171548b0ac0469be2115b2cc31122dcc5b856ff816129e0ff63e07d514e6-d",
                "/usr/local/google/home/rfindley/.cache/go-build/79/79bea79feab5807a48466230c80ae7822f4276a69f3abb41d051d784aa1552e9-d"
        ],
        "Imports": {
                "fmt": "fmt",
                "runtime/cgo": "runtime/cgo",
                "syscall": "syscall",
                "unsafe": "unsafe"
        }
}