mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile: simplify ~r/~b naming
The compiler renames anonymous and blank result parameters to ~rN or ~bN, but the current semantics for computing N are rather annoying and difficult to reproduce cleanly. They also lead to difficult to read escape analysis results in tests. This CL changes N to always be calculated as the parameter's index within the function's result parameter tuple. E.g., if a function has a single result, it will now always be named "~r0". The normative change to this CL is fairly simple, but it requires updating a lot of test expectations. Change-Id: I58a3c94de00cb822cb94efe52d115531193c993c Reviewed-on: https://go-review.googlesource.com/c/go/+/323010 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>
This commit is contained in:
parent
4c68edd1fe
commit
e99e9a6e01
17 changed files with 101 additions and 102 deletions
|
|
@ -113,19 +113,21 @@ func (g *irgen) obj(obj types2.Object) *ir.Name {
|
|||
}
|
||||
|
||||
case *types2.Var:
|
||||
var sym *types.Sym
|
||||
if class == ir.PPARAMOUT {
|
||||
sym := g.sym(obj)
|
||||
if class == ir.PPARAMOUT && (sym == nil || sym.IsBlank()) {
|
||||
// Backend needs names for result parameters,
|
||||
// even if they're anonymous or blank.
|
||||
switch obj.Name() {
|
||||
case "":
|
||||
sym = typecheck.LookupNum("~r", len(ir.CurFunc.Dcl)) // 'r' for "result"
|
||||
case "_":
|
||||
sym = typecheck.LookupNum("~b", len(ir.CurFunc.Dcl)) // 'b' for "blank"
|
||||
nresults := 0
|
||||
for _, n := range ir.CurFunc.Dcl {
|
||||
if n.Class == ir.PPARAMOUT {
|
||||
nresults++
|
||||
}
|
||||
}
|
||||
if sym == nil {
|
||||
sym = typecheck.LookupNum("~r", nresults) // 'r' for "result"
|
||||
} else {
|
||||
sym = typecheck.LookupNum("~b", nresults) // 'b' for "blank"
|
||||
}
|
||||
}
|
||||
if sym == nil {
|
||||
sym = g.sym(obj)
|
||||
}
|
||||
name = g.objCommon(pos, ir.ONAME, sym, class, g.typ(obj.Type()))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue