From 4fb2e1cb86a1f15a69ebf97a80503e865287642c Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Tue, 12 Oct 2021 12:52:59 -0700 Subject: [PATCH] cmd/compile: allow spaces in types.(*Type).LinkString() Go back to allowing spaces in types.(*Type).LinkSring(). Delve folks prefer that there are spaces in type names, if needed, since DWARF expects type names to be "a string representing the name as it appears in the source program". At this point, it doesn't necessarily seem worth having a separate function that removes spaces, only for use when printing the type names in a function/method instantiation. Most names of function/method instantiations will still not have spaces, since they most type args are named or builtin types. I confirmed that we are back to the original definition of LinkString(), except for some comment changes. Change-Id: Iab7143f659ddea4f099c6230cb134edf8aaef868 Reviewed-on: https://go-review.googlesource.com/c/go/+/355354 Run-TryBot: Dan Scales TryBot-Result: Go Bot Trust: Dan Scales Reviewed-by: Keith Randall --- src/cmd/compile/internal/types/fmt.go | 45 ++++++--------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go index c70e22c946..23fc4221e1 100644 --- a/src/cmd/compile/internal/types/fmt.go +++ b/src/cmd/compile/internal/types/fmt.go @@ -461,25 +461,15 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type case TINTER: if t.IsEmptyInterface() { - if mode == fmtTypeID { - b.WriteString("interface{}") - } else { - b.WriteString("interface {}") - } + b.WriteString("interface {}") break } - if mode == fmtTypeID { - b.WriteString("interface{") - } else { - b.WriteString("interface {") - } + b.WriteString("interface {") for i, f := range t.AllMethods().Slice() { if i != 0 { b.WriteByte(';') } - if mode != fmtTypeID { - b.WriteByte(' ') - } + b.WriteByte(' ') switch { case f.Sym == nil: // Check first that a symbol is defined for this type. @@ -495,7 +485,7 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type } tconv2(b, f.Type, 'S', mode, visited) } - if t.AllMethods().Len() != 0 && mode != fmtTypeID { + if t.AllMethods().Len() != 0 { b.WriteByte(' ') } b.WriteByte('}') @@ -570,21 +560,15 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type } b.WriteByte(byte(close)) } else { - if mode == fmtTypeID { - b.WriteString("struct{") - } else { - b.WriteString("struct {") - } + b.WriteString("struct {") for i, f := range t.Fields().Slice() { if i != 0 { b.WriteByte(';') } - if mode != fmtTypeID { - b.WriteByte(' ') - } + b.WriteByte(' ') fldconv(b, f, 'L', mode, visited, funarg) } - if t.NumFields() != 0 && mode != fmtTypeID { + if t.NumFields() != 0 { b.WriteByte(' ') } b.WriteByte('}') @@ -668,14 +652,7 @@ func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Ty if name != "" { b.WriteString(name) - if mode == fmtTypeID { - // This is the one case where we can't omit the space, since - // we need a separate between field name and type, so we use - // "#" instead. - b.WriteString("#") - } else { - b.WriteString(" ") - } + b.WriteString(" ") } if f.IsDDD() { @@ -690,11 +667,7 @@ func fldconv(b *bytes.Buffer, f *Field, verb rune, mode fmtMode, visited map[*Ty } if verb != 'S' && funarg == FunargNone && f.Note != "" { - if mode != fmtTypeID { - b.WriteString(" ") - } - // TODO: for fmtTypeID, we should possibly using %-quoting, so - // space is %20, etc. + b.WriteString(" ") b.WriteString(strconv.Quote(f.Note)) } } -- 2.50.0