Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, x/tools/gopls: crash when editing gioui.org/app/os_x11.go #59944

Closed
kortschak opened this issue May 3, 2023 · 11 comments
Closed

go/types, x/tools/gopls: crash when editing gioui.org/app/os_x11.go #59944

kortschak opened this issue May 3, 2023 · 11 comments
Assignees
Labels
FrozenDueToAge gopls/incremental gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@kortschak
Copy link
Contributor

gopls version

2563079

go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/user/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/pkg/mod"
GONOPROXY="git.sr.ht"
GONOSUMDB="git.sr.ht"
GOOS="linux"
GOPATH="/home/user"
GOPRIVATE="git.sr.ht"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/user/src/gioui.org/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3558781779=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Open gioui.org/app/os_x11.go at 59695984e53cff7ed440b054318dbd421285421e in Sublime Text.
  2. Wait
  3. Crash

What did you expect to see?

No crash.

What did you see instead?

:: <-  gopls window/logMessage: {'message': '2023/05/03 19:58:23 go/packages.Load #1: updating metadata for 209 packages\n', 'type': 3}
:: <-  gopls $/progress: {'value': {'message': 'Finished loading packages.', 'kind': 'end'}, 'token': '1223999446160520122'}
:: <-- gopls client/registerCapability(3): {'registrations': [{'id': 'workspace/didChangeConfiguration', 'method': 'workspace/didChangeConfiguration'}]}
:: >>> gopls 3: None
:: <-  gopls textDocument/publishDiagnostics: {'diagnostics': [], 'uri': 'file:///.../src/gioui.org/app/os_x11.go'}
:: <-  gopls textDocument/publishDiagnostics: {'diagnostics': [{'codeDescription': {'href': 'https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#MissingFieldOrMethod'}, 'message': 'caps.MinExtent undefined (type vk._Ctype_struct_VkSurfaceCapabilitiesKHR has no field or method MinExtent)', 'severity': 1, 'code': 'MissingFieldOrMethod', 'range': {'end': {'line': 177, 'character': 33}, 'start': {'line': 177, 'character': 24}}, 'source': 'compiler'}, {'codeDescription': {'href': 'https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#MissingFieldOrMethod'}, 'message': 'caps.MaxExtent undefined (type vk._Ctype_struct_VkSurfaceCapabilitiesKHR has no field or method MaxExtent)', 'severity': 1, 'code': 'MissingFieldOrMethod', 'range': {'end': {'line': 177, 'character': 51}, 'start': {'line': 177, 'character': 42}}, 'source': 'compiler'}], 'uri': 'file:///.../src/gioui.org/app/vulkan.go'}
gopls: panic: couldn't find method func (*gioui.org/shader/piet._Ctype_struct_backdrop_descriptor_set_layout).Binding0() *gioui.org/cpu._Ctype_struct_buffer_descriptor on type gioui.org/shader/piet._Ctype_struct_backdrop_descriptor_set_layout
gopls: 
gopls: goroutine 3355 [running]:
gopls: golang.org/x/tools/go/types/objectpath.(*Encoder).concreteMethod(0xc0046a9b70?, 0xc004f59980)
gopls: 	.../src/golang.org/x/tools/go/types/objectpath/objectpath.go:421 +0x2fb
gopls: golang.org/x/tools/go/types/objectpath.(*Encoder).For(0xc003be5be8?, {0x116dd38, 0xc004f59980})
gopls: 	.../src/golang.org/x/tools/go/types/objectpath/objectpath.go:244 +0x2e5
gopls: golang.org/x/tools/go/types/objectpath.For(...)
gopls: 	.../src/golang.org/x/tools/go/types/objectpath/objectpath.go:120
gopls: golang.org/x/tools/internal/facts.(*Set).Encode(0xc0059ff110)
gopls: 	.../src/golang.org/x/tools/internal/facts/facts.go:260 +0x17f
gopls: golang.org/x/tools/gopls/internal/lsp/cache.(*action).exec(0xc000352fc0)
gopls: 	.../src/golang.org/x/tools/gopls/internal/lsp/cache/analysis.go:1113 +0xcbf
gopls: golang.org/x/tools/gopls/internal/lsp/cache.execActions.func1.1()
gopls: 	.../src/golang.org/x/tools/gopls/internal/lsp/cache/analysis.go:898 +0x3c
gopls: sync.(*Once).doSlow(0xc002658c00?, 0x95e360?)
gopls: 	.../go/src/sync/once.go:74 +0xc2
gopls: sync.(*Once).Do(...)
gopls: 	.../go/src/sync/once.go:65
gopls: golang.org/x/tools/gopls/internal/lsp/cache.execActions.func1()
gopls: 	.../src/golang.org/x/tools/gopls/internal/lsp/cache/analysis.go:896 +0x85
gopls: created by golang.org/x/tools/gopls/internal/lsp/cache.execActions
gopls: 	.../src/golang.org/x/tools/gopls/internal/lsp/cache/analysis.go:894 +0x3c

Editor and settings

Sublime Text.

Logs

Above.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels May 3, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 3, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.0 May 3, 2023
@findleyr
Copy link
Contributor

findleyr commented May 3, 2023

CC @mdempsky @griesemer @adonovan

Somehow we have a method on a cgo type that is not recorded on its receiver. This looks like a go/types bug. Note that gopls uses the hidden types.Config.go115UsesCgo.

I'll avoid the panic for now. Haven't yet found the bug.

@findleyr
Copy link
Contributor

findleyr commented May 3, 2023

Oh! I think I found it.

We need to consider the Ctype prefix here:
https://cs.opensource.google/go/go/+/master:src/go/types/resolver.go;l=611;drc=804d786a30c664df63ef1e0c95d44772063afae1

Otherwise, we will not find the root object to add the Binding0 method to:
https://git.sr.ht/~eliasnaur/gio-shader/tree/main/item/piet/elements_abi.go#L29

@findleyr findleyr self-assigned this May 3, 2023
@findleyr findleyr changed the title x/tools/gopls: crash when editing gioui.org/app/os_x11.go go/types, x/tools/gopls: crash when editing gioui.org/app/os_x11.go May 3, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/492315 mentions this issue: go/types/objectpath: don't panic when receiver is missing a method

gopherbot pushed a commit to golang/tools that referenced this issue May 9, 2023
Due to a long-standing bug in go/types, the objectpath package cannot
find methods declared on aliases of cgo types.

We should fix the bug in go/types, but also must avoid the panic in
gopls as this fix will not be back-ported to all supported Go versions.

Updates golang/go#59944

Change-Id: I42d94e610ad92d258c8034d59ea3b0ef312ddebb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/492315
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/493877 mentions this issue: go/types: resolve cgo base type names

@mdempsky
Copy link
Member

mdempsky commented May 9, 2023

While gopls probably shouldn't crash, note that it's not intended that users are allowed to declare methods on C types anyway. E.g., see #57926.

@findleyr
Copy link
Contributor

findleyr commented May 9, 2023

@mdempsky thanks. I was unaware of that discussion. CC @adonovan

Unfortunate timing; I wonder if we should support this in go/types anyway.

But now that I look at it, I'm not sure why gopls even needs the go115UsesCgo field on types.Config, since it operates on CompiledGoFiles anyway.

Matthew: do you think we could eliminate this configuration?

@findleyr findleyr modified the milestones: gopls/v0.12.0, Go1.21 May 9, 2023
@kortschak
Copy link
Contributor Author

@mdempsky I took a look at the code base that raised this and could not find any instance of either a direct method declaration on a C type, or via a type alias, though this #57926 (comment) suggests that it's not an alien concept in gio.

@findleyr
Copy link
Contributor

findleyr commented May 9, 2023

@kortschak the reference is in the gio-shader dependency here:
https://git.sr.ht/~eliasnaur/gio-shader/tree/main/item/piet/elements_abi.go#L29

The panic occured while recording analysis facts for this package.

@kortschak
Copy link
Contributor Author

Thanks.

@heschi
Copy link
Contributor

heschi commented May 17, 2023

@findleyr is this a Go release blocker for 1.21? Or only a gopls release blocker, which I think is now fixed?

@findleyr
Copy link
Contributor

Not a release blocker, sorry (though it will be fixed before the freeze).

@golang golang locked and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls/incremental gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants