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: Go1.22RC1 compiler crash when using GOEXPERIMENT=rangefunc #64930

Closed
bolazec opened this issue Jan 2, 2024 · 6 comments
Closed
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. release-blocker
Milestone

Comments

@bolazec
Copy link

bolazec commented Jan 2, 2024

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

$ go version
go version devel go1.22-fe1b2f95e6 Fri Dec 8 23:05:48 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

This problem happens with go1.22rc1 when using GOEXPERIMENT=rangefunc

#61405

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

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/rafter/.cache/go-build'
GOENV='/home/rafter/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/rafter/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/rafter/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/rafter/go-compilers/go-tip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/rafter/go-compilers/go-tip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.22-fe1b2f95e6 Fri Dec 8 23:05:48 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
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-build12169918115877555041=/tmp/go-build -gno-record-gcc-switches'
GOROOT/bin/go version: go version devel go1.22-fe1b2f95e6 Fri Dec 8 23:05:48 2023 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.22-fe1b2f95e6 Fri Dec 8 23:05:48 2023 +0000
uname -sr: Linux 5.4.0-169-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.6 LTS
Release:	20.04
Codename:	focal
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.14) stable release version 2.31.
gdb --version: GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2

See the program at https://go.dev/play/p/KyQscllQkMW

With GOEXPERIMENT=rangefunc this program compiles and runs correctly,
which shows that the types and functions are all OK.

However when the commented out for loop is re-enabled the program causes a compiler crash.

What did you expect to see?

No compiler crash, and a program that runs.

What did you see instead?

Compiler Output ...
# example.com/iterators/bugs/bug-1-seq2
: internal compiler error: panic: interface conversion: syntax.Type is *types2.Named, not *types2.Signature

