mirror of
https://github.com/golang/go.git
synced 2025-11-11 06:01:06 +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
8 changed files with 18 additions and 32 deletions
|
|
@ -49,7 +49,6 @@ import (
|
||||||
// pointer from the Func back to the OCALLPART.
|
// pointer from the Func back to the OCALLPART.
|
||||||
type Func struct {
|
type Func struct {
|
||||||
miniNode
|
miniNode
|
||||||
typ *types.Type
|
|
||||||
Body Nodes
|
Body Nodes
|
||||||
Iota int64
|
Iota int64
|
||||||
|
|
||||||
|
|
@ -116,9 +115,7 @@ func NewFunc(pos src.XPos) *Func {
|
||||||
|
|
||||||
func (f *Func) isStmt() {}
|
func (f *Func) isStmt() {}
|
||||||
|
|
||||||
func (f *Func) Type() *types.Type { return f.typ }
|
func (f *Func) Type() *types.Type { return f.Nname.Type() }
|
||||||
func (f *Func) SetType(x *types.Type) { f.typ = x }
|
|
||||||
|
|
||||||
func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
|
func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
|
||||||
func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
|
func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
|
||||||
|
|
||||||
|
|
@ -236,17 +233,6 @@ func FuncSymName(s *types.Sym) string {
|
||||||
return s.Name + "·f"
|
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.
|
// MarkFunc marks a node as a function.
|
||||||
func MarkFunc(n *Name) {
|
func MarkFunc(n *Name) {
|
||||||
if n.Op() != ONAME || n.Class_ != Pxxx {
|
if n.Op() != ONAME || n.Class_ != Pxxx {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
|
||||||
_32bit uintptr // size on 32bit platforms
|
_32bit uintptr // size on 32bit platforms
|
||||||
_64bit uintptr // size on 64bit platforms
|
_64bit uintptr // size on 64bit platforms
|
||||||
}{
|
}{
|
||||||
{Func{}, 200, 352},
|
{Func{}, 196, 344},
|
||||||
{Name{}, 132, 232},
|
{Name{}, 132, 232},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -524,7 +524,8 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {
|
||||||
name = ir.BlankNode.Sym() // filled in by typecheckfunc
|
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.Defn = f
|
||||||
f.Nname.Ntype = t
|
f.Nname.Ntype = t
|
||||||
|
|
||||||
|
|
@ -1742,7 +1743,9 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
|
||||||
|
|
||||||
fn := ir.NewFunc(p.pos(expr))
|
fn := ir.NewFunc(p.pos(expr))
|
||||||
fn.SetIsHiddenClosure(ir.CurFunc != nil)
|
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.Ntype = xtype
|
||||||
fn.Nname.Defn = fn
|
fn.Nname.Defn = fn
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ func DeclFunc(sym *types.Sym, tfn ir.Ntype) *ir.Func {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn := ir.NewFunc(base.Pos)
|
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.Defn = fn
|
||||||
fn.Nname.Ntype = tfn
|
fn.Nname.Ntype = tfn
|
||||||
ir.MarkFunc(fn.Nname)
|
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
|
// ipkg is the package being imported
|
||||||
func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
|
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)
|
n := importobj(ipkg, pos, s, ir.ONAME, ir.PFUNC, t)
|
||||||
|
n.Func = ir.NewFunc(pos)
|
||||||
fn := ir.NewFunc(pos)
|
n.Func.Nname = n
|
||||||
fn.SetType(t)
|
|
||||||
n.SetFunc(fn)
|
|
||||||
fn.Nname = n
|
|
||||||
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -409,7 +409,6 @@ func tcFunc(n *ir.Func) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n.SetType(t)
|
|
||||||
rcvr := t.Recv()
|
rcvr := t.Recv()
|
||||||
if rcvr != nil && n.Shortname != nil {
|
if rcvr != nil && n.Shortname != nil {
|
||||||
m := addmethod(n, n.Shortname, t, true, n.Pragma&ir.Nointerface != 0)
|
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()
|
recv := r.param()
|
||||||
mtyp := r.signature(recv)
|
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.
|
// 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 := types.NewField(mpos, msym, mtyp)
|
||||||
f.Nname = m
|
f.Nname = m
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func Closure(fn *ir.Func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
types.CalcSize(f.Type())
|
types.CalcSize(f.Type())
|
||||||
fn.SetType(f.Type()) // update type of ODCLFUNC
|
fn.Nname.SetType(f.Type()) // update type of ODCLFUNC
|
||||||
} else {
|
} else {
|
||||||
// The closure is not called, so it is going to stay as closure.
|
// The closure is not called, so it is going to stay as closure.
|
||||||
var body []ir.Node
|
var body []ir.Node
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue