mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
go.tools/ssa: avoid calling go/types.NewSelection, and eliminate it.
Also: s/LookupMethod/Method/ R=gri CC=golang-dev https://golang.org/cl/12058052
This commit is contained in:
parent
4ae33302a4
commit
2f6855ad75
@ -46,12 +46,6 @@ type Selection struct {
|
||||
indirect bool // set if there was any pointer indirection on the path, false if kind == PackageObj
|
||||
}
|
||||
|
||||
// NewSelection returns a new Selection.
|
||||
// TODO(gri) At the moment this is only used by package ssa.
|
||||
func NewSelection(kind SelectionKind, recv Type, obj Object, index []int, indirect bool) *Selection {
|
||||
return &Selection{kind, recv, obj, index, indirect}
|
||||
}
|
||||
|
||||
// Kind returns the selection kind.
|
||||
func (s *Selection) Kind() SelectionKind { return s.kind }
|
||||
|
||||
|
@ -633,7 +633,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
|
||||
case types.MethodExpr:
|
||||
// (*T).f or T.f, the method f from the method-set of type T.
|
||||
// For declared methods, a simple conversion will suffice.
|
||||
return emitConv(fn, fn.Prog.LookupMethod(sel), fn.Pkg.typeOf(e))
|
||||
return emitConv(fn, fn.Prog.Method(sel), fn.Pkg.typeOf(e))
|
||||
|
||||
case types.MethodVal:
|
||||
// e.f where e is an expression and f is a method.
|
||||
|
@ -100,7 +100,7 @@ func main() {
|
||||
}
|
||||
mset := types.NewPointer(mem.Type()).MethodSet()
|
||||
for i, n := 0, mset.Len(); i < n; i++ {
|
||||
m := prog.LookupMethod(mset.At(i))
|
||||
m := prog.Method(mset.At(i))
|
||||
// For external types, only synthetic wrappers have code.
|
||||
expExt := !strings.Contains(m.Synthetic, "wrapper")
|
||||
if expExt && !isEmpty(m) {
|
||||
|
@ -144,7 +144,7 @@ func lookupMethod(i *interpreter, typ types.Type, meth *types.Func) *ssa.Functio
|
||||
case errorType:
|
||||
return i.errorMethods[meth.Id()]
|
||||
}
|
||||
return i.prog.LookupMethod(typ.MethodSet().Lookup(meth.Pkg(), meth.Name()))
|
||||
return i.prog.Method(typ.MethodSet().Lookup(meth.Pkg(), meth.Name()))
|
||||
}
|
||||
|
||||
// visitInstr interprets a single ssa.Instruction within the activation
|
||||
|
@ -32,21 +32,20 @@ func methodSetOf(typ types.Type) *types.MethodSet {
|
||||
return typ.MethodSet()
|
||||
}
|
||||
|
||||
// LookupMethod returns the Function for the specified method object,
|
||||
// building wrapper methods on demand. It returns nil if the typ has
|
||||
// no such method.
|
||||
// Method returns the Function implementing method meth, building
|
||||
// wrapper methods on demand.
|
||||
//
|
||||
// Thread-safe.
|
||||
//
|
||||
// EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
|
||||
//
|
||||
func (prog *Program) LookupMethod(meth *types.Selection) *Function {
|
||||
func (prog *Program) Method(meth *types.Selection) *Function {
|
||||
if meth == nil {
|
||||
panic("LookupMethod(nil)")
|
||||
panic("Method(nil)")
|
||||
}
|
||||
typ := meth.Recv()
|
||||
if prog.mode&LogSource != 0 {
|
||||
defer logStack("LookupMethod %s %v", typ, meth)()
|
||||
defer logStack("Method %s %v", typ, meth)()
|
||||
}
|
||||
|
||||
prog.methodsMu.Lock()
|
||||
|
@ -103,7 +103,7 @@ func findNamedFunc(pkg *Package, pos token.Pos) *Function {
|
||||
case *Type:
|
||||
mset := methodSetOf(types.NewPointer(mem.Type()))
|
||||
for i, n := 0, mset.Len(); i < n; i++ {
|
||||
// Don't call LookupMethod: avoid creating wrappers.
|
||||
// Don't call Program.Method: avoid creating wrappers.
|
||||
obj := mset.At(i).Obj().(*types.Func)
|
||||
if obj.Pos() == pos {
|
||||
return pkg.values[obj].(*Function)
|
||||
@ -224,8 +224,8 @@ func (prog *Program) FuncValue(obj *types.Func) Value {
|
||||
return v
|
||||
}
|
||||
// Interface method wrapper?
|
||||
sel := types.NewSelection(types.MethodExpr, recvType(obj), obj, nil, false)
|
||||
return prog.LookupMethod(sel)
|
||||
meth := methodSetOf(recvType(obj)).Lookup(obj.Pkg(), obj.Name())
|
||||
return prog.Method(meth)
|
||||
}
|
||||
|
||||
// ConstValue returns the SSA Value denoted by the source-level named
|
||||
|
@ -584,7 +584,7 @@ type ChangeInterface struct {
|
||||
// value of a concrete type.
|
||||
//
|
||||
// Use X.Type().MethodSet() to find the method-set of X, and
|
||||
// Program.LookupMethod(m) to find the implementation of a method.
|
||||
// Program.Method(m) to find the implementation of a method.
|
||||
//
|
||||
// To construct the zero value of an interface type T, use:
|
||||
// NewConst(exact.MakeNil(), T, pos)
|
||||
|
@ -48,7 +48,7 @@ func (visit *visitor) methodSet(typ types.Type) {
|
||||
mset := methodSetOf(typ)
|
||||
for i, n := 0, mset.Len(); i < n; i++ {
|
||||
// Side-effect: creates all wrapper methods.
|
||||
visit.function(visit.prog.LookupMethod(mset.At(i)))
|
||||
visit.function(visit.prog.Method(mset.At(i)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user