From d5cd55a289144c25aff4ae8d293bb31f9bdba3a3 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 19 Aug 2023 23:04:46 -0700 Subject: [PATCH] cmd/compile/internal/abi: stop using types.Func This is supposed to be an internal type within package types. At least for now, users of the types package should stick to the types.Type APIs as much as possible. This CL also unexports FuncType and a few others to prevent backsliding. Change-Id: I053fc115a5e6a57c148c8149851a45114756072f Reviewed-on: https://go-review.googlesource.com/c/go/+/521255 Run-TryBot: Matthew Dempsky Auto-Submit: Matthew Dempsky Reviewed-by: Cuong Manh Le Reviewed-by: Austin Clements TryBot-Result: Gopher Robot --- src/cmd/compile/internal/abi/abiutils.go | 20 +++++----- src/cmd/compile/internal/gc/compile.go | 2 +- .../compile/internal/reflectdata/reflect.go | 9 ++--- src/cmd/compile/internal/ssa/debug.go | 4 +- src/cmd/compile/internal/ssagen/abi.go | 2 +- src/cmd/compile/internal/types/type.go | 38 +++++++++---------- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index 71fbb88888..7d3da3c66d 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -380,25 +380,24 @@ func (config *ABIConfig) ABIAnalyzeTypes(rcvr *types.Type, ins, outs []*types.Ty // 'config' and analyzes the function to determine how its parameters // and results will be passed (in registers or on the stack), returning // an ABIParamResultInfo object that holds the results of the analysis. -func (config *ABIConfig) ABIAnalyzeFuncType(ft *types.Func) *ABIParamResultInfo { +func (config *ABIConfig) ABIAnalyzeFuncType(ft *types.Type) *ABIParamResultInfo { setup() s := assignState{ stackOffset: config.offsetForLocals, rTotal: config.regAmounts, } result := &ABIParamResultInfo{config: config} - result.preAllocateParams(ft.Receiver != nil, ft.Params.NumFields(), ft.Results.NumFields()) + result.preAllocateParams(ft.Recv() != nil, ft.NumParams(), ft.NumResults()) // Receiver // TODO(register args) ? seems like "struct" and "fields" is not right anymore for describing function parameters - if ft.Receiver != nil && ft.Receiver.NumFields() != 0 { - r := ft.Receiver.FieldSlice()[0] + if r := ft.Recv(); r != nil { result.inparams = append(result.inparams, s.assignParamOrReturn(r.Type, r.Nname, false)) } // Inputs - ifsl := ft.Params.FieldSlice() + ifsl := ft.Params().FieldSlice() for _, f := range ifsl { result.inparams = append(result.inparams, s.assignParamOrReturn(f.Type, f.Nname, false)) @@ -408,7 +407,7 @@ func (config *ABIConfig) ABIAnalyzeFuncType(ft *types.Func) *ABIParamResultInfo // Outputs s.rUsed = RegAmounts{} - ofsl := ft.Results.FieldSlice() + ofsl := ft.Results().FieldSlice() for _, f := range ofsl { result.outparams = append(result.outparams, s.assignParamOrReturn(f.Type, f.Nname, true)) } @@ -428,19 +427,18 @@ func (config *ABIConfig) ABIAnalyzeFuncType(ft *types.Func) *ABIParamResultInfo // outputs because their frame location transitions from BOGUS_FUNARG_OFFSET // to zero to an as-if-AUTO offset that has no use for callers. func (config *ABIConfig) ABIAnalyze(t *types.Type, setNname bool) *ABIParamResultInfo { - ft := t.FuncType() - result := config.ABIAnalyzeFuncType(ft) + result := config.ABIAnalyzeFuncType(t) // Fill in the frame offsets for receiver, inputs, results k := 0 if t.NumRecvs() != 0 { - config.updateOffset(result, ft.Receiver.FieldSlice()[0], result.inparams[0], false, setNname) + config.updateOffset(result, t.Recv(), result.inparams[0], false, setNname) k++ } - for i, f := range ft.Params.FieldSlice() { + for i, f := range t.Params().FieldSlice() { config.updateOffset(result, f, result.inparams[k+i], false, setNname) } - for i, f := range ft.Results.FieldSlice() { + for i, f := range t.Results().FieldSlice() { config.updateOffset(result, f, result.outparams[i], true, setNname) } return result diff --git a/src/cmd/compile/internal/gc/compile.go b/src/cmd/compile/internal/gc/compile.go index a2ffed7b00..27d9c55fdb 100644 --- a/src/cmd/compile/internal/gc/compile.go +++ b/src/cmd/compile/internal/gc/compile.go @@ -56,7 +56,7 @@ func enqueueFunc(fn *ir.Func) { ir.InitLSym(fn, false) types.CalcSize(fn.Type()) a := ssagen.AbiForBodylessFuncStackMap(fn) - abiInfo := a.ABIAnalyzeFuncType(fn.Type().FuncType()) // abiInfo has spill/home locations for wrapper + abiInfo := a.ABIAnalyzeFuncType(fn.Type()) // abiInfo has spill/home locations for wrapper liveness.WriteFuncMap(fn, abiInfo) if fn.ABI == obj.ABI0 { x := ssagen.EmitArgInfo(fn, abiInfo) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 2e5301c823..ba8c0b2af6 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1384,12 +1384,11 @@ func WriteImportStrings() { // WriteBasicTypes always writes pointer types; any pointer has been stripped off typ already. func writtenByWriteBasicTypes(typ *types.Type) bool { if typ.Sym() == nil && typ.Kind() == types.TFUNC { - f := typ.FuncType() // func(error) string - if f.Receiver.NumFields() == 0 && - f.Params.NumFields() == 1 && f.Results.NumFields() == 1 && - f.Params.FieldType(0) == types.ErrorType && - f.Results.FieldType(0) == types.Types[types.TSTRING] { + if typ.NumRecvs() == 0 && + typ.NumParams() == 1 && typ.NumResults() == 1 && + typ.Params().FieldType(0) == types.ErrorType && + typ.Results().FieldType(0) == types.Types[types.TSTRING] { return true } } diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index 63934662a5..36f9271ebf 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -433,7 +433,7 @@ func (sc *slotCanonicalizer) canonSlot(idx SlKeyIdx) LocalSlot { // synthesizes new (dead) values for the non-live params or the // non-live pieces of partially live params. func PopulateABIInRegArgOps(f *Func) { - pri := f.ABISelf.ABIAnalyzeFuncType(f.Type.FuncType()) + pri := f.ABISelf.ABIAnalyzeFuncType(f.Type) // When manufacturing new slots that correspond to splits of // composite parameters, we want to avoid creating a new sub-slot @@ -1754,7 +1754,7 @@ func isNamedRegParam(p abi.ABIParamAssignment) bool { // each input param reg will be spilled in the prolog). func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, stackOffset func(LocalSlot) int32, rval *FuncDebug) { - pri := f.ABISelf.ABIAnalyzeFuncType(f.Type.FuncType()) + pri := f.ABISelf.ABIAnalyzeFuncType(f.Type) // Look to see if we have any named register-promoted parameters. // If there are none, bail early and let the caller sort things diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go index cd01fdacbe..bec30c9f2c 100644 --- a/src/cmd/compile/internal/ssagen/abi.go +++ b/src/cmd/compile/internal/ssagen/abi.go @@ -436,7 +436,7 @@ func setupWasmABI(f *ir.Func) { // // (import "a_module" "add" (func (param i32 i32) (result i32))) abiConfig := AbiForBodylessFuncStackMap(f) - abiInfo := abiConfig.ABIAnalyzeFuncType(f.Type().FuncType()) + abiInfo := abiConfig.ABIAnalyzeFuncType(f.Type()) wi.Params = paramsToWasmFields(f, abiInfo, abiInfo.InParams()) wi.Results = resultsToWasmFields(f, abiInfo, abiInfo.OutParams()) } diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index 2b72a9cd24..7a69aaabc1 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -292,8 +292,8 @@ type Forward struct { Embedlineno src.XPos // first use of this type as an embedded type } -// ForwardType returns t's extra forward-type-specific fields. -func (t *Type) ForwardType() *Forward { +// forwardType returns t's extra forward-type-specific fields. +func (t *Type) forwardType() *Forward { t.wantEtype(TFORW) return t.extra.(*Forward) } @@ -310,8 +310,8 @@ type Func struct { Argwid int64 } -// FuncType returns t's extra func-specific fields. -func (t *Type) FuncType() *Func { +// funcType returns t's extra func-specific fields. +func (t *Type) funcType() *Func { t.wantEtype(TFUNC) return t.extra.(*Func) } @@ -369,8 +369,8 @@ type Chan struct { Dir ChanDir // channel direction } -// ChanType returns t's extra channel-specific fields. -func (t *Type) ChanType() *Chan { +// chanType returns t's extra channel-specific fields. +func (t *Type) chanType() *Chan { t.wantEtype(TCHAN) return t.extra.(*Chan) } @@ -570,7 +570,7 @@ func NewSlice(elem *Type) *Type { // NewChan returns a new chan Type with direction dir. func NewChan(elem *Type, dir ChanDir) *Type { t := newType(TCHAN) - ct := t.ChanType() + ct := t.chanType() ct.Elem = elem ct.Dir = dir if elem.HasShape() { @@ -742,9 +742,9 @@ func SubstAny(t *Type, types *[]*Type) *Type { results := SubstAny(t.Results(), types) if recvs != t.Recvs() || params != t.Params() || results != t.Results() { t = t.copy() - t.FuncType().Receiver = recvs - t.FuncType().Results = results - t.FuncType().Params = params + t.funcType().Receiver = recvs + t.funcType().Results = results + t.funcType().Params = params } case TSTRUCT: @@ -815,13 +815,13 @@ func (t *Type) wantEtype(et Kind) { } } -func (t *Type) Recvs() *Type { return t.FuncType().Receiver } -func (t *Type) Params() *Type { return t.FuncType().Params } -func (t *Type) Results() *Type { return t.FuncType().Results } +func (t *Type) Recvs() *Type { return t.funcType().Receiver } +func (t *Type) Params() *Type { return t.funcType().Params } +func (t *Type) Results() *Type { return t.funcType().Results } -func (t *Type) NumRecvs() int { return t.FuncType().Receiver.NumFields() } -func (t *Type) NumParams() int { return t.FuncType().Params.NumFields() } -func (t *Type) NumResults() int { return t.FuncType().Results.NumFields() } +func (t *Type) NumRecvs() int { return t.funcType().Receiver.NumFields() } +func (t *Type) NumParams() int { return t.funcType().Params.NumFields() } +func (t *Type) NumResults() int { return t.funcType().Results.NumFields() } // IsVariadic reports whether function type t is variadic. func (t *Type) IsVariadic() bool { @@ -1628,11 +1628,11 @@ func (t *Type) SetVargen() { func (t *Type) SetUnderlying(underlying *Type) { if underlying.kind == TFORW { // This type isn't computed yet; when it is, update n. - underlying.ForwardType().Copyto = append(underlying.ForwardType().Copyto, t) + underlying.forwardType().Copyto = append(underlying.forwardType().Copyto, t) return } - ft := t.ForwardType() + ft := t.forwardType() // TODO(mdempsky): Fix Type rekinding. t.kind = underlying.kind @@ -1717,7 +1717,7 @@ func NewSignature(recv *Field, params, results []*Field) *Type { } t := newType(TFUNC) - ft := t.FuncType() + ft := t.funcType() funargs := func(fields []*Field, funarg Funarg) *Type { s := NewStruct(fields) -- 2.50.0