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: gopls crash due to monoGraph assertion failure (generics) #53794

Open
474420502 opened this issue Jul 8, 2022 · 6 comments
Open

go/types: gopls crash due to monoGraph assertion failure (generics) #53794

474420502 opened this issue Jul 8, 2022 · 6 comments
Labels
gopls Tools
Milestone

Comments

@474420502
Copy link

@474420502 474420502 commented Jul 8, 2022

gopls version: v0.9.0 (go1.18.3)
gopls flags:
update flags: proxy
extension version: 0.34.1
go version: 1.18.3
environment: Visual Studio Code linux
initialization error: undefined
issue timestamp: Fri, 08 Jul 2022 20:17:06 GMT
restart history:
Fri, 08 Jul 2022 20:16:56 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: assertion failed

goroutine 1212 [running]:
go/types.(*Checker).handleBailout(0xc0029fa380, 0xc003279528)
	  check.go:303  0x8b
panic({0xcc9180, 0x106a6c0})
	  panic.go:838  0x207
go/types.assert(...)
	  errors.go:21
go/types.(*monoGraph).assign.func2({0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:213  0x4ea
go/types.(*monoGraph).assign(0xc00004c2a0%3F, 0x7f37b84d7fff%3F, 0x1%3F, 0x1%3F, {0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:258  0xd1
go/types.(*monoGraph).recordInstance(0x2%3F, 0x5cf957%3F, 0xabd1e5, {0xc002cc62d0, 0x2, 0xcfd2c0%3F}, {0xc0023f2fc0, 0x2, 0x106fd00%3F}, {0x0, ...})
	  mono.go:176  0x69
go/types.(*Checker).instantiateSignature.func2()
	  call.go:90  0x1f5
go/types.(*Checker).processDelayed(0xc0029fa380, 0x11)
	  check.go:388  0x39
panic({0xcc9180, 0x106a6c0})
	  panic.go:844  0x258
go/types.assert(...)
	  errors.go:21
go/types.(*monoGraph).assign.func2({0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:213  0x4ea
go/types.(*monoGraph).assign(0xc00004c2a0%3F, 0xc004337ae0%3F, 0x1%3F, 0x1%3F, {0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:258  0xd1
go/types.(*monoGraph).recordInstance(0x2%3F, 0x5cf957%3F, 0xabd1e5, {0xc002cc62d0, 0x2, 0x106fdc8%3F}, {0xc0023f2fc0, 0x2, 0x106fd00%3F}, {0x0, ...})
	  mono.go:176  0x69
go/types.(*Checker).instantiateSignature.func2()
	  call.go:90  0x1f5
go/types.(*Checker).processDelayed(0xc0029fa380, 0x11)
	  check.go:388  0x39
panic({0xcc9180, 0x106a6c0})
	  panic.go:844  0x258
go/types.assert(...)
	  errors.go:21
go/types.(*monoGraph).assign.func2({0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:213  0x4ea
go/types.(*monoGraph).assign(0xc00004c2a0%3F, 0x0%3F, 0x1%3F, 0x1%3F, {0x106fe68%3F, 0xc003c1bbc0%3F})
	  mono.go:258  0xd1
go/types.(*monoGraph).recordInstance(0x2%3F, 0x404476%3F, 0xabd1e5, {0xc002cc62d0, 0x2, 0xc00333aa00%3F}, {0xc0023f2fc0, 0x2, 0x4105cb%3F}, {0x0, ...})
	  mono.go:176  0x69
go/types.(*Checker).instantiateSignature.func2()
	  call.go:90  0x1f5
go/types.(*Checker).processDelayed(0xc0029fa380, 0x11)
	  check.go:388  0x39
go/types.(*Checker).stmt(0xc0029fa380, 0x3, {0x1071e68%3F, 0xc00333aa40%3F})
	  stmt.go:935  0x28a5
go/types.(*Checker).stmtList(0xc0029fa380%3F, 0x3, {0xc002acb440%3F, 0xdf484a%3F, 0x5%3F})
	  stmt.go:125  0xc9
go/types.(*Checker).stmt(0xc0029fa380, 0x3, {0x1071f88%3F, 0xc003a2a750%3F})
	  stmt.go:559  0x23c6
go/types.(*Checker).stmt(0xc0029fa380, 0x0, {0x10724f8%3F, 0xc003294ff0%3F})
	  stmt.go:930  0x2b97
go/types.(*Checker).stmtList(0xc0029fa380%3F, 0x0, {0xc00333aa80%3F, 0xc0029fa380%3F, 0x106de60%3F})
	  stmt.go:125  0xc9
go/types.(*Checker).funcBody(0xc0029fa380, 0xc002c9dec0, {0x0%3F, 0xc003e45bd8%3F}, 0xc004166d00, 0xc003a2a780, {0x0, 0x0})
	  stmt.go:46  0x285
go/types.(*Checker).funcDecl.func1()
	  decl.go:807  0x45
go/types.(*Checker).processDelayed(0xc0029fa380, 0x0)
	  check.go:388  0x39
go/types.(*Checker).checkFiles(0xc0029fa380, {0xc003148fc0%3F, 0xc003294c80%3F, 0x0%3F})
	  check.go:336  0xcb
go/types.(*Checker).Files(...)
	  check.go:308
golang.org/x/tools/internal/lsp/cache.doTypeCheck({0x1073668, 0xc003298e40}, 0xc000255e60, 0xc000641950, 0x2, 0xc000d87590, 0x0%3F)
	  check.go:552  0x97b
golang.org/x/tools/internal/lsp/cache.typeCheck({0x1073668, 0xc003298e40}, 0xc000255e60, 0xc000641950, 0x2, 0xc000d87590%3F)
	  check.go:318  0xe5
golang.org/x/tools/internal/lsp/cache.(*snapshot).buildPackageHandle.func1({0x1073668%3F, 0xc003298e40}, {0x106ce00%3F, 0xc000255e60})
	  check.go:125  0x233
golang.org/x/tools/internal/memoize.(*Handle).run.func1.1()
	  memoize.go:407  0xa9
runtime/trace.WithRegion({0x1073668%3F, 0xc003298e40%3F}, {0xc0007217d0, 0x21}, 0xc00118b790)
	  annotation.go:141  0xe3
golang.org/x/tools/internal/memoize.(*Handle).run.func1()
	  memoize.go:400  0x135
created by golang.org/x/tools/internal/memoize.(*Handle).run
	  memoize.go:399  0x1aa
[Error - 04:16:58] 

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.

<OPTIONAL: ATTACH LOGS HERE>

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jul 11, 2022

Hi, thanks for the report! Do you recall what you were typing / working on when you encountered this panic?

@474420502
Copy link
Author

@474420502 474420502 commented Jul 11, 2022

@findleyr I remember just ctrl+s, then it panic!

@suzmue suzmue changed the title gopls: automated issue report (crash) x/tools/gopls: gopls crashed on save Jul 11, 2022
@suzmue suzmue transferred this issue from golang/vscode-go Jul 11, 2022
@suzmue suzmue added this to the gopls/v0.9.1 milestone Jul 11, 2022
@gopherbot gopherbot added Tools gopls labels Jul 11, 2022
@gopherbot gopherbot modified the milestones: gopls/v0.9.1, Unreleased Jul 11, 2022
@suzmue suzmue modified the milestones: Unreleased, gopls/v0.9.1 Jul 11, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Jul 11, 2022

@474420502 is this reproducible? This crash is in the type checker, so any details you could share about the generic code you were editing would be very helpful.

@findleyr findleyr changed the title x/tools/gopls: gopls crashed on save x/tools/gopls: type-checking crash on save (generics) Jul 13, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Jul 13, 2022

CC @griesemer @mdempsky

@474420502 any additional information you could share would be incredibly helpful. A crash in the type-checker may be a big deal, and potentially something that we would try to fix for the 1.19 release.

I briefly investigated this crashing stack, and don't yet see how this assertion failure is possible: the assertion suggests that a generic function is somehow instantiated with a type parameter from another package, but I observe:

  1. We panic on the first call to do, which is checking the targ: https://cs.opensource.google/go/go/+/master:src/go/types/mono.go;l=213;drc=bc32dd1b69b0629a54cfe50626e42eb4b75eb017
  2. Unless I'm missing something, we always construct type parameters with check.pkg (search for callers of [nN]ewTypeParam)
  3. Type parameters should always be declared in an inner scope.

With these constraints, I don't see how we could pass a type parameter from another package as a type argument. My best guess is that there may be a bug in type inference allowing a type parameter from the function declaration to be inferred as a type argument.

@474420502
Copy link
Author

@474420502 474420502 commented Jul 13, 2022

@findleyr i can't reproducible this. It probably came up when I converted the tree structure to a generic type.

@findleyr findleyr modified the milestones: gopls/v0.9.1, gopls/v0.9.2 Jul 13, 2022
@findleyr findleyr changed the title x/tools/gopls: type-checking crash on save (generics) go/types: gopls crash due to monoGraph assertion failure (generics) Jul 13, 2022
@findleyr findleyr modified the milestones: gopls/v0.9.2, Go1.20 Jul 13, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Jul 13, 2022

Tentatively marking this for 1.20. We should get to the bottom of this crash, but since it is a crash (and not a miscompilation), and this code has not changed recently, I think it is probably OK to address in 1.20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Tools
Projects
None yet
Development

No branches or pull requests

4 participants