aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/type.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-11-25 00:30:58 -0500
committerRuss Cox <rsc@golang.org>2020-11-25 17:30:40 +0000
commitc26aead50c3c8226c51fb97a94852f2134b881aa (patch)
treeb6e9d775fce43b9c96d290e73adc6403eff13514 /src/cmd/compile/internal/types/type.go
parentacb4d1cef14529585266df1868045f80e37ae081 (diff)
downloadgo-c26aead50c3c8226c51fb97a94852f2134b881aa.tar.gz
go-c26aead50c3c8226c51fb97a94852f2134b881aa.zip
[dev.regabi] cmd/compile: convert types.Node (a pointer) to types.IRNode (an interface)
The pointer hack was nice and saved a word, but it's untenable in a world where nodes are themselves interfaces with different underlying types. Bite the bullet and use an interface to hold the Node when in types.Sym and types.Type. This has the nice benefit of removing AsTypesNode entirely. AsNode is still useful because of its nil handling. Change-Id: I298cba9ff788b956ee287283bec78010e8b601e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/272933 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r--src/cmd/compile/internal/types/type.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index b93409aac1..8499a36edc 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -10,10 +10,10 @@ import (
"fmt"
)
-// Our own “Node” so we can refer to *gc.Node without actually
-// having a gc.Node. Necessary to break import cycles.
-// TODO(gri) try to eliminate soon
-type Node struct{ _ int }
+// IRNode represents an ir.Node, but without needing to import cmd/compile/internal/ir,
+// which would cause an import cycle. The uses in other packages must type assert
+// values of type IRNode to ir.Node or a more specific type.
+type IRNode interface{ Type() *Type }
//go:generate stringer -type EType -trimprefix T
@@ -141,8 +141,8 @@ type Type struct {
methods Fields
allMethods Fields
- Nod *Node // canonical OTYPE node
- Orig *Type // original type (type literal or predefined type)
+ Nod IRNode // canonical OTYPE node
+ Orig *Type // original type (type literal or predefined type)
// Cache of composite types, with this type being the element type.
Cache struct {
@@ -360,7 +360,7 @@ type Field struct {
// For fields that represent function parameters, Nname points
// to the associated ONAME Node.
- Nname *Node
+ Nname IRNode
// Offset in bytes of this field or method within its enclosing struct
// or interface Type.