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: cannot export DCLTYPE (50) node #48328

Closed
Merovius opened this issue Sep 10, 2021 · 1 comment
Closed

cmd/compile: cannot export DCLTYPE (50) node #48328

Merovius opened this issue Sep 10, 2021 · 1 comment

Comments

@Merovius
Copy link
Contributor

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

$ gotip version                                                                                                       1
go version devel go1.18-cf2fe5d Fri Sep 10 17:15:37 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

With gotip yes, with the latest release not. It's a generics issue.

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

go env Output
$ gotip env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mero/.cache/go-build"
GOENV="/home/mero/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mero/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mero"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/mero/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/mero/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-cf2fe5d Fri Sep 10 17:15:37 2021 +0000"
GCCGO="/usr/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mero/tmp/x/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1538326350=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Trying to build this program using gotip (please ignore that it's a bad idea or broken code, just playing around):

package main

import (
	"fmt"
	"reflect"
	"sync"
	"unsafe"
)

func main() {
	h := Hasher[int]()
	fmt.Printf("%.16x\n", h(42, 0))
}

func Hasher[T comparable]() func(T, uintptr) uintptr {
	rt := reflect.TypeOf(*new(T))
	if h, ok := cache.Load(rt); ok {
		return h.(func(T, uintptr) uintptr)
	}
	mt := reflect.MapOf(rt, reflect.TypeOf(struct{}{}))
	ptr_size := reflect.TypeOf(mt).Size()
	rtype_size := reflect.TypeOf(mt).Elem().Size()

	rtype_base := (*[2]unsafe.Pointer)(unsafe.Pointer(&mt))[1]
	hasher_ptr := unsafe.Add(rtype_base, rtype_size+3*ptr_size)

	type hasherFn func(unsafe.Pointer, uintptr) uintptr
	hasher := *(*hasherFn)(unsafe.Pointer(&hasher_ptr))

	h := func(v T, seed uintptr) uintptr {
		return hasher(unsafe.Pointer(&v), seed)
	}
	cache.LoadOrStore(rt, h)
	return h
}

var cache sync.Map

What did you expect to see?

Nothing

What did you see instead?

Compiler error:

./x.go:34:2: internal compiler error: cannot export DCLTYPE (50) node
==> please file an issue and assign to gri@

Stack trace
goroutine 1 [running]:
runtime/debug.Stack()
	/home/mero/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0xc0c0, 0xc0}, {0xd1a707, 0x47}, {0xc0000fd690, 0x2, 0x2})
	/home/mero/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
	/home/mero/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.(*exportWriter).expr(0xc0006b6620, {0xe6b8d8, 0xc00000c0c0})
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:2072 +0x19dd
cmd/compile/internal/typecheck.(*exportWriter).node(0xc0006b1ec0, {0xe6b8d8, 0xc00000c0c0})
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1455 +0x7b
cmd/compile/internal/typecheck.(*exportWriter).stmtList(0xc0006b6620, {0xc0000ae600, 0xc, 0xc0006b1ec0})
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1446 +0x76
cmd/compile/internal/typecheck.(*exportWriter).funcBody(0xc0006b6620, 0xc00009e580)
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1441 +0x5b
cmd/compile/internal/typecheck.(*iexporter).doInline(0xc0000f0bb0, 0xc0000e9860)
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:632 +0xc5
cmd/compile/internal/typecheck.(*exportWriter).funcExt(0xc0006b64d0, 0xc0000e9860)
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1378 +0x1b6
cmd/compile/internal/typecheck.(*iexporter).doDecl(0xc0000f0bb0, 0xc0000e9860)
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:503 +0x21e
cmd/compile/internal/typecheck.WriteExports({0xe52660, 0xc0006b1d10}, 0x1)
	/home/mero/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:301 +0x2e5
cmd/compile/internal/noder.WriteExports(0xc0006676f0)
	/home/mero/sdk/gotip/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc0006676f0)
	/home/mero/sdk/gotip/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7ffe4c471c76, 0x24}, 0x3)
	/home/mero/sdk/gotip/src/cmd/compile/internal/gc/obj.go:63 +0x17b
cmd/compile/internal/gc.dumpobj()
	/home/mero/sdk/gotip/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0xd21e78)
	/home/mero/sdk/gotip/src/cmd/compile/internal/gc/main.go:329 +0x10ef
main.main()
	/home/mero/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

I don't think I can assign anyone, but let me try summoning @griesemer :)

@randall77
Copy link
Contributor

Closing as a dup of #47631

@golang golang locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants