Skip to content

Commit b53088a

Browse files
committed
Revert "go/printer: forbid empty line before first comment in block"
This reverts commit 08f19bb. 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 <[email protected]> Run-TryBot: Joe Tsai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 2065685 commit b53088a

File tree

30 files changed

+26
-293
lines changed

30 files changed

+26
-293
lines changed

misc/cgo/test/buildid_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func testBuildID(t *testing.T) {
3939
}
4040

4141
for len(d) > 0 {
42+
4243
// ELF standards differ as to the sizes in
4344
// note sections. Both the GNU linker and
4445
// gold always generate 32-bit sizes, so that

src/cmd/compile/internal/ssa/gen/rulegen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ func extract(val string) (op string, typ string, auxint string, aux string, args
659659
// It returns the op and unparsed strings for typ, auxint, and aux restrictions and for all args.
660660
// oparch is the architecture that op is located in, or "" for generic.
661661
func parseValue(val string, arch arch, loc string) (op opData, oparch string, typ string, auxint string, aux string, args []string) {
662+
662663
// Resolve the op.
663664
var s string
664665
s, typ, auxint, aux, args = extract(val)

src/cmd/internal/obj/ppc64/asm9.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,7 @@ func (c *ctxt9) asmout(p *obj.Prog, o *Optab, out []uint32) {
24742474
d := c.vregoff(p.GetFrom3())
24752475
var a int
24762476
switch p.As {
2477+
24772478
// These opcodes expect a mask operand that has to be converted into the
24782479
// appropriate operand. The way these were defined, not all valid masks are possible.
24792480
// Left here for compatibility in case they were used or generated.

src/cmd/internal/obj/x86/asm6.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
20512051
c = 0
20522052
for p := s.Func.Text; p != nil; p = p.Link {
20532053
if ctxt.Headtype == objabi.Hnacl && p.Isize > 0 {
2054+
20542055
// pad everything to avoid crossing 32-byte boundary
20552056
if c>>5 != (c+int32(p.Isize)-1)>>5 {
20562057
c = naclpad(ctxt, s, c, -c&31)

src/cmd/link/internal/ld/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,7 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint6
18591859
// Only break at outermost syms.
18601860

18611861
if ctxt.Arch.InFamily(sys.PPC64) && s.Outer == nil && ctxt.IsELF && ctxt.LinkMode == LinkExternal && va-sect.Vaddr+funcsize+maxSizeTrampolinesPPC64(s, isTramp) > 0x1c00000 {
1862+
18621863
// Set the length for the previous text section
18631864
sect.Length = va - sect.Vaddr
18641865

src/cmd/link/internal/ppc64/asm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ func archrelocaddr(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool
523523

524524
// resolve direct jump relocation r in s, and add trampoline if necessary
525525
func trampoline(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol) {
526+
526527
// Trampolines are created if the branch offset is too large and the linker cannot insert a call stub to handle it.
527528
// For internal linking, trampolines are always created for long calls.
528529
// 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) {
541542
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) {
542543
var tramp *sym.Symbol
543544
for i := 0; ; i++ {
545+
544546
// Using r.Add as part of the name is significant in functions like duffzero where the call
545547
// target is at some offset within the function. Calls to duff+8 and duff+256 must appear as
546548
// distinct trampolines.

src/encoding/base32/base32.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
290290
dlen := 8
291291

292292
for j := 0; j < 8; {
293+
293294
// We have reached the end and are missing padding
294295
if len(src) == 0 && enc.padChar != NoPadding {
295296
return n, false, CorruptInputError(olen - len(src) - j)

src/go/doc/testdata/blank.0.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ TYPES
4848
H uint32
4949

5050
A uint8
51-
5251
// contains filtered or unexported fields
5352
}
5453

src/go/doc/testdata/blank.2.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ TYPES
4848
H uint32
4949

5050
A uint8
51-
5251
// contains filtered or unexported fields
5352
}
5453

src/go/doc/testdata/testing.0.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ TYPES
4242
// B is a type passed to Benchmark functions to manage benchmark ...
4343
type B struct {
4444
N int
45-
4645
// contains filtered or unexported fields
4746
}
4847

src/go/doc/testdata/testing.2.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ TYPES
4242
// B is a type passed to Benchmark functions to manage benchmark ...
4343
type B struct {
4444
N int
45-
4645
// contains filtered or unexported fields
4746
}
4847

src/go/printer/nodes.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool)
479479
if isIncomplete {
480480
if len(list) > 0 {
481481
p.print(formfeed)
482-
p.print(newline)
483482
}
484483
p.flush(p.posFor(rbrace), token.RBRACE) // make sure we don't lose the last line comment
485484
p.setLineComment("// contains filtered or unexported fields")
@@ -507,7 +506,6 @@ func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool)
507506
if isIncomplete {
508507
if len(list) > 0 {
509508
p.print(formfeed)
510-
p.print(newline)
511509
}
512510
p.flush(p.posFor(rbrace), token.RBRACE) // make sure we don't lose the last line comment
513511
p.setLineComment("// contains filtered or unexported methods")

src/go/printer/printer.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type printer struct {
6262
mode pmode // current printer mode
6363
impliedSemi bool // if set, a linebreak implies a semicolon
6464
lastTok token.Token // last token printed (token.ILLEGAL if it's whitespace)
65-
prevOpen token.Token // previous "open" token: (, [, {, or token.ILLEGAL
65+
prevOpen token.Token // previous non-brace "open" token (, [, or token.ILLEGAL
6666
wsbuf []whiteSpace // delayed white space
6767

6868
// Positions
@@ -426,11 +426,6 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, prev *ast.Comment
426426
n := 0
427427
if pos.IsValid() && p.last.IsValid() {
428428
n = pos.Line - p.last.Line
429-
if n > 1 && p.prevOpen != token.ILLEGAL && prev == nil {
430-
// Forbid multiple empty lines from appearing immediately
431-
// following some type of open paren, bracket, or brace.
432-
n = 1
433-
}
434429
if n < 0 { // should never happen
435430
n = 0
436431
}
@@ -884,7 +879,7 @@ func (p *printer) print(args ...interface{}) {
884879
switch p.lastTok {
885880
case token.ILLEGAL:
886881
// ignore (white space)
887-
case token.LPAREN, token.LBRACK, token.LBRACE:
882+
case token.LPAREN, token.LBRACK:
888883
p.prevOpen = p.lastTok
889884
default:
890885
// other tokens followed any opening token

src/go/printer/testdata/comments.golden

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -97,109 +97,6 @@ type S3 struct {
9797
f3 int // f3 is not exported
9898
}
9999

100-
type T struct { // foo
101-
102-
// bar
103-
x int
104-
X int
105-
}
106-
107-
type T struct { /* foo */
108-
109-
// bar
110-
x int
111-
}
112-
113-
type T struct { // foo
114-
115-
x int
116-
117-
X int
118-
}
119-
120-
type T struct { /* foo */
121-
122-
x int
123-
}
124-
125-
type T struct {
126-
x int
127-
}
128-
129-
type T struct {
130-
x int
131-
}
132-
133-
type T struct{ x int }
134-
135-
type T struct {
136-
x int
137-
}
138-
139-
type T struct {
140-
x int
141-
X int
142-
x int
143-
}
144-
145-
type T struct {
146-
// Comment
147-
x int
148-
// X.
149-
X int
150-
// Comment
151-
x int
152-
}
153-
154-
const ( // foo
155-
156-
// bar
157-
x int = 0
158-
X int = 0
159-
)
160-
161-
const ( /* foo */
162-
163-
// bar
164-
x int = 0
165-
)
166-
167-
const ( // foo
168-
169-
x int = 0
170-
171-
X int = 0
172-
)
173-
174-
const ( /* foo */
175-
176-
x int = 0
177-
)
178-
179-
const (
180-
x int = 0
181-
)
182-
183-
const (
184-
x int = 0
185-
X int = 0
186-
)
187-
188-
const (
189-
x int = 0
190-
X int = 0
191-
x int = 0
192-
)
193-
194-
const (
195-
// Comment
196-
x int = 0
197-
// X.
198-
X int = 0
199-
// Comment
200-
x int = 0
201-
)
202-
203100
// This comment group should be separated
204101
// with a newline from the next comment
205102
// group.

src/go/printer/testdata/comments.input

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -97,113 +97,6 @@ type S3 struct {
9797
f3 int // f3 is not exported
9898
}
9999

100-
type T struct { // foo
101-
102-
// bar
103-
x int
104-
X int
105-
}
106-
107-
type T struct { /* foo */
108-
109-
// bar
110-
x int
111-
}
112-
113-
type T struct { // foo
114-
115-
x int
116-
117-
X int
118-
}
119-
120-
type T struct { /* foo */
121-
122-
123-
124-
x int
125-
}
126-
127-
type T struct {x int
128-
}
129-
130-
type T struct {
131-
x int}
132-
133-
type T struct {x int}
134-
135-
type T struct {
136-
137-
x int
138-
}
139-
140-
type T struct {
141-
x int
142-
X int
143-
x int
144-
}
145-
146-
type T struct {
147-
// Comment
148-
x int
149-
// X.
150-
X int
151-
// Comment
152-
x int
153-
}
154-
155-
const ( // foo
156-
157-
// bar
158-
x int = 0
159-
X int = 0
160-
)
161-
162-
const ( /* foo */
163-
164-
// bar
165-
x int = 0
166-
)
167-
168-
const ( // foo
169-
170-
x int = 0
171-
172-
X int = 0
173-
)
174-
175-
const ( /* foo */
176-
177-
x int = 0
178-
)
179-
180-
const (
181-
182-
x int = 0
183-
)
184-
185-
const (
186-
187-
x int = 0
188-
X int = 0
189-
190-
)
191-
192-
const (
193-
x int = 0
194-
X int = 0
195-
x int = 0
196-
)
197-
198-
const (
199-
// Comment
200-
x int = 0
201-
// X.
202-
X int = 0
203-
// Comment
204-
x int = 0
205-
)
206-
207100
// This comment group should be separated
208101
// with a newline from the next comment
209102
// group.

0 commit comments

Comments
 (0)