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: X has no location (type parameters, inlining, struct field with defined type) #48414

Closed
ahamlinman opened this issue Sep 16, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@ahamlinman
Copy link

@ahamlinman ahamlinman commented Sep 16, 2021

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

$ gotip version
go version devel go1.18-cfa233d76b Wed Sep 15 22:53:42 2021 +0000 linux/amd64

For good measure, I've also tested with patch set 1 of https://golang.org/cl/349909 from #48337 (not yet merged as of this writing) and confirmed that it exhibits the same behavior:

$ gotip version
go version devel go1.18-e908806648 Tue Sep 14 09:13:23 2021 -0700 linux/amd64

Does this issue reproduce with the latest release?

No, using the latest master.

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

go env Output
$ gotip env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alexhamlin/.cache/go-build"
GOENV="/home/alexhamlin/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/alexhamlin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/alexhamlin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/alexhamlin/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/alexhamlin/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-cfa233d76b Wed Sep 15 22:53:42 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/home/alexhamlin/Desktop/typeparams-no-location/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1996298261=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempt to go build the contents of https://github.com/ahamlinman/typeparams-no-location:

-- go.mod --
module github.com/ahamlinman/typeparams-no-location

go 1.18
-- main.go --
package main

import "github.com/ahamlinman/typeparams-no-location/controller"

func main() {
	controller.NewController().Status()
}
-- controller/controller.go --
package controller

import "github.com/ahamlinman/typeparams-no-location/value"

type State int

const StateNone State = iota

type Status struct {
	State State
}

type Controller struct {
	status *value.Value[Status]
}

func NewController() *Controller {
	return &Controller{
		status: value.NewValue(Status{}),
	}
}

func (c *Controller) Status() Status {
	return c.status.Get()
}
-- value/value.go --
package value

type Value[T any] struct {
	value T
}

func NewValue[T any](value T) *Value[T] {
	return &Value[T]{value}
}

func (v *Value[T]) Get() T {
	return v.value
}

What did you expect to see?

A successful build with no errors reported.

What did you see instead?

# github.com/ahamlinman/typeparams-no-location                                      
./main.go:6:35: internal compiler error: value.(*Value[.shape.struct{ State "".State }_0]).Get has no location
Full error with stack trace
# github.com/ahamlinman/typeparams-no-location
./main.go:6:35: internal compiler error: value.(*Value[.shape.struct{ State "".State }_0]).Get has no location

goroutine 1 [running]:
runtime/debug.Stack()
/home/alexhamlin/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x430d80, 0xc0}, {0xcfd6a8, 0x12}, {0xc000438780, 0x1, 0x1})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/escape.(*batch).oldLoc(0xc000425110, 0xc000425110)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/graph.go:211 +0xa7
cmd/compile/internal/escape.(*escape).exprSkipInit(0xc0000390e0, {0xc000401060, 0xc000438ce0, 0x0, 0x50}, {0xe6dc58, 0xc000425110})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/expr.go:49 +0xa9c
cmd/compile/internal/escape.(*escape).expr(0xc000401060, {0xc000401060, 0x0, 0x0, 0x78}, {0xe6dc58, 0xc000425110})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/expr.go:20 +0xad
cmd/compile/internal/escape.(*escape).callCommon.func1(0xc000425110, {0xc000401060, 0xc000079350, 0x0, 0x1}, 0xc00043a798)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:34 +0xd9
cmd/compile/internal/escape.(*escape).callCommon.func2(...)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:38
cmd/compile/internal/escape.(*escape).callCommon(0xc0000390e0, {0xc000438e50, 0xc000438cf8, 0x1}, {0xe6c678, 0xc00043a750}, 0xc00043a750, 0xc000425380)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:99 +0xf76
cmd/compile/internal/escape.(*escape).call(0xc00043a750, {0xc000438e50, 0xc000444690, 0x465de7}, {0xe6c678, 0xc00043a750})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:20 +0x65
cmd/compile/internal/escape.(*escape).exprSkipInit(0xc0000390e0, {0xc000444700, 0x6f1aa8, 0x0, 0x0}, {0xe6c678, 0xc00043a750})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/expr.go:138 +0x1305
cmd/compile/internal/escape.(*escape).expr(0xc000444700, {0xc000444700, 0x0, 0x0, 0x0}, {0xe6c678, 0xc00043a750})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/expr.go:20 +0xad
cmd/compile/internal/escape.(*escape).assignList(0xc0000390e0, {0xc000062800, 0x6f4ef1, 0xe6ca60}, {0xc000062810, 0x1, 0x203000}, {0xcf6916, 0xb}, {0xe6c100, ...})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/assign.go:93 +0x3fe
cmd/compile/internal/escape.(*escape).stmt(0xc0000390e0, {0xe6c100, 0xc00006d440})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:150 +0xb85
cmd/compile/internal/escape.(*escape).stmts(0xc00007ec00, {0xc000039040, 0x2, 0x0})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:189 +0x5d
cmd/compile/internal/escape.(*escape).stmt(0xc0000390e0, {0xe6c4e8, 0xc00007ec00})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:42 +0x875
cmd/compile/internal/escape.(*escape).stmts(0xc0004443f0, {0xc000039060, 0x2, 0xc0000627a0})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:189 +0x5d
cmd/compile/internal/escape.(*escape).callCommon(0xc0000390e0, {0x0, 0xc00000cae0, 0x0}, {0xe6d550, 0xc0004443f0}, 0xc0004443f0, 0xc00006d500)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:122 +0x8ab
cmd/compile/internal/escape.(*escape).call(0xc0004443f0, {0x0, 0x2, 0x5be787}, {0xe6d550, 0xc0004443f0})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/call.go:20 +0x65
cmd/compile/internal/escape.(*escape).stmt(0xc0000390e0, {0xe6d550, 0xc0004443f0})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:177 +0x1035
cmd/compile/internal/escape.(*escape).stmts(0xe6cfd8, {0xc0000622e0, 0x1, 0xc000439a98})
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:189 +0x5d
cmd/compile/internal/escape.(*escape).block(...)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/stmt.go:196
cmd/compile/internal/escape.(*batch).walkFunc(0xc000400fc0, 0xc00007a2c0)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/escape.go:227 +0xee
cmd/compile/internal/escape.Batch({0xc00000e450, 0x1, 0x1}, 0x30)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/escape.go:143 +0x21a
cmd/compile/internal/ir.(*bottomUpVisitor).visit(0xc0000795c0, 0xc00007a2c0)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/ir/scc.go:127 +0x2f0
cmd/compile/internal/ir.VisitFuncsBottomUp({0xc00007e740, 0x4, 0x2}, 0xd234e8)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/ir/scc.go:60 +0x105
cmd/compile/internal/escape.Funcs(...)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/escape/escape.go:118
cmd/compile/internal/gc.Main(0xd233c8)
/home/alexhamlin/sdk/gotip/src/cmd/compile/internal/gc/main.go:276 +0xd71
main.main()
/home/alexhamlin/sdk/gotip/src/cmd/compile/main.go:55 +0xdd


Any one of the following allows the program to build successfully in my testing:

  • go build -gcflags=-l (disable inlining)
  • GOEXPERIMENT=unified go build
  • Change the type of the State field in controller.Status, e.g. from State to int
@cuonglm cuonglm added this to the Go1.18 milestone Sep 16, 2021
@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 16, 2021

Loading

@danscales danscales self-assigned this Sep 20, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 20, 2021

Change https://golang.org/cl/351114 mentions this issue: cmd/compile: don't create or instantiate methods on shape types

Loading

@gopherbot gopherbot closed this in 48cf96c Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants