golang / go

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

x/tools/gopls: nil panic loading analysisNode.summary #66732

Open jstbyte opened 7 months ago

jstbyte commented 7 months ago

gopls version: v0.15.2/go1.20.1 gopls flags: update flags: proxy extension version: 0.41.2 environment: Visual Studio Code win32 initialization error: undefined issue timestamp: Sun, 07 Apr 2024 03:13:55 GMT restart history: Sun, 07 Apr 2024 03:01:06 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x40 pc=0x163a7fc]

goroutine 186 [running]:
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze(0x0, {0x1e17ad8, 0xc00082df50}, 0xc000219bf0, {0xc00017f800, 0xcc, 0xc000867d88%3F}, 0xc00048ea20)
      analysis.go:461  0x139c
golang.org/x/tools/gopls/internal/golang.Analyze({0x1e17ad8, 0xc00082df50}, 0xc00007e240, 0xc0005a5560%3F, 0x1a4f8a0%3F)
      diagnostics.go:42  0x16b
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6()
      diagnostics.go:507  0xc5
created by golang.org/x/tools/gopls/internal/server.(*server).diagnose
      diagnostics.go:502  0x10a5
gopls stats -anon { "DirStats": { "Files": 2, "TestdataFiles": 0, "GoFiles": 1, "ModFiles": 1, "Dirs": 1 }, "GOARCH": "amd64", "GOOS": "windows", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.20.1", "GoplsVersion": "v0.15.2", "InitialWorkspaceLoadDuration": "1.8348831s", "MemStats": { "HeapAlloc": 2531088, "HeapInUse": 5169152, "TotalAlloc": 12289392 }, "WorkspaceStats": { "Files": { "Total": 2, "Largest": 60, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.2", "AllPackages": { "Packages": 1, "LargestPackage": 1, "CompiledGoFiles": 1, "Modules": 1 }, "WorkspacePackages": { "Packages": 1, "LargestPackage": 1, "CompiledGoFiles": 1, "Modules": 1 }, "Diagnostics": 0 } ] } }
OPTIONAL: If you would like to share more information, you can attach your complete gopls logs. NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE. DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY. Dups: 3DjTOg
findleyr commented 7 months ago

CC @adonovan: another mysterious case where analysisNode.summary may be nil.

adonovan commented 7 months ago

It's definitely the summary and not the root that is nil.

xtools$ git co  gopls/v0.15.2
xtools$ GOOS=windows GOARCH=amd64 GOTOOLCHAIN=go1.20.1 go build -o x ./gopls
xtools$ go tool objdump -S x | less
...
  0xa7a81c              48898c2470010000        MOVQ CX, 0x170(SP)      
                        srcAnalyzer, ok := toSrc[a]
  0xa7a824              488d05155a4000          LEAQ type:*+799296(SB), AX              
  0xa7a82b              488d9c2448030000        LEAQ 0x348(SP), BX                      
  0xa7a833              e8487f99ff              CALL runtime.mapaccess2_fast64(SB)      
  0xa7a838              488b10                  MOVQ 0(AX), DX                          
  0xa7a83b              0f1f440000              NOPL 0(AX)(AX*1)                        
  0xa7a840              84db                    TESTL BL, BL                            
                        if !ok {
  0xa7a842              0f84b0000000            JE 0xa7a8f8             
                        srcAnalyzer, ok := toSrc[a]
  0xa7a848              48899424f8000000        MOVQ DX, 0xf8(SP) // spill srcAnalyzer     
                        summary, ok := root.summary.Actions[stableNames[a]]
  0xa7a850              488b942408010000        MOVQ 0x108(SP), DX                      
  0xa7a858              488b7278                MOVQ 0x78(DX), SI  // load root.summary             
  0xa7a85c              488b7640                MOVQ 0x40(SI), SI // load analyzeSummary.Actions <-- SEGV here
  0xa7a860              4889b42498010000        MOVQ SI, 0x198(SP)                      
  0xa7a868              488b8c2470010000        MOVQ 0x170(SP), CX                      
  0xa7a870              488d05e95a4000          LEAQ type:*+799584(SB), AX     // type for stableNames map             
  0xa7a877              488b9c24f0000000        MOVQ 0xf0(SP), BX                       
  0xa7a87f              90                      NOPL                                    
  0xa7a880              e85b7d99ff              CALL runtime.mapaccess1_fast64(SB)      

(Lovin' the new hover size/offset feature!)

gopherbot commented 7 months ago

Change https://go.dev/cl/577435 mentions this issue: gopls/internal/cache: add debug assertions to refine golang/go#66732

gopherbot commented 7 months ago

Change https://go.dev/cl/577596 mentions this issue: [gopls-release-branch.0.15] gopls/internal/cache: add debug assertions to refine golang/go#66732

adonovan commented 2 months ago

This stack 3DjTOg was reported by telemetry:

"root analysisNode has nil summary"

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Report:=68
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze:+263
golang.org/x/tools/gopls/internal/golang.Analyze:+12
golang.org/x/tools/gopls/internal/server.(*server).diagnose.func6:+5
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.2-pre.1 go1.22.2 linux/amd64 other,vscode-insiders (1)

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

findleyr commented 2 weeks ago

This may still be a problem but I'm bumping to v0.18.0 as the analysis driver has changed significantly; let's reevaluate after v0.17.0.