]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "go/printer: forbid empty line before first comment in block"
authorJoe Tsai <thebrokentoaster@gmail.com>
Fri, 1 Dec 2017 00:59:45 +0000 (00:59 +0000)
committerJoe Tsai <joetsai@google.com>
Fri, 1 Dec 2017 01:12:26 +0000 (01:12 +0000)
This reverts commit 08f19bbde1b01227fdc2fa2d326e4029bb74dd96.

Reason for revert:
The changed transformation takes effect on a larger set
of code snippets than expected.

For example, this:
    func foo() {

        // Comment
        bar()

    }
becomes:
    func foo() {
        // Comment
        bar()

    }

This is an unintended consequence.

Change-Id: Ifca88d6267dab8a8170791f7205124712bf8ace8
Reviewed-on: https://go-review.googlesource.com/81335
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Joe Tsai <joetsai@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

30 files changed:
misc/cgo/test/buildid_linux.go
src/cmd/compile/internal/ssa/gen/rulegen.go
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/x86/asm6.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ppc64/asm.go
src/encoding/base32/base32.go
src/go/doc/testdata/blank.0.golden
src/go/doc/testdata/blank.2.golden
src/go/doc/testdata/testing.0.golden
src/go/doc/testdata/testing.2.golden
src/go/printer/nodes.go
src/go/printer/printer.go
src/go/printer/testdata/comments.golden
src/go/printer/testdata/comments.input
src/go/printer/testdata/comments.x
src/hash/crc32/crc32_ppc64le.go
src/image/internal/imageutil/impl.go
src/net/http/httputil/dump_test.go
src/net/http/httputil/persist.go
src/net/http/internal/chunked.go
src/net/http/requestwrite_test.go
src/net/http/server.go
src/net/mail/message_test.go
src/regexp/syntax/parse.go
src/runtime/symtab.go
src/syscall/syscall_netbsd.go
src/syscall/syscall_openbsd.go
src/time/sleep_test.go
src/unicode/example_test.go

index d25a7ac434735c8b35ffd01e7a01b54c00c14a7f..47dd87128fffb4d0b052a17314334852544585ae 100644 (file)
@@ -39,6 +39,7 @@ func testBuildID(t *testing.T) {
                }
 
                for len(d) > 0 {
+
                        // ELF standards differ as to the sizes in
                        // note sections.  Both the GNU linker and
                        // gold always generate 32-bit sizes, so that
index 5946b01f8e44edf2f67a4df6506f36708457933c..c23a54d9b5dd2b3fe5aee4eab4c6840139cf9628 100644 (file)
@@ -659,6 +659,7 @@ func extract(val string) (op string, typ string, auxint string, aux string, args
 // It returns the op and unparsed strings for typ, auxint, and aux restrictions and for all args.
 // oparch is the architecture that op is located in, or "" for generic.
 func parseValue(val string, arch arch, loc string) (op opData, oparch string, typ string, auxint string, aux string, args []string) {
+
        // Resolve the op.
        var s string
        s, typ, auxint, aux, args = extract(val)
index 1f488d5e4d2bf1d7d09dcdc54b989d63394acad3..3938cebef627dea1fd174a384f6d5178395d152e 100644 (file)
@@ -2474,6 +2474,7 @@ func (c *ctxt9) asmout(p *obj.Prog, o *Optab, out []uint32) {
                d := c.vregoff(p.GetFrom3())
                var a int
                switch p.As {
+
                // These opcodes expect a mask operand that has to be converted into the
                // appropriate operand.  The way these were defined, not all valid masks are possible.
                // Left here for compatibility in case they were used or generated.
index a44497b35bb66a9412f862769da3e323c2b5f8f0..7b80892cf0fe724150cafdd223d9c22512951b6d 100644 (file)
@@ -2051,6 +2051,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
                c = 0
                for p := s.Func.Text; p != nil; p = p.Link {
                        if ctxt.Headtype == objabi.Hnacl && p.Isize > 0 {
+
                                // pad everything to avoid crossing 32-byte boundary
                                if c>>5 != (c+int32(p.Isize)-1)>>5 {
                                        c = naclpad(ctxt, s, c, -c&31)
index e8e7a53bdb7f5db7adc9779c04af731b0dadbb3f..e0541c435bd8860b565b7c0e9c6f49ce2304d1ca 100644 (file)
@@ -1859,6 +1859,7 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint6
        // Only break at outermost syms.
 
        if ctxt.Arch.InFamily(sys.PPC64) && s.Outer == nil && ctxt.IsELF && ctxt.LinkMode == LinkExternal && va-sect.Vaddr+funcsize+maxSizeTrampolinesPPC64(s, isTramp) > 0x1c00000 {
+
                // Set the length for the previous text section
                sect.Length = va - sect.Vaddr
 
index 9b30e5f27cc12b336e948904c50261ca6bb29d80..4e277f9aa9898658be8556ec74f5cd1708b0d95a 100644 (file)
@@ -523,6 +523,7 @@ func archrelocaddr(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool
 
 // resolve direct jump relocation r in s, and add trampoline if necessary
 func trampoline(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol) {
+
        // Trampolines are created if the branch offset is too large and the linker cannot insert a call stub to handle it.
        // For internal linking, trampolines are always created for long calls.
        // For external linking, the linker can insert a call stub to handle a long call, but depends on having the TOC address in
@@ -541,6 +542,7 @@ func trampoline(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol) {
                if (ctxt.LinkMode == ld.LinkExternal && s.Sect != r.Sym.Sect) || (ctxt.LinkMode == ld.LinkInternal && int64(int32(t<<6)>>6) != t) || (*ld.FlagDebugTramp > 1 && s.File != r.Sym.File) {
                        var tramp *sym.Symbol
                        for i := 0; ; i++ {
+
                                // Using r.Add as part of the name is significant in functions like duffzero where the call
                                // target is at some offset within the function.  Calls to duff+8 and duff+256 must appear as
                                // distinct trampolines.
index e0a6e04b1dbc5bc8c6803373e8f72d02e1693b32..e72ba74983e235f1a3ccb9263ed18e82ac721056 100644 (file)
@@ -290,6 +290,7 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
                dlen := 8
 
                for j := 0; j < 8; {
+
                        // We have reached the end and are missing padding
                        if len(src) == 0 && enc.padChar != NoPadding {
                                return n, false, CorruptInputError(olen - len(src) - j)
index 29c30f69429faec52e13c37267187c2fbcfe35bd..70f2929f8a6f6a978289b38e1de8c11536ae3a9a 100644 (file)
@@ -48,7 +48,6 @@ TYPES
                H       uint32
        
                A       uint8
-       
                // contains filtered or unexported fields
        }
 
index 29c30f69429faec52e13c37267187c2fbcfe35bd..70f2929f8a6f6a978289b38e1de8c11536ae3a9a 100644 (file)
@@ -48,7 +48,6 @@ TYPES
                H       uint32
        
                A       uint8
-       
                // contains filtered or unexported fields
        }
 
index 6bdf726efcfab264e6c86f57329adde8f5d9522f..83cf37cd3a9c3d90dcd77b089dfc498cd1eef8cb 100644 (file)
@@ -42,7 +42,6 @@ TYPES
        // B is a type passed to Benchmark functions to manage benchmark ...
        type B struct {
                N int
-       
                // contains filtered or unexported fields
        }
 
index 6bdf726efcfab264e6c86f57329adde8f5d9522f..83cf37cd3a9c3d90dcd77b089dfc498cd1eef8cb 100644 (file)
@@ -42,7 +42,6 @@ TYPES
        // B is a type passed to Benchmark functions to manage benchmark ...
        type B struct {
                N int
-       
                // contains filtered or unexported fields
        }
 
index 5b5b6063fbfade7c7d13d0c149225e7b45346a36..3e2ff4f5ae3365526820379f9c8552b5b241ce1e 100644 (file)
@@ -479,7 +479,6 @@ func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool)
                if isIncomplete {
                        if len(list) > 0 {
                                p.print(formfeed)
-                               p.print(newline)
                        }
                        p.flush(p.posFor(rbrace), token.RBRACE) // make sure we don't lose the last line comment
                        p.setLineComment("// contains filtered or unexported fields")
@@ -507,7 +506,6 @@ func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool)
                if isIncomplete {
                        if len(list) > 0 {
                                p.print(formfeed)
-                               p.print(newline)
                        }
                        p.flush(p.posFor(rbrace), token.RBRACE) // make sure we don't lose the last line comment
                        p.setLineComment("// contains filtered or unexported methods")
index 61723899d4dd202a1a5a76086477f7c867c115f3..dbb4bbd90cf205cfbc9304b23ca63ccb81803f71 100644 (file)
@@ -62,7 +62,7 @@ type printer struct {
        mode        pmode        // current printer mode
        impliedSemi bool         // if set, a linebreak implies a semicolon
        lastTok     token.Token  // last token printed (token.ILLEGAL if it's whitespace)
-       prevOpen    token.Token  // previous "open" token: (, [, {, or token.ILLEGAL
+       prevOpen    token.Token  // previous non-brace "open" token (, [, or token.ILLEGAL
        wsbuf       []whiteSpace // delayed white space
 
        // Positions
@@ -426,11 +426,6 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, prev *ast.Comment
                n := 0
                if pos.IsValid() && p.last.IsValid() {
                        n = pos.Line - p.last.Line
-                       if n > 1 && p.prevOpen != token.ILLEGAL && prev == nil {
-                               // Forbid multiple empty lines from appearing immediately
-                               // following some type of open paren, bracket, or brace.
-                               n = 1
-                       }
                        if n < 0 { // should never happen
                                n = 0
                        }
@@ -884,7 +879,7 @@ func (p *printer) print(args ...interface{}) {
                switch p.lastTok {
                case token.ILLEGAL:
                        // ignore (white space)
-               case token.LPAREN, token.LBRACK, token.LBRACE:
+               case token.LPAREN, token.LBRACK:
                        p.prevOpen = p.lastTok
                default:
                        // other tokens followed any opening token
index 3fc29ccf9133f11971bcc1b120dcb7c223cba6bd..e1818e5fd53042bf3148a79d6abcb0b1f4754301 100644 (file)
@@ -97,109 +97,6 @@ type S3 struct {
        f3      int     // f3 is not exported
 }
 
-type T struct {        // foo
-
-       // bar
-       x       int
-       X       int
-}
-
-type T struct {        /* foo */
-
-       // bar
-       x int
-}
-
-type T struct {        // foo
-
-       x       int
-
-       X       int
-}
-
-type T struct {        /* foo */
-
-       x int
-}
-
-type T struct {
-       x int
-}
-
-type T struct {
-       x int
-}
-
-type T struct{ x int }
-
-type T struct {
-       x int
-}
-
-type T struct {
-       x       int
-       X       int
-       x       int
-}
-
-type T struct {
-       // Comment
-       x       int
-       // X.
-       X       int
-       // Comment
-       x       int
-}
-
-const (        // foo
-
-       // bar
-       x       int     = 0
-       X       int     = 0
-)
-
-const (        /* foo */
-
-       // bar
-       x int = 0
-)
-
-const (        // foo
-
-       x       int     = 0
-
-       X       int     = 0
-)
-
-const (        /* foo */
-
-       x int = 0
-)
-
-const (
-       x int = 0
-)
-
-const (
-       x       int     = 0
-       X       int     = 0
-)
-
-const (
-       x       int     = 0
-       X       int     = 0
-       x       int     = 0
-)
-
-const (
-       // Comment
-       x       int     = 0
-       // X.
-       X       int     = 0
-       // Comment
-       x       int     = 0
-)
-
 // This comment group should be separated
 // with a newline from the next comment
 // group.
index 985e33479561507117fd72cc0612864553ffa6c5..f3eda12c22959cbe7834645c173adba21bc48f2b 100644 (file)
@@ -97,113 +97,6 @@ type S3 struct {
        f3 int // f3 is not exported
 }
 
-type T struct { // foo
-
-   // bar
-   x int
-   X int
-}
-
-type T struct { /* foo */
-
-                        // bar
-   x int
-}
-
-type T struct { // foo
-
-                                x int
-
-   X int
-}
-
-type T struct { /* foo */
-
-
-
-x int
-}
-
-type T struct {x int
-}
-
-type T struct {
-                                       x int}
-
-type T struct {x int}
-
-type T struct {
-
-   x int
-}
-
-type T struct {
-   x int
-   X int
-   x int
-}
-
-type T struct {
-   // Comment
-   x int
-   // X.
-   X int
-   // Comment
-   x int
-}
-
-const ( // foo
-
-   // bar
-   x int = 0
-   X int = 0
-)
-
-const ( /* foo */
-
-   // bar
-   x int = 0
-)
-
-const ( // foo
-
-   x int = 0
-
-   X int = 0
-)
-
-const ( /* foo */
-
-   x int = 0
-)
-
-const (
-
-   x int = 0
-)
-
-const (
-
-   x int = 0
-   X int = 0
-
-)
-
-const (
-   x int = 0
-   X int = 0
-   x int = 0
-)
-
-const (
-   // Comment
-   x int = 0
-   // X.
-   X int = 0
-   // Comment
-   x int = 0
-)
-
 // This comment group should be separated
 // with a newline from the next comment
 // group.
index 7178519b9531a18c254440034697fa06e81a755c..ae7729286e5a63aae5c784d1e16d6b5973e66612 100644 (file)
@@ -54,73 +54,3 @@ type S3 struct {
        F2      int     // line comment for F2
        // contains filtered or unexported fields
 }
-
-type T struct {
-       X int
-
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       X int
-
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       X int
-
-       // contains filtered or unexported fields
-}
-
-type T struct {
-       // X.
-       X int
-
-       // contains filtered or unexported fields
-}
-
-const (
-       X int = 0
-)
-
-const (
-       X int = 0
-)
-
-const (
-       X int = 0
-)
-
-const (
-       X int = 0
-)
-
-const (
-       // X.
-       X int = 0
-)
index 8e54d52b948f7cb14095857b46387b8020581f91..686722761d53ca744530a0a7c96405ac279b386b 100644 (file)
@@ -65,6 +65,7 @@ func archInitIEEE() {
 
 // archUpdateIEEE calculates the checksum of p using vectorizedIEEE.
 func archUpdateIEEE(crc uint32, p []byte) uint32 {
+
        // Check if vector code should be used.  If not aligned, then handle those
        // first up to the aligned bytes.
 
index 4c6de742da0e6c4976225e2441d8364b6a9246ad..cfd5047879a9dc828f84f84b351ded2f6db6c3ba 100644 (file)
@@ -42,6 +42,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
 
                        ci := (sy-src.Rect.Min.Y)*src.CStride + (sp.X - src.Rect.Min.X)
                        for x := x0; x != x1; x, yi, ci = x+4, yi+1, ci+1 {
+
                                // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
                                yy1 := int32(src.Y[yi]) * 0x10101
                                cb1 := int32(src.Cb[ci]) - 128
@@ -211,6 +212,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
 
                        ci := (sy/2-src.Rect.Min.Y/2)*src.CStride + (sp.X - src.Rect.Min.X)
                        for x := x0; x != x1; x, yi, ci = x+4, yi+1, ci+1 {
+
                                // This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
                                yy1 := int32(src.Y[yi]) * 0x10101
                                cb1 := int32(src.Cb[ci]) - 128
index a403c88eaa1499464b3f3497f266746a3fc55b83..f881020fef7e57a341a4704d600bb7b79643ab86 100644 (file)
@@ -27,6 +27,7 @@ type dumpTest struct {
 }
 
 var dumpTests = []dumpTest{
+
        // HTTP/1.1 => chunked coding; body; empty trailer
        {
                Req: http.Request{
index 24c9c734745dc5091c7f75f6ccea9e1716d41157..cbedf25ad1be5c5bc03ee10a31ed7ac9da885045 100644 (file)
@@ -173,6 +173,7 @@ func (sc *ServerConn) Pending() int {
 // Response.Close field to true. Write should be considered operational until
 // it returns an error, regardless of any errors returned on the Read side.
 func (sc *ServerConn) Write(req *http.Request, resp *http.Response) error {
+
        // Retrieve the pipeline ID of this request/response pair
        sc.mu.Lock()
        id, ok := sc.pipereq[req]
index 7f83a56f1c4f42a1a879f424fa896bf3a10f8b66..63f321d03b957dfcbacafc39acfc972d33e1eb4f 100644 (file)
@@ -192,6 +192,7 @@ type chunkedWriter struct {
 // NOTE: Note that the corresponding chunk-writing procedure in Conn.Write has
 // a bug since it does not check for success of io.WriteString
 func (cw *chunkedWriter) Write(data []byte) (n int, err error) {
+
        // Don't send 0-length data. It looks like EOF for chunked encoding.
        if len(data) == 0 {
                return 0, nil
index 74b01db6da6aacce133ba14d97eb11512579a8d0..eb65b9f736f5ba81e923f1b33ce837b757e1bc5b 100644 (file)
@@ -813,6 +813,7 @@ func TestRequestWriteError(t *testing.T) {
 // try to restore it. It always dumps the whole body.
 // And it doesn't support https.
 func dumpRequestOut(req *Request, onReadHeaders func()) ([]byte, error) {
+
        // Use the actual Transport code to record what we would send
        // on the wire, but not using TCP.  Use a Transport with a
        // custom dialer that returns a fake net.Conn that waits
index 45877096e283581bcf0fdac6bca34422d9aaed14..5338bee9b552cd37b21b4ee914bfea6417fb0243 100644 (file)
@@ -2249,6 +2249,7 @@ func (mux *ServeMux) shouldRedirect(path string) bool {
 // If there is no registered handler that applies to the request,
 // Handler returns a ``page not found'' handler and an empty pattern.
 func (mux *ServeMux) Handler(r *Request) (h Handler, pattern string) {
+
        // CONNECT requests are not canonicalized.
        if r.Method == "CONNECT" {
                // If r.URL.Path is /tree and its handler is not registered,
index b37393a34574016576681d77525a7a494ffed744..b19da52c423a7ffd08d8d3a84d89be7a5d4d8e87 100644 (file)
@@ -787,6 +787,7 @@ func TestAddressString(t *testing.T) {
 
 // Check if all valid addresses can be parsed, formatted and parsed again
 func TestAddressParsingAndFormatting(t *testing.T) {
+
        // Should pass
        tests := []string{
                `<Bob@example.com>`,
index 8b5b32a786e9c338769482f2792fdc79981f35ab..8c6d43a70636944fca38dd5a8af0e3158614fc87 100644 (file)
@@ -1626,6 +1626,7 @@ func (p *parser) parseClass(s string) (rest string, err error) {
 // cleanClass sorts the ranges (pairs of elements of r),
 // merges them, and eliminates duplicates.
 func cleanClass(rp *[]rune) []rune {
+
        // Sort by lo increasing, hi decreasing to break ties.
        sort.Sort(ranges{rp})
 
index c6c2b89f69aa6825e0a3e829259a92027e22b9ad..bdf98b9e9dc63798d41feca071490c91e4d5e45b 100644 (file)
@@ -648,6 +648,7 @@ func findfunc(pc uintptr) funcInfo {
                idx = uint32(len(datap.ftab) - 1)
        }
        if pc < datap.ftab[idx].entry {
+
                // With multiple text sections, the idx might reference a function address that
                // is higher than the pc being searched, so search backward until the matching address is found.
 
@@ -658,6 +659,7 @@ func findfunc(pc uintptr) funcInfo {
                        throw("findfunc: bad findfunctab entry idx")
                }
        } else {
+
                // linear search to find func with pc >= entry.
                for datap.ftab[idx+1].entry <= pc {
                        idx++
index 5545532bc912760d0598213ba038c18ae3daabe8..c645b139b1cdd43c856f2137986a42cd14840509 100644 (file)
@@ -52,6 +52,7 @@ func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) {
 }
 
 func nametomib(name string) (mib []_C_int, err error) {
+
        // Split name into components.
        var parts []string
        last := 0
index 8f58f7d34147baf1d647ddcea3cde1fd915b6f04..a43d88bf7a827a3cce90bee53f47a0b03f29a665 100644 (file)
@@ -29,6 +29,7 @@ type SockaddrDatalink struct {
 func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
 
 func nametomib(name string) (mib []_C_int, err error) {
+
        // Perform lookup via a binary search
        left := 0
        right := len(sysctlMib) - 1
index ea29ac4489c0b346673f6b46fb31ed84cd7dcab1..9af39c0d03b5c9693bdfe9770eb9a74dd3af048e 100644 (file)
@@ -82,6 +82,7 @@ func TestAfterStress(t *testing.T) {
 }
 
 func benchmark(b *testing.B, bench func(n int)) {
+
        // Create equal number of garbage timers on each P before starting
        // the benchmark.
        var wg sync.WaitGroup
index a60dae4458218aab19f325a6eb19d27051758f1e..50c5b18a48e63d8269996a21e810fbface9e6acf 100644 (file)
@@ -12,6 +12,7 @@ import (
 // Functions starting with "Is" can be used to inspect which table of range a
 // rune belongs to. Note that runes may fit into more than one range.
 func Example_is() {
+
        // constant with mixed type runes
        const mixed = "\b5Ὂg̀9! ℃ᾭG"
        for _, c := range mixed {