aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-28 16:14:11 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-12-29 02:35:04 +0000
commit4629f6a51da5afabbebe9616f65fbfe0675d6039 (patch)
tree8e81fbaa7ef4a2efc7cbc750df95c0eb817a4bee /src/cmd/compile/internal/typecheck
parente563715b3085f44a76564485214e33e3c3b2b7b0 (diff)
downloadgo-4629f6a51da5afabbebe9616f65fbfe0675d6039.tar.gz
go-4629f6a51da5afabbebe9616f65fbfe0675d6039.zip
[dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr
These three expression nodes all represent the same syntax, and so they're represented the same within types2. And also they're not handled that meaningfully differently throughout the rest of the compiler to merit unique representations. Method expressions are somewhat unique today that they're very frequently turned into plain function names. But eventually that can be handled by a post-typecheck desugaring phase that reduces the number of redundant AST forms. Passes toolstash -cmp. Change-Id: I20df91bbd0d885c1f18ec67feb61ae1558670719 Reviewed-on: https://go-review.googlesource.com/c/go/+/280636 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck')
-rw-r--r--src/cmd/compile/internal/typecheck/expr.go6
-rw-r--r--src/cmd/compile/internal/typecheck/func.go16
-rw-r--r--src/cmd/compile/internal/typecheck/iexport.go21
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go15
4 files changed, 21 insertions, 37 deletions
diff --git a/src/cmd/compile/internal/typecheck/expr.go b/src/cmd/compile/internal/typecheck/expr.go
index 3e7a880c2a..0682548c27 100644
--- a/src/cmd/compile/internal/typecheck/expr.go
+++ b/src/cmd/compile/internal/typecheck/expr.go
@@ -626,10 +626,8 @@ func tcDot(n *ir.SelectorExpr, top int) ir.Node {
}
if (n.Op() == ir.ODOTINTER || n.Op() == ir.ODOTMETH) && top&ctxCallee == 0 {
- // Create top-level function.
- fn := makepartialcall(n)
-
- return ir.NewCallPartExpr(n.Pos(), n.X, n.Selection, fn)
+ n.SetOp(ir.OCALLPART)
+ n.SetType(MethodValueWrapper(n).Type())
}
return n
}
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go
index ed4f3ad4fe..c58fef10ec 100644
--- a/src/cmd/compile/internal/typecheck/func.go
+++ b/src/cmd/compile/internal/typecheck/func.go
@@ -91,7 +91,7 @@ func ClosureType(clo *ir.ClosureExpr) *types.Type {
// PartialCallType returns the struct type used to hold all the information
// needed in the closure for n (n must be a OCALLPART node).
// The address of a variable of the returned type can be cast to a func.
-func PartialCallType(n *ir.CallPartExpr) *types.Type {
+func PartialCallType(n *ir.SelectorExpr) *types.Type {
t := types.NewStruct(types.NoPkg, []*types.Field{
types.NewField(base.Pos, Lookup("F"), types.Types[types.TUINTPTR]),
types.NewField(base.Pos, Lookup("R"), n.X.Type()),
@@ -247,9 +247,17 @@ func closurename(outerfunc *ir.Func) *types.Sym {
// globClosgen is like Func.Closgen, but for the global scope.
var globClosgen int32
-// makepartialcall returns a DCLFUNC node representing the wrapper function (*-fm) needed
-// for partial calls.
-func makepartialcall(dot *ir.SelectorExpr) *ir.Func {
+// MethodValueWrapper returns the DCLFUNC node representing the
+// wrapper function (*-fm) needed for the given method value. If the
+// wrapper function hasn't already been created yet, it's created and
+// added to Target.Decls.
+//
+// TODO(mdempsky): Move into walk. This isn't part of type checking.
+func MethodValueWrapper(dot *ir.SelectorExpr) *ir.Func {
+ if dot.Op() != ir.OCALLPART {
+ base.Fatalf("MethodValueWrapper: unexpected %v (%v)", dot, dot.Op())
+ }
+
t0 := dot.Type()
meth := dot.Sel
rcvrtype := dot.X.Type()
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go
index 3b071a61ab..e35cbcafa2 100644
--- a/src/cmd/compile/internal/typecheck/iexport.go
+++ b/src/cmd/compile/internal/typecheck/iexport.go
@@ -1252,17 +1252,6 @@ func (w *exportWriter) expr(n ir.Node) {
w.pos(n.Pos())
w.value(n.Type(), n.Val())
- case ir.OMETHEXPR:
- // Special case: explicit name of func (*T) method(...) is turned into pkg.(*T).method,
- // but for export, this should be rendered as (*pkg.T).meth.
- // These nodes have the special property that they are names with a left OTYPE and a right ONAME.
- n := n.(*ir.MethodExpr)
- w.op(ir.OXDOT)
- w.pos(n.Pos())
- w.op(ir.OTYPE)
- w.typ(n.T) // n.Left.Op == OTYPE
- w.selector(n.Method.Sym)
-
case ir.ONAME:
// Package scope name.
n := n.(*ir.Name)
@@ -1336,15 +1325,7 @@ func (w *exportWriter) expr(n ir.Node) {
// case OSTRUCTKEY:
// unreachable - handled in case OSTRUCTLIT by elemList
- case ir.OCALLPART:
- // An OCALLPART is an OXDOT before type checking.
- n := n.(*ir.CallPartExpr)
- w.op(ir.OXDOT)
- w.pos(n.Pos())
- w.expr(n.X)
- w.selector(n.Method.Sym)
-
- case ir.OXDOT, ir.ODOT, ir.ODOTPTR, ir.ODOTINTER, ir.ODOTMETH:
+ case ir.OXDOT, ir.ODOT, ir.ODOTPTR, ir.ODOTINTER, ir.ODOTMETH, ir.OCALLPART, ir.OMETHEXPR:
n := n.(*ir.SelectorExpr)
w.op(ir.OXDOT)
w.pos(n.Pos())
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index e23c249ff2..ff9178b597 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -1176,19 +1176,16 @@ func typecheckMethodExpr(n *ir.SelectorExpr) (res ir.Node) {
return n
}
- me := ir.NewMethodExpr(n.Pos(), n.X.Type(), m)
- me.SetType(NewMethodType(m.Type, n.X.Type()))
- f := NewName(ir.MethodSym(t, m.Sym))
- f.Class_ = ir.PFUNC
- f.SetType(me.Type())
- me.FuncName_ = f
+ n.SetOp(ir.OMETHEXPR)
+ n.Selection = m
+ n.SetType(NewMethodType(m.Type, n.X.Type()))
// Issue 25065. Make sure that we emit the symbol for a local method.
if base.Ctxt.Flag_dynlink && !inimport && (t.Sym() == nil || t.Sym().Pkg == types.LocalPkg) {
- NeedFuncSym(me.FuncName_.Sym())
+ NeedFuncSym(n.FuncName().Sym())
}
- return me
+ return n
}
func derefall(t *types.Type) *types.Type {
@@ -1422,7 +1419,7 @@ notenough:
// Method expressions have the form T.M, and the compiler has
// rewritten those to ONAME nodes but left T in Left.
if call.Op() == ir.OMETHEXPR {
- call := call.(*ir.MethodExpr)
+ call := call.(*ir.SelectorExpr)
base.Errorf("not enough arguments in call to method expression %v%s", call, details)
} else {
base.Errorf("not enough arguments in call to %v%s", call, details)