]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: replace copytype to setUnderlying
authorMatthew Dempsky <mdempsky@google.com>
Fri, 30 Aug 2019 22:59:16 +0000 (15:59 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 3 Sep 2019 17:50:54 +0000 (17:50 +0000)
While here, change the params to be easier to understand: "t" is now
always the type being updated, and "underlying" is now used to
represent the underlying type.

Updates #33658.

Change-Id: Iabb64414ca3abaa8c780e4c9093e0c77b76fabf9
Reviewed-on: https://go-review.googlesource.com/c/go/+/192724
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/types/type.go

index 4f44c5486846938420ad6a0bcc7781e5dfeeff28..1d4329b4b1d47e1d4aee9ed676cb8cce9947f159 100644 (file)
@@ -300,7 +300,7 @@ func (r *importReader) doDecl(n *Node) {
                // after the underlying type has been assigned.
                defercheckwidth()
                underlying := r.typ()
-               copytype(typenod(t), underlying)
+               setUnderlying(t, underlying)
                resumecheckwidth()
 
                if underlying.IsInterface() {
index 610c9066b88104858558cd0908ad772ef5c57bf6..5d5348fe2ca23b4b00a72f821f61dbc7baa77326 100644 (file)
@@ -3442,26 +3442,28 @@ func checkMapKeys() {
        mapqueue = nil
 }
 
-func copytype(n *Node, t *types.Type) {
-       if t.Etype == TFORW {
+func setUnderlying(t, underlying *types.Type) {
+       if underlying.Etype == TFORW {
                // This type isn't computed yet; when it is, update n.
-               t.ForwardType().Copyto = append(t.ForwardType().Copyto, asTypesNode(n))
+               underlying.ForwardType().Copyto = append(underlying.ForwardType().Copyto, t)
                return
        }
 
-       embedlineno := n.Type.ForwardType().Embedlineno
-       l := n.Type.ForwardType().Copyto
-
-       cache := n.Type.Cache
+       n := asNode(t.Nod)
+       ft := t.ForwardType()
+       cache := t.Cache
 
        // TODO(mdempsky): Fix Type rekinding.
-       *n.Type = *t
+       *t = *underlying
 
-       t = n.Type
+       // Restore unnecessarily clobbered attributes.
+       t.Nod = asTypesNode(n)
        t.Sym = n.Sym
        if n.Name != nil {
                t.Vargen = n.Name.Vargen
        }
+       t.Cache = cache
+       t.SetDeferwidth(false)
 
        // spec: "The declared type does not inherit any methods bound
        // to the existing type, but the method set of an interface
@@ -3471,24 +3473,20 @@ func copytype(n *Node, t *types.Type) {
                *t.AllMethods() = types.Fields{}
        }
 
-       t.Nod = asTypesNode(n)
-       t.SetDeferwidth(false)
-       t.Cache = cache
-
        // Propagate go:notinheap pragma from the Name to the Type.
        if n.Name != nil && n.Name.Param != nil && n.Name.Param.Pragma&NotInHeap != 0 {
                t.SetNotInHeap(true)
        }
 
-       // Update nodes waiting on this type.
-       for _, n := range l {
-               copytype(asNode(n), t)
+       // Update types waiting on this type.
+       for _, w := range ft.Copyto {
+               setUnderlying(w, t)
        }
 
        // Double-check use of type as embedded type.
-       if embedlineno.IsKnown() {
+       if ft.Embedlineno.IsKnown() {
                if t.IsPtr() || t.IsUnsafePtr() {
-                       yyerrorl(embedlineno, "embedded type cannot be a pointer")
+                       yyerrorl(ft.Embedlineno, "embedded type cannot be a pointer")
                }
        }
 }
@@ -3509,7 +3507,7 @@ func typecheckdeftype(n *Node) {
        } else {
                // copy new type and clear fields
                // that don't come along.
-               copytype(n, t)
+               setUnderlying(n.Type, t)
        }
 }
 
index e4ab40c4fdf47189e2dd1863baa6fd54f40c5fff..2c8409b3b350e282d8e93bc2ae18cb8dae8f4654 100644 (file)
@@ -236,7 +236,7 @@ func (t *Type) MapType() *Map {
 
 // Forward contains Type fields specific to forward types.
 type Forward struct {
-       Copyto      []*Node  // where to copy the eventual value to
+       Copyto      []*Type  // where to copy the eventual value to
        Embedlineno src.XPos // first use of this type as an embedded type
 }