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: internal compiler error: panic: interface conversion: ir.Node is *ir.BasicLit, not *ir.ConstExpr #58339

Closed
578559967 opened this issue Feb 5, 2023 · 16 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@578559967
Copy link

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

$ go version
go version go1.20 darwin/arm64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/r/Library/Caches/go-build"
GOENV="/Users/r/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/r/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/r/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/r/sdk/go1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/r/sdk/go1.20/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/r/workspace/testcode/testinline/bug2.1/go.mod"
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/go-build2923148267=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.20 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.20
uname -v: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
ProductName:		macOS
ProductVersion:		13.1
BuildVersion:		22C65
lldb --version: lldb-1400.0.38.17
Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)

What did you do?

go.mod:

module foo

go 1.20

pkg/a.go:

package pkg

func Assert(msgAndArgs ...any) {
}

func Run() int {
        Assert("%v")
        return 0
}

func Run2() int {
        return Run()
}

b.go:

package main

import "foo/pkg"

var A = pkg.Run2()

func main() {
}

GOEXPERIMENT=nounified go1.20 build ./b.go

What did you expect to see?

Build successfully.

What did you see instead?

# command-line-arguments
./b.go:5:5: internal compiler error: panic: interface conversion: ir.Node is *ir.BasicLit, not *ir.ConstExpr

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 5, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 5, 2023

Sounds like the non-unified frontend importer import "%v" as an untyped constant: https://github.com/golang/go/blob/release-branch.go1.20/src/cmd/compile/internal/typecheck/iimport.go#L1283, while the unified IR frontend represents "%v" as a constant-fold - constant expression - node. That's why there's an ICE with GOEXPERIMENT=nounified.

The non-unified frontend is gone at tip, so I think there's nothing to do here.

cc @mdempsky

@cuonglm cuonglm added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 5, 2023
@randall77
Copy link
Contributor

We should check 1.19. If it fails there we should arrange a backport for that.

@cuonglm
Copy link
Member

cuonglm commented Feb 5, 2023

We should check 1.19. If it fails there we should arrange a backport for that.

Inline static init is only added in 1.20, 1.19 have no effect.

@sywhang
Copy link
Contributor

sywhang commented Feb 7, 2023

Can confirm this issue is only happening on Go 1.20 and is currently blocking Uber's upgrade to Go 1.20.

@cuonglm
Copy link
Member

cuonglm commented Feb 7, 2023

Can confirm this issue is only happening on Go 1.20 and is currently blocking Uber's upgrade to Go 1.20.

This only affects non-unified IR IIRC, do you set GOEXPERIMENT=nounified in your go build?

@sywhang
Copy link
Contributor

sywhang commented Feb 7, 2023

do you set GOEXPERIMENT=nounified in your go build?

Unfortunately yes, we have some codegen based tooling that's seeing huge build time regression due to almost 10x regression in calling gcexportdata.Read when we do not set that.

@cuonglm
Copy link
Member

cuonglm commented Feb 7, 2023

do you set GOEXPERIMENT=nounified in your go build?

Unfortunately yes, we have some codegen based tooling that's seeing huge build time regression due to almost 10x regression in calling gcexportdata.Read when we do not set that.

Thanks for confirmation, I just worry there's another regression in Unified IR.

Note that GOEXPERIMENT=nounified will be gone in go1.21, so you may want to file new issue about that regression so we could take a look.

@sywhang
Copy link
Contributor

sywhang commented Feb 7, 2023

Will do. We do have plans to migrate that codegen toolchain not rely on gcexportdata before 1.21 is out but we'll get back to you soon with some repro and profile after further investigation.

@sywhang
Copy link
Contributor

sywhang commented Feb 7, 2023

An even simpler repro:

package main

import (
	"go.uber.org/zap"
)

var nopLogger = zap.NewNop()

func main() {
	nopLogger.Info("Hi")
}

@gopherbot
Copy link

Change https://go.dev/cl/466175 mentions this issue: cmd/compile/internal/staticinit: fix panic in interface conversion

sywhang added a commit to sywhang/go that referenced this issue Feb 7, 2023
This patch fixes a panic from incorrect interface conversion
from *ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go 1.20
and removed from master.

Fixes golang#58339
sywhang added a commit to sywhang/go that referenced this issue Feb 8, 2023
This patch fixes a panic from incorrect interface conversion
from *ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go 1.20
and removed from master.

Fixes golang#58339
sywhang added a commit to sywhang/go that referenced this issue Feb 8, 2023
This patch fixes a panic from incorrect interface conversion
from *ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go 1.20
and removed from master.

Fixes golang#58339
sywhang added a commit to sywhang/go that referenced this issue Feb 8, 2023
This patch fixes a panic from incorrect interface conversion
from *ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go 1.20
and removed from master.

Fixes golang#58339
sywhang added a commit to sywhang/go that referenced this issue Feb 8, 2023
This patch fixes a panic from incorrect interface conversion
from *ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go 1.20
and removed from master.

Fixes golang#58339
@gopherbot
Copy link

Change https://go.dev/cl/466277 mentions this issue: cmd/compile: rename EvalConst to EvalExpr

@sywhang
Copy link
Contributor

sywhang commented Feb 9, 2023

@mdempsky @cuonglm Thanks for the reviews. Can this be backported to Go 1.20 branch?

@cuonglm
Copy link
Member

cuonglm commented Feb 9, 2023

@mdempsky @cuonglm Thanks for the reviews. Can this be backported to Go 1.20 branch?

Let wait for the decision in #58439. The fix there will also fix this issue if backported.

@cuonglm cuonglm reopened this Feb 9, 2023
@gopherbot
Copy link

Change https://go.dev/cl/467015 mentions this issue: cmd/compile: disable inline static init optimization

@gopherbot
Copy link

Change https://go.dev/cl/467016 mentions this issue: cmd/compile: reenable inline static init

gopherbot pushed a commit that referenced this issue Feb 9, 2023
There are a plenty of regression in 1.20 with this optimization. This CL
disable inline static init, so it's safer to backport to 1.20 branch.

The optimization will be enabled again during 1.21 cycle.

Updates #58293
Updates #58339
For #58293

Change-Id: If5916008597b46146b4dc7108c6b389d53f35e95
Reviewed-on: https://go-review.googlesource.com/c/go/+/467015
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
@cuonglm
Copy link
Member

cuonglm commented Feb 10, 2023

CL https://go-review.googlesource.com/c/go/+/467035 is going to be backported, so I don't think we need to backport this one.

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 12, 2023
This patch fixes a panic from incorrect interface conversion from
*ir.BasicLit to *ir.ConstExpr. This only occurs when nounified
GOEXPERIMENT is set, so ideally it should be backported to Go
1.20 and removed from master.

Fixes golang#58339

Change-Id: I357069d7ee1707d5cc6811bd2fbdd7b0456323ae
GitHub-Last-Rev: 641dedb
GitHub-Pull-Request: golang#58389
Reviewed-on: https://go-review.googlesource.com/c/go/+/466175
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 12, 2023
There are a plenty of regression in 1.20 with this optimization. This CL
disable inline static init, so it's safer to backport to 1.20 branch.

The optimization will be enabled again during 1.21 cycle.

Updates golang#58293
Updates golang#58339
For golang#58293

Change-Id: If5916008597b46146b4dc7108c6b389d53f35e95
Reviewed-on: https://go-review.googlesource.com/c/go/+/467015
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopherbot pushed a commit that referenced this issue Apr 14, 2023
Static init inliner is using typecheck.EvalConst to handle string
concatenation expressions. But static init inliner may reveal constant
expressions after substitution, and the compiler needs to evaluate those
expressions in non-constant semantic. Using typecheck.EvalConst, which
always evaluates expressions in constant semantic, is not the right
choice.

For safety, this CL fold the logic to handle string concatenation to
static init inliner, so there won't be regression in handling constant
expressions in non-constant semantic. And also, future CL can simplify
typecheck.EvalConst logic.

Updates #58293
Updates #58339
Fixes #58439

Change-Id: I74068d99c245938e576afe9460cbd2b39677bbff
Reviewed-on: https://go-review.googlesource.com/c/go/+/466277
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
gopherbot pushed a commit that referenced this issue Apr 14, 2023
Updates #58293
Updates #58339
Fixes #58439

Change-Id: I06d2d92f86fa4a672d69515c4066d69d3e0fc75b
Reviewed-on: https://go-review.googlesource.com/c/go/+/467016
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
@golang golang locked and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants