]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove types2.(*Selection).TArgs(), now that instance bug seems fixed
authorDan Scales <danscales@google.com>
Thu, 4 Mar 2021 20:09:04 +0000 (12:09 -0800)
committerDan Scales <danscales@google.com>
Thu, 4 Mar 2021 23:37:01 +0000 (23:37 +0000)
Previously, we would sometimes see an internal (*instance) type for a
receiver of a types2 method, which was a bug. To deal with that, we put
in an extra (*Selection).TArgs() method. However, that (*instance) type
is no longer showing up for receivers, so we can remove the types2
method we added and do the work with existing types2 API methods.

Change-Id: I03e68f5bbaaf82fe706b6efecbb02e951bbd3cd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/298869
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>

src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/types2/selection.go

index 3fded144dcdaf30a28177c5dbeca37a81da63a80..b99f5a4cdd92edafa3777bb4ce2783479dd410a0 100644 (file)
@@ -253,7 +253,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
 
                                // selinfo.Targs() are the types used to
                                // instantiate the type of receiver
-                               targs2 := selinfo.TArgs()
+                               targs2 := getTargs(selinfo)
                                targs := make([]ir.Node, len(targs2))
                                for i, targ2 := range targs2 {
                                        targs[i] = ir.TypeNode(g.typ(targ2))
@@ -279,6 +279,19 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
        return n
 }
 
+// getTargs gets the targs associated with the receiver of a selected method
+func getTargs(selinfo *types2.Selection) []types2.Type {
+       r := selinfo.Recv()
+       if p := types2.AsPointer(r); p != nil {
+               r = p.Elem()
+       }
+       n := types2.AsNamed(r)
+       if n == nil {
+               base.Fatalf("Incorrect type for selinfo %v", selinfo)
+       }
+       return n.TArgs()
+}
+
 func (g *irgen) exprList(expr syntax.Expr) []ir.Node {
        switch expr := expr.(type) {
        case nil:
index 02c0fc690252c0aba0b1ee79755652591499e461..8128aeee2e5113b6979990cfba4e94e373b206a9 100644 (file)
@@ -51,22 +51,6 @@ func (s *Selection) Kind() SelectionKind { return s.kind }
 // Recv returns the type of x in x.f.
 func (s *Selection) Recv() Type { return s.recv }
 
-// Work-around for a compiler issue where an (*instance) escapes.
-// TODO(gri): Is this still needed?
-func (s *Selection) TArgs() []Type {
-       r := s.recv
-       if p := asPointer(r); p != nil {
-               r = p.Elem()
-       }
-       if n := asNamed(r); n != nil {
-               return n.TArgs()
-       }
-       // The base type (after skipping any pointer) must be a Named type. The
-       // bug is that sometimes it can be an instance type (which is supposed to
-       // be an internal type only).
-       return r.(*instance).targs
-}
-
 // Obj returns the object denoted by x.f; a *Var for
 // a field selection, and a *Func in all other cases.
 func (s *Selection) Obj() Object { return s.obj }