cmd/go: include simd bridge package in compiled test imports It looks like a missing logic which breaks a very simple hello world simd program. To reproduce: create a new directory, `go mod init main`, write a very simple main.go that imports simd/archsimd, and then open it with vscode+gopls, then cmd/go will panic: Error loading workspace: packages.Load error: err: exit status 2: stderr: panic: runtime error: index out of range [0] with length 0 This CL fixes that. Change-Id: I03706a12dd0d8e2351494abe95265e4fc7672e48 Reviewed-on: https://go-review.googlesource.com/c/go/+/788281 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go index 44e1c2a..8453cb2 100644 --- a/src/cmd/go/internal/load/test.go +++ b/src/cmd/go/internal/load/test.go
@@ -117,10 +117,6 @@ stk.Push(ImportInfo{Pkg: p.ImportPath + " (test)"}) rawTestImports := str.StringList(p.TestImports) - if hasSimd := hasSimd(p.TestImports); hasSimd { - p.TestImports = append(p.TestImports, SimdBridgePkg) - } - for i, path := range p.TestImports { p1, err := loadImport(ld, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.TestImportPos[path], ResolveImport) if err != nil && ptestErr == nil { @@ -133,6 +129,20 @@ p.TestImports[i] = p1.ImportPath imports = append(imports, p1) } + + var ptestCompiledImports []string + if hasSimd := hasSimd(p.TestImports); hasSimd { + p1, err := loadImport(ld, ctx, opts, pre, SimdBridgePkg, p.Dir, p, &stk, nil, ResolveImport|allowSimdInternalBridge) + if err != nil && ptestErr == nil { + ptestErr = err + incomplete = true + } + if p1.Incomplete { + incomplete = true + } + imports = append(imports, p1) + ptestCompiledImports = append(ptestCompiledImports, p1.ImportPath) + } var err error p.TestEmbedFiles, testEmbed, err = resolveEmbed(p.Dir, p.TestEmbedPatterns) if err != nil { @@ -151,10 +161,6 @@ var pxtestIncomplete bool rawXTestImports := str.StringList(p.XTestImports) - if hasSimd := hasSimd(p.XTestImports); hasSimd { - p.XTestImports = append(p.XTestImports, SimdBridgePkg) - } - for i, path := range p.XTestImports { p1, err := loadImport(ld, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.XTestImportPos[path], ResolveImport) if err != nil && pxtestErr == nil { @@ -170,6 +176,19 @@ } p.XTestImports[i] = p1.ImportPath } + + var pxtestCompiledImports []string + if hasSimd := hasSimd(p.XTestImports); hasSimd { + p1, err := loadImport(ld, ctx, opts, pre, SimdBridgePkg, p.Dir, p, &stk, nil, ResolveImport|allowSimdInternalBridge) + if err != nil && pxtestErr == nil { + pxtestErr = err + } + if p1.Incomplete { + pxtestIncomplete = true + } + ximports = append(ximports, p1) + pxtestCompiledImports = append(pxtestCompiledImports, p1.ImportPath) + } p.XTestEmbedFiles, xtestEmbed, err = resolveEmbed(p.Dir, p.XTestEmbedPatterns) if err != nil && pxtestErr == nil { pxtestErr = &PackageError{ @@ -210,6 +229,12 @@ ptest.Imports = str.StringList(p.TestImports, p.Imports) ptest.Internal.Imports = append(imports, p.Internal.Imports...) ptest.Internal.RawImports = str.StringList(rawTestImports, p.Internal.RawImports) + ptest.Internal.CompiledImports = slices.Clone(p.Internal.CompiledImports) + for _, path := range ptestCompiledImports { + if !slices.Contains(ptest.Internal.CompiledImports, path) { + ptest.Internal.CompiledImports = append(ptest.Internal.CompiledImports, path) + } + } ptest.Internal.ForceLibrary = true ptest.Internal.BuildInfo = nil ptest.Internal.Build = new(build.Package) @@ -258,8 +283,9 @@ ImportPos: p.Internal.Build.XTestImportPos, Directives: p.Internal.Build.XTestDirectives, }, - Imports: ximports, - RawImports: rawXTestImports, + Imports: ximports, + RawImports: rawXTestImports, + CompiledImports: pxtestCompiledImports, Asmflags: p.Internal.Asmflags, Gcflags: p.Internal.Gcflags,