mirror of
https://github.com/golang/go
synced 2024-11-22 21:20:03 -07:00
cmd/compile: set ir.Name.Func in more cases
ir.Name.Func is non-nil for *almost* all function names. This CL fixes a few more major cases that leave it nil, though there are still a few cases left: interface method values, and algorithms generated by eqFor, hashfor, and hashmem. We'll need this for mapping from ir.Names to function ABIs shortly. The remaining cases would be nice to fix, but they're all guaranteed to be ABIInternal, so we can at least work around them. For #40724. Change-Id: Ifcfa781c78899ccea0bf155d80f8cfc27f30351e Reviewed-on: https://go-review.googlesource.com/c/go/+/305271 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
33b4ffc357
commit
0d1423583b
@ -528,6 +528,13 @@ func (n *SelectorExpr) FuncName() *Name {
|
|||||||
fn := NewNameAt(n.Selection.Pos, MethodSym(n.X.Type(), n.Sel))
|
fn := NewNameAt(n.Selection.Pos, MethodSym(n.X.Type(), n.Sel))
|
||||||
fn.Class = PFUNC
|
fn.Class = PFUNC
|
||||||
fn.SetType(n.Type())
|
fn.SetType(n.Type())
|
||||||
|
if n.Selection.Nname != nil {
|
||||||
|
// TODO(austin): Nname is nil for interface method
|
||||||
|
// expressions (I.M), so we can't attach a Func to
|
||||||
|
// those here. reflectdata.methodWrapper generates the
|
||||||
|
// Func.
|
||||||
|
fn.Func = n.Selection.Nname.(*Name).Func
|
||||||
|
}
|
||||||
return fn
|
return fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ type Name struct {
|
|||||||
pragma PragmaFlag // int16
|
pragma PragmaFlag // int16
|
||||||
flags bitset16
|
flags bitset16
|
||||||
sym *types.Sym
|
sym *types.Sym
|
||||||
Func *Func
|
Func *Func // TODO(austin): nil for I.M, eqFor, hashfor, and hashmem
|
||||||
Offset_ int64
|
Offset_ int64
|
||||||
val constant.Value
|
val constant.Value
|
||||||
Opt interface{} // for use by escape analysis
|
Opt interface{} // for use by escape analysis
|
||||||
|
@ -287,6 +287,7 @@ func hashfor(t *types.Type) ir.Node {
|
|||||||
sym = TypeSymPrefix(".hash", t)
|
sym = TypeSymPrefix(".hash", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(austin): This creates an ir.Name with a nil Func.
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
||||||
@ -775,6 +776,7 @@ func memrun(t *types.Type, start int) (size int64, next int) {
|
|||||||
func hashmem(t *types.Type) ir.Node {
|
func hashmem(t *types.Type) ir.Node {
|
||||||
sym := ir.Pkgs.Runtime.Lookup("memhash")
|
sym := ir.Pkgs.Runtime.Lookup("memhash")
|
||||||
|
|
||||||
|
// TODO(austin): This creates an ir.Name with a nil Func.
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
||||||
|
@ -1741,6 +1741,9 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym {
|
|||||||
typecheck.NewFuncParams(method.Type.Params(), true),
|
typecheck.NewFuncParams(method.Type.Params(), true),
|
||||||
typecheck.NewFuncParams(method.Type.Results(), false))
|
typecheck.NewFuncParams(method.Type.Results(), false))
|
||||||
|
|
||||||
|
// TODO(austin): SelectorExpr may have created one or more
|
||||||
|
// ir.Names for these already with a nil Func field. We should
|
||||||
|
// consolidate these and always attach a Func to the Name.
|
||||||
fn := typecheck.DeclFunc(newnam, tfn)
|
fn := typecheck.DeclFunc(newnam, tfn)
|
||||||
fn.SetDupok(true)
|
fn.SetDupok(true)
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
|
|||||||
n := ir.NewNameAt(old.Pos(), old.Sym())
|
n := ir.NewNameAt(old.Pos(), old.Sym())
|
||||||
n.Class = old.Class
|
n.Class = old.Class
|
||||||
n.SetType(types.SubstAny(old.Type(), &types_))
|
n.SetType(types.SubstAny(old.Type(), &types_))
|
||||||
|
n.Func = old.Func
|
||||||
if len(types_) > 0 {
|
if len(types_) > 0 {
|
||||||
base.Fatalf("SubstArgTypes: too many argument types")
|
base.Fatalf("SubstArgTypes: too many argument types")
|
||||||
}
|
}
|
||||||
|
@ -426,6 +426,7 @@ func eqFor(t *types.Type) (n ir.Node, needsize bool) {
|
|||||||
return n, true
|
return n, true
|
||||||
case types.ASPECIAL:
|
case types.ASPECIAL:
|
||||||
sym := reflectdata.TypeSymPrefix(".eq", t)
|
sym := reflectdata.TypeSymPrefix(".eq", t)
|
||||||
|
// TODO(austin): This creates an ir.Name with a nil Func.
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
|
||||||
|
Loading…
Reference in New Issue
Block a user