]> Cypherpunks repositories - gostls13.git/commit
[dev.typeparams] cmd/compile: simplify formatting of defined types
authorMatthew Dempsky <mdempsky@google.com>
Mon, 31 May 2021 01:13:36 +0000 (18:13 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 31 May 2021 03:22:58 +0000 (03:22 +0000)
commitf32f4f58d9cd9d15371ee6198c1b222bcf2b56d9
tree8f314ee8fd07ead2b9fa8657eb076e3527607e89
parent22f5ece3b13b7e5f6dece399c96d1d665b3a05bc
[dev.typeparams] cmd/compile: simplify formatting of defined types

The existing code for deciding how to format defined type names is
incredibly convoluted and difficult to follow. In particular, I'm
looking at changing how Vargen works, and I couldn't tell from the
existing code whether my idea was viable.

This CL overhauls the logic to be much simpler with fewer special
cases, while overall behaving the same. A few notable intentional
differences from how the current code works:

1. The old code replaced the 'S' verb for fmtTypeGo and fmtTypeDebug
to 'v', whereas the new code leaves it alone. There's currently no
code that actually uses 'S' with these modes anyway, so it doesn't
seem important to maintain this special case. If future code wants 'v'
formatting, it should just use 'v' instead of 'S'.

2. The old code included Vargen for fmtTypeIDName mode with the 'S'
verb; but again, this functionality isn't actually used. I think it
would make sense for fmtTypeIDName to include Vargen like fmtTypeID
does (Vargen is logically part of the type's identity after all), but
that breaks tests and toolstash -cmp. So for now, this is left as a
TODO to investigate in the future.

3. The old code only added Vargen for fmtTypeID in 'v' mode when
printing types from the local package. But because we don't currently
support exporting function-scoped defined types anyway, this is again
irrelevant. In fact, once we *do* support exporting function-scoped
defined types, we'll need to include Vargen to generate the linker
symbols correctly.

Passes toolstash -cmp.

Change-Id: I4e481276bc4dc8d5b17eebf597b612737f26be5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/323709
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/types/fmt.go