mirror of
https://github.com/golang/go
synced 2024-11-14 22:40:40 -07:00
cmd/go/internal/load: clone pgo variant's PackagePublic.Imports in split
Before this change the pgo and non-pgo variants Imports slices pointed to the same array, so modifying the pgo variant's Imports slice to add the .ForMain suffix modified the non-pgo vairant's Imports slice too. This change clones the imports slice to avoid that. Fixes #66218 Change-Id: Ic936086f2c31f2056988d6546216142e4fce4d8d Reviewed-on: https://go-review.googlesource.com/c/go/+/588275 Reviewed-by: Sam Thanawalla <samthanawalla@google.com> Auto-Submit: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
377646589d
commit
94aeedc33a
@ -2943,8 +2943,10 @@ func setPGOProfilePath(pkgs []*Package) {
|
|||||||
}
|
}
|
||||||
p1 := new(Package)
|
p1 := new(Package)
|
||||||
*p1 = *p
|
*p1 = *p
|
||||||
// Unalias the Internal.Imports slice, which is we're going to
|
// Unalias the Imports and Internal.Imports slices,
|
||||||
// modify. We don't copy other slices as we don't change them.
|
// which we're going to modify. We don't copy other slices as
|
||||||
|
// we don't change them.
|
||||||
|
p1.Imports = slices.Clone(p.Imports)
|
||||||
p1.Internal.Imports = slices.Clone(p.Internal.Imports)
|
p1.Internal.Imports = slices.Clone(p.Internal.Imports)
|
||||||
p1.Internal.ForMain = pmain.ImportPath
|
p1.Internal.ForMain = pmain.ImportPath
|
||||||
visited[p] = p1
|
visited[p] = p1
|
||||||
|
28
src/cmd/go/testdata/script/list_pgo_issue66218.txt
vendored
Normal file
28
src/cmd/go/testdata/script/list_pgo_issue66218.txt
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Test that pgo properly splits off the Imports field so that list doesn't alias
|
||||||
|
# the non-pgo variant's slice when it modifies the pgo variant's Imports field to
|
||||||
|
# add the [.ForMain] suffix.
|
||||||
|
|
||||||
|
go list -f 'ImportPath: "{{.ImportPath}}", Imports: "{{.Imports}}", ImportMap: "{{.ImportMap}}"' m/a m/b
|
||||||
|
cmp stdout want
|
||||||
|
|
||||||
|
-- want --
|
||||||
|
ImportPath: "m/a", Imports: "[m/b [m/a]]", ImportMap: "map[m/b:m/b [m/a]]"
|
||||||
|
ImportPath: "m/b", Imports: "[m/c]", ImportMap: "map[]"
|
||||||
|
-- go.mod --
|
||||||
|
module m
|
||||||
|
|
||||||
|
go 1.23
|
||||||
|
|
||||||
|
-- a/a.go --
|
||||||
|
package main
|
||||||
|
|
||||||
|
import _ "m/b"
|
||||||
|
-- a/default.pgo --
|
||||||
|
-- b/b.go --
|
||||||
|
package a
|
||||||
|
|
||||||
|
import _ "m/c"
|
||||||
|
|
||||||
|
-- c/c.go --
|
||||||
|
package c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user