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: width not calculated: interface {} #25055

Closed
ALTree opened this issue Apr 24, 2018 · 7 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@ALTree
Copy link
Member

ALTree commented Apr 24, 2018

$ gotip version
go version devel +cd037bce09 Tue Apr 24 16:11:41 2018 +0000 linux/amd64

The following 2-packages program (reduced from a gosmith-generated one):

b/b.go

package b

type T chan *interface{}

var B = (T)(nil)

a/a.go

package a

import "b"

var A = (<-(b.B))

crashes the tip compiler (when building a) with:

# command-line-arguments
<autogenerated>:1: internal compiler error: width not calculated: interface {}

goroutine 7 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/alberto/go/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xc0d28a, 0x18, 0xc0004d9298, 0x1, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:182 +0x1f7
cmd/compile/internal/gc.dowidth(0xc000358f00)
	/home/alberto/go/src/cmd/compile/internal/gc/align.go:193 +0x192
cmd/compile/internal/types.(*Type).Fields(0xc000358f00, 0x0)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:871 +0x6c
cmd/compile/internal/types.(*Type).NumFields(0xc000358f00, 0xc05a21)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:1330 +0x2b
cmd/compile/internal/types.(*Type).IsEmptyInterface(0xc000358f00, 0xbf6560)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:1317 +0x41
cmd/compile/internal/gc.typefmt(0xc000358f00, 0x0, 0x2, 0x2, 0xc000394c20, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:745 +0x1c1b
cmd/compile/internal/gc.tconv(0xc000358f00, 0x0, 0x2, 0x1, 0xc000394d40, 0x120000c000502320)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1763 +0xca
cmd/compile/internal/gc.tmodeString(0xc000358f00, 0x2, 0x1, 0x7f5365bea001, 0x1000000)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1669 +0x48
cmd/compile/internal/gc.typefmt(0xc000358f60, 0x0, 0x2, 0x1, 0xc0004bc3b9, 0xc0004d99d0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:716 +0x4dd
cmd/compile/internal/gc.tconv(0xc000358f60, 0x1, 0x0, 0x0, 0x4108c3, 0xc0000185d0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1763 +0xca
cmd/compile/internal/gc.Main.func2(0xc000358f60, 0x1, 0x0, 0x0, 0x40ab8f, 0xc0004c20c0)
	/home/alberto/go/src/cmd/compile/internal/gc/main.go:439 +0x49
cmd/compile/internal/types.(*Type).ShortString(0xc000358f60, 0xc0004d9ab0, 0x4d683c)
	/home/alberto/go/src/cmd/compile/internal/types/utils.go:56 +0x53
cmd/compile/internal/gc.typesymname(0xc000358f60, 0xc00000e240, 0x120000c0004bc3a8)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:925 +0x2f
cmd/compile/internal/gc.typesym(0xc000358f60, 0xc000358f00)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:948 +0x2b
cmd/compile/internal/gc.typenamesym(0xc000358f60, 0x7)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:970 +0xb1
cmd/compile/internal/gc.ngotype(0xc000349e00, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:1887 +0x34
cmd/compile/internal/gc.debuginfo(0xc000314ee0, 0xbf6560, 0xc0004a8000, 0xc000314fc0, 0xc000315030, 0x0, 0xc0003150a0, 0x0, 0x180)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:356 +0x1ca
cmd/internal/obj.(*Link).populateDWARF(0xc00000e240, 0xbf6560, 0xc0004a8000, 0xc000314ee0, 0x7ffea36f72b8, 0x16)
	/home/alberto/go/src/cmd/internal/obj/objfile.go:551 +0x548
cmd/internal/obj.Flushplist(0xc00000e240, 0xc0004d9f08, 0xc0004c60d0, 0x7ffea36f72b8, 0x16)
	/home/alberto/go/src/cmd/internal/obj/plist.go:109 +0x715
cmd/compile/internal/gc.(*Progs).Flush(0xc000502280)
	/home/alberto/go/src/cmd/compile/internal/gc/gsubr.go:87 +0xbc
cmd/compile/internal/gc.compileSSA(0xc0004a8000, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:268 +0x184
cmd/compile/internal/gc.compileFunctions.func2(0xc0004ac240, 0xc000018610, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:309 +0x49
created by cmd/compile/internal/gc.compileFunctions
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:307 +0x11a

The compiler does not crash if passed -iexport=false.

cc @mdempsky

@ALTree ALTree added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Apr 24, 2018
@ALTree ALTree added this to the Go1.11 milestone Apr 24, 2018
@griesemer
Copy link
Contributor

This seems related to -c=4 (any value > 1), i.e., concurrent compilation. Here's a slightly simpler reproducer. With:

$ cat a.go
package a

var A chan *interface{}
$ cat b.go
package b

import "./a"

var _ = <-a.A

To reproduce:

go tool compile a.go
go tool compile -c=2 b.go

The crash disappears for -c=1 (or no -c).

@josharian
Copy link
Contributor

This seems related to -c=4 (any value > 1), i.e., concurrent compilation.

That is because the "width not calculated" check is guarded by sizeCalculationDisabled, which is only set when concurrent compilation is enabled. That's because an assumption of concurrent compilation is that all type sizes have been calculated before the backend begins.

Fixing this kind of bug (which I did a lot of in 1.9) generally consists of finding the right spot in the front end to insert a dowidth(t). The assumption is that someday in the distant future the front end will be reworked such that all types are made concrete through some clearly terminating, complete algorithm.

@griesemer
Copy link
Contributor

@josharian Thanks for the input - that matches my understanding. There's possibly a missing dowidth in the new importer (iimport.go).

@mdempsky
Copy link
Member

mdempsky commented Jul 3, 2018

I can't reproduce this issue at master or even at cd037bc. Can anyone else?

@ALTree
Copy link
Member Author

ALTree commented Jul 4, 2018

@mdempsky I still see the crash @ current tip.

$ gotip version
go version devel +36c623046b Wed Jul 4 00:22:11 2018 +0000 linux/amd64

Here what my workspace looks like:

$ cd $GOPATH/src

$ tree github.com/ALTree/a github.com/ALTree/b
github.com/ALTree/a
└── a.go
github.com/ALTree/b
└── b.go

0 directories, 2 files

the content of a.go and b.go is the same as in my first post in this thread:

$ cat github.com/ALTree/a/a.go

package a

import "github.com/ALTree/b"

var A = (<-(b.B))
$ cat github.com/ALTree/b/b.go

package b

type T chan *interface{}

var B = (T)(nil)

this is how I build it:

$ gotip build github.com/ALTree/a
# github.com/ALTree/a
<autogenerated>:1: internal compiler error: width not calculated: interface {}

goroutine 19 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/alberto/go/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xcb9e62, 0x18, 0xc0004e51c8, 0x1, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:182 +0x1f7
cmd/compile/internal/gc.dowidth(0xc00035cea0)
	/home/alberto/go/src/cmd/compile/internal/gc/align.go:193 +0x192
cmd/compile/internal/types.(*Type).Fields(0xc00035cea0, 0x40)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:866 +0x6c
cmd/compile/internal/types.(*Type).NumFields(0xc00035cea0, 0xc0004ca138)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:1320 +0x2b
cmd/compile/internal/types.(*Type).IsEmptyInterface(0xc00035cea0, 0xc00031d300)
	/home/alberto/go/src/cmd/compile/internal/types/type.go:1312 +0x41
cmd/compile/internal/gc.typefmt(0xc00035cea0, 0x0, 0x2, 0x2, 0x48, 0xc221c0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:745 +0x1b0a
cmd/compile/internal/gc.tconv(0xc00035cea0, 0x0, 0x2, 0x1, 0x0, 0x1200000000000000)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1766 +0xca
cmd/compile/internal/gc.tmodeString(0xc00035cea0, 0x2, 0x1, 0x0, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1672 +0x48
cmd/compile/internal/gc.typefmt(0xc00035cf00, 0x0, 0x2, 0x1, 0x0, 0xc0004e59d0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:716 +0x4d9
cmd/compile/internal/gc.tconv(0xc00035cf00, 0x1, 0x0, 0x0, 0x4113c1, 0xc0004980e0)
	/home/alberto/go/src/cmd/compile/internal/gc/fmt.go:1766 +0xca
cmd/compile/internal/gc.Main.func2(0xc00035cf00, 0x1, 0x0, 0x0, 0x40b53f, 0xc0004be190)
	/home/alberto/go/src/cmd/compile/internal/gc/main.go:441 +0x49
cmd/compile/internal/types.(*Type).ShortString(0xc00035cf00, 0xc0004e5ab0, 0x4d911c)
	/home/alberto/go/src/cmd/compile/internal/types/utils.go:56 +0x53
cmd/compile/internal/gc.typesymname(0xc00035cf00, 0xc00000e240, 0x120000c00049a440)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:925 +0x2f
cmd/compile/internal/gc.typesym(0xc00035cf00, 0xc00035cea0)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:948 +0x2b
cmd/compile/internal/gc.typenamesym(0xc00035cf00, 0x7)
	/home/alberto/go/src/cmd/compile/internal/gc/reflect.go:970 +0xb1
cmd/compile/internal/gc.ngotype(0xc0004c41e0, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:1886 +0x34
cmd/compile/internal/gc.debuginfo(0xc0004b1110, 0xca17e0, 0xc0004c8000, 0xc0004b11f0, 0xc0004b1260, 0x0, 0xc0004b12d0, 0x7ff252c2a000, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:370 +0x1ca
cmd/internal/obj.(*Link).populateDWARF(0xc00000e240, 0xca17e0, 0xc0004c8000, 0xc0004b1110, 0x7ffc1a8ef301, 0x13)
	/home/alberto/go/src/cmd/internal/obj/objfile.go:551 +0x548
cmd/internal/obj.Flushplist(0xc00000e240, 0xc0004e5f08, 0xc0004c21f0, 0x7ffc1a8ef301, 0x13)
	/home/alberto/go/src/cmd/internal/obj/plist.go:109 +0x715
cmd/compile/internal/gc.(*Progs).Flush(0xc0004b1650)
	/home/alberto/go/src/cmd/compile/internal/gc/gsubr.go:93 +0xbc
cmd/compile/internal/gc.compileSSA(0xc0004c8000, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:283 +0x2b9
cmd/compile/internal/gc.compileFunctions.func2(0xc0004b4c60, 0xc000498120, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:323 +0x49
created by cmd/compile/internal/gc.compileFunctions
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:321 +0x11a

@mdempsky
Copy link
Member

mdempsky commented Jul 4, 2018

Thanks, I can reproduce that now.

@gopherbot
Copy link

Change https://golang.org/cl/122517 mentions this issue: cmd/compile: fix "width not calculated" ICE

@golang golang locked and limited conversation to collaborators Jul 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants