1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:46:47 -07:00

cmd/compile/internal/ir: remove Ntype

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>
This commit is contained in:
Matthew Dempsky 2023-08-17 23:23:40 -07:00 committed by Gopher Robot
parent f9410990e6
commit 09b03117b0
4 changed files with 6 additions and 46 deletions

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

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

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

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