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/compile: unreachable panic with GODEBUG=gotypesalias=1 #65778

Closed
mvdan opened this issue Feb 18, 2024 · 15 comments
Closed

cmd/compile: unreachable panic with GODEBUG=gotypesalias=1 #65778

mvdan opened this issue Feb 18, 2024 · 15 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Feb 18, 2024

Go version

go version devel go1.23-86a32d6d9c 2024-02-17 06:03:15 +0000 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/mvdan/.cache/go-build'
GOENV='/home/mvdan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mvdan/go/pkg/mod'
GONOPROXY='github.com/cue-unity'
GONOSUMDB='github.com/cue-unity'
GOOS='linux'
GOPATH='/home/mvdan/go'
GOPRIVATE='github.com/cue-unity'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mvdan/tip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/mvdan/tip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.23-86a32d6d9c 2024-02-17 06:03:15 +0000'
GCCGO='gccgo'
GOAMD64='v3'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -ffile-prefix-map=/tmp/go-build938505312=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Clone https://github.com/mvdan/garble-fork at branch go-alias-panic (9e9c6235febfa5a6ea9d87569ea67d4cca0721a9).

$ export GODEBUG=gotypesalias=1
$ go build

What did you see happen?

# runtime
../../tip/src/runtime/runtime2.go:993:6: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
	../../tip/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0x12a640?, 0xc0?}, {0xdf38ce, 0x10}, {0x0, 0x0, 0x0})
	../../tip/src/cmd/compile/internal/base/print.go:225 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	../../tip/src/cmd/compile/internal/base/print.go:194
cmd/compile/internal/base.Assert(...)
	../../tip/src/cmd/compile/internal/base/print.go:237
