]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ir: remove Ntype
authorMatthew Dempsky <mdempsky@google.com>
Fri, 18 Aug 2023 06:23:40 +0000 (23:23 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 18 Aug 2023 22:38:58 +0000 (22:38 +0000)
This type used to provide extra type safety around which syntactic
nodes could also represent types, but now the only remaining use is
ir.TypeNode, and it always ends up as an ir.Node anyway. So we might
as well use Node instead.

Change-Id: Ia0842864794365b0e155dc5af154c673ffa2967b
Reviewed-on: https://go-review.googlesource.com/c/go/+/520609
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/ir/mknode.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/ir/type.go
src/cmd/compile/internal/noder/reader.go

index 716e84389ff9997db07054af099479ce450a9d8c..ca78a03d048ffab05bae48a02b306e1fa54a50fb 100644 (file)
@@ -335,9 +335,9 @@ func processType(t *ast.TypeSpec) {
 }
 
 func generateHelpers() {
-       for _, typ := range []string{"CaseClause", "CommClause", "Name", "Node", "Ntype"} {
+       for _, typ := range []string{"CaseClause", "CommClause", "Name", "Node"} {
                ptr := "*"
-               if typ == "Node" || typ == "Ntype" {
+               if typ == "Node" {
                        ptr = "" // interfaces don't need *
                }
                fmt.Fprintf(&buf, "\n")
index debaeefc3d394044fa6b26ca56c66d88b3744f97..cde7ab0ca8b5d00b43fce4d8a8243f61efc9b3cf 100644 (file)
@@ -1799,27 +1799,3 @@ func editNodes(list []Node, edit func(Node) Node) {
                }
        }
 }
-
-func copyNtypes(list []Ntype) []Ntype {
-       if list == nil {
-               return nil
-       }
-       c := make([]Ntype, len(list))
-       copy(c, list)
-       return c
-}
-func doNtypes(list []Ntype, do func(Node) bool) bool {
-       for _, x := range list {
-               if x != nil && do(x) {
-                       return true
-               }
-       }
-       return false
-}
-func editNtypes(list []Ntype, edit func(Node) Node) {
-       for i, x := range list {
-               if x != nil {
-                       list[i] = edit(x).(Ntype)
-               }
-       }
-}
index 033d1eed4a252dfb3d180398186f935abff4bb68..00d0a1d634fe96160e4b6317d7a8c0c6e42bdca9 100644 (file)
@@ -11,21 +11,8 @@ import (
        "fmt"
 )
 
-// Nodes that represent the syntax of a type before type-checking.
-// After type-checking, they serve only as shells around a *types.Type.
 // Calling TypeNode converts a *types.Type to a Node shell.
 
-// An Ntype is a Node that syntactically looks like a type.
-// It can be the raw syntax for a type before typechecking,
-// or it can be an OTYPE with Type() set to a *types.Type.
-// Note that syntax doesn't guarantee it's a type: an expression
-// like *fmt is an Ntype (we don't know whether names are types yet),
-// but at least 1+1 is not an Ntype.
-type Ntype interface {
-       Node
-       CanBeNtype()
-}
-
 // A Field is a declared function parameter.
 // It is not a Node.
 type Field struct {
@@ -56,20 +43,20 @@ func newTypeNode(typ *types.Type) *typeNode {
        n := &typeNode{typ: typ}
        n.pos = src.NoXPos
        n.op = OTYPE
+       n.SetTypecheck(1)
        return n
 }
 
 func (n *typeNode) Type() *types.Type { return n.typ }
 func (n *typeNode) Sym() *types.Sym   { return n.typ.Sym() }
-func (n *typeNode) CanBeNtype()       {}
 
 // TypeNode returns the Node representing the type t.
-func TypeNode(t *types.Type) Ntype {
+func TypeNode(t *types.Type) Node {
        if n := t.Obj(); n != nil {
                if n.Type() != t {
                        base.Fatalf("type skew: %v has type %v, but expected %v", n, n.Type(), t)
                }
-               return n.(Ntype)
+               return n.(*Name)
        }
        return newTypeNode(t)
 }
index 99755a976b7e597166cd67a54c9d066ee6359631..08d731637fb7b41a9a967c246c564c6141a33ccc 100644 (file)
@@ -3287,10 +3287,7 @@ func (r *reader) exprType() ir.Node {
                typ, rtype = r.rtype0(pos)
 
                if !r.Bool() { // not derived
-                       // TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node.
-                       n := ir.TypeNode(typ)
-                       n.SetTypecheck(1)
-                       return n
+                       return ir.TypeNode(typ)
                }
        }