cmd/compile: replace copytype to setUnderlying

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>
This commit is contained in:
Matthew Dempsky 2019-08-30 15:59:16 -07:00
parent 380ef6b759
commit a71967e4c5
3 changed files with 19 additions and 21 deletions

View file

@ -300,7 +300,7 @@ func (r *importReader) doDecl(n *Node) {
// after the underlying type has been assigned. // after the underlying type has been assigned.
defercheckwidth() defercheckwidth()
underlying := r.typ() underlying := r.typ()
copytype(typenod(t), underlying) setUnderlying(t, underlying)
resumecheckwidth() resumecheckwidth()
if underlying.IsInterface() { if underlying.IsInterface() {

View file

@ -3442,26 +3442,28 @@ func checkMapKeys() {
mapqueue = nil mapqueue = nil
} }
func copytype(n *Node, t *types.Type) { func setUnderlying(t, underlying *types.Type) {
if t.Etype == TFORW { if underlying.Etype == TFORW {
// This type isn't computed yet; when it is, update n. // 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 return
} }
embedlineno := n.Type.ForwardType().Embedlineno n := asNode(t.Nod)
l := n.Type.ForwardType().Copyto ft := t.ForwardType()
cache := t.Cache
cache := n.Type.Cache
// TODO(mdempsky): Fix Type rekinding. // 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 t.Sym = n.Sym
if n.Name != nil { if n.Name != nil {
t.Vargen = n.Name.Vargen t.Vargen = n.Name.Vargen
} }
t.Cache = cache
t.SetDeferwidth(false)
// spec: "The declared type does not inherit any methods bound // spec: "The declared type does not inherit any methods bound
// to the existing type, but the method set of an interface // 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.AllMethods() = types.Fields{}
} }
t.Nod = asTypesNode(n)
t.SetDeferwidth(false)
t.Cache = cache
// Propagate go:notinheap pragma from the Name to the Type. // Propagate go:notinheap pragma from the Name to the Type.
if n.Name != nil && n.Name.Param != nil && n.Name.Param.Pragma&NotInHeap != 0 { if n.Name != nil && n.Name.Param != nil && n.Name.Param.Pragma&NotInHeap != 0 {
t.SetNotInHeap(true) t.SetNotInHeap(true)
} }
// Update nodes waiting on this type. // Update types waiting on this type.
for _, n := range l { for _, w := range ft.Copyto {
copytype(asNode(n), t) setUnderlying(w, t)
} }
// Double-check use of type as embedded type. // Double-check use of type as embedded type.
if embedlineno.IsKnown() { if ft.Embedlineno.IsKnown() {
if t.IsPtr() || t.IsUnsafePtr() { 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 { } else {
// copy new type and clear fields // copy new type and clear fields
// that don't come along. // that don't come along.
copytype(n, t) setUnderlying(n.Type, t)
} }
} }

View file

@ -236,7 +236,7 @@ func (t *Type) MapType() *Map {
// Forward contains Type fields specific to forward types. // Forward contains Type fields specific to forward types.
type Forward struct { 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 Embedlineno src.XPos // first use of this type as an embedded type
} }