From b0f680ccb8947d4e0d40e324862ccbc683afaa20 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 10 Sep 2024 13:48:55 -0400 Subject: [PATCH] go/ssa: reenable TestStdlib It wasn't broken on the builder--only with my local go toolchain. (There was some cgo-related problem with cmd/cgo/internal/test.) At least that explains why we didn't notice the failures... This CL also adds a missing error check that made the real cause of the problem hard to spot, and improves some comments and assertions. Fixes golang/go#69287 Change-Id: Iccbe2a72770499749ca780f78e2a61d5576f613b Reviewed-on: https://go-review.googlesource.com/c/tools/+/612044 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley --- go/ssa/stdlib_test.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/go/ssa/stdlib_test.go b/go/ssa/stdlib_test.go index e56d6a98156..391240ad757 100644 --- a/go/ssa/stdlib_test.go +++ b/go/ssa/stdlib_test.go @@ -35,13 +35,18 @@ func bytesAllocated() uint64 { return stats.Alloc } -// TestStdlib loads the entire standard library and its tools. +// TestStdlib loads the entire standard library and its tools and all +// their dependencies. +// +// (As of go1.23, std is transitively closed, so adding the -deps flag +// doesn't increase its result set. The cmd pseudomodule of course +// depends on a good chunk of std, but the std+cmd set is also +// transitively closed, so long as -pgo=off.) // // Apart from a small number of internal packages that are not // returned by the 'std' query, the set is essentially transitively // closed, so marginal per-dependency costs are invisible. func TestStdlib(t *testing.T) { - t.Skip("broken; see https://go.dev/issues/69287") testLoad(t, 500, "std", "cmd") } @@ -78,6 +83,9 @@ func testLoad(t *testing.T, minPkgs int, patterns ...string) { if err != nil { t.Fatal(err) } + if packages.PrintErrors(pkgs) > 0 { + t.Fatal("there were errors loading the packages") + } t1 := time.Now() alloc1 := bytesAllocated() @@ -195,9 +203,13 @@ func srcFunctions(prog *ssa.Program, pkgs []*packages.Package) (res []*ssa.Funct if decl, ok := decl.(*ast.FuncDecl); ok { obj := pkg.TypesInfo.Defs[decl.Name].(*types.Func) if obj == nil { - panic("nil *Func") + panic("nil *types.Func: " + decl.Name.Name) + } + fn := prog.FuncValue(obj) + if fn == nil { + panic("nil *ssa.Function: " + obj.String()) } - addSrcFunc(prog.FuncValue(obj)) + addSrcFunc(fn) } } }