1
0
mirror of https://github.com/golang/go synced 2024-11-26 06:27:58 -07:00

[dev.typeparams] cmd/compile: don't export blank functions in unified IR

After the previous two CLs, there's no need for unified IR to
write/read blank functions anymore: types2 has already checked that
they're valid, and the compiler backend is going to ignore them.

Allows dropping code for worrying about blank methods and will
probably simplify some of the object handling code eventually too.

Fixes #47446.

Change-Id: I03cb722793d676a246b1ab768b5cf0d3d2578b12
Reviewed-on: https://go-review.googlesource.com/c/go/+/338096
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2021-07-28 13:17:56 -07:00
parent 506fd520d5
commit 4a47e40a14

View File

@ -550,25 +550,6 @@ func (w *writer) doObj(obj types2.Object) codeObj {
assert(ok) assert(ok)
sig := obj.Type().(*types2.Signature) sig := obj.Type().(*types2.Signature)
// Rewrite blank methods into blank functions.
// They aren't included in the receiver type's method set,
// and we still want to write them out to be compiled
// for regression tests.
// TODO(mdempsky): Change regress tests to avoid relying
// on blank functions/methods, so we can just ignore them
// altogether.
if recv := sig.Recv(); recv != nil {
assert(obj.Name() == "_")
assert(sig.TParams() == nil)
params := make([]*types2.Var, 1+sig.Params().Len())
params[0] = recv
for i := 0; i < sig.Params().Len(); i++ {
params[1+i] = sig.Params().At(i)
}
sig = types2.NewSignature(nil, types2.NewTuple(params...), sig.Results(), sig.Variadic())
}
w.pos(obj) w.pos(obj)
w.typeParamNames(sig.TParams()) w.typeParamNames(sig.TParams())
w.signature(sig) w.signature(sig)
@ -1683,6 +1664,10 @@ func (w *writer) pkgDecl(decl syntax.Decl) {
w.pkgObjs(decl.NameList...) w.pkgObjs(decl.NameList...)
case *syntax.FuncDecl: case *syntax.FuncDecl:
if decl.Name.Value == "_" {
break // skip blank functions
}
obj := w.p.info.Defs[decl.Name].(*types2.Func) obj := w.p.info.Defs[decl.Name].(*types2.Func)
sig := obj.Type().(*types2.Signature) sig := obj.Type().(*types2.Signature)
@ -1690,7 +1675,7 @@ func (w *writer) pkgDecl(decl syntax.Decl) {
break // skip generic functions break // skip generic functions
} }
if recv := sig.Recv(); recv != nil && obj.Name() != "_" { if recv := sig.Recv(); recv != nil {
w.code(declMethod) w.code(declMethod)
w.typ(recvBase(recv)) w.typ(recvBase(recv))
w.selector(obj) w.selector(obj)