]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types: remove Funarg
authorMatthew Dempsky <mdempsky@google.com>
Sun, 20 Aug 2023 21:06:17 +0000 (14:06 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 22 Aug 2023 20:43:28 +0000 (20:43 +0000)
There's no need for the Funarg type anymore. A simple boolean suffices
to indicate whether a TSTRUCT represents a parameter tuple.

While here, rename Struct.Funarg to ParamTuple.

Change-Id: I657512d4ba10e51ec4cfd7c7d77e0194bdb0853b
Reviewed-on: https://go-review.googlesource.com/c/go/+/521315
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/types/fmt.go
src/cmd/compile/internal/types/type.go

index 7489edd42e5e7f5f5fed15b5b33f067f9f751e25..2b9ba083144ff1cbb31d1bccbd24af4931ea6cce 100644 (file)
@@ -520,12 +520,8 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
                        break
                }
 
-               if funarg := t.StructType().Funarg; funarg != FunargNone {
-                       open, close := '(', ')'
-                       if funarg == FunargTparams {
-                               open, close = '[', ']'
-                       }
-                       b.WriteByte(byte(open))
+               if t.StructType().ParamTuple {
+                       b.WriteByte('(')
                        fieldVerb := 'v'
                        switch mode {
                        case fmtTypeID, fmtTypeIDName, fmtGo:
@@ -536,9 +532,9 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
                                if i != 0 {
                                        b.WriteString(", ")
                                }
-                               fldconv(b, f, fieldVerb, mode, visited, funarg)
+                               fldconv(b, f, fieldVerb, mode, visited, true)
                        }
-                       b.WriteByte(byte(close))
+                       b.WriteByte(')')
                } else {
                        b.WriteString("struct {")
                        for i, f := range t.Fields() {
@@ -546,7 +542,7 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
                                        b.WriteByte(';')
                                }
                                b.WriteByte(' ')
-                               fldconv(b, f, 'L', mode, visited, funarg)
+                               fldconv(b, f, 'L', mode, visited, false)
                        }
                        if t.NumFields() != 0 {
                                b.WriteByte(' ')
@@ -577,7 +573,7 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
        }
 }
 
-func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Type]int, funarg Funarg) {
+func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Type]int, isParam bool) {
        if f == nil {
                b.WriteString("<T>")
                return
@@ -634,7 +630,7 @@ func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Ty
                }
 
                if s != nil {
-                       if funarg != FunargNone {
+                       if isParam {
                                name = fmt.Sprint(f.Nname)
                        } else if verb == 'L' {
                                name = s.Name
@@ -666,7 +662,7 @@ func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Ty
                tconv2(b, f.Type, 0, mode, visited)
        }
 
-       if verb != 'S' && funarg == FunargNone && f.Note != "" {
+       if verb != 'S' && !isParam && f.Note != "" {
                b.WriteString(" ")
                b.WriteString(strconv.Quote(f.Note))
        }
index 696e8a5bc1321e1593e22aa27baeaa4461e8a20b..343cc69c180319fcc41359e9fe401b2aa2ecbfe4 100644 (file)
@@ -323,20 +323,9 @@ type Struct struct {
        // Map links such structs back to their map type.
        Map *Type
 
-       Funarg Funarg // type of function arguments for arg struct
+       ParamTuple bool // whether this struct is actually a tuple of signature parameters
 }
 
-// Funarg records the kind of function argument
-type Funarg uint8
-
-const (
-       FunargNone    Funarg = iota
-       FunargRcvr           // receiver
-       FunargParams         // input parameters
-       FunargResults        // output results
-       FunargTparams        // type params
-)
-
 // StructType returns t's extra struct-specific fields.
 func (t *Type) StructType() *Struct {
        t.wantEtype(TSTRUCT)
@@ -890,7 +879,7 @@ func (t *Type) FuncArgs() *Type {
 
 // IsFuncArgStruct reports whether t is a struct representing function parameters or results.
 func (t *Type) IsFuncArgStruct() bool {
-       return t.kind == TSTRUCT && t.extra.(*Struct).Funarg != FunargNone
+       return t.kind == TSTRUCT && t.extra.(*Struct).ParamTuple
 }
 
 // Methods returns a pointer to the base methods (excluding embedding) for type t.
@@ -1716,9 +1705,9 @@ func NewSignature(recv *Field, params, results []*Field) *Type {
        t := newType(TFUNC)
        ft := t.funcType()
 
-       funargs := func(fields []*Field, funarg Funarg) *Type {
+       funargs := func(fields []*Field) *Type {
                s := NewStruct(fields)
-               s.StructType().Funarg = funarg
+               s.StructType().ParamTuple = true
                return s
        }
 
@@ -1727,9 +1716,9 @@ func NewSignature(recv *Field, params, results []*Field) *Type {
        }
        unzeroFieldOffsets(params)
        unzeroFieldOffsets(results)
-       ft.Receiver = funargs(recvs, FunargRcvr)
-       ft.Params = funargs(params, FunargParams)
-       ft.Results = funargs(results, FunargResults)
+       ft.Receiver = funargs(recvs)
+       ft.Params = funargs(params)
+       ft.Results = funargs(results)
        if fieldsHasShape(recvs) || fieldsHasShape(params) || fieldsHasShape(results) {
                t.SetHasShape(true)
        }