1
0
mirror of https://github.com/golang/go synced 2024-11-05 12:06:15 -07:00

cmd/compile: stop changing Field.Sym for parameters

Field.Sym now always contains the original symbol as it appeared in Go
source, so we don't need OrigSym anymore.

Instead, when the mangled name is desired, Field.Nname.Sym() can be
used instead, which is always non-nil if Nname is non-nil.

Change-Id: I96cd61db6458d4a2e07ec5810239236e3dfba747
Reviewed-on: https://go-review.googlesource.com/c/go/+/527516
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Matthew Dempsky 2023-09-11 17:45:37 -07:00 committed by Gopher Robot
parent e924ea03cc
commit d9aca84da0
6 changed files with 7 additions and 39 deletions

View File

@ -423,7 +423,7 @@ func (config *ABIConfig) ABIAnalyze(t *types.Type, setNname bool) *ABIParamResul
func (config *ABIConfig) updateOffset(result *ABIParamResultInfo, f *types.Field, a ABIParamAssignment, isResult, setNname bool) {
if f.Offset != types.BADWIDTH {
base.Fatalf("field offset for %s at %s has been set to %d", f.Sym.Name, base.FmtPos(f.Pos), f.Offset)
base.Fatalf("field offset for %s at %s has been set to %d", f.Sym, base.FmtPos(f.Pos), f.Offset)
}
// Everything except return values in registers has either a frame home (if not in a register) or a frame spill location.

View File

@ -379,8 +379,8 @@ const (
func (b *batch) paramTag(fn *ir.Func, narg int, f *types.Field) string {
name := func() string {
if f.Sym != nil {
return f.Sym.Name
if f.Nname != nil {
return f.Nname.Sym().Name
}
return fmt.Sprintf("arg#%d", narg)
}
@ -481,7 +481,7 @@ func (b *batch) reportLeaks(pos src.XPos, name string, esc leaks, sig *types.Typ
}
for i := 0; i < numEscResults; i++ {
if x := esc.Result(i); x >= 0 {
res := sig.Result(i).Sym
res := sig.Result(i).Nname.Sym().Name
base.WarnfAt(pos, "leaking param: %v to result %v level=%d", name, res, x)
warned = true
}

View File

@ -471,7 +471,7 @@ func canDelayResults(fn *ir.Func) bool {
// temporaries for return values.
for _, param := range fn.Type().Results() {
if sym := types.OrigSym(param.Sym); sym != nil && !sym.IsBlank() {
if sym := param.Sym; sym != nil && !sym.IsBlank() {
return false // found a named result parameter (case 3)
}
}

View File

@ -1507,7 +1507,7 @@ func (r *reader) funcargs(fn *ir.Func) {
}
for i, param := range sig.Results() {
sym := types.OrigSym(param.Sym)
sym := param.Sym
if sym == nil || sym.IsBlank() {
prefix := "~r"
@ -1536,7 +1536,6 @@ func (r *reader) funcarg(param *types.Field, sym *types.Sym, ctxt ir.Class) {
if r.inlCall == nil {
if !r.funarghack {
param.Sym = sym
param.Nname = name
}
} else {

View File

@ -9,7 +9,6 @@ import (
"encoding/binary"
"fmt"
"strconv"
"strings"
"sync"
"cmd/compile/internal/base"
@ -28,31 +27,6 @@ var UnsafePkg *Pkg
// BlankSym is the blank (_) symbol.
var BlankSym *Sym
// OrigSym returns the original symbol written by the user.
func OrigSym(s *Sym) *Sym {
if s == nil {
return nil
}
if len(s.Name) > 1 && s.Name[0] == '~' {
switch s.Name[1] {
case 'r': // originally an unnamed result
return nil
case 'b': // originally the blank identifier _
// TODO(mdempsky): Does s.Pkg matter here?
return BlankSym
}
return s
}
if strings.HasPrefix(s.Name, ".anon") {
// originally an unnamed or _ name (see subr.go: NewFuncParams)
return nil
}
return s
}
// numImport tracks how often a package with a given name is imported.
// It is used to provide a better error message (by using the package
// path to disambiguate) if a package that appears multiple times with
@ -583,11 +557,6 @@ func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Ty
if verb != 'S' {
s := f.Sym
// Take the name from the original.
if mode == fmtGo {
s = OrigSym(s)
}
// Using type aliases and embedded fields, it's possible to
// construct types that can't be directly represented as a
// type literal. For example, given "type Int = int" (#50190),

View File

@ -392,7 +392,7 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
continue
}
if sym := types.OrigSym(name.Sym()); sym == nil || sym.IsBlank() {
if ir.IsBlank(name) {
// We can ignore assignments to blank or anonymous result parameters.
// These can't appear in expressions anyway.
continue