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

cmd/go2go: assertion failed in unifier.nify #40038

Closed
tdakkota opened this issue Jul 4, 2020 · 5 comments
Closed

cmd/go2go: assertion failed in unifier.nify #40038

tdakkota opened this issue Jul 4, 2020 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tdakkota
Copy link

tdakkota commented Jul 4, 2020

What version of Go are you using (go version)?

$ go version
go version devel +34f76220c3 Sat Jul 4 04:55:49 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

n/a

What operating system and processor architecture are you using (go env)?

  • Go2go playground
  • windows/amd64

What did you do?

https://go2goplay.golang.org/p/JXCEVdUcw-2

What did you expect to see?

Successful compilation or some error.
I don't know should or should't this example compile, but type checker should not panic.

What did you see instead?

Stack trace:

panic: assertion failed [recovered]
	panic: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc0001046c0, 0xc000077be0)
	G:/workspace/exprm/go/src/go/types/check.go:251 +0x9f
panic(0x101ff20, 0x10b5700)
	G:/workspace/exprm/go/src/runtime/panic.go:969 +0x176
go/types.assert(...)
	G:/workspace/exprm/go/src/go/types/errors.go:19
go/types.(*unifier).nify(0xc000052780, 0x10c17a0, 0xc00003eba0, 0x10c1200, 0xc00007e2d0, 0x0, 0x0)
	G:/workspace/exprm/go/src/go/types/unify.go:368 +0x18e5
go/types.(*unifier).nify(0xc000052780, 0x10c15c0, 0xc00014e440, 0x10c15c0, 0xc00014ed00, 0x0, 0xf09093)
	G:/workspace/exprm/go/src/go/types/unify.go:261 +0xd07
go/types.(*unifier).nify(0xc000052780, 0x10c1340, 0xc00003eae0, 0x10c1340, 0xc00003f740, 0x0, 0xc000052780)
	G:/workspace/exprm/go/src/go/types/unify.go:278 +0xb3f
go/types.(*unifier).unify(0xc000052780, 0x10c1340, 0xc00003eae0, 0x10c1340, 0xc00003f740, 0xc00000a650)
	G:/workspace/exprm/go/src/go/types/unify.go:38 +0x65
go/types.(*Checker).missingMethod(0xc0001046c0, 0x10c1200, 0xc00007e2d0, 0xc00010a900, 0xc00014ec01, 0x10c10c0, 0xc00010a900)
	G:/workspace/exprm/go/src/go/types/lookup.go:418 +0x393
go/types.(*Checker).instantiate(0xc0001046c0, 0x306, 0x10c1340, 0xc00003f1a0, 0xc000153280, 0x4, 0x4, 0xc000010880, 0x4, 0x4, ...)
	G:/workspace/exprm/go/src/go/types/subst.go:165 +0x8b6
go/types.(*Checker).call(0xc0001046c0, 0xc000153140, 0xc00003d680, 0x1230e20)
	G:/workspace/exprm/go/src/go/types/call.go:116 +0x339
go/types.(*Checker).exprInternal(0xc0001046c0, 0xc000153140, 0x10bd540, 0xc00003d680, 0x0, 0x0, 0x10c12a0)
	G:/workspace/exprm/go/src/go/types/expr.go:1576 +0x1df0
go/types.(*Checker).rawExpr(0xc0001046c0, 0xc000153140, 0x10bd540, 0xc00003d680, 0x0, 0x0, 0x0)
	G:/workspace/exprm/go/src/go/types/expr.go:1033 +0xc7
go/types.(*Checker).exprOrType(0xc0001046c0, 0xc000153140, 0x10bd540, 0xc00003d680)
	G:/workspace/exprm/go/src/go/types/expr.go:1724 +0x5c
go/types.(*Checker).call(0xc0001046c0, 0xc000153140, 0xc00003d740, 0x230dcfab748)
	G:/workspace/exprm/go/src/go/types/call.go:17 +0x78