goroutine 1 [running]:
runtime/debug.Stack()
../../../../go-compilers/go-tip/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0x44a750?, 0xc0?}, {0xdf1b09, 0x9}, {0xc00044a780, 0x1, 0x1})
../../../../go-compilers/go-tip/src/cmd/compile/internal/base/print.go:225 +0x1d7
cmd/compile/internal/base.Fatalf(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/base/print.go:194
cmd/compile/internal/gc.handlePanic()
../../../../go-compilers/go-tip/src/cmd/compile/internal/gc/main.go:52 +0x90
panic({0xd72320?, 0xc000443890?})
../../../../go-compilers/go-tip/src/runtime/panic.go:770 +0x132
cmd/compile/internal/rangefunc.(*rewriter).endLoop(0xc000154400, 0xc00044e4c0)
../../../../go-compilers/go-tip/src/cmd/compile/internal/rangefunc/rewrite.go:937 +0xa3b
cmd/compile/internal/rangefunc.(*rewriter).inspect(0xc000154400, {0x0?, 0x0?})
../../../../go-compilers/go-tip/src/cmd/compile/internal/rangefunc/rewrite.go:610 +0x3f8
cmd/compile/internal/syntax.inspector.Visit(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:23
cmd/compile/internal/syntax.walker.node({{0xf5aa00?, 0xc00003b3c0?}}, {0xf5d000, 0xc0004127d0})
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:315 +0x10b8
cmd/compile/internal/syntax.walker.stmtList(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:332
cmd/compile/internal/syntax.walker.node({{0xf5aa00?, 0xc00003b3c0?}}, {0xf5c250, 0xc000414200})
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:222 +0x14f0
cmd/compile/internal/syntax.Walk(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:41
cmd/compile/internal/syntax.Inspect(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:17
cmd/compile/internal/rangefunc.rewriteFunc(0xc0003f1e00, 0xc0003f1da0, 0xc000127340, 0xc000414200)
../../../../go-compilers/go-tip/src/cmd/compile/internal/rangefunc/rewrite.go:551 +0xed
cmd/compile/internal/rangefunc.Rewrite.func1({0xf5c1c0?, 0xc0003f19e0?})
../../../../go-compilers/go-tip/src/cmd/compile/internal/rangefunc/rewrite.go:528 +0x58
cmd/compile/internal/syntax.inspector.Visit(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:23
cmd/compile/internal/syntax.walker.node({{0xf5aa00?, 0xc00040e918?}}, {0xf5c1c0, 0xc0003f19e0})
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:60 +0x8a
cmd/compile/internal/syntax.walker.declList(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:320
cmd/compile/internal/syntax.walker.node({{0xf5aa00?, 0xc00040e918?}}, {0xf5c130, 0xc0003f1980})
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:69 +0x207a
cmd/compile/internal/syntax.Walk(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:41
cmd/compile/internal/syntax.Inspect(...)
../../../../go-compilers/go-tip/src/cmd/compile/internal/syntax/walk.go:17
cmd/compile/internal/rangefunc.Rewrite(0xc0003f1e00, 0xc0003f1da0, {0xc00005c590, 0x1, 0x1?})
../../../../go-compilers/go-tip/src/cmd/compile/internal/rangefunc/rewrite.go:525 +0x5b
cmd/compile/internal/noder.checkFiles({0x0, {0x0, 0x0}}, {0xc00005c528, 0x1, 0xf6a708?})
../../../../go-compilers/go-tip/src/cmd/compile/internal/noder/irgen.go:148 +0x956
cmd/compile/internal/noder.writePkgStub({0x0?, {0x0?, 0x0?}}, {0xc00005c528, 0x1, 0x1})
../../../../go-compilers/go-tip/src/cmd/compile/internal/noder/unified.go:296 +0x6a
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0xc00005c528?, 0xd38440?, 0x0?})
../../../../go-compilers/go-tip/src/cmd/compile/internal/noder/unified.go:172 +0x9a
cmd/compile/internal/noder.LoadPackage({0xc000022230, 0x1, 0x1})
../../../../go-compilers/go-tip/src/cmd/compile/internal/noder/noder.go:77 +0x43a
cmd/compile/internal/gc.Main(0xe2ac48)
../../../../go-compilers/go-tip/src/cmd/compile/internal/gc/main.go:197 +0xbbd
main.main()
../../../../go-compilers/go-tip/src/cmd/compile/main.go:57 +0xf9

@mauri870 mauri870 added NeedsFix The path to resolution is known, but the work has not been done. release-blocker compiler/runtime Issues related to the Go compiler and/or runtime. labels Jan 2, 2024
@mauri870
Copy link
Member

mauri870 commented Jan 2, 2024

Tentatively marking as release blocker, but it only affects GOEXPERIMENT=rangefunc.

cc @rsc @golang/release @golang/compiler

@mauri870 mauri870 changed the title Go1.22RC1 compiler crash when using GOEXPERIMENT=rangefunc cmd/compile: Go1.22RC1 compiler crash when using GOEXPERIMENT=rangefunc Jan 2, 2024
@gopherbot
Copy link

Change https://go.dev/cl/553455 mentions this issue: cmd/compile/internal/rangefunc: handle aliased type in yield func

@mauri870 mauri870 self-assigned this Jan 2, 2024
@mauri870 mauri870 added this to the Go1.22 milestone Jan 2, 2024
@gopherbot
Copy link

Change https://go.dev/cl/553436 mentions this issue: cmd/compile: handle defined iter func type correctly

@mauri870
Copy link
Member

mauri870 commented Jan 2, 2024

@cuonglm I had already started working on a fix in an earlier CL (553455), but I'm open to discard that in favor of your fix.

Out of curiosity, what is the fundamental difference between

ftyp := types2.AsSignature(rfunc.Params().At(0).Type()) // func(...) bool

And

ftyp := types2.CoreType(rfunc.Params().At(0).Type()).(*types2.Signature) // func(...) bool

Since both seem to fix the issue?

@cuonglm
Copy link
Member

cuonglm commented Jan 2, 2024

@mauri870 The types2.CoreType can handle type parameter and others. I don't have any concrete example off-hand, but given the fact that we already used types2.CoreType for range expression func(func(...) bool), using it for iter func func(...) bool is more reasonable IMHO.

@mauri870
Copy link
Member

mauri870 commented Jan 2, 2024

@mauri870 The types2.CoreType can handle type parameter and others. I don't have any concrete example off-hand, but given the fact that we already used types2.CoreType for range expression func(func(...) bool), using it for iter func func(...) bool is more reasonable IMHO.

Makes sense, thanks!

@mauri870 mauri870 assigned mauri870 and cuonglm and unassigned mauri870 Jan 2, 2024
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
Fixed golang#64930

Change-Id: I916de7f97116fb20cb2f3f0b425ac34409afd494
Reviewed-on: https://go-review.googlesource.com/c/go/+/553436
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>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
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. release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants