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: expression has untyped type #54537

Closed
johejo opened this issue Aug 19, 2022 · 9 comments
Closed

cmd/compile: internal compiler error: expression has untyped type #54537

johejo opened this issue Aug 19, 2022 · 9 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@johejo
Copy link

johejo commented Aug 19, 2022

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

$ go version
go version devel go1.20-ee833ed72e Fri Aug 19 01:34:22 2022 +0000 darwin/arm64

Does this issue reproduce with the latest release?

tip only

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/mitsuoheijo/Library/Caches/go-build"
GOENV="/Users/mitsuoheijo/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mitsuoheijo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mitsuoheijo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/mitsuoheijo/ghq/github.com/golang/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/mitsuoheijo/ghq/github.com/golang/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="devel go1.20-ee833ed72e Fri Aug 19 01:34:22 2022 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mitsuoheijo/ghq/github.com/golang/go/src/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bq/s3vkkxm17jq79lx5qy3856zh0000gn/T/go-build1579252278=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Build hashicorp/nomad

git clone https://github.com/hashicorp/nomad
cd nomad
gotip build ./...

Trying to find minimal reproduction.

What did you expect to see?

Build successful

What did you see instead?

# github.com/hashicorp/nomad/nomad/structs/config
nomad/structs/config/consul.go:153:36: internal compiler error: expression has untyped type:
.   ANDAND untyped bool tc(1) # consul.go:153:36
.   .   ANDAND untyped bool tc(1) # consul.go:153:36
.   .   .   EQ untyped bool tc(1) # consul.go:153:36
.   .   .   .   LEN int tc(1) # consul.go:153:36
.   .   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   LITERAL-5 int tc(1) # consul.go:153:36
.   .   .   EQ untyped bool tc(1) # consul.go:153:36
.   .   .   .   LITERAL-1886680168 uint32 tc(1) # consul.go:153:36
.   .   .   .   OR uint32 tc(1) # consul.go:153:36
.   .   .   .   .   OR uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   OR uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   CONV uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   INDEX byte tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   .   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   .   .   .   .   .   LITERAL-0 int tc(1) # consul.go:153:36
.   .   .   .   .   .   .   LSH uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   CONV uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   .   INDEX byte tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   .   .   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   .   .   .   .   .   .   LITERAL-1 int tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   LITERAL-8 uint tc(1) # consul.go:153:36
.   .   .   .   .   .   LSH uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   CONV uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   INDEX byte tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   .   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   .   .   .   .   .   LITERAL-2 int tc(1) # consul.go:153:36
.   .   .   .   .   .   .   LITERAL-16 uint tc(1) # consul.go:153:36
.   .   .   .   .   LSH uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   CONV uint32 tc(1) # consul.go:153:36
.   .   .   .   .   .   .   INDEX byte tc(1) # consul.go:153:36
.   .   .   .   .   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   .   .   .   .   LITERAL-3 int tc(1) # consul.go:153:36
.   .   .   .   .   .   LITERAL-24 uint tc(1) # consul.go:153:36
.   .   EQ untyped bool tc(1) # consul.go:153:36
.   .   .   INDEX byte tc(1) # consul.go:153:36
.   .   .   .   DOTPTR config.Scheme string tc(1) # consul.go:153:28
.   .   .   .   .   NAME-config.def esc(no) Class:PAUTO Offset:0 OnStack Used PTR-*api.Config tc(1) # consul.go:136:2
.   .   .   .   LITERAL-4 int tc(1) # consul.go:153:36
.   .   .   LITERAL-115 byte tc(1) # consul.go:153:36

goroutine 1 [running]:
runtime/debug.Stack()
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/runtime/debug/stack.go:24 +0x64
cmd/compile/internal/base.FatalfAt({0x5768738?, 0x1?}, {0x10552e41f, 0x20}, {0x14000aac8b8, 0x1, 0x1})
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/base/print.go:227 +0x224
cmd/compile/internal/base.Fatalf(...)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/walk.walkExpr({0x105768738, 0x140003d73e0}, 0x14000dbb530)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:53 +0x358
cmd/compile/internal/walk.finishCompare(0x14000502e00, {0x105768738?, 0x140003d73e0?}, 0x104efc158?)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/compare.go:457 +0x4c
cmd/compile/internal/walk.walkCompareString(0x14000502e00, 0x14000aad530)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/compare.go:422 +0x1000
cmd/compile/internal/walk.walkCompare(0x14000502e00, 0x14000aad530)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/compare.go:48 +0xfa4
cmd/compile/internal/walk.walkExpr1({0x105767488, 0x14000502e00}, 0x14000502e00?)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:156 +0x6f8
cmd/compile/internal/walk.walkExpr({0x105767488, 0x14000502e00}, 0x14000aad530)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:56 +0x368
cmd/compile/internal/walk.walkAssign(0x14000dbb530, {0x105767318?, 0x140005b1c20?})
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/assign.go:72 +0x944
cmd/compile/internal/walk.walkExpr1({0x105767318, 0x140005b1c20}, 0x140005b1c20?)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:180 +0x3c8
cmd/compile/internal/walk.walkExpr({0x105767318, 0x140005b1c20}, 0x14000aad530)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:56 +0x368
cmd/compile/internal/walk.appendWalkStmt(0x14000dbb530, {0x105767318, 0x140005b1c20})
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/walk.go:256 +0x64
cmd/compile/internal/walk.ascompatee(0x15, {0x14000899000?, 0x2, 0x1?}, {0x14000899040?, 0x2, 0x1?})
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/assign.go:375 +0x494
cmd/compile/internal/walk.walkAssignList(0x14000aad8d0, 0x14000827680)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/assign.go:147 +0x128
cmd/compile/internal/walk.walkExpr1({0x1057671a8, 0x14000827680}, 0x14000827680?)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:184 +0x2cc
cmd/compile/internal/walk.walkExpr({0x1057671a8, 0x14000827680}, 0x14000aad8d0)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/expr.go:56 +0x368
cmd/compile/internal/walk.walkStmt({0x1057671a8, 0x14000827680?})
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/stmt.go:58 +0x74c
cmd/compile/internal/walk.walkStmtList(...)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/stmt.go:177
cmd/compile/internal/walk.Walk(0x140009583c0)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/walk/walk.go:43 +0x194
cmd/compile/internal/gc.prepareFunc(0x140009583c0)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:92 +0x80
cmd/compile/internal/gc.enqueueFunc(0x140009583c0)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:66 +0x29c
cmd/compile/internal/gc.Main(0x10575cc60)
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/internal/gc/main.go:295 +0x1174
main.main()
        /Users/mitsuoheijo/ghq/github.com/golang/go/src/cmd/compile/main.go:57 +0xf4
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 19, 2022
@johejo
Copy link
Author

johejo commented Aug 19, 2022

Build passed when GOEXPERIMENT=nounified

@seankhliao
Copy link
Member

seankhliao commented Aug 19, 2022

cc @mdempsky

@cuonglm cuonglm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 19, 2022
@cuonglm cuonglm added this to the Go1.20 milestone Aug 19, 2022
@cuonglm
Copy link
Member

cuonglm commented Aug 19, 2022

Minimal reproducer:

package p

func G[T any](t T) *T {
	return &t
}

func f(x string) {
	_ = G(x == "foo")
}

@mdempsky
Copy link
Member

mdempsky commented Aug 19, 2022

In the -l -W=2 output for @cuonglm's minimized test case, I see:

before walk f
.   AS tc(1) # w.go:8:4
.   .   NAME-p._ Offset:0 blank tc(1)
.   .   CALLFUNC PTR-*go.shape.bool tc(1) # w.go:8:7
.   .   .   NAME-p.G[go.shape.bool] Class:PFUNC Offset:0 Used FUNC-func(*[2]uintptr, go.shape.bool) *go.shape.bool tc(1) # w.go:3:6
.   .   CALLFUNC-Args
.   .   .   ADDR PTR-*[2]uintptr tc(1) # w.go:8:6
.   .   .   .   NAME-p..dict.G[bool] Class:PEXTERN Offset:0 Addrtaken Used ARRAY-[2]uintptr tc(1) # <autogenerated>:1:0
.   .   .   EQ go.shape.bool tc(1) # w.go:8:10
.   .   .   .   NAME-p.x esc(no) Class:PPARAM Offset:0 OnStack Used string tc(1) # w.go:7:8
.   .   .   .   LITERAL-"foo" string tc(1) # w.go:8:13

That looks right to me.

I think the issue is that walk is desugaring the OEQ expression into an "untyped bool" expression; and then somewhere we decide whether to convert it to the original type (go.shape.bool), but types.Identical reports them as identical so we skip coercing back to go.shape.bool.

Probably the fix is to ensure the conversion from "untyped bool" to "go.shape.bool" really happens as needed.

@mdempsky
Copy link
Member

mdempsky commented Aug 19, 2022

I think the issue is the typecheck.Conv call in walk.finishCompare.

Probably we want to change the types.Identical calls to types.IdenticalStrict.

@cuonglm
Copy link
Member

cuonglm commented Aug 19, 2022

I think the issue is the typecheck.Conv call in walk.finishCompare.

Probably we want to change the types.Identical calls to types.IdenticalStrict.

Yeah, for nounified, at that stage, n.Type() is bool, not go.shape.bool like unified. I wonder we can make unified IR behaves the same 🤔

@mdempsky
Copy link
Member

mdempsky commented Aug 19, 2022

The issue affects nounified too: https://go.dev/play/p/BKYr_UUMGvH

@gopherbot
Copy link

gopherbot commented Aug 19, 2022

Change https://go.dev/cl/424936 mentions this issue: cmd/compile: fix unified IR regressions

@gopherbot
Copy link

gopherbot commented Aug 19, 2022

Change https://go.dev/cl/424937 mentions this issue: cmd/compile: fix "expression has untyped type" ICE in generic code

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. 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