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

[dev.typeparams]: internal compiler error: Nil type for v #46472

Closed
JAicewizard opened this issue May 31, 2021 · 6 comments
Closed

[dev.typeparams]: internal compiler error: Nil type for v #46472

JAicewizard opened this issue May 31, 2021 · 6 comments

Comments

@JAicewizard
Copy link

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

$ go version
go version devel go1.17-f32f4f58d9 Mon May 31 03:22:58 2021 +0000 linux/amd64

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jaap/.cache/go-build"
GOENV="/home/jaap/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jaap/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jaap/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jaap/Projects/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jaap/Projects/goroot/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.17-f32f4f58d9 Mon May 31 03:22:58 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jaap/Projects/tt/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-build2903782367=/tmp/go-build -gno-record-gcc-switches"

What did you do?

main.go

package main

import (
	"fmt"
)

func foo[T any](d T) {
	switch v := interface{}(d).(type) {
	case string:
		fmt.Println(v=="x")
	}

}
func main() {
	foo("x")
}

go run -gcflags='-G=3' main.go

What did you expect to see?

True

What did you see instead?

stacktrace
```
# command-line-arguments
: internal compiler error: Nil type for v

goroutine 1 [running]:
runtime/debug.Stack()
/home/jaap/Projects/goroot/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0xcf2924, 0x0}, {0xc0000285f0, 0xe}, {0x0, 0x0, 0x0})
/home/jaap/Projects/goroot/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
/home/jaap/Projects/goroot/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/noder.(*subster).node.func1({0xe531e0, 0xc0003b26c0})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:369 +0x279
cmd/compile/internal/ir.(*TypeSwitchGuard).editChildren(0xc00039d590, 0xc00000cac8)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/node_gen.go:1334 +0x3d
cmd/compile/internal/ir.EditChildren(...)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe54ba8, 0xc00039d380})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:375 +0x30f
cmd/compile/internal/ir.(*SwitchStmt).editChildren(0xc0000f8480, 0xc00000cac8)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/node_gen.go:1262 +0x58
cmd/compile/internal/ir.EditChildren(...)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe54950, 0xc0000f8400})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:375 +0x30f
cmd/compile/internal/noder.(*subster).node(0xc0003ad590, {0xe54950, 0xc0000f8400})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:541 +0xa5
cmd/compile/internal/noder.(*subster).list(0x13a6248, {0xc0003a45e0, 0x1, 0xc0000c4550})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:561 +0x8e
cmd/compile/internal/noder.(*irgen).genericSubst(0xc000324990, 0xc0003ad540, 0xc000373790, {0xc0000ba2d0, 0x1, 0x1}, 0x0)
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:312 +0x7a5
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc000324990, 0xc000373790, {0xc0000ba2d0, 0x1, 0x1}, 0x8)
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:219 +0x1cf
cmd/compile/internal/noder.(*irgen).getInstantiationForNode(0xc00037d860, 0xc00037d860)
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:197 +0xe5
cmd/compile/internal/noder.(*irgen).stencil.func1({0xe527b8, 0xc000324ea0})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:89 +0xda
cmd/compile/internal/ir.Visit.func1({0xe527b8, 0xc000324ea0})
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes({0xc0003a4630, 0x1, 0xc0000285bb}, 0xc00000ca98)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/node_gen.go:1456 +0x67
cmd/compile/internal/ir.(*Func).doChildren(0xe52f88, 0xc0003a6580)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/func.go:151 +0x2e
cmd/compile/internal/ir.DoChildren(...)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe52f88, 0xc0003a6580})
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0xe52f88, 0xc0003a6580}, 0xc0003b05a0)
/home/jaap/Projects/goroot/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*irgen).stencil(0xc000324990)
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/stencil.go:74 +0x1a5
cmd/compile/internal/noder.(*irgen).generate(0xc000324990, {0xc00009a820, 0x2, 0xc0003a4090})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/irgen.go:185 +0x26c
cmd/compile/internal/noder.check2({0xc00009a820, 0x0, 0x2})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/irgen.go:78 +0x5da
cmd/compile/internal/noder.LoadPackage({0xc0000c0120, 0x2, 0x0})
/home/jaap/Projects/goroot/src/cmd/compile/internal/noder/noder.go:80 +0x30b
cmd/compile/internal/gc.Main(0xd1ab98)
/home/jaap/Projects/goroot/src/cmd/compile/internal/gc/main.go:192 +0xb35
main.main()
/home/jaap/Projects/goroot/src/cmd/compile/main.go:55 +0xdd

</pre></details>
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/323731 mentions this issue: [dev.typeparams] cmd/compile: handle ONONAME in subster.node

@JAicewizard
Copy link
Author

This seems to be fixed, thanks for the super fast patch. Works for me as well!

@mdempsky
Copy link
Contributor

mdempsky commented Jun 1, 2021

The CL hasn't been submitted yet.

@mdempsky mdempsky reopened this Jun 1, 2021
@JAicewizard
Copy link
Author

oh I thought it was marked as merged. sorry!

gopherbot pushed a commit that referenced this issue Jun 1, 2021
Fixes #46472

Change-Id: I27802978fa0c3bb32a29e452165a6fcac93473bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/323731
Trust: Cuong Manh Le <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Dan Scales <[email protected]>
@dr2chase
Copy link
Contributor

dr2chase commented Jun 1, 2021

I think this is fixed now, so I'll close the bug.

@dr2chase dr2chase closed this as completed Jun 1, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/324573 mentions this issue: [dev.typeparams] cmd/compile: unified IR construction

gopherbot pushed a commit that referenced this issue Jun 15, 2021
This CL adds a new unified IR construction mode to the frontend.  It's
purely additive, and all files include "UNREVIEWED" at the top, like
how types2 was initially imported. The next CL adds a -d=unified flag
to actually enable unified IR mode.

See below for more details, but some highlights:

1. It adds ~6kloc (excluding enum listings and stringer output), but I
estimate it will allow removing ~14kloc (see CL 324670, including its
commit message);

2. When enabled by default, it passes more tests than -G=3 does (see
CL 325213 and CL 324673);

3. Without requiring any new code, it supports inlining of more code
than the current inliner (see CL 324574; contrast CL 283112 and CL
266203, which added support for inlining function literals and type
switches, respectively);

4. Aside from dictionaries (which I intend to add still), its support
for generics is more complete (e.g., it fully supports local types,
including local generic types within generic functions and
instantiating generic types with local types; see
test/typeparam/nested.go);

5. It supports lazy loading of types and objects for types2 type
checking;

6. It supports re-exporting of types, objects, and inline bodies
without needing to parse them into IR;

7. The new export data format has extensive support for debugging with
"sync" markers, so mistakes during development are easier to catch;

8. When compiling with -d=inlfuncswithclosures=0, it enables "quirks
mode" where it generates output that passes toolstash -cmp.

--

The new unified IR pipeline combines noding, stenciling, inlining, and
import/export into a single, shared code path. Previously, IR trees
went through multiple phases of copying during compilation:

1. "Noding": the syntax AST is copied into the initial IR form. To
support generics, there's now also "irgen", which implements the same
idea, but takes advantage of types2 type-checking results to more
directly construct IR.

2. "Stenciling": generic IR forms are copied into instantiated IR
forms, substituting type parameters as appropriate.

3. "Inlining": the inliner made backup copies of inlinable functions,
and then copied them again when inlining into a call site, with some
modifications (e.g., updating position information, rewriting variable
references, changing "return" statements into "goto").

4. "Importing/exporting": the exporter wrote out the IR as saved by
the inliner, and then the importer read it back as to be used by the
inliner again. Normal functions are imported/exported "desugared",
while generic functions are imported/exported in source form.

These passes are all conceptually the same thing: make a copy of a
function body, maybe with some minor changes/substitutions. However,
they're all completely separate implementations that frequently run
into the same issues because IR has many nuanced corner cases.

For example, inlining currently doesn't support local defined types,
"range" loops, or labeled "for"/"switch" statements, because these
require special handling around Sym references. We've recently
extended the inliner to support new features like inlining type
switches and function literals, and they've had issues. The exporter
only knows how to export from IR form, so when re-exporting inlinable
functions (e.g., methods on imported types that are exposed via
exported APIs), these functions may need to be imported as IR for the
sole purpose of being immediately exported back out again.

By unifying all of these modes of copying into a single code path that
cleanly separates concerns, we eliminate many of these possible
issues. Some recent examples:

1. Issues #45743 and #46472 were issues where type switches were
mishandled by inlining and stenciling, respectively; but neither of
these affected unified IR, because it constructs type switches using
the exact same code as for normal functions.

2. CL 325409 fixes an issue in stenciling with implicit conversion of
values of type-parameter type to variables of interface type, but this
issue did not affect unified IR.

Change-Id: I5a05991fe16d68bb0f712503e034cb9f2d19e296
Reviewed-on: https://go-review.googlesource.com/c/go/+/324573
Trust: Matthew Dempsky <[email protected]>
Trust: Robert Griesemer <[email protected]>
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
@golang golang locked and limited conversation to collaborators Jun 3, 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

4 participants