]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: enable -pgo=auto by default
authorCherry Mui <cherryyz@google.com>
Tue, 7 Mar 2023 22:49:34 +0000 (17:49 -0500)
committerCherry Mui <cherryyz@google.com>
Wed, 22 Mar 2023 21:17:50 +0000 (21:17 +0000)
Updates #58099.
Updates #55022.

Change-Id: I32eacdf9f008d16566e0b30230ecc25d110a9811
Reviewed-on: https://go-review.googlesource.com/c/go/+/474236
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/go/alldocs.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/work/build.go
src/cmd/go/testdata/script/build_pgo_auto.txt

index ca676d5a88f1ea73647034879688a19093862b66..d6701dcfffd631b81f398ffaee4857ddc080886c 100644 (file)
 //             build, the go command selects a file named "default.pgo" in the package's
 //             directory if that file exists, and applies it to the (transitive)
 //             dependencies of the main package (other packages are not affected).
-//             Special name "off" turns off PGO.
+//             Special name "off" turns off PGO. The default is "auto".
 //     -pkgdir dir
 //             install and load all packages from dir instead of the usual locations.
 //             For example, when building with a non-standard configuration,
index e8201efe9cbdc078e76f660c66117dc251229fed..6855f67d37a77d965f1c532e8e3c2234beec5695 100644 (file)
@@ -2939,8 +2939,6 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
 // In -pgo=auto mode, it finds the default PGO profile.
 func setPGOProfilePath(pkgs []*Package) {
        switch cfg.BuildPGO {
-       case "":
-               fallthrough // default to "off"
        case "off":
                return
 
index ac9718bfb3b1660195261fd618af32ef041fdd00..6ba66be9b6af100fcbb0e1795394dff830da91f9 100644 (file)
@@ -163,7 +163,7 @@ and test commands:
                build, the go command selects a file named "default.pgo" in the package's
                directory if that file exists, and applies it to the (transitive)
                dependencies of the main package (other packages are not affected).
-               Special name "off" turns off PGO.
+               Special name "off" turns off PGO. The default is "auto".
        -pkgdir dir
                install and load all packages from dir instead of the usual locations.
                For example, when building with a non-standard configuration,
@@ -318,7 +318,7 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
        cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
        cmd.Flag.Var(&load.BuildLdflags, "ldflags", "")
        cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "")
-       cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "", "")
+       cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "auto", "")
        cmd.Flag.StringVar(&cfg.BuildPkgdir, "pkgdir", "", "")
        cmd.Flag.BoolVar(&cfg.BuildRace, "race", false, "")
        cmd.Flag.BoolVar(&cfg.BuildMSan, "msan", false, "")
index b3dcdcc481a091a4c9233b3cd8b4ef0b1dfb9e40..77f32d43b8575c04bca3c5c58aa84ade16e242c7 100644 (file)
@@ -34,6 +34,21 @@ go list -test -pgo=auto ./a/a1
 
 go list -deps -pgo=auto ./a/a1
 
+# -pgo=auto is the default. Commands without explicit -pgo=auto
+# should work as -pgo=auto.
+go build -n ./a/a1
+stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'
+stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'
+
+go build -n -o nopgo.exe ./nopgo
+stderr 'compile.*nopgo.go'
+! stderr '-pgoprofile'
+
+# -pgo=off should turn off PGO.
+go build -n -pgo=off ./a/a1
+stderr 'compile.*a1.go'
+! stderr '-pgoprofile'
+
 -- go.mod --
 module test
 go 1.20