]> Cypherpunks.ru repositories - gostls13.git/commit
go/printer: remove exported StdFormat flag
authorDmitri Shuralyov <dmitshur@golang.org>
Wed, 1 Jul 2020 16:49:43 +0000 (12:49 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 17 Jul 2020 02:15:01 +0000 (02:15 +0000)
commit6f264801a76bbf1a0defacba4230efaefc47598c
tree62e26fcd8386a98a5974847c92017cfd8a1f6f06
parent4469f5446ad754d87afb340f59c213aec2dc4fb8
go/printer: remove exported StdFormat flag

The StdFormat flag was added as part of CL 231461, where the primary aim
was to fix the bug #37476. It's expected that the existing printer modes
only adjust spacing but do not change any of the code text itself. A new
printing flag served as a way for cmd/gofmt and go/format to delegate
a part of formatting work to the printer—where it's more more convenient
and efficient to perform—while maintaining current low-level printing
behavior of go/printer unmodified.

We already have cmd/gofmt and the go/format API that implement standard
formatting of Go source code, so there isn't a need to expose StdFormat
flag to the world, as it can only cause confusion.

Consider that to format source in canonical gofmt style completely it
may require tasks A, B, C to be done. In one version of Go, the printer
may do both A and B, while cmd/gofmt and go/format will do the remaining
task C. In another version, the printer may take on doing just A, while
cmd/gofmt and go/format will perform B and C. This makes it hard to add
a gofmt-like mode to the printer without compromising on above fluidity.

This change prefers to shift back some complexity to the implementation
of the standard library, allowing us to avoid creating the new exported
printing flag just for the internal needs of gofmt and go/format today.

We may still want to re-think the API and consider if something better
should be added, but unfortunately there isn't time for Go 1.15. We are
not adding new APIs now, so we can defer this decision until Go 1.16 or
later, when there is more time.

For #37476.
For #37453.
For #39489.
For #37419.

Change-Id: I0bb07156dca852b043487099dcf05c5350b29e20
Reviewed-on: https://go-review.googlesource.com/c/go/+/240683
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
api/go1.15.txt
doc/go1.15.html
src/cmd/gofmt/gofmt.go
src/go/format/format.go
src/go/format/format_test.go
src/go/printer/nodes.go
src/go/printer/performance_test.go
src/go/printer/printer.go
src/go/printer/printer_test.go
src/go/printer/testdata/go2numbers.norm [moved from src/go/printer/testdata/go2numbers.stdfmt with 100% similarity]