summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2019-08-30 15:59:16 -0700
committerMatthew Dempsky <mdempsky@google.com>2019-09-03 17:50:54 +0000
commita71967e4c5aa34f274b8b9aff915f14ac00e7ee8 (patch)
tree803190cf4660ffa5c842e83d5879f5454f4c6447 /src
parent380ef6b75905400855a170de4f159faec587015e (diff)
downloadgo-git-a71967e4c5aa34f274b8b9aff915f14ac00e7ee8.tar.gz
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>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/iimport.go2
-rw-r--r--src/cmd/compile/internal/gc/typecheck.go36
-rw-r--r--src/cmd/compile/internal/types/type.go2
3 files changed, 19 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/gc/iimport.go b/src/cmd/compile/internal/gc/iimport.go
index 4f44c54868..1d4329b4b1 100644
--- a/src/cmd/compile/internal/gc/iimport.go
+++ b/src/cmd/compile/internal/gc/iimport.go
@@ -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() {
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 610c9066b8..5d5348fe2c 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -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)
}
}
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index e4ab40c4fd..2c8409b3b3 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -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
}