1
0
mirror of https://github.com/golang/go synced 2024-11-17 07:54:41 -07:00

cmd/compile: remove ir.TypeAssertExpr.Ntype

As with ir.CompLitExpr.Ntype, there's no need for
ir.TypeAssertExpr.Ntype in a pure-types2 world.

Change-Id: Iff48c98330f072fd6b26099e13a19c56adecdc42
Reviewed-on: https://go-review.googlesource.com/c/go/+/403842
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2022-05-02 18:39:07 -07:00
parent 27b844f767
commit 025a9c3438
9 changed files with 17 additions and 41 deletions

View File

@ -648,18 +648,20 @@ func (n *StarExpr) SetOTYPE(t *types.Type) {
// Before type-checking, the type is Ntype. // Before type-checking, the type is Ntype.
type TypeAssertExpr struct { type TypeAssertExpr struct {
miniExpr miniExpr
X Node X Node
Ntype Ntype
// Runtime type information provided by walkDotType for // Runtime type information provided by walkDotType for
// assertions from non-empty interface to concrete type. // assertions from non-empty interface to concrete type.
Itab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type Itab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type
} }
func NewTypeAssertExpr(pos src.XPos, x Node, typ Ntype) *TypeAssertExpr { func NewTypeAssertExpr(pos src.XPos, x Node, typ *types.Type) *TypeAssertExpr {
n := &TypeAssertExpr{X: x, Ntype: typ} n := &TypeAssertExpr{X: x}
n.pos = pos n.pos = pos
n.op = ODOTTYPE n.op = ODOTTYPE
if typ != nil {
n.SetType(typ)
}
return n return n
} }

View File

@ -717,10 +717,6 @@ func exprFmt(n Node, s fmt.State, prec int) {
case ODOTTYPE, ODOTTYPE2: case ODOTTYPE, ODOTTYPE2:
n := n.(*TypeAssertExpr) n := n.(*TypeAssertExpr)
exprFmt(n.X, s, nprec) exprFmt(n.X, s, nprec)
if n.Ntype != nil {
fmt.Fprintf(s, ".(%v)", n.Ntype)
return
}
fmt.Fprintf(s, ".(%v)", n.Type()) fmt.Fprintf(s, ".(%v)", n.Type())
case OINDEX, OINDEXMAP: case OINDEX, OINDEXMAP:

View File

@ -1249,9 +1249,6 @@ func (n *TypeAssertExpr) doChildren(do func(Node) bool) bool {
if n.X != nil && do(n.X) { if n.X != nil && do(n.X) {
return true return true
} }
if n.Ntype != nil && do(n.Ntype) {
return true
}
return false return false
} }
func (n *TypeAssertExpr) editChildren(edit func(Node) Node) { func (n *TypeAssertExpr) editChildren(edit func(Node) Node) {
@ -1259,9 +1256,6 @@ func (n *TypeAssertExpr) editChildren(edit func(Node) Node) {
if n.X != nil { if n.X != nil {
n.X = edit(n.X).(Node) n.X = edit(n.X).(Node)
} }
if n.Ntype != nil {
n.Ntype = edit(n.Ntype).(Ntype)
}
} }
func (n *TypeSwitchGuard) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) } func (n *TypeSwitchGuard) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) }

View File

@ -1638,7 +1638,7 @@ func (r *reader) expr() (res ir.Node) {
if typ, ok := typ.(*ir.DynamicType); ok && typ.Op() == ir.ODYNAMICTYPE { if typ, ok := typ.(*ir.DynamicType); ok && typ.Op() == ir.ODYNAMICTYPE {
return typed(typ.Type(), ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, x, typ.X)) return typed(typ.Type(), ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, x, typ.X))
} }
return typecheck.Expr(ir.NewTypeAssertExpr(pos, x, typ.(ir.Ntype))) return typecheck.Expr(ir.NewTypeAssertExpr(pos, x, typ.Type()))
case exprUnaryOp: case exprUnaryOp:
op := r.op() op := r.op()

View File

@ -2266,15 +2266,12 @@ func closureSym(outer *ir.Func, prefix string, n int) *types.Sym {
// assertToBound returns a new node that converts a node rcvr with interface type to // assertToBound returns a new node that converts a node rcvr with interface type to
// the 'dst' interface type. // the 'dst' interface type.
func assertToBound(info *instInfo, dictVar *ir.Name, pos src.XPos, rcvr ir.Node, dst *types.Type) ir.Node { func assertToBound(info *instInfo, dictVar *ir.Name, pos src.XPos, rcvr ir.Node, dst *types.Type) ir.Node {
if dst.HasShape() { if !dst.HasShape() {
ix := findDictType(info, dst) return typed(dst, ir.NewTypeAssertExpr(pos, rcvr, nil))
assert(ix >= 0)
rt := getDictionaryType(info, dictVar, pos, ix)
rcvr = ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, rcvr, rt)
typed(dst, rcvr)
} else {
rcvr = ir.NewTypeAssertExpr(pos, rcvr, nil)
typed(dst, rcvr)
} }
return rcvr
ix := findDictType(info, dst)
assert(ix >= 0)
rt := getDictionaryType(info, dictVar, pos, ix)
return typed(dst, ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, rcvr, rt))
} }

View File

@ -532,14 +532,7 @@ func tcDotType(n *ir.TypeAssertExpr) ir.Node {
return n return n
} }
if n.Ntype != nil { base.AssertfAt(n.Type() != nil, n.Pos(), "missing type: %v", n)
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
n.Ntype = nil
if n.Type() == nil {
return n
}
}
if n.Type() != nil && !n.Type().IsInterface() { if n.Type() != nil && !n.Type().IsInterface() {
var missing, have *types.Field var missing, have *types.Field

View File

@ -1480,8 +1480,7 @@ func (r *importReader) node() ir.Node {
return n return n
case ir.ODOTTYPE, ir.ODOTTYPE2: case ir.ODOTTYPE, ir.ODOTTYPE2:
n := ir.NewTypeAssertExpr(r.pos(), r.expr(), nil) n := ir.NewTypeAssertExpr(r.pos(), r.expr(), r.typ())
n.SetType(r.typ())
n.SetOp(op) n.SetOp(op)
return n return n

View File

@ -234,10 +234,6 @@ func Func(fn *ir.Func) {
} }
} }
func typecheckNtype(n ir.Ntype) ir.Ntype {
return typecheck(n, ctxType).(ir.Ntype)
}
// typecheck type checks node n. // typecheck type checks node n.
// The result of typecheck MUST be assigned back to n, e.g. // The result of typecheck MUST be assigned back to n, e.g.
// //

View File

@ -567,8 +567,7 @@ func (s *typeSwitch) Add(pos src.XPos, n1 ir.Node, caseVar *ir.Name, jmp ir.Node
switch n1.Op() { switch n1.Op() {
case ir.OTYPE: case ir.OTYPE:
// Static type assertion (non-generic) // Static type assertion (non-generic)
dot := ir.NewTypeAssertExpr(pos, s.facename, nil) dot := ir.NewTypeAssertExpr(pos, s.facename, typ) // iface.(type)
dot.SetType(typ) // iface.(type)
as.Rhs = []ir.Node{dot} as.Rhs = []ir.Node{dot}
case ir.ODYNAMICTYPE: case ir.ODYNAMICTYPE:
// Dynamic type assertion (generic) // Dynamic type assertion (generic)