Skip to content

Commit d4e66bd

Browse files
committed
go/ssa: TestStdlib: disable check that function names are distinct
Even though the test doesn't request test packages, and thus doesn't encounter test variants, go list may now report PGO variants of non-test packages that would violate this assertion. Fixes golang/go#60263 Change-Id: I247e8265e380976aa26f8e4cba13445fda62c703 Reviewed-on: https://go-review.googlesource.com/c/tools/+/496575 gopls-CI: kokoro <[email protected]> Run-TryBot: Alan Donovan <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tim King <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 738ea2b commit d4e66bd

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

go/ssa/stdlib_test.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func bytesAllocated() uint64 {
3636

3737
func TestStdlib(t *testing.T) {
3838
if testing.Short() {
39-
t.Skip("skipping in short mode; too slow (https://golang.org/issue/14113)")
39+
t.Skip("skipping in short mode; too slow (https://golang.org/issue/14113)") // ~5s
4040
}
4141
testenv.NeedsTool(t, "go")
4242

@@ -81,20 +81,33 @@ func TestStdlib(t *testing.T) {
8181

8282
allFuncs := ssautil.AllFunctions(prog)
8383

84-
// Check that all non-synthetic functions have distinct names.
85-
// Synthetic wrappers for exported methods should be distinct too,
86-
// except for unexported ones (explained at (*Function).RelString).
87-
byName := make(map[string]*ssa.Function)
88-
for fn := range allFuncs {
89-
if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
90-
str := fn.String()
91-
prev := byName[str]
92-
byName[str] = fn
93-
if prev != nil {
94-
t.Errorf("%s: duplicate function named %s",
95-
prog.Fset.Position(fn.Pos()), str)
96-
t.Errorf("%s: (previously defined here)",
97-
prog.Fset.Position(prev.Pos()))
84+
// The assertion below is not valid if the program contains
85+
// variants of the same package, such as the test variants
86+
// (e.g. package p as compiled for test executable x) obtained
87+
// when cfg.Tests=true. Profile-guided optimization may
88+
// lead to similar variation for non-test executables.
89+
//
90+
// Ideally, the test would assert that all functions within
91+
// each executable (more generally: within any singly rooted
92+
// transitively closed subgraph of the import graph) have
93+
// distinct names, but that isn't so easy to compute efficiently.
94+
// Disabling for now.
95+
if false {
96+
// Check that all non-synthetic functions have distinct names.
97+
// Synthetic wrappers for exported methods should be distinct too,
98+
// except for unexported ones (explained at (*Function).RelString).
99+
byName := make(map[string]*ssa.Function)
100+
for fn := range allFuncs {
101+
if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
102+
str := fn.String()
103+
prev := byName[str]
104+
byName[str] = fn
105+
if prev != nil {
106+
t.Errorf("%s: duplicate function named %s",
107+
prog.Fset.Position(fn.Pos()), str)
108+
t.Errorf("%s: (previously defined here)",
109+
prog.Fset.Position(prev.Pos()))
110+
}
98111
}
99112
}
100113
}

0 commit comments

Comments
 (0)