]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix "width not calculated" ICE
authorMatthew Dempsky <mdempsky@google.com>
Fri, 6 Jul 2018 19:14:22 +0000 (12:14 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 6 Jul 2018 20:25:52 +0000 (20:25 +0000)
Expanding interface method sets is handled during width calculation,
which can't be performed concurrently. Make sure that we eagerly
expand interfaces in the frontend when importing them, even if they're
not actually used by code, because we might need to generate a type
description of them.

Fixes #25055.

Change-Id: I6fd2756de2c7d5dbc33056f70b3028ca3aebab41
Reviewed-on: https://go-review.googlesource.com/122517
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/iimport.go
test/fixedbugs/issue25055.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue25055.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue25055.go [new file with mode: 0644]

index 54c5d8dc2ff10e092fd5f10a9d59b51f776ca2b0..21151b52159e1a3e3484f35a11837a3d6577bfe3 100644 (file)
@@ -296,8 +296,23 @@ func (r *importReader) doDecl(n *Node) {
                // declaration before recursing.
                t := importtype(r.p.ipkg, pos, n.Sym)
 
+               // We also need to defer width calculations until
+               // after the underlying type has been assigned.
+               //
+               // TODO(mdempsky): Add nesting support directly to
+               // {defer,resume}checkwidth? Width calculations are
+               // already deferred during initial typechecking, but
+               // not when we're expanding inline function bodies, so
+               // we currently need to handle both cases here.
+               deferring := defercalc != 0
+               if !deferring {
+                       defercheckwidth()
+               }
                underlying := r.typ()
                copytype(typenod(t), underlying)
+               if !deferring {
+                       resumecheckwidth()
+               }
 
                if underlying.IsInterface() {
                        break
@@ -576,6 +591,10 @@ func (r *importReader) typ1() *types.Type {
                t := types.New(TINTER)
                t.SetPkg(r.currPkg)
                t.SetInterface(append(embeddeds, methods...))
+
+               // Ensure we expand the interface in the frontend (#25055).
+               checkwidth(t)
+
                return t
        }
 }
diff --git a/test/fixedbugs/issue25055.dir/a.go b/test/fixedbugs/issue25055.dir/a.go
new file mode 100644 (file)
index 0000000..7fea195
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+var A chan *interface{}
diff --git a/test/fixedbugs/issue25055.dir/b.go b/test/fixedbugs/issue25055.dir/b.go
new file mode 100644 (file)
index 0000000..01efeae
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package b
+
+import "./a"
+
+var _ = <-a.A
diff --git a/test/fixedbugs/issue25055.go b/test/fixedbugs/issue25055.go
new file mode 100644 (file)
index 0000000..0e15a8e
--- /dev/null
@@ -0,0 +1,7 @@
+// compiledir -c=2
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ignored