1
0
mirror of https://github.com/golang/go synced 2024-07-03 00:40:45 +00:00

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.
defercheckwidth()
underlying := r.typ()
copytype(typenod(t), underlying)
setUnderlying(t, underlying)
resumecheckwidth()
if underlying.IsInterface() {

View 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)
}
}

View 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
}