Skip to content

Commit 2dfb423

Browse files
committed
cmd/compile: loop to ensure all autogenerated functions are compiled
I was wrong. There was a need to loop here. Fixes golang#24761 Change-Id: If13b3ab72febde930bdaebdddd1c05e0d0446020 Reviewed-on: https://go-review.googlesource.com/105615 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 8f6ae33 commit 2dfb423

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/cmd/compile/internal/gc/obj.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,17 @@ func dumpLinkerObj(bout *bio.Writer) {
144144
dumpimportstrings()
145145
dumpbasictypes()
146146

147-
// The first call to dumpsignats can generate functions,
147+
// Calls to dumpsignats can generate functions,
148148
// like method wrappers and hash and equality routines.
149-
compileFunctions()
150-
151-
// Process any new signats added during compilation.
152-
// No need to loop here; signats from compiling the generated
153-
// functions should not themselves generate new functions.
154-
// If they do, we'll know about it; the sanity check of
155-
// len(compilequeue) in gc.Main will fail.
156-
dumpsignats()
149+
// Compile any generated functions, process any new resulting types, repeat.
150+
// This can't loop forever, because there is no way to generate an infinite
151+
// number of types in a finite amount of code.
152+
// In the typical case, we loop 0 or 1 times.
153+
// It was not until issue 24761 that we found any code that required a loop at all.
154+
for len(compilequeue) > 0 {
155+
compileFunctions()
156+
dumpsignats()
157+
}
157158

158159
// Dump extra globals.
159160
tmp := externdcl

test/fixedbugs/issue24761.dir/a.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
type T2 struct{}
8+
9+
func (t *T2) M2(a, b float64) {
10+
variadic(a, b)
11+
}
12+
13+
func variadic(points ...float64) {
14+
println(points)
15+
}

test/fixedbugs/issue24761.dir/b.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
import "./a"
8+
9+
type T1 struct {
10+
*a.T2
11+
}

test/fixedbugs/issue24761.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compiledir -c=4
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package ignored

0 commit comments

Comments
 (0)