mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +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:
parent
380ef6b759
commit
a71967e4c5
@ -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() {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user