]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: fix some issues with cons.go
authorKeith Randall <khr@golang.org>
Fri, 23 Jul 2021 22:23:57 +0000 (15:23 -0700)
committerKeith Randall <khr@golang.org>
Fri, 23 Jul 2021 23:44:49 +0000 (23:44 +0000)
Add a test to make sure there's no invalid OCONVIFACEs when stenciling is done.

Use concrete types for the type of DOTTYPE and DOTTYPE2.

MarkTypeUsedInInterface - should we allow types with shape types
underneath? I think the itab CL will help with this (at least, for
a remaining cons.go issue).

Change-Id: I2c96d74e8daaca26cadc84ea94abb9a27c0bb240
Reviewed-on: https://go-review.googlesource.com/c/go/+/337069
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/reflectdata/reflect.go

index 461083d171017e74e1226e3b8d3612935037cb7d..85538f590dcf8ba0c8075595d9ea9d5a5d1a580e 100644 (file)
@@ -994,6 +994,26 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, shapes, targs
        g.instTypeList = append(g.instTypeList, subst.unshapify.InstTypeList...)
        g.instTypeList = append(g.instTypeList, subst.concretify.InstTypeList...)
 
+       if doubleCheck {
+               okConvs := map[ir.Node]bool{}
+               ir.Visit(newf, func(n ir.Node) {
+                       if n.Op() == ir.OIDATA {
+                               // IDATA(OCONVIFACE(x)) is ok, as we don't use the type of x.
+                               // TODO: use some other op besides OCONVIFACE. ONEW might work
+                               // (with appropriate direct vs. indirect interface cases).
+                               okConvs[n.(*ir.UnaryExpr).X] = true
+                       }
+                       if n.Op() == ir.OCONVIFACE && !okConvs[n] {
+                               c := n.(*ir.ConvExpr)
+                               if c.X.Type().HasShape() {
+                                       ir.Dump("BAD FUNCTION", newf)
+                                       ir.Dump("BAD CONVERSION", c)
+                                       base.Fatalf("converting shape type to interface")
+                               }
+                       }
+               })
+       }
+
        return newf
 }
 
@@ -1367,6 +1387,8 @@ func (subst *subster) node(n ir.Node) ir.Node {
                        if x.X.Type().HasTParam() {
                                m = subst.convertUsingDictionary(m.Pos(), m.(*ir.ConvExpr).X, x, m.Type(), x.X.Type())
                        }
+               case ir.ODOTTYPE, ir.ODOTTYPE2:
+                       m.SetType(subst.unshapifyTyp(m.Type()))
 
                case ir.ONEW:
                        // New needs to pass a concrete type to the runtime.
@@ -1535,7 +1557,7 @@ func (g *irgen) getDictionarySym(gf *ir.Name, targs []*types.Type, isMeth bool)
 
        // Enforce that only concrete types can make it to here.
        for _, t := range targs {
-               if t.IsShape() {
+               if t.HasShape() {
                        panic(fmt.Sprintf("shape %+v in dictionary for %s", t, gf.Sym().Name))
                }
        }
index 1391102d0f05e69edd7df5ad44f4400fee4564c0..875d53b3cca4c1486119f8bcbfc24bc5c681ee8a 100644 (file)
@@ -1982,6 +1982,12 @@ var ZeroSize int64
 // MarkTypeUsedInInterface marks that type t is converted to an interface.
 // This information is used in the linker in dead method elimination.
 func MarkTypeUsedInInterface(t *types.Type, from *obj.LSym) {
+       if t.HasShape() {
+               // TODO: shape types shouldn't be put in interfaces, so we shouldn't ever get here.
+               // We don't from ../noder/stencil.go, but we do from ../walk/walk.go when we let
+               // shape types become the types of interfaces.
+               //base.Fatalf("shape types have no methods %+v", t)
+       }
        tsym := TypeLinksym(t)
        // Emit a marker relocation. The linker will know the type is converted
        // to an interface if "from" is reachable.