cmd/compile/internal/noder.assert(...)
	../../tip/src/cmd/compile/internal/noder/stencil.go:15
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:430
cmd/compile/internal/noder.(*reader).typWrapped(0xc00012a280, 0x1)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*reader).typ(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:382
cmd/compile/internal/noder.(*pkgReader).objIdxMayFail(0xc00204b880, 0x6c, {0x0, 0x0, 0x0}, {0x1591860, 0x0, 0x0}, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:744 +0xca6
cmd/compile/internal/noder.(*pkgReader).objIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:670
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc00204b880, {0xffffffff?, {0x1591860?, 0x13c400000005?, 0xbcdc4e?}}, 0xc002141520, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:662 +0xe7
cmd/compile/internal/noder.(*reader).obj(0xc000127e00)
	../../tip/src/cmd/compile/internal/noder/reader.go:634 +0x46
cmd/compile/internal/noder.(*reader).doTyp(0xc000127e00)
	../../tip/src/cmd/compile/internal/noder/reader.go:500 +0x72
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:429
cmd/compile/internal/noder.(*reader).typWrapped(0xc000127cc0, 0x1)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*reader).typ(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:382
cmd/compile/internal/noder.(*reader).doTyp(0xc000127cc0)
	../../tip/src/cmd/compile/internal/noder/reader.go:516 +0x1af
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:429
cmd/compile/internal/noder.(*reader).typWrapped(0xc000127b80, 0x1)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*reader).typ(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:382
cmd/compile/internal/noder.(*reader).doTyp(0xc000127b80)
	../../tip/src/cmd/compile/internal/noder/reader.go:509 +0x29f
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:429
cmd/compile/internal/noder.(*reader).typWrapped(0xc000127900, 0x1)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*reader).typ(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:382
cmd/compile/internal/noder.(*reader).structType(0xc000127900)
	../../tip/src/cmd/compile/internal/noder/reader.go:589 +0x90
cmd/compile/internal/noder.(*reader).doTyp(0xc000127900)
	../../tip/src/cmd/compile/internal/noder/reader.go:522 +0x35a
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:429
cmd/compile/internal/noder.(*reader).typWrapped(0xc000127680, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*pkgReader).objIdxMayFail(0xc00204b880, 0x493, {0x0, 0x0, 0x0}, {0x1591860, 0x0, 0x0}, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:805 +0x53c
cmd/compile/internal/noder.(*pkgReader).objIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:670
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc00204b880, {0xffffffff?, {0x1591860?, 0x0?, 0xc0020e0840?}}, 0xc002141450, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:662 +0xe7
cmd/compile/internal/noder.(*reader).obj(0xc0001272c0)
	../../tip/src/cmd/compile/internal/noder/reader.go:634 +0x46
cmd/compile/internal/noder.(*reader).doTyp(0xc0001272c0)
	../../tip/src/cmd/compile/internal/noder/reader.go:500 +0x72
cmd/compile/internal/noder.(*pkgReader).typIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:429
cmd/compile/internal/noder.(*reader).typWrapped(0xc000126f00, 0x1)
	../../tip/src/cmd/compile/internal/noder/reader.go:388 +0x4e
cmd/compile/internal/noder.(*reader).typ(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:382
cmd/compile/internal/noder.(*pkgReader).objIdxMayFail(0xc00204b880, 0x8c3, {0x0, 0x0, 0x0}, {0x1591860, 0x0, 0x0}, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:830 +0xb27
cmd/compile/internal/noder.(*pkgReader).objIdx(...)
	../../tip/src/cmd/compile/internal/noder/reader.go:670
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc00204b880, {0xf5d358?, {0x1591860?, 0x45ff09?, 0x10?}}, 0x0, 0x0)
	../../tip/src/cmd/compile/internal/noder/reader.go:662 +0xe7
cmd/compile/internal/noder.(*reader).obj(0xc0000ac3c0)
	../../tip/src/cmd/compile/internal/noder/reader.go:634 +0x46
cmd/compile/internal/noder.(*reader).pkgInitOrder(0xc0000ac3c0, 0xc000002180)
	../../tip/src/cmd/compile/internal/noder/reader.go:3253 +0x5bb
cmd/compile/internal/noder.(*reader).pkgInit(0xc0000ac3c0, 0xc00009c320?, 0xc000002180)
	../../tip/src/cmd/compile/internal/noder/reader.go:3224 +0xd6
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0xc0001ae588?, 0xd312c0?, 0x0?})
	../../tip/src/cmd/compile/internal/noder/unified.go:188 +0x17c
cmd/compile/internal/noder.LoadPackage({0xc000022d38, 0xa1, 0xac})
	../../tip/src/cmd/compile/internal/noder/noder.go:77 +0x43a
cmd/compile/internal/gc.Main(0xe231f0)
	../../tip/src/cmd/compile/internal/gc/main.go:197 +0xbbd
main.main()
	../../tip/src/cmd/compile/main.go:57 +0xf9

What did you expect to see?

No failure, just like without GODEBUG.

I can reproduce by building other modules as well, but I'm just showing one here with a known "bad" commit.

Go 1.22.0 also fails, just with less information:

$ go version
go version go1.22.0 linux/amd64
$ go build
# mvdan.cc/garble
<unknown line number>: internal compiler error: panic: unreachable

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

cc @findleyr @adonovan @griesemer

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 18, 2024
@mvdan
Copy link
Member Author

mvdan commented Feb 18, 2024

The line in runtime2.go appears to be type itab = abi.ITab. I'm a bit surprised that it fails on the runtime, even though GODEBUG=gotypesalias=1 go build runtime appears to work just fine.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 20, 2024
@cuonglm
Copy link
Member

cuonglm commented Feb 21, 2024

@griesemer I think there's also a problem in types2 and go/types. Running gotype also panic:

$ gotype .
panic: unreachable [recovered]
	panic: unreachable [recovered]
	panic: unreachable

goroutine 1 [running]:
main.checkPkgFiles.func2()
	/home/cuonglm/sources/x/tools/cmd/gotype/gotype.go:300 +0x3d
panic({0x61a8e0?, 0x6ba9a8?})
	/home/cuonglm/sources/go/src/runtime/panic.go:759 +0x132
go/types.(*Checker).handleBailout(0xc0000cc200, 0xc002cdbd80)
	/home/cuonglm/sources/go/src/go/types/check.go:368 +0x88
panic({0x61a8e0?, 0x6ba9a8?})
	/home/cuonglm/sources/go/src/runtime/panic.go:759 +0x132
go/types.unreachable(...)
	/home/cuonglm/sources/go/src/go/types/errors.go:33
go/types.(*subster).typ(0xc002cd9120, {0x6bce50, 0xc00083b080})
	/home/cuonglm/sources/go/src/go/types/subst.go:276 +0x150f
go/types.(*subster).typ(0xc002cd9120, {0x6bce28, 0xc000e7e8a0})
	/home/cuonglm/sources/go/src/go/types/subst.go:201 +0x1b8
go/types.(*Checker).subst(0xc0000cc200, 0x0, {0x6bce28, 0xc000e7e8a0}, 0xc001361d10, 0x0, 0xc000e7f800)
	/home/cuonglm/sources/go/src/go/types/subst.go:80 +0x194
go/types.(*Checker).infer(0xc0000cc200, {0x6bbc20, 0xc0004e1b00}, {0xc000b3e0e0, 0x4, 0x4}, {0xc001cec540, 0x4, 0x4}, 0xc0015e2ac8, ...)
	/home/cuonglm/sources/go/src/go/types/infer.go:401 +0x21a5
go/types.(*Checker).arguments(0xc0000cc200, 0xc0004e1b00, 0xc000653640, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, {0xc0014a6520, ...}, ...)
	/home/cuonglm/sources/go/src/go/types/call.go:611 +0xe98
go/types.(*Checker).callExpr(0xc0000cc200, 0xc001cec440, 0xc0004e1b00)
	/home/cuonglm/sources/go/src/go/types/call.go:299 +0x705
go/types.(*Checker).exprInternal(0xc0000cc200, 0x0, 0xc001cec440, {0x6bd528, 0xc0004e1b00}, {0x0, 0x0})
	/home/cuonglm/sources/go/src/go/types/expr.go:1379 +0xf8
go/types.(*Checker).rawExpr(0xc0000cc200, 0x0, 0xc001cec440, {0x6bd528?, 0xc0004e1b00?}, {0x0?, 0x0?}, 0x0)
	/home/cuonglm/sources/go/src/go/types/expr.go:979 +0x19e
go/types.(*Checker).stmt(0xc0000cc200, 0x0, {0x6bd858, 0xc0004bf610})
	/home/cuonglm/sources/go/src/go/types/stmt.go:394 +0x12d
go/types.(*Checker).stmtList(0xc0000cc200, 0x0, {0xc0004e1bc0?, 0x0?, 0x3?})
	/home/cuonglm/sources/go/src/go/types/stmt.go:121 +0x85
go/types.(*Checker).funcBody(0xc0000cc200, 0x6bcc98?, {0xc00045f5e8?, 0xc002c6ee70?}, 0xc000e952c0, 0xc0004e44b0, {0x0?, 0x0?})
	/home/cuonglm/sources/go/src/go/types/stmt.go:41 +0x331
go/types.(*Checker).funcDecl.func1()
	/home/cuonglm/sources/go/src/go/types/decl.go:852 +0x3a
go/types.(*Checker).processDelayed(0xc0000cc200, 0x0)
	/home/cuonglm/sources/go/src/go/types/check.go:468 +0x162
go/types.(*Checker).checkFiles(0xc0000cc200, {0xc000154b90, 0x9, 0x9})
	/home/cuonglm/sources/go/src/go/types/check.go:412 +0x1cc
go/types.(*Checker).Files(...)
	/home/cuonglm/sources/go/src/go/types/check.go:373
go/types.(*Config).Check(0xc000558000, {0x6622d5?, 0x662667?}, 0x80abe0, {0xc000154b90, 0x9, 0x9}, 0x0)
	/home/cuonglm/sources/go/src/go/types/api.go:458 +0x18
main.checkPkgFiles({0xc000154b90, 0x9, 0x9})
	/home/cuonglm/sources/x/tools/cmd/gotype/gotype.go:305 +0x225
main.main()
	/home/cuonglm/sources/x/tools/cmd/gotype/gotype.go:336 +0x15d

@griesemer
Copy link
Contributor

@cuonglm Thanks. I am reproducing this now.

@griesemer griesemer assigned griesemer and unassigned mdempsky Feb 21, 2024
@cuonglm
Copy link
Member

cuonglm commented Feb 21, 2024

@cuonglm Thanks. I am reproducing this now.

To clarify, I do think the problem happens with both types2 and the compiler. The last time I look at this, I was able to have a patch for types2 to make gotype run ok, but the compiler still crash.

It could also be my patch is not good enough and not fixing the root cause in types2.

@griesemer
Copy link
Contributor

subst.go is missing an Unalias call on line 92 I think.

@cuonglm
Copy link
Member

cuonglm commented Feb 21, 2024

subst.go is missing an Unalias call on line 92 I think.

Yeah, I tried adding that missing piece, and gotype run ok. I haven't have time for looking at the cmd/compile issue.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/565835 mentions this issue: go/types, types2: handle Alias types in substitution

gopherbot pushed a commit that referenced this issue Feb 21, 2024
Fixes #65854.
For #65778. // for x/tools/cmd/gotype

Change-Id: I67d4644b28e831926fc6c233098aa1755c57162f
Reviewed-on: https://go-review.googlesource.com/c/go/+/565835
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
@findleyr
Copy link
Contributor

@gopherbot please consider this for backport to 1.22. It is a panic that prevents tool developers from preparing their tool for go/types Aliases.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #65858 (for 1.22).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/565840 mentions this issue: [release-branch.go1.22] go/types, types2: handle Alias types in substitution

@griesemer
Copy link
Contributor

Just to be clear, the cherry-pick only addresses the cmd/gotype issue. The compiler crash is still present.

@griesemer
Copy link
Contributor

@mdempsky This still crashes in the compiler front-end somewhere. Assigning to you for now.

@griesemer griesemer assigned mdempsky and unassigned griesemer Feb 22, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/565995 mentions this issue: cmd/compile: add missing Unalias call when writing type alias

@cuonglm cuonglm self-assigned this Feb 23, 2024
@cuonglm cuonglm added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 23, 2024
@mknyszek mknyszek modified the milestones: Backlog, Go1.23 Feb 28, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/568156 mentions this issue: cmd/internal/testdir: support -godebug

@mvdan
Copy link
Member Author

mvdan commented Feb 29, 2024

Thanks all for the updates. Happy to try GODEBUG=gotypesalias=1 again on master once the fixes have all landed.

gopherbot pushed a commit that referenced this issue Feb 29, 2024
Similar with what we are doing for -goexperiment.

For #65778

Change-Id: I7dda69512a3ffb491e3de31941ae1c3d34fececf
Reviewed-on: https://go-review.googlesource.com/c/go/+/568156
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopherbot pushed a commit that referenced this issue Mar 26, 2024
…itution

Fixes #65858.
For #65778. // for x/tools/cmd/gotype

Change-Id: I67d4644b28e831926fc6c233098aa1755c57162f
Reviewed-on: https://go-review.googlesource.com/c/go/+/565835
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/565840
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

8 participants