mirror of
https://github.com/golang/go
synced 2024-10-14 20:05:36 +00:00
[dev.regabi] cmd/compile: simplify ir.Func somewhat
Two simplifications: 1. Statements (including ODCLFUNC) don't have types, and the Func.Nname already has a type. There's no need for a second one. However, there is a lot of code that expects to be able to call Func.Type, so leave a forwarding method, like with Sym and Linksym. 2. Inline and remove ir.NewFuncNameAt. It doesn't really save any code, and it's only used a handful of places. Passes toolstash -cmp. Change-Id: I51acaa341897dae0fcdf2fa576a10174a2ae4d1e Reviewed-on: https://go-review.googlesource.com/c/go/+/280648 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
e40cb4d4ae
commit
9ea272e5ec
|
@ -49,7 +49,6 @@ import (
|
|||
// pointer from the Func back to the OCALLPART.
|
||||
type Func struct {
|
||||
miniNode
|
||||
typ *types.Type
|
||||
Body Nodes
|
||||
Iota int64
|
||||
|
||||
|
@ -116,9 +115,7 @@ func NewFunc(pos src.XPos) *Func {
|
|||
|
||||
func (f *Func) isStmt() {}
|
||||
|
||||
func (f *Func) Type() *types.Type { return f.typ }
|
||||
func (f *Func) SetType(x *types.Type) { f.typ = x }
|
||||
|
||||
func (f *Func) Type() *types.Type { return f.Nname.Type() }
|
||||
func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
|
||||
func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
|
||||
|
||||
|
@ -236,17 +233,6 @@ func FuncSymName(s *types.Sym) string {
|
|||
return s.Name + "·f"
|
||||
}
|
||||
|
||||
// NewFuncNameAt generates a new name node for a function or method.
|
||||
func NewFuncNameAt(pos src.XPos, s *types.Sym, fn *Func) *Name {
|
||||
if fn.Nname != nil {
|
||||
base.Fatalf("newFuncName - already have name")
|
||||
}
|
||||
n := NewNameAt(pos, s)
|
||||
n.SetFunc(fn)
|
||||
fn.Nname = n
|
||||
return n
|
||||
}
|
||||
|
||||
// MarkFunc marks a node as a function.
|
||||
func MarkFunc(n *Name) {
|
||||
if n.Op() != ONAME || n.Class_ != Pxxx {
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
|
|||
_32bit uintptr // size on 32bit platforms
|
||||
_64bit uintptr // size on 64bit platforms
|
||||
}{
|
||||
{Func{}, 200, 352},
|
||||
{Func{}, 196, 344},
|
||||
{Name{}, 132, 232},
|
||||
}
|
||||
|
||||
|
|
|
@ -524,7 +524,8 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {
|
|||
name = ir.BlankNode.Sym() // filled in by typecheckfunc
|
||||
}
|
||||
|
||||
f.Nname = ir.NewFuncNameAt(p.pos(fun.Name), name, f)
|
||||
f.Nname = ir.NewNameAt(p.pos(fun.Name), name)
|
||||
f.Nname.Func = f
|
||||
f.Nname.Defn = f
|
||||
f.Nname.Ntype = t
|
||||
|
||||
|
@ -1742,7 +1743,9 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
|
|||
|
||||
fn := ir.NewFunc(p.pos(expr))
|
||||
fn.SetIsHiddenClosure(ir.CurFunc != nil)
|
||||
fn.Nname = ir.NewFuncNameAt(p.pos(expr), ir.BlankNode.Sym(), fn) // filled in by typecheckclosure
|
||||
|
||||
fn.Nname = ir.NewNameAt(p.pos(expr), ir.BlankNode.Sym()) // filled in by typecheckclosure
|
||||
fn.Nname.Func = fn
|
||||
fn.Nname.Ntype = xtype
|
||||
fn.Nname.Defn = fn
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ func DeclFunc(sym *types.Sym, tfn ir.Ntype) *ir.Func {
|
|||
}
|
||||
|
||||
fn := ir.NewFunc(base.Pos)
|
||||
fn.Nname = ir.NewFuncNameAt(base.Pos, sym, fn)
|
||||
fn.Nname = ir.NewNameAt(base.Pos, sym)
|
||||
fn.Nname.Func = fn
|
||||
fn.Nname.Defn = fn
|
||||
fn.Nname.Ntype = tfn
|
||||
ir.MarkFunc(fn.Nname)
|
||||
|
|
|
@ -31,12 +31,8 @@ func importconst(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type, val
|
|||
// ipkg is the package being imported
|
||||
func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
|
||||
n := importobj(ipkg, pos, s, ir.ONAME, ir.PFUNC, t)
|
||||
|
||||
fn := ir.NewFunc(pos)
|
||||
fn.SetType(t)
|
||||
n.SetFunc(fn)
|
||||
fn.Nname = n
|
||||
|
||||
n.Func = ir.NewFunc(pos)
|
||||
n.Func.Nname = n
|
||||
return n
|
||||
}
|
||||
|
||||
|
|
|
@ -409,7 +409,6 @@ func tcFunc(n *ir.Func) {
|
|||
if t == nil {
|
||||
return
|
||||
}
|
||||
n.SetType(t)
|
||||
rcvr := t.Recv()
|
||||
if rcvr != nil && n.Shortname != nil {
|
||||
m := addmethod(n, n.Shortname, t, true, n.Pragma&ir.Nointerface != 0)
|
||||
|
|
|
@ -331,12 +331,13 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
|
|||
recv := r.param()
|
||||
mtyp := r.signature(recv)
|
||||
|
||||
fn := ir.NewFunc(mpos)
|
||||
fn.SetType(mtyp)
|
||||
m := ir.NewFuncNameAt(mpos, ir.MethodSym(recv.Type, msym), fn)
|
||||
m.SetType(mtyp)
|
||||
m.Class_ = ir.PFUNC
|
||||
// methodSym already marked m.Sym as a function.
|
||||
m := ir.NewNameAt(mpos, ir.MethodSym(recv.Type, msym))
|
||||
m.Class_ = ir.PFUNC
|
||||
m.SetType(mtyp)
|
||||
|
||||
m.Func = ir.NewFunc(mpos)
|
||||
m.Func.Nname = m
|
||||
|
||||
f := types.NewField(mpos, msym, mtyp)
|
||||
f.Nname = m
|
||||
|
|
|
@ -67,7 +67,7 @@ func Closure(fn *ir.Func) {
|
|||
}
|
||||
|
||||
types.CalcSize(f.Type())
|
||||
fn.SetType(f.Type()) // update type of ODCLFUNC
|
||||
fn.Nname.SetType(f.Type()) // update type of ODCLFUNC
|
||||
} else {
|
||||
// The closure is not called, so it is going to stay as closure.
|
||||
var body []ir.Node
|
||||
|
|
Loading…
Reference in a new issue