go/types.(*Checker).exprInternal(0xc0001046c0, 0xc000153140, 0x10bd540, 0xc00003d740, 0x0, 0x0, 0x38)
	G:/workspace/exprm/go/src/go/types/expr.go:1576 +0x1df0
go/types.(*Checker).rawExpr(0xc0001046c0, 0xc000153140, 0x10bd540, 0xc00003d740, 0x0, 0x0, 0x0)
	G:/workspace/exprm/go/src/go/types/expr.go:1033 +0xc7
go/types.(*Checker).stmt(0xc0001046c0, 0x0, 0x10bd7c0, 0xc000032e30)
	G:/workspace/exprm/go/src/go/types/stmt.go:330 +0x3e78
go/types.(*Checker).stmtList(0xc0001046c0, 0x0, 0xc000032e40, 0x1, 0x1)
	G:/workspace/exprm/go/src/go/types/stmt.go:125 +0xd6
go/types.(*Checker).funcBody(0xc0001046c0, 0xc00003e720, 0xc00000a6d8, 0x4, 0xc00003f440, 0xc000067e90, 0x0, 0x0)
	G:/workspace/exprm/go/src/go/types/stmt.go:42 +0x268
go/types.(*Checker).funcDecl.func1()
	G:/workspace/exprm/go/src/go/types/decl.go:792 +0x6e
go/types.(*Checker).processDelayed(0xc0001046c0, 0x0)
	G:/workspace/exprm/go/src/go/types/check.go:315 +0x45
go/types.(*Checker).checkFiles(0xc0001046c0, 0xc000077cb8, 0x1, 0x1, 0x0, 0x0)
	G:/workspace/exprm/go/src/go/types/check.go:283 +0x14d
go/types.(*Checker).Files(...)
	G:/workspace/exprm/go/src/go/types/check.go:256
go/types.(*Config).Check(0xc00003d780, 0xc00000a4d0, 0x4, 0xc00003c280, 0xc000077cb8, 0x1, 0x1, 0xc000041360, 0x0, 0xc000142000, ...)
	G:/workspace/exprm/go/src/go/types/api.go:387 +0x188
go/go2go.RewriteBuffer(0xc00003e2a0, 0xc00000e360, 0x26, 0xc000144000, 0x355, 0x555, 0x0, 0xc000066ba0, 0xc000066b70, 0xc000066b40, ...)
	G:/workspace/exprm/go/src/go/go2go/go2go.go:137 +0x25b
main.translateFile(0xc00003e2a0, 0xc00000e360, 0x26)
	G:/workspace/exprm/go/src/cmd/go2go/translate.go:26 +0xb0
main.main()
	G:/workspace/exprm/go/src/cmd/go2go/main.go:65 +0x30a
@thepudds
Copy link
Contributor

thepudds commented Jul 4, 2020

Hi @tdakkota, thanks for filing this as well.

In the current version of the go2go playground, your example fails on an assertion in go/types.(*unifier).nify on line 351 of go/types/unify.go.

Just a quick comment that Crash 24 from #39634 (comment) also crashes on the same assert on the same line 351 of go/types/unify.go.

That said, the call stacks leading up to the assert are fairly different between your example vs. Crash 24, so might not be the same core issue.

In any event, just wanted to mention this in case it helps with triage.

Current playground stacktrace for @tdakkota example

panic: assertion failed [recovered]
panic: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc000084900, 0xc0000f1be0)
/usr/local/go-faketime/src/go/types/check.go:251 +0x98
panic(0x6498a0, 0x6db5e0)
/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
go/types.assert(...)
/usr/local/go-faketime/src/go/types/errors.go:19
go/types.(*unifier).nify(0xc000098780, 0x6e6f20, 0xc00004aae0, 0x6e6980, 0xc00007e240, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/unify.go:351 +0x18c5
go/types.(*unifier).nify(0xc000098780, 0x6e6d40, 0xc00000d920, 0x6e6d40, 0xc0000e81a0, 0x0, 0x537953)
/usr/local/go-faketime/src/go/types/unify.go:244 +0xce7
go/types.(*unifier).nify(0xc000098780, 0x6e6ac0, 0xc00004aa20, 0x6e6ac0, 0xc00004b620, 0x0, 0xc000098780)
/usr/local/go-faketime/src/go/types/unify.go:261 +0xb1f
go/types.(*unifier).unify(0xc000098780, 0x6e6ac0, 0xc00004aa20, 0x6e6ac0, 0xc00004b620, 0xc00001a520)
/usr/local/go-faketime/src/go/types/unify.go:38 +0x5c
go/types.(*Checker).missingMethod(0xc000084900, 0x6e6980, 0xc00007e240, 0xc00008c980, 0xc0000e8101, 0x6e6840, 0xc00008c980)
/usr/local/go-faketime/src/go/types/lookup.go:418 +0x393
go/types.(*Checker).instantiate(0xc000084900, 0x296, 0x6e6ac0, 0xc00004b0e0, 0xc0000e4a40, 0x4, 0x4, 0xc000016400, 0x4, 0x4, ...)
/usr/local/go-faketime/src/go/types/subst.go:164 +0x896
go/types.(*Checker).call(0xc000084900, 0xc0000e4900, 0xc00007b240, 0x0)
/usr/local/go-faketime/src/go/types/call.go:109 +0x325
go/types.(*Checker).exprInternal(0xc000084900, 0xc0000e4900, 0x6e32a0, 0xc00007b240, 0x0, 0x0, 0xc00000d620)
/usr/local/go-faketime/src/go/types/expr.go:1569 +0x1dd0
go/types.(*Checker).rawExpr(0xc000084900, 0xc0000e4900, 0x6e32a0, 0xc00007b240, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).exprOrType(0xc000084900, 0xc0000e4900, 0x6e32a0, 0xc00007b240)
/usr/local/go-faketime/src/go/types/expr.go:1717 +0x55
go/types.(*Checker).call(0xc000084900, 0xc0000e4900, 0xc00007b300, 0x7f667791d6c0)
/usr/local/go-faketime/src/go/types/call.go:17 +0x69
go/types.(*Checker).exprInternal(0xc000084900, 0xc0000e4900, 0x6e32a0, 0xc00007b300, 0x0, 0x0, 0x38)
/usr/local/go-faketime/src/go/types/expr.go:1569 +0x1dd0
go/types.(*Checker).rawExpr(0xc000084900, 0xc0000e4900, 0x6e32a0, 0xc00007b300, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).stmt(0xc000084900, 0x0, 0x6e3520, 0xc00001cc50)
/usr/local/go-faketime/src/go/types/stmt.go:330 +0x3e78
go/types.(*Checker).stmtList(0xc000084900, 0x0, 0xc00001cc60, 0x1, 0x1)
/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).funcBody(0xc000084900, 0xc00004a7e0, 0xc00001a5a8, 0x4, 0xc00004b380, 0xc0000118f0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/stmt.go:42 +0x257
go/types.(*Checker).funcDecl.func1()
/usr/local/go-faketime/src/go/types/decl.go:790 +0x67
go/types.(*Checker).processDelayed(0xc000084900, 0x0)
/usr/local/go-faketime/src/go/types/check.go:315 +0x3e
go/types.(*Checker).checkFiles(0xc000084900, 0xc0000c9cb8, 0x1, 0x1, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/check.go:283 +0x145
go/types.(*Checker).Files(...)
/usr/local/go-faketime/src/go/types/check.go:256
go/types.(*Config).Check(0xc00007b340, 0xc00001a3e0, 0x4, 0xc00007a240, 0xc0000c9cb8, 0x1, 0x1, 0xc000055360, 0x0, 0x4b702f, ...)
/usr/local/go-faketime/src/go/types/api.go:387 +0x188
go/go2go.RewriteBuffer(0xc00004a3c0, 0x7ffe1dcd0dec, 0x1e, 0xc0000c2000, 0x2e5, 0x4e5, 0x0, 0xc000010a50, 0xc000010a20, 0xc0000109f0, ...)
/usr/local/go-faketime/src/go/go2go/go2go.go:137 +0x24f
main.translateFile(0xc00004a3c0, 0x7ffe1dcd0dec, 0x1e)
/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()

Current playground stacktrace for Crash 24 example
panic: assertion failed [recovered]
	panic: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc00007c900, 0xc0000c3be0)
/usr/local/go-faketime/src/go/types/check.go:251 +0x98
panic(0x6498a0, 0x6db5e0)
/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
go/types.assert(...)
/usr/local/go-faketime/src/go/types/errors.go:19
go/types.(*unifier).nify(0xc000090320, 0x6e6f20, 0xc00004a600, 0x6e6980, 0xc00007a240, 0x0, 0xc0000c1420)
/usr/local/go-faketime/src/go/types/unify.go:351 +0x18c5
go/types.(*unifier).unify(...)
/usr/local/go-faketime/src/go/types/unify.go:38
go/types.(*Checker).infer(0xc00007c900, 0x25, 0xc00000e0d8, 0x1, 0x1, 0xc0000c1730, 0xc0000c16e8, 0x1, 0x1, 0xc00001a430, ...)
/usr/local/go-faketime/src/go/types/infer.go:52 +0x36a
go/types.(*Checker).selector(0xc00007c900, 0xc000072600, 0xc00000c380)
/usr/local/go-faketime/src/go/types/call.go:529 +0xdfa
go/types.(*Checker).exprInternal(0xc00007c900, 0xc000072600, 0x6e3a20, 0xc00000c380, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1320 +0x29cc
go/types.(*Checker).rawExpr(0xc00007c900, 0xc000072600, 0x6e3a20, 0xc00000c380, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).exprOrType(0xc00007c900, 0xc000072600, 0x6e3a20, 0xc00000c380)
/usr/local/go-faketime/src/go/types/expr.go:1717 +0x55
go/types.(*Checker).call(0xc00007c900, 0xc000072600, 0xc0000723c0, 0x0)
/usr/local/go-faketime/src/go/types/call.go:17 +0x69
go/types.(*Checker).exprInternal(0xc00007c900, 0xc000072600, 0x6e32a0, 0xc0000723c0, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1569 +0x1dd0
go/types.(*Checker).rawExpr(0xc00007c900, 0xc000072600, 0x6e32a0, 0xc0000723c0, 0x0, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).multiExpr(0xc00007c900, 0xc000072600, 0x6e32a0, 0xc0000723c0)
/usr/local/go-faketime/src/go/types/expr.go:1692 +0x51
go/types.(*Checker).exprList(0xc00007c900, 0xc00001c580, 0x1, 0x1, 0x81bb00, 0x7fe5ecc14108, 0x0, 0x50, 0xc000055860)
/usr/local/go-faketime/src/go/types/call.go:206 +0xb4
go/types.(*Checker).initVars(0xc00007c900, 0xc00000e0f8, 0x1, 0x1, 0xc00001c580, 0x1, 0x1, 0x0)
/usr/local/go-faketime/src/go/types/assignments.go:214 +0x94
go/types.(*Checker).shortVarDecl(0xc00007c900, 0x35, 0xc00001c560, 0x1, 0x1, 0xc00001c580, 0x1, 0x1)
/usr/local/go-faketime/src/go/types/assignments.go:326 +0x27e
go/types.(*Checker).stmt(0xc00007c900, 0x0, 0x6e30a0, 0xc000072400)
/usr/local/go-faketime/src/go/types/stmt.go:403 +0x351d
go/types.(*Checker).stmtList(0xc00007c900, 0x0, 0xc00001c590, 0x1, 0x1)
/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).funcBody(0xc00007c900, 0xc00004a540, 0x809ce8, 0x1, 0xc00004a5a0, 0xc000010c00, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/stmt.go:42 +0x257
go/types.(*Checker).funcDecl.func1()
/usr/local/go-faketime/src/go/types/decl.go:790 +0x67
go/types.(*Checker).processDelayed(0xc00007c900, 0x0)
/usr/local/go-faketime/src/go/types/check.go:315 +0x3e
go/types.(*Checker).checkFiles(0xc00007c900, 0xc00003dcb8, 0x1, 0x1, 0x0, 0x0)
/usr/local/go-faketime/src/go/types/check.go:283 +0x145
go/types.(*Checker).Files(...)
/usr/local/go-faketime/src/go/types/check.go:256
go/types.(*Config).Check(0xc000072440, 0xc00001a3e0, 0x4, 0xc000072240, 0xc00003dcb8, 0x1, 0x1, 0xc000055360, 0x0, 0x4b702f, ...)
/usr/local/go-faketime/src/go/types/api.go:387 +0x188
go/go2go.RewriteBuffer(0xc00004a3c0, 0x7ffd9c5d6dec, 0x1e, 0xc0000ba000, 0x3f, 0x23f, 0x0, 0xc000010a50, 0xc000010a20, 0xc0000109f0, ...)
/usr/local/go-faketime/src/go/go2go/go2go.go:137 +0x24f
main.translateFile(0xc00004a3c0, 0x7ffd9c5d6dec, 0x1e)
/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()

cc @griesemer

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 4, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jul 4, 2020
@tdakkota
Copy link
Author

tdakkota commented Jul 7, 2020

I tried change

go/src/go/types/unify.go

Lines 363 to 368 in 9d9619a

if y, ok := y.(*Named); ok {
// TODO(gri) This is not always correct: two types may have the same names
// in the same package if one of them is nested in a function.
// Extremely unlikely but we need an always correct solution.
if x.obj.pkg == y.obj.pkg && x.obj.name == y.obj.name {
assert(len(x.targs) == len(y.targs))

to

		if y, ok := y.(*Named); ok {
			// TODO(gri) This is not always correct: two types may have the same names
			//           in the same package if one of them is nested in a function.
			//           Extremely unlikely but we need an always correct solution.
			if x.obj.pkg == y.obj.pkg && x.obj.name == y.obj.name {
				if len(x.targs) != len(y.targs) {
					return false
				}

It's should fix both crash cases.

It happens because type checker fails to infer types

func main() {
	Map(string, int, Optional, Optional)("1", func(s string) int { // here: Optional(T)
		return 1
	})
}                               

and

package main
type C(type P) P
func (r C(P)) m() { y := C.m() } // here: C(P)

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/247498 mentions this issue: [dev.go2go] go/types: fix instantiation crash for generic type parame…

tdakkota added a commit to tdakkota/go that referenced this issue Aug 11, 2020
gopherbot pushed a commit that referenced this issue Aug 11, 2020
…ters

Fixes #40038.

Change-Id: I5b095d01fd1e3703561c179c34ddc3b43d7510f6
GitHub-Last-Rev: 3e5067a
GitHub-Pull-Request: #40644
Reviewed-on: https://go-review.googlesource.com/c/go/+/247498
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@griesemer
Copy link
Contributor

Fixed by https://golang.org/cl/247498.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/248058 mentions this issue: [dev.go2go] cmd/compile/internal/types2: fix instantiation crash for generic type parameters

gopherbot pushed a commit that referenced this issue Aug 12, 2020
…generic type parameters

Port of go/types CL https://golang.org/cl/247498.

Updates #40038.

Change-Id: Iab002132627b689e0113c087b3f4d38c6356c3a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/248058
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants