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, types2: stack overflow while type-checking generic code #48619

Open
eliben opened this issue Sep 24, 2021 · 5 comments
Open

go/types, types2: stack overflow while type-checking generic code #48619

eliben opened this issue Sep 24, 2021 · 5 comments
Assignees
Milestone

Comments

@eliben
Copy link
Member

@eliben eliben commented Sep 24, 2021

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

$  gotip version
go version devel go1.18-fe8347b Fri Sep 24 10:51:48 2021 +0000 linux/amd64

What did you do?

Trying to compile this sample: https://go2goplay.golang.org/p/MAplKhfhuKs

What did you expect to see?

The sample is incomplete (I tried to minimize it), so I don't expect it to compile. At the very least, there are calls to functions that don't exist.

The code is also incorrect. In the signature of quickSort_gen_func, a, b should be int, not Elem. Fixing this, the compiler produces an expected error message instead of going into infinite recursion.

What did you see instead?

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc0205e0318 stack=[0xc0205e0000, 0xc0405e0000]
fatal error: stack overflow

runtime stack:
runtime.throw(0x6aa2fc, 0xe)
	/usr/local/go-faketime/src/runtime/panic.go:1126 +0x74
runtime.newstack()
	/usr/local/go-faketime/src/runtime/stack.go:1069 +0x7de
runtime.morestack()
	/usr/local/go-faketime/src/runtime/asm_amd64.s:436 +0x8b

goroutine 1 [running]:
go/types.(*unifier).nifyEq(0xc00058a140, 0x6f32a0, 0xc0000105a0, 0x6f30e8, 0x817000, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/unify.go:197 +0xb8 fp=0xc0205e0328 sp=0xc0205e0320 pc=0x5a6c18
go/types.(*unifier).nify(0xc00058a140, 0x6f32a0, 0xc0000105a0, 0x6f30e8, 0x817000, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/unify.go:238 +0x10f6 fp=0xc0205e0488 sp=0xc0205e0328 pc=0x5a7d16
go/types.(*unifier).nifyEq(0xc00058a140, 0x6f32a0, 0xc0000105a0, 0x6f30e8, 0x817000, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/unify.go:198 +0x70 fp=0xc0205e04d0 sp=0xc0205e0488 pc=0x5a6bd0
go/types.(*unifier).nify(0xc00058a140, 0x6f32a0, 0xc0000105a0, 0x6f30e8, 0x817000, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/unify.go:238 +0x10f6 fp=0xc0205e0630 sp=0xc0205e04d0 pc=0x5a7d16
...
<SNIP>
@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 25, 2021

Smaller reproducer:

package p

func f[P any](a, _ P) {
	f(a, int(0))
}

Compiling leads to an infinite recursion in type inference.

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 28, 2021

Change https://golang.org/cl/352832 mentions this issue: cmd/compile/internal/types2: avoid infinite recursion in unification

@gopherbot gopherbot closed this in 435718e Sep 28, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 29, 2021

Change https://golang.org/cl/353029 mentions this issue: go/types: avoid infinite recursion in unification

gopherbot pushed a commit that referenced this issue Sep 29, 2021
This is an almost clean port of CL 352832 from types2 to go/types:
The nest files and unify.go where copied verbatim; unify.go was
adjusted with correct package name, a slightly different comment
was restored to what it was. The test files got adjustments for
error position. infer.go got a missing _Todo error code.

For #48619.
For #48656.

Change-Id: Ia1a2d09e8bb37a85032b4b7e7c7a0b08e8c793a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/353029
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 7, 2021

Change https://golang.org/cl/354690 mentions this issue: cmd/compile/internal/types2: fix unification (again)

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 8, 2021

The previous fix attempt was incorrect. Re-opening.

@griesemer griesemer reopened this Oct 8, 2021
gopherbot pushed a commit that referenced this issue Oct 8, 2021
…"fix"

The "fix" (CL 352832) for #48619 was incorrect and broke
the unification algorithm in some cases (e.g., #48695).

This CL reverts the changes made by CL 352832 to unify.go,
and comments out code in corresponding tests.

As a result, #48695 will be fixed, and we will re-open #48619.

Fixes #48695.
For #48619.
For #48656.

Change-Id: I91bc492062dbcc8dae7626f6b33f6dfabf48bcb8
Reviewed-on: https://go-review.googlesource.com/c/go/+/354690
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants