diff --git a/go/types/selection.go b/go/types/selection.go index 8d4f1582..d8faf694 100644 --- a/go/types/selection.go +++ b/go/types/selection.go @@ -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 } diff --git a/ssa/builder.go b/ssa/builder.go index 3bc8203f..3ee47d63 100644 --- a/ssa/builder.go +++ b/ssa/builder.go @@ -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. diff --git a/ssa/builder_test.go b/ssa/builder_test.go index 61d225e6..e40bb100 100644 --- a/ssa/builder_test.go +++ b/ssa/builder_test.go @@ -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) { diff --git a/ssa/interp/interp.go b/ssa/interp/interp.go index 96831913..c318ec78 100644 --- a/ssa/interp/interp.go +++ b/ssa/interp/interp.go @@ -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 diff --git a/ssa/promote.go b/ssa/promote.go index 310384c0..1d26b8b9 100644 --- a/ssa/promote.go +++ b/ssa/promote.go @@ -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() diff --git a/ssa/source.go b/ssa/source.go index 46e0396b..714c9e1d 100644 --- a/ssa/source.go +++ b/ssa/source.go @@ -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 diff --git a/ssa/ssa.go b/ssa/ssa.go index 453b5a01..c08b3e63 100644 --- a/ssa/ssa.go +++ b/ssa/ssa.go @@ -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) diff --git a/ssa/visit.go b/ssa/visit.go index 11dd603d..3679ac70 100644 --- a/ssa/visit.go +++ b/ssa/visit.go @@ -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))) } }