From 31267f82e16249a1d9065099c615a936dc32688b Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 23 Dec 2020 02:48:57 -0800 Subject: [dev.regabi] cmd/compile: simplify function/interface/struct typechecking After the previous CL, the only callers to NewFuncType, tointerface, or NewStructType are the functions for type-checking the type literal ASTs. So just inline the code there. While here, refactor the Field type-checking logic a little bit, to reduce some duplication. Passes toolstash -cmp. Change-Id: Ie12d14b87ef8b6e528ac9dccd609604bd09b98ec Reviewed-on: https://go-review.googlesource.com/c/go/+/279956 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/typecheck/dcl.go | 87 ------------------------------- 1 file changed, 87 deletions(-) (limited to 'src/cmd/compile/internal/typecheck/dcl.go') diff --git a/src/cmd/compile/internal/typecheck/dcl.go b/src/cmd/compile/internal/typecheck/dcl.go index bfdd76ba10..db18c17e13 100644 --- a/src/cmd/compile/internal/typecheck/dcl.go +++ b/src/cmd/compile/internal/typecheck/dcl.go @@ -281,72 +281,6 @@ func CheckFuncStack() { } } -// turn a parsed function declaration into a type -func NewFuncType(nrecv *ir.Field, nparams, nresults []*ir.Field) *types.Type { - funarg := func(n *ir.Field) *types.Field { - lno := base.Pos - base.Pos = n.Pos - - if n.Ntype != nil { - n.Type = typecheckNtype(n.Ntype).Type() - n.Ntype = nil - } - - f := types.NewField(n.Pos, n.Sym, n.Type) - f.SetIsDDD(n.IsDDD) - if n.Decl != nil { - n.Decl.SetType(f.Type) - f.Nname = n.Decl - } - - base.Pos = lno - return f - } - funargs := func(nn []*ir.Field) []*types.Field { - res := make([]*types.Field, len(nn)) - for i, n := range nn { - res[i] = funarg(n) - } - return res - } - - var recv *types.Field - if nrecv != nil { - recv = funarg(nrecv) - } - - t := types.NewSignature(types.LocalPkg, recv, funargs(nparams), funargs(nresults)) - checkdupfields("argument", t.Recvs().FieldSlice(), t.Params().FieldSlice(), t.Results().FieldSlice()) - return t -} - -// convert a parsed id/type list into -// a type for struct/interface/arglist -func NewStructType(l []*ir.Field) *types.Type { - lno := base.Pos - - fields := make([]*types.Field, len(l)) - for i, n := range l { - base.Pos = n.Pos - - if n.Ntype != nil { - n.Type = typecheckNtype(n.Ntype).Type() - n.Ntype = nil - } - f := types.NewField(n.Pos, n.Sym, n.Type) - if n.Embedded { - checkembeddedtype(n.Type) - f.Embedded = 1 - } - f.Note = n.Note - fields[i] = f - } - checkdupfields("field", fields) - - base.Pos = lno - return types.NewStruct(types.LocalPkg, fields) -} - // Add a method, declared as a function. // - msym is the method symbol // - t is function type (with receiver) @@ -604,27 +538,6 @@ func initname(s string) bool { return s == "init" } -func tointerface(nmethods []*ir.Field) *types.Type { - if len(nmethods) == 0 { - return types.Types[types.TINTER] - } - - lno := base.Pos - - methods := make([]*types.Field, len(nmethods)) - for i, n := range nmethods { - base.Pos = n.Pos - if n.Ntype != nil { - n.Type = typecheckNtype(n.Ntype).Type() - n.Ntype = nil - } - methods[i] = types.NewField(n.Pos, n.Sym, n.Type) - } - - base.Pos = lno - return types.NewInterface(types.LocalPkg, methods) -} - var vargen int func Temp(t *types.Type) *ir.Name { -- cgit v1.2.3-54-g00ecf