diff options
| author | Alan Donovan <adonovan@google.com> | 2025-11-11 14:48:22 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-11-11 19:59:40 -0800 |
| commit | 4bfc3a9d14c0b3bfcfe4ce987e47cda6720785a2 (patch) | |
| tree | 0cbf1ec55d3a61af8bf45ac4a00af7e7bcc426db /src/cmd/internal | |
| parent | 2263d4aabdde8a4a466009ecc356501f87c7efb7 (diff) | |
| download | go-4bfc3a9d14c0b3bfcfe4ce987e47cda6720785a2.tar.xz | |
std,cmd: go fix -any std cmd
This change mechanically replaces all occurrences of interface{}
by 'any' (where deemed safe by the 'any' modernizer) throughout
std and cmd, minus their vendor trees.
Since this fix is relatively numerous, it gets its own CL.
Also, 'go generate go/types'.
Change-Id: I14a6b52856c3291c1d27935409bca8d5fd4242a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/719702
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/internal')
| -rw-r--r-- | src/cmd/internal/cov/readcovdata.go | 6 | ||||
| -rw-r--r-- | src/cmd/internal/dwarf/dwarf.go | 19 | ||||
| -rw-r--r-- | src/cmd/internal/macho/macho.go | 4 | ||||
| -rw-r--r-- | src/cmd/internal/obj/dwarf.go | 12 | ||||
| -rw-r--r-- | src/cmd/internal/obj/link.go | 24 | ||||
| -rw-r--r-- | src/cmd/internal/obj/loong64/asm.go | 2 | ||||
| -rw-r--r-- | src/cmd/internal/obj/pcln.go | 12 | ||||
| -rw-r--r-- | src/cmd/internal/obj/ppc64/asm_test.go | 2 | ||||
| -rw-r--r-- | src/cmd/internal/obj/sizeof_test.go | 6 | ||||
| -rw-r--r-- | src/cmd/internal/objabi/flag.go | 10 |
10 files changed, 48 insertions, 49 deletions
diff --git a/src/cmd/internal/cov/readcovdata.go b/src/cmd/internal/cov/readcovdata.go index e0e0634459..f9fd522930 100644 --- a/src/cmd/internal/cov/readcovdata.go +++ b/src/cmd/internal/cov/readcovdata.go @@ -145,14 +145,14 @@ func (r *CovDataReader) Visit() error { return nil } -func (r *CovDataReader) verb(vlevel int, s string, a ...interface{}) { +func (r *CovDataReader) verb(vlevel int, s string, a ...any) { if r.verbosityLevel >= vlevel { fmt.Fprintf(os.Stderr, s, a...) fmt.Fprintf(os.Stderr, "\n") } } -func (r *CovDataReader) warn(s string, a ...interface{}) { +func (r *CovDataReader) warn(s string, a ...any) { fmt.Fprintf(os.Stderr, "warning: ") fmt.Fprintf(os.Stderr, s, a...) fmt.Fprintf(os.Stderr, "\n") @@ -161,7 +161,7 @@ func (r *CovDataReader) warn(s string, a ...interface{}) { } } -func (r *CovDataReader) fatal(s string, a ...interface{}) error { +func (r *CovDataReader) fatal(s string, a ...any) error { if r.err != nil { return nil } diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go index 6e06f139b0..b8956b4cff 100644 --- a/src/cmd/internal/dwarf/dwarf.go +++ b/src/cmd/internal/dwarf/dwarf.go @@ -40,8 +40,7 @@ const AbstractFuncSuffix = "$abstract" var logDwarf bool // Sym represents a symbol. -type Sym interface { -} +type Sym any // A Var represents a local variable or a function parameter. type Var struct { @@ -194,16 +193,16 @@ type Context interface { Size(s Sym) int64 AddInt(s Sym, size int, i int64) AddBytes(s Sym, b []byte) - AddAddress(s Sym, t interface{}, ofs int64) - AddCURelativeAddress(s Sym, t interface{}, ofs int64) - AddSectionOffset(s Sym, size int, t interface{}, ofs int64) - AddDWARFAddrSectionOffset(s Sym, t interface{}, ofs int64) - AddIndirectTextRef(s Sym, t interface{}) + AddAddress(s Sym, t any, ofs int64) + AddCURelativeAddress(s Sym, t any, ofs int64) + AddSectionOffset(s Sym, size int, t any, ofs int64) + AddDWARFAddrSectionOffset(s Sym, t any, ofs int64) + AddIndirectTextRef(s Sym, t any) CurrentOffset(s Sym) int64 RecordDclReference(from Sym, to Sym, dclIdx int, inlIndex int) RecordChildDieOffsets(s Sym, vars []*Var, offsets []int32) AddString(s Sym, v string) - Logf(format string, args ...interface{}) + Logf(format string, args ...any) } // AppendUleb128 appends v to b using DWARF's unsigned LEB128 encoding. @@ -874,7 +873,7 @@ type DWAttr struct { Atr uint16 // DW_AT_ Cls uint8 // DW_CLS_ Value int64 - Data interface{} + Data any } // DWDie represents a DWARF debug info entry. @@ -886,7 +885,7 @@ type DWDie struct { Sym Sym } -func putattr(ctxt Context, s Sym, abbrev int, form int, cls int, value int64, data interface{}) error { +func putattr(ctxt Context, s Sym, abbrev int, form int, cls int, value int64, data any) error { switch form { case DW_FORM_addr: // address // Allow nil addresses for DW_AT_go_runtime_type. diff --git a/src/cmd/internal/macho/macho.go b/src/cmd/internal/macho/macho.go index ad29c32c50..6c9907dbb4 100644 --- a/src/cmd/internal/macho/macho.go +++ b/src/cmd/internal/macho/macho.go @@ -100,7 +100,7 @@ func (r *LoadCmdReader) Next() (LoadCmd, error) { return cmd, nil } -func (r LoadCmdReader) ReadAt(offset int64, data interface{}) error { +func (r LoadCmdReader) ReadAt(offset int64, data any) error { if _, err := r.f.Seek(r.offset+offset, 0); err != nil { return err } @@ -117,7 +117,7 @@ func NewLoadCmdUpdater(f io.ReadWriteSeeker, order binary.ByteOrder, nextOffset return LoadCmdUpdater{NewLoadCmdReader(f, order, nextOffset)} } -func (u LoadCmdUpdater) WriteAt(offset int64, data interface{}) error { +func (u LoadCmdUpdater) WriteAt(offset int64, data any) error { if _, err := u.f.Seek(u.offset+offset, 0); err != nil { return err } diff --git a/src/cmd/internal/obj/dwarf.go b/src/cmd/internal/obj/dwarf.go index 670b0f3510..d09aa985f0 100644 --- a/src/cmd/internal/obj/dwarf.go +++ b/src/cmd/internal/obj/dwarf.go @@ -231,7 +231,7 @@ func (c dwCtxt) AddString(s dwarf.Sym, v string) { ls.WriteString(c.Link, ls.Size, len(v), v) ls.WriteInt(c.Link, ls.Size, 1, 0) } -func (c dwCtxt) AddAddress(s dwarf.Sym, data interface{}, value int64) { +func (c dwCtxt) AddAddress(s dwarf.Sym, data any, value int64) { ls := s.(*LSym) size := c.PtrSize() if data != nil { @@ -241,15 +241,15 @@ func (c dwCtxt) AddAddress(s dwarf.Sym, data interface{}, value int64) { ls.WriteInt(c.Link, ls.Size, size, value) } } -func (c dwCtxt) AddCURelativeAddress(s dwarf.Sym, data interface{}, value int64) { +func (c dwCtxt) AddCURelativeAddress(s dwarf.Sym, data any, value int64) { ls := s.(*LSym) rsym := data.(*LSym) ls.WriteCURelativeAddr(c.Link, ls.Size, rsym, value) } -func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64) { +func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t any, ofs int64) { panic("should be used only in the linker") } -func (c dwCtxt) AddDWARFAddrSectionOffset(s dwarf.Sym, t interface{}, ofs int64) { +func (c dwCtxt) AddDWARFAddrSectionOffset(s dwarf.Sym, t any, ofs int64) { size := 4 if isDwarf64(c.Link) { size = 8 @@ -284,11 +284,11 @@ func (c dwCtxt) RecordChildDieOffsets(s dwarf.Sym, vars []*dwarf.Var, offsets [] c.Link.DwFixups.RegisterChildDIEOffsets(ls, vars, offsets) } -func (c dwCtxt) Logf(format string, args ...interface{}) { +func (c dwCtxt) Logf(format string, args ...any) { c.Link.Logf(format, args...) } -func (c dwCtxt) AddIndirectTextRef(s dwarf.Sym, t interface{}) { +func (c dwCtxt) AddIndirectTextRef(s dwarf.Sym, t any) { ls := s.(*LSym) tsym := t.(*LSym) // Note the doubling below -- DwTextCount is an estimate and diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index 9f3814e748..85dca33d27 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -211,7 +211,7 @@ type Addr struct { // for TYPE_FCONST, a float64 // for TYPE_BRANCH, a *Prog (optional) // for TYPE_TEXTSIZE, an int32 (optional) - Val interface{} + Val any } type AddrName int8 @@ -464,7 +464,7 @@ type LSym struct { P []byte R []Reloc - Extra *interface{} // *FuncInfo, *VarInfo, *FileInfo, *TypeInfo, or *ItabInfo, if present + Extra *any // *FuncInfo, *VarInfo, *FileInfo, *TypeInfo, or *ItabInfo, if present Pkg string PkgIdx int32 @@ -523,7 +523,7 @@ func (s *LSym) NewFuncInfo() *FuncInfo { panic(fmt.Sprintf("invalid use of LSym - NewFuncInfo with Extra of type %T", *s.Extra)) } f := new(FuncInfo) - s.Extra = new(interface{}) + s.Extra = new(any) *s.Extra = f return f } @@ -547,7 +547,7 @@ func (s *LSym) NewVarInfo() *VarInfo { panic(fmt.Sprintf("invalid use of LSym - NewVarInfo with Extra of type %T", *s.Extra)) } f := new(VarInfo) - s.Extra = new(interface{}) + s.Extra = new(any) *s.Extra = f return f } @@ -574,7 +574,7 @@ func (s *LSym) NewFileInfo() *FileInfo { panic(fmt.Sprintf("invalid use of LSym - NewFileInfo with Extra of type %T", *s.Extra)) } f := new(FileInfo) - s.Extra = new(interface{}) + s.Extra = new(any) *s.Extra = f return f } @@ -591,7 +591,7 @@ func (s *LSym) File() *FileInfo { // A TypeInfo contains information for a symbol // that contains a runtime._type. type TypeInfo struct { - Type interface{} // a *cmd/compile/internal/types.Type + Type any // a *cmd/compile/internal/types.Type } func (s *LSym) NewTypeInfo() *TypeInfo { @@ -599,7 +599,7 @@ func (s *LSym) NewTypeInfo() *TypeInfo { panic(fmt.Sprintf("invalid use of LSym - NewTypeInfo with Extra of type %T", *s.Extra)) } t := new(TypeInfo) - s.Extra = new(interface{}) + s.Extra = new(any) *s.Extra = t return t } @@ -616,7 +616,7 @@ func (s *LSym) TypeInfo() *TypeInfo { // An ItabInfo contains information for a symbol // that contains a runtime.itab. type ItabInfo struct { - Type interface{} // a *cmd/compile/internal/types.Type + Type any // a *cmd/compile/internal/types.Type } func (s *LSym) NewItabInfo() *ItabInfo { @@ -624,7 +624,7 @@ func (s *LSym) NewItabInfo() *ItabInfo { panic(fmt.Sprintf("invalid use of LSym - NewItabInfo with Extra of type %T", *s.Extra)) } t := new(ItabInfo) - s.Extra = new(interface{}) + s.Extra = new(any) *s.Extra = t return t } @@ -1178,7 +1178,7 @@ type Link struct { DwFixups *DwarfFixupTable DwTextCount int Imports []goobj.ImportedPkg - DiagFunc func(string, ...interface{}) + DiagFunc func(string, ...any) DiagFlush func() DebugInfo func(ctxt *Link, fn *LSym, info *LSym, curfn Func) ([]dwarf.Scope, dwarf.InlCalls) GenAbstractFunc func(fn *LSym) @@ -1223,12 +1223,12 @@ func _(ctxt *Link) { } } -func (ctxt *Link) Diag(format string, args ...interface{}) { +func (ctxt *Link) Diag(format string, args ...any) { ctxt.Errors++ ctxt.DiagFunc(format, args...) } -func (ctxt *Link) Logf(format string, args ...interface{}) { +func (ctxt *Link) Logf(format string, args ...any) { fmt.Fprintf(ctxt.Bso, format, args...) ctxt.Bso.Flush() } diff --git a/src/cmd/internal/obj/loong64/asm.go b/src/cmd/internal/obj/loong64/asm.go index e0aca15005..53cea8d37c 100644 --- a/src/cmd/internal/obj/loong64/asm.go +++ b/src/cmd/internal/obj/loong64/asm.go @@ -1340,7 +1340,7 @@ func opset(a, b0 obj.As) { func buildop(ctxt *obj.Link) { if ctxt.DiagFunc == nil { - ctxt.DiagFunc = func(format string, args ...interface{}) { + ctxt.DiagFunc = func(format string, args ...any) { log.Printf(format, args...) } } diff --git a/src/cmd/internal/obj/pcln.go b/src/cmd/internal/obj/pcln.go index 67a078091c..1cfcde7aa5 100644 --- a/src/cmd/internal/obj/pcln.go +++ b/src/cmd/internal/obj/pcln.go @@ -22,7 +22,7 @@ import ( // // where func is the function, val is the current value, p is the instruction being // considered, and arg can be used to further parameterize valfunc. -func funcpctab(ctxt *Link, func_ *LSym, desc string, valfunc func(*Link, *LSym, int32, *Prog, int32, interface{}) int32, arg interface{}) *LSym { +func funcpctab(ctxt *Link, func_ *LSym, desc string, valfunc func(*Link, *LSym, int32, *Prog, int32, any) int32, arg any) *LSym { dbg := desc == ctxt.Debugpcln dst := []byte{} sym := &LSym{ @@ -138,7 +138,7 @@ func funcpctab(ctxt *Link, func_ *LSym, desc string, valfunc func(*Link, *LSym, // or the line number (arg == 1) to use at p. // Because p.Pos applies to p, phase == 0 (before p) // takes care of the update. -func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg interface{}) int32 { +func pctofileline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg any) int32 { if p.As == ATEXT || p.As == ANOP || p.Pos.Line() == 0 || phase == 1 { return oldval } @@ -198,7 +198,7 @@ func (s *pcinlineState) setParentPC(ctxt *Link, globalIndex int, pc int32) { // pctoinline computes the index into the local inlining tree to use at p. // If p is not the result of inlining, pctoinline returns -1. Because p.Pos // applies to p, phase == 0 (before p) takes care of the update. -func (s *pcinlineState) pctoinline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg interface{}) int32 { +func (s *pcinlineState) pctoinline(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg any) int32 { if phase == 1 { return oldval } @@ -224,7 +224,7 @@ func (s *pcinlineState) pctoinline(ctxt *Link, sym *LSym, oldval int32, p *Prog, // It is oldval plus any adjustment made by p itself. // The adjustment by p takes effect only after p, so we // apply the change during phase == 1. -func pctospadj(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg interface{}) int32 { +func pctospadj(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg any) int32 { if oldval == -1 { // starting oldval = 0 } @@ -245,7 +245,7 @@ func pctospadj(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg in // non-PCDATA instructions. // Since PCDATA instructions have no width in the final code, // it does not matter which phase we use for the update. -func pctopcdata(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg interface{}) int32 { +func pctopcdata(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg any) int32 { if phase == 0 || p.As != APCDATA || p.From.Offset != int64(arg.(uint32)) { return oldval } @@ -337,7 +337,7 @@ func linkpcln(ctxt *Link, cursym *LSym) { Attribute: AttrContentAddressable | AttrPcdata, } } else { - pcln.Pcdata[i] = funcpctab(ctxt, cursym, "pctopcdata", pctopcdata, interface{}(uint32(i))) + pcln.Pcdata[i] = funcpctab(ctxt, cursym, "pctopcdata", pctopcdata, any(uint32(i))) } } diff --git a/src/cmd/internal/obj/ppc64/asm_test.go b/src/cmd/internal/obj/ppc64/asm_test.go index ab7af2205e..9f1acf4b62 100644 --- a/src/cmd/internal/obj/ppc64/asm_test.go +++ b/src/cmd/internal/obj/ppc64/asm_test.go @@ -439,7 +439,7 @@ func TestAddrClassifier(t *testing.T) { } tsts := [...]struct { arg obj.Addr - output interface{} + output any }{ // Supported register type args {obj.Addr{Type: obj.TYPE_REG, Reg: REG_R1}, C_REG}, diff --git a/src/cmd/internal/obj/sizeof_test.go b/src/cmd/internal/obj/sizeof_test.go index 69e60473f5..fdee114f5b 100644 --- a/src/cmd/internal/obj/sizeof_test.go +++ b/src/cmd/internal/obj/sizeof_test.go @@ -16,9 +16,9 @@ func TestSizeof(t *testing.T) { const _64bit = unsafe.Sizeof(uintptr(0)) == 8 var tests = []struct { - val interface{} // type as a value - _32bit uintptr // size on 32bit platforms - _64bit uintptr // size on 64bit platforms + val any // type as a value + _32bit uintptr // size on 32bit platforms + _64bit uintptr // size on 64bit platforms }{ {Addr{}, 32, 48}, {LSym{}, 72, 120}, diff --git a/src/cmd/internal/objabi/flag.go b/src/cmd/internal/objabi/flag.go index 8709c4e5cf..32d71d0575 100644 --- a/src/cmd/internal/objabi/flag.go +++ b/src/cmd/internal/objabi/flag.go @@ -85,7 +85,7 @@ var buildID string // filled in by linker type versionFlag struct{} func (versionFlag) IsBoolFlag() bool { return true } -func (versionFlag) Get() interface{} { return nil } +func (versionFlag) Get() any { return nil } func (versionFlag) String() string { return "" } func (versionFlag) Set(s string) error { name := os.Args[0] @@ -148,7 +148,7 @@ func (c *count) Set(s string) error { return nil } -func (c *count) Get() interface{} { +func (c *count) Get() any { return int(*c) } @@ -206,8 +206,8 @@ func DecodeArg(arg string) string { type debugField struct { name string help string - concurrentOk bool // true if this field/flag is compatible with concurrent compilation - val interface{} // *int or *string + concurrentOk bool // true if this field/flag is compatible with concurrent compilation + val any // *int or *string } type DebugFlag struct { @@ -234,7 +234,7 @@ type DebugSSA func(phase, flag string, val int, valString string) string // // If debugSSA is non-nil, any debug flags of the form ssa/... will be // passed to debugSSA for processing. -func NewDebugFlag(debug interface{}, debugSSA DebugSSA) *DebugFlag { +func NewDebugFlag(debug any, debugSSA DebugSSA) *DebugFlag { flag := &DebugFlag{ tab: make(map[string]debugField), debugSSA: debugSSA, |
